Skip to content

Commit fe21ff5

Browse files
benhor01Marc Zyngier
authored andcommitted
KVM: arm64: Make MTE_frac masking conditional on MTE capability
If MTE_frac is masked out unconditionally then the guest will always see ID_AA64PFR1_EL1_MTE_frac as 0. However, a value of 0 when ID_AA64PFR1_EL1_MTE is 2 indicates that MTE_ASYNC is supported. Hence, for a host with ID_AA64PFR1_EL1_MTE==2 and ID_AA64PFR1_EL1_MTE_frac==0xf (MTE_ASYNC unsupported) the guest would see MTE_ASYNC advertised as supported whilst the host does not support it. Hence, expose the sanitised value of MTE_frac to the guest and user-space. As MTE_frac was previously hidden, always 0, and KVM must accept values from KVM provided by user-space, when ID_AA64PFR1_EL1.MTE is 2 allow user-space to set ID_AA64PFR1_EL1.MTE_frac to 0. However, ignore it to avoid incorrectly claiming hardware support for MTE_ASYNC in the guest. Note that linux does not check the value of ID_AA64PFR1_EL1_MTE_frac and wrongly assumes that MTE async faults can be generated even on hardware that does nto support them. This issue is not addressed here. Signed-off-by: Ben Horgan <ben.horgan@arm.com> Link: https://lore.kernel.org/r/20250512114112.359087-3-ben.horgan@arm.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 5799a29 commit fe21ff5

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,13 +1600,14 @@ static u64 __kvm_read_sanitised_id_reg(const struct kvm_vcpu *vcpu,
16001600
val = sanitise_id_aa64pfr0_el1(vcpu, val);
16011601
break;
16021602
case SYS_ID_AA64PFR1_EL1:
1603-
if (!kvm_has_mte(vcpu->kvm))
1603+
if (!kvm_has_mte(vcpu->kvm)) {
16041604
val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_MTE);
1605+
val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_MTE_frac);
1606+
}
16051607

16061608
val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_SME);
16071609
val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_RNDR_trap);
16081610
val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_NMI);
1609-
val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_MTE_frac);
16101611
val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_GCS);
16111612
val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_THE);
16121613
val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_MTEX);
@@ -1953,11 +1954,34 @@ static int set_id_aa64pfr1_el1(struct kvm_vcpu *vcpu,
19531954
{
19541955
u64 hw_val = read_sanitised_ftr_reg(SYS_ID_AA64PFR1_EL1);
19551956
u64 mpam_mask = ID_AA64PFR1_EL1_MPAM_frac_MASK;
1957+
u8 mte = SYS_FIELD_GET(ID_AA64PFR1_EL1, MTE, hw_val);
1958+
u8 user_mte_frac = SYS_FIELD_GET(ID_AA64PFR1_EL1, MTE_frac, user_val);
1959+
u8 hw_mte_frac = SYS_FIELD_GET(ID_AA64PFR1_EL1, MTE_frac, hw_val);
19561960

19571961
/* See set_id_aa64pfr0_el1 for comment about MPAM */
19581962
if ((hw_val & mpam_mask) == (user_val & mpam_mask))
19591963
user_val &= ~ID_AA64PFR1_EL1_MPAM_frac_MASK;
19601964

1965+
/*
1966+
* Previously MTE_frac was hidden from guest. However, if the
1967+
* hardware supports MTE2 but not MTE_ASYM_FAULT then a value
1968+
* of 0 for this field indicates that the hardware supports
1969+
* MTE_ASYNC. Whereas, 0xf indicates MTE_ASYNC is not supported.
1970+
*
1971+
* As KVM must accept values from KVM provided by user-space,
1972+
* when ID_AA64PFR1_EL1.MTE is 2 allow user-space to set
1973+
* ID_AA64PFR1_EL1.MTE_frac to 0. However, ignore it to avoid
1974+
* incorrectly claiming hardware support for MTE_ASYNC in the
1975+
* guest.
1976+
*/
1977+
1978+
if (mte == ID_AA64PFR1_EL1_MTE_MTE2 &&
1979+
hw_mte_frac == ID_AA64PFR1_EL1_MTE_frac_NI &&
1980+
user_mte_frac == ID_AA64PFR1_EL1_MTE_frac_ASYNC) {
1981+
user_val &= ~ID_AA64PFR1_EL1_MTE_frac_MASK;
1982+
user_val |= hw_val & ID_AA64PFR1_EL1_MTE_frac_MASK;
1983+
}
1984+
19611985
return set_id_reg(vcpu, rd, user_val);
19621986
}
19631987

0 commit comments

Comments
 (0)