KVM: selftests: Add guest_snprintf() to KVM selftests
authorAaron Lewis <aaronlewis@google.com>
Sat, 29 Jul 2023 00:36:14 +0000 (17:36 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 2 Aug 2023 21:41:59 +0000 (14:41 -0700)
commite5119382499cefc839097dcc78f27ab00131e7ad
treea46d59739c5b576c43c91356ba9dea961514a90c
parenta1c1b55e116c14de4f8a78286b502101f2a1620c
KVM: selftests: Add guest_snprintf() to KVM selftests

Add a local version of guest_snprintf() for use in the guest.

Having a local copy allows the guest access to string formatting
options without dependencies on LIBC.  LIBC is problematic because
it heavily relies on both AVX-512 instructions and a TLS, neither of
which are guaranteed to be set up in the guest.

The file guest_sprintf.c was lifted from arch/x86/boot/printf.c and
adapted to work in the guest, including the addition of buffer length.
I.e. s/sprintf/snprintf/

The functions where prefixed with "guest_" to allow guests to
explicitly call them.

A string formatted by this function is expected to succeed or die.  If
something goes wrong during the formatting process a GUEST_ASSERT()
will be thrown.

Signed-off-by: Aaron Lewis <aaronlewis@google.com>
Link: https://lore.kernel.org/all/mtdi6smhur5rqffvpu7qux7mptonw223y2653x2nwzvgm72nlo@zyc4w3kwl3rg
[sean: add a link to the discussion of other options]
Link: https://lore.kernel.org/r/20230729003643.1053367-6-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/Makefile
tools/testing/selftests/kvm/include/test_util.h
tools/testing/selftests/kvm/lib/guest_sprintf.c [new file with mode: 0644]