Commit 589944b5 authored by Ram Pai's avatar Ram Pai Committed by Linus Torvalds

selftests/vm/pkeys: introduce powerpc support

This makes use of the abstractions added earlier and introduces support
for powerpc.

For powerpc, after receiving the SIGSEGV, the signal handler must
explicitly restore access permissions for the faulting pkey to allow the
test to continue.  As this makes use of pkey_access_allow(), all of its
dependencies and other similar functions have been moved ahead of the
signal handler.

[sandipan@linux.ibm.com: fix powerpc access right updates]
  Link: http://lkml.kernel.org/r/5f65cf37be993760de8112a88da194e3ccbb2bf8.1588959697.git.sandipan@linux.ibm.comSigned-off-by: default avatarRam Pai <linuxram@us.ibm.com>
Signed-off-by: default avatarSandipan Das <sandipan@linux.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Acked-by: default avatarDave Hansen <dave.hansen@intel.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Florian Weimer <fweimer@redhat.com>
Cc: "Desnes A. Nunes do Rosario" <desnesn@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thiago Jung Bauermann <bauerman@linux.ibm.com>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Suchanek <msuchanek@suse.de>
Cc: Shuah Khan <shuah@kernel.org>
Link: http://lkml.kernel.org/r/b121e9fd33789ed9195276e32fe4e80bb6b88a31.1585646528.git.sandipan@linux.ibm.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 604c496b
...@@ -79,6 +79,8 @@ void expected_pkey_fault(int pkey); ...@@ -79,6 +79,8 @@ void expected_pkey_fault(int pkey);
#if defined(__i386__) || defined(__x86_64__) /* arch */ #if defined(__i386__) || defined(__x86_64__) /* arch */
#include "pkey-x86.h" #include "pkey-x86.h"
#elif defined(__powerpc64__) /* arch */
#include "pkey-powerpc.h"
#else /* arch */ #else /* arch */
#error Architecture not supported #error Architecture not supported
#endif /* arch */ #endif /* arch */
......
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _PKEYS_POWERPC_H
#define _PKEYS_POWERPC_H
#ifndef SYS_mprotect_key
# define SYS_mprotect_key 386
#endif
#ifndef SYS_pkey_alloc
# define SYS_pkey_alloc 384
# define SYS_pkey_free 385
#endif
#define REG_IP_IDX PT_NIP
#define REG_TRAPNO PT_TRAP
#define gregs gp_regs
#define fpregs fp_regs
#define si_pkey_offset 0x20
#ifndef PKEY_DISABLE_ACCESS
# define PKEY_DISABLE_ACCESS 0x3 /* disable read and write */
#endif
#ifndef PKEY_DISABLE_WRITE
# define PKEY_DISABLE_WRITE 0x2
#endif
#define NR_PKEYS 32
#define NR_RESERVED_PKEYS_4K 27 /* pkey-0, pkey-1, exec-only-pkey
and 24 other keys that cannot be
represented in the PTE */
#define NR_RESERVED_PKEYS_64K 3 /* pkey-0, pkey-1 and exec-only-pkey */
#define PKEY_BITS_PER_PKEY 2
#define HPAGE_SIZE (1UL << 24)
#define PAGE_SIZE (1UL << 16)
static inline u32 pkey_bit_position(int pkey)
{
return (NR_PKEYS - pkey - 1) * PKEY_BITS_PER_PKEY;
}
static inline u64 __read_pkey_reg(void)
{
u64 pkey_reg;
asm volatile("mfspr %0, 0xd" : "=r" (pkey_reg));
return pkey_reg;
}
static inline void __write_pkey_reg(u64 pkey_reg)
{
u64 amr = pkey_reg;
dprintf4("%s() changing %016llx to %016llx\n",
__func__, __read_pkey_reg(), pkey_reg);
asm volatile("isync; mtspr 0xd, %0; isync"
: : "r" ((unsigned long)(amr)) : "memory");
dprintf4("%s() pkey register after changing %016llx to %016llx\n",
__func__, __read_pkey_reg(), pkey_reg);
}
static inline int cpu_has_pku(void)
{
return 1;
}
static inline int get_arch_reserved_keys(void)
{
if (sysconf(_SC_PAGESIZE) == 4096)
return NR_RESERVED_PKEYS_4K;
else
return NR_RESERVED_PKEYS_64K;
}
void expect_fault_on_read_execonly_key(void *p1, int pkey)
{
/*
* powerpc does not allow userspace to change permissions of exec-only
* keys since those keys are not allocated by userspace. The signal
* handler wont be able to reset the permissions, which means the code
* will infinitely continue to segfault here.
*/
return;
}
/* 4-byte instructions * 16384 = 64K page */
#define __page_o_noops() asm(".rept 16384 ; nop; .endr")
#endif /* _PKEYS_POWERPC_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment