* [PATCH] KVM: selftests: Treat %llx like %lx when formatting guest printf
@ 2023-09-21 17:16 Sean Christopherson
2023-10-05 1:29 ` Sean Christopherson
0 siblings, 1 reply; 2+ messages in thread
From: Sean Christopherson @ 2023-09-21 17:16 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: kvm, linux-kernel, Aaron Lewis, Sean Christopherson
Treat %ll* formats the same as %l* formats when processing printfs from
the guest so that using e.g. %llx instead of %lx generates the expected
output. Ideally, unexpected formats would generate compile-time warnings
or errors, but it's not at all obvious how to actually accomplish that.
Alternatively, guest_vsnprintf() could assert on an unexpected format,
but since the vast majority of printfs are for failed guest asserts,
getting *something* printed is better than nothing.
E.g. before
==== Test Assertion Failure ====
x86_64/private_mem_conversions_test.c:265: mem[i] == 0
pid=4286 tid=4290 errno=4 - Interrupted system call
1 0x0000000000401c74: __test_mem_conversions at private_mem_conversions_test.c:336
2 0x00007f3aae6076da: ?? ??:0
3 0x00007f3aae32161e: ?? ??:0
Expected 0x0 at offset 0 (gpa 0x%lx), got 0x0
and after
==== Test Assertion Failure ====
x86_64/private_mem_conversions_test.c:265: mem[i] == 0
pid=5664 tid=5668 errno=4 - Interrupted system call
1 0x0000000000401c74: __test_mem_conversions at private_mem_conversions_test.c:336
2 0x00007fbe180076da: ?? ??:0
3 0x00007fbe17d2161e: ?? ??:0
Expected 0x0 at offset 0 (gpa 0x100000000), got 0xcc
Fixes: e5119382499c ("KVM: selftests: Add guest_snprintf() to KVM selftests")
Cc: Aaron Lewis <aaronlewis@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
tools/testing/selftests/kvm/lib/guest_sprintf.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/tools/testing/selftests/kvm/lib/guest_sprintf.c b/tools/testing/selftests/kvm/lib/guest_sprintf.c
index c4a69d8aeb68..74627514c4d4 100644
--- a/tools/testing/selftests/kvm/lib/guest_sprintf.c
+++ b/tools/testing/selftests/kvm/lib/guest_sprintf.c
@@ -200,6 +200,13 @@ int guest_vsnprintf(char *buf, int n, const char *fmt, va_list args)
++fmt;
}
+ /*
+ * Play nice with %llu, %llx, etc. KVM selftests only support
+ * 64-bit builds, so just treat %ll* the same as %l*.
+ */
+ if (qualifier == 'l' && *fmt == 'l')
+ ++fmt;
+
/* default base */
base = 10;
base-commit: 7c7cce2cf7ee2ac54851ba1fbcf0e968932e32b9
--
2.42.0.515.g380fc7ccd1-goog
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] KVM: selftests: Treat %llx like %lx when formatting guest printf
2023-09-21 17:16 [PATCH] KVM: selftests: Treat %llx like %lx when formatting guest printf Sean Christopherson
@ 2023-10-05 1:29 ` Sean Christopherson
0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2023-10-05 1:29 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel, Aaron Lewis
On Thu, 21 Sep 2023 10:16:41 -0700, Sean Christopherson wrote:
> Treat %ll* formats the same as %l* formats when processing printfs from
> the guest so that using e.g. %llx instead of %lx generates the expected
> output. Ideally, unexpected formats would generate compile-time warnings
> or errors, but it's not at all obvious how to actually accomplish that.
>
> Alternatively, guest_vsnprintf() could assert on an unexpected format,
> but since the vast majority of printfs are for failed guest asserts,
> getting *something* printed is better than nothing.
>
> [...]
Applied to kvm-x86 selftests, thanks!
[1/1] KVM: selftests: Treat %llx like %lx when formatting guest printf
https://github.com/kvm-x86/linux/commit/b15e7490a1ef
--
https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-05 1:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-21 17:16 [PATCH] KVM: selftests: Treat %llx like %lx when formatting guest printf Sean Christopherson
2023-10-05 1:29 ` 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®