Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1882404pxb; Mon, 18 Jan 2021 02:24:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzuCgF0h0VZdvPo8wuAtRrzCbeprwTu7143V2ghWgSTilwnohT2DPIUAhbOmqI2VqsEt6CU X-Received: by 2002:a17:906:a951:: with SMTP id hh17mr17753903ejb.388.1610965448483; Mon, 18 Jan 2021 02:24:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610965448; cv=none; d=google.com; s=arc-20160816; b=dRu9L9ZaKvnyYMic9O5pmSGfJCOBeJbnfmNS2RGL3ci0BgQzhaOl7F97XYFKPXCdUt TugxhGXrAlwNlT6bDxfR7Ik/rOZBynmfQO5HIISeiCdWURZ483HHFZRgBO5MFgiME++v pjKqIBChdYfi13xZBij5FIQ8IgLvckVVO3ejirj1hW/flY5UjZmas3xmkteuNHfne73J 2DRkpJ7M4as/Y5WAgatvN8DdsjZ7EYApPhsVlMuLz2NccT0Y/kzyYFsL/AR1MrcV9oM4 GYUJRI/cqpcwtLTeI/M/NFrJG4vLr/X+Od+atcpvI9ZhDXUKg9aKqEruG/oB7mMxx3LL kZkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=iC4rAliS2wyEF1StMc5MtG6vGrStDHGlYaKEl00rpBw=; b=jp/QudErhiHFVp64s1dw5OEO3LxqeT/T15+Ro6D/jEOWJycZMnQhuC6RONGteZSXOc Ur6XfuaMUWjZO9KjHew9FKfLxoB2qLte7rrUHavNiN+TsExwrukV75YJKb7KJTP0IUt8 EkZ4od64Sm1llhdWI1kyg8TuDK3iO1Qx+MrJbeK3dnQdxt0+ZqM3CkFHrThKxX+fm1/1 Vi3cWlrCeknyAEt+vUIvy7uNi8iqVsjFN0OwSPgFptEJT30FFCrNFiNf67/muSWCjLw9 ankwHzeDgQtJr/KQRttwCk+HV/oT2O/8Rh7p9A65XTz48KMYom4O9qo8hhYGI4qmy9KH uANg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z18si1060271ejr.345.2021.01.18.02.23.44; Mon, 18 Jan 2021 02:24:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388882AbhARKVa (ORCPT + 99 others); Mon, 18 Jan 2021 05:21:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:39320 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389444AbhARKDT (ORCPT ); Mon, 18 Jan 2021 05:03:19 -0500 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4EB4722ADC; Mon, 18 Jan 2021 10:00:28 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1l1R72-008RhD-7u; Mon, 18 Jan 2021 09:46:17 +0000 From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Mark Rutland , David Brazdil , Alexandru Elisei , Ard Biesheuvel , Jing Zhang , Ajay Patil , Prasad Sodagudi , Srinivas Ramana , James Morse , Julien Thierry , Suzuki K Poulose , kernel-team@android.com Subject: [PATCH v4 19/21] arm64: cpufeatures: Allow disabling of BTI from the command-line Date: Mon, 18 Jan 2021 09:45:31 +0000 Message-Id: <20210118094533.2874082-20-maz@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210118094533.2874082-1-maz@kernel.org> References: <20210118094533.2874082-1-maz@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, dbrazdil@google.com, alexandru.elisei@arm.com, ardb@kernel.org, jingzhangos@google.com, pajay@qti.qualcomm.com, psodagud@codeaurora.org, sramana@codeaurora.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to be able to disable BTI at runtime, whether it is for testing purposes, or to work around HW issues, let's add support for overriding the ID_AA64PFR1_EL1.BTI field. This is further mapped on the arm64.nobti command-line alias. Signed-off-by: Marc Zyngier --- Documentation/admin-guide/kernel-parameters.txt | 3 +++ arch/arm64/include/asm/cpufeature.h | 2 ++ arch/arm64/kernel/cpufeature.c | 5 ++++- arch/arm64/kernel/idreg-override.c | 12 ++++++++++++ arch/arm64/mm/mmu.c | 2 +- 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 2786fd39a047..7599fd0f1ad7 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -373,6 +373,9 @@ arcrimi= [HW,NET] ARCnet - "RIM I" (entirely mem-mapped) cards Format: ,, + arm64.nobti [ARM64] Unconditionally disable Branch Target + Identification support + ataflop= [HW,M68k] atarimouse= [HW,MOUSE] Atari Mouse diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 80a5f423444e..d3e0f6dd43c4 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -816,6 +816,8 @@ static inline unsigned int get_vmid_bits(u64 mmfr1) extern u64 id_aa64mmfr1_val; extern u64 id_aa64mmfr1_mask; +extern u64 id_aa64pfr1_val; +extern u64 id_aa64pfr1_mask; u32 get_kvm_ipa_limit(void); void dump_cpu_features(void); diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 5b9343d2e9f0..f223171a7c34 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -557,6 +557,8 @@ static const struct arm64_ftr_bits ftr_raz[] = { u64 id_aa64mmfr1_val; u64 id_aa64mmfr1_mask; +u64 id_aa64pfr1_val; +u64 id_aa64pfr1_mask; static const struct __ftr_reg_entry { u32 sys_id; @@ -592,7 +594,8 @@ static const struct __ftr_reg_entry { /* Op1 = 0, CRn = 0, CRm = 4 */ ARM64_FTR_REG(SYS_ID_AA64PFR0_EL1, ftr_id_aa64pfr0), - ARM64_FTR_REG(SYS_ID_AA64PFR1_EL1, ftr_id_aa64pfr1), + ARM64_FTR_REG_OVERRIDE(SYS_ID_AA64PFR1_EL1, ftr_id_aa64pfr1, + &id_aa64pfr1_val, &id_aa64pfr1_mask), ARM64_FTR_REG(SYS_ID_AA64ZFR0_EL1, ftr_id_aa64zfr0), /* Op1 = 0, CRn = 0, CRm = 5 */ diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c index 143fe7b8e3ce..a9e3ed193fd4 100644 --- a/arch/arm64/kernel/idreg-override.c +++ b/arch/arm64/kernel/idreg-override.c @@ -33,6 +33,16 @@ static const struct reg_desc mmfr1 __initdata = { }, }; +static const struct reg_desc pfr1 __initdata = { + .name = "id_aa64pfr1", + .val = &id_aa64pfr1_val, + .mask = &id_aa64pfr1_mask, + .fields = { + { "bt", ID_AA64PFR1_BT_SHIFT }, + {} + }, +}; + extern u64 kaslr_feature_val; extern u64 kaslr_feature_mask; @@ -50,6 +60,7 @@ static const struct reg_desc kaslr __initdata = { static const struct reg_desc * const regs[] __initdata = { &mmfr1, + &pfr1, &kaslr, }; @@ -59,6 +70,7 @@ static const struct { } aliases[] __initdata = { { "kvm-arm.mode=nvhe", "id_aa64mmfr1.vh=0" }, { "kvm-arm.mode=protected", "id_aa64mmfr1.vh=0" }, + { "arm64.nobti", "id_aa64pfr1.bt=0" }, { "nokaslr", "kaslr.disabled=1" }, }; diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index ae0c3d023824..617e704c980b 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -628,7 +628,7 @@ static bool arm64_early_this_cpu_has_bti(void) if (!IS_ENABLED(CONFIG_ARM64_BTI_KERNEL)) return false; - pfr1 = read_sysreg_s(SYS_ID_AA64PFR1_EL1); + pfr1 = __read_sysreg_by_encoding(SYS_ID_AA64PFR1_EL1); return cpuid_feature_extract_unsigned_field(pfr1, ID_AA64PFR1_BT_SHIFT); } -- 2.29.2