Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <ljs@kernel.org>
To: Zi Yan <ziy@nvidia.com>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
	"Thomas Bogendoerfer" <tsbogend@alpha.franken.de>,
	"Madhavan Srinivasan" <maddy@linux.ibm.com>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"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>,
	"Lucas Stach" <l.stach@pengutronix.de>,
	"Inki Dae" <inki.dae@samsung.com>,
	"Seung-Woo Kim" <sw0312.kim@samsung.com>,
	"Kyungmin Park" <kyungmin.park@samsung.com>,
	"Krzysztof Kozlowski" <krzk@kernel.org>,
	"Peter Griffin" <peter.griffin@linaro.org>,
	"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>,
	"Rob Clark" <robin.clark@oss.qualcomm.com>,
	"Dmitry Baryshkov" <lumag@kernel.org>,
	"Lyude Paul" <lyude@redhat.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Tomi Valkeinen" <tomi.valkeinen@ideasonboard.com>,
	"Sandy Huang" <hjc@rock-chips.com>,
	"Heiko Stübner" <heiko@sntech.de>,
	"Andy Yan" <andy.yan@rock-chips.com>,
	"Thierry Reding" <thierry.reding@kernel.org>,
	"Mikko Perttunen" <mperttunen@nvidia.com>,
	"Jonathan Hunter" <jonathanh@nvidia.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
	"Zack Rusin" <zack.rusin@broadcom.com>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Thomas Hellstrom" <thomas.hellstrom@linux.intel.com>,
	"Oleksandr Andrushchenko" <oleksandr_andrushchenko@epam.com>,
	"Helge Deller" <deller@gmx.de>,
	"Benjamin LaHaise" <bcrl@kvack.org>,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Christian Brauner" <brauner@kernel.org>,
	"Muchun Song" <muchun.song@linux.dev>,
	"Oscar Salvador" <osalvador@suse.de>,
	"David Hildenbrand" <david@kernel.org>,
	"Baolin Wang" <baolin.wang@linux.alibaba.com>,
	"Liam R . Howlett" <liam@infradead.org>,
	"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>,
	"Hugh Dickins" <hughd@google.com>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Michal Hocko" <mhocko@suse.com>, "Jann Horn" <jannh@google.com>,
	"Pedro Falcato" <pfalcato@suse.de>, "Kees Cook" <kees@kernel.org>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>,
	linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org, dri-devel@lists.freedesktop.org,
	etnaviv@lists.freedesktop.org,
	linux-arm-kernel@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org,
	intel-gfx@lists.freedesktop.org, linux-arm-msm@vger.kernel.org,
	freedreno@lists.freedesktop.org, nouveau@lists.freedesktop.org,
	linux-rockchip@lists.infradead.org, linux-tegra@vger.kernel.org,
	virtualization@lists.linux.dev, intel-xe@lists.freedesktop.org,
	xen-devel@lists.xenproject.org, linux-fbdev@vger.kernel.org,
	linux-aio@kvack.org, linux-fsdevel@vger.kernel.org,
	linux-mm@kvack.org, linux-sound@vger.kernel.org
Subject: Re: [PATCH 02/13] mm/vma: update do_mmap() to use vma_flags_t
Date: Tue, 7 Jul 2026 11:15:02 +0100	[thread overview]
Message-ID: <akzRdIS8ZotxIOFR@lucifer> (raw)
In-Reply-To: <DJRZ2QCEIVA6.1AZF5S891NKS4@nvidia.com>

