arm64: proton-pack: Expose whether the platform is mitigated by firmware
authorJames Morse <james.morse@arm.com>
Mon, 19 Aug 2024 13:15:53 +0000 (14:15 +0100)
committerJames Morse <james.morse@arm.com>
Thu, 8 May 2025 14:28:35 +0000 (15:28 +0100)
is_spectre_bhb_fw_affected() allows the caller to determine if the CPU
is known to need a firmware mitigation. CPUs are either on the list
of CPUs we know about, or firmware has been queried and reported that
the platform is affected - and mitigated by firmware.

This helper is not useful to determine if the platform is mitigated
by firmware. A CPU could be on the know list, but the firmware may
not be implemented. Its affected but not mitigated.

spectre_bhb_enable_mitigation() handles this distinction by checking
the firmware state before enabling the mitigation.

Add a helper to expose this state. This will be used by the BPF JIT
to determine if calling firmware for a mitigation is necessary and
supported.

Signed-off-by: James Morse <james.morse@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/include/asm/spectre.h
arch/arm64/kernel/proton-pack.c

index f1524cdeacf1c4ed455109e0a4c8bb5d249e1dd0..78fb720987fb4508cce62327443bb915f3989e1c 100644 (file)
@@ -97,6 +97,7 @@ enum mitigation_state arm64_get_meltdown_state(void);
 
 enum mitigation_state arm64_get_spectre_bhb_state(void);
 bool is_spectre_bhb_affected(const struct arm64_cpu_capabilities *entry, int scope);
+bool is_spectre_bhb_fw_mitigated(void);
 void spectre_bhb_enable_mitigation(const struct arm64_cpu_capabilities *__unused);
 bool try_emulate_el1_ssbs(struct pt_regs *regs, u32 instr);
 
index b607f6dfc5e6f63020897a9c9ab20a9eb37f5353..355f1f3098a24d5e75f35269c13c9298839cbc43 100644 (file)
@@ -1094,6 +1094,11 @@ void spectre_bhb_enable_mitigation(const struct arm64_cpu_capabilities *entry)
        update_mitigation_state(&spectre_bhb_state, state);
 }
 
+bool is_spectre_bhb_fw_mitigated(void)
+{
+       return test_bit(BHB_FW, &system_bhb_mitigations);
+}
+
 /* Patched to NOP when enabled */
 void noinstr spectre_bhb_patch_loop_mitigation_enable(struct alt_instr *alt,
                                                     __le32 *origptr,