Skip to content

Commit

Permalink
selftests/powerpc: Fix pkey access right updates
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Sandipan Das authored and Michael Ellerman committed Jun 30, 2020
1 parent 105fb38 commit 828ca43
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tools/testing/selftests/powerpc/include/reg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/powerpc/ptrace/core-pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 828ca43

Please sign in to comment.