On 6/10/2022 4:35 PM, ira.weiny@intel.com wrote:
+void test_pkey_alloc_on_unsupported_cpu(void) +{
- int test_pkey = sys_pkey_alloc(0, 0);
- dprintf1("pkey_alloc: %d (%d %s)\n", test_pkey, errno,
strerror(errno));
- pkey_assert(test_pkey < 0);
- pkey_assert(errno == ENOSPC);
This assert fails on a kernel with CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS disabled.
Since pkey_alloc() is an architecture dependent syscall, ENOSYS is returned instead of ENOSPC when support is disabled at compile time. See kernel/sys_ni.c
This brings us to an interesting question.
Should we have different return error codes when compile support is disabled vs when runtime support is missing?
Here is the current behavior for pkey_alloc():
No compile time support -> return ENOSYS No runtime support (but compile time support present) -> return ENOSPC
I would think applications would prefer the same error code. But, I am not sure if we can achieve this now due to ABI reasons.
+}