Skip to contentSkip to conversation

RFC: KVM test infrastructure (WIP)

PATCH New Martin Doucha 1 participant 1 message Jan 6, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RFC: KVM test infrastructure (WIP)

*** DO NOT MERGE THIS PATCH ***

This is a tech demo of the new KVM test library for LTP. The code has 3 main parts:
- KVM host library
- host_lib.c
- KVM guest library
- boostrap.S
- guest_lib.c
- kvm_x86.c
- Tests
- kvm_pagefault01.c

The host library provides functions for setting up and running virtual machines with test payload built from test sources.

The guest library provides CPU bootstrap code and basic implementation of some C and LTP library functions as well as functions for accessing low-level arch features like special registers, interrupt tables or memory mapping tables.

The test sources contain both guest-side payload code and host-side setup code separated by preprocessor switch. The files get compiled twice with different compiler options. Once to build the VM payload, once to build the main program that will create the VM and execute the payload inside it.

The KVM tests currently work only on x86_64. I'm still working on implementing i386 bootstrap code and skipping the build on unsupported archs.

Beware that if you merge this patch into LTP upstream in this state, you'll break LTP compilation on all non-x86 archs. This code is intended for discussion and private experiments only.

---
 include/mk/env_post.mk                    |   1 +
 include/mk/rules.mk                       |   8 +
 testcases/kernel/Makefile                 |   1 +
 testcases/kernel/kvm/Makefile             |  53 +++
 testcases/kernel/kvm/bootstrap_x86.S      | 372 ++++++++++++++++++++++
 testcases/kernel/kvm/guest_lib.c          |  92 ++++++
 testcases/kernel/kvm/host_lib.c           | 208 ++++++++++++
 testcases/kernel/kvm/include/kvm_common.h |  31 ++
 testcases/kernel/kvm/include/kvm_guest.h  |  47 +++
 testcases/kernel/kvm/include/kvm_host.h   | 115 +++++++
 testcases/kernel/kvm/include/kvm_test.h   |  23 ++
 testcases/kernel/kvm/include/kvm_x86.h    |  61 ++++
 testcases/kernel/kvm/kvm_pagefault01.c    | 104 ++++++
 testcases/kernel/kvm/kvm_x86.c            |  54 ++++
 testcases/kernel/kvm/layout-x86_64.lds    |  67 ++++
 testcases/kernel/kvm/payload.lds          |  11 +
 16 files changed, 1248 insertions(+)
 create mode 100644 testcases/kernel/kvm/Makefile
 create mode 100644 testcases/kernel/kvm/bootstrap_x86.S
 create mode 100644 testcases/kernel/kvm/guest_lib.c
 create mode 100644 testcases/kernel/kvm/host_lib.c
 create mode 100644 testcases/kernel/kvm/include/kvm_common.h
 create mode 100644 testcases/kernel/kvm/include/kvm_guest.h
 create mode 100644 testcases/kernel/kvm/include/kvm_host.h
 create mode 100644 testcases/kernel/kvm/include/kvm_test.h
 create mode 100644 testcases/kernel/kvm/include/kvm_x86.h
 create mode 100644 testcases/kernel/kvm/kvm_pagefault01.c
 create mode 100644 testcases/kernel/kvm/kvm_x86.c
 create mode 100644 testcases/kernel/kvm/layout-x86_64.lds
 create mode 100644 testcases/kernel/kvm/payload.lds
include/mk/env_post.mk +1 -0
index ec045c40d..dc4df41d3 100644
@@ -32,6 +32,7 @@ ENV_POST_LOADED = 1
 # poor software design if you need more than one search directory, and
 # would suggest creating a general purpose static library to that end.
 vpath %.c $(abs_srcdir)
+vpath %.S $(abs_srcdir)
 
 # For config.h, et all.
 CPPFLAGS			+= -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/include/old/
include/mk/rules.mk +8 -0
index a60e6705a..32d8d05a7 100644
@@ -1,5 +1,13 @@
 target_rel_dir := $(if $(cwd_rel_from_top),$(cwd_rel_from_top)/,)
 
