Received: by 10.223.164.202 with SMTP id h10csp12444wrb; Mon, 6 Nov 2017 01:32:57 -0800 (PST) X-Google-Smtp-Source: ABhQp+SfULR3nOlNuxSAK7nDSxg24SYpnsy8KTMUJOkXpVxj4iw0JLNctb5/87tEP4gEh4BX0en6 X-Received: by 10.101.68.129 with SMTP id l1mr14633461pgq.4.1509960777682; Mon, 06 Nov 2017 01:32:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509960777; cv=none; d=google.com; s=arc-20160816; b=csaBx5i2Jhb/5Fj+JAd5msM2B4NYAw5NKzHnIdYEQDaqEFCWsR+3288dq7Omf6wV8Q +L0Vb9Wp+bQ9tycdSsPaWjgk4eyRR+RLTlE5WuG61uTnrXe4EmLmp9U5TZnl7p8AYHXg c3kYHvafhmWll16Chw1ypxGksD/x7xh1JRAxviI7sTFFXjBUC2bmA8Jt5yTGI7wPEZyb uXNloeWm58QtnHwX2w1xeHi/YuVRFvNvW5WNm0hnRHzLllt1kcdGwkDUUSlukCWvvs7O FMTr8KpO7pNz4dj/kRMwV2yBh/85eRztqKT2Ms2VUj676tuH8yENwwUw6UD6hByk6i/b CeEQ== 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=be+8hsuDmX3bt7lb+81BUS7Ue8ZRhsZ4Gkk3xDgjU/g=; b=VsBFPDolL4u8G7X2BXSyCII1ikX4PvrgD2PnQ+uvtDomVhERLZVfq9UDrKEklWfPDs +onc8DsnEKQ6dYFM6MeWrnh/sPXVGFLPUg4pJVqvqjcRp5w/CF/ToJ1Oll/CA8RJTMiT X9QsyceASOmwVysfp0fNn4tSb8iMOJQRTS5uUS5J9gTJ+XeGY+djgAwQGGUjvse2Fbry rEFESNQuNlvzkZDY/lSzUaF74Tug6xkDV1oGGGT61LIfHBovhGU7IBPXLj6Wf+Bc3gwe ADraJJzFmMjM/0morK3cdkF8GQBn2bQmv1SN722xg5/S1rv/wkXoXZt/PK91zr0WZW+q 70hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=OX1VTOBW; 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 x5si10068889plv.273.2017.11.06.01.32.44; Mon, 06 Nov 2017 01:32:57 -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=OX1VTOBW; 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 S1752273AbdKFJbn (ORCPT + 98 others); Mon, 6 Nov 2017 04:31:43 -0500 Received: from mail-qk0-f196.google.com ([209.85.220.196]:50923 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752375AbdKFI7Z (ORCPT ); Mon, 6 Nov 2017 03:59:25 -0500 Received: by mail-qk0-f196.google.com with SMTP id o187so10008188qke.7; Mon, 06 Nov 2017 00:59:25 -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=be+8hsuDmX3bt7lb+81BUS7Ue8ZRhsZ4Gkk3xDgjU/g=; b=OX1VTOBWG0gaRJ8zzIZpskx7dxOzNMAK7hzT/mobFQY6NsmJ6B75yTMup1S3bRtX9Y 3F6v15tTnV6fd+/wVoOuccXVwCJ60aA1Mg8e9ojep9j7w0Jp4AefqoemA67nnhvj32EI b2CqWjWngrmZ8/+R1lx2uIVcBINmwPyGFK/SLz3oAfZW8Ob1s/T8kpLz94Z77D3MYRAb tlzTiSXTaKfK4rNMlmR1gCV2gnR18eKHYlzK2dhtk8iVYNdwdGXu9/TVIoWNFoIj/trC rQXI3WiP8+eVIKmHj4qefCNLhkEwDbl2TG/mHZ3HNfRKWR3/YsRQe/jPERkL+ReWGwAu 6aAA== 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=be+8hsuDmX3bt7lb+81BUS7Ue8ZRhsZ4Gkk3xDgjU/g=; b=ZcaFHauMku9fr6LaZWLrlA+yez7FUBgfQvqBf74vzySJrK448r1Q81hzJzRO/ZDvvr ar4/7lxC5u6ggk0+jkpWfQlqJ1jAZPguMSxQNUw5wEHEmOohAYfoKeDGk0PCNlgTstqk Qi+g/iZoWttEA8apMldOWuHgQhO9KdFHLT1y/lR5SL8aOxkAbEMZe/VflYoIqFgCfra2 Ijjb5Orc6ip4hw/cbmnbTPqdVU+xPAsZAHD09rXtkJIK5E5LpCpWT50nqdsPNq/MSH8r leoil676lldpJ0Mmmqk11bPdkhwWucZFgZPhZot8q4HqtA35hrVlOcrr/uzuYku5gWGn dukQ== X-Gm-Message-State: AJaThX41txCcQ6cBYIu3O251Y+LWpnjeQqCG73UhloZ+vdTn3mGfF7XS 3hxAw4Abr4u8UK+6RsGUghI= X-Received: by 10.55.198.80 with SMTP id b77mr5118956qkj.138.1509958764589; Mon, 06 Nov 2017 00:59:24 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 00:59:24 -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 23/51] powerpc: Enable pkey subsystem Date: Mon, 6 Nov 2017 00:57:15 -0800 Message-Id: <1509958663-18737-24-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 PAPR defines 'ibm,processor-storage-keys' property. It exports two values. The first value holds the number of data-access keys and the second holds the number of instruction-access keys. Due to a bug in the firmware, instruction-access keys is always reported as zero. However any key can be configured to disable data-access and/or disable execution-access. The inavailablity of the second value is not a big handicap, though it could have been used to determine if the platform supported disable-execution-access. Non PAPR platforms do not define this property in the device tree yet. Here, we hardcode CPUs that support pkey by consulting PowerISA3.0 This patch calculates the number of keys supported by the platform. Alsi it determines the platform support for read/write/execution access support for pkeys. Signed-off-by: Ram Pai --- arch/powerpc/include/asm/cputable.h | 15 +++++++++---- arch/powerpc/include/asm/mmu_context.h | 1 + arch/powerpc/include/asm/pkeys.h | 10 +++++++++ arch/powerpc/kernel/prom.c | 18 +++++++++++++++++ arch/powerpc/mm/pkeys.c | 33 +++++++++++++++++++++---------- 5 files changed, 61 insertions(+), 16 deletions(-) diff --git a/arch/powerpc/include/asm/cputable.h b/arch/powerpc/include/asm/cputable.h index 53b31c2..b288735 100644 --- a/arch/powerpc/include/asm/cputable.h +++ b/arch/powerpc/include/asm/cputable.h @@ -215,7 +215,9 @@ enum { #define CPU_FTR_DAWR LONG_ASM_CONST(0x0400000000000000) #define CPU_FTR_DABRX LONG_ASM_CONST(0x0800000000000000) #define CPU_FTR_PMAO_BUG LONG_ASM_CONST(0x1000000000000000) +#define CPU_FTR_PKEY LONG_ASM_CONST(0x2000000000000000) #define CPU_FTR_POWER9_DD1 LONG_ASM_CONST(0x4000000000000000) +#define CPU_FTR_PKEY_EXECUTE LONG_ASM_CONST(0x8000000000000000) #ifndef __ASSEMBLY__ @@ -436,7 +438,8 @@ enum { CPU_FTR_PPCAS_ARCH_V2 | CPU_FTR_CTRL | \ CPU_FTR_MMCRA | CPU_FTR_SMT | \ CPU_FTR_COHERENT_ICACHE | CPU_FTR_PURR | \ - CPU_FTR_STCX_CHECKS_ADDRESS | CPU_FTR_POPCNTB | CPU_FTR_DABRX) + CPU_FTR_STCX_CHECKS_ADDRESS | CPU_FTR_POPCNTB | CPU_FTR_DABRX | \ + CPU_FTR_PKEY) #define CPU_FTRS_POWER6 (CPU_FTR_USE_TB | CPU_FTR_LWSYNC | \ CPU_FTR_PPCAS_ARCH_V2 | CPU_FTR_CTRL | \ CPU_FTR_MMCRA | CPU_FTR_SMT | \ @@ -444,7 +447,7 @@ enum { CPU_FTR_PURR | CPU_FTR_SPURR | CPU_FTR_REAL_LE | \ CPU_FTR_DSCR | CPU_FTR_UNALIGNED_LD_STD | \ CPU_FTR_STCX_CHECKS_ADDRESS | CPU_FTR_POPCNTB | CPU_FTR_CFAR | \ - CPU_FTR_DABRX) + CPU_FTR_DABRX | CPU_FTR_PKEY) #define CPU_FTRS_POWER7 (CPU_FTR_USE_TB | CPU_FTR_LWSYNC | \ CPU_FTR_PPCAS_ARCH_V2 | CPU_FTR_CTRL | CPU_FTR_ARCH_206 |\ CPU_FTR_MMCRA | CPU_FTR_SMT | \ @@ -453,7 +456,7 @@ enum { CPU_FTR_DSCR | CPU_FTR_SAO | CPU_FTR_ASYM_SMT | \ CPU_FTR_STCX_CHECKS_ADDRESS | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD | \ CPU_FTR_ICSWX | CPU_FTR_CFAR | CPU_FTR_HVMODE | \ - CPU_FTR_VMX_COPY | CPU_FTR_HAS_PPR | CPU_FTR_DABRX) + CPU_FTR_VMX_COPY | CPU_FTR_HAS_PPR | CPU_FTR_DABRX | CPU_FTR_PKEY) #define CPU_FTRS_POWER8 (CPU_FTR_USE_TB | CPU_FTR_LWSYNC | \ CPU_FTR_PPCAS_ARCH_V2 | CPU_FTR_CTRL | CPU_FTR_ARCH_206 |\ CPU_FTR_MMCRA | CPU_FTR_SMT | \ @@ -463,7 +466,8 @@ enum { CPU_FTR_STCX_CHECKS_ADDRESS | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD | \ CPU_FTR_ICSWX | CPU_FTR_CFAR | CPU_FTR_HVMODE | CPU_FTR_VMX_COPY | \ CPU_FTR_DBELL | CPU_FTR_HAS_PPR | CPU_FTR_DAWR | \ - CPU_FTR_ARCH_207S | CPU_FTR_TM_COMP) + CPU_FTR_ARCH_207S | CPU_FTR_TM_COMP | CPU_FTR_PKEY |\ + CPU_FTR_PKEY_EXECUTE) #define CPU_FTRS_POWER8E (CPU_FTRS_POWER8 | CPU_FTR_PMAO_BUG) #define CPU_FTRS_POWER8_DD1 (CPU_FTRS_POWER8 & ~CPU_FTR_DBELL) #define CPU_FTRS_POWER9 (CPU_FTR_USE_TB | CPU_FTR_LWSYNC | \ @@ -475,7 +479,8 @@ enum { CPU_FTR_STCX_CHECKS_ADDRESS | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD | \ CPU_FTR_CFAR | CPU_FTR_HVMODE | CPU_FTR_VMX_COPY | \ CPU_FTR_DBELL | CPU_FTR_HAS_PPR | CPU_FTR_DAWR | \ - CPU_FTR_ARCH_207S | CPU_FTR_TM_COMP | CPU_FTR_ARCH_300) + CPU_FTR_ARCH_207S | CPU_FTR_TM_COMP | CPU_FTR_ARCH_300 | \ + CPU_FTR_PKEY | CPU_FTR_PKEY_EXECUTE) #define CPU_FTRS_POWER9_DD1 ((CPU_FTRS_POWER9 | CPU_FTR_POWER9_DD1) & \ (~CPU_FTR_SAO)) #define CPU_FTRS_CELL (CPU_FTR_USE_TB | CPU_FTR_LWSYNC | \ diff --git a/arch/powerpc/include/asm/mmu_context.h b/arch/powerpc/include/asm/mmu_context.h index 95a3288..5a15d37 100644 --- a/arch/powerpc/include/asm/mmu_context.h +++ b/arch/powerpc/include/asm/mmu_context.h @@ -152,6 +152,7 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, #define thread_pkey_regs_save(thread) #define thread_pkey_regs_restore(new_thread, old_thread) #define thread_pkey_regs_init(thread) +#define pkey_mmu_values(total_data, total_execute) static inline int vma_pkey(struct vm_area_struct *vma) { diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h index 9ee4731..333fb28 100644 --- a/arch/powerpc/include/asm/pkeys.h +++ b/arch/powerpc/include/asm/pkeys.h @@ -13,6 +13,7 @@ #define _ASM_POWERPC_KEYS_H #include +#include DECLARE_STATIC_KEY_TRUE(pkey_disabled); extern int pkeys_total; /* total pkeys as per device tree */ @@ -227,6 +228,15 @@ static inline void pkey_mm_init(struct mm_struct *mm) mm->context.execute_only_pkey = -1; } +static inline void pkey_mmu_values(int total_data, int total_execute) +{ + /* + * Since any pkey can be used for data or execute, we will just treat + * all keys as equal and track them as one entity. + */ + pkeys_total = total_data; +} + extern void thread_pkey_regs_save(struct thread_struct *thread); extern void thread_pkey_regs_restore(struct thread_struct *new_thread, struct thread_struct *old_thread); diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index f830562..8b75e9b 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -228,6 +229,22 @@ static void __init check_cpu_pa_features(unsigned long node) ibm_pa_features, ARRAY_SIZE(ibm_pa_features)); } +static void __init check_cpu_pkey_feature(unsigned long node) +{ + const __be32 *ftrs; + int len, total_data, total_execute; + + ftrs = of_get_flat_dt_prop(node, "ibm,processor-storage-keys", &len); + if (ftrs == NULL) + return; + + len /= sizeof(int); + total_execute = (len >= 2) ? be32_to_cpu(ftrs[1]) : 0; + total_data = (len >= 1) ? be32_to_cpu(ftrs[0]) : 0; + pkey_mmu_values(total_data, total_execute); +} + + #ifdef CONFIG_PPC_STD_MMU_64 static void __init init_mmu_slb_size(unsigned long node) { @@ -391,6 +408,7 @@ static int __init early_init_dt_scan_cpus(unsigned long node, check_cpu_feature_properties(node); check_cpu_pa_features(node); + check_cpu_pkey_feature(node); } identical_pvr_fixup(node); diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c index 3b221bd..5047371 100644 --- a/arch/powerpc/mm/pkeys.c +++ b/arch/powerpc/mm/pkeys.c @@ -26,6 +26,14 @@ #define PKEY_REG_BITS (sizeof(u64)*8) #define pkeyshift(pkey) (PKEY_REG_BITS - ((pkey+1) * AMR_BITS_PER_PKEY)) +static inline bool pkey_mmu_enabled(void) +{ + if (firmware_has_feature(FW_FEATURE_LPAR)) + return pkeys_total; + else + return cpu_has_feature(CPU_FTR_PKEY); +} + void __init pkey_initialize(void) { int os_reserved, i; @@ -46,14 +54,9 @@ void __init pkey_initialize(void) __builtin_popcountl(ARCH_VM_PKEY_FLAGS >> VM_PKEY_SHIFT) != (sizeof(u64) * BITS_PER_BYTE)); - /* - * Disable the pkey system till everything is in place. A subsequent - * patch will enable it. - */ - static_branch_enable(&pkey_disabled); - - /* Lets assume 32 keys */ - pkeys_total = 32; + /* Let's assume 32 keys if we are not told the number of pkeys. */ + if (!pkeys_total) + pkeys_total = 32; /* * Adjust the upper limit, based on the number of bits supported by @@ -62,11 +65,19 @@ void __init pkey_initialize(void) pkeys_total = min_t(int, pkeys_total, (ARCH_VM_PKEY_FLAGS >> VM_PKEY_SHIFT)); + if (!pkey_mmu_enabled() || radix_enabled() || !pkeys_total) + static_branch_enable(&pkey_disabled); + else + static_branch_disable(&pkey_disabled); + + if (static_branch_likely(&pkey_disabled)) + return; + /* - * Disable execute_disable support for now. A subsequent patch will - * enable it. + * The device tree cannot be relied on for execute_disable support. + * Hence we depend on CPU FTR. */ - pkey_execute_disable_supported = false; + pkey_execute_disable_supported = cpu_has_feature(CPU_FTR_PKEY_EXECUTE); #ifdef CONFIG_PPC_4K_PAGES /* -- 1.7.1 From 1583844545044099149@xxx Sun Nov 12 07:31:03 +0000 2017 X-GM-THRID: 1583844545044099149 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread