mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests/proc: proc-empty-vm: handle CPUs without protection keys
@ 2026-11-09 15:19 Kurt Lin
  2026-11-13 13:10 ` Kevin Brodsky
  2026-11-13 15:44 ` [PATCH v2] " Kurt Lin
  0 siblings, 2 replies; 3+ messages in thread
From: Kurt Lin @ 2026-11-09 15:19 UTC (permalink / raw)
  To: Andrew Morton, Shuah Khan
  Cc: Alexey Dobriyan, Swarup Laxman Kotiaklapudi, linux-kselftest,
	linux-fsdevel, linux-kernel, Kurt Lin

On x86 CPUs without protection keys, pkey_alloc() fails with ENOSPC,
as documented in pkey_alloc(2). protection_key_support() only expects
ENOSYS or EINVAL, so the test fails on such machines, e.g. an Intel
Core i5-7200U:

  protection_key_support: error: rv -1, errno 28

Treat ENOSPC as "no protection key support" as well.

An AI coding assistant (Claude) was used to analyze the failure and to
draft the fix and this changelog. Tested on v7.4-rc1 on the machine
above; the test now passes.

Fixes: bf5add391eeb ("proc: test ProtectionKey in proc-empty-vm test")
Signed-off-by: Kurt Lin <lylin1023@gmail.com>
---
 tools/testing/selftests/proc/proc-empty-vm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/testing/selftests/proc/proc-empty-vm.c b/tools/testing/selftests/proc/proc-empty-vm.c
