Skip to content

Commit c512298

Browse files
Andrew JonesMarc Zyngier
authored andcommitted
KVM: arm64: Remove AA64ZFR0_EL1 accessors
The AA64ZFR0_EL1 accessors are just the general accessors with its visibility function open-coded. It also skips the if-else chain in read_id_reg, but there's no reason not to go there. Indeed consolidating ID register accessors and removing lines of code make it worthwhile. Remove the AA64ZFR0_EL1 accessors, replacing them with the general accessors for sanitized ID registers. No functional change intended. Signed-off-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20201105091022.15373-5-drjones@redhat.com
1 parent 912dee5 commit c512298

1 file changed

Lines changed: 11 additions & 50 deletions

File tree

arch/arm64/kvm/sys_regs.c

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,16 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,
11541154
static unsigned int id_visibility(const struct kvm_vcpu *vcpu,
11551155
const struct sys_reg_desc *r)
11561156
{
1157+
u32 id = sys_reg((u32)r->Op0, (u32)r->Op1,
1158+
(u32)r->CRn, (u32)r->CRm, (u32)r->Op2);
1159+
1160+
switch (id) {
1161+
case SYS_ID_AA64ZFR0_EL1:
1162+
if (!vcpu_has_sve(vcpu))
1163+
return REG_RAZ;
1164+
break;
1165+
}
1166+
11571167
return 0;
11581168
}
11591169

@@ -1201,55 +1211,6 @@ static unsigned int sve_visibility(const struct kvm_vcpu *vcpu,
12011211
return REG_HIDDEN;
12021212
}
12031213

1204-
/* Generate the emulated ID_AA64ZFR0_EL1 value exposed to the guest */
1205-
static u64 guest_id_aa64zfr0_el1(const struct kvm_vcpu *vcpu)
1206-
{
1207-
if (!vcpu_has_sve(vcpu))
1208-
return 0;
1209-
1210-
return read_sanitised_ftr_reg(SYS_ID_AA64ZFR0_EL1);
1211-
}
1212-
1213-
static bool access_id_aa64zfr0_el1(struct kvm_vcpu *vcpu,
1214-
struct sys_reg_params *p,
1215-
const struct sys_reg_desc *rd)
1216-
{
1217-
if (p->is_write)
1218-
return write_to_read_only(vcpu, p, rd);
1219-
1220-
p->regval = guest_id_aa64zfr0_el1(vcpu);
1221-
return true;
1222-
}
1223-
1224-
static int get_id_aa64zfr0_el1(struct kvm_vcpu *vcpu,
1225-
const struct sys_reg_desc *rd,
1226-
const struct kvm_one_reg *reg, void __user *uaddr)
1227-
{
1228-
u64 val;
1229-
1230-
val = guest_id_aa64zfr0_el1(vcpu);
1231-
return reg_to_user(uaddr, &val, reg->id);
1232-
}
1233-
1234-
static int set_id_aa64zfr0_el1(struct kvm_vcpu *vcpu,
1235-
const struct sys_reg_desc *rd,
1236-
const struct kvm_one_reg *reg, void __user *uaddr)
1237-
{
1238-
const u64 id = sys_reg_to_index(rd);
1239-
int err;
1240-
u64 val;
1241-
1242-
err = reg_from_user(&val, uaddr, id);
1243-
if (err)
1244-
return err;
1245-
1246-
/* This is what we mean by invariant: you can't change it. */
1247-
if (val != guest_id_aa64zfr0_el1(vcpu))
1248-
return -EINVAL;
1249-
1250-
return 0;
1251-
}
1252-
12531214
/*
12541215
* cpufeature ID register user accessors
12551216
*
@@ -1506,7 +1467,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {
15061467
ID_SANITISED(ID_AA64PFR1_EL1),
15071468
ID_UNALLOCATED(4,2),
15081469
ID_UNALLOCATED(4,3),
1509-
{ SYS_DESC(SYS_ID_AA64ZFR0_EL1), access_id_aa64zfr0_el1, .get_user = get_id_aa64zfr0_el1, .set_user = set_id_aa64zfr0_el1, },
1470+
ID_SANITISED(ID_AA64ZFR0_EL1),
15101471
ID_UNALLOCATED(4,5),
15111472
ID_UNALLOCATED(4,6),
15121473
ID_UNALLOCATED(4,7),

0 commit comments

Comments
 (0)