Skip to content

Commit

Permalink
KVM: selftests: Fix benign %llx vs. %lx issues in guest asserts
Browse files Browse the repository at this point in the history
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.

Link: https://lore.kernel.org/r/20231129224916.532431-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
  • Loading branch information
sean-jc committed Dec 1, 2023
1 parent 1af3bf2 commit 4d53dcc
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions tools/testing/selftests/kvm/set_memory_region_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/kvm/x86_64/hyperv_features.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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++) {
Expand All @@ -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);
}

Expand Down

0 comments on commit 4d53dcc

Please sign in to comment.