KVM: selftests: Fix nested SVM tests when built with clang
authorJim Mattson <jmattson@google.com>
Thu, 30 Sep 2021 00:36:49 +0000 (17:36 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 22 Oct 2021 16:46:37 +0000 (12:46 -0400)
commited290e1c20da19fa100a3e0f421aa31b65984960
tree92335b7007afd0ee1930c0e7ad09a974404ff2a9
parentdfd3c713a9c87ade13c7bf618455a57f4d01e97b
KVM: selftests: Fix nested SVM tests when built with clang

Though gcc conveniently compiles a simple memset to "rep stos," clang
prefers to call the libc version of memset. If a test is dynamically
linked, the libc memset isn't available in L1 (nor is the PLT or the
GOT, for that matter). Even if the test is statically linked, the libc
memset may choose to use some CPU features, like AVX, which may not be
enabled in L1. Note that __builtin_memset doesn't solve the problem,
because (a) the compiler is free to call memset anyway, and (b)
__builtin_memset may also choose to use features like AVX, which may
not be available in L1.

To avoid a myriad of problems, use an explicit "rep stos" to clear the
VMCB in generic_svm_setup(), which is called both from L0 and L1.

Reported-by: Ricardo Koller <ricarkol@google.com>
Signed-off-by: Jim Mattson <jmattson@google.com>
Fixes: 20ba262f8631a ("selftests: KVM: AMD Nested test infrastructure")
Message-Id: <20210930003649.4026553-1-jmattson@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/lib/x86_64/svm.c