Skip to contentSkip to conversation

KVM: selftests: Add get-reg-list regression test

PATCH Superseded Andrew Jones 3 participants 9 messages Oct 29, 2020 – Nov 9, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover KVM: selftests: Add get-reg-list regression test

Since Eric complained in his KVM Forum talk that there weren't any aarch64-specific KVM selftests, now he gets to review one. This test was inspired by recent regression report about get-reg-list losing a register between an old kernel version and a new one.

Thanks,
drew

Andrew Jones (4):
KVM: selftests: Don't require THP to run tests
KVM: selftests: Add aarch64 get-reg-list test
KVM: selftests: Update aarch64 get-reg-list blessed list
KVM: selftests: Add blessed SVE registers to get-reg-list

 tools/testing/selftests/kvm/.gitignore        |   2 +
 tools/testing/selftests/kvm/Makefile          |   2 +
 .../selftests/kvm/aarch64/get-reg-list-sve.c  |   3 +
 .../selftests/kvm/aarch64/get-reg-list.c      | 841 ++++++++++++++++++
 .../testing/selftests/kvm/include/kvm_util.h  |   1 +
 tools/testing/selftests/kvm/lib/kvm_util.c    |  52 +-
 6 files changed, 894 insertions(+), 7 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/aarch64/get-reg-list-sve.c
 create mode 100644 tools/testing/selftests/kvm/aarch64/get-reg-list.c
Signature · 6 lines
2.27.0

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
#1 lore raw

PATCH 1/4 KVM: selftests: Don't require THP to run tests

Unless we want to test with THP, then we shouldn't require it to be configured by the host kernel. Unfortunately, even advising with MADV_NOHUGEPAGE does require it, so check for THP first in order to avoid madvise failing with EINVAL.

---
 tools/testing/selftests/kvm/lib/kvm_util.c | 23 +++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
tools/testing/selftests/kvm/lib/kvm_util.c +16 -7
index 74776ee228f2..3327cebc1095 100644
@@ -14,6 +14,7 @@
 #include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <unistd.h>
 #include <linux/kernel.h>
 
 #define KVM_UTIL_PGS_PER_HUGEPG 512
@@ -664,13 +665,21 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
 
 	/* As needed perform madvise */
 	if (src_type == VM_MEM_SRC_ANONYMOUS || src_type == VM_MEM_SRC_ANONYMOUS_THP) {
-		ret = madvise(region->host_mem, npages * vm->page_size,
-			     src_type == VM_MEM_SRC_ANONYMOUS ? MADV_NOHUGEPAGE : MADV_HUGEPAGE);
-		TEST_ASSERT(ret == 0, "madvise failed,\n"
-			    "  addr: %p\n"
-			    "  length: 0x%lx\n"
-			    "  src_type: %x",
-			    region->host_mem, npages * vm->page_size, src_type);
+		struct stat statbuf;
+
+		ret = stat("/sys/kernel/mm/transparent_hugepage", &statbuf);
+		TEST_ASSERT(ret == 0 || (ret == -1 && errno == ENOENT),
+			    "stat /sys/kernel/mm/transparent_hugepage");
+
+		TEST_ASSERT(ret == 0 || src_type != VM_MEM_SRC_ANONYMOUS_THP,
+			    "VM_MEM_SRC_ANONYMOUS_THP requires THP to be configured in the host kernel");
+
+		if (ret == 0) {
+			ret = madvise(region->host_mem, npages * vm->page_size,
+				      src_type == VM_MEM_SRC_ANONYMOUS ? MADV_NOHUGEPAGE : MADV_HUGEPAGE);
+			TEST_ASSERT(ret == 0, "madvise failed, addr: %p length: 0x%lx src_type: %x",
+				    region->host_mem, npages * vm->page_size, src_type);
+		}
 	}
 
 	region->unused_phy_pages = sparsebit_alloc();
Signature · 6 lines
2.27.0

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
#2 lore raw

PATCH 2/4 KVM: selftests: Add aarch64 get-reg-list test

In reply to Andrew Jones

