Received: by 10.213.65.68 with SMTP id h4csp598382imn; Fri, 23 Mar 2018 11:15:07 -0700 (PDT) X-Google-Smtp-Source: AG47ELukqgFaWgH1ELA9aazjm8ijqiMJHKlc6y4DJ/pdtwOGEjMjzzwJxQ+eftERgNaCskfhLXT+ X-Received: by 2002:a17:902:341:: with SMTP id 59-v6mr29606206pld.407.1521828907743; Fri, 23 Mar 2018 11:15:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521828907; cv=none; d=google.com; s=arc-20160816; b=hZBFO9JJqtXG6nd1Ue+FV8rBEssEP/TNLrnzjjA7in2Cm9lHzxNReCPijNqy30w+yw nLQ21MuF9V/xDWKC9P/8gsD3DTFpviprqvkGfX4hHYegcVeOoCwBKFZc04AXkVTMyfQ5 xArv5zq/gpCcpzJDrc02TWR8k+LwA8d7dklip5KOC8vyjd67lR04yPeid9+BmgrfPXHe 6mQktHm1oBV5TsPbcLGmOD5I0r15e9aESzLx85tIi0AhNGDwOXtvKnKENAobSgZONijX BMBZwb9o0btu0hORyeEjNtOeUvHO5kGWsMlO/J99w4oQS9e30+uV2L+BeAExzpUlg+Ob mMzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:in-reply-to:references:date :from:cc:to:subject:arc-authentication-results; bh=p1msNN/cVeBP54XGhdZV8GbLYX72ln2rh6L5kP4ehYs=; b=wMMb3vg0dHxfpqxwCcyb5EpHXz2wIx2kBnPV/EkO+rHACALBdaDYDw23Dzrxl5BccQ 6mUCDbkTRIdWpi6dw+6yIPN3Pt+l6lADYIs0I9PNRoQhph56PCvp2MC6tUHi1n7NKV8C QYKkwJ4a5/itGu/J26ndAp46gFj2e78uH1Bpc9iSbuPTq/OsWla0nwFGjvgCaf1P1WNc jztjiT4bJry/Nm1pkdhyUCse62rj3Mo66FiIE7ZF94qgYCoO8HlfWOf7Z0ZEyLsRWzGs ZncmOFY1ZYo9Oq5KlSM5ys8qw5VvLU2i0h1g6Je1PvRn2Uql+cK24aJxnRRep8gROSpU JDuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si2042457plx.463.2018.03.23.11.14.53; Fri, 23 Mar 2018 11:15:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752296AbeCWSLO (ORCPT + 99 others); Fri, 23 Mar 2018 14:11:14 -0400 Received: from mga07.intel.com ([134.134.136.100]:27172 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751691AbeCWSLK (ORCPT ); Fri, 23 Mar 2018 14:11:10 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Mar 2018 11:11:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,351,1517904000"; d="scan'208";a="26495466" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.119]) by fmsmga007.fm.intel.com with ESMTP; 23 Mar 2018 11:11:08 -0700 Subject: [PATCH 2/9] x86, pkeys, selftests: save off 'prot' for allocations To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Dave Hansen , 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 From: Dave Hansen Date: Fri, 23 Mar 2018 11:09:07 -0700 References: <20180323180903.33B17168@viggo.jf.intel.com> In-Reply-To: <20180323180903.33B17168@viggo.jf.intel.com> Message-Id: <20180323180907.2CA27831@viggo.jf.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Hansen 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 Cc: Ram Pai Cc: Thomas Gleixner Cc: Dave Hansen Cc: Michael Ellermen Cc: Ingo Molnar Cc: Andrew Morton Cc: Shuah Khan --- 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-21 15:47:48.740198925 -0700 +++ b/tools/testing/selftests/x86/protection_keys.c 2018-03-21 15:47:48.743198925 -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); _