KVM: selftests: Guest printf extra prep patches
Sean Christopherson
reviewercover KVM: selftests: Guest printf extra prep patches
Delta patches for v4 of the guest printf series to enable guest_printf_test for all architectures. Sending all 36 patches seemed counter-productive, and I want to get input on adding ucall.h asap.
v4.1:
- Add ucall.h and have each arch UCALL_EXIT_REASON so that generic code can query whether or not a ucall exit actually occurred. [Drew]
- Use UCALL_EXIT_REASON in guest_printf_test.c and enable the test for all architectures. [Drew]
v4: https://lore.kernel.org/all/20230729003643.1053367-1-seanjc at google.com
Aaron Lewis (1):
KVM: selftests: Add a selftest for guest prints and formatted asserts
Sean Christopherson (2):
KVM: selftests: Add arch ucall.h and inline simple arch hooks
KVM: selftests: Add #define of expected KVM exit reason for ucall
tools/testing/selftests/kvm/Makefile | 4 + .../testing/selftests/kvm/guest_print_test.c | 221 ++++++++++++++++++ .../selftests/kvm/include/aarch64/ucall.h | 20 ++ .../selftests/kvm/include/riscv/ucall.h | 20 ++ .../selftests/kvm/include/s390x/ucall.h | 19 ++ .../selftests/kvm/include/ucall_common.h | 1 + .../selftests/kvm/include/x86_64/ucall.h | 13 ++ .../testing/selftests/kvm/lib/aarch64/ucall.c | 11 +- tools/testing/selftests/kvm/lib/riscv/ucall.c | 11 - tools/testing/selftests/kvm/lib/s390x/ucall.c | 10 - .../testing/selftests/kvm/lib/x86_64/ucall.c | 4 - 11 files changed, 299 insertions(+), 35 deletions(-) create mode 100644 tools/testing/selftests/kvm/guest_print_test.c create mode 100644 tools/testing/selftests/kvm/include/aarch64/ucall.h create mode 100644 tools/testing/selftests/kvm/include/riscv/ucall.h create mode 100644 tools/testing/selftests/kvm/include/s390x/ucall.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/ucall.h
base-commit: 12dcd9e1fe9264d306837622952b8f79d1181fab
Signature · 1 line
2.41.0.585.gd2178a4bd4-goog
Sean Christopherson
reviewerPATCH 1/3 KVM: selftests: Add arch ucall.h and inline simple arch hooks
Add an architecture specific ucall.h and inline the simple arch hooks, e.g. the init hook for everything except ARM, and the actual "do ucall" hook for everything except x86 (which should be simple, but temporarily isn't due to carrying a workaround).
Having a per-arch ucall header will allow adding a #define for the expected KVM exit reason for a ucall that is colocated (for everything except x86) with the ucall itself.
--- .../selftests/kvm/include/aarch64/ucall.h | 18 ++++++++++++++++++ .../selftests/kvm/include/riscv/ucall.h | 18 ++++++++++++++++++ .../selftests/kvm/include/s390x/ucall.h | 17 +++++++++++++++++ .../selftests/kvm/include/ucall_common.h | 1 + .../selftests/kvm/include/x86_64/ucall.h | 11 +++++++++++ .../testing/selftests/kvm/lib/aarch64/ucall.c | 11 +---------- tools/testing/selftests/kvm/lib/riscv/ucall.c | 11 ----------- tools/testing/selftests/kvm/lib/s390x/ucall.c | 10 ---------- tools/testing/selftests/kvm/lib/x86_64/ucall.c | 4 ---- 9 files changed, 66 insertions(+), 35 deletions(-) create mode 100644 tools/testing/selftests/kvm/include/aarch64/ucall.h create mode 100644 tools/testing/selftests/kvm/include/riscv/ucall.h create mode 100644 tools/testing/selftests/kvm/include/s390x/ucall.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/ucall.h
tools/testing/selftests/kvm/include/aarch64/ucall.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef SELFTEST_KVM_UCALL_H +#define SELFTEST_KVM_UCALL_H + +#include "kvm_util_base.h" + +/* +* ucall_exit_mmio_addr holds per-VM values (global data is duplicated by each +* VM), it must not be accessed from host code. +*/ +extern vm_vaddr_t *ucall_exit_mmio_addr; + +static inline void ucall_arch_do_ucall (vm_vaddr_t uc) +{ +WRITE_ONCE (*ucall_exit_mmio_addr, uc); +} + +#endif
tools/testing/selftests/kvm/include/riscv/ucall.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef SELFTEST_KVM_UCALL_H +#define SELFTEST_KVM_UCALL_H + +#include "processor.h" + +static inline void ucall_arch_init (struct kvm_vm *vm,vm_paddr_t mmio_gpa) +{ +} + +static inline void ucall_arch_do_ucall (vm_vaddr_t uc) +{ +sbi_ecall (KVM_RISCV_SELFTESTS_SBI_EXT , +KVM_RISCV_SELFTESTS_SBI_UCALL , + uc,0 ,0 ,0 ,0 ,0 ); +} + +#endif
tools/testing/selftests/kvm/include/s390x/ucall.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef SELFTEST_KVM_UCALL_H +#define SELFTEST_KVM_UCALL_H + +#include "kvm_util_base.h" + +static inline void ucall_arch_init (struct kvm_vm *vm,vm_paddr_t mmio_gpa) +{ +} + +static inline void ucall_arch_do_ucall (vm_vaddr_t uc) +{ +/* Exit via DIAGNOSE 0x501 (normally used for breakpoints) */ + asmvolatile ("diag 0,%0,0x501" : :"a" (uc) :"memory" ); +} + +#endif
tools/testing/selftests/kvm/include/ucall_common.h +1 -0
@@ -7,6 +7,7 @@#ifndef SELFTEST_KVM_UCALL_COMMON_H #define SELFTEST_KVM_UCALL_COMMON_H #include "test_util.h" +#include "ucall.h" /* Common ucalls */ enum {
tools/testing/selftests/kvm/include/x86_64/ucall.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef SELFTEST_KVM_UCALL_H +#define SELFTEST_KVM_UCALL_H + +#include "kvm_util_base.h" + +static inline void ucall_arch_init (struct kvm_vm *vm,vm_paddr_t mmio_gpa) +{ +} + +#endif
tools/testing/selftests/kvm/lib/aarch64/ucall.c +1 -10
@@ -6,11 +6,7 @@*/ #include "kvm_util.h" -/* -* ucall_exit_mmio_addr holds per-VM values (global data is duplicated by each -* VM), it must not be accessed from host code. -*/ -static vm_vaddr_t *ucall_exit_mmio_addr; +vm_vaddr_t *ucall_exit_mmio_addr;void ucall_arch_init (struct kvm_vm *vm,vm_paddr_t mmio_gpa) {
@@ -23,11 +19,6 @@ void ucall_arch_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa)write_guest_global (vm, ucall_exit_mmio_addr, (vm_vaddr_t *)mmio_gva); } -void ucall_arch_do_ucall (vm_vaddr_t uc) -{ -WRITE_ONCE (*ucall_exit_mmio_addr, uc); -} -void *ucall_arch_get_ucall (struct kvm_vcpu *vcpu) {struct kvm_run *run = vcpu->run;
tools/testing/selftests/kvm/lib/riscv/ucall.c +0 -11
@@ -10,10 +10,6 @@#include "kvm_util.h" #include "processor.h" -void ucall_arch_init (struct kvm_vm *vm,vm_paddr_t mmio_gpa) -{ -} - struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4,
@@ -40,13 +36,6 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,return ret; } -void ucall_arch_do_ucall (vm_vaddr_t uc) -{ -sbi_ecall (KVM_RISCV_SELFTESTS_SBI_EXT , -KVM_RISCV_SELFTESTS_SBI_UCALL , - uc,0 ,0 ,0 ,0 ,0 ); -} -void *ucall_arch_get_ucall (struct kvm_vcpu *vcpu) {struct kvm_run *run = vcpu->run;
tools/testing/selftests/kvm/lib/s390x/ucall.c +0 -10
@@ -6,16 +6,6 @@*/ #include "kvm_util.h" -void ucall_arch_init (struct kvm_vm *vm,vm_paddr_t mmio_gpa) -{ -} - -void ucall_arch_do_ucall (vm_vaddr_t uc) -{ -/* Exit via DIAGNOSE 0x501 (normally used for breakpoints) */ - asmvolatile ("diag 0,%0,0x501" : :"a" (uc) :"memory" ); -} -void *ucall_arch_get_ucall (struct kvm_vcpu *vcpu) {struct kvm_run *run = vcpu->run;
tools/testing/selftests/kvm/lib/x86_64/ucall.c +0 -4
@@ -8,10 +8,6 @@#define UCALL_PIO_PORT ((uint16_t)0x1000) -void ucall_arch_init (struct kvm_vm *vm,vm_paddr_t mmio_gpa) -{ -} -void ucall_arch_do_ucall (vm_vaddr_t uc) {/*
Signature · 1 line
2.41.0.585.gd2178a4bd4-goog
Re: [PATCH v4.1 1/3] KVM: selftests: Add arch ucall.h and inline simple arch hooks
Quoted 10 lines · Sean Christopherson
Add an architecture specific
ucall.hand inline the simple arch hooks, e.g. the init hook for everything except ARM, and the actual "do ucall" hook for everything except x86 (which should be simple, but temporarily isn't due to carrying a workaround).Having a per-arch ucall header will allow adding a #define for the expected KVM exit reason for a ucall that is colocated (for everything except x86) with the ucall itself.
Signed-off-by Sean Christopherson <[email protected]>
Quoted 16 lines
--- .../selftests/kvm/include/aarch64/ucall.h | 18 ++++++++++++++++++ .../selftests/kvm/include/riscv/ucall.h | 18 ++++++++++++++++++ .../selftests/kvm/include/s390x/ucall.h | 17 +++++++++++++++++ .../selftests/kvm/include/ucall_common.h | 1 + .../selftests/kvm/include/x86_64/ucall.h | 11 +++++++++++ .../testing/selftests/kvm/lib/aarch64/ucall.c | 11 +---------- tools/testing/selftests/kvm/lib/riscv/ucall.c | 11 ----------- tools/testing/selftests/kvm/lib/s390x/ucall.c | 10 ---------- tools/testing/selftests/kvm/lib/x86_64/ucall.c | 4 ---- 9 files changed, 66 insertions(+), 35 deletions(-) create mode 100644 tools/testing/selftests/kvm/include/aarch64/ucall.h create mode 100644 tools/testing/selftests/kvm/include/riscv/ucall.h create mode 100644 tools/testing/selftests/kvm/include/s390x/ucall.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/ucall.h
Sean Christopherson
reviewerPATCH 2/3 KVM: selftests: Add #define of expected KVM exit reason for ucall
In reply to Sean ChristophersonDefine the expected architecture specific exit reason for a successful ucall so that common tests can assert that a ucall occurred without the test needing to implement arch specific code.
--- tools/testing/selftests/kvm/include/aarch64/ucall.h | 2 ++ tools/testing/selftests/kvm/include/riscv/ucall.h | 2 ++ tools/testing/selftests/kvm/include/s390x/ucall.h | 2 ++ tools/testing/selftests/kvm/include/x86_64/ucall.h | 2 ++ 4 files changed, 8 insertions(+)
tools/testing/selftests/kvm/include/aarch64/ucall.h +2 -0
@@ -4,6 +4,8 @@#include "kvm_util_base.h" +#define UCALL_EXIT_REASON KVM_EXIT_MMIO +/* * ucall_exit_mmio_addr holds per-VM values (global data is duplicated by each * VM), it must not be accessed from host code.
tools/testing/selftests/kvm/include/riscv/ucall.h +2 -0
@@ -4,6 +4,8 @@#include "processor.h" +#define UCALL_EXIT_REASON KVM_EXIT_RISCV_SBI +static inline void ucall_arch_init (struct kvm_vm *vm,vm_paddr_t mmio_gpa) { }
tools/testing/selftests/kvm/include/s390x/ucall.h +2 -0
@@ -4,6 +4,8 @@#include "kvm_util_base.h" +#define UCALL_EXIT_REASON KVM_EXIT_S390_SIEIC +static inline void ucall_arch_init (struct kvm_vm *vm,vm_paddr_t mmio_gpa) { }
tools/testing/selftests/kvm/include/x86_64/ucall.h +2 -0
@@ -4,6 +4,8 @@#include "kvm_util_base.h" +#define UCALL_EXIT_REASON KVM_EXIT_IO +static inline void ucall_arch_init (struct kvm_vm *vm,vm_paddr_t mmio_gpa) { }
Signature · 1 line
2.41.0.585.gd2178a4bd4-goog
Re: [PATCH v4.1 2/3] KVM: selftests: Add #define of expected KVM exit reason for ucall
Quoted 4 lines · Sean Christopherson
Define the expected architecture specific exit reason for a successful ucall so that common tests can assert that a ucall occurred without the test needing to implement arch specific code.
Quoted 9 lines
Suggested-by Andrew Jones <[email protected]>Signed-off-by Sean Christopherson <[email protected]>--- tools/testing/selftests/kvm/include/aarch64/ucall.h | 2 ++ tools/testing/selftests/kvm/include/riscv/ucall.h | 2 ++ tools/testing/selftests/kvm/include/s390x/ucall.h | 2 ++ tools/testing/selftests/kvm/include/x86_64/ucall.h | 2 ++ 4 files changed, 8 insertions(+)
Sean Christopherson
reviewerPATCH 3/3 KVM: selftests: Add a selftest for guest prints and formatted asserts
In reply to Sean ChristophersonFrom: Aaron Lewis <[email protected]>
Add a test to exercise the various features in KVM selftest's local snprintf() and compare them to LIBC's snprintf() to ensure they behave the same.
This is not an exhaustive test. KVM's local snprintf() does not implement all the features LIBC does, e.g. KVM's local snprintf() does not support floats or doubles, so testing for those features were excluded.
Testing was added for the features that are expected to work to support a minimal version of printf() in the guest.
--- tools/testing/selftests/kvm/Makefile | 4 + .../testing/selftests/kvm/guest_print_test.c | 221 ++++++++++++++++++ 2 files changed, 225 insertions(+) create mode 100644 tools/testing/selftests/kvm/guest_print_test.c
tools/testing/selftests/kvm/Makefile +4 -0
@@ -123,6 +123,7 @@ TEST_GEN_PROGS_x86_64 += access_tracking_perf_test TEST_GEN_PROGS_x86_64 += demand_paging_test TEST_GEN_PROGS_x86_64 += dirty_log_test TEST_GEN_PROGS_x86_64 += dirty_log_perf_test +TEST_GEN_PROGS_x86_64 += guest_print_test TEST_GEN_PROGS_x86_64 += hardware_disable_test TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus TEST_GEN_PROGS_x86_64 += kvm_page_table_test
@@ -153,6 +154,7 @@ TEST_GEN_PROGS_aarch64 += access_tracking_perf_test TEST_GEN_PROGS_aarch64 += demand_paging_test TEST_GEN_PROGS_aarch64 += dirty_log_test TEST_GEN_PROGS_aarch64 += dirty_log_perf_test +TEST_GEN_PROGS_aarch64 += guest_print_test TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus TEST_GEN_PROGS_aarch64 += kvm_page_table_test TEST_GEN_PROGS_aarch64 += memslot_modification_stress_test
@@ -169,6 +171,7 @@ TEST_GEN_PROGS_s390x += s390x/tprot TEST_GEN_PROGS_s390x += s390x/cmma_test TEST_GEN_PROGS_s390x += demand_paging_test TEST_GEN_PROGS_s390x += dirty_log_test +TEST_GEN_PROGS_s390x += guest_print_test TEST_GEN_PROGS_s390x += kvm_create_max_vcpus TEST_GEN_PROGS_s390x += kvm_page_table_test TEST_GEN_PROGS_s390x += rseq_test
@@ -177,6 +180,7 @@ TEST_GEN_PROGS_s390x += kvm_binary_stats_test TEST_GEN_PROGS_riscv += demand_paging_test TEST_GEN_PROGS_riscv += dirty_log_test +TEST_GEN_PROGS_riscv += guest_print_test TEST_GEN_PROGS_riscv += kvm_create_max_vcpus TEST_GEN_PROGS_riscv += kvm_page_table_test TEST_GEN_PROGS_riscv += set_memory_region_test
tools/testing/selftests/kvm/guest_print_test.c new file +221 -0
221 lines not on this page · raw message
Signature · 1 line
2.41.0.585.gd2178a4bd4-goog