Check for KVM_GET_REG_LIST regressions. The blessed list was created by running on v4.15 with the --core-reg-fixup option. The following script was also used in order to annotate system registers with their names when possible. When new system registers are added the names can just be added manually using the same grep.

while read reg; do

	if [[ ! $reg =~ ARM64_SYS_REG ]]; then
		printf "\t$reg\n"
		continue
	fi
	encoding=$(echo "$reg" | sed "s/ARM64_SYS_REG(//;s/),//")
	if ! name=$(grep "$encoding" ../../../../arch/arm64/include/asm/sysreg.h); then
		printf "\t$reg\n"
		continue
	fi
	name=$(echo "$name" | sed "s/.*SYS_//;s/[\t ]*sys_reg($encoding)$//")
	printf "\t$reg\t/* $name */\n"

done < <(aarch64/get-reg-list --core-reg-fixup --list)

---
 tools/testing/selftests/kvm/.gitignore        |   1 +
 tools/testing/selftests/kvm/Makefile          |   1 +
 .../selftests/kvm/aarch64/get-reg-list.c      | 665 ++++++++++++++++++
 .../testing/selftests/kvm/include/kvm_util.h  |   1 +
 tools/testing/selftests/kvm/lib/kvm_util.c    |  29 +
 5 files changed, 697 insertions(+)
 create mode 100644 tools/testing/selftests/kvm/aarch64/get-reg-list.c
tools/testing/selftests/kvm/.gitignore +1 -0
index 307ceaadbbb9..d1c82ab8d131 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
+/aarch64/get-reg-list
 /s390x/memop
 /s390x/resets
 /s390x/sync_regs_test
tools/testing/selftests/kvm/Makefile +1 -0
index 7ebe71fbca53..64a76f4ef8ba 100644
@@ -64,6 +64,7 @@ TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus
 TEST_GEN_PROGS_x86_64 += set_memory_region_test
 TEST_GEN_PROGS_x86_64 += steal_time
 
+TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list
 TEST_GEN_PROGS_aarch64 += clear_dirty_log_test
 TEST_GEN_PROGS_aarch64 += demand_paging_test
 TEST_GEN_PROGS_aarch64 += dirty_log_test
tools/testing/selftests/kvm/aarch64/get-reg-list.c new file +665 -0

665 lines not on this page · raw message

tools/testing/selftests/kvm/include/kvm_util.h +1 -0
index 919e161dd289..eef061de7087 100644
@@ -149,6 +149,7 @@ void vcpu_set_guest_debug(struct kvm_vm *vm, uint32_t vcpuid,
 			  struct kvm_guest_debug *debug);
 void vcpu_set_mp_state(struct kvm_vm *vm, uint32_t vcpuid,
 		       struct kvm_mp_state *mp_state);
+struct kvm_reg_list *vcpu_get_reg_list(struct kvm_vm *vm, uint32_t vcpuid);
 void vcpu_regs_get(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_regs *regs);
 void vcpu_regs_set(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_regs *regs);
 
tools/testing/selftests/kvm/lib/kvm_util.c +29 -0
index 3327cebc1095..2e990727b893 100644
@@ -1260,6 +1260,35 @@ void vcpu_set_mp_state(struct kvm_vm *vm, uint32_t vcpuid,
 		"rc: %i errno: %i", ret, errno);
 }
 
