Skip to contentSkip to conversation

selftests/proc: proc-empty-vm: handle CPUs without protection keys

PATCH Superseded Kurt Lin 3 participants 4 messages Nov 9 – Nov 18

Subsystems (3)
lore
Share & tools
lore

Kurt Lin

author
#0 lore raw

PATCH 1/1 selftests/proc: proc-empty-vm: handle CPUs without protection keys

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")
---
 tools/testing/selftests/proc/proc-empty-vm.c | 3 +++
 1 file changed, 3 insertions(+)
tools/testing/selftests/proc/proc-empty-vm.c +3 -0
index b3f898aab4ab..a9d3c973a663 100644
@@ -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);
Signature · 1 line
2.56.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · 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:

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:

Quoted 28 lines

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")
---
 tools/testing/selftests/proc/proc-empty-vm.c | 3 +++
 1 file changed, 3 insertions(+)
tools/testing/selftests/proc/proc-empty-vm.c +3 -0
index b3f898aab4ab..a9d3c973a663 100644
@@ -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);
author
#2 lore raw

PATCH v2 1/1 selftests/proc: proc-empty-vm: handle CPUs without protection keys

In reply to 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")

---
v2:
- Mention commit dee87e09b0dd, which made the failure visible (Kevin)
- Add Reviewed-by from Kevin

v1: https://lore.kernel.org/linux-kselftest/[email protected]/

 tools/testing/selftests/proc/proc-empty-vm.c | 3 +++
 1 file changed, 3 insertions(+)
tools/testing/selftests/proc/proc-empty-vm.c +3 -0
index b3f898aab4ab..a9d3c973a663 100644
@@ -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);
Signature · 1 line
2.56.0
maintainer Applied
#3 lore raw
Quoted 8 lines · 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

[...]

Applied to the vfs-7.5.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.5.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.5.misc

[1/1] selftests/proc: proc-empty-vm: handle CPUs without protection keys

      https://git.kernel.org/vfs/vfs/c/21cd133d5875