[PATCH v2 11/20] arm64: Add bbm_through_af capability

From: James Houghton

Date: Fri Oct 02 2026 - 20:22:30 EST


HVO requires BBM Level 3 for the block -> table transitions when
optimizing the vmemmap, and it requires hardware AF management to avoid
taking page faults on the !AF translation that is installed as part of
the RW table -> RO + new OA table transitions.

Call this requirement "BBM through AF"; i.e., all CPUs support BBM-less,
in-place TTD updates. Model this as a system feature, as all CPUs must
support it for the kernel to use it.

It may seem odd to check for HVO support directly in bbm_through_af().
If this weren't done, any system with mismatched HW AF will no longer be
able to start late CPUs that are missing HW AF if all early CPUs have HW
AF (and BBML3).

Signed-off-by: James Houghton <jthoughton@xxxxxxxxxx>
---
arch/arm64/include/asm/cpufeature.h | 5 +++++
arch/arm64/kernel/cpufeature.c | 26 ++++++++++++++++++++++++++
arch/arm64/tools/cpucaps | 1 +
3 files changed, 32 insertions(+)

diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
index 4f04ad82ea34..fbededd7b748 100644
--- a/arch/arm64/include/asm/cpufeature.h
+++ b/arch/arm64/include/asm/cpufeature.h
@@ -878,6 +878,11 @@ static inline bool system_supports_bbml3(void)
return alternative_has_cap_unlikely(ARM64_HAS_BBML3);
}

+static inline bool system_supports_bbm_through_af(void)
+{
+ return alternative_has_cap_unlikely(ARM64_HAS_BBM_THROUGH_AF);
+}
+
int do_emulate_mrs(struct pt_regs *regs, u32 sys_reg, u32 rt);
bool try_emulate_mrs(struct pt_regs *regs, u32 isn);

diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 32102c3912fa..448d4ef085de 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -76,6 +76,7 @@
#include <linux/kasan.h>
#include <linux/percpu.h>
#include <linux/sched/isolation.h>
+#include <linux/hugetlb.h>

#include <asm/arm_pmuv3.h>
#include <asm/cpu.h>
@@ -2193,6 +2194,25 @@ static bool has_bbml3(const struct arm64_cpu_capabilities *caps, int scope)
return cpu_supports_bbml3();
}

+static bool has_bbm_through_af(const struct arm64_cpu_capabilities *caps, int scope)
+{
+ /*
+ * BBM-through-AF is only needed for HVO. If HVO is not in use, don't
+ * penalize systems with mismatched support.
+ */
+ if (!hugetlb_vmemmap_optimize_enabled()) {
+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_ARCH_WANT_HUGETLB_VMEMMAP_RO_AFTER_INIT));
+ return false;
+ }
+
+ /*
+ * We need BBML3 to support Block -> Table transitions without taking
+ * faults, and we need HW AF support to support changing the OA without
+ * taking faults.
+ */
+ return cpu_supports_bbml3() && cpu_has_hw_af();
+}
+
static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused)
{
/*
@@ -3102,6 +3122,12 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
.type = ARM64_CPUCAP_EARLY_LOCAL_CPU_FEATURE,
.matches = has_bbml3,
},
+ {
+ .desc = "BBM-less TTD updates via Access Flag",
+ .capability = ARM64_HAS_BBM_THROUGH_AF,
+ .type = ARM64_CPUCAP_SYSTEM_FEATURE,
+ .matches = has_bbm_through_af,
+ },
{
.desc = "52-bit Virtual Addressing for KVM (LPA2)",
.capability = ARM64_HAS_LPA2,
diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps
index 2775ba3359cf..25a84aa8a363 100644
--- a/arch/arm64/tools/cpucaps
+++ b/arch/arm64/tools/cpucaps
@@ -15,6 +15,7 @@ HAS_ADDRESS_AUTH_IMP_DEF
HAS_AMU_EXTN
HAS_ARMv8_4_TTL
HAS_BBML3
+HAS_BBM_THROUGH_AF
HAS_CACHE_DIC
HAS_CACHE_IDC
HAS_CNP
--
2.56.0.rc1.315.gc6ed9934b7-goog