From patchwork Thu Jun 14 00:45:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10463107 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 1FF6D603EE for ; Thu, 14 Jun 2018 00:47:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12DFB28988 for ; Thu, 14 Jun 2018 00:47:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0732528BA8; Thu, 14 Jun 2018 00:47:50 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID 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 8C32528988 for ; Thu, 14 Jun 2018 00:47:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF5556B0280; Wed, 13 Jun 2018 20:47:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BA4706B0282; Wed, 13 Jun 2018 20:47:19 -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 A47136B0283; Wed, 13 Jun 2018 20:47:19 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f197.google.com (mail-qt0-f197.google.com [209.85.216.197]) by kanga.kvack.org (Postfix) with ESMTP id 755BE6B0280 for ; Wed, 13 Jun 2018 20:47:19 -0400 (EDT) Received: by mail-qt0-f197.google.com with SMTP id n10-v6so3286381qtp.11 for ; Wed, 13 Jun 2018 17:47:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:sender:from:to:cc:subject:date :message-id:in-reply-to:references; bh=pijILdgMLnQtvi0ETCeqbqJ8yE5z7l6/T13tWuI7bLM=; b=UIcibC4ah0z9sKcumrStwN3KKXbzAKY/L5SoMfVGGXii73i65NP1V6HOCKoevu+U5v bfIFuGb68OANwZswdUUOChdpwKW7Yssbs+MrwSg4LSx9GVQVqTKPRcLkdnaz5RzeE1vE gln1EGruZU3+K5A7/+48TEICWx+wF4oA9uNsIt2mR71LDJS8phdOJAijTw8+S4fQk1hP artcnibOdRk/YU51blKECI3SUxS4zdFH4CisUA8gowlzM+wNeqDtffWpDArOIypS0XFM YSE68mOYOjMBogX0aRRvD/Bal0S0cCtdopfKoNiygQ+N3Ueop4ohxYBmdaGrgpz7X3U1 RrTw== X-Gm-Message-State: APt69E35oY0NUSo467YTmixCH23sa9/VIpcaYTP9pGEOPZS0QUwt91NA Jx4k03og8xtsvaBtoM0pmJd0zertpBbtOR0ECBP+czF5bPu/Kx0g9ffqmKw93LB8j9h+DtpzEso nb2dxjzFvIeXTWi73CjYCIR706qsnW2pMxHrL8R/lktYOvqSe6IJ4N5HhP9IvL0xGMJdWWuzODJ KviFFs1Lidq78qDSiX+0h3lmUEAgYK320kCLxsgiq1OXUPZAkz4K2mrU+fYP8LsPX30XurnRdaM HVE1ISlaQ7kmtEJPdraPi/GazQoiw8YhzzHfvkvO2XgEZM1EanXyxdXeq5amnbvJk4nqrojnIRr LBQuavxZk0jznmStBZ2K+GKa9jTg3TNyMsZR32y2J8gHFFC05cvAola3jYTy3fDgAcWeCeTXnA= = X-Received: by 2002:a0c:d895:: with SMTP id q21-v6mr359323qvj.71.1528937239274; Wed, 13 Jun 2018 17:47:19 -0700 (PDT) X-Received: by 2002:a0c:d895:: with SMTP id q21-v6mr359292qvj.71.1528937238635; Wed, 13 Jun 2018 17:47:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528937238; cv=none; d=google.com; s=arc-20160816; b=ygOqei9rH1xgm0h/sElwGaEd1S9I6uJz9RWFb1I+NNCtlgGDi+ezqvWgVNdHXpIP9h sdtHxqQD0XgTzCV4PQohiFKXpYKQ62ziPFhUKLRNx1bygue6AH1V6q49MSRrPEewknbu OBwDKhuBIKhIF2g6B12zkBg4IdF5cVqzPzE13QEzPU19oz2zmtoGO8Mz0C0cL6lZrBck 3+kqgEnJwG+Ux8br4MnZpVCHtva3CbCJBtRtva5GKbPI9yJiKom9m2crI8yjcgPuEgJW Avil2t2xQxyGg3kPS0h+t4fnuALx7ArydDqUkDx4m/u3v7tTpjhpN8e/hhTeIvwstz7h ge7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature:arc-authentication-results; bh=pijILdgMLnQtvi0ETCeqbqJ8yE5z7l6/T13tWuI7bLM=; b=O4tDGW2vfVQrxEWC2/LBPI2oyPie+ZtI8qGIPb6lzDcIYXSPZCHQeK0Z+Jrqtg5c7A W80uCEzCz8tYdoR077aOIqarYWWnHX0V9ImkyaMas013yc4M6lzNbj7xTpbQSmQXglNS HfMuunOd34JAHLUw3oC8H109F+apkmeIHKQ/+TgjLHoJum35Z9rFS4B7IrMLqlluYYy8 iegUycZz2ZT3jV9vqevcYJ1ARF7j6riEdjex2Yw9yrMTXmvslYjA2D9NvWJnY2fs9qfb 2si3hMb3CEnObeGvpdP4SJTtt+9WNGUEolXfxdDUipw/PnfmaX5qe9fElmUVZtrwmBI+ DcsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iTP1fSmJ; spf=pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ram.n.pai@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id z7-v6sor1603370qki.25.2018.06.13.17.47.18 for (Google Transport Security); Wed, 13 Jun 2018 17:47:18 -0700 (PDT) Received-SPF: pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iTP1fSmJ; spf=pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ram.n.pai@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=pijILdgMLnQtvi0ETCeqbqJ8yE5z7l6/T13tWuI7bLM=; b=iTP1fSmJR2QnDzE8HPsVHPs83TB+kxyVrG34OBQ/Nn8EzDvQkh+yViV7znqM1UGvzd mbBQsOefXZyBHQjeEq5bwD7R1FY5iu4IV6TBQVrl+gG9EYgDIYCib7I74DyJ1SfdtvHj A+8/e8tcqW8q9QqduetnFpq6aQoW70tmmFObXY6dlQS87Jmer1NZAQvJuoyrScJy/TBn jZrzGA3OyLlrqqfJAaBki3bIVSY/UeXmdK7iTiNYezt+i2kOB8Cck0Xm3udBTr0VKUpD 2lSPsm3DtX0jZvwCtQhST3zGNjo7uRofbZVaEzq8t/SSaFUJauhsmt1SlhfOSrzHoTqC xIZQ== X-Google-Smtp-Source: ADUXVKIUhKLpLFqPyEVuFQMMpjoAEN0R7bRXjvWddQ5nRpY/VQsLzE//FAz9BnxR353vw6j5CF6l3A== X-Received: by 2002:a37:8fc3:: with SMTP id r186-v6mr352677qkd.27.1528937238383; Wed, 13 Jun 2018 17:47:18 -0700 (PDT) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id u31-v6sm3225898qtc.28.2018.06.13.17.47.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 17:47:17 -0700 (PDT) From: Ram Pai To: shuahkh@osg.samsung.com, linux-kselftest@vger.kernel.org Cc: mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, mingo@redhat.com, dave.hansen@intel.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, linuxram@us.ibm.com, fweimer@redhat.com, msuchanek@suse.de, aneesh.kumar@linux.vnet.ibm.com Subject: [PATCH v13 17/24] selftests/vm: powerpc implementation to check support for pkey Date: Wed, 13 Jun 2018 17:45:08 -0700 Message-Id: <1528937115-10132-18-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1528937115-10132-1-git-send-email-linuxram@us.ibm.com> References: <1528937115-10132-1-git-send-email-linuxram@us.ibm.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 pkey subsystem is supported if the hardware and kernel has support. We determine that by checking if allocation of a key succeeds or not. cc: Dave Hansen cc: Florian Weimer Signed-off-by: Ram Pai --- tools/testing/selftests/vm/pkey-helpers.h | 2 ++ tools/testing/selftests/vm/pkey-powerpc.h | 14 ++++++++++++-- tools/testing/selftests/vm/pkey-x86.h | 8 ++++---- tools/testing/selftests/vm/protection_keys.c | 9 +++++---- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/vm/pkey-helpers.h b/tools/testing/selftests/vm/pkey-helpers.h index 321bbbd..288ccff 100644 --- a/tools/testing/selftests/vm/pkey-helpers.h +++ b/tools/testing/selftests/vm/pkey-helpers.h @@ -76,6 +76,8 @@ static inline void sigsafe_printf(const char *format, ...) __attribute__((noinline)) int read_ptr(int *ptr); void expected_pkey_fault(int pkey); +int sys_pkey_alloc(unsigned long flags, u64 init_val); +int sys_pkey_free(unsigned long pkey); #if defined(__i386__) || defined(__x86_64__) /* arch */ #include "pkey-x86.h" diff --git a/tools/testing/selftests/vm/pkey-powerpc.h b/tools/testing/selftests/vm/pkey-powerpc.h index ec6f5d7..957f6f6 100644 --- a/tools/testing/selftests/vm/pkey-powerpc.h +++ b/tools/testing/selftests/vm/pkey-powerpc.h @@ -62,9 +62,19 @@ static inline void __write_pkey_reg(pkey_reg_t pkey_reg) pkey_reg); } -static inline int cpu_has_pku(void) +static inline bool is_pkey_supported(void) { - return 1; + /* + * No simple way to determine this. + * Lets try allocating a key and see if it succeeds. + */ + int ret = sys_pkey_alloc(0, 0); + + if (ret > 0) { + sys_pkey_free(ret); + return true; + } + return false; } static inline int arch_reserved_keys(void) diff --git a/tools/testing/selftests/vm/pkey-x86.h b/tools/testing/selftests/vm/pkey-x86.h index 95ee952..6820c10 100644 --- a/tools/testing/selftests/vm/pkey-x86.h +++ b/tools/testing/selftests/vm/pkey-x86.h @@ -105,7 +105,7 @@ static inline void __cpuid(unsigned int *eax, unsigned int *ebx, #define X86_FEATURE_PKU (1<<3) /* Protection Keys for Userspace */ #define X86_FEATURE_OSPKE (1<<4) /* OS Protection Keys Enable */ -static inline int cpu_has_pku(void) +static inline bool is_pkey_supported(void) { unsigned int eax; unsigned int ebx; @@ -118,13 +118,13 @@ static inline int cpu_has_pku(void) if (!(ecx & X86_FEATURE_PKU)) { dprintf2("cpu does not have PKU\n"); - return 0; + return false; } if (!(ecx & X86_FEATURE_OSPKE)) { dprintf2("cpu does not have OSPKE\n"); - return 0; + return false; } - return 1; + return true; } #define XSTATE_PKEY_BIT (9) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index ba184ca..cb81a47 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1393,8 +1393,8 @@ void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey) int size = PAGE_SIZE; int sret; - if (cpu_has_pku()) { - dprintf1("SKIP: %s: no CPU support\n", __func__); + if (is_pkey_supported()) { + dprintf1("SKIP: %s: no CPU/kernel support\n", __func__); return; } @@ -1458,12 +1458,13 @@ void run_tests_once(void) int main(void) { int nr_iterations = 22; + int pkey_supported = is_pkey_supported(); setup_handlers(); - printf("has pkey: %d\n", cpu_has_pku()); + printf("has pkey: %s\n", pkey_supported ? "Yes" : "No"); - if (!cpu_has_pku()) { + if (!pkey_supported) { int size = PAGE_SIZE; int *ptr;