Received: by 10.213.65.68 with SMTP id h4csp597287imn; Fri, 23 Mar 2018 11:13:31 -0700 (PDT) X-Google-Smtp-Source: AG47ELsiXeqkEhaLc9pAQL+WvqjEXAu3z00ezwH4ec2CXnxEPxdWzLDhPPuO9U59TbTWyXVyG1QV X-Received: by 2002:a17:902:8f8c:: with SMTP id z12-v6mr21174800plo.400.1521828811730; Fri, 23 Mar 2018 11:13:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521828811; cv=none; d=google.com; s=arc-20160816; b=cZz8tGlK9C2Ftd4+MJJaifcPAE0NhU4l/FgIM8m23Cumg/DTXWH/L7J/n0CVvNCLQ+ zg+6GZujaPjujP3tg2NzhdklSuIRyzJm/JkFChOmONZYKLcphiVUzUH3TkrPzJqv6bt+ K/XBbsaxv6OyFmfA74L6V1cQgV9RAUNvaqwkL2s+Piv8SeN/2o0dJwNIfLwfrIgKOWe3 dEGVOopJ9Xv0wgnLfgzvZEPhpLAs351MeFhg+wRCoMOVvtccwjGl1H8BOSrWrveKkypv HNrfVYnkMD0W/zykHlkjsKyF1gQmRrtgO0UeB6T67zWv4BlFec0jerRsP9SXgls/LhZn Tokw== 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=iMHuVar/QbZwnfVxd9XQGofCSgLE7+x3AimNbQBfPlc=; b=gka5oSMUG4NoDsKymcnPMh16NENlqtT3WXNYSZD6ZqjorJyd6JxfI4kuRhsBY7ZAYs I89roEXrG1fgvphBg1vM8E/RG1pUqIXVJTseBnVbf1/0NPdydB793V69gIsZVwPCzF5T IABdR1qiGBm1JUpkj5tFcuo7jQkW6ruJ1F3QhSM5ieqsq+pDkCFbtDBa7KxjQWEhFnkj zrEmYj6qhLpEo3ov9LKPU6DFv+NgmFjkF5yBdV1NvKHT1EyxvS22L/a8n0ZGNw+iPytE u93CRu6kLSx2vo291mYZ7O+XwGGNblirk2EFQV3WNQd12YLrBAm7zQYMOKRyq38U9wee vwEQ== 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 70-v6si9133903ple.639.2018.03.23.11.13.17; Fri, 23 Mar 2018 11:13:31 -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 S1752534AbeCWSLy (ORCPT + 99 others); Fri, 23 Mar 2018 14:11:54 -0400 Received: from mga04.intel.com ([192.55.52.120]:12722 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752334AbeCWSLR (ORCPT ); Fri, 23 Mar 2018 14:11:17 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Mar 2018 11:11:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,351,1517904000"; d="scan'208";a="27915673" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.119]) by orsmga008.jf.intel.com with ESMTP; 23 Mar 2018 11:11:16 -0700 Subject: [PATCH 7/9] 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: Fri, 23 Mar 2018 11:09:15 -0700 References: <20180323180903.33B17168@viggo.jf.intel.com> In-Reply-To: <20180323180903.33B17168@viggo.jf.intel.com> Message-Id: <20180323180915.F551A7C4@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 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-03-21 15:47:51.447198918 -0700 +++ b/tools/testing/selftests/x86/protection_keys.c 2018-03-21 15:47:51.450198918 -0700 @@ -1277,12 +1277,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); @@ -1292,7 +1289,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); _