LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Siddharth Chandrasekaran <sidcha@amazon.de>
To: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: <kvm@vger.kernel.org>, Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 4/4] KVM: selftests: Test access to XMM fast hypercalls
Date: Fri, 30 Jul 2021 17:01:32 +0200	[thread overview]
Message-ID: <20210730150131.GA31075@u366d62d47e3651.ant.amazon.com> (raw)
In-Reply-To: <878s1namap.fsf@vitty.brq.redhat.com>

On Fri, Jul 30, 2021 at 04:50:06PM +0200, Vitaly Kuznetsov wrote:
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
> 
> 
> 
> Siddharth Chandrasekaran <sidcha@amazon.de> writes:
> 
> > On Fri, Jul 30, 2021 at 02:26:25PM +0200, Vitaly Kuznetsov wrote:
> >> HYPERV_CPUID_FEATURES.EDX and an 'XMM fast' hypercall is issued.
> >>
> >> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> >> ---
> >>  .../selftests/kvm/include/x86_64/hyperv.h     |  5 ++-
> >>  .../selftests/kvm/x86_64/hyperv_features.c    | 41 +++++++++++++++++--
> >>  2 files changed, 42 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/tools/testing/selftests/kvm/include/x86_64/hyperv.h b/tools/testing/selftests/kvm/include/x86_64/hyperv.h
> >> index 412eaee7884a..b66910702c0a 100644
> >> --- a/tools/testing/selftests/kvm/include/x86_64/hyperv.h
> >> +++ b/tools/testing/selftests/kvm/include/x86_64/hyperv.h
> >> @@ -117,7 +117,7 @@
> >>  #define HV_X64_GUEST_DEBUGGING_AVAILABLE               BIT(1)
> >>  #define HV_X64_PERF_MONITOR_AVAILABLE                  BIT(2)
> >>  #define HV_X64_CPU_DYNAMIC_PARTITIONING_AVAILABLE      BIT(3)
> >> -#define HV_X64_HYPERCALL_PARAMS_XMM_AVAILABLE          BIT(4)
> >> +#define HV_X64_HYPERCALL_XMM_INPUT_AVAILABLE           BIT(4)
> >>  #define HV_X64_GUEST_IDLE_STATE_AVAILABLE              BIT(5)
> >>  #define HV_FEATURE_FREQUENCY_MSRS_AVAILABLE            BIT(8)
> >>  #define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE           BIT(10)
> >> @@ -182,4 +182,7 @@
> >>  #define HV_STATUS_INVALID_CONNECTION_ID                18
> >>  #define HV_STATUS_INSUFFICIENT_BUFFERS         19
> >>
> >> +/* hypercall options */
> >> +#define HV_HYPERCALL_FAST_BIT          BIT(16)
> >> +
> >>  #endif /* !SELFTEST_KVM_HYPERV_H */
> >> diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_features.c b/tools/testing/selftests/kvm/x86_64/hyperv_features.c
> >> index af27c7e829c1..91d88aaa9899 100644
> >> --- a/tools/testing/selftests/kvm/x86_64/hyperv_features.c
> >> +++ b/tools/testing/selftests/kvm/x86_64/hyperv_features.c
> >> @@ -47,6 +47,7 @@ static void do_wrmsr(u32 idx, u64 val)
> >>  }
> >>
> >>  static int nr_gp;
> >> +static int nr_ud;
> >>
> >>  static inline u64 hypercall(u64 control, vm_vaddr_t input_address,
> >>                             vm_vaddr_t output_address)
> >> @@ -80,6 +81,12 @@ static void guest_gp_handler(struct ex_regs *regs)
> >>                 regs->rip = (uint64_t)&wrmsr_end;
> >>  }
> >>
> >> +static void guest_ud_handler(struct ex_regs *regs)
> >> +{
> >> +       nr_ud++;
> >> +       regs->rip += 3;
> >> +}
> >> +
> >>  struct msr_data {
> >>         uint32_t idx;
> >>         bool available;
> >> @@ -90,6 +97,7 @@ struct msr_data {
> >>  struct hcall_data {
> >>         uint64_t control;
> >>         uint64_t expect;
> >> +       bool ud_expected;
> >>  };
> >>
> >>  static void guest_msr(struct msr_data *msr)
> >> @@ -117,13 +125,26 @@ static void guest_msr(struct msr_data *msr)
> >>  static void guest_hcall(vm_vaddr_t pgs_gpa, struct hcall_data *hcall)
> >>  {
> >>         int i = 0;
> >> +       u64 res, input, output;
> >>
> >>         wrmsr(HV_X64_MSR_GUEST_OS_ID, LINUX_OS_ID);
> >>         wrmsr(HV_X64_MSR_HYPERCALL, pgs_gpa);
> >>
> >>         while (hcall->control) {
> >> -               GUEST_ASSERT(hypercall(hcall->control, pgs_gpa,
> >> -                                      pgs_gpa + 4096) == hcall->expect);
> >> +               nr_ud = 0;
> >> +               if (!(hcall->control & HV_HYPERCALL_FAST_BIT)) {
> >> +                       input = pgs_gpa;
> >> +                       output = pgs_gpa + 4096;
> >> +               } else {
> >> +                       input = output = 0;
> >> +               }
> >> +
> >> +               res = hypercall(hcall->control, input, output);
> >> +               if (hcall->ud_expected)
> >> +                       GUEST_ASSERT(nr_ud == 1);
> >
> > Should we also do WRITE_ONCE(nr_ur, 0) here?
> 
> It could probably make sense to replace 'nr_ud = 0' above with this so
> compiler doesn't screw us up one day..
> 
> > or perhaps pass the the
> > expected value of nr_ud + 1 in hcall->ud_expected from caller and do,
> >
> >     if (hcall->ud_expected)
> >         GUEST_ASSERT(nr_ud == hcall->ud_expected);
> >
> > This way there can be other test that can also expect a UD.
> 
> My idea was that we don't really need to count #UDs for now, just
> checking the fact that it happened is OK so I reset nr_ud before doing
> the hypercall and check it after. It is possible to add more tests with
> 'ud_expected' this way.

Oops, my bad, didn't notice that you were resetting nr_ud before
hypercall(). Thanks for clarifying.

Reviewed-by: Siddharth Chandrasekaran <sidcha@amazon.de>

~ Sid.

> >
> >> +               else
> >> +                       GUEST_ASSERT(res == hcall->expect);
> >> +
> >>                 GUEST_SYNC(i++);
> >>         }
> >>
> >> @@ -552,8 +573,18 @@ static void guest_test_hcalls_access(struct kvm_vm *vm, struct hcall_data *hcall
> >>                         recomm.ebx = 0xfff;
> >>                         hcall->expect = HV_STATUS_SUCCESS;
> >>                         break;
> >> -
> >>                 case 17:
> >> +                       /* XMM fast hypercall */
> >> +                       hcall->control = HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE | HV_HYPERCALL_FAST_BIT;
> >> +                       hcall->ud_expected = true;
> >> +                       break;
> >> +               case 18:
> >> +                       feat.edx |= HV_X64_HYPERCALL_XMM_INPUT_AVAILABLE;
> >> +                       hcall->ud_expected = false;
> >> +                       hcall->expect = HV_STATUS_SUCCESS;
> >> +                       break;
> >> +
> >> +               case 19:
> >>                         /* END */
> >>                         hcall->control = 0;
> >>                         break;
> >> @@ -625,6 +656,10 @@ int main(void)
> >>         /* Test hypercalls */
> >>         vm = vm_create_default(VCPU_ID, 0, guest_hcall);
> >>
> >> +       vm_init_descriptor_tables(vm);
> >> +       vcpu_init_descriptor_tables(vm, VCPU_ID);
> >> +       vm_install_exception_handler(vm, UD_VECTOR, guest_ud_handler);
> >> +
> >>         /* Hypercall input/output */
> >>         hcall_page = vm_vaddr_alloc_pages(vm, 2);
> >>         memset(addr_gva2hva(vm, hcall_page), 0x0, 2 * getpagesize());
> >> --
> >> 2.31.1
> >>
> >
> >
> >
> > Amazon Development Center Germany GmbH
> > Krausenstr. 38
> > 10117 Berlin
> > Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
> > Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
> > Sitz: Berlin
> > Ust-ID: DE 289 237 879
> >
> >
> >
> 
> --
> Vitaly
> 



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




  reply	other threads:[~2021-07-30 15:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-30 12:26 [PATCH 0/4] KVM: x86: hyper-v: Check if guest is allowed to use XMM registers for hypercall input Vitaly Kuznetsov
2021-07-30 12:26 ` [PATCH 1/4] KVM: x86: hyper-v: Check access to hypercall before reading XMM registers Vitaly Kuznetsov
2021-07-30 14:29   ` Siddharth Chandrasekaran
2021-07-30 12:26 ` [PATCH 2/4] KVM: x86: Introduce trace_kvm_hv_hypercall_done() Vitaly Kuznetsov
2021-07-30 14:30   ` Siddharth Chandrasekaran
2021-07-30 12:26 ` [PATCH 3/4] KVM: x86: hyper-v: Check if guest is allowed to use XMM registers for hypercall input Vitaly Kuznetsov
2021-07-30 14:30   ` Siddharth Chandrasekaran
2021-07-30 12:26 ` [PATCH 4/4] KVM: selftests: Test access to XMM fast hypercalls Vitaly Kuznetsov
2021-07-30 14:35   ` Siddharth Chandrasekaran
2021-07-30 14:50     ` Vitaly Kuznetsov
2021-07-30 15:01       ` Siddharth Chandrasekaran [this message]
2021-08-03 10:10       ` Paolo Bonzini
2021-08-03 10:10 ` [PATCH 0/4] KVM: x86: hyper-v: Check if guest is allowed to use XMM registers for hypercall input Paolo Bonzini
2021-08-03 10:17 ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210730150131.GA31075@u366d62d47e3651.ant.amazon.com \
    --to=sidcha@amazon.de \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --subject='Re: [PATCH 4/4] KVM: selftests: Test access to XMM fast hypercalls' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).