Skip to content

Commit 8af3e8a

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Enforce the sorting of the GICv3 system register table
In order to avoid further embarassing bugs, enforce that the GICv3 sysreg table is actually sorted, just like all the other tables. Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Sebastian Ott <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent f5e6ebf commit 8af3e8a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5298,8 +5298,9 @@ int kvm_finalize_sys_regs(struct kvm_vcpu *vcpu)
52985298

52995299
int __init kvm_sys_reg_table_init(void)
53005300
{
5301+
const struct sys_reg_desc *gicv3_regs;
53015302
bool valid = true;
5302-
unsigned int i;
5303+
unsigned int i, sz;
53035304
int ret = 0;
53045305

53055306
/* Make sure tables are unique and in order. */
@@ -5310,6 +5311,9 @@ int __init kvm_sys_reg_table_init(void)
53105311
valid &= check_sysreg_table(cp15_64_regs, ARRAY_SIZE(cp15_64_regs), false);
53115312
valid &= check_sysreg_table(sys_insn_descs, ARRAY_SIZE(sys_insn_descs), false);
53125313

5314+
gicv3_regs = vgic_v3_get_sysreg_table(&sz);
5315+
valid &= check_sysreg_table(gicv3_regs, sz, false);
5316+
53135317
if (!valid)
53145318
return -EINVAL;
53155319

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,12 @@ static const struct sys_reg_desc gic_v3_icc_reg_descs[] = {
443443
EL2_REG(ICH_LR15_EL2, ich_reg),
444444
};
445445

446+
const struct sys_reg_desc *vgic_v3_get_sysreg_table(unsigned int *sz)
447+
{
448+
*sz = ARRAY_SIZE(gic_v3_icc_reg_descs);
449+
return gic_v3_icc_reg_descs;
450+
}
451+
446452
static u64 attr_to_id(u64 attr)
447453
{
448454
return ARM64_SYS_REG(FIELD_GET(KVM_REG_ARM_VGIC_SYSREG_OP0_MASK, attr),

arch/arm64/kvm/vgic/vgic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ int vgic_v3_redist_uaccess(struct kvm_vcpu *vcpu, bool is_write,
315315
int vgic_v3_cpu_sysregs_uaccess(struct kvm_vcpu *vcpu,
316316
struct kvm_device_attr *attr, bool is_write);
317317
int vgic_v3_has_cpu_sysregs_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);
318+
const struct sys_reg_desc *vgic_v3_get_sysreg_table(unsigned int *sz);
318319
int vgic_v3_line_level_info_uaccess(struct kvm_vcpu *vcpu, bool is_write,
319320
u32 intid, u32 *val);
320321
int kvm_register_vgic_device(unsigned long type);

0 commit comments

Comments
 (0)