On Mon, Jul 06, 2026 at 10:10:32PM -0400, Zi Yan wrote:
> On Mon Jun 29, 2026 at 3:25 PM EDT, Lorenzo Stoakes wrote:
> > The core do_mmap() function accepts a vm_flags_t parameter which it then
> > manipulates before passing to mmap_region() to do the heavy lifting of the
> > memory mapping.
> >
> > Update do_mmap() to instead accept a vma_flags_t parameter, and adjust all
> > the logic within do_mmap() to manipulate this instead.
> >
> > This is as part of the ongoing effort to convert VMA flags from a system
> > word size to a bitmap type which allows us to unrestrict the number of VMA
> > flags, as well as gain control over how VMA flag manipulation occurs.
> >
> > We do not cascade these changes to all functions which accept vm_flags_t,
> > but rather use vma_flags_to_legacy() where necessary, specifically
> > deferring converting calc_vm_prot_bits(), calc_vm_flag_bits() and
> > __get_unmapped_area() to vma_flags_t.
> >
> > Also utilise the new vma_flags_can_grow() predicate which correctly handles
> > the case of architectures without upward growing stacks.
> >
> > As part of this change, introduce VMA_SHADOW_STACK so we can correctly
> > handle the case of the shadow stack not being defined.
> >
> > No functional change intended.
> >
> > Signed-off-by: Lorenzo Stoakes <ljs@kernel.org>
> > ---
> >  arch/mips/kernel/vdso.c |  4 +--
> >  fs/aio.c                |  2 +-
> >  include/linux/memfd.h   |  6 ++--
> >  include/linux/mm.h      |  6 ++--
> >  ipc/shm.c               |  3 +-
> >  mm/memfd.c              | 15 ++++-----
> >  mm/mmap.c               | 67 ++++++++++++++++++++++++-----------------
> >  mm/nommu.c              |  3 +-
> >  mm/util.c               | 10 +++---
> >  mm/vma.c                |  7 ++---
> >  mm/vma.h                |  2 +-
> >  11 files changed, 69 insertions(+), 56 deletions(-)
> >
>
> <snip>
>
> >
> > -static int check_write_seal(vm_flags_t *vm_flags_ptr)
> > +static int check_write_seal(vma_flags_t *vma_flags_ptr)
> >  {
> > -	vm_flags_t vm_flags = *vm_flags_ptr;
> > -	vm_flags_t mask = vm_flags & (VM_SHARED | VM_WRITE);
> > -
> >  	/* If a private mapping then writability is irrelevant. */
> > -	if (!(mask & VM_SHARED))
> > +	if (!vma_flags_test(vma_flags_ptr, VMA_SHARED_BIT))
> >  		return 0;
> >
> >  	/*
> >  	 * New PROT_WRITE and MAP_SHARED mmaps are not allowed when
> >  	 * write seals are active.
> >  	 */
> > -	if (mask & VM_WRITE)
> > +	if (vma_flags_test(vma_flags_ptr, VMA_WRITE_BIT))
> >  		return -EPERM;
> >
> >  	/*
> >  	 * This is a read-only mapping, disallow mprotect() from making a
> >  	 * write-sealed mapping writable in future.
> >  	 */
> > -	*vm_flags_ptr &= ~VM_MAYWRITE;
> > +	vma_flags_clear(vma_flags_ptr, VMA_MAYWRITE_BIT);
> >
> >  	return 0;
> >  }
>
> This function alone changed its original behavior, since vm_flags is a
> snapshot of *vm_flags_ptr, but after the change this snapshot is gone.
> But its only caller memfd_check_seals_mmap() gets vm_flags_ptr from the
> input parameter of do_mmap(), so the overall behavior does not change.

Right yeah, the snapshot was always just a convenience thing :)

>
> <snip>
>
> > +		case MAP_DROPPABLE: {
> > +			vma_flags_t droppable = VMA_DROPPABLE;
> > +
> > +			if (vma_flags_empty(&droppable))
> >  				return -EOPNOTSUPP;
> > +			vma_flags_set_mask(&vma_flags, droppable);
> > +
> >  			/*
> >  			 * A locked or stack area makes no sense to be droppable.
> >  			 *
> > @@ -515,23 +527,24 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
> >  			 */
> >  			if (flags & (MAP_LOCKED | MAP_HUGETLB))
> >  			        return -EINVAL;
> > -			if (vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
> > +			if (vma_flags_can_grow(&vma_flags))
> >  			        return -EINVAL;
> >
> > -			vm_flags |= VM_DROPPABLE;
> > -
>
> Lance pointed out the reordering of setting VMA_DROPPABLE and checking
> of can_grow, but these flags are not overlapped and there is no parallel
> writer to vma_flags. So it is still no functional change, just not
> mechanical changes. :)

Right yes exactly :)

>
> Otherwise, LGTM.
>
> Reviewed-by: Zi Yan <ziy@nvidia.com>

Thanks!

>
> --
> Best Regards,
> Yan, Zi
>

