aboutsummaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kvm/get-reg-list.c
diff options
context:
space:
mode:
authorGravatar Andrew Jones <ajones@ventanamicro.com> 2023-07-25 16:41:33 +0800
committerGravatar Anup Patel <anup@brainfault.org> 2023-08-09 12:15:12 +0530
commitbe4c58060c3efd1f8dff59e59ff8e69d08f00560 (patch)
tree40cfc454eff18881ed27ee30a6d1ca5523b61b51 /tools/testing/selftests/kvm/get-reg-list.c
parentKVM: arm64: selftests: Split get-reg-list test code (diff)
downloadlinux-be4c58060c3efd1f8dff59e59ff8e69d08f00560.tar.gz
linux-be4c58060c3efd1f8dff59e59ff8e69d08f00560.tar.bz2
linux-be4c58060c3efd1f8dff59e59ff8e69d08f00560.zip
KVM: arm64: selftests: Finish generalizing get-reg-list
Add some unfortunate #ifdeffery to ensure the common get-reg-list.c can be compiled and run with other architectures. The next architecture to support get-reg-list should now only need to provide $(ARCH_DIR)/get-reg-list.c where arch-specific print_reg() and vcpu_configs[] get defined. Signed-off-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Haibo Xu <haibo1.xu@intel.com> Signed-off-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'tools/testing/selftests/kvm/get-reg-list.c')
-rw-r--r--tools/testing/selftests/kvm/get-reg-list.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/tools/testing/selftests/kvm/get-reg-list.c b/tools/testing/selftests/kvm/get-reg-list.c
index a29e548643d1..853cbf470da2 100644
--- a/tools/testing/selftests/kvm/get-reg-list.c
+++ b/tools/testing/selftests/kvm/get-reg-list.c
@@ -104,6 +104,7 @@ void __weak print_reg(const char *prefix, __u64 id)
printf("\t0x%llx,\n", id);
}
+#ifdef __aarch64__
static void prepare_vcpu_init(struct vcpu_reg_list *c, struct kvm_vcpu_init *init)
{
struct vcpu_reg_sublist *s;
@@ -126,6 +127,25 @@ static void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c)
}
}
+static struct kvm_vcpu *vcpu_config_get_vcpu(struct vcpu_reg_list *c, struct kvm_vm *vm)
+{
+ struct kvm_vcpu_init init = { .target = -1, };
+ struct kvm_vcpu *vcpu;
+
+ prepare_vcpu_init(c, &init);
+ vcpu = __vm_vcpu_add(vm, 0);
+ aarch64_vcpu_setup(vcpu, &init);
+ finalize_vcpu(vcpu, c);
+
+ return vcpu;
+}
+#else
+static struct kvm_vcpu *vcpu_config_get_vcpu(struct vcpu_reg_list *c, struct kvm_vm *vm)
+{
+ return __vm_vcpu_add(vm, 0);
+}
+#endif
+
static void check_supported(struct vcpu_reg_list *c)
{
struct vcpu_reg_sublist *s;
@@ -145,7 +165,6 @@ static bool print_filtered;
static void run_test(struct vcpu_reg_list *c)
{
- struct kvm_vcpu_init init = { .target = -1, };
int new_regs = 0, missing_regs = 0, i, n;
int failed_get = 0, failed_set = 0, failed_reject = 0;
struct kvm_vcpu *vcpu;
@@ -155,10 +174,7 @@ static void run_test(struct vcpu_reg_list *c)
check_supported(c);
vm = vm_create_barebones();
- prepare_vcpu_init(c, &init);
- vcpu = __vm_vcpu_add(vm, 0);
- aarch64_vcpu_setup(vcpu, &init);
- finalize_vcpu(vcpu, c);
+ vcpu = vcpu_config_get_vcpu(c, vm);
reg_list = vcpu_get_reg_list(vcpu);