From patchwork Mon Jan 8 17:32:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 123752 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3001443qgn; Mon, 8 Jan 2018 09:33:01 -0800 (PST) X-Google-Smtp-Source: ACJfBovZaH52PQlXeCPd3u/6qd1COh3qjyYuPVzWGjca665Y47mJWfBzFgEplxcOhiiLXOeu9YLY X-Received: by 10.84.252.142 with SMTP id y14mr13040649pll.275.1515432780977; Mon, 08 Jan 2018 09:33:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515432780; cv=none; d=google.com; s=arc-20160816; b=gMIyWkblpOi9jcM/sKnGTKoVN28hYwYHxGhc8F4KMLc8X8IqbgJP0uffnsG/M1jyOO qZBOtSePP2U/mOsrIYJvK/eXAIHtipFfiJ4nfdAlPq+p6UtIvNJ0lMWjL9nOsfWMjdA0 UOQPDQTV190/hadBmcF9sJAK9WqS41HtIM7sbD77qsYsXGY08OKHrbnH+nWzfiwbcOCq o8e4Ut0Fgm0pfPSGgwFlXB1VcUL9iuJ6y5yzGIFDHsa3q00fZ3LCHnfbCIRY4nnXZ32i ds52b4QtI0MPwVfrpqOBvSDB6K8+aILEOcMkT0cEULlwIN9KEsUZt15HN1eNupDVsX9L 51sw== 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:arc-authentication-results; bh=wncafycWI4aj1SK8RTDAAXsSzBOiMpoTGc+li5wkM84=; b=vs1x57hHeYrQvTtdfIw7Whz5WHpBlnmzq4yrh2rH+hHnLTyBg9Isxhy6+nn70hZp4o a2lbZHO0jNGeInMjtZY1OoILzZdv95DQ6axw8DCKbJ0EoNL2WOlzi7xHEF1YZ/RP4hAp MLrxtpxIIOqOaKZQh/AI5Lb1HQM+C+TgZtoDhhlTuIOLMsW1bgIC4+7XR4ZLTzUPiKTT lsv0WFFKFO0bW72a0LdxmvwBm3bkRMiuvrRHT3FoWkm1F8HNV5V4MVQGc3Avp5qpdhAC E8Gh/Hmdy1cxIauHDWsvWsNoXNNfrbrmUEX7S7K/TEsyb62pmZ9JG8Vqp31W3Rqni/+O TFug== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z3si7720536pgv.49.2018.01.08.09.33.00; Mon, 08 Jan 2018 09:33:00 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754386AbeAHRcp (ORCPT + 28 others); Mon, 8 Jan 2018 12:32:45 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:42860 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754292AbeAHRcj (ORCPT ); Mon, 8 Jan 2018 12:32:39 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5B9551610; Mon, 8 Jan 2018 09:32:39 -0800 (PST) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2D7783F627; Mon, 8 Jan 2018 09:32:39 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 1DF1F1AE1894; Mon, 8 Jan 2018 17:32:41 +0000 (GMT) From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, ard.biesheuvel@linaro.org, marc.zyngier@arm.com, lorenzo.pieralisi@arm.com, christoffer.dall@linaro.org, linux-kernel@vger.kernel.org, shankerd@codeaurora.org, jnair@caviumnetworks.com, Will Deacon Subject: [PATCH v3 03/13] arm64: Take into account ID_AA64PFR0_EL1.CSV3 Date: Mon, 8 Jan 2018 17:32:28 +0000 Message-Id: <1515432758-26440-4-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1515432758-26440-1-git-send-email-will.deacon@arm.com> References: <1515432758-26440-1-git-send-email-will.deacon@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For non-KASLR kernels where the KPTI behaviour has not been overridden on the command line we can use ID_AA64PFR0_EL1.CSV3 to determine whether or not we should unmap the kernel whilst running at EL0. Reviewed-by: Suzuki K Poulose Signed-off-by: Will Deacon --- arch/arm64/include/asm/sysreg.h | 1 + arch/arm64/kernel/cpufeature.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) -- 2.1.4 diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index 08cc88574659..ae519bbd3f9e 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -437,6 +437,7 @@ #define ID_AA64ISAR1_DPB_SHIFT 0 /* id_aa64pfr0 */ +#define ID_AA64PFR0_CSV3_SHIFT 60 #define ID_AA64PFR0_SVE_SHIFT 32 #define ID_AA64PFR0_GIC_SHIFT 24 #define ID_AA64PFR0_ASIMD_SHIFT 20 diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 9f0545dfe497..d723fc071f39 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -145,6 +145,7 @@ static const struct arm64_ftr_bits ftr_id_aa64isar1[] = { }; static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { + ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64PFR0_CSV3_SHIFT, 4, 0), ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_SVE_SHIFT, 4, 0), ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_GIC_SHIFT, 4, 0), S_ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_ASIMD_SHIFT, 4, ID_AA64PFR0_ASIMD_NI), @@ -851,6 +852,8 @@ static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, int __unused) { + u64 pfr0 = read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1); + /* Forced on command line? */ if (__kpti_forced) { pr_info_once("kernel page table isolation forced %s by command line option\n", @@ -862,7 +865,9 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) return true; - return false; + /* Defer to CPU feature registers */ + return !cpuid_feature_extract_unsigned_field(pfr0, + ID_AA64PFR0_CSV3_SHIFT); } static int __init parse_kpti(char *str) @@ -967,6 +972,7 @@ static const struct arm64_cpu_capabilities arm64_features[] = { }, #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 { + .desc = "Kernel page table isolation (KPTI)", .capability = ARM64_UNMAP_KERNEL_AT_EL0, .def_scope = SCOPE_SYSTEM, .matches = unmap_kernel_at_el0,