aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDave Hansen <dave.hansen@linux.intel.com>2018-05-09 13:13:54 -0400
committerIngo Molnar <mingo@kernel.org>2018-05-14 05:14:45 -0400
commitacb25d761d6f2f64e785ccefc71e54f244f1eda4 (patch)
tree4bda589bbbb209d044f459d82e9cf86e6455eb7b /tools
parent3d64f4ed15c3c53dba4c514bf59c334464dee373 (diff)
x86/pkeys/selftests: Save off 'prot' for allocations
This makes it possible to to tell what 'prot' a given allocation is supposed to have. That way, if we want to change just the pkey, we know what 'prot' to pass to mprotect_pkey(). Also, keep a record of the most recent allocation so the tests can easily find it. Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Michael Ellermen <mpe@ellerman.id.au> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ram Pai <linuxram@us.ibm.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20180509171354.AA23E228@viggo.jf.intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/x86/protection_keys.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/tools/testing/selftests/x86/protection_keys.c b/tools/testing/selftests/x86/protection_keys.c
index ee8176358d12..986ed38a2b25 100644
--- a/tools/testing/selftests/x86/protection_keys.c
+++ b/tools/testing/selftests/x86/protection_keys.c
@@ -677,10 +677,12 @@ int mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot,
677struct pkey_malloc_record { 677struct pkey_malloc_record {
678 void *ptr; 678 void *ptr;
679 long size; 679 long size;
680 int prot;
680}; 681};
681struct pkey_malloc_record *pkey_malloc_records; 682struct pkey_malloc_record *pkey_malloc_records;
683struct pkey_malloc_record *pkey_last_malloc_record;
682long nr_pkey_malloc_records; 684long nr_pkey_malloc_records;
683void record_pkey_malloc(void *ptr, long size) 685void record_pkey_malloc(void *ptr, long size, int prot)
684{ 686{
685 long i; 687 long i;
686 struct pkey_malloc_record *rec = NULL; 688 struct pkey_malloc_record *rec = NULL;
@@ -712,6 +714,8 @@ void record_pkey_malloc(void *ptr, long size)
712 (int)(rec - pkey_malloc_records), rec, ptr, size); 714 (int)(rec - pkey_malloc_records), rec, ptr, size);
713 rec->ptr = ptr; 715 rec->ptr = ptr;
714 rec->size = size; 716 rec->size = size;
717 rec->prot = prot;
718 pkey_last_malloc_record = rec;
715 nr_pkey_malloc_records++; 719 nr_pkey_malloc_records++;
716} 720}
717 721
@@ -756,7 +760,7 @@ void *malloc_pkey_with_mprotect(long size, int prot, u16 pkey)
756 pkey_assert(ptr != (void *)-1); 760 pkey_assert(ptr != (void *)-1);
757 ret = mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey); 761 ret = mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey);
758 pkey_assert(!ret); 762 pkey_assert(!ret);
759 record_pkey_malloc(ptr, size); 763 record_pkey_malloc(ptr, size, prot);
760 rdpkru(); 764 rdpkru();
761 765
762 dprintf1("%s() for pkey %d @ %p\n", __func__, pkey, ptr); 766 dprintf1("%s() for pkey %d @ %p\n", __func__, pkey, ptr);
@@ -777,7 +781,7 @@ void *malloc_pkey_anon_huge(long size, int prot, u16 pkey)
777 size = ALIGN_UP(size, HPAGE_SIZE * 2); 781 size = ALIGN_UP(size, HPAGE_SIZE * 2);
778 ptr = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); 782 ptr = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
779 pkey_assert(ptr != (void *)-1); 783 pkey_assert(ptr != (void *)-1);
780 record_pkey_malloc(ptr, size); 784 record_pkey_malloc(ptr, size, prot);
781 mprotect_pkey(ptr, size, prot, pkey); 785 mprotect_pkey(ptr, size, prot, pkey);
782 786
783 dprintf1("unaligned ptr: %p\n", ptr); 787 dprintf1("unaligned ptr: %p\n", ptr);
@@ -850,7 +854,7 @@ void *malloc_pkey_hugetlb(long size, int prot, u16 pkey)
850 pkey_assert(ptr != (void *)-1); 854 pkey_assert(ptr != (void *)-1);
851 mprotect_pkey(ptr, size, prot, pkey); 855 mprotect_pkey(ptr, size, prot, pkey);
852 856
853 record_pkey_malloc(ptr, size); 857 record_pkey_malloc(ptr, size, prot);
854 858
855 dprintf1("mmap()'d hugetlbfs for pkey %d @ %p\n", pkey, ptr); 859 dprintf1("mmap()'d hugetlbfs for pkey %d @ %p\n", pkey, ptr);
856 return ptr; 860 return ptr;
@@ -872,7 +876,7 @@ void *malloc_pkey_mmap_dax(long size, int prot, u16 pkey)
872 876
873 mprotect_pkey(ptr, size, prot, pkey); 877 mprotect_pkey(ptr, size, prot, pkey);
874 878
875 record_pkey_malloc(ptr, size); 879 record_pkey_malloc(ptr, size, prot);
876 880
877 dprintf1("mmap()'d for pkey %d @ %p\n", pkey, ptr); 881 dprintf1("mmap()'d for pkey %d @ %p\n", pkey, ptr);
878 close(fd); 882 close(fd);