index b3f898aab4ab..a9d3c973a663 100644
--- a/tools/testing/selftests/proc/proc-empty-vm.c
+++ b/tools/testing/selftests/proc/proc-empty-vm.c
@@ -77,6 +77,9 @@ static int protection_key_support(void)
 	} else if (rv == -1 && errno == EINVAL) {
 		// ospke=n
 		return 0;
+	} else if (rv == -1 && errno == ENOSPC) {
+		// CPU without protection keys
+		return 0;
 	} else {
 		fprintf(stderr, "%s: error: rv %ld, errno %d\n", __func__, rv, errno);
 		exit(EXIT_FAILURE);
-- 
2.56.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/proc: proc-empty-vm: handle CPUs without protection keys
  2026-11-09 15:19 [PATCH] selftests/proc: proc-empty-vm: handle CPUs without protection keys Kurt Lin
@ 2026-11-13 13:10 ` Kevin Brodsky
  2026-11-13 15:44 ` [PATCH v2] " Kurt Lin
  1 sibling, 0 replies; 3+ messages in thread
From: Kevin Brodsky @ 2026-11-13 13:10 UTC (permalink / raw)
  To: Kurt Lin, Andrew Morton, Shuah Khan
  Cc: Alexey Dobriyan, Swarup Laxman Kotiaklapudi, linux-kselftest,
	linux-fsdevel, linux-kernel

On 09/11/2026 16:19, Kurt Lin wrote:
> On x86 CPUs without protection keys, pkey_alloc() fails with ENOSPC,
> as documented in pkey_alloc(2). protection_key_support() only expects
> ENOSYS or EINVAL, so the test fails on such machines, e.g. an Intel
> Core i5-7200U:

It would be good to mention that the x86 implementation had a bug where
the first call to pkey_alloc() would return -EINVAL instead of -ENOSPC.
This was recently fixed by commit dee87e09b0dd ("x86/pkeys: Fix
pkey_alloc() return value when pkeys are not supported"); that's
probably why the issue appeared only now.

-EINVAL is technically not an expected error in this situation, but for
backwards-compatibility with older kernels it probably makes sense to
allow it for a little while.

With the commit message expanded:

Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com>

>   protection_key_support: error: rv -1, errno 28
>
> Treat ENOSPC as "no protection key support" as well.
>
> An AI coding assistant (Claude) was used to analyze the failure and to
> draft the fix and this changelog. Tested on v7.4-rc1 on the machine
> above; the test now passes.
>
> Fixes: bf5add391eeb ("proc: test ProtectionKey in proc-empty-vm test")
> Signed-off-by: Kurt Lin <lylin1023@gmail.com>
> ---
>  tools/testing/selftests/proc/proc-empty-vm.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/tools/testing/selftests/proc/proc-empty-vm.c b/tools/testing/selftests/proc/proc-empty-vm.c
> index b3f898aab4ab..a9d3c973a663 100644
> --- a/tools/testing/selftests/proc/proc-empty-vm.c
> +++ b/tools/testing/selftests/proc/proc-empty-vm.c
> @@ -77,6 +77,9 @@ static int protection_key_support(void)
>  	} else if (rv == -1 && errno == EINVAL) {
>  		// ospke=n
>  		return 0;
> +	} else if (rv == -1 && errno == ENOSPC) {
> +		// CPU without protection keys
> +		return 0;
>  	} else {
>  		fprintf(stderr, "%s: error: rv %ld, errno %d\n", __func__, rv, errno);
>  		exit(EXIT_FAILURE);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] selftests/proc: proc-empty-vm: handle CPUs without protection keys
  2026-11-09 15:19 [PATCH] selftests/proc: proc-empty-vm: handle CPUs without protection keys Kurt Lin
  2026-11-13 13:10 ` Kevin Brodsky
@ 2026-11-13 15:44 ` Kurt Lin
  1 sibling, 0 replies; 3+ messages in thread
From: Kurt Lin @ 2026-11-13 15:44 UTC (permalink / raw)
  To: Andrew Morton, Shuah Khan
  Cc: Kevin Brodsky, Alexey Dobriyan, Swarup Laxman Kotiaklapudi,
	linux-kselftest, linux-fsdevel, linux-kernel, Kurt Lin

On x86 CPUs without protection keys, pkey_alloc() fails with ENOSPC,
as documented in pkey_alloc(2). protection_key_support() only expects
ENOSYS or EINVAL, so the test fails on such machines, e.g. an Intel
Core i5-7200U:

  protection_key_support: error: rv -1, errno 28

Before commit dee87e09b0dd ("x86/pkeys: Fix pkey_alloc() return value
when pkeys are not supported"), the first pkey_alloc() call on such
CPUs wrongly returned EINVAL, so the failure only shows up on kernels
with that fix.

Treat ENOSPC as "no protection key support" as well. Keep accepting
EINVAL for kernels before v7.3.

An AI coding assistant (Claude) was used to analyze the failure and to
draft the fix and this changelog. Tested on v7.4-rc1 on the machine
above; the test now passes.

Fixes: bf5add391eeb ("proc: test ProtectionKey in proc-empty-vm test")
Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com>
Signed-off-by: Kurt Lin <lylin1023@gmail.com>
---
v2:
- Mention commit dee87e09b0dd, which made the failure visible (Kevin)
- Add Reviewed-by from Kevin

v1: https://lore.kernel.org/linux-kselftest/20261109151912.156518-1-lylin1023@gmail.com/

 tools/testing/selftests/proc/proc-empty-vm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/testing/selftests/proc/proc-empty-vm.c b/tools/testing/selftests/proc/proc-empty-vm.c
index b3f898aab4ab..a9d3c973a663 100644
--- a/tools/testing/selftests/proc/proc-empty-vm.c
+++ b/tools/testing/selftests/proc/proc-empty-vm.c
@@ -77,6 +77,9 @@ static int protection_key_support(void)
 	} else if (rv == -1 && errno == EINVAL) {
 		// ospke=n
 		return 0;
+	} else if (rv == -1 && errno == ENOSPC) {
+		// CPU without protection keys
+		return 0;
 	} else {
 		fprintf(stderr, "%s: error: rv %ld, errno %d\n", __func__, rv, errno);
 		exit(EXIT_FAILURE);
-- 
2.56.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-13 15:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 15:19 [PATCH] selftests/proc: proc-empty-vm: handle CPUs without protection keys Kurt Lin
2026-11-13 13:10 ` Kevin Brodsky
2026-11-13 15:44 ` [PATCH v2] " Kurt Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®