Cheers, Lorenzo


  reply	other threads:[~2026-07-07 10:15 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29 19:25 [PATCH 00/13] convert more vm_flags_t users to vma_flags_t Lorenzo Stoakes
2026-06-29 19:25 ` [PATCH 01/13] mm: introduce vma_flags_can_grow() and vma_can_grow() Lorenzo Stoakes
2026-06-29 20:26   ` Zi Yan
2026-06-30  7:38     ` Lorenzo Stoakes
2026-06-30 15:09       ` Zi Yan
2026-07-03 15:19   ` Zi Yan
2026-06-29 19:25 ` [PATCH 02/13] mm/vma: update do_mmap() to use vma_flags_t Lorenzo Stoakes
     [not found]   ` <20260702111531.64883-1-lance.yang@linux.dev>
     [not found]     ` <akZwsS-_cywsXSjL@lucifer>
2026-07-02 15:08       ` Lance Yang
2026-07-07  2:10   ` Zi Yan
2026-07-07 10:15     ` Lorenzo Stoakes [this message]
2026-06-29 19:25 ` [PATCH 03/13] mm: convert __get_unmapped_area() " Lorenzo Stoakes
2026-07-07  2:28   ` Zi Yan
2026-07-07 10:16     ` Lorenzo Stoakes
2026-06-29 19:25 ` [PATCH 04/13] mm: update generic_get_unmapped_area[_topdown]() " Lorenzo Stoakes
2026-07-07  2:29   ` Zi Yan
2026-06-29 19:25 ` [PATCH 05/13] mm: prefer mm->def_vma_flags in mm logic Lorenzo Stoakes
     [not found]   ` <20260702121022.49113-1-lance.yang@linux.dev>
2026-07-02 15:24     ` Lorenzo Stoakes
2026-06-29 19:25 ` [PATCH 06/13] mm/vma: convert vm_pgprot_modify() to use vma_flags_t and rename Lorenzo Stoakes
     [not found]   ` <20260702122116.65642-1-lance.yang@linux.dev>
2026-07-02 15:29     ` Lorenzo Stoakes
2026-06-29 19:25 ` [PATCH 07/13] mm/vma: rename vma_get_page_prot to vma_flags_to_page_prot Lorenzo Stoakes
2026-06-29 19:25 ` [PATCH 08/13] mm: introduce vma_get_page_prot() and use it Lorenzo Stoakes
2026-06-30  7:57   ` Thomas Zimmermann
2026-06-30 10:23   ` Jani Nikula
     [not found]   ` <20260702123845.95316-1-lance.yang@linux.dev>
2026-07-02 15:40     ` Lorenzo Stoakes
2026-06-29 19:25 ` [PATCH 09/13] mm/vma: update create_init_stack_vma() to use vma_flags_t Lorenzo Stoakes
2026-06-29 19:25 ` [PATCH 10/13] mm/vma: convert miscellaneous uses of VMA flags in core mm Lorenzo Stoakes
     [not found]   ` <20260702131233.59026-1-lance.yang@linux.dev>
2026-07-02 15:46     ` Lorenzo Stoakes
2026-06-29 19:25 ` [PATCH 11/13] mm/mlock: convert mlock code to use vma_flags_t Lorenzo Stoakes
     [not found]   ` <20260702132107.73727-1-lance.yang@linux.dev>
2026-07-02 15:47     ` Lorenzo Stoakes
2026-06-29 19:25 ` [PATCH 12/13] mm/mprotect: convert mprotect " Lorenzo Stoakes
2026-07-01 16:09   ` Lance Yang
2026-07-02 15:53     ` Lorenzo Stoakes
2026-06-29 19:25 ` [PATCH 13/13] mm/mremap: convert mremap " Lorenzo Stoakes
     [not found]   ` <20260702134947.25189-1-lance.yang@linux.dev>
2026-07-02 16:07     ` Lorenzo Stoakes
2026-07-02 16:17       ` Lance Yang
2026-07-02 16:31         ` Lorenzo Stoakes

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=akzRdIS8ZotxIOFR@lucifer \
    --to=ljs@kernel.org \
    --cc=airlied@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andy.yan@rock-chips.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=bcrl@kvack.org \
    --cc=brauner@kernel.org \
    --cc=dakr@kernel.org \
    --cc=david@kernel.org \
    --cc=deller@gmx.de \
    --cc=dev.jain@arm.com \
    --cc=dmitry.osipenko@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=etnaviv@lists.freedesktop.org \
    --cc=freedreno@lists.freedesktop.org \
    --cc=heiko@sntech.de \
    --cc=hjc@rock-chips.com \
    --cc=hughd@google.com \
    --cc=inki.dae@samsung.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=jannh@google.com \
    --cc=jonathanh@nvidia.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=kees@kernel.org \
    --cc=kraxel@redhat.com \
    --cc=krzk@kernel.org \
    --cc=kyungmin.park@samsung.com \
    --cc=l.stach@pengutronix.de \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-aio@kvack.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=lumag@kernel.org \
    --cc=lyude@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=maddy@linux.ibm.com \
    --cc=matthew.brost@intel.com \
    --cc=mhocko@suse.com \
    --cc=mpe@ellerman.id.au \
    --cc=mperttunen@nvidia.com \
    --cc=mripard@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=nouveau@lists.freedesktop.org \
    --cc=npache@redhat.com \
    --cc=oleksandr_andrushchenko@epam.com \
    --cc=osalvador@suse.de \
    --cc=perex@perex.cz \
    --cc=peter.griffin@linaro.org \
    --cc=pfalcato@suse.de \
    --cc=robin.clark@oss.qualcomm.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=simona@ffwll.ch \
    --cc=surenb@google.com \
    --cc=sw0312.kim@samsung.com \
    --cc=thierry.reding@kernel.org \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tiwai@suse.com \
    --cc=tomi.valkeinen@ideasonboard.com \
    --cc=tsbogend@alpha.franken.de \
    --cc=tursulin@ursulin.net \
    --cc=tzimmermann@suse.de \
    --cc=vbabka@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=virtualization@lists.linux.dev \
    --cc=xen-devel@lists.xenproject.org \
    --cc=zack.rusin@broadcom.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