Skip to contentSkip to conversation

KVM: selftests: Cleanups, take 2

PATCH Superseded Andrew Jones 4 participants 17 messages Nov 16, 2020 – Dec 18, 2020

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover KVM: selftests: Cleanups, take 2

This series attempts to clean up demand_paging_test, dirty_log_perf_test, and dirty_log_test by factoring out common code, creating some new API along the way. It also splits include/perf_test_util.h into a more conventional header and source pair.

I've tested on x86 and AArch64 (one config each), but not s390x.

v3:
- Rebased remaining four patches from v2 onto kvm/queue
- Picked up r-b's from Peter and Ben

v2: https://www.spinics.net/lists/kvm/msg228711.html

Thanks,
drew

Andrew Jones (4):
KVM: selftests: Factor out guest mode code
KVM: selftests: dirty_log_test: Remove create_vm
KVM: selftests: Use vm_create_with_vcpus in create_vm
KVM: selftests: Implement perf_test_util more conventionally

 tools/testing/selftests/kvm/Makefile          |   2 +-
 .../selftests/kvm/demand_paging_test.c        | 118 ++++--------
 .../selftests/kvm/dirty_log_perf_test.c       | 145 +++++---------
 tools/testing/selftests/kvm/dirty_log_test.c  | 179 +++++-------------
 .../selftests/kvm/include/guest_modes.h       |  21 ++
 .../testing/selftests/kvm/include/kvm_util.h  |   9 +
 .../selftests/kvm/include/perf_test_util.h    | 167 ++--------------
 tools/testing/selftests/kvm/lib/guest_modes.c |  70 +++++++
 tools/testing/selftests/kvm/lib/kvm_util.c    |   9 +-
 .../selftests/kvm/lib/perf_test_util.c        | 134 +++++++++++++
 10 files changed, 378 insertions(+), 476 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/include/guest_modes.h
 create mode 100644 tools/testing/selftests/kvm/lib/guest_modes.c
 create mode 100644 tools/testing/selftests/kvm/lib/perf_test_util.c
Signature · 1 line
2.26.2
#1 lore raw

PATCH v3 1/4 KVM: selftests: Factor out guest mode code

demand_paging_test, dirty_log_test, and dirty_log_perf_test have redundant guest mode code. Factor it out.

Also, while adding a new include, remove the ones we don't need.

---
 tools/testing/selftests/kvm/Makefile          |   2 +-
 .../selftests/kvm/demand_paging_test.c        | 107 ++++-----------
 .../selftests/kvm/dirty_log_perf_test.c       | 121 +++++------------
 tools/testing/selftests/kvm/dirty_log_test.c  | 125 ++++++------------
 .../selftests/kvm/include/guest_modes.h       |  21 +++
 tools/testing/selftests/kvm/lib/guest_modes.c |  70 ++++++++++
 6 files changed, 189 insertions(+), 257 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/include/guest_modes.h
 create mode 100644 tools/testing/selftests/kvm/lib/guest_modes.c
tools/testing/selftests/kvm/Makefile +1 -1
index 4febf4d5ead9..ba24691719ef 100644
@@ -33,7 +33,7 @@ ifeq ($(ARCH),s390)
 	UNAME_M := s390x
 endif
 
-LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c
+LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c lib/guest_modes.c
 LIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c lib/x86_64/handlers.S
 LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c
 LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c
tools/testing/selftests/kvm/demand_paging_test.c +26 -81

184 lines not on this page · raw message

tools/testing/selftests/kvm/dirty_log_perf_test.c +34 -87

214 lines not on this page · raw message

tools/testing/selftests/kvm/dirty_log_test.c +37 -88

210 lines not on this page · raw message

tools/testing/selftests/kvm/include/guest_modes.h new file +21 -0
new file mode 100644
index 000000000000..b691df33e64e
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020, Red Hat, Inc.
+ */
+#include "kvm_util.h"
+
+struct guest_mode {
+	bool supported;
+	bool enabled;
+};
+
+extern struct guest_mode guest_modes[NUM_VM_MODES];
+
+#define guest_mode_append(mode, supported, enabled) ({ \
+	guest_modes[mode] = (struct guest_mode){ supported, enabled }; \
+})
+
+void guest_modes_append_default(void);
+void for_each_guest_mode(void (*func)(enum vm_guest_mode, void *), void *arg);
+void guest_modes_help(void);
+void guest_modes_cmdline(const char *arg);
tools/testing/selftests/kvm/lib/guest_modes.c new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
2.26.2
#2 lore raw

PATCH v3 2/4 KVM: selftests: dirty_log_test: Remove create_vm

In reply to Andrew Jones

Use vm_create_with_vcpus instead of create_vm and do some minor cleanups around it.

---
 tools/testing/selftests/kvm/dirty_log_test.c | 56 ++++++--------------
 1 file changed, 16 insertions(+), 40 deletions(-)
tools/testing/selftests/kvm/dirty_log_test.c +16 -40
index bb2752d78fe3..5af730deb86b 100644
@@ -5,8 +5,6 @@
  * Copyright (C) 2018, Red Hat, Inc.
  */
 
-#define _GNU_SOURCE /* for program_invocation_name */
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <pthread.h>
@@ -25,6 +23,9 @@
 
 #define VCPU_ID				1
 
+#define DIRTY_MEM_BITS			30 /* 1G */
+#define DIRTY_MEM_SIZE			(1UL << DIRTY_MEM_BITS)
+
 /* The memory slot index to track dirty pages */
 #define TEST_MEM_SLOT_INDEX		1
 
