Skip to content

Commit b0acc5d

Browse files
Ram Paitorvalds
authored andcommitted
selftests/vm/pkeys: fix assertion in test_pkey_alloc_exhaust()
Some pkeys which are valid on the hardware are reserved and not available for application use. These keys cannot be allocated. test_pkey_alloc_exhaust() tries to account for these and has an assertion which validates if all available pkeys have been exahaustively allocated. However, the expression that is currently used is only valid for x86. On powerpc, a pkey is additionally reserved as compared to x86. Hence, the assertion is made to use an arch-specific helper to get the correct count of reserved pkeys. 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: Dave Hansen <[email protected]> Cc: Florian Weimer <[email protected]> Cc: "Desnes A. Nunes do Rosario" <[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/38b08d0318820ae46af3aa6048384fd8056c3df7.1585646528.git.sandipan@linux.ibm.com Signed-off-by: Linus Torvalds <[email protected]>
1 parent c63e5e7 commit b0acc5d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tools/testing/selftests/vm/protection_keys.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,15 +1153,24 @@ void test_pkey_alloc_exhaust(int *ptr, u16 pkey)
11531153
dprintf3("%s()::%d\n", __func__, __LINE__);
11541154

11551155
/*
1156+
* On x86:
11561157
* There are 16 pkeys supported in hardware. Three are
11571158
* allocated by the time we get here:
11581159
* 1. The default key (0)
11591160
* 2. One possibly consumed by an execute-only mapping.
11601161
* 3. One allocated by the test code and passed in via
11611162
* 'pkey' to this function.
11621163
* Ensure that we can allocate at least another 13 (16-3).
1164+
*
1165+
* On powerpc:
1166+
* There are either 5, 28, 29 or 32 pkeys supported in
1167+
* hardware depending on the page size (4K or 64K) and
1168+
* platform (powernv or powervm). Four are allocated by
1169+
* the time we get here. These include pkey-0, pkey-1,
1170+
* exec-only pkey and the one allocated by the test code.
1171+
* Ensure that we can allocate the remaining.
11631172
*/
1164-
pkey_assert(i >= NR_PKEYS-3);
1173+
pkey_assert(i >= (NR_PKEYS - get_arch_reserved_keys() - 1));
11651174

11661175
for (i = 0; i < nr_allocated_pkeys; i++) {
11671176
err = sys_pkey_free(allocated_pkeys[i]);

0 commit comments

Comments
 (0)