From patchwork Tue Jul 17 13:49:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10529521 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 7AA18600F4 for ; Tue, 17 Jul 2018 13:51:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60E8529203 for ; Tue, 17 Jul 2018 13:51:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 550A429221; Tue, 17 Jul 2018 13:51:09 +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 D3FD029203 for ; Tue, 17 Jul 2018 13:51:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 702F86B0275; Tue, 17 Jul 2018 09:50:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 685276B0276; Tue, 17 Jul 2018 09:50:36 -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 4D7586B0277; Tue, 17 Jul 2018 09:50:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f198.google.com (mail-qt0-f198.google.com [209.85.216.198]) by kanga.kvack.org (Postfix) with ESMTP id 1B46A6B0275 for ; Tue, 17 Jul 2018 09:50:36 -0400 (EDT) Received: by mail-qt0-f198.google.com with SMTP id j9-v6so717812qtn.22 for ; Tue, 17 Jul 2018 06:50:36 -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=cPkI2u2U7O8M9Gdq3WQJyhHpzjJb0wMlH/uI6U7yn5w=; b=Q8DTYu1eJWTJMH4hdkV+Ha8mbhgI0y2VmdsEf0XCdmjy1cjTL0E/zLM7CwLU463j1x J3QixznLTZDMO6mjRTcDCDiKcPE+CcNHLFcwipc+B4Ef0do1du2/h/mlSeDKEcgLGUxj WQerAveZ3gswuj8c4n0s1pyOsc0LcpJwh34IDjbPAWe64wjqmEKmuaLNKGkCvguG4Oyo bAeEFZzIBD9s3x7zhj5Sc9K8KkvpgPAdOaM0cWHXMXVrJNsce2qPLNov3rsToAkfpgKs 3jWcukGJx3sZAD/G0YObeE0GvlYujEb5OPZGCDkRhe4r+57HX6rV6F+vpnXybTohUJHh 8f4Q== X-Gm-Message-State: AOUpUlErU6jqrxDRnE2mEGUJ4mTHjUVGdO4a8xNixz9eQ/7zLPQYtT/G SEyXl2E4of5qsfDFkMnMAALVKJy1G2Erv9F5hV1LlaiP9sbKb9/XYrpGKBRCP6RGRRdxYTlzTSc YtIQraG5IJn3QTdxFgmgZo+NxvlWzpKK4uQyuE49qXxIvB3QshJJEumyL6Jxz1lDHAeYJvHDwac wU2I6kgAgh8p0eI6taMY6JuLkuQ3ekUFRrOfi8kE8f4betz67iwt6i243SGgc0qOHqVXX7BG/Yh JomaX8a7MXNe/1WVFdAtauDmrpYOdVL/mPti/t2RcOwg8RH7RI1OasCJ2gh62VlHadfegvpUN2y Crh8uesfqhWVAoj+g/Mcwr345bCTqovGtLZvbYznS6Oqgacuxl9ArC4MrV9p3tkqCQit1c3l3w= = X-Received: by 2002:ac8:2cb0:: with SMTP id 45-v6mr1591085qtw.29.1531835435875; Tue, 17 Jul 2018 06:50:35 -0700 (PDT) X-Received: by 2002:ac8:2cb0:: with SMTP id 45-v6mr1591029qtw.29.1531835435153; Tue, 17 Jul 2018 06:50:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531835435; cv=none; d=google.com; s=arc-20160816; b=irOUbSnyWL+4KAPWtT/WCdyeKQ+57M2Zrh/RNHd0e1m0blImFKM/MB7SOHK96byIgD ZwRCa9QudRA3uAyrj6JX3yz0iOuQUHCgVdg+P4I1+CFd6Yhjt6F3xX7QJR82vpgpTOrz ct650jFwO8fLNuLPC7pAx4VJ4a++h0kjaBSsUo8IfUB6JXhS2XfQoQZImMP8PDYk3TSz bqBw3LjBaocmMCBAXBDoijSdkbyQt5ZtMRN+mEomqhpAQU3SdD7uws8dqaSggOkFvPdV wfTWAA9wrqW1HDFYtJq3pwTHw6Q+qQAC1My+l9TkSG9/ZakboQl7HmpRSaXb3ffkIJjv fW1g== 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=cPkI2u2U7O8M9Gdq3WQJyhHpzjJb0wMlH/uI6U7yn5w=; b=fE1IpWPiQCos4JkLRcEDiCNCQ7iccK3jlJqt68Jy3RSrbtgEPXT60BNhHmRIFtkr7H xf2A7VpfMn98oIxHEYL4tAudK96hfP7u7f1kQ1vOjrbUv8B/kZ+LLsq9Ijfl8BIVZGZ0 5uNlZVEsRs9W46Z2EcgKODBbZp/rq/XpBAyUYd8jSZbrlogS8aAAsTAmjsyL4J/Hm55z UUF8IMY4uB7JltcCUU9XTJtdeDAh3m5Z8ZqCPgF98ScfskVgWQLx+HSYOv9boBt+SGHI 4Mrl//zDBTo6ANBlhY2droiw0QTjQdppMXTz4IhpheY15yW2YU+Nhpy4ZAoBttMMUOop zkOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kBL5pDi3; 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 j14-v6sor481306qvo.105.2018.07.17.06.50.35 for (Google Transport Security); Tue, 17 Jul 2018 06:50:35 -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=kBL5pDi3; 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=cPkI2u2U7O8M9Gdq3WQJyhHpzjJb0wMlH/uI6U7yn5w=; b=kBL5pDi3jg/tec4wmVkI8BpuWioEqjSHAocep6zHuj1SiuL2JslyNZrr4vdLXXEOrx jhR6CXU+dh8VsvAwwxH19R9JTT62EA1escUe+SrDAkXJgob7g7TVLl9wxk2kPfpjXtv+ IidychjyeexRCnB5p/6cNY2t6lpJfYQtOQPaDNgh+EjopADjpkFkIdpS5rEsmCW7JHvY cL1ErFJ55nuqiX4l8MY0juHLyLrYI48K6cobYpZeZHKJORR3plG3lJWRYdTqg44L1eik MxYuUakdPLibG1W9hClRVeJzRJoaPvkqg1WtfNDW99jiHGXLzTJaSQnvHG0GtOPWzBV3 KEDA== X-Google-Smtp-Source: AAOMgpdHc7exBcpx/WIOQwbsO0YEoX7yuhF7rQWWC0+UH4zoYCAeBF0YcpoGSb7VGcUjNPD58QSEyA== X-Received: by 2002:a0c:9259:: with SMTP id 25-v6mr1758849qvz.239.1531835434920; Tue, 17 Jul 2018 06:50:34 -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 s83-v6sm640937qki.20.2018.07.17.06.50.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 06:50:34 -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 v14 15/22] selftests/vm: powerpc implementation to check support for pkey Date: Tue, 17 Jul 2018 06:49:18 -0700 Message-Id: <1531835365-32387-16-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1531835365-32387-1-git-send-email-linuxram@us.ibm.com> References: <1531835365-32387-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 b0d1abe..b649e85 100644 --- a/tools/testing/selftests/vm/pkey-powerpc.h +++ b/tools/testing/selftests/vm/pkey-powerpc.h @@ -64,9 +64,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 f5d0ff2..887acf2 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 18e1bb7..d27fa5e 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1389,8 +1389,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; } @@ -1454,12 +1454,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;