Skip to content

Commit c63e5e7

Browse files
Desnes A. Nunes do Rosariotorvalds
authored andcommitted
selftests/vm/pkeys: fix number of reserved powerpc pkeys
The number of reserved pkeys in a PowerNV environment is different from that on PowerVM or KVM. Tested on PowerVM and PowerNV environments. Signed-off-by: "Desnes A. Nunes do Rosario" <[email protected]> Signed-off-by: Ram Pai <[email protected]> Signed-off-by: Sandipan Das <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Acked-by: Dave Hansen <[email protected]> Cc: Florian Weimer <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Thiago Jung Bauermann <[email protected]> Cc: "Aneesh Kumar K.V" <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Michal Suchanek <[email protected]> Cc: Shuah Khan <[email protected]> Link: http://lkml.kernel.org/r/0341a0ca961166814b44c9e724774672c18d54ca.1585646528.git.sandipan@linux.ibm.com Signed-off-by: Linus Torvalds <[email protected]>
1 parent 589944b commit c63e5e7

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

tools/testing/selftests/vm/pkey-powerpc.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
#define NR_RESERVED_PKEYS_4K 27 /* pkey-0, pkey-1, exec-only-pkey
2929
and 24 other keys that cannot be
3030
represented in the PTE */
31-
#define NR_RESERVED_PKEYS_64K 3 /* pkey-0, pkey-1 and exec-only-pkey */
31+
#define NR_RESERVED_PKEYS_64K_3KEYS 3 /* PowerNV and KVM: pkey-0,
32+
pkey-1 and exec-only key */
33+
#define NR_RESERVED_PKEYS_64K_4KEYS 4 /* PowerVM: pkey-0, pkey-1,
34+
pkey-31 and exec-only key */
3235
#define PKEY_BITS_PER_PKEY 2
3336
#define HPAGE_SIZE (1UL << 24)
3437
#define PAGE_SIZE (1UL << 16)
@@ -66,12 +69,27 @@ static inline int cpu_has_pku(void)
6669
return 1;
6770
}
6871

72+
static inline bool arch_is_powervm()
73+
{
74+
struct stat buf;
75+
76+
if ((stat("/sys/firmware/devicetree/base/ibm,partition-name", &buf) == 0) &&
77+
(stat("/sys/firmware/devicetree/base/hmc-managed?", &buf) == 0) &&
78+
(stat("/sys/firmware/devicetree/base/chosen/qemu,graphic-width", &buf) == -1) )
79+
return true;
80+
81+
return false;
82+
}
83+
6984
static inline int get_arch_reserved_keys(void)
7085
{
7186
if (sysconf(_SC_PAGESIZE) == 4096)
7287
return NR_RESERVED_PKEYS_4K;
7388
else
74-
return NR_RESERVED_PKEYS_64K;
89+
if (arch_is_powervm())
90+
return NR_RESERVED_PKEYS_64K_4KEYS;
91+
else
92+
return NR_RESERVED_PKEYS_64K_3KEYS;
7593
}
7694

7795
void expect_fault_on_read_execonly_key(void *p1, int pkey)

0 commit comments

Comments
 (0)