+/*
+ * VM VCPU Get Reg List
+ *
+ * Input Args:
+ *   vm - Virtual Machine
+ *   vcpuid - VCPU ID
+ *
+ * Output Args:
+ *   None
+ *
+ * Return:
+ *   A pointer to an allocated struct kvm_reg_list
+ *
+ * Get the list of guest registers which are supported for
+ * KVM_GET_ONE_REG/KVM_SET_ONE_REG calls
+ */
+struct kvm_reg_list *vcpu_get_reg_list(struct kvm_vm *vm, uint32_t vcpuid)
+{
+	struct kvm_reg_list reg_list_n = { .n = 0 }, *reg_list;
+	int ret;
+
+	ret = _vcpu_ioctl(vm, vcpuid, KVM_GET_REG_LIST, &reg_list_n);
+	TEST_ASSERT(ret == -1 && errno == E2BIG, "KVM_GET_REG_LIST n=0");
+	reg_list = calloc(1, sizeof(*reg_list) + reg_list_n.n * sizeof(__u64));
+	reg_list->n = reg_list_n.n;
+	vcpu_ioctl(vm, vcpuid, KVM_GET_REG_LIST, reg_list);
+	return reg_list;
+}
+
 /*
  * VM VCPU Regs Get
  *
Signature · 1 line
2.27.0
#3 lore raw

PATCH 3/4 KVM: selftests: Update aarch64 get-reg-list blessed list

In reply to Andrew Jones

The new registers come from the following commits:

commit 99adb567632b ("KVM: arm/arm64: Add save/restore support for firmware workaround state")

commit c773ae2b3476 ("KVM: arm64: Save/Restore guest DISR_EL1")

commit 03fdfb269009 ("KVM: arm64: Don't write junk to sysregs on reset")

The last commit, which adds ARM64_SYS_REG(3, 3, 9, 12, 0) (PMCR_EL0), and was committed for v5.3, doesn't indicate in its commit message that enumerating it for save/restore was the plan, so doing so may have been by accident. It's a good idea anyway, though, since the other PMU registers have been enumerated since v4.10.

---
 tools/testing/selftests/kvm/aarch64/get-reg-list.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/aarch64/get-reg-list.c +7 -1
index 3aeb3de780a1..3ff097f6886e 100644
@@ -352,7 +352,8 @@ int main(int ac, char **av)
 }
 
 /*
- * The current blessed list comes from kernel version v4.15 with --core-reg-fixup
+ * The current blessed list was primed with the output of kernel version
+ * v4.15 with --core-reg-fixup and then later updated with new registers.
  */
 static __u64 blessed_reg[] = {
 	KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[0]),
@@ -430,6 +431,9 @@ static __u64 blessed_reg[] = {
 	KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[31]),
 	KVM_REG_ARM64 | KVM_REG_SIZE_U32 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.fpsr),
 	KVM_REG_ARM64 | KVM_REG_SIZE_U32 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.fpcr),
+	KVM_REG_ARM_FW_REG(0),
+	KVM_REG_ARM_FW_REG(1),
+	KVM_REG_ARM_FW_REG(2),
 	ARM64_SYS_REG(3, 3, 14, 3, 1),	/* CNTV_CTL_EL0 */
 	ARM64_SYS_REG(3, 3, 14, 3, 2),	/* CNTV_CVAL_EL0 */
 	ARM64_SYS_REG(3, 3, 14, 0, 2),
@@ -578,10 +582,12 @@ static __u64 blessed_reg[] = {
 	ARM64_SYS_REG(3, 0, 10, 2, 0),	/* MAIR_EL1 */
 	ARM64_SYS_REG(3, 0, 10, 3, 0),	/* AMAIR_EL1 */
 	ARM64_SYS_REG(3, 0, 12, 0, 0),	/* VBAR_EL1 */
+	ARM64_SYS_REG(3, 0, 12, 1, 1),	/* DISR_EL1 */
 	ARM64_SYS_REG(3, 0, 13, 0, 1),	/* CONTEXTIDR_EL1 */
 	ARM64_SYS_REG(3, 0, 13, 0, 4),	/* TPIDR_EL1 */
 	ARM64_SYS_REG(3, 0, 14, 1, 0),	/* CNTKCTL_EL1 */
 	ARM64_SYS_REG(3, 2, 0, 0, 0),	/* CSSELR_EL1 */
+	ARM64_SYS_REG(3, 3, 9, 12, 0),	/* PMCR_EL0 */
 	ARM64_SYS_REG(3, 3, 9, 12, 1),	/* PMCNTENSET_EL0 */
 	ARM64_SYS_REG(3, 3, 9, 12, 2),	/* PMCNTENCLR_EL0 */
 	ARM64_SYS_REG(3, 3, 9, 12, 3),	/* PMOVSCLR_EL0 */
Signature · 1 line
2.27.0
maintainer
#4 lore raw

Re: [PATCH 3/4] KVM: selftests: Update aarch64 get-reg-list blessed list

Quoted 6 lines · Andrew Jones

The new registers come from the following commits:

commit 99adb567632b ("KVM: arm/arm64: Add save/restore support for firmware workaround state")

Quoted 8 lines

commit c773ae2b3476 ("KVM: arm64: Save/Restore guest DISR_EL1")

commit 03fdfb269009 ("KVM: arm64: Don't write junk to sysregs on reset")

The last commit, which adds ARM64_SYS_REG(3, 3, 9, 12, 0) (PMCR_EL0), and was committed for v5.3, doesn't indicate in its commit message that enumerating it for save/restore was the plan, so doing so may have been by accident.

It definitely was.

Quoted 2 lines

It's a good idea anyway, though, since the other PMU registers have been enumerated since v4.10.

Quite. The state of the PMU is pretty much unknown on restore until then.

Quoted 11 lines
---
 tools/testing/selftests/kvm/aarch64/get-reg-list.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/aarch64/get-reg-list.c +0 -0
index 3aeb3de780a1..3ff097f6886e 100644

tools/testing/selftests/kvm/aarch64/get-reg-list.c int main(int ac, char **av) · line 356

Quoted 6 lines
tools/testing/selftests/kvm/aarch64/get-reg-list.c +2 -1
@@ -352,7 +352,8 @@ int main(int ac, char **av)
 }
 
 /*
- * The current blessed list comes from kernel version v4.15 with --core-reg-fixup
+ * The current blessed list was primed with the output of kernel version
+ * v4.15 with --core-reg-fixup and then later updated with new registers.

Maybe have a reference to the last kernel version this was checked against? Either here or in the commit message?

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#5 lore raw

Re: [PATCH 3/4] KVM: selftests: Update aarch64 get-reg-list blessed list

Quoted 37 lines · Marc Zyngier
Quoted 6 lines · Andrew Jones

The new registers come from the following commits:

commit 99adb567632b ("KVM: arm/arm64: Add save/restore support for firmware workaround state")

Quoted 8 lines

commit c773ae2b3476 ("KVM: arm64: Save/Restore guest DISR_EL1")

commit 03fdfb269009 ("KVM: arm64: Don't write junk to sysregs on reset")

The last commit, which adds ARM64_SYS_REG(3, 3, 9, 12, 0) (PMCR_EL0), and was committed for v5.3, doesn't indicate in its commit message that enumerating it for save/restore was the plan, so doing so may have been by accident.

It definitely was.

Quoted 2 lines

It's a good idea anyway, though, since the other PMU registers have been enumerated since v4.10.

Quite. The state of the PMU is pretty much unknown on restore until then.

Quoted 13 lines
---
 tools/testing/selftests/kvm/aarch64/get-reg-list.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/aarch64/get-reg-list.c +0 -0
index 3aeb3de780a1..3ff097f6886e 100644
@@ -352,7 +352,8 @@ int main(int ac, char **av)
 }
 
Quoted 7 lines

tools/testing/selftests/kvm/aarch64/get-reg-list.c int main(int ac, char **av) · line 356

Quoted 4 lines
tools/testing/selftests/kvm/aarch64/get-reg-list.c +2 -1
 /*
- * The current blessed list comes from kernel version v4.15 with --core-reg-fixup
+ * The current blessed list was primed with the output of kernel version
+ * v4.15 with --core-reg-fixup and then later updated with new registers.

Maybe have a reference to the last kernel version this was checked against? Either here or in the commit message?

Good idea. I'll put it in the comment in list form, encouraging the list to be continued as we add more.

Thanks,
drew

Quoted 8 lines

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#6 lore raw

PATCH 4/4 KVM: selftests: Add blessed SVE registers to get-reg-list

In reply to Andrew Jones

Add support for the SVE registers to get-reg-list and create a new test, get-reg-list-sve, which tests them when running on a machine with SVE support.

---
 tools/testing/selftests/kvm/.gitignore        |   1 +
 tools/testing/selftests/kvm/Makefile          |   1 +
 .../selftests/kvm/aarch64/get-reg-list-sve.c  |   3 +
 .../selftests/kvm/aarch64/get-reg-list.c      | 254 +++++++++++++++---
 4 files changed, 217 insertions(+), 42 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/aarch64/get-reg-list-sve.c
tools/testing/selftests/kvm/.gitignore +1 -0
index d1c82ab8d131..3af38b20d0ee 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 /aarch64/get-reg-list
+/aarch64/get-reg-list-sve
 /s390x/memop
 /s390x/resets
 /s390x/sync_regs_test
tools/testing/selftests/kvm/Makefile +1 -0
index 64a76f4ef8ba..5f222fd07dea 100644
@@ -65,6 +65,7 @@ TEST_GEN_PROGS_x86_64 += set_memory_region_test
 TEST_GEN_PROGS_x86_64 += steal_time
 
 TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list
+TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list-sve
 TEST_GEN_PROGS_aarch64 += clear_dirty_log_test
 TEST_GEN_PROGS_aarch64 += demand_paging_test
 TEST_GEN_PROGS_aarch64 += dirty_log_test
tools/testing/selftests/kvm/aarch64/get-reg-list-sve.c new file +3 -0
new file mode 100644
index 000000000000..efba76682b4b
@@ -0,0 +1,3 @@
+// SPDX-License-Identifier: GPL-2.0
+#define REG_LIST_SVE
+#include "get-reg-list.c"
tools/testing/selftests/kvm/aarch64/get-reg-list.c +212 -42

328 lines not on this page · raw message

Signature · 6 lines
2.27.0

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
#7 lore raw
In reply to Andrew Jones
Quoted 2 lines · Andrew Jones

Since Eric complained in his KVM Forum talk that there weren't any aarch64-specific KVM selftests, now he gets to review one.

okay ... :-)

Eric
This test

Quoted 23 lines

was inspired by recent regression report about get-reg-list losing a register between an old kernel version and a new one.

Thanks,
drew

Andrew Jones (4):
KVM: selftests: Don't require THP to run tests
KVM: selftests: Add aarch64 get-reg-list test
KVM: selftests: Update aarch64 get-reg-list blessed list
KVM: selftests: Add blessed SVE registers to get-reg-list

 tools/testing/selftests/kvm/.gitignore        |   2 +
 tools/testing/selftests/kvm/Makefile          |   2 +
 .../selftests/kvm/aarch64/get-reg-list-sve.c  |   3 +
 .../selftests/kvm/aarch64/get-reg-list.c      | 841 ++++++++++++++++++
 .../testing/selftests/kvm/include/kvm_util.h  |   1 +
 tools/testing/selftests/kvm/lib/kvm_util.c    |  52 +-
 6 files changed, 894 insertions(+), 7 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/aarch64/get-reg-list-sve.c
 create mode 100644 tools/testing/selftests/kvm/aarch64/get-reg-list.c
#8 lore raw
In reply to Andrew Jones
Quoted 9 lines · Andrew Jones

Since Eric complained in his KVM Forum talk that there weren't any aarch64-specific KVM selftests, now he gets to review one. This test was inspired by recent regression report about get-reg-list losing a register between an old kernel version and a new one.

Thanks,
drew

Quoted 6 lines

Andrew Jones (4):
KVM: selftests: Don't require THP to run tests
KVM: selftests: Add aarch64 get-reg-list test
KVM: selftests: Update aarch64 get-reg-list blessed list
KVM: selftests: Add blessed SVE registers to get-reg-list

Paolo,

I see you silently applied this series to kvm/master, but there's a v2 of the series on the list which incorporates Marc's comments. And, the application of the series is bad, because you've squashed "Update aarch64 get-reg-list blessed list" into "Add aarch64 get-reg-list test". Those were created as separate patches on purpose in order for the commit message of "Add aarch64 get-reg-list test" to reflect the kernel version from which the blessed reg list was primed and the commit message of "Update aarch64 get-reg-list blessed list" to explicitly point out the new commits that introduce the new registers since the priming kernel version up to the current kernel version. The division was also done to ensure the same pattern is used for future updates of the list.

Thanks,
drew