From patchwork Wed May 9 17:13:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 10390267 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 C585160236 for ; Wed, 9 May 2018 17:19:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B63132851A for ; Wed, 9 May 2018 17:19:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAB802851E; Wed, 9 May 2018 17:19:30 +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=unavailable 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 1A6C62851A for ; Wed, 9 May 2018 17:19:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C22E06B0549; Wed, 9 May 2018 13:19:04 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BD1506B054A; Wed, 9 May 2018 13:19:04 -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 AEA926B054B; Wed, 9 May 2018 13:19:04 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f197.google.com (mail-pf0-f197.google.com [209.85.192.197]) by kanga.kvack.org (Postfix) with ESMTP id 691D16B0549 for ; Wed, 9 May 2018 13:19:04 -0400 (EDT) Received: by mail-pf0-f197.google.com with SMTP id e20so26538080pff.14 for ; Wed, 09 May 2018 10:19:04 -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=3ghBQv84+GZ+iEilgXI9RxX6+ohiqOQk+KxsFDmkxIw=; b=pdvGgS/rTzUDraYlI1eqKem9CrfrFYGe366uEG23xIRMrj2lnxtBbLCFBAUzvVvAv2 IZmOUNWT+ZJH3HPEfggXDrNb1mUiRCl7syRH5Q02x8Z6onB/LVPyd6MVLy7J2PEPeWFG HEeuAG8EXcWbd4dMfnVKpiKwTscztEdmk5e+4Za5YIR1ur5ZrR43BepXiwuw1l2TxUhq rk6ORXsXumXnX1JaGtnpzJZ3Z+2fvtFOyG6eGoyIk7OvkemNtOFYpUMwhZ8/wfZNPAb1 7Fl2tzOH+6qJsz1+ZLyltJvf3KEjvOjYSMZzd0lA6sx6gzDkWNFAb6kwA5UaiTE/4YEb GTQQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=dave.hansen@linux.intel.com X-Gm-Message-State: ALQs6tDaCIHIAaUHB/dpqxbS1+Y87ICBTchTjm3zLsQE5ZIA58KTk22s aUKAoIDCclrmiQ8SFkR+Lniky1vGKGYPcN8HEpYaTIhyldGKK9pw3Gtnd/F9YijjbWF9JF5XWst C2AbuSPOmWk1g/dotfJVaceFAOd4H0cAISxTjn1lUrRM5uHf+tgdI7VM/Ur3P+47QeQ== X-Received: by 2002:a17:902:bd46:: with SMTP id b6-v6mr46417981plx.170.1525886344136; Wed, 09 May 2018 10:19:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoEt4os9m5H33+YFa5a8DerRCRL9bdgzyHYPaybrrKBJAY9YKNJyiRwRUyushi39y+yWbXC X-Received: by 2002:a17:902:bd46:: with SMTP id b6-v6mr46417934plx.170.1525886343404; Wed, 09 May 2018 10:19:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525886343; cv=none; d=google.com; s=arc-20160816; b=YobTwq3kMUCV2QujCCQBudJNT/+A3c0mCu7rJgu0dh2fbYH9UjtciqXLZ1FH0M+TDH hR8vtww+mPqP0Tp7fG/gh6g4Vd2Us5GHfHgAln6gfLsJfcUbjex/zhNoRMSXica8ZA4n Wgm9QueHOsgZADGSGQJ63Hx7KEtQokyQ06adR6dWJnfpvnHRQREA/T83J4CGk8xRPKWm dqIPn25F/ZzfqeAhmlqyY9CbrkyYKEeIJeJLIMbXwP/iPESxEfZYOhklWXFCwtBQ4QCs TcJ10PrdjPtA8+HpFXwV7zkh2G2Qyf0W8Ssgbt5QiYOjmF37hKuUSn6imCVbSXiwAvjj SrXA== 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=3ghBQv84+GZ+iEilgXI9RxX6+ohiqOQk+KxsFDmkxIw=; b=TccGbHqGJwZLKp8ZvWaWP6JneqzBrujhR24ncrqkSha4coYMxW7IyJww5+uvhaOXpK pI+ja72jaikxBJgg8LaNvBvpkXSxKThxYbyCNjwkuYpVH9nYIb1Zx4IhRyPhLX01Dofk NF9xXt8KDHZburxQ1QQAr50Y+gYJF29lsck664MpK+KoNV9JgH/EAzZIdbVFoBNau8ev jDxvBfhmWmntkkOKNmmxLo8Tp+dBCx8+zCDV3ec3WGlNSDiN8FD7Uy4kM3F5U9Id9uN1 lEs6KvdRH2ukCL6jrFA3N4DRyROXgurRHbzv/T2vE8WnJmoiTVZK1QlJLy2DTTJzeHPl Qd1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=dave.hansen@linux.intel.com Received: from mga02.intel.com (mga02.intel.com. [134.134.136.20]) by mx.google.com with ESMTPS id t127-v6si1047914pgc.519.2018.05.09.10.19.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 May 2018 10:19:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 134.134.136.20 as permitted sender) client-ip=134.134.136.20; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 134.134.136.20 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 fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2018 10:19:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,382,1520924400"; d="scan'208";a="38056871" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.119]) by fmsmga007.fm.intel.com with ESMTP; 09 May 2018 10:19:02 -0700 Subject: [PATCH 12/13] x86/pkeys/selftests: Add a test for pkey 0 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:56 -0700 References: <20180509171336.76636D88@viggo.jf.intel.com> In-Reply-To: <20180509171336.76636D88@viggo.jf.intel.com> Message-Id: <20180509171356.9E40B254@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 Protection key 0 is the default key for all memory and will not normally come back from pkey_alloc(). But, you might still want pass it to mprotect_pkey(). This check ensures that you can use pkey 0. 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 | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff -puN tools/testing/selftests/x86/protection_keys.c~pkeys-update-selftests-with-pkey-0-test tools/testing/selftests/x86/protection_keys.c --- a/tools/testing/selftests/x86/protection_keys.c~pkeys-update-selftests-with-pkey-0-test 2018-05-09 09:20:23.852698394 -0700 +++ b/tools/testing/selftests/x86/protection_keys.c 2018-05-09 09:20:23.855698394 -0700 @@ -1169,6 +1169,35 @@ void test_pkey_alloc_exhaust(int *ptr, u } } +/* + * pkey 0 is special. It is allocated by default, so you do not + * have to call pkey_alloc() to use it first. Make sure that it + * is usable. + */ +void test_mprotect_with_pkey_0(int *ptr, u16 pkey) +{ + long size; + int prot; + + assert(pkey_last_malloc_record); + size = pkey_last_malloc_record->size; + /* + * This is a bit of a hack. But mprotect() requires + * huge-page-aligned sizes when operating on hugetlbfs. + * So, make sure that we use something that's a multiple + * of a huge page when we can. + */ + if (size >= HPAGE_SIZE) + size = HPAGE_SIZE; + prot = pkey_last_malloc_record->prot; + + /* Use pkey 0 */ + mprotect_pkey(ptr, size, prot, 0); + + /* Make sure that we can set it back to the original pkey. */ + mprotect_pkey(ptr, size, prot, pkey); +} + void test_ptrace_of_child(int *ptr, u16 pkey) { __attribute__((__unused__)) int peek_result; @@ -1363,6 +1392,7 @@ void (*pkey_tests[])(int *ptr, u16 pkey) test_kernel_gup_write_to_write_disabled_region, test_executing_on_unreadable_memory, test_implicit_mprotect_exec_only_memory, + test_mprotect_with_pkey_0, test_ptrace_of_child, test_pkey_syscalls_on_non_allocated_pkey, test_pkey_syscalls_bad_args,