LKML Archive on lore.kernel.org help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@linux.intel.com> To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Dave Hansen <dave.hansen@linux.intel.com>, linuxram@us.ibm.com, tglx@linutronix.de, dave.hansen@intel.com, mpe@ellerman.id.au, mingo@kernel.org, akpm@linux-foundation.org, shuah@kernel.org Subject: [PATCH 2/9] x86, pkeys, selftests: save off 'prot' for allocations Date: Mon, 26 Mar 2018 10:27:24 -0700 [thread overview] Message-ID: <20180326172724.ED505E4B@viggo.jf.intel.com> (raw) In-Reply-To: <20180326172721.D5B2CBB4@viggo.jf.intel.com> From: Dave Hansen <dave.hansen@linux.intel.com> 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: Ram Pai <linuxram@us.ibm.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Michael Ellermen <mpe@ellerman.id.au> Cc: Ingo Molnar <mingo@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Shuah Khan <shuah@kernel.org> --- b/tools/testing/selftests/x86/protection_keys.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff -puN tools/testing/selftests/x86/protection_keys.c~pkeys-update-selftests-store-malloc-record tools/testing/selftests/x86/protection_keys.c --- a/tools/testing/selftests/x86/protection_keys.c~pkeys-update-selftests-store-malloc-record 2018-03-26 10:22:34.301170195 -0700 +++ b/tools/testing/selftests/x86/protection_keys.c 2018-03-26 10:22:34.305170195 -0700 @@ -674,10 +674,12 @@ int mprotect_pkey(void *ptr, size_t size struct pkey_malloc_record { void *ptr; long size; + int prot; }; struct pkey_malloc_record *pkey_malloc_records; +struct pkey_malloc_record *pkey_last_malloc_record; long nr_pkey_malloc_records; -void record_pkey_malloc(void *ptr, long size) +void record_pkey_malloc(void *ptr, long size, int prot) { long i; struct pkey_malloc_record *rec = NULL; @@ -709,6 +711,8 @@ void record_pkey_malloc(void *ptr, long (int)(rec - pkey_malloc_records), rec, ptr, size); rec->ptr = ptr; rec->size = size; + rec->prot = prot; + pkey_last_malloc_record = rec; nr_pkey_malloc_records++; } @@ -753,7 +757,7 @@ void *malloc_pkey_with_mprotect(long siz pkey_assert(ptr != (void *)-1); ret = mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey); pkey_assert(!ret); - record_pkey_malloc(ptr, size); + record_pkey_malloc(ptr, size, prot); rdpkru(); dprintf1("%s() for pkey %d @ %p\n", __func__, pkey, ptr); @@ -774,7 +778,7 @@ void *malloc_pkey_anon_huge(long size, i size = ALIGN_UP(size, HPAGE_SIZE * 2); ptr = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); pkey_assert(ptr != (void *)-1); - record_pkey_malloc(ptr, size); + record_pkey_malloc(ptr, size, prot); mprotect_pkey(ptr, size, prot, pkey); dprintf1("unaligned ptr: %p\n", ptr); @@ -847,7 +851,7 @@ void *malloc_pkey_hugetlb(long size, int pkey_assert(ptr != (void *)-1); mprotect_pkey(ptr, size, prot, pkey); - record_pkey_malloc(ptr, size); + record_pkey_malloc(ptr, size, prot); dprintf1("mmap()'d hugetlbfs for pkey %d @ %p\n", pkey, ptr); return ptr; @@ -869,7 +873,7 @@ void *malloc_pkey_mmap_dax(long size, in mprotect_pkey(ptr, size, prot, pkey); - record_pkey_malloc(ptr, size); + record_pkey_malloc(ptr, size, prot); dprintf1("mmap()'d for pkey %d @ %p\n", pkey, ptr); close(fd); _
next prev parent reply other threads:[~2018-03-26 17:29 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-03-26 17:27 [PATCH 0/9] [v2] x86, pkeys: two protection keys bug fixes Dave Hansen 2018-03-26 17:27 ` [PATCH 1/9] x86, pkeys: do not special case protection key 0 Dave Hansen 2018-03-26 17:47 ` Shuah Khan 2018-03-26 17:53 ` Dave Hansen 2018-03-26 17:58 ` Shuah Khan 2018-03-26 17:27 ` Dave Hansen [this message] 2018-03-26 17:27 ` [PATCH 3/9] x86, pkeys, selftests: add a test for pkey 0 Dave Hansen 2018-03-26 17:27 ` [PATCH 4/9] x86, pkeys: override pkey when moving away from PROT_EXEC Dave Hansen 2018-04-07 0:09 ` Ram Pai 2018-04-07 0:47 ` Dave Hansen 2018-04-07 1:09 ` Ram Pai 2018-04-26 17:57 ` Dave Hansen 2018-04-30 7:51 ` Ram Pai 2018-04-30 16:36 ` Dave Hansen 2018-04-25 22:10 ` Shakeel Butt 2018-04-26 8:55 ` Thomas Gleixner 2018-04-26 18:17 ` Dave Hansen 2018-03-26 17:27 ` [PATCH 5/9] x86, pkeys, selftests: fix pointer math Dave Hansen 2018-03-26 17:27 ` [PATCH 6/9] x86, pkeys, selftests: fix pkey exhaustion test off-by-one Dave Hansen 2018-03-26 17:27 ` [PATCH 7/9] x86, pkeys, selftests: factor out "instruction page" Dave Hansen 2018-03-26 17:27 ` [PATCH 8/9] x86, pkeys, selftests: add allow faults on unknown keys Dave Hansen 2018-03-26 17:27 ` [PATCH 9/9] x86, pkeys, selftests: add PROT_EXEC test Dave Hansen -- strict thread matches above, loose matches on Subject: below -- 2018-04-27 17:45 [PATCH 0/9] [v3] x86, pkeys: two protection keys bug fixes Dave Hansen 2018-04-27 17:45 ` [PATCH 2/9] x86, pkeys, selftests: save off 'prot' for allocations Dave Hansen 2018-03-23 18:09 [PATCH 0/9] x86, pkeys: two protection keys bug fixes Dave Hansen 2018-03-23 18:09 ` [PATCH 2/9] x86, pkeys, selftests: save off 'prot' for allocations Dave Hansen
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180326172724.ED505E4B@viggo.jf.intel.com \ --to=dave.hansen@linux.intel.com \ --cc=akpm@linux-foundation.org \ --cc=dave.hansen@intel.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=linuxram@us.ibm.com \ --cc=mingo@kernel.org \ --cc=mpe@ellerman.id.au \ --cc=shuah@kernel.org \ --cc=tglx@linutronix.de \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).