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

Re: [Xen-devel] [PATCH v4 2/7] x86/hyperv: setup hypercall page


  • To: Jan Beulich <jbeulich@xxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • From: Michael Kelley <mikelley@xxxxxxxxxxxxx>
  • Date: Thu, 23 Jan 2020 15:20:56 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=D8/LivvNoGoUdHMTsMWP6Fml+/K1S6wqN0qc1aVpgCk=; b=DcLShrCzySYlFG8MRmogHBocRDnouRgvzyp00FaL4bbK6CpRC3CZtDE/Q5YVU/mP0EdS96GzL7JjaJ0FWC0W2JVKCEggq34VS1nqH8jFcPp1XwdRt2sRN4zi6LeLB/r1mW21Ep5qV/mn1z68MKTsrFyUQ3YkPKyelY1LHfgvlG1CbIjeRXO1n4tyEzTWzr/3YZ81SHoSZog+FGUg5E/uAnv0K+uuZ1exj+6gQMe7LyPG4cDwimnqpkjjuA1xZnqweySN5Tz73exmxn/owOvip/47JrkuDqdYi9fQnanDQzPbRoR/4AgPdN26GUSYOw1rjiWjdG5qzbpusX1TSt2r9A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mLwt+4v+lycYdOoKn36ICC66rTgCc7kMJHcKVf5Bmak55+T/ZDnSjDlWfryHlfe9j7Yc44tmub9eOiixOTEZexHpU4CKwUZ5s/8jU49nZXnN4rtRPJ4uvPmWkXEqWsRfPLyHmu54FWeHS/SkJEp4eS4HdcHh/Npp8ohIyzuzODC+Z0etMuQRrBKStV7fGu+lyhC9ZHL2Qv2O6uZZowQcIrZZ9zHtmfnA8r+D+1Dn0QsLo65yN74chnH7/11F9tSwrDSoFODlbU7LleDF5oHHOIhHyvzL21Zfyzrx8TkTV2l+SP5qYueYYpP7C0NoriQ8n/sNxQN8Q3rE58V+xhMJ0A==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=mikelley@xxxxxxxxxxxxx;
  • Cc: Wei Liu <liuwe@xxxxxxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Paul Durrant <pdurrant@xxxxxxxxxx>, Xen Development List <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Thu, 23 Jan 2020 15:21:14 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=True; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Owner=mikelley@xxxxxxxxxxxxxxxxxxx; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2020-01-23T15:20:54.5877868Z; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=General; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Application=Microsoft Azure Information Protection; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=08f24227-399e-40c8-8a7c-b6e0b2ae4568; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Extended_MSFT_Method=Automatic
  • Thread-index: AQHV0WHc3YI15L4ktUefA+4TX5s0hKf4GveAgABBBeA=
  • Thread-topic: [PATCH v4 2/7] x86/hyperv: setup hypercall page

From: Jan Beulich <jbeulich@xxxxxxxx> Sent: Thursday, January 23, 2020 3:19 AM
> 
> On 22.01.2020 21:23, Wei Liu wrote:
> > --- a/xen/arch/x86/e820.c
> > +++ b/xen/arch/x86/e820.c
> > @@ -36,6 +36,22 @@ boolean_param("e820-verbose", e820_verbose);
> >  struct e820map e820;
> >  struct e820map __initdata e820_raw;
> >
> > +static unsigned int find_phys_addr_bits(void)
> > +{
> > +    uint32_t eax;
> > +    unsigned int phys_bits = 36;
> > +
> > +    eax = cpuid_eax(0x80000000);
> > +    if ( (eax >> 16) == 0x8000 && eax >= 0x80000008 )
> > +    {
> > +        phys_bits = (uint8_t)cpuid_eax(0x80000008);
> > +        if ( phys_bits > PADDR_BITS )
> > +            phys_bits = PADDR_BITS;
> > +    }
> > +
> > +    return phys_bits;
> > +}
> 
> Instead of this, how about pulling further ahead the call to
> early_cpu_init() in setup.c? (Otherwise the function wants to
> be __init at least.)
> 
> > @@ -357,6 +373,21 @@ static unsigned long __init find_max_pfn(void)
> >              max_pfn = end;
> >      }
> >
> > +#ifdef CONFIG_HYPERV_GUEST
> > +    {
> > +   /*
> > +    * We reserve the top-most page for hypercall page. Adjust
> > +    * max_pfn if necessary.
> > +    */
> > +        unsigned int phys_bits = find_phys_addr_bits();
> > +        unsigned long hcall_pfn =
> > +          ((1ull << phys_bits) - 1) >> PAGE_SHIFT;
> > +
> > +        if ( max_pfn >= hcall_pfn )
> > +          max_pfn = hcall_pfn - 1;
> > +    }
> > +#endif
> 
> This wants abstracting away: There shouldn't be Hyper-V specific
> code in here if at all possible, and the adjustment also shouldn't
> be made unless actually running on Hyper-V.
> 
> > --- a/xen/arch/x86/guest/hyperv/hyperv.c
> > +++ b/xen/arch/x86/guest/hyperv/hyperv.c
> > @@ -18,17 +18,27 @@
> >   *
> >   * Copyright (c) 2019 Microsoft.
> >   */
> > +#include <xen/version.h>
> >  #include <xen/init.h>
> 
> Please sort alphabetically.
> 
> > +#include <asm/fixmap.h>
> >  #include <asm/guest.h>
> >  #include <asm/guest/hyperv-tlfs.h>
> > +#include <asm/processor.h>
> >
> >  struct ms_hyperv_info __read_mostly ms_hyperv;
> >
> > -static const struct hypervisor_ops ops = {
> > -    .name = "Hyper-V",
> > -};
> > +static uint64_t generate_guest_id(void)
> > +{
> > +    uint64_t id = 0;
> 
> Pointless initializer.
> 
> > +    id = (uint64_t)HV_XEN_VENDOR_ID << 48;
> > +    id |= (xen_major_version() << 16) | xen_minor_version();
> > +
> > +    return id;
> > +}
> >
> > +static const struct hypervisor_ops ops;
> >  const struct hypervisor_ops *__init hyperv_probe(void)
> 
> Blank line between these two please (if you can't get away without
> this declaration in the first place).
> 
> > @@ -72,6 +82,43 @@ const struct hypervisor_ops *__init hyperv_probe(void)
> >      return &ops;
> >  }
> >
> > +static void __init setup_hypercall_page(void)
> > +{
> > +    union hv_x64_msr_hypercall_contents hypercall_msr;
> > +    union hv_guest_os_id guest_id;
> > +    unsigned long mfn;
> > +
> > +    rdmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id.raw);
> > +    if ( !guest_id.raw )
> > +    {
> > +        guest_id.raw = generate_guest_id();
> > +        wrmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id.raw);
> > +    }
> > +
> > +    rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
> > +    if ( !hypercall_msr.enable )
> > +    {
> > +        mfn = ((1ull << paddr_bits) - 1) >> HV_HYP_PAGE_SHIFT;
> 
> Along the lines of the abstracting-away request above: How is
> anyone to notice what else needs changing if it is decided
> that this page gets moved elsewhere?
> 
> > +        hypercall_msr.enable = 1;
> > +        hypercall_msr.guest_physical_address = mfn;
> > +        wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
> 
> So on Hyper-V the hypervisor magically populates this page as
> a side effect of the MSR write?
> 

Yes, that's exactly what happens. :-)  Hyper-V takes the guest
physical address and remaps it to a different physical page that
Hyper-V has set up with whatever is needed to execute the hypercall
sequence. The original physical page corresponding to the guest physical
address is not modified, but it remains unused and inaccessible to the
guest.  When/if the MSR is written again with the enable flag set to 0,
the mapping is flipped back, and the original physical page, with its
original contents, reappears. There are a few other pages with this
same behavior.  The Hyper-V TLFS refers to these "GPA Overlay
Pages".  See Section 5.2.1 of the TLFS.

Michael
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.