Skip to content

Commit 5aa4b62

Browse files
mblenczewski-armctmarinas
authored andcommitted
arm64: Add BBM Level 2 cpu feature
The Break-Before-Make cpu feature supports multiple levels (levels 0-2), and this commit adds a dedicated BBML2 cpufeature to test against support for. To support BBML2 in as wide a range of contexts as we can, we want not only the architectural guarantees that BBML2 makes, but additionally want BBML2 to not create TLB conflict aborts. Not causing aborts avoids us having to prove that no recursive faults can be induced in any path that uses BBML2, allowing its use for arbitrary kernel mappings. This feature builds on the previous ARM64_CPUCAP_EARLY_LOCAL_CPU_FEATURE, as all early cpus must support BBML2 for us to enable it (and any later cpus must also support it to be onlined). Not onlining late cpus that do not support BBML2 is unavoidable, as we might currently be using BBML2 semantics for kernel memory regions. This could cause faults in the late cpus, and would be difficult to unwind, so let us avoid the case altogether. Signed-off-by: Mikołaj Lenczewski <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Reviewed-by: Suzuki K Poulose <[email protected]> Reviewed-by: Ryan Roberts <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 3eb06f6 commit 5aa4b62

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

arch/arm64/include/asm/cpufeature.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,11 @@ static inline bool system_supports_pmuv3(void)
871871
return cpus_have_final_cap(ARM64_HAS_PMUV3);
872872
}
873873

874+
static inline bool system_supports_bbml2_noabort(void)
875+
{
876+
return alternative_has_cap_unlikely(ARM64_HAS_BBML2_NOABORT);
877+
}
878+
874879
int do_emulate_mrs(struct pt_regs *regs, u32 sys_reg, u32 rt);
875880
bool try_emulate_mrs(struct pt_regs *regs, u32 isn);
876881

arch/arm64/kernel/cpufeature.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,38 @@ static bool hvhe_possible(const struct arm64_cpu_capabilities *entry,
22132213
return arm64_test_sw_feature_override(ARM64_SW_FEATURE_OVERRIDE_HVHE);
22142214
}
22152215

2216+
static bool has_bbml2_noabort(const struct arm64_cpu_capabilities *caps, int scope)
2217+
{
2218+
/*
2219+
* We want to allow usage of BBML2 in as wide a range of kernel contexts
2220+
* as possible. This list is therefore an allow-list of known-good
2221+
* implementations that both support BBML2 and additionally, fulfill the
2222+
* extra constraint of never generating TLB conflict aborts when using
2223+
* the relaxed BBML2 semantics (such aborts make use of BBML2 in certain
2224+
* kernel contexts difficult to prove safe against recursive aborts).
2225+
*
2226+
* Note that implementations can only be considered "known-good" if their
2227+
* implementors attest to the fact that the implementation never raises
2228+
* TLB conflict aborts for BBML2 mapping granularity changes.
2229+
*/
2230+
static const struct midr_range supports_bbml2_noabort_list[] = {
2231+
MIDR_REV_RANGE(MIDR_CORTEX_X4, 0, 3, 0xf),
2232+
MIDR_REV_RANGE(MIDR_NEOVERSE_V3, 0, 2, 0xf),
2233+
{}
2234+
};
2235+
2236+
/* Does our cpu guarantee to never raise TLB conflict aborts? */
2237+
if (!is_midr_in_range_list(supports_bbml2_noabort_list))
2238+
return false;
2239+
2240+
/*
2241+
* We currently ignore the ID_AA64MMFR2_EL1 register, and only care
2242+
* about whether the MIDR check passes.
2243+
*/
2244+
2245+
return true;
2246+
}
2247+
22162248
#ifdef CONFIG_ARM64_PAN
22172249
static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused)
22182250
{
@@ -2980,6 +3012,12 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
29803012
.matches = has_cpuid_feature,
29813013
ARM64_CPUID_FIELDS(ID_AA64MMFR2_EL1, EVT, IMP)
29823014
},
3015+
{
3016+
.desc = "BBM Level 2 without TLB conflict abort",
3017+
.capability = ARM64_HAS_BBML2_NOABORT,
3018+
.type = ARM64_CPUCAP_EARLY_LOCAL_CPU_FEATURE,
3019+
.matches = has_bbml2_noabort,
3020+
},
29833021
{
29843022
.desc = "52-bit Virtual Addressing for KVM (LPA2)",
29853023
.capability = ARM64_HAS_LPA2,

arch/arm64/tools/cpucaps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ HAS_LPA2
4545
HAS_LSE_ATOMICS
4646
HAS_MOPS
4747
HAS_NESTED_VIRT
48+
HAS_BBML2_NOABORT
4849
HAS_PAN
4950
HAS_PMUV3
5051
HAS_S1PIE

0 commit comments

Comments
 (0)