@@ -651,27 +652,6 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap)
 	}
 }
 
-static struct kvm_vm *create_vm(enum vm_guest_mode mode, uint32_t vcpuid,
-				uint64_t extra_mem_pages, void *guest_code)
-{
-	struct kvm_vm *vm;
-	uint64_t extra_pg_pages = extra_mem_pages / 512 * 2;
-
-	pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
-
-	vm = vm_create(mode, DEFAULT_GUEST_PHY_PAGES + extra_pg_pages, O_RDWR);
-	kvm_vm_elf_load(vm, program_invocation_name, 0, 0);
-#ifdef __x86_64__
-	vm_create_irqchip(vm);
-#endif
-	log_mode_create_vm_done(vm);
-	vm_vcpu_add_default(vm, vcpuid, guest_code);
-	return vm;
-}
-
-#define DIRTY_MEM_BITS 30 /* 1G */
-#define PAGE_SHIFT_4K  12
-
 struct test_params {
 	unsigned long iterations;
 	unsigned long interval;
@@ -690,43 +670,39 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 		return;
 	}
 
+	pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
+
 	/*
 	 * We reserve page table for 2 times of extra dirty mem which
-	 * will definitely cover the original (1G+) test range.  Here
-	 * we do the calculation with 4K page size which is the
-	 * smallest so the page number will be enough for all archs
-	 * (e.g., 64K page size guest will need even less memory for
-	 * page tables).
+	 * will definitely cover the original (1G+) test range.
 	 */
-	vm = create_vm(mode, VCPU_ID,
-		       2ul << (DIRTY_MEM_BITS - PAGE_SHIFT_4K),
-		       guest_code);
+	vm = vm_create_with_vcpus(mode, 1,
+			vm_calc_num_guest_pages(mode, DIRTY_MEM_SIZE * 2),
+			0, guest_code, (uint32_t []){ VCPU_ID });
+
+	log_mode_create_vm_done(vm);
 
 	guest_page_size = vm_get_page_size(vm);
+	host_page_size = getpagesize();
+
 	/*
 	 * A little more than 1G of guest page sized pages.  Cover the
 	 * case where the size is not aligned to 64 pages.
 	 */
-	guest_num_pages = (1ul << (DIRTY_MEM_BITS -
-				   vm_get_page_shift(vm))) + 3;
-	guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
-
-	host_page_size = getpagesize();
+	guest_num_pages = vm_adjust_num_guest_pages(mode,
+				(1ul << (DIRTY_MEM_BITS - vm_get_page_shift(vm))) + 3);
 	host_num_pages = vm_num_host_pages(mode, guest_num_pages);
 
 	if (!p->phys_offset) {
-		guest_test_phys_mem = (vm_get_max_gfn(vm) -
-				       guest_num_pages) * guest_page_size;
+		guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) * guest_page_size;
 		guest_test_phys_mem &= ~(host_page_size - 1);
 	} else {
 		guest_test_phys_mem = p->phys_offset;
 	}
-
 #ifdef __s390x__
 	/* Align to 1M (segment size) */
 	guest_test_phys_mem &= ~((1 << 20) - 1);
 #endif
-
 	pr_info("guest physical test memory offset: 0x%lx\n", guest_test_phys_mem);
 
 	bmap = bitmap_alloc(host_num_pages);
Signature · 1 line
2.26.2
#3 lore raw

PATCH v3 3/4 KVM: selftests: Use vm_create_with_vcpus in create_vm

In reply to Andrew Jones
---
 .../selftests/kvm/demand_paging_test.c        |  2 +-
 .../selftests/kvm/dirty_log_perf_test.c       |  2 -
 .../testing/selftests/kvm/include/kvm_util.h  |  8 ++++
 .../selftests/kvm/include/perf_test_util.h    | 47 +++++--------------
 tools/testing/selftests/kvm/lib/kvm_util.c    |  9 +---
 5 files changed, 21 insertions(+), 47 deletions(-)
tools/testing/selftests/kvm/demand_paging_test.c +1 -1
index 946161a9ce2d..b0c41de32e9b 100644
@@ -7,7 +7,7 @@
  * Copyright (C) 2019, Google, Inc.
  */
 
-#define _GNU_SOURCE /* for program_invocation_name and pipe2 */
+#define _GNU_SOURCE /* for pipe2 */
 
 #include <stdio.h>
 #include <stdlib.h>
tools/testing/selftests/kvm/dirty_log_perf_test.c +0 -2
index 506741eb5d7f..36bea75a8d6f 100644
@@ -8,8 +8,6 @@
  * Copyright (C) 2020, Google, Inc.
  */
 
