diff mbox series

[RFC,07/12] arm64: [HACK] Add option to show the kernel's KVM register ID list

Message ID 1547828061-20462-8-git-send-email-Dave.Martin@arm.com (mailing list archive)
State RFC
Headers show
Series arm64: SVE guest support test hacks | expand

Commit Message

Dave Martin Jan. 18, 2019, 4:14 p.m. UTC
To assist with testing and debugging the behaviour of
KVM_GET_REG_LIST, this patch adds a crude option --show-reg-list to
print out the list of register IDs reported by the kernel on vcpu
startup.

This is a development hack only and not currently friendly (or
useful) for users.

Signed-off-by: Dave Martin <Dave.Martin@arm.com>
---
 arm/aarch64/include/kvm/kvm-config-arch.h |  2 ++
 arm/include/arm-common/kvm-config-arch.h  |  1 +
 arm/kvm-cpu.c                             | 50 +++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+)
diff mbox series

Patch

diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h
index 04be43d..cb3f8bc 100644
--- a/arm/aarch64/include/kvm/kvm-config-arch.h
+++ b/arm/aarch64/include/kvm/kvm-config-arch.h
@@ -6,6 +6,8 @@ 
 			"Run AArch32 guest"),				\
 	OPT_BOOLEAN('\0', "pmu", &(cfg)->has_pmuv3,			\
 			"Create PMUv3 device"),				\
+	OPT_BOOLEAN('\0', "show-reg-list", &(cfg)->show_reg_list,	\
+		    "Show the list of KVM register IDs on startup"),	\
 	OPT_U64('\0', "kaslr-seed", &(cfg)->kaslr_seed,			\
 			"Specify random seed for Kernel Address Space "	\
 			"Layout Randomization (KASLR)"),
diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h
index 6a196f1..f18bfd4 100644
--- a/arm/include/arm-common/kvm-config-arch.h
+++ b/arm/include/arm-common/kvm-config-arch.h
@@ -9,6 +9,7 @@  struct kvm_config_arch {
 	bool		virtio_trans_pci;
 	bool		aarch32_guest;
 	bool		has_pmuv3;
+	bool		show_reg_list;
 	u64		kaslr_seed;
 	enum irqchip_type irqchip;
 };
diff --git a/arm/kvm-cpu.c b/arm/kvm-cpu.c
index 7780251..38a071b 100644
--- a/arm/kvm-cpu.c
+++ b/arm/kvm-cpu.c
@@ -1,6 +1,53 @@ 
+#include <errno.h>
+#include <stddef.h>
+#include <stdio.h>
+
 #include "kvm/kvm.h"
 #include "kvm/kvm-cpu.h"
 
+static int kvm_show_reg_list(struct kvm_cpu const *vcpu)
+{
+	int ret = -1;
+	struct kvm_reg_list regs, *pregs = NULL;
+	u64 i;
+
+	regs.n = 0;
+	if (ioctl(vcpu->vcpu_fd, KVM_GET_REG_LIST, &regs) && errno != E2BIG) {
+		perror("KVM_GET_REG_LIST");
+		goto error;
+	}
+
+	pregs = malloc(((char *)&pregs->reg[0] - (char *)pregs) +
+		       regs.n * sizeof(pregs->reg[0]));
+	if (!pregs) {
+		errno = ENOMEM;
+		perror(NULL);
+		goto error;
+	}
+
+	pregs->n = regs.n;
+	if (ioctl(vcpu->vcpu_fd, KVM_GET_REG_LIST, pregs)) {
+		perror("KVM_GET_REG_LIST");
+		goto error;
+	}
+
+	fflush(stdout);
+
+	printf("Register list for cpu 0x%lx:\n", vcpu->cpu_id);
+
+	for (i = 0; i < pregs->n; ++i)
+		printf("\treg[%lu]:\t0x%.16lx\n",
+		       (unsigned long)i, (unsigned long)pregs->reg[i]);
+
+	putchar('\n');
+
+	fflush(stdout);
+
+error:
+	free(pregs);
+	return ret;
+}
+
 static int debug_fd;
 
 void kvm_cpu__set_debug_fd(int fd)
@@ -109,6 +156,9 @@  struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)
 	if (err || target->init(vcpu))
 		die("Unable to initialise vcpu");
 
+	if (kvm->cfg.arch.show_reg_list)
+		kvm_show_reg_list(vcpu);
+
 	coalesced_offset = ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION,
 				 KVM_CAP_COALESCED_MMIO);
 	if (coalesced_offset)