From patchwork Wed May 9 17:13:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 10390249 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 ED48E60236 for ; Wed, 9 May 2018 17:19:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD0762851A for ; Wed, 9 May 2018 17:19:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D16A82851E; Wed, 9 May 2018 17:19:07 +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 BE2E52851D for ; Wed, 9 May 2018 17:19:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0E476B0543; Wed, 9 May 2018 13:18:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C97B26B0544; Wed, 9 May 2018 13:18:54 -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 B3AAE6B0545; Wed, 9 May 2018 13:18:54 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f198.google.com (mail-pf0-f198.google.com [209.85.192.198]) by kanga.kvack.org (Postfix) with ESMTP id 6DF9E6B0543 for ; Wed, 9 May 2018 13:18:54 -0400 (EDT) Received: by mail-pf0-f198.google.com with SMTP id x21so9816008pfn.23 for ; Wed, 09 May 2018 10:18:54 -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=bqy7egUNEPqpmniJJlQJYI2R9AMzk0Wsp/cfCLdJEfU=; b=ISYZDEzLsB9Fw6r/okJZeyjT2OYzc1x4+w4pgq7N+p4E+Y1vCmDZhmg5FT9J1Li/Vb z2OtZLE2PNSA8ixMgfFVA0gmWjpHy4ap2zfG/wIj4DsiL3veizbNG2lRzeFkokaX+vfw /yyXA7F/l4HuE6xOJFdFYph/4IjIxyKZlDi0S97nDbDOC6KN5fkQTEqEB13gftUmmsTJ F9gbgGfqx0pLLRiexAiyc2/4hcfLHCmX8wMvPMKN5Eu30FbtCwCu0KkFGFoFEShm1tNf s1mIrBP+cmvH2vrMHzNO6dRY7SvOLp0OLs0LRHjlluNqlIjfCOt95Wvt+YM+BHuehP/Y u+9w== 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.31 as permitted sender) smtp.mailfrom=dave.hansen@linux.intel.com X-Gm-Message-State: ALQs6tC58o1JTpKK1XALpPYcJrIVsv27K84LvaEW7jNdULiqv9NJ8JK0 sUemt1q8qUEmgtlH+xqQ2xkFHhpIpOErxzC6Zkyx2kv30EkP9l1cmBoNrUBxzZagtj9JgU8UE1L 5EmOMj6jICdSnzXHGock/FBHz5+bDrXaGbjE8jW6cFFmpI3Y9+jv1MRTlzjBxZnfPzw== X-Received: by 10.98.72.29 with SMTP id v29mr38937496pfa.57.1525886334132; Wed, 09 May 2018 10:18:54 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpiisyinFuZF0fGq9wLAt5/uzpn2Rk3Um50sY1I5Iud3HKbeKO7gsaCmATW60zZTZCeg10L X-Received: by 10.98.72.29 with SMTP id v29mr38937455pfa.57.1525886333224; Wed, 09 May 2018 10:18:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525886333; cv=none; d=google.com; s=arc-20160816; b=B+DjJiZHVQEYtd4vez+udT85Br7UuRdXEV7pQY9ZwVWZfuXod+EjeLfY/HkZzwvVPb am1v60ZZ+7wgWo/+NQIkOmsFsyh96tQyFvChgRhgHk/VtIT9muWlcgFTHFlUAY853p06 vAMwYIKQCMedAUr84TK+4yGC/d2tmzB9zx8wCNHcA70GEBrWV0p8ly2cv6gtoDDLzM8z Re8RdWL5P5hNcE639i3vcgCKbifjZLADrnQqauPSaSGGhCniB4rJ6RKC/lCksImENfOZ ZXKhYbra1HwlM0xGubMZoWh8o0tvN1c3Mw4QGtsfCc8p8sRydCjhqLQfUYx39IHlkZ7x uSVg== 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=bqy7egUNEPqpmniJJlQJYI2R9AMzk0Wsp/cfCLdJEfU=; b=RGvpRtpmko1qPZzYN89uemH0Pjk+kiqCuLZl0NSf0DnLdIg+xNf1qVBlRUIIespiRa 8d3VbW0QNFPZHRtCk328K13z5owataSYKwWUXQW2Kc2zKONYitON1fE2RJGLezWm/ghW J74HnU6mLWjhzmHz8S2QQiT+AhfAZG1iMZfgTeXSOkksF8a3KIpJfLHgPaS2XnxIpmM5 mCPgMvPDyz4kNpbhGu41e60UUXPvgHR1Uj7tPDKxaY7ERSSct7Csr0wseyfLvQ+tSu9D ArxO/qFm9j+QFVyuPRo1WvqtPme1PdI5vYyEoYXvyWBS8W7rDDDpaRjRYA1AbRt01HMz R0jQ== 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.31 as permitted sender) smtp.mailfrom=dave.hansen@linux.intel.com Received: from mga06.intel.com (mga06.intel.com. [134.134.136.31]) by mx.google.com with ESMTPS id l22-v6si21891155pgn.74.2018.05.09.10.18.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 May 2018 10:18:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 134.134.136.31 as permitted sender) client-ip=134.134.136.31; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 134.134.136.31 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 orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2018 10:18:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,382,1520924400"; d="scan'208";a="57270839" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.119]) by orsmga002.jf.intel.com with ESMTP; 09 May 2018 10:18:52 -0700 Subject: [PATCH 06/13] x86/pkeys/selftests: Factor out "instruction page" 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:47 -0700 References: <20180509171336.76636D88@viggo.jf.intel.com> In-Reply-To: <20180509171336.76636D88@viggo.jf.intel.com> Message-Id: <20180509171347.C64AB733@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 We currently have an execute-only test, but it is for the explicit mprotect_pkey() interface. We will soon add a test for the implicit mprotect(PROT_EXEC) enterface. We need this code in both tests. 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 | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff -puN tools/testing/selftests/x86/protection_keys.c~pkeys-selftests-get_pointer_to_instructions tools/testing/selftests/x86/protection_keys.c --- a/tools/testing/selftests/x86/protection_keys.c~pkeys-selftests-get_pointer_to_instructions 2018-05-09 09:20:20.764698402 -0700 +++ b/tools/testing/selftests/x86/protection_keys.c 2018-05-09 09:20:20.767698402 -0700 @@ -1238,12 +1238,9 @@ void test_ptrace_of_child(int *ptr, u16 free(plain_ptr_unaligned); } -void test_executing_on_unreadable_memory(int *ptr, u16 pkey) +void *get_pointer_to_instructions(void) { void *p1; - int scratch; - int ptr_contents; - int ret; p1 = ALIGN_PTR_UP(&lots_o_noops_around_write, PAGE_SIZE); dprintf3("&lots_o_noops: %p\n", &lots_o_noops_around_write); @@ -1253,7 +1250,23 @@ void test_executing_on_unreadable_memory /* Point 'p1' at the *second* page of the function: */ p1 += PAGE_SIZE; + /* + * Try to ensure we fault this in on next touch to ensure + * we get an instruction fault as opposed to a data one + */ madvise(p1, PAGE_SIZE, MADV_DONTNEED); + + return p1; +} + +void test_executing_on_unreadable_memory(int *ptr, u16 pkey) +{ + void *p1; + int scratch; + int ptr_contents; + int ret; + + p1 = get_pointer_to_instructions(); lots_o_noops_around_write(&scratch); ptr_contents = read_ptr(p1); dprintf2("ptr (%p) contents@%d: %x\n", p1, __LINE__, ptr_contents);