Skip to content

Commit 3f1e072

Browse files
Sebastian Ottoupton
authored andcommitted
KVM: arm64: Allow userspace to write ID_AA64MMFR0_EL1.TGRAN*_2
Allow userspace to write the safe (NI) value for ID_AA64MMFR0_EL1.TGRAN*_2. Disallow to change these fields for NV since kvm provides a sanitized view for them based on the PAGE_SIZE. Signed-off-by: Sebastian Ott <sebott@redhat.com> Link: https://lore.kernel.org/kvmarm/20250306184013.30008-1-sebott@redhat.com/ Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 8b0b98e commit 3f1e072

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,21 @@ static int set_id_aa64pfr1_el1(struct kvm_vcpu *vcpu,
19391939
return set_id_reg(vcpu, rd, user_val);
19401940
}
19411941

1942+
static int set_id_aa64mmfr0_el1(struct kvm_vcpu *vcpu,
1943+
const struct sys_reg_desc *rd, u64 user_val)
1944+
{
1945+
u64 sanitized_val = kvm_read_sanitised_id_reg(vcpu, rd);
1946+
u64 tgran2_mask = ID_AA64MMFR0_EL1_TGRAN4_2_MASK |
1947+
ID_AA64MMFR0_EL1_TGRAN16_2_MASK |
1948+
ID_AA64MMFR0_EL1_TGRAN64_2_MASK;
1949+
1950+
if (vcpu_has_nv(vcpu) &&
1951+
((sanitized_val & tgran2_mask) != (user_val & tgran2_mask)))
1952+
return -EINVAL;
1953+
1954+
return set_id_reg(vcpu, rd, user_val);
1955+
}
1956+
19421957
static int set_id_aa64mmfr2_el1(struct kvm_vcpu *vcpu,
19431958
const struct sys_reg_desc *rd, u64 user_val)
19441959
{
@@ -2662,10 +2677,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
26622677
ID_UNALLOCATED(6,7),
26632678

26642679
/* CRm=7 */
2665-
ID_WRITABLE(ID_AA64MMFR0_EL1, ~(ID_AA64MMFR0_EL1_RES0 |
2666-
ID_AA64MMFR0_EL1_TGRAN4_2 |
2667-
ID_AA64MMFR0_EL1_TGRAN64_2 |
2668-
ID_AA64MMFR0_EL1_TGRAN16_2 |
2680+
ID_FILTERED(ID_AA64MMFR0_EL1, id_aa64mmfr0_el1,
2681+
~(ID_AA64MMFR0_EL1_RES0 |
26692682
ID_AA64MMFR0_EL1_ASIDBITS)),
26702683
ID_WRITABLE(ID_AA64MMFR1_EL1, ~(ID_AA64MMFR1_EL1_RES0 |
26712684
ID_AA64MMFR1_EL1_HCX |

0 commit comments

Comments
 (0)