* [PATCH v2 0/4] KVM: selftests: Annotate guest printfs as such
@ 2023-11-29 22:49 Sean Christopherson
2023-11-29 22:49 ` [PATCH v2 1/4] KVM: selftests: Fix MWAIT error message when guest assertion fails Sean Christopherson
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Sean Christopherson @ 2023-11-29 22:49 UTC (permalink / raw)
To: Paolo Bonzini, Sean Christopherson; +Cc: kvm, linux-kernel, Maxim Levitsky
Fix a handful of broken guest assert/printf messages, and annotate guest
ucall, printf, and assert helpers with __printf() so that such breakage is
detected by the compiler.
v2:
- Annotate the relevant helpers. [Maxim]
- Fix all other warnings (v1 fixed only the MWAIT error message)
v1: https://lore.kernel.org/all/20231107182159.404770-1-seanjc@google.com
Sean Christopherson (4):
KVM: selftests: Fix MWAIT error message when guest assertion fails
KVM: selftests: Fix benign %llx vs. %lx issues in guest asserts
KVM: selftests: Fix broken assert messages in Hyper-V features test
KVM: selftests: Annotate guest ucall, printf, and assert helpers with
__printf()
tools/testing/selftests/kvm/include/test_util.h | 2 +-
tools/testing/selftests/kvm/include/ucall_common.h | 7 ++++---
tools/testing/selftests/kvm/set_memory_region_test.c | 6 +++---
tools/testing/selftests/kvm/x86_64/hyperv_features.c | 10 +++++-----
.../testing/selftests/kvm/x86_64/monitor_mwait_test.c | 6 ++++--
.../kvm/x86_64/private_mem_conversions_test.c | 2 +-
.../selftests/kvm/x86_64/svm_nested_soft_inject_test.c | 4 ++--
tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c | 2 +-
tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c | 8 ++++----
9 files changed, 25 insertions(+), 22 deletions(-)
base-commit: 6803fb00772cc50cd59a66bd8caaee5c84b13fcf
--
2.43.0.rc1.413.gea7ed67945-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/4] KVM: selftests: Fix MWAIT error message when guest assertion fails
2023-11-29 22:49 [PATCH v2 0/4] KVM: selftests: Annotate guest printfs as such Sean Christopherson
@ 2023-11-29 22:49 ` Sean Christopherson
2023-11-29 22:49 ` [PATCH v2 2/4] KVM: selftests: Fix benign %llx vs. %lx issues in guest asserts Sean Christopherson
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2023-11-29 22:49 UTC (permalink / raw)
To: Paolo Bonzini, Sean Christopherson; +Cc: kvm, linux-kernel, Maxim Levitsky
Print out the test and vector as intended when a guest assert fails an
assertion regarding MONITOR/MWAIT faulting. Unfortunately, the guest
printf support doesn't detect such issues at compile-time, so the bug
manifests as a confusing error message, e.g. in the most confusing case,
the test complains that it got vector "0" instead of expected vector "0".
Fixes: 0f52e4aaa614 ("KVM: selftests: Convert the MONITOR/MWAIT test to use printf guest asserts")
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Link: https://lore.kernel.org/r/20231107182159.404770-1-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c b/tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c
index 80aa3d8b18f8..853802641e1e 100644
--- a/tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c
+++ b/tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c
@@ -27,10 +27,12 @@ do { \
\
if (fault_wanted) \
__GUEST_ASSERT((vector) == UD_VECTOR, \
- "Expected #UD on " insn " for testcase '0x%x', got '0x%x'", vector); \
+ "Expected #UD on " insn " for testcase '0x%x', got '0x%x'", \
+ testcase, vector); \
else \
__GUEST_ASSERT(!(vector), \
- "Expected success on " insn " for testcase '0x%x', got '0x%x'", vector); \
+ "Expected success on " insn " for testcase '0x%x', got '0x%x'", \
+ testcase, vector); \
} while (0)
static void guest_monitor_wait(int testcase)
--
2.43.0.rc1.413.gea7ed67945-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/4] KVM: selftests: Fix benign %llx vs. %lx issues in guest asserts
2023-11-29 22:49 [PATCH v2 0/4] KVM: selftests: Annotate guest printfs as such Sean Christopherson
2023-11-29 22:49 ` [PATCH v2 1/4] KVM: selftests: Fix MWAIT error message when guest assertion fails Sean Christopherson
@ 2023-11-29 22:49 ` Sean Christopherson
2023-11-29 22:49 ` [PATCH v2 3/4] KVM: selftests: Fix broken assert messages in Hyper-V features test Sean Christopherson
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2023-11-29 22:49 UTC (permalink / raw)
To: Paolo Bonzini, Sean Christopherson; +Cc: kvm, linux-kernel, Maxim Levitsky
Convert %llx to %lx as appropriate in guest asserts. The guest printf
implementation treats them the same as KVM selftests are 64-bit only, but
strictly adhering to the correct format will allow annotating the
underlying helpers with __printf() without introducing new warnings in the
build.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
tools/testing/selftests/kvm/set_memory_region_test.c | 6 +++---
tools/testing/selftests/kvm/x86_64/hyperv_features.c | 2 +-
.../selftests/kvm/x86_64/private_mem_conversions_test.c | 2 +-
.../selftests/kvm/x86_64/svm_nested_soft_inject_test.c | 4 ++--
tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c | 2 +-
tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c | 8 ++++----
6 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/testing/selftests/kvm/set_memory_region_test.c
index 6637a0845acf..03ec7efd19aa 100644
--- a/tools/testing/selftests/kvm/set_memory_region_test.c
+++ b/tools/testing/selftests/kvm/set_memory_region_test.c
@@ -157,17 +157,17 @@ static void guest_code_move_memory_region(void)
*/
val = guest_spin_on_val(0);
__GUEST_ASSERT(val == 1 || val == MMIO_VAL,
- "Expected '1' or MMIO ('%llx'), got '%llx'", MMIO_VAL, val);
+ "Expected '1' or MMIO ('%lx'), got '%lx'", MMIO_VAL, val);
/* Spin until the misaligning memory region move completes. */
val = guest_spin_on_val(MMIO_VAL);
__GUEST_ASSERT(val == 1 || val == 0,
- "Expected '0' or '1' (no MMIO), got '%llx'", val);
+ "Expected '0' or '1' (no MMIO), got '%lx'", val);
/* Spin until the memory region starts to get re-aligned. */
val = guest_spin_on_val(0);
__GUEST_ASSERT(val == 1 || val == MMIO_VAL,
- "Expected '1' or MMIO ('%llx'), got '%llx'", MMIO_VAL, val);
+ "Expected '1' or MMIO ('%lx'), got '%lx'", MMIO_VAL, val);
/* Spin until the re-aligning memory region move completes. */
val = guest_spin_on_val(MMIO_VAL);
diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_features.c b/tools/testing/selftests/kvm/x86_64/hyperv_features.c
index 9f28aa276c4e..4bb63b6ee4a0 100644
--- a/tools/testing/selftests/kvm/x86_64/hyperv_features.c
+++ b/tools/testing/selftests/kvm/x86_64/hyperv_features.c
@@ -66,7 +66,7 @@ static void guest_msr(struct msr_data *msr)
if (msr->write)
__GUEST_ASSERT(!vector,
- "WRMSR(0x%x) to '0x%llx', RDMSR read '0x%llx'",
+ "WRMSR(0x%x) to '0x%lx', RDMSR read '0x%lx'",
msr->idx, msr->write_val, msr_val);
/* Invariant TSC bit appears when TSC invariant control MSR is written to */
diff --git a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c
index 4d6a37a5d896..65ad38b6be1f 100644
--- a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c
+++ b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c
@@ -35,7 +35,7 @@ do { \
\
for (i = 0; i < size; i++) \
__GUEST_ASSERT(mem[i] == pattern, \
- "Guest expected 0x%x at offset %lu (gpa 0x%llx), got 0x%x", \
+ "Guest expected 0x%x at offset %lu (gpa 0x%lx), got 0x%x", \
pattern, i, gpa + i, mem[i]); \
} while (0)
diff --git a/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c b/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c
index 7ee44496cf97..0c7ce3d4e83a 100644
--- a/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c
+++ b/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c
@@ -103,7 +103,7 @@ static void l1_guest_code(struct svm_test_data *svm, uint64_t is_nmi, uint64_t i
run_guest(vmcb, svm->vmcb_gpa);
__GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL,
- "Expected VMMCAL #VMEXIT, got '0x%x', info1 = '0x%llx, info2 = '0x%llx'",
+ "Expected VMMCAL #VMEXIT, got '0x%x', info1 = '0x%lx, info2 = '0x%lx'",
vmcb->control.exit_code,
vmcb->control.exit_info_1, vmcb->control.exit_info_2);
@@ -133,7 +133,7 @@ static void l1_guest_code(struct svm_test_data *svm, uint64_t is_nmi, uint64_t i
run_guest(vmcb, svm->vmcb_gpa);
__GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_HLT,
- "Expected HLT #VMEXIT, got '0x%x', info1 = '0x%llx, info2 = '0x%llx'",
+ "Expected HLT #VMEXIT, got '0x%x', info1 = '0x%lx, info2 = '0x%lx'",
vmcb->control.exit_code,
vmcb->control.exit_info_1, vmcb->control.exit_info_2);
diff --git a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c
index ebbcb0a3f743..2a8d4ac2f020 100644
--- a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c
+++ b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c
@@ -56,7 +56,7 @@ static void guest_test_perf_capabilities_gp(uint64_t val)
uint8_t vector = wrmsr_safe(MSR_IA32_PERF_CAPABILITIES, val);
__GUEST_ASSERT(vector == GP_VECTOR,
- "Expected #GP for value '0x%llx', got vector '0x%x'",
+ "Expected #GP for value '0x%lx', got vector '0x%x'",
val, vector);
}
diff --git a/tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c b/tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c
index 77d04a7bdadd..dc6217440db3 100644
--- a/tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c
+++ b/tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c
@@ -25,7 +25,7 @@ do { \
\
__GUEST_ASSERT((__supported & (xfeatures)) != (xfeatures) || \
__supported == ((xfeatures) | (dependencies)), \
- "supported = 0x%llx, xfeatures = 0x%llx, dependencies = 0x%llx", \
+ "supported = 0x%lx, xfeatures = 0x%llx, dependencies = 0x%llx", \
__supported, (xfeatures), (dependencies)); \
} while (0)
@@ -42,7 +42,7 @@ do { \
uint64_t __supported = (supported_xcr0) & (xfeatures); \
\
__GUEST_ASSERT(!__supported || __supported == (xfeatures), \
- "supported = 0x%llx, xfeatures = 0x%llx", \
+ "supported = 0x%lx, xfeatures = 0x%llx", \
__supported, (xfeatures)); \
} while (0)
@@ -81,7 +81,7 @@ static void guest_code(void)
vector = xsetbv_safe(0, supported_xcr0);
__GUEST_ASSERT(!vector,
- "Expected success on XSETBV(0x%llx), got vector '0x%x'",
+ "Expected success on XSETBV(0x%lx), got vector '0x%x'",
supported_xcr0, vector);
for (i = 0; i < 64; i++) {
@@ -90,7 +90,7 @@ static void guest_code(void)
vector = xsetbv_safe(0, supported_xcr0 | BIT_ULL(i));
__GUEST_ASSERT(vector == GP_VECTOR,
- "Expected #GP on XSETBV(0x%llx), supported XCR0 = %llx, got vector '0x%x'",
+ "Expected #GP on XSETBV(0x%llx), supported XCR0 = %lx, got vector '0x%x'",
BIT_ULL(i), supported_xcr0, vector);
}
--
2.43.0.rc1.413.gea7ed67945-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 3/4] KVM: selftests: Fix broken assert messages in Hyper-V features test
2023-11-29 22:49 [PATCH v2 0/4] KVM: selftests: Annotate guest printfs as such Sean Christopherson
2023-11-29 22:49 ` [PATCH v2 1/4] KVM: selftests: Fix MWAIT error message when guest assertion fails Sean Christopherson
2023-11-29 22:49 ` [PATCH v2 2/4] KVM: selftests: Fix benign %llx vs. %lx issues in guest asserts Sean Christopherson
@ 2023-11-29 22:49 ` Sean Christopherson
2023-11-29 22:49 ` [PATCH v2 4/4] KVM: selftests: Annotate guest ucall, printf, and assert helpers with __printf() Sean Christopherson
2023-12-01 23:30 ` [PATCH v2 0/4] KVM: selftests: Annotate guest printfs as such Sean Christopherson
4 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2023-11-29 22:49 UTC (permalink / raw)
To: Paolo Bonzini, Sean Christopherson; +Cc: kvm, linux-kernel, Maxim Levitsky
Swap the ordering of parameters to guest asserts related to {RD,WR}MSR
success/failure in the Hyper-V features test. As is, the output will
be mangled and broken due to passing an integer as a string and vice
versa.
Opportunistically fix a benign %u vs. %lu issue as well.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
tools/testing/selftests/kvm/x86_64/hyperv_features.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_features.c b/tools/testing/selftests/kvm/x86_64/hyperv_features.c
index 4bb63b6ee4a0..29f6bdbce817 100644
--- a/tools/testing/selftests/kvm/x86_64/hyperv_features.c
+++ b/tools/testing/selftests/kvm/x86_64/hyperv_features.c
@@ -55,11 +55,11 @@ static void guest_msr(struct msr_data *msr)
if (msr->fault_expected)
__GUEST_ASSERT(vector == GP_VECTOR,
"Expected #GP on %sMSR(0x%x), got vector '0x%x'",
- msr->idx, msr->write ? "WR" : "RD", vector);
+ msr->write ? "WR" : "RD", msr->idx, vector);
else
__GUEST_ASSERT(!vector,
"Expected success on %sMSR(0x%x), got vector '0x%x'",
- msr->idx, msr->write ? "WR" : "RD", vector);
+ msr->write ? "WR" : "RD", msr->idx, vector);
if (vector || is_write_only_msr(msr->idx))
goto done;
@@ -102,11 +102,11 @@ static void guest_hcall(vm_vaddr_t pgs_gpa, struct hcall_data *hcall)
vector = __hyperv_hypercall(hcall->control, input, output, &res);
if (hcall->ud_expected) {
__GUEST_ASSERT(vector == UD_VECTOR,
- "Expected #UD for control '%u', got vector '0x%x'",
+ "Expected #UD for control '%lu', got vector '0x%x'",
hcall->control, vector);
} else {
__GUEST_ASSERT(!vector,
- "Expected no exception for control '%u', got vector '0x%x'",
+ "Expected no exception for control '%lu', got vector '0x%x'",
hcall->control, vector);
GUEST_ASSERT_EQ(res, hcall->expect);
}
--
2.43.0.rc1.413.gea7ed67945-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 4/4] KVM: selftests: Annotate guest ucall, printf, and assert helpers with __printf()
2023-11-29 22:49 [PATCH v2 0/4] KVM: selftests: Annotate guest printfs as such Sean Christopherson
` (2 preceding siblings ...)
2023-11-29 22:49 ` [PATCH v2 3/4] KVM: selftests: Fix broken assert messages in Hyper-V features test Sean Christopherson
@ 2023-11-29 22:49 ` Sean Christopherson
2023-12-01 23:30 ` [PATCH v2 0/4] KVM: selftests: Annotate guest printfs as such Sean Christopherson
4 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2023-11-29 22:49 UTC (permalink / raw)
To: Paolo Bonzini, Sean Christopherson; +Cc: kvm, linux-kernel, Maxim Levitsky
Annotate guest printf helpers with __printf() so that the compiler will
warn about incorrect formatting at compile time (see git log for how easy
it is to screw up with the formatting).
Suggested-by: Maxim Levitsky <mlevitsk@redhat.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
tools/testing/selftests/kvm/include/test_util.h | 2 +-
tools/testing/selftests/kvm/include/ucall_common.h | 7 ++++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
index a0c7dd3a5b30..71a41fa924b7 100644
--- a/tools/testing/selftests/kvm/include/test_util.h
+++ b/tools/testing/selftests/kvm/include/test_util.h
@@ -191,7 +191,7 @@ static inline uint32_t atoi_non_negative(const char *name, const char *num_str)
}
int guest_vsnprintf(char *buf, int n, const char *fmt, va_list args);
-int guest_snprintf(char *buf, int n, const char *fmt, ...);
+__printf(3, 4) int guest_snprintf(char *buf, int n, const char *fmt, ...);
char *strdup_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2), nonnull(1)));
diff --git a/tools/testing/selftests/kvm/include/ucall_common.h b/tools/testing/selftests/kvm/include/ucall_common.h
index 0fb472a5a058..d9d6581b8d4f 100644
--- a/tools/testing/selftests/kvm/include/ucall_common.h
+++ b/tools/testing/selftests/kvm/include/ucall_common.h
@@ -34,9 +34,10 @@ void ucall_arch_do_ucall(vm_vaddr_t uc);
void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu);
void ucall(uint64_t cmd, int nargs, ...);
-void ucall_fmt(uint64_t cmd, const char *fmt, ...);
-void ucall_assert(uint64_t cmd, const char *exp, const char *file,
- unsigned int line, const char *fmt, ...);
+__printf(2, 3) void ucall_fmt(uint64_t cmd, const char *fmt, ...);
+__printf(5, 6) void ucall_assert(uint64_t cmd, const char *exp,
+ const char *file, unsigned int line,
+ const char *fmt, ...);
uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc);
void ucall_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa);
int ucall_nr_pages_required(uint64_t page_size);
--
2.43.0.rc1.413.gea7ed67945-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/4] KVM: selftests: Annotate guest printfs as such
2023-11-29 22:49 [PATCH v2 0/4] KVM: selftests: Annotate guest printfs as such Sean Christopherson
` (3 preceding siblings ...)
2023-11-29 22:49 ` [PATCH v2 4/4] KVM: selftests: Annotate guest ucall, printf, and assert helpers with __printf() Sean Christopherson
@ 2023-12-01 23:30 ` Sean Christopherson
4 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2023-12-01 23:30 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel, Maxim Levitsky
On Wed, 29 Nov 2023 14:49:12 -0800, Sean Christopherson wrote:
> Fix a handful of broken guest assert/printf messages, and annotate guest
> ucall, printf, and assert helpers with __printf() so that such breakage is
> detected by the compiler.
>
> v2:
> - Annotate the relevant helpers. [Maxim]
> - Fix all other warnings (v1 fixed only the MWAIT error message)
>
> [...]
Applied rather quickly to kvm-x86 selftests, as I want to get these a few days
of exposure in -next before sending them to Paolo for 6.7-rc5. I'll happily do
fixups if there is any feedback that needs to be addressed. Thanks!
[1/4] KVM: selftests: Fix MWAIT error message when guest assertion fails
https://github.com/kvm-x86/linux/commit/1af3bf2befc0
[2/4] KVM: selftests: Fix benign %llx vs. %lx issues in guest asserts
https://github.com/kvm-x86/linux/commit/4d53dcc5d0bc
[3/4] KVM: selftests: Fix broken assert messages in Hyper-V features test
https://github.com/kvm-x86/linux/commit/f813e6d41baf
[4/4] KVM: selftests: Annotate guest ucall, printf, and assert helpers with __printf()
https://github.com/kvm-x86/linux/commit/1b2658e4c709
--
https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-12-01 23:36 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-29 22:49 [PATCH v2 0/4] KVM: selftests: Annotate guest printfs as such Sean Christopherson
2023-11-29 22:49 ` [PATCH v2 1/4] KVM: selftests: Fix MWAIT error message when guest assertion fails Sean Christopherson
2023-11-29 22:49 ` [PATCH v2 2/4] KVM: selftests: Fix benign %llx vs. %lx issues in guest asserts Sean Christopherson
2023-11-29 22:49 ` [PATCH v2 3/4] KVM: selftests: Fix broken assert messages in Hyper-V features test Sean Christopherson
2023-11-29 22:49 ` [PATCH v2 4/4] KVM: selftests: Annotate guest ucall, printf, and assert helpers with __printf() Sean Christopherson
2023-12-01 23:30 ` [PATCH v2 0/4] KVM: selftests: Annotate guest printfs as such Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®