From patchwork Wed Feb 21 19:40:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13566186 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA3F3C48BEB for ; Wed, 21 Feb 2024 19:41:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C46866B0095; Wed, 21 Feb 2024 14:41:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BCE436B0096; Wed, 21 Feb 2024 14:41:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9ABC16B0098; Wed, 21 Feb 2024 14:41:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7FDB86B0095 for ; Wed, 21 Feb 2024 14:41:12 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5C2CAA0F8A for ; Wed, 21 Feb 2024 19:41:12 +0000 (UTC) X-FDA: 81816829584.08.96BDC54 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf20.hostedemail.com (Postfix) with ESMTP id A14BD1C000A for ; Wed, 21 Feb 2024 19:41:10 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Up2wyhnL; spf=pass (imf20.hostedemail.com: domain of 31VHWZQYKCAg02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=31VHWZQYKCAg02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708544470; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QzsUMX2xNFk2gXovx8vmt7vEJ3oqQRqP0H0Mn26pLn0=; b=tlOSLOIR6++/QuehYGjYvlG90ftvnl/H/dTBRmfuPVvC/WgTK9HIrg4b7NeZL8zXHrPM2t kKT0q3P4ZlTFXApgVmyZw47E58oauN0jGrx2xKPfF5OVAxLMnX8ZJ2/rpZ2MCtQJ+IxVNb 5pvyGwTXntOcgz50XV1A4nmQZ83MMNc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708544470; a=rsa-sha256; cv=none; b=vLCzM8QqYV/s/inRo4gXoywzu7ga36LFZ2uXe/6XZcPDd6Osq14Q8r10eIqvX5GntgP9dA lkhD98lgfBJUWxwEmK1czRLQY6UncOb1qg+CgTXbzWNNE5wgGEyo1jjOdMDYHQxvJ92b+o S0mzjcLBzKDmPkMQMXrRWL4ODHtvXAI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Up2wyhnL; spf=pass (imf20.hostedemail.com: domain of 31VHWZQYKCAg02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=31VHWZQYKCAg02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-608575317f8so43595487b3.3 for ; Wed, 21 Feb 2024 11:41:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708544470; x=1709149270; darn=kvack.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=QzsUMX2xNFk2gXovx8vmt7vEJ3oqQRqP0H0Mn26pLn0=; b=Up2wyhnLDFMs4ShVNnl9vBgO/8MKOCLGytkygJt4k4pE38ZjhwlQADxT/dV2Bx3LHd 8yCGU9tg8q/ln2mW3MPeIKwxDR7U9w2qP5CivP9B5gaugppvn5QahI65DGeqvg9yCEz4 y4LULLnjUQaruLEY5WF/AWw9/U+4KujBAMgCtz+2SQywxTQU6K9cZCQHnNsHJ4b0PV9r Fenx++1HevbC3Sonvu5BRJMTEq0Fw+kqFWRAuf2CHkwYbhFZORhqe5whmZ8hu01YFvca S41AFJpCpROaKmJo3/6tYE94gKgw/BSASleNYYZ9ug+lo1FahmxzcxvEAhRJ8+h+pGJ8 bJnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708544470; x=1709149270; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=QzsUMX2xNFk2gXovx8vmt7vEJ3oqQRqP0H0Mn26pLn0=; b=YPEykuyQDMU25gyyn6JR3jZIKTprFKG3nObr2LytwTfKVupEKznp7xuv47JT7mN44c U+ZloaFRPctHrs0fMAl9oYjHyCRSi+tmeUE/NbUlITIgnzRJUbYSqWhyyvoO7RQEAoHO /Sw0MEB2AgTrdjBrSBAj0qczskM1YX6OdBVLDgk43RnKuL5uDzG5rxIEayn9/qwsy/jA RY+DrnE+f9vtElh64p+c1RcYtpEU/i0rnRYeGKSW9KDO5z8v5Dr5ZOe9p4UBX1+ZY/yb m7UT4ka9jfkVLE82YjoKYokpoSuyB0mCKSQjVq6m+koA6DPmxIwtP6/D1n/J109qqBQe QF7g== X-Forwarded-Encrypted: i=1; AJvYcCVirkFzcAZjQAhuYRoCgxBnYsDikfCoko8wh5i7yF8YWZl1ZJOI61IoS5JxvWKEAL/ZfOgv7AAV/TwBZw5EjqKpHO4= X-Gm-Message-State: AOJu0YzA9xAgGzq1AoD4q5iw1FpIIqno9y9Ft/Qmb/1mAT7OBAgTYODe ofrOqbEApT2/0E9KqEAVheL0R+rQq5T/iXG8NnHmqEfL9JLzj3sWN97EACMCfMWApcfjSq7hzfq abw== X-Google-Smtp-Source: AGHT+IF7qn4ITZM6B47DxNzFWv3QLjl0M2+lztN5UUvu7bxl5t2P16qOZECK10ItUf59ZcZs0KUc+Z86KCU= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:953b:9a4e:1e10:3f07]) (user=surenb job=sendgmr) by 2002:a0d:e6c5:0:b0:608:801a:e66e with SMTP id p188-20020a0de6c5000000b00608801ae66emr474072ywe.3.1708544469656; Wed, 21 Feb 2024 11:41:09 -0800 (PST) Date: Wed, 21 Feb 2024 11:40:19 -0800 In-Reply-To: <20240221194052.927623-1-surenb@google.com> Mime-Version: 1.0 References: <20240221194052.927623-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240221194052.927623-7-surenb@google.com> Subject: [PATCH v4 06/36] mm: enumerate all gfp flags From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, penguin-kernel@i-love.sakura.ne.jp, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, surenb@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org, " =?utf-8?b?UGV0ciBU?= =?utf-8?b?ZXNhxZnDrWs=?= " X-Stat-Signature: y4j6u1ey638hwtw6yh8d9exg3d3ozeoq X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A14BD1C000A X-Rspam-User: X-HE-Tag: 1708544470-782240 X-HE-Meta: U2FsdGVkX19uyvjJEao3dBQWEMHtHaeK2TBUrVO8hIJdDY64CLAI4aNmvz5g3sApcwLCDpLWIk2zXM8qSX+E6HZwt07OsuJUq2h3FA6wy8yqwN7tzvscDA5uho2lZHKp2txtGkjvv5vLRBGnu9tQp+DbMtHkfEBDcFlf63dRzvQGBWhB098xO88sb/s2ok1ehmQhm9TUsRA+QOqblGwFOMfadOTH8ILNg2ecyyn3zxizw9fAI883UbE6UCBDVqPdx6gyzMWSXuRbcDimMTqWqtlgJBIX7cHit2npxkFL1SgLyiGEwa/rIuK3ImcQAfH/AZmJkIk1NZ40Bg6uA240U8qrLL7qbrTCBKeB70UL+lRsrBLEbtsCKzCDBU7e31lEWo1xlRaywk+rPSpsg5qV3hDiV4ps4ke2+k9bbzaBWKljO3mC9qoTiU3V/jsiffEGY5GOVlShIDVJS0fdRlmRSoPQ8wqImFM4yH07RWCVjEVCk8c7zcC+xwpAdkS6KloxpWzGSkrtn6x0+vJZbnCEOGuhc14mUlmPdmeejgy89vSR/kCRSfx/k0qk/X/mu61+542QspqBfyWEjwzRjie1es28TLaf8dXjH/tjuhEfxTCthHtNxtr1ayUlEJJOEiYrilr7WW77CCfuZ2/XTgk1KsluSt2mckX9uslVHEcQwgx0R2skMHjnKKApz6bal+79GpNF9Ra06MhJJIIjE+YJeIqM0eQANyjJUb2x1d9jIM2E53fv7/Rn5yR7roak6sG+juv1UhYDQGC9bIInoshxp3olQoGvHumMGAbjJPMgO0PWjvpf0082d9Pvh1fKIEx7lq8RiWKGRch0lJ7naGB1r/XX34/ogCABHERmV3xEwxkzqDKHJgYQG7X53vD742VTmoJhddYt79HHZuem5H0OMNZ8Tzt4laRPynAgKnfbV0aCYYM6FaHIziwhC+nSZwtKtErh9eL7FEYeN8Gz1zZ 8vWdsUCm LGE4vKJcaBLHCv4k3DtvHiM6Tb4tiIjYlgWi33c7P0uq8gXx6uL1AQ7EFM3UfKzrnwCiwk0ekvUh8QPW3+U4j1k1pMtzXtLYT5pqE+uFYgzEuLDC2JO/GszOyYTcki2H5Ax8vjGgWZbmqXgkKmUIDQLyN26iSjp/apMAFS6iE89FDbzYOMRTA2egr9/tTRjsk0VNtalO5f9qB7nOtuD5pMpiFvFAk9Tmo47/KmHrIWzB/uis2UZr3S2h+oVDI6QBU2LUVtoWnBTdlzJkpFOpxEHzrktOisHOFElK4PycjwQLtyNbKtuEu//Hg8XMS2VpyfY9CC31w4CqA3KrIatfC2R75CaDDK2cIYw21zKMDZNeSdul+tM8l6u7eoebEgW5cZCeeXwWnQX62YGypSSRcJ3aRr3YmYx5qWPMU X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Introduce GFP bits enumeration to let compiler track the number of used bits (which depends on the config options) instead of hardcoding them. That simplifies __GFP_BITS_SHIFT calculation. Suggested-by: Petr Tesařík Signed-off-by: Suren Baghdasaryan Reviewed-by: Kees Cook Reviewed-by: Pasha Tatashin Acked-by: Michal Hocko --- include/linux/gfp_types.h | 90 +++++++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 28 deletions(-) diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h index 1b6053da8754..868c8fb1bbc1 100644 --- a/include/linux/gfp_types.h +++ b/include/linux/gfp_types.h @@ -21,44 +21,78 @@ typedef unsigned int __bitwise gfp_t; * include/trace/events/mmflags.h and tools/perf/builtin-kmem.c */ +enum { + ___GFP_DMA_BIT, + ___GFP_HIGHMEM_BIT, + ___GFP_DMA32_BIT, + ___GFP_MOVABLE_BIT, + ___GFP_RECLAIMABLE_BIT, + ___GFP_HIGH_BIT, + ___GFP_IO_BIT, + ___GFP_FS_BIT, + ___GFP_ZERO_BIT, + ___GFP_UNUSED_BIT, /* 0x200u unused */ + ___GFP_DIRECT_RECLAIM_BIT, + ___GFP_KSWAPD_RECLAIM_BIT, + ___GFP_WRITE_BIT, + ___GFP_NOWARN_BIT, + ___GFP_RETRY_MAYFAIL_BIT, + ___GFP_NOFAIL_BIT, + ___GFP_NORETRY_BIT, + ___GFP_MEMALLOC_BIT, + ___GFP_COMP_BIT, + ___GFP_NOMEMALLOC_BIT, + ___GFP_HARDWALL_BIT, + ___GFP_THISNODE_BIT, + ___GFP_ACCOUNT_BIT, + ___GFP_ZEROTAGS_BIT, +#ifdef CONFIG_KASAN_HW_TAGS + ___GFP_SKIP_ZERO_BIT, + ___GFP_SKIP_KASAN_BIT, +#endif +#ifdef CONFIG_LOCKDEP + ___GFP_NOLOCKDEP_BIT, +#endif + ___GFP_LAST_BIT +}; + /* Plain integer GFP bitmasks. Do not use this directly. */ -#define ___GFP_DMA 0x01u -#define ___GFP_HIGHMEM 0x02u -#define ___GFP_DMA32 0x04u -#define ___GFP_MOVABLE 0x08u -#define ___GFP_RECLAIMABLE 0x10u -#define ___GFP_HIGH 0x20u -#define ___GFP_IO 0x40u -#define ___GFP_FS 0x80u -#define ___GFP_ZERO 0x100u +#define ___GFP_DMA BIT(___GFP_DMA_BIT) +#define ___GFP_HIGHMEM BIT(___GFP_HIGHMEM_BIT) +#define ___GFP_DMA32 BIT(___GFP_DMA32_BIT) +#define ___GFP_MOVABLE BIT(___GFP_MOVABLE_BIT) +#define ___GFP_RECLAIMABLE BIT(___GFP_RECLAIMABLE_BIT) +#define ___GFP_HIGH BIT(___GFP_HIGH_BIT) +#define ___GFP_IO BIT(___GFP_IO_BIT) +#define ___GFP_FS BIT(___GFP_FS_BIT) +#define ___GFP_ZERO BIT(___GFP_ZERO_BIT) /* 0x200u unused */ -#define ___GFP_DIRECT_RECLAIM 0x400u -#define ___GFP_KSWAPD_RECLAIM 0x800u -#define ___GFP_WRITE 0x1000u -#define ___GFP_NOWARN 0x2000u -#define ___GFP_RETRY_MAYFAIL 0x4000u -#define ___GFP_NOFAIL 0x8000u -#define ___GFP_NORETRY 0x10000u -#define ___GFP_MEMALLOC 0x20000u -#define ___GFP_COMP 0x40000u -#define ___GFP_NOMEMALLOC 0x80000u -#define ___GFP_HARDWALL 0x100000u -#define ___GFP_THISNODE 0x200000u -#define ___GFP_ACCOUNT 0x400000u -#define ___GFP_ZEROTAGS 0x800000u +#define ___GFP_DIRECT_RECLAIM BIT(___GFP_DIRECT_RECLAIM_BIT) +#define ___GFP_KSWAPD_RECLAIM BIT(___GFP_KSWAPD_RECLAIM_BIT) +#define ___GFP_WRITE BIT(___GFP_WRITE_BIT) +#define ___GFP_NOWARN BIT(___GFP_NOWARN_BIT) +#define ___GFP_RETRY_MAYFAIL BIT(___GFP_RETRY_MAYFAIL_BIT) +#define ___GFP_NOFAIL BIT(___GFP_NOFAIL_BIT) +#define ___GFP_NORETRY BIT(___GFP_NORETRY_BIT) +#define ___GFP_MEMALLOC BIT(___GFP_MEMALLOC_BIT) +#define ___GFP_COMP BIT(___GFP_COMP_BIT) +#define ___GFP_NOMEMALLOC BIT(___GFP_NOMEMALLOC_BIT) +#define ___GFP_HARDWALL BIT(___GFP_HARDWALL_BIT) +#define ___GFP_THISNODE BIT(___GFP_THISNODE_BIT) +#define ___GFP_ACCOUNT BIT(___GFP_ACCOUNT_BIT) +#define ___GFP_ZEROTAGS BIT(___GFP_ZEROTAGS_BIT) #ifdef CONFIG_KASAN_HW_TAGS -#define ___GFP_SKIP_ZERO 0x1000000u -#define ___GFP_SKIP_KASAN 0x2000000u +#define ___GFP_SKIP_ZERO BIT(___GFP_SKIP_ZERO_BIT) +#define ___GFP_SKIP_KASAN BIT(___GFP_SKIP_KASAN_BIT) #else #define ___GFP_SKIP_ZERO 0 #define ___GFP_SKIP_KASAN 0 #endif #ifdef CONFIG_LOCKDEP -#define ___GFP_NOLOCKDEP 0x4000000u +#define ___GFP_NOLOCKDEP BIT(___GFP_NOLOCKDEP_BIT) #else #define ___GFP_NOLOCKDEP 0 #endif -/* If the above are modified, __GFP_BITS_SHIFT may need updating */ /* * Physical address zone modifiers (see linux/mmzone.h - low four bits) @@ -249,7 +283,7 @@ typedef unsigned int __bitwise gfp_t; #define __GFP_NOLOCKDEP ((__force gfp_t)___GFP_NOLOCKDEP) /* Room for N __GFP_FOO bits */ -#define __GFP_BITS_SHIFT (26 + IS_ENABLED(CONFIG_LOCKDEP)) +#define __GFP_BITS_SHIFT ___GFP_LAST_BIT #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) /**