+%.o: %.S
+ifdef VERBOSE
+	$(AS) $(ASFLAGS) -c -o $@ $<
+else
+	@$(AS) $(ASFLAGS) -c -o $@ $<
+	@echo AS $(target_rel_dir)$@
+endif
+
 %.o: %.c
 ifdef VERBOSE
 	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
testcases/kernel/Makefile +1 -0
index 4604f1f38..bad5c03a5 100644
@@ -29,6 +29,7 @@ SUBDIRS			+= connectors \
 			   io \
 			   ipc \
 			   irq \
+			   kvm \
 			   logging \
 			   mem \
 			   numa \
testcases/kernel/kvm/Makefile new file +53 -0

53 lines not on this page · raw message

testcases/kernel/kvm/bootstrap_x86.S new file +372 -0

372 lines not on this page · raw message

testcases/kernel/kvm/guest_lib.c new file +92 -0

92 lines not on this page · raw message

testcases/kernel/kvm/host_lib.c new file +208 -0

208 lines not on this page · raw message

testcases/kernel/kvm/include/kvm_common.h new file +31 -0
new file mode 100644
index 000000000..264f83841
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2021 SUSE LLC <[email protected]>
+ *
+ * Common definitions for communication between KVM guest and host.
+ */
+
+#ifndef KVM_COMMON_H_
+#define KVM_COMMON_H_
+
+/*
+ * KVM_Txxxx constants must match value of the corresponding Txxxx constant
+ * defined in tst_res_flags.h, if it exists.
+ */
+#define KVM_TNONE	-1	/* No result flag */
+#define KVM_TPASS	0	/* Test passed flag */
+#define KVM_TFAIL	1	/* Test failed flag */
+#define KVM_TBROK	2	/* Test broken flag */
+#define KVM_TWARN	4	/* Test warning flag */
+#define KVM_TINFO	16	/* Test information flag */
+#define KVM_TCONF	32	/* Test not appropriate for configuration */
+
+#define KVM_RESULT_BASEADDR 0xfffff000
+#define KVM_RESULT_SIZE 0x1000
+
+struct tst_kvm_result {
+	int result;
+	char message[0];
+};
+
+#endif /* KVM_COMMON_H_ */
testcases/kernel/kvm/include/kvm_guest.h new file +47 -0

47 lines not on this page · raw message

testcases/kernel/kvm/include/kvm_host.h new file +115 -0

115 lines not on this page · raw message

testcases/kernel/kvm/include/kvm_test.h new file +23 -0
new file mode 100644
index 000000000..55989eaa5
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2021 SUSE LLC <[email protected]>
+ *
+ * Minimal test library for KVM tests
+ */
+
+#ifndef KVM_TEST_H_
+#define KVM_TEST_H_
+
+#ifdef COMPILE_PAYLOAD
+
+  #include "kvm_guest.h"
+  #include "kvm_common.h"
+
+#else
+
+  #include "tst_test.h"
+  #include "kvm_host.h"
+
+#endif /* COMPILE_PAYLOAD */
+
+#endif /* KVM_TEST_H_ */
testcases/kernel/kvm/include/kvm_x86.h new file +61 -0

61 lines not on this page · raw message

testcases/kernel/kvm/kvm_pagefault01.c new file +104 -0

104 lines not on this page · raw message

testcases/kernel/kvm/kvm_x86.c new file +54 -0

54 lines not on this page · raw message

testcases/kernel/kvm/layout-x86_64.lds new file +67 -0

67 lines not on this page · raw message

testcases/kernel/kvm/payload.lds new file +11 -0
new file mode 100644
index 000000000..a544fd37a
@@ -0,0 +1,11 @@
+TARGET(binary)
+
+SECTIONS
+{
+	.data :
+	{
+		kvm_payload_start = .;
+		KEEP(*(.data))
+		kvm_payload_end = .;
+	}
+}
Signature · 5 lines
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp