selftests: powerpc: Fixes and execute-disable test for pkeys
Subsystems (3)
v3 cover selftests: powerpc: Fixes and execute-disable test for pkeys
This fixes the way the Authority Mask Register (AMR) is updated by the existing pkey tests and adds a new test to verify the functionality of execute-disabled pkeys.
Previous versions can be found at:
v2: https://lore.kernel.org/linuxppc-dev/[email protected]/
v1: https://lore.kernel.org/linuxppc-dev/[email protected]/
Changes in v3:
- Fixed AMR writes for existing pkey tests (new patch).
- Moved Hash MMU check under utilities (new patch) and removed duplicate code.
- Fixed comments on why the pkey permission bits were redefined.
- Switched to existing mfspr() macro for reading AMR.
- Switched to sig_atomic_t as data type for variables updated in the signal handlers.
- Switched to exit()-ing if the signal handlers come across an unexpected condition instead of trying to reset page and pkey permissions.
- Switched to write() from printf() for printing error messages from the signal handlers.
- Switched to getpagesize().
- Renamed fault counter to denote remaining faults.
- Dropped unnecessary randomization for choosing an address to fault at.
- Added additional information on change in permissions due to AMR and IAMR bits in comments.
- Switched the first instruction word of the executable region to a trap to test if it is actually overwritten by a no-op later.
- Added an new test scenario where the pkey imposes no restrictions and an attempt is made to jump to the executable region again.
Changes in v2:
- Added .gitignore entry for test binary.
- Fixed builds for older distros where siginfo_t might not have si_pkey as a formal member based on discussion with Michael.
Sandipan Das (3):
selftests: powerpc: Fix pkey access right updates
selftests: powerpc: Move Hash MMU check to utilities
selftests: powerpc: Add test for execute-disabled pkeys
tools/testing/selftests/powerpc/include/reg.h | 6 + .../testing/selftests/powerpc/include/utils.h | 1 + tools/testing/selftests/powerpc/mm/.gitignore | 1 + tools/testing/selftests/powerpc/mm/Makefile | 5 +- .../selftests/powerpc/mm/bad_accesses.c | 28 -- .../selftests/powerpc/mm/pkey_exec_prot.c | 388 ++++++++++++++++++ .../selftests/powerpc/ptrace/core-pkey.c | 2 +- .../selftests/powerpc/ptrace/ptrace-pkey.c | 2 +- tools/testing/selftests/powerpc/utils.c | 28 ++ 9 files changed, 429 insertions(+), 32 deletions(-) create mode 100644 tools/testing/selftests/powerpc/mm/pkey_exec_prot.c
Signature · 1 line
2.25.1
PATCH v3 1/3 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.
--- tools/testing/selftests/powerpc/include/reg.h | 6 ++++++ tools/testing/selftests/powerpc/ptrace/core-pkey.c | 2 +- tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/powerpc/include/reg.h +6 -0
@@ -57,6 +57,12 @@#define SPRN_PPR 896/* Program Priority Register */ #define SPRN_AMR 13/* Authority Mask Register - problem state */ +#define set_amr (v) asm volatile("isync;" \ + "mtspr " __stringify(SPRN_AMR) ",%0;" \ + "isync" : \ + : "r" ((unsigned long)(v)) \ + : "memory") +/* TEXASR register bits */ #define TEXASR_FC 0xFE00000000000000#define TEXASR_FP 0x0100000000000000
tools/testing/selftests/powerpc/ptrace/core-pkey.c +1 -1
@@ -150,7 +150,7 @@ static int child(struct shared_info *info)printf ("%-30s AMR: %016lx pkey1: %d pkey2: %d pkey3: %d\n" , user_write, info->amr, pkey1, pkey2, pkey3); -mtspr (SPRN_AMR , info->amr); +set_amr (info->amr);/* * We won't use pkey3. This tests whether the kernel restores the UAMOR
tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c +1 -1
@@ -126,7 +126,7 @@ static int child(struct shared_info *info)printf ("%-30s AMR: %016lx pkey1: %d pkey2: %d pkey3: %d\n" , user_write, info->amr1, pkey1, pkey2, pkey3); -mtspr (SPRN_AMR , info->amr1); +set_amr (info->amr1);/* Wait for parent to read our AMR value and write a new one. */ ret =prod_parent (&info->child_sync);
Signature · 1 line
2.25.1
PATCH v3 2/3 selftests: powerpc: Move Hash MMU check to utilities
In reply to Sandipan DasThis moves a function to test if the MMU is in Hash mode under the generic test utilities.
--- .../testing/selftests/powerpc/include/utils.h | 1 + tools/testing/selftests/powerpc/mm/Makefile | 2 +- .../selftests/powerpc/mm/bad_accesses.c | 28 ------------------- tools/testing/selftests/powerpc/utils.c | 28 +++++++++++++++++++ 4 files changed, 30 insertions(+), 29 deletions(-)
tools/testing/selftests/powerpc/include/utils.h +1 -0
@@ -60,6 +60,7 @@ static inline bool have_hwcap2(unsigned long ftr2)#endif bool is_ppc64le (void ); +int using_hash_mmu (bool *using_hash);/* Yes, this is evil */ #define FAIL_IF (x) \
tools/testing/selftests/powerpc/mm/Makefile +1 -1
@@ -10,7 +10,7 @@ TEST_GEN_FILES := tempfile top_srcdir = ../../../../.. include ../../lib.mk -$(TEST_GEN_PROGS): ../harness.c +$(TEST_GEN_PROGS): ../harness.c ../utils.c $(OUTPUT)/prot_sao: ../utils.c
tools/testing/selftests/powerpc/mm/bad_accesses.c +0 -28
@@ -64,34 +64,6 @@ int bad_access(char *p, bool write)return 0 ; } -static int using_hash_mmu (bool *using_hash) -{ -char line[128 ]; -FILE *f; -int rc; - - f =fopen ("/proc/cpuinfo" ,"r" ); -FAIL_IF (!f); - - rc =0 ; -while (fgets (line,sizeof (line), f) !=NULL ) { -if (strcmp (line,"MMU : Hash\n" ) ==0 ) { - *using_hash = true; - goto out; - } - -if (strcmp (line,"MMU : Radix\n" ) ==0 ) { - *using_hash = false; - goto out; - } - } - - rc =-1 ; -out: -fclose (f); -return rc; -} -static int test (void ) {unsigned long i, j, addr, region_shift, page_shift, page_size;
tools/testing/selftests/powerpc/utils.c +28 -0
@@ -293,3 +293,31 @@ void set_dscr(unsigned long val) asmvolatile ("mtspr %1,%0" : :"r" (val),"i" (SPRN_DSCR )); } + +int using_hash_mmu (bool *using_hash) +{ +char line[128 ]; +FILE *f; +int rc; + + f =fopen ("/proc/cpuinfo" ,"r" ); +FAIL_IF (!f); + + rc =0 ; +while (fgets (line,sizeof (line), f) !=NULL ) { +if (strcmp (line,"MMU : Hash\n" ) ==0 ) { + *using_hash = true; + goto out; + } + +if (strcmp (line,"MMU : Radix\n" ) ==0 ) { + *using_hash = false; + goto out; + } + } + + rc =-1 ; +out: +fclose (f); +return rc; +}
Signature · 1 line
2.25.1
PATCH v3 3/3 selftests: powerpc: Add test for execute-disabled pkeys
In reply to Sandipan DasApart from read and write access, memory protection keys can also be used for restricting execute permission of pages on powerpc. This adds a test to verify if the feature works as expected.
--- tools/testing/selftests/powerpc/mm/.gitignore | 1 + tools/testing/selftests/powerpc/mm/Makefile | 3 +- .../selftests/powerpc/mm/pkey_exec_prot.c | 388 ++++++++++++++++++ 3 files changed, 391 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/mm/pkey_exec_prot.c
tools/testing/selftests/powerpc/mm/.gitignore +1 -0
@@ -8,3 +8,4 @@ wild_bctr large_vm_fork_separation bad_accesses tlbie_test +pkey_exec_prot
tools/testing/selftests/powerpc/mm/Makefile +2 -1
@@ -3,7 +3,7 @@ noarg: $(MAKE) -C ../ TEST_GEN_PROGS := hugetlb_vs_thp_test subpage_prot prot_sao segv_errors wild_bctr \ - large_vm_fork_separation bad_accesses + large_vm_fork_separation bad_accesses pkey_exec_prot TEST_GEN_PROGS_EXTENDED := tlbie_test TEST_GEN_FILES := tempfile
@@ -17,6 +17,7 @@ $(OUTPUT)/prot_sao: ../utils.c $(OUTPUT)/wild_bctr: CFLAGS += -m64 $(OUTPUT)/large_vm_fork_separation: CFLAGS += -m64 $(OUTPUT)/bad_accesses: CFLAGS += -m64 +$(OUTPUT)/pkey_exec_prot: CFLAGS += -m64 $(OUTPUT)/tempfile: dd if=/dev/zero of=$@ bs=64k count=1
tools/testing/selftests/powerpc/mm/pkey_exec_prot.c new file +388 -0
388 lines not on this page · raw message
Signature · 1 line
2.25.1
Michael Ellerman
AppliedQuoted 9 lines · Sandipan Das
This fixes the way the Authority Mask Register (AMR) is updated by the existing pkey tests and adds a new test to verify the functionality of execute-disabled pkeys.
Previous versions can be found at:
v2: https://lore.kernel.org/linuxppc-dev/[email protected]/
v1: https://lore.kernel.org/linuxppc-dev/[email protected]/[...]
Applied to powerpc/next.
[1/3] selftests/powerpc: Fix pkey access right updates
https://git.kernel.org/powerpc/c/828ca4320d130bbe1d12866152600c49ff6a9f79 [2/3] selftests/powerpc: Move Hash MMU check to utilities https://git.kernel.org/powerpc/c/c405b738daf9d8e8a5aedfeb6be851681e65e54b [3/3] selftests/powerpc: Add test for execute-disabled pkeys https://git.kernel.org/powerpc/c/1addb6444791f9e87fce0eb9882ec96a4a76e615
cheers