lkml.org 
[lkml]   [2022]   [Oct]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH v12 45/46] KVM: selftests: hyperv_svm_test: Introduce L2 TLB flush test
    On Fri, Oct 21, 2022, Vitaly Kuznetsov wrote:
    > Enable Hyper-V L2 TLB flush and check that Hyper-V TLB flush hypercalls
    > from L2 don't exit to L1 unless 'TlbLockCount' is set in the Partition
    > assist page.
    >
    > Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
    > ---
    > .../selftests/kvm/include/x86_64/svm.h | 4 ++
    > .../selftests/kvm/x86_64/hyperv_svm_test.c | 61 +++++++++++++++++--
    > 2 files changed, 60 insertions(+), 5 deletions(-)
    >
    > diff --git a/tools/testing/selftests/kvm/include/x86_64/svm.h b/tools/testing/selftests/kvm/include/x86_64/svm.h
    > index 483e6ae12f69..4803e1056055 100644
    > --- a/tools/testing/selftests/kvm/include/x86_64/svm.h
    > +++ b/tools/testing/selftests/kvm/include/x86_64/svm.h
    > @@ -76,6 +76,10 @@ struct hv_vmcb_enlightenments {
    > */
    > #define HV_VMCB_NESTED_ENLIGHTENMENTS (1U << 31)
    >
    > +/* Synthetic VM-Exit */
    > +#define HV_SVM_EXITCODE_ENL 0xf0000000
    > +#define HV_SVM_ENL_EXITCODE_TRAP_AFTER_FLUSH (1)
    > +
    > struct __attribute__ ((__packed__)) vmcb_control_area {
    > u32 intercept_cr;
    > u32 intercept_dr;
    > diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c b/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c
    > index 1c3fc38b4f15..edb779615a79 100644
    > --- a/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c
    > +++ b/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c
    > @@ -25,6 +25,8 @@
    >
    > void l2_guest_code(void)
    > {
    > + u64 unused;
    > +
    > GUEST_SYNC(3);
    > /* Exit to L1 */
    > vmmcall();
    > @@ -38,11 +40,30 @@ void l2_guest_code(void)
    >
    > GUEST_SYNC(5);
    >
    > + /* L2 TLB flush tests */
    > + hyperv_hypercall(HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE |
    > + HV_HYPERCALL_FAST_BIT, 0x0,
    > + HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES |
    > + HV_FLUSH_ALL_PROCESSORS);
    > + rdmsr(MSR_FS_BASE);

    Why doesn't the SVM test need to clobber GPRs?

    > + /*
    > + * Note: hypercall status (RAX) is not preserved correctly by L1 after
    > + * synthetic vmexit, use unchecked version.
    > + */
    > + __hyperv_hypercall(HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE |
    > + HV_HYPERCALL_FAST_BIT, 0x0,
    > + HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES |
    > + HV_FLUSH_ALL_PROCESSORS, &unused);
    > + /* Make sure we're not issuing Hyper-V TLB flush call again */
    > + __asm__ __volatile__ ("mov $0xdeadbeef, %rcx");

    Heh, and a patch to vmmcall() itself "safe"...

    > +
    > /* Done, exit to L1 and never come back. */
    > vmmcall();
    > }

    \
     
     \ /
      Last update: 2022-10-27 00:24    [W:4.030 / U:0.860 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site