From patchwork Tue Apr 3 11:09:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 132725 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp3666235ljb; Tue, 3 Apr 2018 04:10:25 -0700 (PDT) X-Google-Smtp-Source: AIpwx49xK3DJtQ50J8A2Vn30V789HMbg5SiepzSqx9mWguNCEsFQOvd5Hd+WpPLSNrwRilidJi31 X-Received: by 10.101.73.74 with SMTP id q10mr8909712pgs.323.1522753825482; Tue, 03 Apr 2018 04:10:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522753825; cv=none; d=google.com; s=arc-20160816; b=atesTyywPqO/qQ9RADt/nGM8FTEH1thlnOb0ccp602QmTAx5dSNge2Il8dvbMa8gWv 4mYk/JtXnQDjbcI6YJKd64CWnuh3iDZ2eINKkpS2A3S2/WPO8UbzdapQ6ZvnwMeIbE0z TFU2VwHuvAUqrIzHM/XKAc6KTuHq+cJ5pz5UIrXJR7JqR4X8b20fuCxn1eQ/9YQVEH+0 9PvtdbGRZe5tHFtY7t0Zdi2Wzf9pEGAbFCFWXFoU2Vmacg7HW3BmJf5kRhSOlvUJ10F9 mEtU28qI+GKeSsH1G4bqUB/p0IEOUxq0sYzcvjfIs4xIj/rHRLzgHDAuuk+MQhNy8hzo /C2g== 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=E7uAr9GEB9STMdtCvsAc2NKLt5sT2dmVR3BwmQ8MBPU=; b=05iF5Y2JBVvsHHjxbx4MGO7PXjH+Y2mu5+7ug8AHrUXu0MiTyXpfW+PBAJEs5BgOjp v3TozzjILPcOUXuLzwaVHdsjqeyNYDa/isuzninWUFPqHOjduSARv/97vMYJFO0Nuc/P hoG2C8uySE/0xwoRVb6hQOpNj23D3IvoCSwvDA2XflAOnMIVZrDd3tuwovs4q3tm1PwX UmTqrvjDB7IAlF1ZyKNQJfRe/f0Yai3mfFQxUMjMwTdBgE+6K1WnDmKlF5Lr4yaHp+eE TFsuWCEEs1gSciVJNKRozyo4Q557kZ+lELHUshdYAG/LS8y69BxIDqxiOWJEXXILCRyq apMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 l91-v6si306341plb.301.2018.04.03.04.10.25; Tue, 03 Apr 2018 04:10:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754963AbeDCLKX (ORCPT + 11 others); Tue, 3 Apr 2018 07:10:23 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:59382 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755504AbeDCLKW (ORCPT ); Tue, 3 Apr 2018 07:10:22 -0400 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 C39481435; Tue, 3 Apr 2018 04:10:21 -0700 (PDT) Received: from lakrids.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 92F933F587; Tue, 3 Apr 2018 04:10:20 -0700 (PDT) From: Mark Rutland To: stable@vger.kernel.org Cc: mark.brown@linaro.org, ard.biesheuvel@linaro.org, marc.zyngier@arm.com, will.deacon@arm.com Subject: [PATCH v4.9.y 18/27] arm64: Take into account ID_AA64PFR0_EL1.CSV3 Date: Tue, 3 Apr 2018 12:09:14 +0100 Message-Id: <20180403110923.43575-19-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180403110923.43575-1-mark.rutland@arm.com> References: <20180403110923.43575-1-mark.rutland@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Will Deacon commit 179a56f6f9fb upstream. 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 Signed-off-by: Catalin Marinas [Alex: s/read_sanitised_ftr_reg/read_system_reg/ to match v4.9 naming] Signed-off-by: Alex Shi [v4.9 backport] [Mark: correct zero bits in ftr_id_aa64pfr0 to account for CSV3] Signed-off-by: Mark Rutland [v4.9 backport] --- arch/arm64/include/asm/sysreg.h | 1 + arch/arm64/kernel/cpufeature.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) -- 2.11.0 diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index 7393cc767edb..7cb7f7cdcfbc 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -117,6 +117,7 @@ #define ID_AA64ISAR0_AES_SHIFT 4 /* id_aa64pfr0 */ +#define ID_AA64PFR0_CSV3_SHIFT 60 #define ID_AA64PFR0_GIC_SHIFT 24 #define ID_AA64PFR0_ASIMD_SHIFT 20 #define ID_AA64PFR0_FP_SHIFT 16 diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 74b168c51abd..d24e59cedae5 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -93,7 +93,8 @@ static const struct arm64_ftr_bits ftr_id_aa64isar0[] = { }; static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { - ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 32, 32, 0), + ARM64_FTR_BITS(FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64PFR0_CSV3_SHIFT, 4, 0), + ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 32, 28, 0), ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 28, 4, 0), ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64PFR0_GIC_SHIFT, 4, 0), S_ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_ASIMD_SHIFT, 4, ID_AA64PFR0_ASIMD_NI), @@ -752,6 +753,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_system_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", @@ -763,7 +766,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) @@ -865,6 +870,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,