Commit 8af3e8ab authored by Marc Zyngier's avatar Marc Zyngier Committed by Oliver Upton
Browse files

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: default avatarMarc Zyngier <maz@kernel.org>
Reviewed-by: default avatarSebastian Ott <sebott@redhat.com>
Link: https://lore.kernel.org/r/20250718111154.104029-4-maz@kernel.org


Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
parent f5e6ebf2
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -5298,8 +5298,9 @@ int kvm_finalize_sys_regs(struct kvm_vcpu *vcpu)

int __init kvm_sys_reg_table_init(void)
{
	const struct sys_reg_desc *gicv3_regs;
	bool valid = true;
	unsigned int i;
	unsigned int i, sz;
	int ret = 0;

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

	gicv3_regs = vgic_v3_get_sysreg_table(&sz);
	valid &= check_sysreg_table(gicv3_regs, sz, false);

	if (!valid)
		return -EINVAL;

+6 −0
Original line number Diff line number Diff line
@@ -443,6 +443,12 @@ static const struct sys_reg_desc gic_v3_icc_reg_descs[] = {
	EL2_REG(ICH_LR15_EL2, ich_reg),
};

const struct sys_reg_desc *vgic_v3_get_sysreg_table(unsigned int *sz)
{
	*sz = ARRAY_SIZE(gic_v3_icc_reg_descs);
	return gic_v3_icc_reg_descs;
}

static u64 attr_to_id(u64 attr)
{
	return ARM64_SYS_REG(FIELD_GET(KVM_REG_ARM_VGIC_SYSREG_OP0_MASK, attr),
+1 −0
Original line number Diff line number Diff line
@@ -315,6 +315,7 @@ int vgic_v3_redist_uaccess(struct kvm_vcpu *vcpu, bool is_write,
int vgic_v3_cpu_sysregs_uaccess(struct kvm_vcpu *vcpu,
				struct kvm_device_attr *attr, bool is_write);
int vgic_v3_has_cpu_sysregs_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);
const struct sys_reg_desc *vgic_v3_get_sysreg_table(unsigned int *sz);
int vgic_v3_line_level_info_uaccess(struct kvm_vcpu *vcpu, bool is_write,
				    u32 intid, u32 *val);
int kvm_register_vgic_device(unsigned long type);