From: Ram Pai <linux...@us.ibm.com> [ Upstream commit 6e373263ce07eeaa6410843179535fbdf561fc31 ]
alloc_random_pkey() was allocating the same pkey every time. Not all pkeys were geting tested. This fixes it. Signed-off-by: Ram Pai <linux...@us.ibm.com> Signed-off-by: Sandipan Das <sandi...@linux.ibm.com> Signed-off-by: Andrew Morton <a...@linux-foundation.org> Acked-by: Dave Hansen <dave.han...@intel.com> Cc: Dave Hansen <dave.han...@intel.com> Cc: Florian Weimer <fwei...@redhat.com> Cc: "Desnes A. Nunes do Rosario" <desn...@linux.vnet.ibm.com> Cc: Ingo Molnar <mi...@kernel.org> Cc: Thiago Jung Bauermann <bauer...@linux.ibm.com> Cc: "Aneesh Kumar K.V" <aneesh.ku...@linux.ibm.com> Cc: Michael Ellerman <m...@ellerman.id.au> Cc: Michal Hocko <mho...@kernel.org> Cc: Michal Suchanek <msucha...@suse.de> Cc: Shuah Khan <sh...@kernel.org> Link: http://lkml.kernel.org/r/0162f55816d4e783a0d6e49e554d0ab9a3c9a23b.1585646528.git.sandi...@linux.ibm.com Signed-off-by: Linus Torvalds <torva...@linux-foundation.org> Signed-off-by: Sasha Levin <sas...@kernel.org> --- tools/testing/selftests/x86/protection_keys.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/x86/protection_keys.c b/tools/testing/selftests/x86/protection_keys.c index 5d546dcdbc80..b8778960da10 100644 --- a/tools/testing/selftests/x86/protection_keys.c +++ b/tools/testing/selftests/x86/protection_keys.c @@ -24,6 +24,7 @@ #define _GNU_SOURCE #include <errno.h> #include <linux/futex.h> +#include <time.h> #include <sys/time.h> #include <sys/syscall.h> #include <string.h> @@ -612,10 +613,10 @@ int alloc_random_pkey(void) int nr_alloced = 0; int random_index; memset(alloced_pkeys, 0, sizeof(alloced_pkeys)); + srand((unsigned int)time(NULL)); /* allocate every possible key and make a note of which ones we got */ max_nr_pkey_allocs = NR_PKEYS; - max_nr_pkey_allocs = 1; for (i = 0; i < max_nr_pkey_allocs; i++) { int new_pkey = alloc_pkey(); if (new_pkey < 0) -- 2.25.1