[PATCH v2] selftests/mm: remove the local PKEY_UNRESTRICTED fallback

Hemanth Selam posted 1 patch 1 month, 1 week ago
There is a newer version of this series
tools/testing/selftests/mm/pkey-helpers.h | 7 -------
1 file changed, 7 deletions(-)
[PATCH v2] selftests/mm: remove the local PKEY_UNRESTRICTED fallback
Posted by Hemanth Selam 1 month, 1 week ago
pkey-helpers.h defines PKEY_UNRESTRICTED itself when the macro is not
already known, a stopgap from when the generic definition was still
under review.  It has been merged since, commit 6d61527d931b ("mm/pkey:
Add PKEY_UNRESTRICTED macro"), so the guard is never taken and the FIXME
can be honoured.

The definition comes from tools/include/uapi/asm-generic/mman-common.h
via TOOLS_INCLUDES, which commit e076eaca5906 ("selftests: break the
dependency upon local header files") added so that the mm selftests
build without "make headers".  It is reached through the
<asm-generic/mman.h> that the system <asm/mman.h> includes.  Building
the pkey tests with KHDR_INCLUDES pointing at an empty directory
confirms that; emptying TOOLS_INCLUDES as well is what makes the macro
go missing.

No functional change intended.

Signed-off-by: Hemanth Selam <hemanth.selam@gmail.com>
---
Changes in v2:
 - Drop the incorrect claim that the mm selftests are built against the
   headers of the kernel source and would fail without "make headers".
   They are not, as Lorenzo pointed out; describe where the definition
   really comes from instead.
 - Leave tools/testing/selftests/powerpc/include/pkeys.h alone, as
   discussed with David on v1.  Unlike the mm one it is an unconditional
   #undef/#define next to other powerpc specific overrides, and that
   header only includes <sys/mman.h>, which does not provide
   PKEY_UNRESTRICTED with or without TOOLS_INCLUDES, so its definition
   is load bearing.

The full include path, for reference:

  pkey-helpers.h
    -> <linux/mman.h>           tools/include/uapi/linux/mman.h
      -> <asm/mman.h>           /usr/include/asm/mman.h
                                (tools/include/uapi/asm/mman.h does not exist)
        -> <asm-generic/mman.h> tools/include/uapi/asm-generic/mman.h
          -> <asm-generic/mman-common-tools.h>
            -> <asm-generic/mman-common.h>      PKEY_UNRESTRICTED

With KHDR_INCLUDES pointing at an empty directory the tests still build,
and cpp -dD reports the macro coming from
tools/include/uapi/asm-generic/mman-common.h.  Emptying TOOLS_INCLUDES
as well gives:

  pkey-helpers.h:188:30: error: 'PKEY_UNRESTRICTED' undeclared

pkey_sighandler_tests and mseal_test are byte identical before and
after; protection_keys differs only in the __LINE__ values that
pkey-helpers.h embeds into its debug output.

v1: https://lore.kernel.org/all/20260818114945.1312987-1-hemanth.selam@gmail.com/
 tools/testing/selftests/mm/pkey-helpers.h | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/tools/testing/selftests/mm/pkey-helpers.h b/tools/testing/selftests/mm/pkey-helpers.h
index 2c377f4e9df1..626c2e1655dc 100644
--- a/tools/testing/selftests/mm/pkey-helpers.h
+++ b/tools/testing/selftests/mm/pkey-helpers.h
@@ -112,13 +112,6 @@ void record_pkey_malloc(void *ptr, long size, int prot);
 #define PKEY_MASK	(PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE)
 #endif
 
-/*
- * FIXME: Remove once the generic PKEY_UNRESTRICTED definition is merged.
- */
-#ifndef PKEY_UNRESTRICTED
-#define PKEY_UNRESTRICTED 0x0
-#endif
-
 #ifndef set_pkey_bits
 static inline u64 set_pkey_bits(u64 reg, int pkey, u64 flags)
 {
-- 
2.43.7
Re: [PATCH v2] selftests/mm: remove the local PKEY_UNRESTRICTED fallback
Posted by David Hildenbrand (Arm) 1 month, 1 week ago
On 8/19/26 09:47, Hemanth Selam wrote:
> pkey-helpers.h defines PKEY_UNRESTRICTED itself when the macro is not
> already known, a stopgap from when the generic definition was still
> under review.  It has been merged since, commit 6d61527d931b ("mm/pkey:
> Add PKEY_UNRESTRICTED macro"), so the guard is never taken and the FIXME
> can be honoured.
> 
> The definition comes from tools/include/uapi/asm-generic/mman-common.h
> via TOOLS_INCLUDES, which commit e076eaca5906 ("selftests: break the
> dependency upon local header files") added so that the mm selftests
> build without "make headers".  It is reached through the
> <asm-generic/mman.h> that the system <asm/mman.h> includes.  Building
> the pkey tests with KHDR_INCLUDES pointing at an empty directory
> confirms that; emptying TOOLS_INCLUDES as well is what makes the macro
> go missing.
> 
> No functional change intended.
> 
> Signed-off-by: Hemanth Selam <hemanth.selam@gmail.com>

Hi,

please prefer not sending new revisions in reply to old revisions the next time.

[...]

>  tools/testing/selftests/mm/pkey-helpers.h | 7 -------
>  1 file changed, 7 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/pkey-helpers.h b/tools/testing/selftests/mm/pkey-helpers.h
> index 2c377f4e9df1..626c2e1655dc 100644
> --- a/tools/testing/selftests/mm/pkey-helpers.h
> +++ b/tools/testing/selftests/mm/pkey-helpers.h
> @@ -112,13 +112,6 @@ void record_pkey_malloc(void *ptr, long size, int prot);
>  #define PKEY_MASK	(PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE)
>  #endif
>  
> -/*
> - * FIXME: Remove once the generic PKEY_UNRESTRICTED definition is merged.
> - */
> -#ifndef PKEY_UNRESTRICTED
> -#define PKEY_UNRESTRICTED 0x0
> -#endif
> -
>  #ifndef set_pkey_bits
>  static inline u64 set_pkey_bits(u64 reg, int pkey, u64 flags)
>  {

Hoping this indeed compiles ;)

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David
Re: [PATCH v2] selftests/mm: remove the local PKEY_UNRESTRICTED fallback
Posted by Lorenzo Stoakes (ARM) 1 month ago
On Wed, Aug 19, 2026 at 04:15:04PM +0200, David Hildenbrand (Arm) wrote:
> On 8/19/26 09:47, Hemanth Selam wrote:
> > pkey-helpers.h defines PKEY_UNRESTRICTED itself when the macro is not
> > already known, a stopgap from when the generic definition was still
> > under review.  It has been merged since, commit 6d61527d931b ("mm/pkey:
> > Add PKEY_UNRESTRICTED macro"), so the guard is never taken and the FIXME
> > can be honoured.
> >
> > The definition comes from tools/include/uapi/asm-generic/mman-common.h
> > via TOOLS_INCLUDES, which commit e076eaca5906 ("selftests: break the
> > dependency upon local header files") added so that the mm selftests
> > build without "make headers".  It is reached through the
> > <asm-generic/mman.h> that the system <asm/mman.h> includes.  Building
> > the pkey tests with KHDR_INCLUDES pointing at an empty directory
> > confirms that; emptying TOOLS_INCLUDES as well is what makes the macro
> > go missing.
> >
> > No functional change intended.
> >
> > Signed-off-by: Hemanth Selam <hemanth.selam@gmail.com>

Since you said load-bearing in the last email - I do have to ask if AI was
involved with this.

If so please adhere to kernel guidelines:

https://docs.kernel.org/process/coding-assistants.html
https://docs.kernel.org/process/generated-content.html

I.e. add an Assisted-by tag.

Anyway given your explanation in the other sub-thread seems ok so:

Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>

>
> Hi,
>
> please prefer not sending new revisions in reply to old revisions the next time.

Yup. Please send respins as an entirely separate main not in-reply to
anything, thanks!

Also add a revision history under the --- with links to prior revisions,
and if >1 patch send a cover letter that has the revisions and all patch
emails are in-reply-to.

>
> [...]
>
> >  tools/testing/selftests/mm/pkey-helpers.h | 7 -------
> >  1 file changed, 7 deletions(-)
> >
> > diff --git a/tools/testing/selftests/mm/pkey-helpers.h b/tools/testing/selftests/mm/pkey-helpers.h
> > index 2c377f4e9df1..626c2e1655dc 100644
> > --- a/tools/testing/selftests/mm/pkey-helpers.h
> > +++ b/tools/testing/selftests/mm/pkey-helpers.h
> > @@ -112,13 +112,6 @@ void record_pkey_malloc(void *ptr, long size, int prot);
> >  #define PKEY_MASK	(PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE)
> >  #endif
> >
> > -/*
> > - * FIXME: Remove once the generic PKEY_UNRESTRICTED definition is merged.
> > - */
> > -#ifndef PKEY_UNRESTRICTED
> > -#define PKEY_UNRESTRICTED 0x0
> > -#endif
> > -
> >  #ifndef set_pkey_bits
> >  static inline u64 set_pkey_bits(u64 reg, int pkey, u64 flags)
> >  {
>
> Hoping this indeed compiles ;)
>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
>
> --
> Cheers,
>
> David

--
Cheers, Lorenzo
Re: [PATCH v2] selftests/mm: remove the local PKEY_UNRESTRICTED fallback
Posted by Hemanth Selam 1 month ago
On Tue, Aug 25, 2026 at 03:36:36PM +0100, Lorenzo Stoakes (ARM) wrote:
> Since you said load-bearing in the last email - I do have to ask if AI was
> involved with this.
>
> If so please adhere to kernel guidelines:
>
> https://docs.kernel.org/process/coding-assistants.html
> https://docs.kernel.org/process/generated-content.html
>
> I.e. add an Assisted-by tag.

Yes, it was.  I used an AI assistant while tracing the include path and
preparing the patch.  The builds and the cpp output I quoted are ones I ran
and checked myself, and the Signed-off-by is mine, but I should have tagged
the assistance from the start.  Sorry for that, and thanks for asking
directly.

The respin will carry

	Assisted-by: Cursor:claude-opus-5

I will send it as a new mail rather than in reply to this thread, as you
and David asked.

Thanks for the Acked-by.

Hemanth