Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp296067rdb; Thu, 22 Feb 2024 04:14:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUF1l5x6ZwXu6giTbti2uacqG8Hyuz6EFhJ4wI9VltDMpquNPzPiFHFbOcwtXUa3828S0I3I0cudkLD4jeKzS8rvY9/Rw0zz8ePX4OXAA== X-Google-Smtp-Source: AGHT+IHmoXAzKK1o9+sK2R7tVEMU3m7SKqK3bhcDbdccv2Q0djx5IOYPjAsev6oF2fSORktx4nGq X-Received: by 2002:a17:90a:990f:b0:299:5bd3:42c3 with SMTP id b15-20020a17090a990f00b002995bd342c3mr11173901pjp.43.1708604046587; Thu, 22 Feb 2024 04:14:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708604046; cv=pass; d=google.com; s=arc-20160816; b=iGELYbnVeeGyQdY7+b/vro3c7JBLyN40/felzKI89fO/Wv+0woc8KiagqXnvLnMjGG q1Kxi3e30iT01OVIOkMvZ61wgsnn5cwoi5UVW6bRlVgK8Xp7R3uDEix9S5VYLL54lvVq GONnx7QF4eHy2WJnUNFicSGXcH0vsjqQiLsi74xywHPJICVNof2yun3CfNHAPo2gfiNu G6ZDpVoPXKjZIH0gez7Ef3TzhIHd2cb2nBIWn969GeMdHf6BzAwvavv0FIcgf5y4AzYm xOOehaHcLZb/FH2pDlqdGTffSy39ECl+L7egH0rKhFyX9UO882ATjwgKTqM6QkAnL2W9 qLeA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=iDZS9rn1ORcB7JdPkuWo18rKAM4Uqo344IyJ6OSxvyU=; fh=Uv1Qjn8qwzHTZ90qIvfQWmAIrV9KYTXOePbvM/Nk5uc=; b=Uf9sxZOxU4MGsmMpNQX38tbu3huFk4hSMoFE5Ve3jV/979UesQlqP0Bgev5OkkT+Mz rgbInWmjPA/tfEE/XuNh31I1ksCSgT79pyQ4aJ3Jl7ZBjt6OKZ41Tnf23NTcMz5acWl+ AG3khQf1rFRUEF488nV3lJQIfcvWhulpqusdiDBG2/sYyWVl2GgihUub2sbi3LtUhNef Aq47zRvmU7IgCnmr1amFK5v/RXmOPoNxyhmZCTuOikcuq99QLZYYZ45YCLEAJ7gq53UD g5sDo89RBwk1v6VIH2nOpEko2rgBb9n6ehSSD0vD+wz3/34jCH0WDOccet9S6zzpkhDG 4yqw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=FE4RHYf6; dkim=pass header.i=@suse.com header.s=susede1 header.b=nU7WDITh; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-76487-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76487-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id pq4-20020a17090b3d8400b0029994c224b2si7877381pjb.37.2024.02.22.04.14.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 04:14:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76487-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=FE4RHYf6; dkim=pass header.i=@suse.com header.s=susede1 header.b=nU7WDITh; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-76487-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76487-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 821F7B252AA for ; Thu, 22 Feb 2024 12:12:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3118E60B87; Thu, 22 Feb 2024 12:12:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="FE4RHYf6"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="nU7WDITh" Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED6E53FE47; Thu, 22 Feb 2024 12:12:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708603954; cv=none; b=c/3niIbK4iQypS4Wa2FvX+lHapaSqvNt3OhoW6xZlOJzrfQeiAFBFdFuY9/mXcDQy6Yfm3j99V2938d0bqBsJIFO6yOQon6VgNt+UwOCgkHEEw0bn6mjXzydMCuqSTGfUKFm5MDQODAR0WcDujvRK2yNL4OgJ3eK2dnwHZOdY9c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708603954; c=relaxed/simple; bh=FVdZu1RyDYBRnbvcrBaCROcUhkIvKg3pVHlVzcbPamI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nYtL1DhLBfbrV8fCl4s8i5iqXtGlPvIeWEtfIKqidqleCOAvZoivcXNF0zWzIX0USOxjfLcWJ3CR/HtSsalVUKr/qWQJCcIZhJwFw+nWbbZj/b/UnQtMqKExKB7k1RG1lf9LKeWmt/FgzujjGZRSXIboykJ4DNt9kFS2wiY7DOI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=FE4RHYf6; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=nU7WDITh; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E40B71F457; Thu, 22 Feb 2024 12:12:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708603950; h=from:from:reply-to: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; bh=iDZS9rn1ORcB7JdPkuWo18rKAM4Uqo344IyJ6OSxvyU=; b=FE4RHYf6KQniBvu69hMH61YFsJGUm+be/AWgzv3XVTDS8haXVcKEcmtqhLYtyoH79wE+BF 9rTbXWAQMLmYQg3dhbWCm6OQO7Hl7M/EukNOai/eLMIyuZ/W9oozZ458YgCq5yQMsvEOG9 9pG+sSYy3ZZ9rbeHDquU39srhn5O5Vc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1708603949; h=from:from:reply-to: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; bh=iDZS9rn1ORcB7JdPkuWo18rKAM4Uqo344IyJ6OSxvyU=; b=nU7WDIThkhntaO85yrfZH+rTOcDv2P9JE96isJ7T+1A7OWnrrCYh5wjA2AMoxhC/+10aqG iaI/IirNep5cQnEr9Hn5ohr48ApPMWRLfdMJkWuT0SulHAuto1+doT2DtrDHrf4LrtEqzZ KGRJHRN6xIdAfHSvGSq+zmWiPenhKQM= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B76F9133DC; Thu, 22 Feb 2024 12:12:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id tUIxLC0612VEJwAAD6G6ig (envelope-from ); Thu, 22 Feb 2024 12:12:29 +0000 Date: Thu, 22 Feb 2024 13:12:29 +0100 From: Michal Hocko To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, 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, 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, Petr =?utf-8?B?VGVzYcWZw61r?= Subject: Re: [PATCH v4 06/36] mm: enumerate all gfp flags Message-ID: References: <20240221194052.927623-1-surenb@google.com> <20240221194052.927623-7-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240221194052.927623-7-surenb@google.com> Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: 0.70 X-Spamd-Result: default: False [0.70 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_HAM(-0.00)[10.38%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_GT_50(0.00)[75]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_NOT_FQDN(0.50)[]; FREEMAIL_CC(0.00)[linux-foundation.org,linux.dev,suse.cz,cmpxchg.org,suse.de,stgolabs.net,infradead.org,oracle.com,i-love.sakura.ne.jp,lwn.net,manifault.com,redhat.com,arm.com,kernel.org,arndb.de,linutronix.de,linux.intel.com,kernel.dk,soleen.com,google.com,gmail.com,chromium.org,linuxfoundation.org,linaro.org,goodmis.org,linux.com,lge.com,bytedance.com,akamai.com,android.com,vger.kernel.org,lists.linux.dev,kvack.org,googlegroups.com,tesarici.cz]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[] X-Spam-Flag: NO On Wed 21-02-24 11:40:19, Suren Baghdasaryan wrote: > 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 I thought I have responded to this patch but obviously not the case. I like this change. Makes sense even without the rest of the series. Acked-by: Michal Hocko It seems that KASAN flags already __GFP_BITS_SHIFT which just proves how fragile this existing scheme is. > --- > 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)) > > /** > -- > 2.44.0.rc0.258.g7320e95886-goog -- Michal Hocko SUSE Labs