Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/powerpc: Fix pkey access right updates

The Power ISA mandates that all writes to the Authority
Mask Register (AMR) must always be preceded as well as
succeeded by a context synchronizing instruction.

This makes sure that the tests follow this requirement
when attempting to update a pkey's access rights.

Signed-off-by: Sandipan Das <sandipan@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200604125610.649668-2-sandipan@linux.ibm.com

authored by

Sandipan Das and committed by
Michael Ellerman
828ca432 105fb381

+8 -2
+6
tools/testing/selftests/powerpc/include/reg.h
··· 57 57 #define SPRN_PPR 896 /* Program Priority Register */ 58 58 #define SPRN_AMR 13 /* Authority Mask Register - problem state */ 59 59 60 + #define set_amr(v) asm volatile("isync;" \ 61 + "mtspr " __stringify(SPRN_AMR) ",%0;" \ 62 + "isync" : \ 63 + : "r" ((unsigned long)(v)) \ 64 + : "memory") 65 + 60 66 /* TEXASR register bits */ 61 67 #define TEXASR_FC 0xFE00000000000000 62 68 #define TEXASR_FP 0x0100000000000000
+1 -1
tools/testing/selftests/powerpc/ptrace/core-pkey.c
··· 150 150 printf("%-30s AMR: %016lx pkey1: %d pkey2: %d pkey3: %d\n", 151 151 user_write, info->amr, pkey1, pkey2, pkey3); 152 152 153 - mtspr(SPRN_AMR, info->amr); 153 + set_amr(info->amr); 154 154 155 155 /* 156 156 * We won't use pkey3. This tests whether the kernel restores the UAMOR
+1 -1
tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c
··· 126 126 printf("%-30s AMR: %016lx pkey1: %d pkey2: %d pkey3: %d\n", 127 127 user_write, info->amr1, pkey1, pkey2, pkey3); 128 128 129 - mtspr(SPRN_AMR, info->amr1); 129 + set_amr(info->amr1); 130 130 131 131 /* Wait for parent to read our AMR value and write a new one. */ 132 132 ret = prod_parent(&info->child_sync);