kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] Add printf and formatted asserts in the guest
@ 2023-03-01  5:34 Aaron Lewis
  2023-03-01  5:34 ` [PATCH 1/8] KVM: selftests: Hoist XGETBV and XSETBV to make them more accessible Aaron Lewis
                   ` (8 more replies)
  0 siblings, 9 replies; 23+ messages in thread
From: Aaron Lewis @ 2023-03-01  5:34 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, jmattson, seanjc, Aaron Lewis

Extend the ucall framework to offer GUEST_PRINTF and GUEST_ASSERT_FMT
in selftests.  This allows the guest to use string formating for easier
debugging and richer assert messages.

I was originally going to send this series out as an RFC to demonstrate
two different ways of implementing prints in the guest (both through the
same ucall interface).  I ultimately decided against it because the other
approach had enough cons to convince me that this one is better.

As a quick overview on the approach I abondoned, it involved adding enough
support to the guest to allow it to call the LIBC version of vsprintf()
directly.  In order to do that a simple TLS segment had to be added to the
guest, AVX-512 needed to be enabled, and the loadable ELF segments needed
to be copied from the host.  This all seemed very intrusive to the guest.
I tried reducing this burden by getting the string functions to not
use AVX-512 instructions, unfortunately the complier flags I tried didn't
work.  Also, the approach used in this series is far less intrusive to
the guest anyway, so I abondoned it.

That exercise informed how I set up the selftest.  The selftest, aside
from using GUEST_PRINTF and GUEST_ASSERT_FMT, also checks XCR0 to show
that the prints work without AVX-512 being enabled.  Two things I
learned LIBC loves to do when using string functions is use the TLS and
call AVX-512 instructions.  Either of which will cause the test to either
crash or (unintentionally) assert.

I say unintentionally assert because the test ends with a formatted
assert firing.  This is intentional, and is meant to demonstrate the
formatted assert.

That is one reason I don't really expect the selftest to be accepted with
this series.  The other reason is it doesn't test anything in the kernel.
And if the selftest is not accepted then the first two patches can be
omitted too.  The core of the series are patches 3-7.

Patches 1-2:
 - Adds XGETBV/XSETBV and xfeature flags to common code.
 - Needed for the selftest added in the final commit.
 - Also included in:
     https://lore.kernel.org/kvm/20230224223607.1580880-1-aaronlewis@google.com/
 - Can be omitted from the final series along with the selftest.

Patches 3-5:
 - Adds a local version of vsprintf to the selftests for the guest.

Patches 6-7:
 - Adds GUEST_PRINTF and GUEST_ASSERT_FMT to the ucall framework.

Patch 8:
 - Adds a selftest to demonstrate the usage of prints and formatted
   asserts in the guest.
 - This test is a demo and doesn't have to be merged with this series,
   which also means patches 1 and 2 don't have to be merged either.

Aaron Lewis (8):
  KVM: selftests: Hoist XGETBV and XSETBV to make them more accessible
  KVM: selftests: Add XFEATURE masks to common code
  KVM: selftests: Add strnlen() to the string overrides
  KVM: selftests: Copy printf.c to KVM selftests
  KVM: selftests: Add vsprintf() to KVM selftests
  KVM: selftests: Add additional pages to the guest to accommodate ucall
  KVM: selftests: Add string formatting options to ucall
  KVM: selftests: Add a selftest for guest prints and formatted asserts

 tools/testing/selftests/kvm/Makefile          |   3 +
 .../testing/selftests/kvm/include/test_util.h |   2 +
 .../selftests/kvm/include/ucall_common.h      |  20 ++
 .../selftests/kvm/include/x86_64/processor.h  |  36 +++
 tools/testing/selftests/kvm/lib/kvm_util.c    |   4 +
 tools/testing/selftests/kvm/lib/printf.c      | 286 ++++++++++++++++++
 .../selftests/kvm/lib/string_override.c       |   9 +
 .../testing/selftests/kvm/lib/ucall_common.c  |  24 ++
 tools/testing/selftests/kvm/x86_64/amx_test.c |  46 +--
 .../selftests/kvm/x86_64/guest_print_test.c   | 100 ++++++
 10 files changed, 495 insertions(+), 35 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/lib/printf.c
 create mode 100644 tools/testing/selftests/kvm/x86_64/guest_print_test.c

-- 
2.40.0.rc0.216.gc4246ad0f0-goog


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2023-04-21  6:04 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-01  5:34 [PATCH 0/8] Add printf and formatted asserts in the guest Aaron Lewis
2023-03-01  5:34 ` [PATCH 1/8] KVM: selftests: Hoist XGETBV and XSETBV to make them more accessible Aaron Lewis
2023-03-01  5:34 ` [PATCH 2/8] KVM: selftests: Add XFEATURE masks to common code Aaron Lewis
2023-03-01  5:34 ` [PATCH 3/8] KVM: selftests: Add strnlen() to the string overrides Aaron Lewis
2023-03-01  5:34 ` [PATCH 4/8] KVM: selftests: Copy printf.c to KVM selftests Aaron Lewis
2023-03-23 22:04   ` Sean Christopherson
2023-04-17 15:59     ` Aaron Lewis
2023-04-18 15:03       ` Sean Christopherson
2023-04-18 16:06         ` Andrew Jones
2023-04-20 17:50           ` Sean Christopherson
2023-04-21  6:03             ` Andrew Jones
2023-03-01  5:34 ` [PATCH 5/8] KVM: selftests: Add vsprintf() " Aaron Lewis
2023-03-23 21:59   ` Sean Christopherson
2023-04-17 16:08     ` Aaron Lewis
2023-04-18 15:04       ` Sean Christopherson
2023-03-01  5:34 ` [PATCH 6/8] KVM: selftests: Add additional pages to the guest to accommodate ucall Aaron Lewis
2023-03-23 22:07   ` Sean Christopherson
2023-03-01  5:34 ` [PATCH 7/8] KVM: selftests: Add string formatting options to ucall Aaron Lewis
2023-03-01  8:07   ` Shaoqin Huang
2023-03-02 14:52     ` Aaron Lewis
2023-03-23 22:12   ` Sean Christopherson
2023-03-01  5:34 ` [PATCH 8/8] KVM: selftests: Add a selftest for guest prints and formatted asserts Aaron Lewis
2023-03-23 20:57 ` [PATCH 0/8] Add printf and formatted asserts in the guest Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).