[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 01/13] mm: introduce vma_flags_can_grow() and vma_can_grow()
- To: "Lorenzo Stoakes" <ljs@xxxxxxxxxx>, "Andrew Morton" <akpm@xxxxxxxxxxxxxxxxxxxx>
- From: "Zi Yan" <ziy@xxxxxxxxxx>
- Date: Mon, 29 Jun 2026 16:26:18 -0400
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UjOcawimHyWmxgix9NetNoPKlptEq1gcNWDAjaT9jQw=; b=ETjNpAbP7ey+4SFFarO0HFFa58CsUMqTPhTZ6MoEu77yNuv4XlJ7z3qHfH3wTBDxqWfKmR1eryM06/wAPJhYsEGSkpOH1e+zrVfLpV7gTfVNHMv2XWr4LoMAzE6xqFlTDtjubMihZQ4daGCdHxAcmjZ6U3ZkRMFN9whuNWqz+kx2MURGE9CXq2XBL08JCwvBzMyfIav1tWO3vSUJdC/R8nHwqSB9Q7xd7DobDUmWZsd+2fGSr41wxtOt00KtskVCttuCm/WLc+ss4CRZqD1t6b/yJQkHchvV77pB42Thcv1Czd3D2i/HEOuOd39PjMIdMgZqFPxRPF0ADL7YZuJEQw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=T/v44OCgZVv8TnwMyFEqZ59yu11oCB/L8D/YmJ45y3NQvoZQNhrxzCH34Xr4RtJnlmGEbegSVMRmMjurJ9k44Z0/gng+ZdY6mFprMUoGrSiOIiBPpTCnIzNz7C4PAKic1QMjjhB3wrZhwhZWvYn8GEMWsnjwJCqvDm0xSVemHrfuoO+LWQ3P6OJXsI6Q7WguJ8UxcHY5cf3FpmmnpBsQWjSzqxFD3CQYu4gMk9u6t6uC1DIwIwB1teUbMbQf4Q8hZmMYkUC7uOHG7VX2amk9Ekjy/AEO+CuR8vv6qVeoSSMBMi4p0J6sHcCEnLZckLWf+ZiWQ2cdDcfH3MKASIkBKg==
- Authentication-results: eu.smtp.expurgate.cloud; dkim=temperror header.s=selector2 header.d=Nvidia.com header.i="@Nvidia.com"
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com;
- Cc: "Thomas Bogendoerfer" <tsbogend@xxxxxxxxxxxxxxxx>, "Madhavan Srinivasan" <maddy@xxxxxxxxxxxxx>, "Michael Ellerman" <mpe@xxxxxxxxxxxxxx>, "Maarten Lankhorst" <maarten.lankhorst@xxxxxxxxxxxxxxx>, "Maxime Ripard" <mripard@xxxxxxxxxx>, "Thomas Zimmermann" <tzimmermann@xxxxxxx>, "David Airlie" <airlied@xxxxxxxxx>, "Simona Vetter" <simona@xxxxxxxx>, "Lucas Stach" <l.stach@xxxxxxxxxxxxxx>, "Inki Dae" <inki.dae@xxxxxxxxxxx>, "Seung-Woo Kim" <sw0312.kim@xxxxxxxxxxx>, "Kyungmin Park" <kyungmin.park@xxxxxxxxxxx>, "Krzysztof Kozlowski" <krzk@xxxxxxxxxx>, "Peter Griffin" <peter.griffin@xxxxxxxxxx>, "Jani Nikula" <jani.nikula@xxxxxxxxxxxxxxx>, "Joonas Lahtinen" <joonas.lahtinen@xxxxxxxxxxxxxxx>, "Rodrigo Vivi" <rodrigo.vivi@xxxxxxxxx>, "Tvrtko Ursulin" <tursulin@xxxxxxxxxxx>, "Rob Clark" <robin.clark@xxxxxxxxxxxxxxxx>, "Dmitry Baryshkov" <lumag@xxxxxxxxxx>, "Lyude Paul" <lyude@xxxxxxxxxx>, "Danilo Krummrich" <dakr@xxxxxxxxxx>, "Tomi Valkeinen" <tomi.valkeinen@xxxxxxxxxxxxxxxx>, "Sandy Huang" <hjc@xxxxxxxxxxxxxx>, Heiko Stübner <heiko@xxxxxxxxx>, "Andy Yan" <andy.yan@xxxxxxxxxxxxxx>, "Thierry Reding" <thierry.reding@xxxxxxxxxx>, "Mikko Perttunen" <mperttunen@xxxxxxxxxx>, "Jonathan Hunter" <jonathanh@xxxxxxxxxx>, "Gerd Hoffmann" <kraxel@xxxxxxxxxx>, "Dmitry Osipenko" <dmitry.osipenko@xxxxxxxxxxxxx>, "Zack Rusin" <zack.rusin@xxxxxxxxxxxx>, "Matthew Brost" <matthew.brost@xxxxxxxxx>, "Thomas Hellstrom" <thomas.hellstrom@xxxxxxxxxxxxxxx>, "Oleksandr Andrushchenko" <oleksandr_andrushchenko@xxxxxxxx>, "Helge Deller" <deller@xxxxxx>, "Benjamin LaHaise" <bcrl@xxxxxxxxx>, "Alexander Viro" <viro@xxxxxxxxxxxxxxxxxx>, "Christian Brauner" <brauner@xxxxxxxxxx>, "Muchun Song" <muchun.song@xxxxxxxxx>, "Oscar Salvador" <osalvador@xxxxxxx>, "David Hildenbrand" <david@xxxxxxxxxx>, "Baolin Wang" <baolin.wang@xxxxxxxxxxxxxxxxx>, "Liam R . Howlett" <liam@xxxxxxxxxxxxx>, "Nico Pache" <npache@xxxxxxxxxx>, "Ryan Roberts" <ryan.roberts@xxxxxxx>, "Dev Jain" <dev.jain@xxxxxxx>, "Barry Song" <baohua@xxxxxxxxxx>, "Lance Yang" <lance.yang@xxxxxxxxx>, "Hugh Dickins" <hughd@xxxxxxxxxx>, "Vlastimil Babka" <vbabka@xxxxxxxxxx>, "Mike Rapoport" <rppt@xxxxxxxxxx>, "Suren Baghdasaryan" <surenb@xxxxxxxxxx>, "Michal Hocko" <mhocko@xxxxxxxx>, "Jann Horn" <jannh@xxxxxxxxxx>, "Pedro Falcato" <pfalcato@xxxxxxx>, "Kees Cook" <kees@xxxxxxxxxx>, "Jaroslav Kysela" <perex@xxxxxxxx>, "Takashi Iwai" <tiwai@xxxxxxxx>, <linux-mips@xxxxxxxxxxxxxxx>, <linux-kernel@xxxxxxxxxxxxxxx>, <linuxppc-dev@xxxxxxxxxxxxxxxx>, <dri-devel@xxxxxxxxxxxxxxxxxxxxx>, <etnaviv@xxxxxxxxxxxxxxxxxxxxx>, <linux-arm-kernel@xxxxxxxxxxxxxxxxxxx>, <linux-samsung-soc@xxxxxxxxxxxxxxx>, <intel-gfx@xxxxxxxxxxxxxxxxxxxxx>, <linux-arm-msm@xxxxxxxxxxxxxxx>, <freedreno@xxxxxxxxxxxxxxxxxxxxx>, <nouveau@xxxxxxxxxxxxxxxxxxxxx>, <linux-rockchip@xxxxxxxxxxxxxxxxxxx>, <linux-tegra@xxxxxxxxxxxxxxx>, <virtualization@xxxxxxxxxxxxxxx>, <intel-xe@xxxxxxxxxxxxxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>, <linux-fbdev@xxxxxxxxxxxxxxx>, <linux-aio@xxxxxxxxx>, <linux-fsdevel@xxxxxxxxxxxxxxx>, <linux-mm@xxxxxxxxx>, <linux-sound@xxxxxxxxxxxxxxx>
- Delivery-date: Mon, 29 Jun 2026 20:26:52 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On Mon Jun 29, 2026 at 3:25 PM EDT, Lorenzo Stoakes wrote:
> These test whether the VMA has stack sematics, i.e. is able to grow upwards
> or downwards depending on the architecture.
>
> In order to account for arches which do not support upward-growing stacks,
> introduce VMA_GROWSUP whose definition depends on the architecture
> supporting it, and use vma_flags_test_single_mask() in vma_flags_can_grow()
> to account for this.
>
> Update the VMA userland tests to reflect the changes
>
> No functional change intended.
>
> Signed-off-by: Lorenzo Stoakes <ljs@xxxxxxxxxx>
> ---
> include/linux/mm.h | 21 ++++++++++++++++++---
> tools/testing/vma/include/dup.h | 4 ++++
> 2 files changed, 22 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 868b2334bff3..cf7df1569052 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -472,6 +472,7 @@ enum {
> #define VM_SAO INIT_VM_FLAG(SAO)
> #elif defined(CONFIG_PARISC)
> #define VM_GROWSUP INIT_VM_FLAG(GROWSUP)
> +#define VMA_GROWSUP mk_vma_flags(VMA_GROWSUP_BIT)
> #elif defined(CONFIG_SPARC64)
> #define VM_SPARC_ADI INIT_VM_FLAG(SPARC_ADI)
> #define VM_ARCH_CLEAR INIT_VM_FLAG(ARCH_CLEAR)
> @@ -483,6 +484,7 @@ enum {
> #endif
> #ifndef VM_GROWSUP
> #define VM_GROWSUP VM_NONE
> +#define VMA_GROWSUP EMPTY_VMA_FLAGS
> #endif
> #ifdef CONFIG_ARM64_MTE
> #define VM_MTE INIT_VM_FLAG(MTE)
> @@ -1563,11 +1565,24 @@ static inline bool vma_is_initial_stack(const struct
> vm_area_struct *vma)
> vma->vm_end >= vma->vm_mm->start_stack;
> }
>
> -static inline bool vma_is_temporary_stack(const struct vm_area_struct *vma)
> +static inline bool vma_flags_can_grow(const vma_flags_t *flags)
> {
> - int maybe_stack = vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP);
> + if (vma_flags_test_single_mask(flags, VMA_GROWSUP))
> + return true;
> + if (vma_flags_test(flags, VMA_GROWSDOWN_BIT))
> + return true;
> +
> + return false;
> +}
>
> - if (!maybe_stack)
> +static inline bool vma_can_grow(const struct vm_area_struct *vma)
> +{
> + return vma_flags_can_grow(&vma->flags);
Would it save vma_flags_can_grow() if we do below?
return vma_test(vma, VMA_GROWSDOWN_BIT) || vma_test_single_mask(vma,
VMA_GROWSUP);
I find these two functions when I am reading mm.h.
> +}
> +
> +static inline bool vma_is_temporary_stack(const struct vm_area_struct *vma)
> +{
> + if (!vma_can_grow(vma))
> return false;
>
> if ((vma->vm_flags & VM_STACK_INCOMPLETE_SETUP) ==
> diff --git a/tools/testing/vma/include/dup.h b/tools/testing/vma/include/dup.h
> index 5d7d0afd7765..6f5bcd7fbcd8 100644
> --- a/tools/testing/vma/include/dup.h
> +++ b/tools/testing/vma/include/dup.h
> @@ -245,8 +245,10 @@ enum {
> #define VM_STACK INIT_VM_FLAG(STACK)
> #ifdef CONFIG_STACK_GROWS_UP
> #define VM_STACK_EARLY INIT_VM_FLAG(STACK_EARLY)
> +#define VMA_STACK_EARLY mk_vma_flags(VMA_STACK_EARLY_BIT)
> #else
> #define VM_STACK_EARLY VM_NONE
> +#define VMA_STACK_EARLY EMPTY_VMA_FLAGS
> #endif
> #ifdef CONFIG_ARCH_HAS_PKEYS
> #define VM_PKEY_SHIFT ((__force int)VMA_HIGH_ARCH_0_BIT)
> @@ -315,6 +317,8 @@ enum {
>
> /* Bits set in the VMA until the stack is in its final location */
> #define VM_STACK_INCOMPLETE_SETUP (VM_RAND_READ | VM_SEQ_READ |
> VM_STACK_EARLY)
> +#define VMA_STACK_INCOMPLETE_SETUP append_vma_flags( \
> + VMA_STACK_EARLY, VMA_RAND_READ_BIT, VMA_SEQ_READ_BIT)
>
> #define TASK_EXEC_BIT ((current->personality & READ_IMPLIES_EXEC) ? \
> VM_EXEC_BIT : VM_READ_BIT)
Why are VMA_STACK_EARLY and VMA_STACK_INCOMPLETE_SETUP added here but
not in mm.h?
--
Best Regards,
Yan, Zi
|