[PATCH 4/5] arm64: cpufeature: Add cpucap for DCZID_EL0.DZP

Pierre-Clément Tosi ptosi at google.com
Tue Dec 1 07:00:55 PST 2026


Enable the use of static branches on a system-wide CPU capability
matching a (sanitized) DCZID_EL0.DZP by introducing ARM64_HAS_DC_ZVA.

Note that the architecture does not guarantee this field to be constant
(EL2 can alter it for EL1, and EL1 for EL0) but it seems impossible to
me to have a well-behaved system using DZP-dependent instructions under
conditions where the bit flips dynamically as the check MRS DCZID_EL0
followed by DC *VA is inherently TOCTOU-prone. If EL2 lets Linux boot
with DZP=0 and then decides to set it, it must emulate the instructions.

Also note that the polarity of the capability means that instructions
patched with this cpucap default to an always-valid fallback e.g. STZGM
instead of DC GZVA. Similarly, heterogeneous systems with differing DZP
values get sanitized to not having the capability.

Cc: Marc Zyngier <maz at kernel.org>
Signed-off-by: Pierre-Clément Tosi <ptosi at google.com>
---
 arch/arm64/kernel/cpufeature.c | 14 ++++++++++++++
 arch/arm64/tools/cpucaps       |  1 +
 2 files changed, 15 insertions(+)

diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index e817d49037a6..09302f5ebc91 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -2424,6 +2424,13 @@ test_has_gicv5_legacy(const struct arm64_cpu_capabilities *entry, int scope)
 	return !!(read_sysreg_s(SYS_ICC_IDR0_EL1) & ICC_IDR0_EL1_GCIE_LEGACY);
 }
 
+static bool has_dc_zva(const struct arm64_cpu_capabilities *entry, int scope)
+{
+	u64 dczid = read_scoped_sysreg(entry, scope);
+
+	return !SYS_FIELD_GET(DCZID_EL0, DZP, dczid);
+}
+
 static const struct arm64_cpu_capabilities arm64_features[] = {
 	{
 		.capability = ARM64_ALWAYS_BOOT,
@@ -2619,6 +2626,13 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
 		ARM64_CPUID_FIELDS(ID_AA64PFR0_EL1, AMU, IMP)
 	},
 #endif /* CONFIG_ARM64_AMU_EXTN */
+	{
+		.desc = "Data cache zero by VA permitted (DCZID_EL0.DZP == 0)",
+		.capability = ARM64_HAS_DC_ZVA,
+		.type = ARM64_CPUCAP_SYSTEM_FEATURE,
+		.sys_reg = SYS_DCZID_EL0,
+		.matches = has_dc_zva,
+	},
 	{
 		.desc = "Data cache clean to the PoU not required for I/D coherence",
 		.capability = ARM64_HAS_CACHE_IDC,
diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps
index 51f5683374b0..283cc1c8fbe6 100644
--- a/arch/arm64/tools/cpucaps
+++ b/arch/arm64/tools/cpucaps
@@ -21,6 +21,7 @@ HAS_CNP
 HAS_CRC32
 HAS_DCPODP
 HAS_DCPOP
+HAS_DC_ZVA
 HAS_DIT
 HAS_E0PD
 HAS_ECV

-- 
2.56.1.839.g22a8290db9-goog




More information about the linux-arm-kernel mailing list