From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C309C3DDDBB; Tue, 30 Jun 2026 07:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782805159; cv=none; b=CwC6rpGfSwVswnEfzptLP/rGkR4PbE5aENsd/warvrH3LN5Omy0wJk19IQyni5GumdNVOYJ/8Wpwp7A3EiWefMXmAUvu+EZ3eqFyXKr+kV7TzEvteBnBOSBV+UapkKwGDKStP1ZmB0JpvaYVrX7EqwD1DmP3wfBsVwfvM+jY/ZQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782805159; c=relaxed/simple; bh=lvjAdPL/53pFYItQkwcVoVpd0+EC0h2230TPbhE1lZQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HmSpzoSYxrc4H5ztsmq6lCNMe1UnwxMnCR6alLswoUBlxALPDtcz9XI4vOhxpZZI+6+wzjuvcin7O/PEafze9SLaaJMMufggJK3GI+Tk2WUKOpUDSa0gNDa/G9QkNqlN1ict13FNuALj8TYZM44J5QoNM0tpvdCM1tK3gNL5rGY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fDaf4ZqW; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fDaf4ZqW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8F3C1F00A3D; Tue, 30 Jun 2026 07:38:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782805156; bh=QFTirDmiRXM2E2UxDPivyHpH5WU8vmAPSC3LpjlrT8o=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=fDaf4ZqW3PD9fY8acsrJCsXc7pOEzc4lLsW2jgJhfYGl7NXG5KcVo4Pxek2Uz+Nla tOcu2NuZHwmic0JpBPUEEgMmuaTGNKExmRCbT0ES7+8QhHL9YqeimbRUf62O0HtMfs LYny1udM2eWLdF0sRgHD+bBsvogcyV+srg+CrLasOfuUZDDcJr8dZlygrFZBfDoggP p2mllhEamdnPs77YGrH3WGaXXIkqv4Xgyt7g+R7YVqHEf/NFyfi55aJUF3SRsQX/b0 NUbVhpaMaUvlKWWtDdlDlkLmrVKracrOVgHvCwNbE5g49j/+vG6Xvy5Wxh+acQ6BjY MYjz8K0OvlQ3A== Date: Tue, 30 Jun 2026 08:38:51 +0100 From: Lorenzo Stoakes To: Zi Yan Cc: Andrew Morton , Thomas Bogendoerfer , Madhavan Srinivasan , Michael Ellerman , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Lucas Stach , Inki Dae , Seung-Woo Kim , Kyungmin Park , Krzysztof Kozlowski , Peter Griffin , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Rob Clark , Dmitry Baryshkov , Lyude Paul , Danilo Krummrich , Tomi Valkeinen , Sandy Huang , Heiko =?utf-8?Q?St=C3=BCbner?= , Andy Yan , Thierry Reding , Mikko Perttunen , Jonathan Hunter , Gerd Hoffmann , Dmitry Osipenko , Zack Rusin , Matthew Brost , Thomas Hellstrom , Oleksandr Andrushchenko , Helge Deller , Benjamin LaHaise , Alexander Viro , Christian Brauner , Muchun Song , Oscar Salvador , David Hildenbrand , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Hugh Dickins , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jann Horn , Pedro Falcato , Kees Cook , Jaroslav Kysela , Takashi Iwai , 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 01/13] mm: introduce vma_flags_can_grow() and vma_can_grow() Message-ID: References: Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Jun 29, 2026 at 04:26:18PM -0400, Zi Yan wrote: > 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 > > --- > > 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. Yeah but we require vma_flags_can_grow() for code in mmap.c, the majority of checks of this have only vma_flags_t to work with not a VMA :) > > > +} > > + > > +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? Yeah urgh oops my bad. It doesn't really break anything but I'll fix it if a respin is needed... > > > -- > Best Regards, > Yan, Zi > Thanks, Lorenzo