Patch "KVM: selftests: Fix nested SVM tests when built with clang" has been added to the 5.14-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    KVM: selftests: Fix nested SVM tests when built with clang

to the 5.14-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     kvm-selftests-fix-nested-svm-tests-when-built-with-c.patch
and it can be found in the queue-5.14 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 79dcb85d0e47c63dd66bb4b683c694cc03d232b5
Author: Jim Mattson <jmattson@xxxxxxxxxx>
Date:   Wed Sep 29 17:36:49 2021 -0700

    KVM: selftests: Fix nested SVM tests when built with clang
    
    [ Upstream commit ed290e1c20da19fa100a3e0f421aa31b65984960 ]
    
    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@xxxxxxxxxx>
    Signed-off-by: Jim Mattson <jmattson@xxxxxxxxxx>
    Fixes: 20ba262f8631a ("selftests: KVM: AMD Nested test infrastructure")
    Message-Id: <20210930003649.4026553-1-jmattson@xxxxxxxxxx>
    Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/testing/selftests/kvm/lib/x86_64/svm.c b/tools/testing/selftests/kvm/lib/x86_64/svm.c
index 2ac98d70d02bd..161eba7cd1289 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/svm.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/svm.c
@@ -54,6 +54,18 @@ static void vmcb_set_seg(struct vmcb_seg *seg, u16 selector,
 	seg->base = base;
 }
 
+/*
+ * Avoid using memset to clear the vmcb, since libc may not be
+ * available in L1 (and, even if it is, features that libc memset may
+ * want to use, like AVX, may not be enabled).
+ */
+static void clear_vmcb(struct vmcb *vmcb)
+{
+	int n = sizeof(*vmcb) / sizeof(u32);
+
+	asm volatile ("rep stosl" : "+c"(n), "+D"(vmcb) : "a"(0) : "memory");
+}
+
 void generic_svm_setup(struct svm_test_data *svm, void *guest_rip, void *guest_rsp)
 {
 	struct vmcb *vmcb = svm->vmcb;
@@ -70,7 +82,7 @@ void generic_svm_setup(struct svm_test_data *svm, void *guest_rip, void *guest_r
 	wrmsr(MSR_EFER, efer | EFER_SVME);
 	wrmsr(MSR_VM_HSAVE_PA, svm->save_area_gpa);
 
-	memset(vmcb, 0, sizeof(*vmcb));
+	clear_vmcb(vmcb);
 	asm volatile ("vmsave %0\n\t" : : "a" (vmcb_gpa) : "memory");
 	vmcb_set_seg(&save->es, get_es(), 0, -1U, data_seg_attr);
 	vmcb_set_seg(&save->cs, get_cs(), 0, -1U, code_seg_attr);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux