Received: by 10.223.164.200 with SMTP id h8csp928946wrb; Mon, 6 Nov 2017 01:09:05 -0800 (PST) X-Google-Smtp-Source: ABhQp+SH0xd84Zc0FMzVOvD3+Yi0p8gn6jG6rRoCmPp7GvuThK4jDkAqAds7p6SALMQYiXedSMy7 X-Received: by 10.101.96.68 with SMTP id b4mr14456031pgv.155.1509959345163; Mon, 06 Nov 2017 01:09:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509959345; cv=none; d=google.com; s=arc-20160816; b=cq78eIGc+RIkMflS9/qr9vGWFJ0uCry4Jxcx3j7c77gL9VKFlZBD7pduxNFPyQu9oU NB4nOn20rJ+mMYwPVAqtTxzszttSy1XPCdkS4J/KJrCE2zRRUJ8KKks7h5J2nf1bP8sV GfV0Swxurd2HrQWcka59hyQCxCFNkcM+CLIwmzzVcyUoI52q/qfAafkkOPOqaGb2PtbR xE0ceUrs/tJ6/yH+Hxy8rRL7vHkG8wtzu6VwwxrsJBfiYkKVzajfp9PnDV0m02C5OXWS 7Iauc1UwcKW3mlyaRtzqyWq4O76NygzeC6CCRR86akkDyP9X99prcoworvBN5PbbMHB/ JZog== 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=QNpzkAPKYCky72x3zVp6D60kC/IpHV0d01TTi7lmA8A=; b=d7+PA8cTnbfCQP3AFBs6TYdSO81sC174OUlFx39/XioWRK1voUYz5Lv53BcpfOunhv o/smMD6KuC8elUA1oXkLdvSSgybx5EgiNqn4dYQII2EPUGiB5WZ4BiePZQgZ9Ezlpwti 6Uw+iTIwzkT9bI0OUuSeHcKipOw+AH2url8LWyD/hPJMbIjGmuA7ei/boYghrDX72tC4 8/7uPk+/XtJakEnn0xuYwrl0SBYOLyyU+ZMW9eIEbGcc7VAxWxS8/1IVttHIMF7dAwRG OPA2RSbbYEauRSp3Ow/HtiI7w8+tLLAyUZ/9KauWW4V17Y2scgiBWaAUnTR1l0X44C2k QgBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=eOe1PrjM; 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 n14si11079704pgr.11.2017.11.06.01.08.51; Mon, 06 Nov 2017 01:09:05 -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=eOe1PrjM; 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 S1752693AbdKFJIM (ORCPT + 98 others); Mon, 6 Nov 2017 04:08:12 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:47484 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752260AbdKFJAA (ORCPT ); Mon, 6 Nov 2017 04:00:00 -0500 Received: by mail-qt0-f195.google.com with SMTP id z50so10009562qtj.4; Mon, 06 Nov 2017 00:59:59 -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=QNpzkAPKYCky72x3zVp6D60kC/IpHV0d01TTi7lmA8A=; b=eOe1PrjMUps+4PSivPSwN8cvLOcyInPu1T3ljFeYZa1AbMwCggQzAsr3aDCdw2hvql zNbbQgsI+dgOMuOlBvcuQWntTSkpP7r9Ksh0WYnpC2grYfRzTtSoZyYo5MgmE14B7Lp1 ITNlmzZjQ/0wG8rXPtOjj5cToG7hYa9YvQ+RjOkJmOzL/vmepwTFPA6JCelXrxpvJq2L X+uBXWAzf2cak4OUq42Ih/vCrRAIFmKqOctvXiTQs1lXU3WFkOnVs6kSMkklkQC+N/+N 5hWI+BW8tcVp5Erx1KUly3vSe3Tk8wY34IgmgLrYrW42eVG+e05PlQ00imB8Su/MazzV QJJw== 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=QNpzkAPKYCky72x3zVp6D60kC/IpHV0d01TTi7lmA8A=; b=rdpgYrL2WCrQaLfN4GttG8+JpqTu9VV3l6IYEaymcQgJDoZzSUsYhdjEKjkWRBVYqA vFw3NI6t2WSAQl0hzMUyMIBoTf/eB1wP0/+iLxxa4FRrq0KS7NqbUik7MNrQL1IRsBln L7XcXx3naJLC/x5ibw16LgD550J6J/uAJ0VZt32APBFbfZUAk9U+rIhqm3rk4BFnyGGo 08+SSSVXFodK7Nxe8xk22zutY9q3rvCjC30dC9NqqV3VtNtxTBkfTC6UlXwkKJ89DI6d O7GL3SWUKMyrJmnaiEoxhhvO7lyEVuvS1u5ajCZorwQcyNxhm7HX0hFYEy7XfZ3aqDDV zXtg== X-Gm-Message-State: AMCzsaXnNA72DuHeoEJi9yy9pZul0FhMISRKBzL+9lxk57zKMJGXJZ7Y 8U76+ySkmcjqWreooKY4Hyo= X-Received: by 10.200.36.150 with SMTP id s22mr22123284qts.237.1509958799549; Mon, 06 Nov 2017 00:59:59 -0800 (PST) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id r26sm8001094qki.42.2017.11.06.00.59.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 00:59:59 -0800 (PST) From: Ram Pai To: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org, corbet@lwn.net, arnd@arndb.de Cc: linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.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 Subject: [PATCH v9 36/51] selftest/vm: generic function to handle shadow key register Date: Mon, 6 Nov 2017 00:57:28 -0800 Message-Id: <1509958663-18737-37-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1509958663-18737-1-git-send-email-linuxram@us.ibm.com> References: <1509958663-18737-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 helper functions to handler shadow pkey register Signed-off-by: Ram Pai --- tools/testing/selftests/vm/pkey-helpers.h | 27 ++++++++++++++++++++ tools/testing/selftests/vm/protection_keys.c | 34 ++++++++++++++++--------- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/vm/pkey-helpers.h b/tools/testing/selftests/vm/pkey-helpers.h index b03f7e5..d521f53 100644 --- a/tools/testing/selftests/vm/pkey-helpers.h +++ b/tools/testing/selftests/vm/pkey-helpers.h @@ -44,6 +44,33 @@ #define DEBUG_LEVEL 0 #endif #define DPRINT_IN_SIGNAL_BUF_SIZE 4096 + +static inline u32 pkey_to_shift(int pkey) +{ + return pkey * PKEY_BITS_PER_PKEY; +} + +static inline pkey_reg_t reset_bits(int pkey, pkey_reg_t bits) +{ + u32 shift = pkey_to_shift(pkey); + + return ~(bits << shift); +} + +static inline pkey_reg_t left_shift_bits(int pkey, pkey_reg_t bits) +{ + u32 shift = pkey_to_shift(pkey); + + return (bits << shift); +} + +static inline pkey_reg_t right_shift_bits(int pkey, pkey_reg_t bits) +{ + u32 shift = pkey_to_shift(pkey); + + return (bits >> shift); +} + extern int dprint_in_signal; extern char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE]; static inline void sigsafe_printf(const char *format, ...) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index 2e8de01..8e2e277 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -374,7 +374,7 @@ u32 pkey_get(int pkey, unsigned long flags) __func__, pkey, flags, 0, 0); dprintf2("%s() raw pkey_reg: %x\n", __func__, pkey_reg); - shifted_pkey_reg = (pkey_reg >> (pkey * PKEY_BITS_PER_PKEY)); + shifted_pkey_reg = right_shift_bits(pkey, pkey_reg); dprintf2("%s() shifted_pkey_reg: %x\n", __func__, shifted_pkey_reg); masked_pkey_reg = shifted_pkey_reg & mask; dprintf2("%s() masked pkey_reg: %x\n", __func__, masked_pkey_reg); @@ -397,9 +397,9 @@ int pkey_set(int pkey, unsigned long rights, unsigned long flags) /* copy old pkey_reg */ new_pkey_reg = old_pkey_reg; /* mask out bits from pkey in old value: */ - new_pkey_reg &= ~(mask << (pkey * PKEY_BITS_PER_PKEY)); + new_pkey_reg &= reset_bits(pkey, mask); /* OR in new bits for pkey: */ - new_pkey_reg |= (rights << (pkey * PKEY_BITS_PER_PKEY)); + new_pkey_reg |= left_shift_bits(pkey, rights); __wrpkey_reg(new_pkey_reg); @@ -430,7 +430,7 @@ void pkey_disable_set(int pkey, int flags) ret = pkey_set(pkey, pkey_rights, syscall_flags); assert(!ret); /*pkey_reg and flags have the same format */ - shadow_pkey_reg |= flags << (pkey * 2); + shadow_pkey_reg |= left_shift_bits(pkey, flags); dprintf1("%s(%d) shadow: 0x%016lx\n", __func__, pkey, shadow_pkey_reg); @@ -465,7 +465,7 @@ void pkey_disable_clear(int pkey, int flags) ret = pkey_set(pkey, pkey_rights, 0); /* pkey_reg and flags have the same format */ - shadow_pkey_reg &= ~(flags << (pkey * 2)); + shadow_pkey_reg &= reset_bits(pkey, flags); pkey_assert(ret >= 0); pkey_rights = pkey_get(pkey, syscall_flags); @@ -523,6 +523,21 @@ int sys_pkey_alloc(unsigned long flags, unsigned long init_val) return ret; } +void pkey_setup_shadow(void) +{ + shadow_pkey_reg = __rdpkey_reg(); +} + +void pkey_reset_shadow(u32 key) +{ + shadow_pkey_reg &= reset_bits(key, 0x3); +} + +void pkey_set_shadow(u32 key, u64 init_val) +{ + shadow_pkey_reg |= left_shift_bits(key, init_val); +} + int alloc_pkey(void) { int ret; @@ -540,7 +555,7 @@ int alloc_pkey(void) shadow_pkey_reg); if (ret) { /* clear both the bits: */ - shadow_pkey_reg &= ~(0x3 << (ret * 2)); + pkey_reset_shadow(ret); dprintf4("%s()::%d, ret: %d pkey_reg: 0x%016lx " "shadow: 0x%016lx\n", __func__, @@ -550,7 +565,7 @@ int alloc_pkey(void) * move the new state in from init_val * (remember, we cheated and init_val == pkey_reg format) */ - shadow_pkey_reg |= (init_val << (ret * 2)); + pkey_set_shadow(ret, init_val); } dprintf4("%s()::%d, ret: %d pkey_reg: 0x%016lx shadow: 0x%016lx\n", __func__, __LINE__, ret, __rdpkey_reg(), @@ -1322,11 +1337,6 @@ void run_tests_once(void) iteration_nr++; } -void pkey_setup_shadow(void) -{ - shadow_pkey_reg = __rdpkey_reg(); -} - int main(void) { int nr_iterations = 22; -- 1.7.1 From 1583078694280622824@xxx Fri Nov 03 20:38:11 +0000 2017 X-GM-THRID: 1582956709818260170 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread