[PATCH 2/2] KVM: arm64: Only clamp MTE_frac when the VM has MTE

Minhang Zhang sesame_h at qq.com
Fri Dec 4 01:12:25 PST 2026


From: Minhang Zhang <zhangminhang at kylinos.cn>

From: Minhang Zhang <zhangminhang at kylinos.cn>

On a host with ID_AA64PFR1_EL1.MTE == 2 and MTE_frac == 0xf,
set_id_aa64pfr1_el1() rewrites a userspace MTE_frac value of 0 to 0xf.
This preserves compatibility with older KVM versions that hid MTE_frac,
without advertising asynchronous tag check faults that the host does
not support.

The rewrite also applies to VMs without MTE. For these VMs,
sanitise_id_aa64pfr1_el1() clears both MTE and MTE_frac, so userspace
reads MTE_frac == 0. Writing that value back changes it to 0xf, which
does not match the sanitised value of this non-writable field.

When restoring the register to a VM whose ID registers have not yet
been finalised, this causes arm64_check_features() to return -E2BIG,
which set_id_reg() translates to -EINVAL for KVM_SET_ONE_REG. This can
prevent userspace from restoring a VM even though MTE is disabled.

Checking the VM's MTE capability alone is insufficient: nested
virtualisation also hides MTE and MTE_frac, even when that capability
is enabled.

Use the MTE field from KVM's sanitised ID register, which includes both
the VM's MTE capability and the nested virtualisation restrictions.
Only apply the compatibility rewrite when that field reports MTE2,
leaving MTE_frac at zero for VMs where KVM hides MTE.

Fixes: fe21ff5d4b46 ("KVM: arm64: Make MTE_frac masking conditional on MTE capability")
Signed-off-by: Minhang Zhang <zhangminhang at kylinos.cn>
Cc: stable at vger.kernel.org
---
 arch/arm64/kvm/sys_regs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 3eb872c11428..bdb8da50d74f 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -2364,8 +2364,9 @@ static int set_id_aa64pfr1_el1(struct kvm_vcpu *vcpu,
 			       const struct sys_reg_desc *rd, u64 user_val)
 {
 	u64 hw_val = read_sanitised_ftr_reg(SYS_ID_AA64PFR1_EL1);
+	u64 vm_val = kvm_read_sanitised_id_reg(vcpu, rd);
 	u64 mpam_mask = ID_AA64PFR1_EL1_MPAM_frac_MASK;
-	u8 mte = SYS_FIELD_GET(ID_AA64PFR1_EL1, MTE, hw_val);
+	u8 mte = SYS_FIELD_GET(ID_AA64PFR1_EL1, MTE, vm_val);
 	u8 user_mte_frac = SYS_FIELD_GET(ID_AA64PFR1_EL1, MTE_frac, user_val);
 	u8 hw_mte_frac = SYS_FIELD_GET(ID_AA64PFR1_EL1, MTE_frac, hw_val);
 
-- 
2.25.1




More information about the linux-arm-kernel mailing list