From patchwork Thu Jan 4 15:08:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 123433 Delivered-To: patch@linaro.org Received: by 10.80.135.92 with SMTP id 28csp6820006edv; Thu, 4 Jan 2018 07:09:53 -0800 (PST) X-Google-Smtp-Source: ACJfBosMFFS9tWtUSF8BgsXew+nz9bILjwdJtdQ81etlTJPzbVTm6z+iXWXLmorAY6ALIrr9XdVD X-Received: by 10.99.115.93 with SMTP id d29mr4375627pgn.345.1515078593335; Thu, 04 Jan 2018 07:09:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515078593; cv=none; d=google.com; s=arc-20160816; b=rOExtstpLVyiy9WqjnPDQOY3FxhUanBbEpJoTUscBGeVE3S98vrLNBMva9eyB4jcvt 6vRx4VM7CRO39iGxCydVccZRBIVcbBS6scEpWZwOQSpSXGV8axv+CQI8OZ6xEZ+Q4SnY 3hgnK1fZcpt4xLXvfDkxGt+kDOyeQw8i2M2VACwNXo7cKdUDZ7Gld6fFxiSbTqmmI9ak nSuVsj/izaCNyl0gC6cxuMQbd5ceW9Z6qTNU8vla4Gqc2hHhx7v11NRp6/SCa7ACeWAu F5MRwkUfNpoZhL/mxwsCAX7aTpJ62MazSvQ40bav1qrOZcLlh4SE3NQLo3Pxu12jdvLZ eimg== 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=MUOsmZ4kx9+UNLQwsx2AhZiJBk7Zlkesegp7dE63NLY=; b=QN4M/8/QP1Kzd23BwGix64QOfIbfqUR7b3BF0LL0P/t3+sJlRR7G957z9vmIxobzn+ /vAt2Fbv5wTpHepfsN9Dpd84odMklN1vBOAiEy4G4uTDpRWeovEP96Fj4DAYBlgzjxru RM+B9zkOkZ/r9mGd3XKWnmf17Q9steDKUVr2H0W7cWn1oN+SJX0/+T4/c8bQfDDdI0Um yM22lQHED0FDivHdg8p/58xLeImfvGkk3/n/PdbfjA27sY5dxVF0m4uLyKj5fwXFMXK4 uhybAcnPz6aPMh/Dx7NEd8B28mZmeRIrLIAd59BJnzdIGJl9DoysuETGRVilo9EfCazr A61A== 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 h12si2467499pln.288.2018.01.04.07.09.53; Thu, 04 Jan 2018 07:09:53 -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 S932102AbeADPIt (ORCPT + 22 others); Thu, 4 Jan 2018 10:08:49 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33788 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753370AbeADPIk (ORCPT ); Thu, 4 Jan 2018 10:08:40 -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 9C12E15BE; Thu, 4 Jan 2018 07:08:40 -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 6E15F3F7BD; Thu, 4 Jan 2018 07:08:40 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 93A7B1AE0E88; Thu, 4 Jan 2018 15:08:40 +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, Will Deacon Subject: [PATCH 03/11] arm64: Take into account ID_AA64PFR0_EL1.CSV3 Date: Thu, 4 Jan 2018 15:08:27 +0000 Message-Id: <1515078515-13723-4-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1515078515-13723-1-git-send-email-will.deacon@arm.com> References: <1515078515-13723-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. Signed-off-by: Will Deacon --- arch/arm64/include/asm/sysreg.h | 1 + arch/arm64/kernel/cpufeature.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) -- 2.1.4 Reviewed-by: Suzuki K Poulose 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..e11c11bb5b02 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)