Received: by 10.223.176.46 with SMTP id f43csp3255815wra; Mon, 22 Jan 2018 10:54:55 -0800 (PST) X-Google-Smtp-Source: AH8x225om9nIe/k7wt+dwIFKe2qQhKqIplu9PJCzVJEfAEPeH8TWrL3Rp4NJbc3KtcaZmBJCW7Gs X-Received: by 10.36.188.198 with SMTP id n189mr9372994ite.91.1516647295806; Mon, 22 Jan 2018 10:54:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516647295; cv=none; d=google.com; s=arc-20160816; b=oVcZrTW3WBx93QEiVc01/VpFx4RK4VuRXwLwsvXX4Upx8XPcECeludf56aPiqX0ZYl N9bD9jpffJPdrLky09zAaZLH3hYHw69BzGtrbROw0OP7vd28+EyipZF6kn7mgPDCf8XJ rggcyb7qwsNv4NQRcWmzlZddzorrPLSAJsrBtMuNghFcXk3JxlQuouj5oMYHu6xIbeu4 9kBvvpCQOfziMI7+fLCHq3GztXMDFRepK/mwXLJ7wwVHwlaLNv1puId4qRYWlKrD0Ugo TATirNJ9dByJFSHmoIXP5ye4UxymQSMOIvLufVpYzyx7xlG1Hvp/QV0PopoEEcYfYJSW t0rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Y6U7pUJ7NDlstMWM3djZSb7F9da877mbcC9sr3ZA5pU=; b=0ReW3mmdcMDVLh5yVL694AhNE4FgYidN7SjuwFjy84mjJRP2vUcFwiqm+PWSuF2BCs CH0exbsU/91IQ4UlFnRQdaMTrsaykwUQ2mVl+U4L7tlKZ6p0ne11AUn8rZGj2AQLQtDZ nrMI8I/lis/xamfDxE1v48e6mBlJfITRqTjLZqbsfgjwzAWh5UaMNzoD7wIQLHHkBVNB qO4ymsBM29hAr55zddwbWtBRUs0aFZQDpSxaY29Rzz44dpZkkWDJNO6Wh6SvjrMa9S+N WmI968uHUM79/i5Wk+CW900V0ljgXr79V/W3TXER/x63TNOOaUjN8YnGWWrwylE+kLBz dM/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=A+f1qaxU; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p7si13039820iof.29.2018.01.22.10.54.43; Mon, 22 Jan 2018 10:54:55 -0800 (PST) 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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=A+f1qaxU; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751497AbeAVSxg (ORCPT + 99 others); Mon, 22 Jan 2018 13:53:36 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:36984 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751459AbeAVSxc (ORCPT ); Mon, 22 Jan 2018 13:53:32 -0500 Received: by mail-qt0-f195.google.com with SMTP id d54so23490323qtd.4; Mon, 22 Jan 2018 10:53:31 -0800 (PST) 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=Y6U7pUJ7NDlstMWM3djZSb7F9da877mbcC9sr3ZA5pU=; b=A+f1qaxUpMCoRfpYOn27z871qNcY6HF2bNH+sovI0GcN86WL62n+MiFzHCV4+bAtqq hOtjTT7/LNx06FJOY5P70/1QkYPMzCzN9PMGfoHWJI33F8jMGLMc8qI30Z9v79BGYdnR FmQM86tsJZ6sRGyPVPVyDAHEABZU4h+9UIQlVnAr+SdSG3a5qucakRx1vdeHSq2FRSK6 3/IVbgPlNNrWX8/PJQbhKwAHYlJK1qp/KXqpHawyBKwy8PrNw3uViV0SFI9E6cBH1Q84 dDrjhp4WHHdgAREPasLN8naimLiP7/MC+8kQQYOyIiTAq+weD+sCmiz0zzSt7qdQcbRv hAtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Y6U7pUJ7NDlstMWM3djZSb7F9da877mbcC9sr3ZA5pU=; b=mGdjq88HGEzaU7wZ+7VLzbsZxMUYv+F4yVJuUW2FrCaB7QPAAQ5Wub4zvffU+8invO hCsviMBQlA93cK7XLkhRYSeXxk+kHgsOALmmDyVNM8C3+95EPNP6K0x6YLydtPGRfZsI ovDMiWrMNU1f5DqzlOVsEQ7zKwDU4Lt2Hykq+zWS6ZhDpHkYh001U8UDbIp6CjHJJ5Nt FD23OEJt+den45Nij/NacbV3K+MRTtHWvboZNXq75CKFa8e/qOSB+OpiArmyskAWuCQN AFzlKp/oHavh8H3UDkZrM3q9TnhphGKGcXB/TUS9gya5kSaReB101a9Iqs63ZkqftoTR 3s2Q== X-Gm-Message-State: AKwxytf24V1A9nU5I0V3ZrzmcJ3+meaLoiw7/bksuDRe3RMidwsdRPmT QjiVrXQ257052yBpodqxhSo= X-Received: by 10.237.45.225 with SMTP id i88mr11813904qtd.196.1516647211606; Mon, 22 Jan 2018 10:53:31 -0800 (PST) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id o20sm10790061qkl.14.2018.01.22.10.53.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jan 2018 10:53:31 -0800 (PST) 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, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, akpm@linux-foundation.org, dave.hansen@intel.com, benh@kernel.crashing.org, paulus@samba.org, khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com, hbabu@us.ibm.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, ebiederm@xmission.com, linuxram@us.ibm.com, arnd@arndb.de Subject: [PATCH v10 15/24] selftests/vm: powerpc implementation to check support for pkey Date: Mon, 22 Jan 2018 10:52:08 -0800 Message-Id: <1516647137-11174-16-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1516647137-11174-1-git-send-email-linuxram@us.ibm.com> References: <1516647137-11174-1-git-send-email-linuxram@us.ibm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org pkey subsystem is supported if the hardware and kernel has support. We determine that by checking if allocation of a key succeeds or not. Signed-off-by: Ram Pai --- tools/testing/selftests/vm/pkey-helpers.h | 22 ++++++++++++++++------ tools/testing/selftests/vm/protection_keys.c | 9 +++++---- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/vm/pkey-helpers.h b/tools/testing/selftests/vm/pkey-helpers.h index cfc1a18..3559527 100644 --- a/tools/testing/selftests/vm/pkey-helpers.h +++ b/tools/testing/selftests/vm/pkey-helpers.h @@ -261,7 +261,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; @@ -274,13 +274,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) @@ -326,9 +326,19 @@ static inline void __page_o_noops(void) #elif __powerpc64__ /* arch */ #define PAGE_SIZE (0x1UL << 16) -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; } /* 8-bytes of instruction * 16384bytes = 1 page */ diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index d1cbdfe..65e6dd6 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1299,8 +1299,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; } @@ -1362,12 +1362,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; -- 1.7.1