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

Re: [win-pv-devel] [PATCH 1/4] Re-populate hypercall page on resume from suspend/hibernate



> -----Original Message-----
> From: Paul Durrant [mailto:paul.durrant@xxxxxxxxxx]
> Sent: 07 November 2014 13:33
> To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
> Cc: Paul Durrant
> Subject: [PATCH 1/4] Re-populate hypercall page on resume from
> suspend/hibernate
> 
> Doing this has the side effect of latching the shared info page width,
> which is currently done when the callback via is set. When we move to a
> per-cpu event channel upcall then this side effect will be lost, so
> doing this makes sure that the shared info is still of the correct width.
> 
> Additionally in this patch the reporting of the Xen version is improved
> by using the XENVER hypercalls to get major, minor and extra version
> informattion. As part of that change, more headers have been copied in
> from Xen.
> 
> Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>

This patch is missing a file that I forgot to git add. I'll re-post.

  Paul

> ---
>  get_xen_headers.py     |   2 +
>  include/xen.h          |  26 ++++++++++++
>  include/xen/features.h | 112
> +++++++++++++++++++++++++++++++++++++++++++++++++
>  include/xen/version.h  |  96
> ++++++++++++++++++++++++++++++++++++++++++
>  src/xen/driver.c       |  20 +++++++++
>  src/xen/hypercall.c    |  66 ++++++++++++++++-------------
>  src/xenbus/fdo.c       |   2 +
>  src/xenbus/suspend.c   |   2 +
>  vs2012/xen/xen.vcxproj |   1 +
>  vs2013/xen/xen.vcxproj |   3 +-
>  10 files changed, 299 insertions(+), 31 deletions(-)
>  create mode 100644 include/xen/features.h
>  create mode 100644 include/xen/version.h
> 
> diff --git a/get_xen_headers.py b/get_xen_headers.py
> index 5ca5c93..ef1a2c8 100644
> --- a/get_xen_headers.py
> +++ b/get_xen_headers.py
> @@ -61,6 +61,8 @@ if __name__ == '__main__':
>      copy_file(working, 'public', '.', 'sched.h')
>      copy_file(working, 'public', '.', 'event_channel.h')
>      copy_file(working, 'public', '.', 'grant_table.h')
> +    copy_file(working, 'public', '.', 'version.h')
> +    copy_file(working, 'public', '.', 'features.h')
> 
>      copy_file(working, 'xen', '.', 'errno.h')
> 
> diff --git a/include/xen.h b/include/xen.h
> index 0039d7a..0dabc74 100644
> --- a/include/xen.h
> +++ b/include/xen.h
> @@ -44,6 +44,7 @@
>  #include <xen/sched.h>
>  #include <xen/hvm/params.h>
>  #include <xen/io/xs_wire.h>
> +#include <xen/version.h>
> 
>  #ifndef XEN_API
>  #define XEN_API __declspec(dllimport)
> @@ -56,6 +57,14 @@ XenTouch(
>      VOID
>      );
> 
> +// HYPERCALL
> +
> +XEN_API
> +VOID
> +HypercallPopulate(
> +    VOID
> +    );
> +
>  // HVM
> 
>  __checkReturn
> @@ -233,6 +242,23 @@ SchedYield(
>      VOID
>      );
> 
> +// XEN VERSION
> +
> +__checkReturn
> +XEN_API
> +NTSTATUS
> +XenVersion(
> +    OUT PULONG  Major,
> +    OUT PULONG  Minor
> +    );
> +
> +__checkReturn
> +XEN_API
> +NTSTATUS
> +XenVersionExtra(
> +    OUT PCHAR   Extra
> +    );
> +
>  // MODULE
> 
>  XEN_API
> diff --git a/include/xen/features.h b/include/xen/features.h
> new file mode 100644
> index 0000000..b7bf83f
> --- /dev/null
> +++ b/include/xen/features.h
> @@ -0,0 +1,112 @@
> +/*********************************************************
> *********************
> + * features.h
> + *
> + * Feature flags, reported by XENVER_get_features.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> copy
> + * of this software and associated documentation files (the "Software"), to
> + * deal in the Software without restriction, including without limitation the
> + * rights to use, copy, modify, merge, publish, distribute, sublicense, 
> and/or
> + * sell copies of the Software, and to permit persons to whom the Software
> is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
> EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
> OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> OTHER
> + * DEALINGS IN THE SOFTWARE.
> + *
> + * Copyright (c) 2006, Keir Fraser <keir@xxxxxxxxxxxxx>
> + */
> +
> +#ifndef __XEN_PUBLIC_FEATURES_H__
> +#define __XEN_PUBLIC_FEATURES_H__
> +
> +/*
> + * `incontents 200 elfnotes_features XEN_ELFNOTE_FEATURES
> + *
> + * The list of all the features the guest supports. They are set by
> + * parsing the XEN_ELFNOTE_FEATURES and
> XEN_ELFNOTE_SUPPORTED_FEATURES
> + * string. The format is the  feature names (as given here without the
> + * "XENFEAT_" prefix) separated by '|' characters.
> + * If a feature is required for the kernel to function then the feature name
> + * must be preceded by a '!' character.
> + *
> + * Note that if XEN_ELFNOTE_SUPPORTED_FEATURES is used, then in the
> + * XENFEAT_dom0 MUST be set if the guest is to be booted as dom0,
> + */
> +
> +/*
> + * If set, the guest does not need to write-protect its pagetables, and can
> + * update them via direct writes.
> + */
> +#define XENFEAT_writable_page_tables       0
> +
> +/*
> + * If set, the guest does not need to write-protect its segment descriptor
> + * tables, and can update them via direct writes.
> + */
> +#define XENFEAT_writable_descriptor_tables 1
> +
> +/*
> + * If set, translation between the guest's 'pseudo-physical' address space
> + * and the host's machine address space are handled by the hypervisor. In
> this
> + * mode the guest does not need to perform phys-to/from-machine
> translations
> + * when performing page table operations.
> + */
> +#define XENFEAT_auto_translated_physmap    2
> +
> +/* If set, the guest is running in supervisor mode (e.g., x86 ring 0). */
> +#define XENFEAT_supervisor_mode_kernel     3
> +
> +/*
> + * If set, the guest does not need to allocate x86 PAE page directories
> + * below 4GB. This flag is usually implied by auto_translated_physmap.
> + */
> +#define XENFEAT_pae_pgdir_above_4gb        4
> +
> +/* x86: Does this Xen host support the MMU_PT_UPDATE_PRESERVE_AD
> hypercall? */
> +#define XENFEAT_mmu_pt_update_preserve_ad  5
> +
> +/* x86: Does this Xen host support the MMU_{CLEAR,COPY}_PAGE
> hypercall? */
> +#define XENFEAT_highmem_assist             6
> +
> +/*
> + * If set, GNTTABOP_map_grant_ref honors flags to be placed into guest
> kernel
> + * available pte bits.
> + */
> +#define XENFEAT_gnttab_map_avail_bits      7
> +
> +/* x86: Does this Xen host support the HVM callback vector type? */
> +#define XENFEAT_hvm_callback_vector        8
> +
> +/* x86: pvclock algorithm is safe to use on HVM */
> +#define XENFEAT_hvm_safe_pvclock           9
> +
> +/* x86: pirq can be used by HVM guests */
> +#define XENFEAT_hvm_pirqs                 10
> +
> +/* operation as Dom0 is supported */
> +#define XENFEAT_dom0                      11
> +
> +/* Xen also maps grant references at pfn = mfn */
> +#define XENFEAT_grant_map_identity        12
> +
> +#define XENFEAT_NR_SUBMAPS 1
> +
> +#endif /* __XEN_PUBLIC_FEATURES_H__ */
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * tab-width: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
> diff --git a/include/xen/version.h b/include/xen/version.h
> new file mode 100644
> index 0000000..44f26b0
> --- /dev/null
> +++ b/include/xen/version.h
> @@ -0,0 +1,96 @@
> +/*********************************************************
> *********************
> + * version.h
> + *
> + * Xen version, type, and compile information.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> copy
> + * of this software and associated documentation files (the "Software"), to
> + * deal in the Software without restriction, including without limitation the
> + * rights to use, copy, modify, merge, publish, distribute, sublicense, 
> and/or
> + * sell copies of the Software, and to permit persons to whom the Software
> is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
> EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
> OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> OTHER
> + * DEALINGS IN THE SOFTWARE.
> + *
> + * Copyright (c) 2005, Nguyen Anh Quynh <aquynh@xxxxxxxxx>
> + * Copyright (c) 2005, Keir Fraser <keir@xxxxxxxxxxxxx>
> + */
> +
> +#ifndef __XEN_PUBLIC_VERSION_H__
> +#define __XEN_PUBLIC_VERSION_H__
> +
> +#include "xen.h"
> +
> +/* NB. All ops return zero on success, except XENVER_{version,pagesize} */
> +
> +/* arg == NULL; returns major:minor (16:16). */
> +#define XENVER_version      0
> +
> +/* arg == xen_extraversion_t. */
> +#define XENVER_extraversion 1
> +typedef char xen_extraversion_t[16];
> +#define XEN_EXTRAVERSION_LEN (sizeof(xen_extraversion_t))
> +
> +/* arg == xen_compile_info_t. */
> +#define XENVER_compile_info 2
> +struct xen_compile_info {
> +    char compiler[64];
> +    char compile_by[16];
> +    char compile_domain[32];
> +    char compile_date[32];
> +};
> +typedef struct xen_compile_info xen_compile_info_t;
> +
> +#define XENVER_capabilities 3
> +typedef char xen_capabilities_info_t[1024];
> +#define XEN_CAPABILITIES_INFO_LEN (sizeof(xen_capabilities_info_t))
> +
> +#define XENVER_changeset 4
> +typedef char xen_changeset_info_t[64];
> +#define XEN_CHANGESET_INFO_LEN (sizeof(xen_changeset_info_t))
> +
> +#define XENVER_platform_parameters 5
> +struct xen_platform_parameters {
> +    xen_ulong_t virt_start;
> +};
> +typedef struct xen_platform_parameters xen_platform_parameters_t;
> +
> +#define XENVER_get_features 6
> +struct xen_feature_info {
> +    unsigned int submap_idx;    /* IN: which 32-bit submap to return */
> +    uint32_t     submap;        /* OUT: 32-bit submap */
> +};
> +typedef struct xen_feature_info xen_feature_info_t;
> +
> +/* Declares the features reported by XENVER_get_features. */
> +#include "features.h"
> +
> +/* arg == NULL; returns host memory page size. */
> +#define XENVER_pagesize 7
> +
> +/* arg == xen_domain_handle_t. */
> +#define XENVER_guest_handle 8
> +
> +#define XENVER_commandline 9
> +typedef char xen_commandline_t[1024];
> +
> +#endif /* __XEN_PUBLIC_VERSION_H__ */
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * tab-width: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
> diff --git a/src/xen/driver.c b/src/xen/driver.c
> index ba541b4..fce75aa 100644
> --- a/src/xen/driver.c
> +++ b/src/xen/driver.c
> @@ -59,6 +59,26 @@ XenTouch(
>      VOID
>      )
>  {
> +    static ULONG    Reference;
> +    ULONG           Major;
> +    ULONG           Minor;
> +    CHAR            Extra[XEN_EXTRAVERSION_LEN];
> +    NTSTATUS        status;
> +
> +    if (Reference++ != 0)
> +        return;
> +
> +    status = XenVersion(&Major, &Minor);
> +    ASSERT(NT_SUCCESS(status));
> +
> +    status = XenVersionExtra(Extra);
> +    ASSERT(NT_SUCCESS(status));
> +
> +    LogPrintf(LOG_LEVEL_INFO,
> +              "XEN: %u.%u%s\n",
> +              Major,
> +              Minor,
> +              Extra);
>  }
> 
>  static VOID
> diff --git a/src/xen/hypercall.c b/src/xen/hypercall.c
> index 07eb41a..717b8c2 100644
> --- a/src/xen/hypercall.c
> +++ b/src/xen/hypercall.c
> @@ -29,6 +29,9 @@
>   * SUCH DAMAGE.
>   */
> 
> +#undef  XEN_API
> +#define XEN_API __declspec(dllexport)
> +
>  #include <ntddk.h>
>  #include <xen.h>
>  #include <util.h>
> @@ -37,24 +40,41 @@
>  #include "dbg_print.h"
>  #include "assert.h"
> 
> -#define MAXIMUM_HYPERCALL_PFN_COUNT 2
> +#define MAXIMUM_HYPERCALL_PAGE_COUNT 2
> 
>  #pragma code_seg("hypercall")
>  __declspec(allocate("hypercall"))
> -static UCHAR        __Section[(MAXIMUM_HYPERCALL_PFN_COUNT + 1) *
> PAGE_SIZE];
> +static UCHAR        __Section[(MAXIMUM_HYPERCALL_PAGE_COUNT + 1) *
> PAGE_SIZE];
> 
>  static ULONG        XenBaseLeaf = 0x40000000;
> 
> -static USHORT       XenMajorVersion;
> -static USHORT       XenMinorVersion;
> -
> -static PFN_NUMBER   HypercallPfn[MAXIMUM_HYPERCALL_PFN_COUNT];
> -static ULONG        HypercallPfnCount;
> +static PHYSICAL_ADDRESS
> HypercallPage[MAXIMUM_HYPERCALL_PAGE_COUNT];
> +static ULONG            HypercallPageCount;
> 
>  typedef UCHAR           HYPERCALL_GATE[32];
>  typedef HYPERCALL_GATE  *PHYPERCALL_GATE;
> 
>  PHYPERCALL_GATE     Hypercall;
> +ULONG               HypercallMsr;
> +
> +XEN_API
> +VOID
> +HypercallPopulate(
> +    VOID
> +    )
> +{
> +    ULONG       Index;
> +
> +    for (Index = 0; Index < HypercallPageCount; Index++) {
> +        LogPrintf(LOG_LEVEL_INFO,
> +                  "XEN: HYPERCALL PAGE %d @ %08x.%08x\n",
> +                  Index,
> +                  HypercallPage[Index].HighPart,
> +                  HypercallPage[Index].LowPart);
> +
> +        __writemsr(HypercallMsr, HypercallPage[Index].QuadPart);
> +    }
> +}
> 
>  NTSTATUS
>  HypercallInitialize(
> @@ -66,7 +86,6 @@ HypercallInitialize(
>      ULONG       ECX = 'DEAD';
>      ULONG       EDX = 'DEAD';
>      ULONG       Index;
> -    ULONG       HypercallMsr;
>      NTSTATUS    status;
> 
>      status = STATUS_UNSUCCESSFUL;
> @@ -88,13 +107,6 @@ HypercallInitialize(
>              goto fail1;
>      }
> 
> -    __CpuId(XenBaseLeaf + 1, &EAX, NULL, NULL, NULL);
> -    XenMajorVersion = (USHORT)(EAX >> 16);
> -    XenMinorVersion = (USHORT)(EAX & 0xFFFF);
> -
> -    Info("XEN %d.%d\n", XenMajorVersion, XenMinorVersion);
> -    Info("INTERFACE 0x%08x\n", __XEN_INTERFACE_VERSION__);
> -
>      if ((ULONG_PTR)__Section & (PAGE_SIZE - 1))
>          Hypercall = (PVOID)(((ULONG_PTR)__Section + PAGE_SIZE - 1) &
> ~(PAGE_SIZE - 1));
>      else
> @@ -102,22 +114,16 @@ HypercallInitialize(
> 
>      ASSERT3U(((ULONG_PTR)Hypercall & (PAGE_SIZE - 1)), ==, 0);
> 
> -    for (Index = 0; Index < MAXIMUM_HYPERCALL_PFN_COUNT; Index++) {
> -        PHYSICAL_ADDRESS    PhysicalAddress;
> -
> -        PhysicalAddress = MmGetPhysicalAddress((PUCHAR)Hypercall + (Index
> << PAGE_SHIFT));
> -        HypercallPfn[Index] = (PFN_NUMBER)(PhysicalAddress.QuadPart >>
> PAGE_SHIFT);
> -    }
> +    for (Index = 0; Index < MAXIMUM_HYPERCALL_PAGE_COUNT; Index++)
> +        HypercallPage[Index] = MmGetPhysicalAddress((PUCHAR)Hypercall +
> +                                                    (Index << PAGE_SHIFT));
> 
>      __CpuId(XenBaseLeaf + 2, &EAX, &EBX, NULL, NULL);
> -    HypercallPfnCount = EAX;
> -    ASSERT(HypercallPfnCount <= MAXIMUM_HYPERCALL_PFN_COUNT);
> +    HypercallPageCount = EAX;
> +    ASSERT(HypercallPageCount <= MAXIMUM_HYPERCALL_PAGE_COUNT);
>      HypercallMsr = EBX;
> 
> -    for (Index = 0; Index < HypercallPfnCount; Index++) {
> -        Info("HypercallPfn[%d]: %p\n", Index, (PVOID)HypercallPfn[Index]);
> -        __writemsr(HypercallMsr, (ULONG64)HypercallPfn[Index] <<
> PAGE_SHIFT);
> -    }
> +    HypercallPopulate();
> 
>      return STATUS_SUCCESS;
> 
> @@ -177,8 +183,8 @@ HypercallTeardown(
> 
>      Hypercall = NULL;
> 
> -    for (Index = 0; Index < MAXIMUM_HYPERCALL_PFN_COUNT; Index++)
> -        HypercallPfn[Index] = 0;
> +    for (Index = 0; Index < MAXIMUM_HYPERCALL_PAGE_COUNT; Index++)
> +        HypercallPage[Index].QuadPart = 0;
> 
> -    HypercallPfnCount = 0;
> +    HypercallPageCount = 0;
>  }
> diff --git a/src/xenbus/fdo.c b/src/xenbus/fdo.c
> index 59442bd..215c997 100644
> --- a/src/xenbus/fdo.c
> +++ b/src/xenbus/fdo.c
> @@ -2186,6 +2186,8 @@ FdoS4ToS3(
> 
>      KeRaiseIrql(DISPATCH_LEVEL, &Irql);
> 
> +    HypercallPopulate();
> +
>      if (Fdo->UnplugInterface.Interface.Context != NULL)
>          XENFILT_UNPLUG(Replay, &Fdo->UnplugInterface);
> 
> diff --git a/src/xenbus/suspend.c b/src/xenbus/suspend.c
> index 6ab2bd2..de70e42 100644
> --- a/src/xenbus/suspend.c
> +++ b/src/xenbus/suspend.c
> @@ -173,6 +173,8 @@ SuspendTrigger(
> 
>          Context->Count++;
> 
> +        HypercallPopulate();
> +
>          if (Context->UnplugInterface.Interface.Context != NULL)
>              XENFILT_UNPLUG(Replay, &Context->UnplugInterface);
> 
> diff --git a/vs2012/xen/xen.vcxproj b/vs2012/xen/xen.vcxproj
> index eb54692..2f4d958 100644
> --- a/vs2012/xen/xen.vcxproj
> +++ b/vs2012/xen/xen.vcxproj
> @@ -88,6 +88,7 @@
>               <ClCompile Include="..\..\src\xen\event_channel.c" />
>               <ClCompile Include="..\..\src\xen\grant_table.c" />
>               <ClCompile Include="..\..\src\xen\hvm.c" />
> +             <ClCompile Include="..\..\src\xen\xen_version.c" />
>               <ClCompile Include="..\..\src\xen\hypercall.c" />
>               <ClCompile Include="..\..\src\xen\memory.c" />
>               <ClCompile Include="..\..\src\xen\sched.c" />
> diff --git a/vs2013/xen/xen.vcxproj b/vs2013/xen/xen.vcxproj
> index 490294c..81d50ea 100644
> --- a/vs2013/xen/xen.vcxproj
> +++ b/vs2013/xen/xen.vcxproj
> @@ -1,4 +1,4 @@
> -ï<?xml version="1.0" encoding="utf-8"?>
> +<?xml version="1.0" encoding="utf-8"?>
>  <Project DefaultTargets="Build" ToolsVersion="12.0"
> xmlns="http://schemas.microsoft.com/developer/msbuild/2003";>
>    <Import Project="..\configs.props" />
>    <PropertyGroup Label="Globals">
> @@ -128,6 +128,7 @@
>      <ClCompile Include="..\..\src\xen\event_channel.c" />
>      <ClCompile Include="..\..\src\xen\grant_table.c" />
>      <ClCompile Include="..\..\src\xen\hvm.c" />
> +    <ClCompile Include="..\..\src\xen\xen_version.c" />
>      <ClCompile Include="..\..\src\xen\hypercall.c" />
>      <ClCompile Include="..\..\src\xen\memory.c" />
>      <ClCompile Include="..\..\src\xen\sched.c" />
> --
> 2.1.1

_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel

 


Rackspace

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