Skip to content

Commit 9d67455

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Hide ID_AA64MMFR2_EL1.NV from guest and userspace
Since our take on FEAT_NV is to only support FEAT_NV2, we should never expose ID_AA64MMFR2_EL1.NV to a guest nor userspace. Make sure we mask this field for good. Signed-off-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Joey Gouly <joey.gouly@arm.com> Link: https://lore.kernel.org/r/20250220134907.554085-3-maz@kernel.org [oliver: squash diff for NV field] Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 88aea41 commit 9d67455

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,7 @@ static u64 __kvm_read_sanitised_id_reg(const struct kvm_vcpu *vcpu,
16271627
break;
16281628
case SYS_ID_AA64MMFR2_EL1:
16291629
val &= ~ID_AA64MMFR2_EL1_CCIDX_MASK;
1630+
val &= ~ID_AA64MMFR2_EL1_NV;
16301631
break;
16311632
case SYS_ID_AA64MMFR3_EL1:
16321633
val &= ID_AA64MMFR3_EL1_TCRX | ID_AA64MMFR3_EL1_S1POE |
@@ -1945,6 +1946,22 @@ static int set_id_aa64pfr1_el1(struct kvm_vcpu *vcpu,
19451946
return set_id_reg(vcpu, rd, user_val);
19461947
}
19471948

1949+
static int set_id_aa64mmfr2_el1(struct kvm_vcpu *vcpu,
1950+
const struct sys_reg_desc *rd, u64 user_val)
1951+
{
1952+
u64 hw_val = read_sanitised_ftr_reg(SYS_ID_AA64MMFR2_EL1);
1953+
u64 nv_mask = ID_AA64MMFR2_EL1_NV_MASK;
1954+
1955+
/*
1956+
* We made the mistake to expose the now deprecated NV field,
1957+
* so allow userspace to write it, but silently ignore it.
1958+
*/
1959+
if ((hw_val & nv_mask) == (user_val & nv_mask))
1960+
user_val &= ~nv_mask;
1961+
1962+
return set_id_reg(vcpu, rd, user_val);
1963+
}
1964+
19481965
static int set_ctr_el0(struct kvm_vcpu *vcpu,
19491966
const struct sys_reg_desc *rd, u64 user_val)
19501967
{
@@ -2671,7 +2688,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
26712688
ID_AA64MMFR1_EL1_XNX |
26722689
ID_AA64MMFR1_EL1_VH |
26732690
ID_AA64MMFR1_EL1_VMIDBits)),
2674-
ID_WRITABLE(ID_AA64MMFR2_EL1, ~(ID_AA64MMFR2_EL1_RES0 |
2691+
ID_FILTERED(ID_AA64MMFR2_EL1,
2692+
id_aa64mmfr2_el1, ~(ID_AA64MMFR2_EL1_RES0 |
26752693
ID_AA64MMFR2_EL1_EVT |
26762694
ID_AA64MMFR2_EL1_FWB |
26772695
ID_AA64MMFR2_EL1_IDS |

0 commit comments

Comments
 (0)