diff mbox series

[RFC,v2,7/9] KVM: arm64: nv: selftests: Enable test to run in vEL2

Message ID 20250512105251.577874-8-gankulkarni@os.amperecomputing.com
State New
Headers show
Series [RFC,v2,1/9] KVM: arm64: nv: selftests: Add support to run guest code in vEL2. | expand

Commit Message

Ganapatrao Kulkarni May 12, 2025, 10:52 a.m. UTC
Modify the test to run the guest code with NV enabled.
Added code is only applicable to ARM64.

NV is enabled using command line argument and it is disabled by default.

Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
---
 .../testing/selftests/kvm/guest_print_test.c  | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)
diff mbox series

Patch

diff --git a/tools/testing/selftests/kvm/guest_print_test.c b/tools/testing/selftests/kvm/guest_print_test.c
index bcf582852db9..4f786b88fdbe 100644
--- a/tools/testing/selftests/kvm/guest_print_test.c
+++ b/tools/testing/selftests/kvm/guest_print_test.c
@@ -15,6 +15,15 @@ 
 #include "processor.h"
 #include "ucall_common.h"
 
+#ifdef __aarch64__
+#include "nv_util.h"
+static void pr_usage(const char *name)
+{
+	pr_info("%s [-g nv] -h\n", name);
+	pr_info("  -g:\tEnable Nested Virtualization, run guest code as guest hypervisor (default: Disabled)\n");
+}
+#endif
+
 struct guest_vals {
 	uint64_t a;
 	uint64_t b;
@@ -192,7 +201,30 @@  int main(int argc, char *argv[])
 	struct kvm_vcpu *vcpu;
 	struct kvm_vm *vm;
 
+#ifdef __aarch64__
+	int opt;
+	bool is_nested = false;
+	int gic_fd;
+
+	while ((opt = getopt(argc, argv, "g:")) != -1) {
+		switch (opt) {
+		case 'g':
+			is_nested = atoi_non_negative("Is Nested", optarg);
+			break;
+		case 'h':
+		default:
+			pr_usage(argv[0]);
+			return 1;
+		}
+	}
+
+	if (is_nested)
+		vm = nv_vm_create_with_vcpus_gic(1, &vcpu, &gic_fd, guest_code);
+	else
+		vm = vm_create_with_one_vcpu(&vcpu, guest_code);
+#else
 	vm = vm_create_with_one_vcpu(&vcpu, guest_code);
+#endif
 
 	test_type_i64(vcpu, -1, -1);
 	test_type_i64(vcpu, -1,  1);