linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yury Norov <ynorov@nvidia.com>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Jarkko Sakkinen <jarkko@kernel.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Dan Williams <dan.j.williams@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Dave Jiang <dave.jiang@intel.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Tvrtko Ursulin <tursulin@ursulin.net>,
	Christian Koenig <christian.koenig@amd.com>,
	Huang Rui <ray.huang@amd.com>,
	Matthew Auld <matthew.auld@intel.com>,
	Matthew Brost <matthew.brost@intel.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	Benjamin LaHaise <bcrl@kvack.org>, Gao Xiang <xiang@kernel.org>,
	Chao Yu <chao@kernel.org>, Yue Hu <zbestahu@gmail.com>,
	Jeffle Xu <jefflexu@linux.alibaba.com>,
	Sandeep Dhavale <dhavale@google.com>,
	Hongbo Li <lihongbo22@huawei.com>,
	Chunhai Guo <guochunhai@vivo.com>, Theodore Ts'o <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	Muchun Song <muchun.song@linux.dev>,
	Oscar Salvador <osalvador@suse.de>,
	David Hildenbrand <david@kernel.org>,
	Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
	Mike Marshall <hubcap@omnibond.com>,
	Martin Brandenburg <martin@omnibond.com>,
	Tony Luck <tony.luck@intel.com>,
	Reinette Chatre <reinette.chatre@intel.com>,
	Dave Martin <Dave.Martin@arm.com>,
	James Morse <james.morse@arm.com>,
	Babu Moger <babu.moger@amd.com>, Carlos Maiolino <cem@kernel.org>,
	Damien Le Moal <dlemoal@kernel.org>,
	Naohiro Aota <naohiro.aota@wdc.com>,
	Johannes Thumshirn <jth@kernel.org>,
	Matthew Wilcox <willy@infradead.org>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Vlastimil Babka <vbabka@suse.cz>, Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>, Hugh Dickins <hughd@google.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Zi Yan <ziy@nvidia.com>, Nico Pache <npache@redhat.com>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
	Jann Horn <jannh@google.com>, Pedro Falcato <pfalcato@suse.de>,
	David Howells <dhowells@redhat.com>,
	Paul Moore <paul@paul-moore.com>,
	James Morris <jmorris@namei.org>,
	"Serge E . Hallyn" <serge@hallyn.com>,
	Yury Norov <yury.norov@gmail.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org,
	nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org,
	dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
	linux-fsdevel@vger.kernel.org, linux-aio@kvack.org,
	linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org,
	linux-mm@kvack.org, ntfs3@lists.linux.dev,
	devel@lists.orangefs.org, linux-xfs@vger.kernel.org,
	keyrings@vger.kernel.org, linux-security-module@vger.kernel.org,
	Jason Gunthorpe <jgg@nvidia.com>
Subject: Re: [PATCH v2 00/13] mm: add bitmap VMA flag helpers and convert all mmap_prepare to use them
Date: Tue, 27 Jan 2026 08:53:44 -0500	[thread overview]
Message-ID: <aXjDaN4pwEyyBy-I@yury> (raw)
In-Reply-To: <cover.1769097829.git.lorenzo.stoakes@oracle.com>

On Thu, Jan 22, 2026 at 04:06:09PM +0000, Lorenzo Stoakes wrote:
> We introduced the bitmap VMA type vma_flags_t in the aptly named commit
> 9ea35a25d51b ("mm: introduce VMA flags bitmap type") in order to permit
> future growth in VMA flags and to prevent the asinine requirement that VMA
> flags be available to 64-bit kernels only if they happened to use a bit
> number about 32-bits.
> 
> This is a long-term project as there are very many users of VMA flags
> within the kernel that need to be updated in order to utilise this new
> type.
> 
> In order to further this aim, this series adds a number of helper functions
> to enable ordinary interactions with VMA flags - that is testing, setting
> and clearing them.
> 
> In order to make working with VMA bit numbers less cumbersome this series
> introduces the mk_vma_flags() helper macro which generates a vma_flags_t
> from a variadic parameter list, e.g.:
> 
> 	vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
> 					 VMA_EXEC_BIT);

