Skip to content

Commit b61fc08

Browse files
author
Marc Zyngier
committed
KVM: arm64: vgic-v3: Simplify vgic_v3_has_cpu_sysregs_attr()
Finding out whether a sysreg exists has little to do with that register being accessed, so drop the is_write parameter. Also, the reg pointer is completely unused, and we're better off just passing the attr pointer to the function. This result in a small cleanup of the calling site, with a new helper converting the vGIC view of a sysreg into the canonical one (this is purely cosmetic, as the encoding is the same). Reviewed-by: Reiji Watanabe <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 5a420ed commit b61fc08

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

arch/arm64/kvm/vgic-sys-reg-v3.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,18 @@ static const struct sys_reg_desc gic_v3_icc_reg_descs[] = {
260260
{ SYS_DESC(SYS_ICC_IGRPEN1_EL1), access_gic_grpen1 },
261261
};
262262

263-
int vgic_v3_has_cpu_sysregs_attr(struct kvm_vcpu *vcpu, bool is_write, u64 id,
264-
u64 *reg)
263+
static u64 attr_to_id(u64 attr)
265264
{
266-
u64 sysreg = (id & KVM_DEV_ARM_VGIC_SYSREG_MASK) | KVM_REG_SIZE_U64;
265+
return ARM64_SYS_REG(FIELD_GET(KVM_REG_ARM_VGIC_SYSREG_OP0_MASK, attr),
266+
FIELD_GET(KVM_REG_ARM_VGIC_SYSREG_OP1_MASK, attr),
267+
FIELD_GET(KVM_REG_ARM_VGIC_SYSREG_CRN_MASK, attr),
268+
FIELD_GET(KVM_REG_ARM_VGIC_SYSREG_CRM_MASK, attr),
269+
FIELD_GET(KVM_REG_ARM_VGIC_SYSREG_OP2_MASK, attr));
270+
}
267271

268-
if (get_reg_by_id(sysreg, gic_v3_icc_reg_descs,
272+
int vgic_v3_has_cpu_sysregs_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
273+
{
274+
if (get_reg_by_id(attr_to_id(attr->attr), gic_v3_icc_reg_descs,
269275
ARRAY_SIZE(gic_v3_icc_reg_descs)))
270276
return 0;
271277

arch/arm64/kvm/vgic/vgic-mmio-v3.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -986,12 +986,8 @@ int vgic_v3_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr)
986986
iodev.base_addr = 0;
987987
break;
988988
}
989-
case KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS: {
990-
u64 reg, id;
991-
992-
id = (attr->attr & KVM_DEV_ARM_VGIC_SYSREG_INSTR_MASK);
993-
return vgic_v3_has_cpu_sysregs_attr(vcpu, 0, id, &reg);
994-
}
989+
case KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS:
990+
return vgic_v3_has_cpu_sysregs_attr(vcpu, attr);
995991
default:
996992
return -ENXIO;
997993
}

arch/arm64/kvm/vgic/vgic.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ int vgic_v3_redist_uaccess(struct kvm_vcpu *vcpu, bool is_write,
247247
int offset, u32 *val);
248248
int vgic_v3_cpu_sysregs_uaccess(struct kvm_vcpu *vcpu, bool is_write,
249249
u64 id, u64 *val);
250-
int vgic_v3_has_cpu_sysregs_attr(struct kvm_vcpu *vcpu, bool is_write, u64 id,
251-
u64 *reg);
250+
int vgic_v3_has_cpu_sysregs_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);
252251
int vgic_v3_line_level_info_uaccess(struct kvm_vcpu *vcpu, bool is_write,
253252
u32 intid, u64 *val);
254253
int kvm_register_vgic_device(unsigned long type);

0 commit comments

Comments
 (0)