-#define _GNU_SOURCE /* for program_invocation_name */
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
tools/testing/selftests/kvm/include/kvm_util.h +8 -0
index dfa9d369e8fc..149766ecd68b 100644
@@ -70,6 +70,14 @@ enum vm_guest_mode {
 #define vm_guest_mode_string(m) vm_guest_mode_string[m]
 extern const char * const vm_guest_mode_string[];
 
+struct vm_guest_mode_params {
+	unsigned int pa_bits;
+	unsigned int va_bits;
+	unsigned int page_size;
+	unsigned int page_shift;
+};
+extern const struct vm_guest_mode_params vm_guest_mode_params[];
+
 enum vm_mem_backing_src_type {
 	VM_MEM_SRC_ANONYMOUS,
 	VM_MEM_SRC_ANONYMOUS_THP,
tools/testing/selftests/kvm/include/perf_test_util.h +11 -36

87 lines not on this page · raw message

tools/testing/selftests/kvm/lib/kvm_util.c +1 -8
index b2c426adb87f..14fcadb778b5 100644
@@ -153,14 +153,7 @@ const char * const vm_guest_mode_string[] = {
 _Static_assert(sizeof(vm_guest_mode_string)/sizeof(char *) == NUM_VM_MODES,
 	       "Missing new mode strings?");
 
-struct vm_guest_mode_params {
-	unsigned int pa_bits;
-	unsigned int va_bits;
-	unsigned int page_size;
-	unsigned int page_shift;
-};
-
-static const struct vm_guest_mode_params vm_guest_mode_params[] = {
+const struct vm_guest_mode_params vm_guest_mode_params[] = {
 	{ 52, 48,  0x1000, 12 },
 	{ 52, 48, 0x10000, 16 },
 	{ 48, 48,  0x1000, 12 },
Signature · 1 line
2.26.2
#4 lore raw

PATCH v3 4/4 KVM: selftests: Implement perf_test_util more conventionally

In reply to Andrew Jones

It's not conventional C to put non-inline functions in header files. Create a source file for the functions instead. Also reduce the amount of globals and rename the functions to something less generic.

---
 tools/testing/selftests/kvm/Makefile          |   2 +-
 .../selftests/kvm/demand_paging_test.c        |  11 +-
 .../selftests/kvm/dirty_log_perf_test.c       |  22 +--
 .../testing/selftests/kvm/include/kvm_util.h  |   1 +
 .../selftests/kvm/include/perf_test_util.h    | 142 ++----------------
 .../selftests/kvm/lib/perf_test_util.c        | 134 +++++++++++++++++
 6 files changed, 166 insertions(+), 146 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/lib/perf_test_util.c
tools/testing/selftests/kvm/Makefile +1 -1
index ba24691719ef..74e99a2b1b49 100644
@@ -33,7 +33,7 @@ ifeq ($(ARCH),s390)
 	UNAME_M := s390x
 endif
 
-LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c lib/guest_modes.c
+LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c lib/guest_modes.c lib/perf_test_util.c
 LIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c lib/x86_64/handlers.S
 LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c
 LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c
tools/testing/selftests/kvm/demand_paging_test.c +6 -5
index b0c41de32e9b..cdad1eca72f7 100644
@@ -36,12 +36,14 @@
 #define PER_VCPU_DEBUG(...) _no_printf(__VA_ARGS__)
 #endif
 
+static int nr_vcpus = 1;
+static uint64_t guest_percpu_mem_size = DEFAULT_PER_VCPU_MEM_SIZE;
 static char *guest_data_prototype;
 
 static void *vcpu_worker(void *data)
 {
 	int ret;
-	struct vcpu_args *vcpu_args = (struct vcpu_args *)data;
+	struct perf_test_vcpu_args *vcpu_args = (struct perf_test_vcpu_args *)data;
 	int vcpu_id = vcpu_args->vcpu_id;
 	struct kvm_vm *vm = perf_test_args.vm;
 	struct kvm_run *run;
@@ -263,7 +265,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	int vcpu_id;
 	int r;
 
-	vm = create_vm(mode, nr_vcpus, guest_percpu_mem_size);
+	vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size);
 
 	perf_test_args.wr_fract = 1;
 
@@ -275,7 +277,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
 	TEST_ASSERT(vcpu_threads, "Memory allocation failed");
 
-	add_vcpus(vm, nr_vcpus, guest_percpu_mem_size);
+	perf_test_setup_vcpus(vm, nr_vcpus, guest_percpu_mem_size);
 
 	if (p->use_uffd) {
 		uffd_handler_threads =
@@ -359,8 +361,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 		perf_test_args.vcpu_args[0].pages * nr_vcpus /
 		((double)ts_diff.tv_sec + (double)ts_diff.tv_nsec / 100000000.0));
 
-	ucall_uninit(vm);
-	kvm_vm_free(vm);
+	perf_test_destroy_vm(vm);
 
 	free(guest_data_prototype);
 	free(vcpu_threads);
tools/testing/selftests/kvm/dirty_log_perf_test.c +12 -10
index 36bea75a8d6f..2283a0ec74a9 100644
@@ -22,11 +22,14 @@
 /* How many host loops to run by default (one KVM_GET_DIRTY_LOG for each loop)*/
 #define TEST_HOST_LOOP_N		2UL
 
+static int nr_vcpus = 1;
+static uint64_t guest_percpu_mem_size = DEFAULT_PER_VCPU_MEM_SIZE;
+
 /* Host variables */
 static u64 dirty_log_manual_caps;
 static bool host_quit;
 static uint64_t iteration;
-static uint64_t vcpu_last_completed_iteration[MAX_VCPUS];
+static uint64_t vcpu_last_completed_iteration[KVM_MAX_VCPUS];
 
 static void *vcpu_worker(void *data)
 {
@@ -38,7 +41,7 @@ static void *vcpu_worker(void *data)
 	struct timespec ts_diff;
 	struct timespec total = (struct timespec){0};
 	struct timespec avg;
-	struct vcpu_args *vcpu_args = (struct vcpu_args *)data;
+	struct perf_test_vcpu_args *vcpu_args = (struct perf_test_vcpu_args *)data;
 	int vcpu_id = vcpu_args->vcpu_id;
 
 	vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
@@ -108,7 +111,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	struct kvm_enable_cap cap = {};
 	struct timespec clear_dirty_log_total = (struct timespec){0};
 
-	vm = create_vm(mode, nr_vcpus, guest_percpu_mem_size);
+	vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size);
 
 	perf_test_args.wr_fract = p->wr_fract;
 
@@ -126,7 +129,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
 	TEST_ASSERT(vcpu_threads, "Memory allocation failed");
 
-	add_vcpus(vm, nr_vcpus, guest_percpu_mem_size);
+	perf_test_setup_vcpus(vm, nr_vcpus, guest_percpu_mem_size);
 
 	sync_global_to_guest(vm, perf_test_args);
 
@@ -152,7 +155,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 
 	/* Enable dirty logging */
 	clock_gettime(CLOCK_MONOTONIC, &start);
-	vm_mem_region_set_flags(vm, TEST_MEM_SLOT_INDEX,
+	vm_mem_region_set_flags(vm, PERF_TEST_MEM_SLOT_INDEX,
 				KVM_MEM_LOG_DIRTY_PAGES);
 	ts_diff = timespec_diff_now(start);
 	pr_info("Enabling dirty logging time: %ld.%.9lds\n\n",
@@ -179,7 +182,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 			iteration, ts_diff.tv_sec, ts_diff.tv_nsec);
 
 		clock_gettime(CLOCK_MONOTONIC, &start);
-		kvm_vm_get_dirty_log(vm, TEST_MEM_SLOT_INDEX, bmap);
+		kvm_vm_get_dirty_log(vm, PERF_TEST_MEM_SLOT_INDEX, bmap);
 
 		ts_diff = timespec_diff_now(start);
 		get_dirty_log_total = timespec_add(get_dirty_log_total,
@@ -189,7 +192,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 
 		if (dirty_log_manual_caps) {
 			clock_gettime(CLOCK_MONOTONIC, &start);
-			kvm_vm_clear_dirty_log(vm, TEST_MEM_SLOT_INDEX, bmap, 0,
+			kvm_vm_clear_dirty_log(vm, PERF_TEST_MEM_SLOT_INDEX, bmap, 0,
 					       host_num_pages);
 
 			ts_diff = timespec_diff_now(start);
@@ -207,7 +210,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 
 	/* Disable dirty logging */
 	clock_gettime(CLOCK_MONOTONIC, &start);
-	vm_mem_region_set_flags(vm, TEST_MEM_SLOT_INDEX, 0);
+	vm_mem_region_set_flags(vm, PERF_TEST_MEM_SLOT_INDEX, 0);
 	ts_diff = timespec_diff_now(start);
 	pr_info("Disabling dirty logging time: %ld.%.9lds\n",
 		ts_diff.tv_sec, ts_diff.tv_nsec);
@@ -226,8 +229,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 
 	free(bmap);
 	free(vcpu_threads);
-	ucall_uninit(vm);
-	kvm_vm_free(vm);
+	perf_test_destroy_vm(vm);
 }
 
 static void help(char *name)
tools/testing/selftests/kvm/include/kvm_util.h +1 -0
index 149766ecd68b..5cbb861525ed 100644
@@ -16,6 +16,7 @@
 
 #include "sparsebit.h"
 
+#define KVM_MAX_VCPUS 512
 
 /*
  * Callers of kvm_util only have an incomplete/opaque description of the
tools/testing/selftests/kvm/include/perf_test_util.h +12 -130

166 lines not on this page · raw message

tools/testing/selftests/kvm/lib/perf_test_util.c new file +134 -0

134 lines not on this page · raw message

Signature · 1 line
2.26.2
maintainer
#5 lore raw
In reply to Andrew Jones
Quoted 5 lines · Andrew Jones

This series attempts to clean up demand_paging_test, dirty_log_perf_test, and dirty_log_test by factoring out common code, creating some new API along the way. It also splits include/perf_test_util.h into a more conventional header and source pair.

Quoted 7 lines

I've tested on x86 and AArch64 (one config each), but not s390x.

v3:
- Rebased remaining four patches from v2 onto kvm/queue
- Picked up r-b's from Peter and Ben

v2: https://www.spinics.net/lists/kvm/msg228711.html

Unfortunately patch 2 is still broken:

$ ./dirty_log_test -M dirty-ring
Setting log mode to: 'dirty-ring'
Test iterations: 32, interval: 10 (ms)
Testing guest mode: PA-bits:ANY, VA-bits:48,  4K pages
==== Test Assertion Failure ====
  lib/kvm_util.c:85: ret == 0
  pid=2010122 tid=2010122 - Invalid argument
     1	0x0000000000402ee7: vm_enable_cap at kvm_util.c:84
     2	0x0000000000403004: vm_enable_dirty_ring at kvm_util.c:124
     3	0x00000000004021a5: log_mode_create_vm_done at dirty_log_test.c:453
     4	 (inlined by) run_test at dirty_log_test.c:683
     5	0x000000000040b643: for_each_guest_mode at guest_modes.c:37
     6	0x00000000004019c2: main at dirty_log_test.c:864
     7	0x00007fe3f48207b2: ?? ??:0
     8	0x0000000000401aad: _start at ??:?
  KVM_ENABLE_CAP IOCTL failed,
  rc: -1 errno: 22

(Also fails without -M).

Paolo

Quoted 26 lines

Thanks,
drew

Andrew Jones (4):
KVM: selftests: Factor out guest mode code
KVM: selftests: dirty_log_test: Remove create_vm
KVM: selftests: Use vm_create_with_vcpus in create_vm
KVM: selftests: Implement perf_test_util more conventionally

  tools/testing/selftests/kvm/Makefile          |   2 +-
  .../selftests/kvm/demand_paging_test.c        | 118 ++++--------
  .../selftests/kvm/dirty_log_perf_test.c       | 145 +++++---------
  tools/testing/selftests/kvm/dirty_log_test.c  | 179 +++++-------------
  .../selftests/kvm/include/guest_modes.h       |  21 ++
  .../testing/selftests/kvm/include/kvm_util.h  |   9 +
  .../selftests/kvm/include/perf_test_util.h    | 167 ++--------------
  tools/testing/selftests/kvm/lib/guest_modes.c |  70 +++++++
  tools/testing/selftests/kvm/lib/kvm_util.c    |   9 +-
  .../selftests/kvm/lib/perf_test_util.c        | 134 +++++++++++++
  10 files changed, 378 insertions(+), 476 deletions(-)

create mode 100644 tools/testing/selftests/kvm/include/guest_modes.h create mode 100644 tools/testing/selftests/kvm/lib/guest_modes.c create mode 100644 tools/testing/selftests/kvm/lib/perf_test_util.c

#6 lore raw
Quoted 34 lines · Paolo Bonzini
Quoted 5 lines · Andrew Jones

This series attempts to clean up demand_paging_test, dirty_log_perf_test, and dirty_log_test by factoring out common code, creating some new API along the way. It also splits include/perf_test_util.h into a more conventional header and source pair.

Quoted 7 lines

I've tested on x86 and AArch64 (one config each), but not s390x.

v3:
- Rebased remaining four patches from v2 onto kvm/queue
- Picked up r-b's from Peter and Ben

v2: https://www.spinics.net/lists/kvm/msg228711.html

Unfortunately patch 2 is still broken:

$ ./dirty_log_test -M dirty-ring
Setting log mode to: 'dirty-ring'
Test iterations: 32, interval: 10 (ms)
Testing guest mode: PA-bits:ANY, VA-bits:48,  4K pages
==== Test Assertion Failure ====
  lib/kvm_util.c:85: ret == 0
  pid=2010122 tid=2010122 - Invalid argument
     1	0x0000000000402ee7: vm_enable_cap at kvm_util.c:84
     2	0x0000000000403004: vm_enable_dirty_ring at kvm_util.c:124
     3	0x00000000004021a5: log_mode_create_vm_done at dirty_log_test.c:453
     4	 (inlined by) run_test at dirty_log_test.c:683
     5	0x000000000040b643: for_each_guest_mode at guest_modes.c:37
     6	0x00000000004019c2: main at dirty_log_test.c:864
     7	0x00007fe3f48207b2: ?? ??:0
     8	0x0000000000401aad: _start at ??:?
  KVM_ENABLE_CAP IOCTL failed,
  rc: -1 errno: 22
Quoted 1 line

(Also fails without -M).

It should be because of the ordering of creating vcpu and enabling dirty rings, since currently for simplicity when enabling dirty ring we must have not created any vcpus:

+ if (kvm->created_vcpus) {
+ /* We don't allow to change this value after vcpu created */
+ r = -EINVAL;
+ } else {
+ kvm->dirty_ring_size = size;
+ r = 0;
+ }

We may need to call log_mode_create_vm_done() before creating any vcpus somehow. Sorry to not have noticed that when reviewing it.

Signature · 1 line
Peter Xu
#7 lore raw
Quoted 49 lines · Peter Xu
Quoted 34 lines · Paolo Bonzini
Quoted 5 lines · Andrew Jones

This series attempts to clean up demand_paging_test, dirty_log_perf_test, and dirty_log_test by factoring out common code, creating some new API along the way. It also splits include/perf_test_util.h into a more conventional header and source pair.

Quoted 7 lines

I've tested on x86 and AArch64 (one config each), but not s390x.

v3:
- Rebased remaining four patches from v2 onto kvm/queue
- Picked up r-b's from Peter and Ben

v2: https://www.spinics.net/lists/kvm/msg228711.html

Unfortunately patch 2 is still broken:

$ ./dirty_log_test -M dirty-ring
Setting log mode to: 'dirty-ring'
Test iterations: 32, interval: 10 (ms)
Testing guest mode: PA-bits:ANY, VA-bits:48,  4K pages
==== Test Assertion Failure ====
  lib/kvm_util.c:85: ret == 0
  pid=2010122 tid=2010122 - Invalid argument
     1	0x0000000000402ee7: vm_enable_cap at kvm_util.c:84
     2	0x0000000000403004: vm_enable_dirty_ring at kvm_util.c:124
     3	0x00000000004021a5: log_mode_create_vm_done at dirty_log_test.c:453
     4	 (inlined by) run_test at dirty_log_test.c:683
     5	0x000000000040b643: for_each_guest_mode at guest_modes.c:37
     6	0x00000000004019c2: main at dirty_log_test.c:864
     7	0x00007fe3f48207b2: ?? ??:0
     8	0x0000000000401aad: _start at ??:?
  KVM_ENABLE_CAP IOCTL failed,
  rc: -1 errno: 22
Quoted 1 line

(Also fails without -M).

It should be because of the ordering of creating vcpu and enabling dirty rings, since currently for simplicity when enabling dirty ring we must have not created any vcpus:

(quoted diff) +7 -0
+       if (kvm->created_vcpus) {
+               /* We don't allow to change this value after vcpu created */
+               r = -EINVAL;
+       } else {
+               kvm->dirty_ring_size = size;
+               r = 0;
+       }
Quoted 3 lines

We may need to call log_mode_create_vm_done() before creating any vcpus somehow. Sorry to not have noticed that when reviewing it.

And sorry for having not tested with '-M dirty-ring'. I thought we were trying to ensure each unique test type had its own test file (even if we have to do the weird inclusion of C files). Doing that, the command line options are then only used to change stuff like verbosity or to experiment with tweaked configurations.

If we're not doing that, then I think we should. We don't want to try and explain to all the CI people how each test should be run. It's much easier to say "run all the binaries, no parameters necessary". Each binary with no parameters should run the test(s) using a good default or by executing all possible configurations.

Thanks,
drew

#8 lore raw
Quoted 60 lines · Andrew Jones
Quoted 49 lines · Peter Xu
Quoted 34 lines · Paolo Bonzini
Quoted 5 lines · Andrew Jones

This series attempts to clean up demand_paging_test, dirty_log_perf_test, and dirty_log_test by factoring out common code, creating some new API along the way. It also splits include/perf_test_util.h into a more conventional header and source pair.

Quoted 7 lines

I've tested on x86 and AArch64 (one config each), but not s390x.

v3:
- Rebased remaining four patches from v2 onto kvm/queue
- Picked up r-b's from Peter and Ben

v2: https://www.spinics.net/lists/kvm/msg228711.html

Unfortunately patch 2 is still broken:

$ ./dirty_log_test -M dirty-ring
Setting log mode to: 'dirty-ring'
Test iterations: 32, interval: 10 (ms)
Testing guest mode: PA-bits:ANY, VA-bits:48,  4K pages
==== Test Assertion Failure ====
  lib/kvm_util.c:85: ret == 0
  pid=2010122 tid=2010122 - Invalid argument
     1	0x0000000000402ee7: vm_enable_cap at kvm_util.c:84
     2	0x0000000000403004: vm_enable_dirty_ring at kvm_util.c:124
     3	0x00000000004021a5: log_mode_create_vm_done at dirty_log_test.c:453
     4	 (inlined by) run_test at dirty_log_test.c:683
     5	0x000000000040b643: for_each_guest_mode at guest_modes.c:37
     6	0x00000000004019c2: main at dirty_log_test.c:864
     7	0x00007fe3f48207b2: ?? ??:0
     8	0x0000000000401aad: _start at ??:?
  KVM_ENABLE_CAP IOCTL failed,
  rc: -1 errno: 22
Quoted 1 line

(Also fails without -M).

It should be because of the ordering of creating vcpu and enabling dirty rings, since currently for simplicity when enabling dirty ring we must have not created any vcpus:

(quoted diff) +7 -0
+       if (kvm->created_vcpus) {
+               /* We don't allow to change this value after vcpu created */
+               r = -EINVAL;
+       } else {
+               kvm->dirty_ring_size = size;
+               r = 0;
+       }
Quoted 3 lines

We may need to call log_mode_create_vm_done() before creating any vcpus somehow. Sorry to not have noticed that when reviewing it.

And sorry for having not tested with '-M dirty-ring'. I thought we were trying to ensure each unique test type had its own test file (even if we have to do the weird inclusion of C files). Doing that, the command line options are then only used to change stuff like verbosity or to experiment with tweaked configurations.

Quoted 6 lines

If we're not doing that, then I think we should. We don't want to try and explain to all the CI people how each test should be run. It's much easier to say "run all the binaries, no parameters necessary". Each binary with no parameters should run the test(s) using a good default or by executing all possible configurations.

I just double checked and we are running all modes by default. This is the output I get

Test iterations: 32, interval: 10 (ms)
Testing Log Mode 'dirty-log'
Testing guest mode: PA-bits:ANY, VA-bits:48, 4K pages
guest physical test memory offset: 0x7fbfffc000
Dirtied 1024 pages
Total bits checked: dirty (209373), clear (7917184), track_next (38548) Testing Log Mode 'clear-log'
Testing guest mode: PA-bits:ANY, VA-bits:48, 4K pages
guest physical test memory offset: 0x7fbfffc000
Dirtied 1024 pages
Total bits checked: dirty (464547), clear (7662010), track_next (37553) Testing Log Mode 'dirty-ring'
Log mode 'dirty-ring' not supported, skipping test

which matches the output before this patch, except for minor differences in the numbers.

I'm not sure how this is failing in your environment and not mine.

Peter?

Thanks,
drew

#9 lore raw
Quoted 85 lines · Andrew Jones
Quoted 60 lines · Andrew Jones
Quoted 49 lines · Peter Xu
Quoted 34 lines · Paolo Bonzini
Quoted 5 lines · Andrew Jones

This series attempts to clean up demand_paging_test, dirty_log_perf_test, and dirty_log_test by factoring out common code, creating some new API along the way. It also splits include/perf_test_util.h into a more conventional header and source pair.

Quoted 7 lines

I've tested on x86 and AArch64 (one config each), but not s390x.

v3:
- Rebased remaining four patches from v2 onto kvm/queue
- Picked up r-b's from Peter and Ben

v2: https://www.spinics.net/lists/kvm/msg228711.html

Unfortunately patch 2 is still broken:

$ ./dirty_log_test -M dirty-ring
Setting log mode to: 'dirty-ring'
Test iterations: 32, interval: 10 (ms)
Testing guest mode: PA-bits:ANY, VA-bits:48,  4K pages
==== Test Assertion Failure ====
  lib/kvm_util.c:85: ret == 0
  pid=2010122 tid=2010122 - Invalid argument
     1	0x0000000000402ee7: vm_enable_cap at kvm_util.c:84
     2	0x0000000000403004: vm_enable_dirty_ring at kvm_util.c:124
     3	0x00000000004021a5: log_mode_create_vm_done at dirty_log_test.c:453
     4	 (inlined by) run_test at dirty_log_test.c:683
     5	0x000000000040b643: for_each_guest_mode at guest_modes.c:37
     6	0x00000000004019c2: main at dirty_log_test.c:864
     7	0x00007fe3f48207b2: ?? ??:0
     8	0x0000000000401aad: _start at ??:?
  KVM_ENABLE_CAP IOCTL failed,
  rc: -1 errno: 22
Quoted 1 line

(Also fails without -M).

It should be because of the ordering of creating vcpu and enabling dirty rings, since currently for simplicity when enabling dirty ring we must have not created any vcpus:

(quoted diff) +7 -0
+       if (kvm->created_vcpus) {
+               /* We don't allow to change this value after vcpu created */
+               r = -EINVAL;
+       } else {
+               kvm->dirty_ring_size = size;
+               r = 0;
+       }
Quoted 3 lines

We may need to call log_mode_create_vm_done() before creating any vcpus somehow. Sorry to not have noticed that when reviewing it.

And sorry for having not tested with '-M dirty-ring'. I thought we were trying to ensure each unique test type had its own test file (even if we have to do the weird inclusion of C files). Doing that, the command line options are then only used to change stuff like verbosity or to experiment with tweaked configurations.

Quoted 6 lines

If we're not doing that, then I think we should. We don't want to try and explain to all the CI people how each test should be run. It's much easier to say "run all the binaries, no parameters necessary". Each binary with no parameters should run the test(s) using a good default or by executing all possible configurations.

I just double checked and we are running all modes by default. This is the output I get

Test iterations: 32, interval: 10 (ms)
Testing Log Mode 'dirty-log'
Testing guest mode: PA-bits:ANY, VA-bits:48, 4K pages
guest physical test memory offset: 0x7fbfffc000
Dirtied 1024 pages
Total bits checked: dirty (209373), clear (7917184), track_next (38548) Testing Log Mode 'clear-log'
Testing guest mode: PA-bits:ANY, VA-bits:48, 4K pages
guest physical test memory offset: 0x7fbfffc000
Dirtied 1024 pages
Total bits checked: dirty (464547), clear (7662010), track_next (37553) Testing Log Mode 'dirty-ring'
Log mode 'dirty-ring' not supported, skipping test

Quoted 5 lines

which matches the output before this patch, except for minor differences in the numbers.

I'm not sure how this is failing in your environment and not mine.

Doh, sorry. I didn't actually read the output. I was only looking for an assert and the string 'dirty-ring'. It looks like the test is skipping for me. That would explain why it "works" for me...

drew

#10 lore raw
In reply to Paolo Bonzini
Quoted 25 lines · Paolo Bonzini
Quoted 5 lines · Andrew Jones

This series attempts to clean up demand_paging_test, dirty_log_perf_test, and dirty_log_test by factoring out common code, creating some new API along the way. It also splits include/perf_test_util.h into a more conventional header and source pair.

Quoted 7 lines

I've tested on x86 and AArch64 (one config each), but not s390x.

v3:
- Rebased remaining four patches from v2 onto kvm/queue
- Picked up r-b's from Peter and Ben

v2: https://www.spinics.net/lists/kvm/msg228711.html

Unfortunately patch 2 is still broken:

$ ./dirty_log_test -M dirty-ring
Setting log mode to: 'dirty-ring'
Test iterations: 32, interval: 10 (ms)
Testing guest mode: PA-bits:ANY, VA-bits:48,  4K pages
==== Test Assertion Failure ====
  lib/kvm_util.c:85: ret == 0
  pid=2010122 tid=2010122 - Invalid argument
     1	0x0000000000402ee7: vm_enable_cap at kvm_util.c:84
     2	0x0000000000403004: vm_enable_dirty_ring at kvm_util.c:124
Quoted 9 lines
     3	0x00000000004021a5: log_mode_create_vm_done at dirty_log_test.c:453
     4	 (inlined by) run_test at dirty_log_test.c:683
     5	0x000000000040b643: for_each_guest_mode at guest_modes.c:37
     6	0x00000000004019c2: main at dirty_log_test.c:864
     7	0x00007fe3f48207b2: ?? ??:0
     8	0x0000000000401aad: _start at ??:?
  KVM_ENABLE_CAP IOCTL failed,
  rc: -1 errno: 22

So I finally looked closely enough at the dirty-ring stuff to see that patch 2 was always a dumb idea. dirty_ring_create_vm_done() has a comment that says "Switch to dirty ring mode after VM creation but before any of the vcpu creation". I'd argue that that comment would be better served at the log_mode_create_vm_done() call, but that doesn't excuse my sloppiness here. Maybe someday we can add a patch that adds that comment and also tries to use common code for the number of pages calculation for the VM, but not today.

Regarding this series, if the other three patches look good, then we can just drop 2/4. 3/4 and 4/4 should still apply cleanly and work.

Thanks,
drew

maintainer
#11 lore raw
Quoted 11 lines · Andrew Jones

So I finally looked closely enough at the dirty-ring stuff to see that patch 2 was always a dumb idea. dirty_ring_create_vm_done() has a comment that says "Switch to dirty ring mode after VM creation but before any of the vcpu creation". I'd argue that that comment would be better served at the log_mode_create_vm_done() call, but that doesn't excuse my sloppiness here. Maybe someday we can add a patch that adds that comment and also tries to use common code for the number of pages calculation for the VM, but not today.

Regarding this series, if the other three patches look good, then we can just drop 2/4. 3/4 and 4/4 should still apply cleanly and work.

Yes, the rest is good.

Paolo

#12 lore raw
Quoted 10 lines · Paolo Bonzini
Quoted 9 lines · Andrew Jones

So I finally looked closely enough at the dirty-ring stuff to see that patch 2 was always a dumb idea. dirty_ring_create_vm_done() has a comment that says "Switch to dirty ring mode after VM creation but before any of the vcpu creation". I'd argue that that comment would be better served at the log_mode_create_vm_done() call, but that doesn't excuse my sloppiness here. Maybe someday we can add a patch that adds that comment and also tries to use common code for the number of pages calculation for the VM, but not today.

Quoted 5 lines
Quoted 2 lines

Regarding this series, if the other three patches look good, then we can just drop 2/4. 3/4 and 4/4 should still apply cleanly and work.

Yes, the rest is good.

Ping?

Thanks,
drew

#13 lore raw
Quoted 15 lines · Andrew Jones
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · Andrew Jones

So I finally looked closely enough at the dirty-ring stuff to see that patch 2 was always a dumb idea. dirty_ring_create_vm_done() has a comment that says "Switch to dirty ring mode after VM creation but before any of the vcpu creation". I'd argue that that comment would be better served at the log_mode_create_vm_done() call, but that doesn't excuse my sloppiness here. Maybe someday we can add a patch that adds that comment and also tries to use common code for the number of pages calculation for the VM, but not today.

Regarding this series, if the other three patches look good, then we can just drop 2/4. 3/4 and 4/4 should still apply cleanly and work.

Quoted 7 lines
Quoted 2 lines

Yes, the rest is good.

Ping?

Thanks,
drew

FWIW, patches 1, 3, and 4 look good to me too. Once these are merged, I've got another new test ready to go which builds on these.

maintainer
#14 lore raw
In reply to Andrew Jones
Quoted 11 lines · Andrew Jones
Quoted 10 lines · Paolo Bonzini
Quoted 9 lines · Andrew Jones

So I finally looked closely enough at the dirty-ring stuff to see that patch 2 was always a dumb idea. dirty_ring_create_vm_done() has a comment that says "Switch to dirty ring mode after VM creation but before any of the vcpu creation". I'd argue that that comment would be better served at the log_mode_create_vm_done() call, but that doesn't excuse my sloppiness here. Maybe someday we can add a patch that adds that comment and also tries to use common code for the number of pages calculation for the VM, but not today.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Regarding this series, if the other three patches look good, then we can just drop 2/4. 3/4 and 4/4 should still apply cleanly and work.

Yes, the rest is good.

Ping?

Sorry, I was waiting for a resend.

Paolo

#15 lore raw
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Andrew Jones
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · Andrew Jones

So I finally looked closely enough at the dirty-ring stuff to see that patch 2 was always a dumb idea. dirty_ring_create_vm_done() has a comment that says "Switch to dirty ring mode after VM creation but before any of the vcpu creation". I'd argue that that comment would be better served at the log_mode_create_vm_done() call, but that doesn't excuse my sloppiness here. Maybe someday we can add a patch that adds that comment and also tries to use common code for the number of pages calculation for the VM, but not today.

Regarding this series, if the other three patches look good, then we can just drop 2/4. 3/4 and 4/4 should still apply cleanly and work.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Yes, the rest is good.

Ping?

Sorry, I was waiting for a resend.

Oops, I understood that we'd just drop 2/4 while applying. Should I resend now?

Thanks,
drew

maintainer
#16 lore raw
Quoted 19 lines · Andrew Jones
Quoted 18 lines · Paolo Bonzini
Quoted 17 lines · Andrew Jones
Quoted 15 lines · Paolo Bonzini
Quoted 11 lines · Andrew Jones

So I finally looked closely enough at the dirty-ring stuff to see that patch 2 was always a dumb idea. dirty_ring_create_vm_done() has a comment that says "Switch to dirty ring mode after VM creation but before any of the vcpu creation". I'd argue that that comment would be better served at the log_mode_create_vm_done() call, but that doesn't excuse my sloppiness here. Maybe someday we can add a patch that adds that comment and also tries to use common code for the number of pages calculation for the VM, but not today.

Regarding this series, if the other three patches look good, then we can just drop 2/4. 3/4 and 4/4 should still apply cleanly and work.

Yes, the rest is good.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Ping?

Sorry, I was waiting for a resend.

Oops, I understood that we'd just drop 2/4 while applying. Should I resend now?

Yes, please. Maybe there were conflicts, I don't remember why I dropped the whole series on the floor.

Paolo