This should go on the bitmaps level. There's at least one another
possible client for this function - mm_flags_t. Maybe another generic
header bitmap_flags.h?

> It turns out that the compiler optimises this very well to the point that
> this is just as efficient as using VM_xxx pre-computed bitmap values.

It turns out, it's not a compiler - it's people writing code well. :)
Can you please mention the test_bitmap_const_eval() here and also
discuss configurations that break compile-time evaluation, like
KASAN+GCOV?

> This series then introduces the following functions:
> 
> 	bool vma_flags_test_mask(vma_flags_t flags, vma_flags_t to_test);
> 	bool vma_flags_test_all_mask(vma_flags_t flags, vma_flags_t to_test);
> 	void vma_flags_set_mask(vma_flags_t *flags, vma_flags_t to_set);
> 	void vma_flags_clear_mask(vma_flags_t *flags, vma_flags_t to_clear);
> 
> Providing means of testing any flag, testing all flags, setting, and clearing a
> specific vma_flags_t mask.
> 
> For convenience, helper macros are provided - vma_flags_test(),
> vma_flags_set() and vma_flags_clear(), each of which utilise mk_vma_flags()
> to make these operations easier, as well as an EMPTY_VMA_FLAGS macro to
> make initialisation of an empty vma_flags_t value easier, e.g.:
> 
> 	vma_flags_t flags = EMPTY_VMA_FLAGS;
> 
> 	vma_flags_set(&flags, VMA_READ_BIT, VMA_WRITE_BIT, VMA_EXEC_BIT);
> 	...
> 	if (vma_flags_test(flags, VMA_READ_BIT)) {
> 		...
> 	}
> 	...
> 	if (vma_flags_test_all_mask(flags, VMA_REMAP_FLAGS)) {
> 		...
> 	}
> 	...
> 	vma_flags_clear(&flags, VMA_READ_BIT);
> 
> Since callers are often dealing with a vm_area_struct (VMA) or vm_area_desc
> (VMA descriptor as used in .mmap_prepare) object, this series further
> provides helpers for these - firstly vma_set_flags_mask() and vma_set_flags() for a
> VMA:
> 
> 	vma_flags_t flags = EMPTY_VMA_FLAGS:
> 
> 	vma_flags_set(&flags, VMA_READ_BIT, VMA_WRITE_BIT, VMA_EXEC_BIT);
> 	...
> 	vma_set_flags_mask(&vma, flags);
> 	...
> 	vma_set_flags(&vma, VMA_DONTDUMP_BIT);

Having both vma_set_flags() and vma_flags_set() looks confusing...

