From mboxrd@z Thu Jan 1 00:00:00 1970 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 3FC72C48BF6 for ; Sun, 25 Feb 2024 01:13:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51EF96B00E6; Sat, 24 Feb 2024 20:13:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CF636B00E7; Sat, 24 Feb 2024 20:13:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36F3B6B00E8; Sat, 24 Feb 2024 20:13:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 26BA06B00E6 for ; Sat, 24 Feb 2024 20:13:04 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A2A7C804A2 for ; Sun, 25 Feb 2024 01:13:03 +0000 (UTC) X-FDA: 81828552246.10.C026BA8 Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) by imf17.hostedemail.com (Postfix) with ESMTP id 54E484000C for ; Sun, 25 Feb 2024 01:13:00 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=F1lP5HyM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of surenb@google.com designates 209.85.219.174 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708823580; 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=qBmWkRHnX+rayZ1+8KolBLB9Y8UaFwH+z+kRh4M3z/U=; b=yDZrMqt8Uwrwr7LoADIdaxmVoY7Im+no5mABV+ngc0QKIS0K8NsGr82cyZWGkNz/CYOLih NZ3dEjRkTVpiSzd4m6pFqxru/zvZyfmGVc7MoPaTp2IWwfHQszYhlGAtelhqQi3wgVGvWl DoyoBP0EAnbihwv2QgFH1w6BKHA2syc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=F1lP5HyM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of surenb@google.com designates 209.85.219.174 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708823580; a=rsa-sha256; cv=none; b=TF23V9lUaVD3zOO8UjnRgk4QTdKrkWMeo+M5tz0gG674wY3+14KKTgQGyQbJ7w7g+FXxIi QNvhL+6uRv6D+bibV1OVk6AL72CUsyl0RmJ8ME4bAqA84aO+0YgyA8AxBdAShD+qZvlrZK WWebFc29ZWtJkbbG9sg4YRlSVB0GdkE= Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-dcc6fc978ddso1661307276.0 for ; Sat, 24 Feb 2024 17:13:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708823579; x=1709428379; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=qBmWkRHnX+rayZ1+8KolBLB9Y8UaFwH+z+kRh4M3z/U=; b=F1lP5HyM0LpiPzAaIuFVYCasIN5XGmP9wu8z5hB3SIEdZeSc0ao2dR+InJN7SXQvli Wu8rpoRKiWNxJsfq2AUo9YiNNkh1WLuJqTWyiwyJQrVfjiaMET1HknaoaYfSW8QWdpPw xhnFAur7T4INHJlhh0XxlzC2QQlNfbUahs4nhOTpT5GpGHtiBk7sLG8mvRqFo2SO6v8X shyclrah7tl+q/G6pCp8Vh0GbQT1TBCoN7ctFJsOXVqmrJk7ZLRGSt5pM0sdQ3sx5ITc pCE7Khr+2+ME7IrJwqEyMaLYSQqT77zajDYlkFqZjBNSQyQMdnor7OYv+20z8hFYbrSK Yplg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708823579; x=1709428379; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qBmWkRHnX+rayZ1+8KolBLB9Y8UaFwH+z+kRh4M3z/U=; b=so3JBErjTLE99TcKDdw8+YSkLoHNQ0fhfFHtjw5ZWK0SxdLpHHLmfB4WlvhxF7fIKi jikjet+CzLGE1s5CW3u6j3B5ov+qD6S7jJ1uPLOt3dw0RLhS3iOqLnj7rFECda8FakFF gEwZg3SpD1d1kJAm1A6g2BPCLjRtMnBw5SHF67KzM612Cr05lEvC1pu5lxNWLEBxx8CS koKpF/oSfD8Di4EtJytXhfS+bHTrvTItRCVAStipFxDX/g2M2D55jnMfqMm89EqREG14 H90cG6MysNd1+rAAzP5zYwjdMH2F4AQTrEh0qyZA1kkVbksSKGitn5gH7X+11IWyKkGz jySQ== X-Forwarded-Encrypted: i=1; AJvYcCX+/opOJvrTY55x8PxwrsHFGrsdc8BXIzWs+CvgC+VF/LxvHxHoTwmSz8rsW6Xc0B8GYzz2ALHFLBaMKcLCblYNOQM= X-Gm-Message-State: AOJu0YyfR6NSQ7AB1Erc9O2xJHL7nLKhKQghjfi4atImHefa1PA2d/Fi XqVjV4Ewq3kJpS+Ijm30S+nautVYOtQ/lqnTqQywkHNm9OYi4SpB5yh08K0vGusp2vd310iShc6 cXA479MUyNvGQqd7ldrz7MayYL86Q1AsSXe7n X-Google-Smtp-Source: AGHT+IGAAllR6CQecVwzwYFxQv6mTO/GWCkTuo/lW9TrmXUMPa8PaZXxJjHI7bpRL2KwGZ3IpVRA0pKkB/ekKb3d8zw= X-Received: by 2002:a25:ae15:0:b0:dc6:16b7:7d6f with SMTP id a21-20020a25ae15000000b00dc616b77d6fmr2102451ybj.10.1708823579088; Sat, 24 Feb 2024 17:12:59 -0800 (PST) MIME-Version: 1.0 References: <20240224015800.2569851-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Sun, 25 Feb 2024 01:12:46 +0000 Message-ID: Subject: Re: [PATCH v5 1/1] mm: enumerate all gfp flags To: Christophe JAILLET Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, petr@tesarici.cz, keescook@chromium.org, pasha.tatashin@soleen.com, mhocko@suse.com, kernel-team@android.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 54E484000C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 7sr9da5gwzx3za4dnu7qkuqkgohmdhn1 X-HE-Tag: 1708823580-894936 X-HE-Meta: U2FsdGVkX1/T7fpa5RgUW4EYOyZofBNnfy8Iu2vXw/meriG2zqw1UYUNT/oD8IFBYY9zxqqBjrz6IsGVEQN5TD5Nv9QqBN10CbGtTOZNxLTE6mT3tto8eUx/vcYTZ73HimeZkt33IK2qa3oa5gdyR4WbSgfuNXzUPV5DMssYeWYVcSPDiiuCfOhvSCSe069c9ks08L4aqDsIzvG/Odng8m4LLLgGxCr74eJKKUJPMLgQYqe4dWpAMIvkYTtRmhepRNGpjz0UydQKB0Pm97mWhDay6GJyuJnTjL4u1UdKD7MSE/JNNBz3+yckL+kkjHFKX2RMhxAsa5LnzfOEHWxDMQYnmK4IIAG+pBq9xG3L4UcjYNEe/5QlDQut2PJpQ0G9PfqEd6lo8EokikPt2fXNFXbzVP7o/uZdotugcJfzENdzWNk2puGqUuFDyZHJaSUfK4xf3BYrVdlHBu3rNAY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kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Sat, Feb 24, 2024 at 7:03=E2=80=AFAM Christophe JAILLET wrote: > > Le 24/02/2024 =C3=A0 02:58, Suren Baghdasaryan a =C3=A9crit : > > 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=C5=99=C3=ADk > > Signed-off-by: Suren Baghdasaryan > > Reviewed-by: Kees Cook > > Reviewed-by: Pasha Tatashin > > Acked-by: Michal Hocko > > --- > > Changes from v4 [1]: > > - Split from the series [2] as a stand-alone patch, per Michal Hocko > > - Added Reviewed-by, per Pasha Tatashin > > - Added Acked-by, per Michal Hocko > > > > [1] https://lore.kernel.org/all/20240221194052.927623-7-surenb@google.c= om/ > > [2] https://lore.kernel.org/all/20240221194052.927623-1-surenb@google.c= om/ > > > > 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 */ > > Hi, > > what is the need to have this ___GFP_UNUSED_BIT now? Hi! We can remove it but then all values will shift. That should be safe to do now but I prefer one patch to do only one thing. We can add a separate patch to do further cleanup of unused values. > > > + ___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 > > +}; > > Does it make sense to have something like: > BUILD_BUG_ON(___GFP_LAST_BIT > BITS_PER_LONG, "blah"); I suppose that would not hurt, except gfp_t is unsigned int, not long. Something like this would work I think: BUILD_BUG_ON_MSG(___GFP_LAST_BIT > BITS_PER_TYPE(gfp_t), "GFP bit overflow"= ); except I'm not sure where to put this check. One of the __init functions in page_alloc.c would probably work but none seem to be appropriate. mm_core_init() perhaps? Other ideas? > (should we need to use BIT_ULL() one day) > > > + > > /* 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 */ > > Keeping this comment here is now useless, IMHO. Until the cleanup I would prefer to have it here to denote the gap. Thanks, Suren. > > CJ > > > -#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 bit= s) > > @@ -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)= ) > > > > /** > > > > base-commit: 603c04e27c3e9891ce7afa5cd6b496bfacff4206 >