This commit adds a few new tests to exercise the signal handler flow,
especially with pkey 0 disabled.
Signed-off-by: Keith Lucas <keith.lucas@oracle.com>
Signed-off-by: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>
---
tools/testing/selftests/mm/Makefile | 2 +
tools/testing/selftests/mm/pkey-helpers.h | 11 +-
.../selftests/mm/pkey_sighandler_tests.c | 315 ++++++++++++++++++
tools/testing/selftests/mm/protection_keys.c | 10 -
4 files changed, 327 insertions(+), 11 deletions(-)
create mode 100644 tools/testing/selftests/mm/pkey_sighandler_tests.c
diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile
index eb5f39a2668b..2f90344ad11e 100644
--- a/tools/testing/selftests/mm/Makefile
+++ b/tools/testing/selftests/mm/Makefile
@@ -82,6 +82,7 @@ CAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_64bit_pr
CAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_program.c -no-pie)
VMTARGETS := protection_keys
+VMTARGETS := pkey_sighandler_tests
BINARIES_32 := $(VMTARGETS:%=%_32)
BINARIES_64 := $(VMTARGETS:%=%_64)
@@ -100,6 +101,7 @@ else
ifneq (,$(findstring $(ARCH),ppc64))
TEST_GEN_FILES += protection_keys
+TEST_GEN_FILES += pkey_sighandler_tests
endif
endif
diff --git a/tools/testing/selftests/mm/pkey-helpers.h b/tools/testing/selftests/mm/pkey-helpers.h
index 1af3156a9db8..a0766e3d9ab6 100644
--- a/tools/testing/selftests/mm/pkey-helpers.h
+++ b/tools/testing/selftests/mm/pkey-helpers.h
@@ -79,7 +79,16 @@ extern void abort_hooks(void);
} \
} while (0)
-__attribute__((noinline)) int read_ptr(int *ptr);
+#define barrier() __asm__ __volatile__("": : :"memory")
+__attribute__((noinline)) int read_ptr(int *ptr)
+{
+ /*
+ * * Keep GCC from optimizing this away somehow
+ * */
+ barrier();
+ return *ptr;
+}
+
void expected_pkey_fault(int pkey);
int sys_pkey_alloc(unsigned long flags, unsigned long init_val);
int sys_pkey_free(unsigned long pkey);
diff --git a/tools/testing/selftests/mm/pkey_sighandler_tests.c b/tools/testing/selftests/mm/pkey_sighandler_tests.c
new file mode 100644
index 000000000000..eb4155859846
--- /dev/null
+++ b/tools/testing/selftests/mm/pkey_sighandler_tests.c
@@ -0,0 +1,315 @@
+#define _GNU_SOURCE
+#define __SANE_USERSPACE_TYPES__
+#include <errno.h>
+#include <sys/syscall.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <signal.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <limits.h>
+
+#include "pkey-helpers.h"
+
+/*
+ * Compile with:
+ * gcc -mxsave -o pkey_sighandler_tests -O2 -g -std=gnu99 -pthread -Wall pkey_sighandler_tests.c -lrt -ldl -lm
+ */
+
+#define STACK_SIZE PTHREAD_STACK_MIN
+
+void expected_pkey_fault(int pkey) {}
+
+pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+siginfo_t siginfo = {0};
+
+static inline __attribute__((always_inline)) long
+syscall_raw(long n, long a1, long a2, long a3, long a4, long a5, long a6)
+{
+ unsigned long ret;
+ register long r10 asm("r10") = a4;
+ register long r8 asm("r8") = a5;
+ register long r9 asm("r9") = a6;
+ asm volatile ("syscall"
+ : "=a"(ret)
+ : "a"(n), "D"(a1), "S"(a2), "d"(a3), "r"(r10), "r"(r8), "r"(r9)
+ : "rcx", "r11", "memory");
+ return ret;
+}
+
+
+static void sigsegv_handler(int signo, siginfo_t *info, void *ucontext)
+{
+ pthread_mutex_lock(&mutex);
+
+ memcpy(&siginfo, info, sizeof(siginfo_t));
+
+ pthread_cond_signal(&cond);
+ pthread_mutex_unlock(&mutex);
+
+ syscall_raw(SYS_exit, 0, 0, 0, 0, 0, 0);
+}
+
+static void sigusr1_handler(int signo, siginfo_t *info, void *ucontext)
+{
+ pthread_mutex_lock(&mutex);
+
+ memcpy(&siginfo, info, sizeof(siginfo_t));
+
+ pthread_cond_signal(&cond);
+ pthread_mutex_unlock(&mutex);
+}
+
+static void *thread_segv_with_pkey0_disabled(void *ptr)
+{
+ /* Disable MPK 0 (and all others too) */
+ __write_pkey_reg(0x55555555);
+
+ /* Segfault (with SEGV_MAPERR) */
+ *(int *) (0x1) = 1;
+ return NULL;
+}
+
+static void *thread_segv_pkuerr_stack(void *ptr)
+{
+ /* Disable MPK 0 (and all others too) */
+ __write_pkey_reg(0x55555555);
+
+ /* After we disable MPK 0, we can't access the stack to return */
+ return NULL;
+}
+
+static void *thread_segv_maperr_ptr(void *ptr)
+{
+ stack_t *stack = ptr;
+ int *bad = (int *) 1;
+
+ /*
+ * Setup alternate signal stack, which should be pkey_mprotect()ed by
+ * MPK 0. The thread's stack cannot be used for signals because it is
+ * not accessible by the default init_pkru value of 0x55555554.
+ */
+ syscall_raw(SYS_sigaltstack, (long)stack, 0, 0, 0, 0, 0);
+
+ /* Disable MPK 0. Only MPK 1 is enabled. */
+ __write_pkey_reg(0x55555551);
+
+ /* Segfault */
+ *bad = 1;
+ syscall_raw(SYS_exit, 0, 0, 0, 0, 0, 0);
+ return NULL;
+}
+
+/*
+ * Verify that the sigsegv handler is invoked when pkey 0 is disabled.
+ * Note that the new thread stack and the alternate signal stack is
+ * protected by MPK 0.
+ */
+static void test_sigsegv_handler_with_pkey0_disabled(void)
+{
+ struct sigaction sa;
+
+ sa.sa_flags = SA_SIGINFO;
+
+ sa.sa_sigaction = sigsegv_handler;
+ sigemptyset(&sa.sa_mask);
+ if (sigaction(SIGSEGV, &sa, NULL) == -1) {
+ perror("sigaction");
+ exit(EXIT_FAILURE);
+ }
+
+ memset(&siginfo, 0, sizeof(siginfo));
+
+ pthread_t thr;
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ pthread_create(&thr, &attr, thread_segv_with_pkey0_disabled, NULL);
+
+ pthread_mutex_lock(&mutex);
+ while(siginfo.si_signo == 0)
+ pthread_cond_wait(&cond, &mutex);
+ pthread_mutex_unlock(&mutex);
+
+ assert(siginfo.si_signo == SIGSEGV);
+ assert(siginfo.si_code == SEGV_MAPERR);
+ assert(siginfo.si_addr == (void *)1);
+ printf("%s passed!\n", __func__);
+}
+
+/*
+ * Verify that the sigsegv handler is invoked when pkey 0 is disabled.
+ * Note that the new thread stack and the alternate signal stack is
+ * protected by MPK 0, which renders them inaccessible when MPK 0
+ * is disabled. So just the return from the thread should cause a
+ * segfault with SEGV_PKUERR.
+ */
+static void test_sigsegv_handler_cannot_access_stack(void)
+{
+ struct sigaction sa;
+
+ sa.sa_flags = SA_SIGINFO;
+
+ sa.sa_sigaction = sigsegv_handler;
+ sigemptyset(&sa.sa_mask);
+ if (sigaction(SIGSEGV, &sa, NULL) == -1) {
+ perror("sigaction");
+ exit(EXIT_FAILURE);
+ }
+
+ memset(&siginfo, 0, sizeof(siginfo));
+
+ pthread_t thr;
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ pthread_create(&thr, &attr, thread_segv_pkuerr_stack, NULL);
+
+ pthread_mutex_lock(&mutex);
+ while(siginfo.si_signo == 0)
+ pthread_cond_wait(&cond, &mutex);
+ pthread_mutex_unlock(&mutex);
+
+ assert(siginfo.si_signo == SIGSEGV);
+ assert(siginfo.si_code == SEGV_PKUERR);
+ printf("%s passed!\n", __func__);
+}
+
+/*
+ * Verify that the sigsegv handler that uses an alternate signal stack
+ * is correctly invoked for a thread which uses a non-zero MPK to protect
+ * its own stack, and disables all other MPKs (including 0).
+ */
+static void test_sigsegv_handler_with_different_pkey_for_stack(void)
+{
+ struct sigaction sa;
+ static stack_t sigstack;
+ void *stack;
+ int pkey;
+ int parentPid = 0;
+ int childPid = 0;
+
+ sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
+
+ sa.sa_sigaction = sigsegv_handler;
+
+ sigemptyset(&sa.sa_mask);
+ if (sigaction(SIGSEGV, &sa, NULL) == -1) {
+ perror("sigaction");
+ exit(EXIT_FAILURE);
+ }
+
+ stack = mmap(0, STACK_SIZE, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+
+ assert(stack != MAP_FAILED);
+
+ /* Allow access to MPK 0 and MPK 1 */
+ __write_pkey_reg(0x55555550);
+
+ /* Protect the new stack with MPK 1 */
+ pkey = pkey_alloc(0, 0);
+ pkey_mprotect(stack, STACK_SIZE, PROT_READ | PROT_WRITE, pkey);
+
+ /* Set up alternate signal stack that will use the default MPK */
+ sigstack.ss_sp = mmap(0, STACK_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ sigstack.ss_flags = 0;
+ sigstack.ss_size = STACK_SIZE;
+
+ memset(&siginfo, 0, sizeof(siginfo));
+
+ /* Use clone to avoid newer glibcs using rseq on new threads */
+ long ret = syscall_raw(SYS_clone,
+ CLONE_VM | CLONE_FS | CLONE_FILES |
+ CLONE_SIGHAND | CLONE_THREAD | CLONE_SYSVSEM |
+ CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID |
+ CLONE_DETACHED,
+ (long)((char *)(stack) + STACK_SIZE),
+ (long)&parentPid,
+ (long)&childPid, 0, 0);
+
+ if (ret < 0) {
+ errno = -ret;
+ perror("clone");
+ } else if (ret == 0) {
+ thread_segv_maperr_ptr(&sigstack);
+ syscall_raw(SYS_exit, 0, 0, 0, 0, 0, 0);
+ }
+
+ pthread_mutex_lock(&mutex);
+ while(siginfo.si_signo == 0)
+ pthread_cond_wait(&cond, &mutex);
+ pthread_mutex_unlock(&mutex);
+
+ assert(siginfo.si_signo == SIGSEGV);
+ assert(siginfo.si_code == SEGV_MAPERR);
+ assert(siginfo.si_addr == (void *)1);
+ printf("%s passed!\n", __func__);
+}
+
+/*
+ * Verify that the PKRU value set by the application is correctly
+ * restored upon return from signal handling.
+ */
+static void test_pkru_preserved_after_sigusr1(void)
+{
+ struct sigaction sa;
+ unsigned long pkru = 0x45454544;
+
+ sa.sa_flags = SA_SIGINFO;
+
+ sa.sa_sigaction = sigusr1_handler;
+ sigemptyset(&sa.sa_mask);
+ if (sigaction(SIGUSR1, &sa, NULL) == -1) {
+ perror("sigaction");
+ exit(EXIT_FAILURE);
+ }
+
+ memset(&siginfo, 0, sizeof(siginfo));
+
+ __write_pkey_reg(pkru);
+
+ raise(SIGUSR1);
+
+ pthread_mutex_lock(&mutex);
+ while(siginfo.si_signo == 0)
+ pthread_cond_wait(&cond, &mutex);
+ pthread_mutex_unlock(&mutex);
+
+ /* Ensure the pkru value is the same after returning from signal. */
+ assert(pkru == __read_pkey_reg());
+ assert(siginfo.si_signo == SIGUSR1);
+ printf("%s passed!\n", __func__);
+}
+
+
+void (*pkey_tests[])(void) = {
+ test_sigsegv_handler_with_pkey0_disabled,
+ test_sigsegv_handler_cannot_access_stack,
+ test_sigsegv_handler_with_different_pkey_for_stack,
+ test_pkru_preserved_after_sigusr1,
+};
+
+int main(int argc, char *argv[])
+{
+ size_t i;
+
+ for (i = 0; i < sizeof(pkey_tests)/sizeof(pkey_tests[0]); i++) {
+ (*pkey_tests[i])();
+ }
+
+ printf("All pkey-signal-handling tests PASSED!\n");
+ return 0;
+}
+
diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/selftests/mm/protection_keys.c
index 374a308174d2..ec1e1d30ea6f 100644
--- a/tools/testing/selftests/mm/protection_keys.c
+++ b/tools/testing/selftests/mm/protection_keys.c
@@ -951,16 +951,6 @@ void close_test_fds(void)
nr_test_fds = 0;
}
-#define barrier() __asm__ __volatile__("": : :"memory")
-__attribute__((noinline)) int read_ptr(int *ptr)
-{
- /*
- * Keep GCC from optimizing this away somehow
- */
- barrier();
- return *ptr;
-}
-
void test_pkey_alloc_free_attach_pkey0(int *ptr, u16 pkey)
{
int i, err;
--
2.39.3
On Thu, Apr 25 2024 at 18:05, Aruna Ramakrishna wrote:
> This commit adds a few new tests to exercise the signal handler flow,
"This commit" is equally useless as "This patch". See
Documentation/process/ and grep for "This patch".
> especially with pkey 0 disabled.
>
> Signed-off-by: Keith Lucas <keith.lucas@oracle.com>
> Signed-off-by: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>
> ---
> tools/testing/selftests/mm/Makefile | 2 +
> tools/testing/selftests/mm/pkey-helpers.h | 11 +-
> .../selftests/mm/pkey_sighandler_tests.c | 315 ++++++++++++++++++
> tools/testing/selftests/mm/protection_keys.c | 10 -
> 4 files changed, 327 insertions(+), 11 deletions(-)
> create mode 100644 tools/testing/selftests/mm/pkey_sighandler_tests.c
>
> diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile
> index eb5f39a2668b..2f90344ad11e 100644
> --- a/tools/testing/selftests/mm/Makefile
> +++ b/tools/testing/selftests/mm/Makefile
> @@ -82,6 +82,7 @@ CAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_64bit_pr
> CAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_program.c -no-pie)
>
> VMTARGETS := protection_keys
> +VMTARGETS := pkey_sighandler_tests
> BINARIES_32 := $(VMTARGETS:%=%_32)
> BINARIES_64 := $(VMTARGETS:%=%_64)
>
> @@ -100,6 +101,7 @@ else
>
> ifneq (,$(findstring $(ARCH),ppc64))
> TEST_GEN_FILES += protection_keys
> +TEST_GEN_FILES += pkey_sighandler_tests
> endif
>
> endif
> diff --git a/tools/testing/selftests/mm/pkey-helpers.h b/tools/testing/selftests/mm/pkey-helpers.h
> index 1af3156a9db8..a0766e3d9ab6 100644
> --- a/tools/testing/selftests/mm/pkey-helpers.h
> +++ b/tools/testing/selftests/mm/pkey-helpers.h
> @@ -79,7 +79,16 @@ extern void abort_hooks(void);
> } \
> } while (0)
>
> -__attribute__((noinline)) int read_ptr(int *ptr);
> +#define barrier() __asm__ __volatile__("": : :"memory")
#include <linux/compiler.h>
> +__attribute__((noinline)) int read_ptr(int *ptr)
> +{
> + /*
> + * * Keep GCC from optimizing this away somehow
> + * */
That comment is completely malformatted.
> + barrier();
> + return *ptr;
White space damage.
> +
> +static inline __attribute__((always_inline)) long
> +syscall_raw(long n, long a1, long a2, long a3, long a4, long a5, long a6)
> +{
What for? syscall(2) provides exactly what you want, no?
> + unsigned long ret;
> + register long r10 asm("r10") = a4;
> + register long r8 asm("r8") = a5;
> + register long r9 asm("r9") = a6;
> + asm volatile ("syscall"
> + : "=a"(ret)
> + : "a"(n), "D"(a1), "S"(a2), "d"(a3), "r"(r10), "r"(r8), "r"(r9)
> + : "rcx", "r11", "memory");
Aside of that this breaks on 32-bit builds.
> + return ret;
> +}
> +
> +static void *thread_segv_with_pkey0_disabled(void *ptr)
> +{
> + /* Disable MPK 0 (and all others too) */
> + __write_pkey_reg(0x55555555);
> +
> + /* Segfault (with SEGV_MAPERR) */
Please use tabs for indentation. (All over the place)
> + *(int *) (0x1) = 1;
> + return NULL;
> +}
> +
> +/*
> + * Verify that the sigsegv handler is invoked when pkey 0 is disabled.
> + * Note that the new thread stack and the alternate signal stack is
> + * protected by MPK 0.
> + */
> +static void test_sigsegv_handler_with_pkey0_disabled(void)
> +{
> + struct sigaction sa;
> +
> + sa.sa_flags = SA_SIGINFO;
> +
> + sa.sa_sigaction = sigsegv_handler;
> + sigemptyset(&sa.sa_mask);
> + if (sigaction(SIGSEGV, &sa, NULL) == -1) {
> + perror("sigaction");
> + exit(EXIT_FAILURE);
> + }
> +
> + memset(&siginfo, 0, sizeof(siginfo));
> +
> + pthread_t thr;
> + pthread_attr_t attr;
> + pthread_attr_init(&attr);
> + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
> +
> + pthread_create(&thr, &attr, thread_segv_with_pkey0_disabled, NULL);
> +
> + pthread_mutex_lock(&mutex);
> + while(siginfo.si_signo == 0)
> + pthread_cond_wait(&cond, &mutex);
> + pthread_mutex_unlock(&mutex);
> +
> + assert(siginfo.si_signo == SIGSEGV);
> + assert(siginfo.si_code == SEGV_MAPERR);
> + assert(siginfo.si_addr == (void *)1);
This should not use assert(). This wants to use proper kselftest result
and exit mechanisms all over the place.
> + printf("%s passed!\n", __func__);
Ditto for printf().
> +}
> +/*
> + * Verify that the sigsegv handler that uses an alternate signal stack
> + * is correctly invoked for a thread which uses a non-zero MPK to protect
> + * its own stack, and disables all other MPKs (including 0).
> + */
> +static void test_sigsegv_handler_with_different_pkey_for_stack(void)
> +{
> + struct sigaction sa;
> + static stack_t sigstack;
> + void *stack;
> + int pkey;
> + int parentPid = 0;
> + int childPid = 0;
No camel case please
> +int main(int argc, char *argv[])
> +{
> + size_t i;
size_t? What's wrong with int?
> +
> + for (i = 0; i < sizeof(pkey_tests)/sizeof(pkey_tests[0]); i++) {
ARRAY_SIZE() ?
> + (*pkey_tests[i])();
> + }
Pointless brackets.
Thanks,
tglx
On Tue, May 07 2024 at 14:05, Thomas Gleixner wrote: > On Thu, Apr 25 2024 at 18:05, Aruna Ramakrishna wrote: >> especially with pkey 0 disabled. >> >> Signed-off-by: Keith Lucas <keith.lucas@oracle.com> >> Signed-off-by: Aruna Ramakrishna <aruna.ramakrishna@oracle.com> Forgot to mention that this Signed-off-by chain is invalid.
> On May 7, 2024, at 9:56 AM, Thomas Gleixner <tglx@linutronix.de> wrote: > > On Tue, May 07 2024 at 14:05, Thomas Gleixner wrote: >> On Thu, Apr 25 2024 at 18:05, Aruna Ramakrishna wrote: >>> especially with pkey 0 disabled. >>> >>> Signed-off-by: Keith Lucas <keith.lucas@oracle.com> >>> Signed-off-by: Aruna Ramakrishna <aruna.ramakrishna@oracle.com> > > Forgot to mention that this Signed-off-by chain is invalid. Apologies for what is probably an obvious question. Keith Lucas developed the testcases in the new file pkey_sighandler_tests.c. I added them to tools/testing/selftests/mm (i.e. just the changes to Makefile, protection_keys.c and some comments etc.). So should I change this to: Co-developed-by: Keith Lucas <keith.lucas@oracle.com> Signed-off-by: Keith Lucas <keith.lucas@oracle.com> Signed-off-by: Aruna Ramakrishna <aruna.ramakrishna@oracle.com> Thanks, Aruna
On Tue, May 07 2024 at 18:04, Aruna Ramakrishna wrote:
>> On May 7, 2024, at 9:56 AM, Thomas Gleixner <tglx@linutronix.de> wrote:
>>
>> On Tue, May 07 2024 at 14:05, Thomas Gleixner wrote:
>>> On Thu, Apr 25 2024 at 18:05, Aruna Ramakrishna wrote:
>>>> especially with pkey 0 disabled.
>>>>
>>>> Signed-off-by: Keith Lucas <keith.lucas@oracle.com>
>>>> Signed-off-by: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>
>>
>> Forgot to mention that this Signed-off-by chain is invalid.
>
> Apologies for what is probably an obvious question.
>
> Keith Lucas developed the testcases in the new file pkey_sighandler_tests.c.
>
> I added them to tools/testing/selftests/mm (i.e. just the changes
> to Makefile, protection_keys.c and some comments etc.).
>
> So should I change this to:
>
> Co-developed-by: Keith Lucas <keith.lucas@oracle.com>
> Signed-off-by: Keith Lucas <keith.lucas@oracle.com>
> Signed-off-by: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>
If Keith developed them, then you probably want to credit him as author.
[ aruna: Adopted to upstream ]
Signed-off-by: Keith Lucas <keith.lucas@oracle.com>
Signed-off-by: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>
Or split out the pkey helper changes into a separate patch which is
authored by you.
Either way works just fine.
Thanks,
tglx
Hi Aruna,
kernel test robot noticed the following build errors:
[auto build test ERROR on tip/x86/core]
[also build test ERROR on akpm-mm/mm-everything tip/master linus/master v6.9-rc5]
[cannot apply to tip/auto-latest next-20240426]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Aruna-Ramakrishna/x86-pkeys-Signal-handling-function-interface-changes-to-accept-PKRU-as-a-parameter/20240426-020800
base: tip/x86/core
patch link: https://lore.kernel.org/r/20240425180542.1042933-5-aruna.ramakrishna%40oracle.com
patch subject: [PATCH v3 4/4] selftests/mm: Add new testcases for pkeys
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <yujie.liu@intel.com>
| Closes: https://lore.kernel.org/r/202404271128.ERrCledH-lkp@intel.com/
All errors:
linux/tools/testing/selftests/mm$ make
...
gcc -Wall -I /root/linux/tools/testing/selftests/../../.. -isystem /root/linux/tools/testing/selftests/../../../usr/include -no-pie -m32 -mxsave pkey_sighandler_tests.c vm_util.c thp_settings.c -lrt -lpthread -lm -lrt -ldl -lm -o /root/linux/tools/testing/selftests/mm/pkey_sighandler_tests_32
pkey_sighandler_tests.c: In function 'sigsegv_handler':
pkey_sighandler_tests.c:38:23: error: the register specified for 'r10' cannot be accessed by the current target
38 | register long r10 asm("r10") = a4;
| ^~~
pkey_sighandler_tests.c:39:23: error: the register specified for 'r8' cannot be accessed by the current target
39 | register long r8 asm("r8") = a5;
| ^~
pkey_sighandler_tests.c:40:23: error: the register specified for 'r9' cannot be accessed by the current target
40 | register long r9 asm("r9") = a6;
| ^~
In function 'syscall_raw',
inlined from 'sigsegv_handler' at pkey_sighandler_tests.c:58:2:
pkey_sighandler_tests.c:41:9: error: the register 'r11' cannot be clobbered in 'asm' for the current target
41 | asm volatile ("syscall"
| ^~~
pkey_sighandler_tests.c: In function 'thread_segv_maperr_ptr':
pkey_sighandler_tests.c:38:23: error: the register specified for 'r10' cannot be accessed by the current target
38 | register long r10 asm("r10") = a4;
| ^~~
pkey_sighandler_tests.c:39:23: error: the register specified for 'r8' cannot be accessed by the current target
39 | register long r8 asm("r8") = a5;
| ^~
pkey_sighandler_tests.c:40:23: error: the register specified for 'r9' cannot be accessed by the current target
40 | register long r9 asm("r9") = a6;
| ^~
pkey_sighandler_tests.c:38:23: error: the register specified for 'r10' cannot be accessed by the current target
38 | register long r10 asm("r10") = a4;
| ^~~
pkey_sighandler_tests.c:39:23: error: the register specified for 'r8' cannot be accessed by the current target
39 | register long r8 asm("r8") = a5;
| ^~
pkey_sighandler_tests.c:40:23: error: the register specified for 'r9' cannot be accessed by the current target
40 | register long r9 asm("r9") = a6;
| ^~
In function 'syscall_raw',
inlined from 'thread_segv_maperr_ptr' at pkey_sighandler_tests.c:100:9:
pkey_sighandler_tests.c:41:9: error: the register 'r11' cannot be clobbered in 'asm' for the current target
41 | asm volatile ("syscall"
| ^~~
In function 'syscall_raw',
inlined from 'thread_segv_maperr_ptr' at pkey_sighandler_tests.c:107:2:
pkey_sighandler_tests.c:41:9: error: the register 'r11' cannot be clobbered in 'asm' for the current target
41 | asm volatile ("syscall"
| ^~~
pkey_sighandler_tests.c: In function 'test_sigsegv_handler_with_different_pkey_for_stack':
pkey_sighandler_tests.c:38:23: error: the register specified for 'r10' cannot be accessed by the current target
38 | register long r10 asm("r10") = a4;
| ^~~
pkey_sighandler_tests.c:39:23: error: the register specified for 'r8' cannot be accessed by the current target
39 | register long r8 asm("r8") = a5;
| ^~
pkey_sighandler_tests.c:40:23: error: the register specified for 'r9' cannot be accessed by the current target
40 | register long r9 asm("r9") = a6;
| ^~
pkey_sighandler_tests.c:38:23: error: the register specified for 'r10' cannot be accessed by the current target
38 | register long r10 asm("r10") = a4;
| ^~~
pkey_sighandler_tests.c:39:23: error: the register specified for 'r8' cannot be accessed by the current target
39 | register long r8 asm("r8") = a5;
| ^~
pkey_sighandler_tests.c:40:23: error: the register specified for 'r9' cannot be accessed by the current target
40 | register long r9 asm("r9") = a6;
| ^~
In function 'syscall_raw',
inlined from 'test_sigsegv_handler_with_different_pkey_for_stack' at pkey_sighandler_tests.c:233:13:
pkey_sighandler_tests.c:41:9: error: the register 'r11' cannot be clobbered in 'asm' for the current target
41 | asm volatile ("syscall"
| ^~~
In function 'syscall_raw',
inlined from 'test_sigsegv_handler_with_different_pkey_for_stack' at pkey_sighandler_tests.c:247:3:
pkey_sighandler_tests.c:41:9: error: the register 'r11' cannot be clobbered in 'asm' for the current target
41 | asm volatile ("syscall"
| ^~~
make: *** [Makefile:146: /root/linux/tools/testing/selftests/mm/pkey_sighandler_tests_32] Error 1
linux/tools/testing/selftests/mm$ make LLVM=1
...
clang --target=x86_64-linux-gnu -fintegrated-as -Wall -I /root/linux/tools/testing/selftests/../../.. -isystem /root/linux/tools/testing/selftests/../../../usr/include -no-pie -m32 -mxsave pkey_sighandler_tests.c vm_util.c thp_settings.c -lrt -lpthread -lm -lrt -ldl -lm -o /root/linux/tools/testing/selftests/mm/pkey_sighandler_tests_32
pkey_sighandler_tests.c:41:16: error: couldn't allocate input reg for constraint '{r10}'
41 | asm volatile ("syscall"
| ^
pkey_sighandler_tests.c:41:16: error: couldn't allocate input reg for constraint '{r10}'
pkey_sighandler_tests.c:41:16: error: couldn't allocate input reg for constraint '{r10}'
pkey_sighandler_tests.c:41:16: error: couldn't allocate input reg for constraint '{r10}'
pkey_sighandler_tests.c:41:16: error: couldn't allocate input reg for constraint '{r10}'
5 errors generated.
make: *** [Makefile:146: /root/linux/tools/testing/selftests/mm/pkey_sighandler_tests_32] Error 1
vim +41 tools/testing/selftests/mm/pkey_sighandler_tests.c
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 33
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 34 static inline __attribute__((always_inline)) long
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 35 syscall_raw(long n, long a1, long a2, long a3, long a4, long a5, long a6)
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 36 {
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 37 unsigned long ret;
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 38 register long r10 asm("r10") = a4;
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 39 register long r8 asm("r8") = a5;
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 40 register long r9 asm("r9") = a6;
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 @41 asm volatile ("syscall"
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 42 : "=a"(ret)
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 43 : "a"(n), "D"(a1), "S"(a2), "d"(a3), "r"(r10), "r"(r8), "r"(r9)
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 44 : "rcx", "r11", "memory");
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 45 return ret;
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 46 }
6b81215d7e8a34 Aruna Ramakrishna 2024-04-25 47
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.