> Note that these do NOT ensure appropriate locks are taken and assume the
> callers takes care of this.
> 
> For VMA descriptors this series adds vma_desc_[test, set,
> clear]_flags_mask() and vma_desc_[test, set, clear]_flags() for a VMA
> descriptor, e.g.:
> 
> 	static int foo_mmap_prepare(struct vm_area_desc *desc)
> 	{
> 		...
> 		vma_desc_set_flags(desc, VMA_SEQ_READ_BIT);
> 		vma_desc_clear_flags(desc, VMA_RAND_READ_BIT);
> 		...
> 		if (vma_desc_test_flags(desc, VMA_SHARED_BIT) {
> 			...
> 		}
> 		...
> 	}
> 
> With these helpers introduced, this series then updates all mmap_prepare
> users to make use of the vma_flags_t vm_area_desc->vma_flags field rather
> than the legacy vm_flags_t vm_area_desc->vm_flags field.
> 
> In order to do so, several other related functions need to be updated, with
> separate patches for larger changes in hugetlbfs, secretmem and shmem
> before finally removing vm_area_desc->vm_flags altogether.
> 
> This lays the foundations for future elimination of vm_flags_t and
> associated defines and functionality altogether in the long run, and
> elimination of the use of vm_flags_t in f_op->mmap() hooks in the near term
> as mmap_prepare replaces these.
> 
> There is a useful synergy between the VMA flags and mmap_prepare work here
> as with this change in place, converting f_op->mmap() to f_op->mmap_prepare
> naturally also converts use of vm_flags_t to vma_flags_t in all drivers
> which declare mmap handlers.
> 
> This accounts for the majority of the users of the legacy vm_flags_*()
> helpers and thus a large number of drivers which need to interact with VMA
> flags in general.
> 
> This series also updates the userland VMA tests to account for the change,
> and adds unit tests for these helper functions to assert that they behave
> as expected.
> 
> In order to faciliate this change in a sensible way, the series also
> separates out the VMA unit tests into - code that is duplicated from the
> kernel that should be kept in sync, code that is customised for test
> purposes and code that is stubbed out.
> 
> We also separate out the VMA userland tests into separate files to make it
> easier to manage and to provide a sensible baseline for adding the userland
> tests for these helpers.
> 
> 
> REVIEWS NOTE: I rebased this on
> https://lore.kernel.org/linux-mm/cover.1769086312.git.lorenzo.stoakes@oracle.com/
> in order to make life easier with conflict resolutions.

Before I deep into implementation details, can you share more background?

It seems you're implementing an arbitrary-length flags for VMAs, but the
length that you actually set is unconditionally 64. So why just not use
u64 for this?

Even if you expect adding more flags, u128 would double your capacity,
and people will still be able to use language-supported operation on
the bits in flag. Which looks simpler to me...

Thanks,
Yury


  parent reply	other threads:[~2026-01-27 13:54 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-22 16:06 Lorenzo Stoakes
2026-01-22 16:06 ` [PATCH v2 01/13] mm/vma: remove __private sparse decoration from vma_flags_t Lorenzo Stoakes
2026-02-06 17:02   ` Pedro Falcato
2026-02-09 18:38   ` Liam R. Howlett
2026-01-22 16:06 ` [PATCH v2 02/13] mm: rename vma_flag_test/set_atomic() to vma_test/set_atomic_flag() Lorenzo Stoakes
2026-02-06 17:04   ` Pedro Falcato
2026-02-09 18:40   ` Liam R. Howlett
2026-01-22 16:06 ` [PATCH v2 03/13] mm: add mk_vma_flags() bitmap flag macro helper Lorenzo Stoakes
2026-02-06 17:14   ` Pedro Falcato
2026-02-09 14:02     ` Lorenzo Stoakes
2026-02-09 18:44   ` Liam R. Howlett
2026-01-22 16:06 ` [PATCH v2 04/13] tools: bitmap: add missing bitmap_[subset(), andnot()] Lorenzo Stoakes
2026-02-09 18:45   ` Liam R. Howlett
2026-01-22 16:06 ` [PATCH v2 05/13] mm: add basic VMA flag operation helper functions Lorenzo Stoakes
2026-02-06 17:35   ` Pedro Falcato
2026-02-09 14:04     ` Lorenzo Stoakes
2026-02-09 18:53   ` Liam R. Howlett
2026-01-22 16:06 ` [PATCH v2 06/13] mm: update hugetlbfs to use VMA flags on mmap_prepare Lorenzo Stoakes
2026-02-09 19:03   ` Liam R. Howlett
2026-01-22 16:06 ` [PATCH v2 07/13] mm: update secretmem " Lorenzo Stoakes
2026-01-28 12:08   ` Chris Mason
2026-01-28 16:04     ` Lorenzo Stoakes
2026-01-28 16:44   ` Lorenzo Stoakes
2026-02-09 19:06   ` Liam R. Howlett
2026-01-22 16:06 ` [PATCH v2 08/13] mm: update shmem_[kernel]_file_*() functions to use vma_flags_t Lorenzo Stoakes
2026-01-23  6:20   ` Baolin Wang
2026-01-23 12:30     ` Lorenzo Stoakes
2026-01-23  7:46   ` Darrick J. Wong
2026-01-23 12:26     ` Lorenzo Stoakes
2026-01-23 12:33   ` Lorenzo Stoakes
2026-01-25 14:50   ` Jarkko Sakkinen
2026-02-09 19:13   ` Liam R. Howlett
2026-01-22 16:06 ` [PATCH v2 09/13] mm: update all remaining mmap_prepare users " Lorenzo Stoakes
2026-01-22 23:31   ` Damien Le Moal
2026-01-23  7:47   ` Darrick J. Wong
2026-02-06 17:46   ` Pedro Falcato
2026-02-06 19:31     ` Andrew Morton
2026-02-06 20:01       ` Lorenzo Stoakes
2026-02-09 19:27         ` Liam R. Howlett
2026-01-22 16:06 ` [PATCH v2 10/13] mm: make vm_area_desc utilise vma_flags_t only Lorenzo Stoakes
2026-02-06 17:49   ` Pedro Falcato
2026-02-09 19:32   ` Liam R. Howlett
2026-01-22 16:06 ` [PATCH v2 11/13] tools/testing/vma: separate VMA userland tests into separate files Lorenzo Stoakes
2026-02-09 19:58   ` Liam R. Howlett
2026-02-10 17:44     ` Lorenzo Stoakes
2026-01-22 16:06 ` [PATCH v2 12/13] tools/testing/vma: separate out vma_internal.h into logical headers Lorenzo Stoakes
2026-01-27 10:03   ` Lorenzo Stoakes
2026-02-09 20:18   ` Liam R. Howlett
2026-01-22 16:06 ` [PATCH v2 13/13] tools/testing/vma: add VMA userland tests for VMA flag functions Lorenzo Stoakes
2026-02-09 20:23   ` Liam R. Howlett
2026-01-22 16:56 ` [PATCH v2 00/13] mm: add bitmap VMA flag helpers and convert all mmap_prepare to use them Andrew Morton
2026-01-27 13:53 ` Yury Norov [this message]
2026-01-27 14:40   ` Lorenzo Stoakes
2026-01-27 21:36     ` Yury Norov
2026-01-28  9:33       ` Lorenzo Stoakes
2026-01-28 15:50         ` Pedro Falcato

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aXjDaN4pwEyyBy-I@yury \
    --to=ynorov@nvidia.com \
    --cc=Dave.Martin@arm.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=airlied@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=arnd@arndb.de \
    --cc=babu.moger@amd.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=bcrl@kvack.org \
    --cc=bp@alien8.de \
    --cc=brauner@kernel.org \
    --cc=cem@kernel.org \
    --cc=chao@kernel.org \
    --cc=christian.koenig@amd.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dave.jiang@intel.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=devel@lists.orangefs.org \
    --cc=dhavale@google.com \
    --cc=dhowells@redhat.com \
    --cc=dlemoal@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=guochunhai@vivo.com \
    --cc=hpa@zytor.com \
    --cc=hubcap@omnibond.com \
    --cc=hughd@google.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jack@suse.cz \
    --cc=james.morse@arm.com \
    --cc=jani.nikula@linux.intel.com \
    --cc=jannh@google.com \
    --cc=jarkko@kernel.org \
    --cc=jefflexu@linux.alibaba.com \
    --cc=jgg@nvidia.com \
    --cc=jmorris@namei.org \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=jth@kernel.org \
    --cc=keyrings@vger.kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=lihongbo22@huawei.com \
    --cc=linux-aio@kvack.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=martin@omnibond.com \
    --cc=matthew.auld@intel.com \
    --cc=matthew.brost@intel.com \
    --cc=mhocko@suse.com \
    --cc=mingo@redhat.com \
    --cc=mripard@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=naohiro.aota@wdc.com \
    --cc=npache@redhat.com \
    --cc=ntfs3@lists.linux.dev \
    --cc=nvdimm@lists.linux.dev \
    --cc=osalvador@suse.de \
    --cc=paul@paul-moore.com \
    --cc=pfalcato@suse.de \
    --cc=ray.huang@amd.com \
    --cc=reinette.chatre@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=serge@hallyn.com \
    --cc=simona@ffwll.ch \
    --cc=surenb@google.com \
    --cc=tglx@kernel.org \
    --cc=tony.luck@intel.com \
    --cc=tursulin@ursulin.net \
    --cc=tytso@mit.edu \
    --cc=tzimmermann@suse.de \
    --cc=vbabka@suse.cz \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vishal.l.verma@intel.com \
    --cc=willy@infradead.org \
    --cc=x86@kernel.org \
    --cc=xiang@kernel.org \
    --cc=yury.norov@gmail.com \
    --cc=zbestahu@gmail.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox