Commit edba4078 authored by Marc Zyngier's avatar Marc Zyngier
Browse files

KVM: arm64: Add debugfs file dumping computed RESx values



Computing RESx values is hard. Verifying that they are correct is
harder. Add a debugfs file called "resx" that will dump all the RESx
values for a given VM.

I found it useful, maybe you will too.

Co-developed-by: default avatarFuad Tabba <tabba@google.com>
Signed-off-by: default avatarFuad Tabba <tabba@google.com>
Tested-by: default avatarFuad Tabba <tabba@google.com>
Link: https://patch.msgid.link/20260202184329.2724080-21-maz@kernel.org


Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
parent e8ef2790
Loading
Loading
Loading
Loading
+68 −0
Original line number Diff line number Diff line
@@ -5090,12 +5090,80 @@ static const struct seq_operations idregs_debug_sops = {

DEFINE_SEQ_ATTRIBUTE(idregs_debug);

static const struct sys_reg_desc *sr_resx_find(struct kvm *kvm, loff_t pos)
{
	unsigned long i, sr_idx = 0;

	for (i = 0; i < ARRAY_SIZE(sys_reg_descs); i++) {
		const struct sys_reg_desc *r = &sys_reg_descs[i];

		if (r->reg < __SANITISED_REG_START__)
			continue;

		if (sr_idx++ == pos)
			return r;
	}

	return NULL;
}

static void *sr_resx_start(struct seq_file *s, loff_t *pos)
{
	struct kvm *kvm = s->private;

	if (!kvm->arch.sysreg_masks)
		return NULL;

	return (void *)sr_resx_find(kvm, *pos);
}

static void *sr_resx_next(struct seq_file *s, void *v, loff_t *pos)
{
	struct kvm *kvm = s->private;

	(*pos)++;

	return (void *)sr_resx_find(kvm, *pos);
}

static void sr_resx_stop(struct seq_file *s, void *v)
{
}

static int sr_resx_show(struct seq_file *s, void *v)
{
	const struct sys_reg_desc *desc = v;
	struct kvm *kvm = s->private;
	struct resx resx;

	if (!desc)
		return 0;

	resx = kvm_get_sysreg_resx(kvm, desc->reg);

	seq_printf(s, "%20s:\tRES0:%016llx\tRES1:%016llx\n",
		   desc->name, resx.res0, resx.res1);

	return 0;
}

static const struct seq_operations sr_resx_sops = {
	.start	= sr_resx_start,
	.next	= sr_resx_next,
	.stop	= sr_resx_stop,
	.show	= sr_resx_show,
};

DEFINE_SEQ_ATTRIBUTE(sr_resx);

void kvm_sys_regs_create_debugfs(struct kvm *kvm)
{
	kvm->arch.idreg_debugfs_iter = ~0;

	debugfs_create_file("idregs", 0444, kvm->debugfs_dentry, kvm,
			    &idregs_debug_fops);
	debugfs_create_file("resx", 0444, kvm->debugfs_dentry, kvm,
			    &sr_resx_fops);
}

static void reset_vm_ftr_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *reg)