arm64: cpufeatures: Allow disabling of BTI from the command-line
authorMarc Zyngier <maz@kernel.org>
Mon, 8 Feb 2021 09:57:29 +0000 (09:57 +0000)
committerWill Deacon <will@kernel.org>
Tue, 9 Feb 2021 13:50:57 +0000 (13:50 +0000)
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 <maz@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: David Brazdil <dbrazdil@google.com>
Tested-by: Srinivas Ramana <sramana@codeaurora.org>
Link: https://lore.kernel.org/r/20210208095732.3267263-21-maz@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
Documentation/admin-guide/kernel-parameters.txt
arch/arm64/include/asm/cpufeature.h
arch/arm64/kernel/cpufeature.c
arch/arm64/kernel/idreg-override.c
arch/arm64/mm/mmu.c

index 41786d205e0d20b3a89cd1e205b41ec0c9564948..c00236b22c6eff542c46747316574f4ba7401030 100644 (file)
        arcrimi=        [HW,NET] ARCnet - "RIM I" (entirely mem-mapped) cards
                        Format: <io>,<irq>,<nodeID>
 
+       arm64.nobti     [ARM64] Unconditionally disable Branch Target
+                       Identification support
+
        ataflop=        [HW,M68k]
 
        atarimouse=     [HW,MOUSE] Atari Mouse
index 570f1b4ba3cc700a7be9c8276a51f36bf3f927d2..30917b9a760b67534932aa18fba6b95b479c62b4 100644 (file)
@@ -819,6 +819,7 @@ static inline unsigned int get_vmid_bits(u64 mmfr1)
 }
 
 extern struct arm64_ftr_override id_aa64mmfr1_override;
+extern struct arm64_ftr_override id_aa64pfr1_override;
 
 u32 get_kvm_ipa_limit(void);
 void dump_cpu_features(void);
index faada5d8bea69e38b1c3c723f04d777eaf4f4eec..7fbeab497adbf1cca7d50de13b5154eb1c94adcd 100644 (file)
@@ -558,6 +558,7 @@ static const struct arm64_ftr_bits ftr_raz[] = {
 #define ARM64_FTR_REG(id, table) ARM64_FTR_REG_OVERRIDE(id, table, &no_override)
 
 struct arm64_ftr_override __ro_after_init id_aa64mmfr1_override;
+struct arm64_ftr_override __ro_after_init id_aa64pfr1_override;
 
 static const struct __ftr_reg_entry {
        u32                     sys_id;
@@ -593,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_override),
        ARM64_FTR_REG(SYS_ID_AA64ZFR0_EL1, ftr_id_aa64zfr0),
 
        /* Op1 = 0, CRn = 0, CRm = 5 */
index 70dd70eee7a21230521fedd4a91647e81ead8b6a..d691e9015c62806fb88e6db32b14d0979595bf52 100644 (file)
@@ -37,6 +37,15 @@ static const struct ftr_set_desc mmfr1 __initconst = {
        },
 };
 
+static const struct ftr_set_desc pfr1 __initconst = {
+       .name           = "id_aa64pfr1",
+       .override       = &id_aa64pfr1_override,
+       .fields         = {
+               { "bt", ID_AA64PFR1_BT_SHIFT },
+               {}
+       },
+};
+
 extern struct arm64_ftr_override kaslr_feature_override;
 
 static const struct ftr_set_desc kaslr __initconst = {
@@ -52,6 +61,7 @@ static const struct ftr_set_desc kaslr __initconst = {
 
 static const struct ftr_set_desc * const regs[] __initconst = {
        &mmfr1,
+       &pfr1,
        &kaslr,
 };
 
@@ -61,6 +71,7 @@ static const struct {
 } aliases[] __initconst = {
        { "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" },
 };
 
index ae0c3d023824e070fbd4d29d73e2dc2def64a785..617e704c980ba12c22577e8c13262f6f38fdfb3d 100644 (file)
@@ -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);
 }