From patchwork Wed May 9 17:13:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 10390265 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 42FF960236 for ; Wed, 9 May 2018 17:19:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 322BB2851A for ; Wed, 9 May 2018 17:19:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24E782851E; Wed, 9 May 2018 17:19:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13F812851A for ; Wed, 9 May 2018 17:19:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71B0F6B0548; Wed, 9 May 2018 13:19:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6F2486B0549; Wed, 9 May 2018 13:19:02 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E0086B054A; Wed, 9 May 2018 13:19:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f69.google.com (mail-pg0-f69.google.com [74.125.83.69]) by kanga.kvack.org (Postfix) with ESMTP id 19D116B0549 for ; Wed, 9 May 2018 13:19:02 -0400 (EDT) Received: by mail-pg0-f69.google.com with SMTP id f6-v6so15617206pgs.13 for ; Wed, 09 May 2018 10:19:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:to:cc :from:date:references:in-reply-to:message-id; bh=eDIFVtWa/KrECm7sf+kPAJzH3lQne8WDgx1U2MVA//k=; b=U/ZgYvbtCMTkOR1aTSUVV1JExw9w2QKEx1VJp9dlzM7h6+koxvRrls0Gz4qLl629yr BLowoczrFmH3oqgHXlQ24jLhUuN/KJITwcKLptjbzhso2IjON6FOGMbZrauV1kud4qbs cLOpn7Sgr8EOlTjvtTwrgxuvlCufYVtionbRSSAgDMPc8fyfZ+kEib1uQkTesZ0Enos2 TVslA9Ir/jcF5yftRunobblrC1F4AQIZFgPqQqotGNExK44uIob1lHuha6Zzt3TlT5ea ZYg1RPquEx2/eduTeSbPgyaJQGBp3SPyegzGppwn2rLYRj1yjl/vNew86j9pFHf5qg2j bd9w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=dave.hansen@linux.intel.com X-Gm-Message-State: ALQs6tDpujasCV54tIE+rU9k+N77eBGMuC8JrYDcGddMEr86f5ssuDYo rP/r1KNY/TnzK5dR/hBlDgvFpEA9vXJKbgXD58Db7VUsI16lEJ3iylunL3MRSBhw/pblxpiXLKo 0ar8gBBXw39xK93uTBsxKG8bhmIr2tqYBfGbJ1iAnbB9nrml5IdGfPxh47m1qTd2n4Q== X-Received: by 2002:a65:5504:: with SMTP id f4-v6mr21900773pgr.177.1525886341785; Wed, 09 May 2018 10:19:01 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrRVTX3N4Q4nh3OyTRcifQAEeVKYofGl8klrAZXCWI43gnGkMBKujJNPXKAwB+OZgZCIHeE X-Received: by 2002:a65:5504:: with SMTP id f4-v6mr21900752pgr.177.1525886341024; Wed, 09 May 2018 10:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525886340; cv=none; d=google.com; s=arc-20160816; b=EItAzfMcX+A9Lfyr0gy74vji72LPPQgrFxG7I/i+BzChC4eQ1Mz8SX1B+MHjeFzf1U p3Y/7sRclQ3xHKskxZNbyH52EHF6TF+T+mU+RlVlBIzEosxjKuzpjnlDeOpUuLnecP6G ZvinkJin+Vcfts2N+Ct3PU4Nb/tzezduuOF7Sw8D3ogKW0ovKezSEB50jS5TqK51683P qXzDgfGSttq17U4myVPkNFdLXJGIpVWIn7F3rKjX0qDRK2Dodoyo7QXkLD02iAUc81lt GGbdNzyzFI1THqptZoe4+aXC0TN5jTa5JUvJOvtnnVrMD7fNmGvV6ohkBuFwHrHTBmim JgRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:in-reply-to:references:date:from:cc:to:subject :arc-authentication-results; bh=eDIFVtWa/KrECm7sf+kPAJzH3lQne8WDgx1U2MVA//k=; b=Mml13h9gaw8/g9D5Z1rinuczVnFdvbqBVKy3fgIfcwxBK8iH38eZwVf+6p354MntoB 3d5k2daDJJdHpRt6kaSMNC0WueYNaWwwXCefhb7KOQlVfZ1+LxSc1IRwUAkerbnQkpBR 1S44MHOlL0gDxqedns3ueEV/R/GhWQ20BCoqsEcmlWWOZdJqEY/EWu0pRRvr0RZhvEd2 CS6ML+7mxEpXv1RrXpdioZlQfZdVhoa0EN22H1qJ71SxciKo0/0qyYKT6EJghFr34QbL fK/T8RJqzBEFnAgwq2F/8hskuQ3uHpDTFyq0PKIWoRaACgmP85U1sWVgsUj7sZ2Gbp17 5k/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=dave.hansen@linux.intel.com Received: from mga04.intel.com (mga04.intel.com. [192.55.52.120]) by mx.google.com with ESMTPS id s196-v6si3202216pgc.567.2018.05.09.10.19.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 May 2018 10:19:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 192.55.52.120 as permitted sender) client-ip=192.55.52.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=dave.hansen@linux.intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2018 10:19:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,382,1520924400"; d="scan'208";a="53786779" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.119]) by fmsmga001.fm.intel.com with ESMTP; 09 May 2018 10:19:00 -0700 Subject: [PATCH 11/13] 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: Wed, 09 May 2018 10:13:54 -0700 References: <20180509171336.76636D88@viggo.jf.intel.com> In-Reply-To: <20180509171336.76636D88@viggo.jf.intel.com> Message-Id: <20180509171354.AA23E228@viggo.jf.intel.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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-05-09 09:20:23.340698395 -0700 +++ b/tools/testing/selftests/x86/protection_keys.c 2018-05-09 09:20:23.344698395 -0700 @@ -662,10 +662,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; @@ -697,6 +699,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++; } @@ -741,7 +745,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); @@ -762,7 +766,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); @@ -835,7 +839,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; @@ -857,7 +861,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);