win-pvdrivers

changeset 954:da0e40d12a9c 0.11.0.323

Determine xen version and skip initial ballooning if too old
author James Harper <james.harper@bendigoit.com.au>
date Thu Nov 10 21:05:45 2011 +1100 (2011-11-10)
parents cc8651af4e45
children 8fc299076054
files xenpci/memory.c xenpci/xenpci.c xenpci/xenpci.h
line diff
     1.1 --- a/xenpci/memory.c	Thu Nov 10 21:04:53 2011 +1100
     1.2 +++ b/xenpci/memory.c	Thu Nov 10 21:05:45 2011 +1100
     1.3 @@ -1,3 +1,22 @@
     1.4 +/*
     1.5 +PV Drivers for Windows Xen HVM Domains
     1.6 +Copyright (C) 2011 James Harper
     1.7 +
     1.8 +This program is free software; you can redistribute it and/or
     1.9 +modify it under the terms of the GNU General Public License
    1.10 +as published by the Free Software Foundation; either version 2
    1.11 +of the License, or (at your option) any later version.
    1.12 +
    1.13 +This program is distributed in the hope that it will be useful,
    1.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.16 +GNU General Public License for more details.
    1.17 +
    1.18 +You should have received a copy of the GNU General Public License
    1.19 +along with this program; if not, write to the Free Software
    1.20 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    1.21 +*/
    1.22 +
    1.23  #include "xenpci.h"
    1.24  
    1.25  /* must be called at <= DISPATCH_LEVEL if hypercall_stubs == NULL */
    1.26 @@ -5,6 +24,9 @@
    1.27  #define XEN_SIGNATURE_LOWER 0x40000000
    1.28  #define XEN_SIGNATURE_UPPER 0x4000FFFF
    1.29  
    1.30 +USHORT xen_version_major = (USHORT)-1;
    1.31 +USHORT xen_version_minor = (USHORT)-1;
    1.32 +
    1.33  PVOID
    1.34  hvm_get_hypercall_stubs()
    1.35  {
    1.36 @@ -23,22 +45,27 @@ hvm_get_hypercall_stubs()
    1.37      *(ULONG*)(xensig + 4) = cpuid_output[2];
    1.38      *(ULONG*)(xensig + 8) = cpuid_output[3];
    1.39      xensig[12] = '\0';
    1.40 -    KdPrint((__DRIVER_NAME "     base = 0x%08x, Xen Signature = %s, EAX = 0x%08x\n", base, xensig, cpuid_output[0]));
    1.41 +    FUNCTION_MSG("base = 0x%08x, Xen Signature = %s, EAX = 0x%08x\n", base, xensig, cpuid_output[0]);
    1.42      if (!strncmp("XenVMMXenVMM", xensig, 12) && ((cpuid_output[0] - base) >= 2))
    1.43        break;
    1.44    }
    1.45    if (base > XEN_SIGNATURE_UPPER)
    1.46    {
    1.47 -    KdPrint((__DRIVER_NAME "     Cannot find Xen signature\n"));
    1.48 +    FUNCTION_MSG("Cannot find Xen signature\n");
    1.49      return NULL;
    1.50    }
    1.51  
    1.52 +  __cpuid(cpuid_output, base + 1);
    1.53 +  xen_version_major = (USHORT)(cpuid_output[0] >> 16);
    1.54 +  xen_version_minor = (USHORT)(cpuid_output[0] & 0xFFFF);
    1.55 +  FUNCTION_MSG("Xen Version %d.%d\n", xen_version_major, xen_version_minor);
    1.56 +
    1.57    __cpuid(cpuid_output, base + 2);
    1.58    pages = cpuid_output[0];
    1.59    msr = cpuid_output[1];
    1.60  
    1.61    hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
    1.62 -  KdPrint((__DRIVER_NAME "     Hypercall area at %p\n", hypercall_stubs));
    1.63 +  FUNCTION_MSG("Hypercall area at %p\n", hypercall_stubs);
    1.64  
    1.65    if (!hypercall_stubs)
    1.66      return NULL;
     2.1 --- a/xenpci/xenpci.c	Thu Nov 10 21:04:53 2011 +1100
     2.2 +++ b/xenpci/xenpci.c	Thu Nov 10 21:05:45 2011 +1100
     2.3 @@ -595,6 +595,14 @@ XenPci_InitialBalloonDown()
     2.4    if (!hypercall_stubs)
     2.5    {
     2.6      KdPrint((__DRIVER_NAME "     Failed to copy hypercall stubs. Maybe not running under Xen?\n"));
     2.7 +    FUNCTION_EXIT();
     2.8 +    return NULL;
     2.9 +  }
    2.10 +  if (xen_version_major < 4)
    2.11 +  {
    2.12 +    FUNCTION_MSG("No support for PoD. Cannot do initial balloon down.\n");
    2.13 +    FUNCTION_MSG("Expect a crash if maxmem is set much larger than memory.\n");
    2.14 +    FUNCTION_EXIT();
    2.15      return NULL;
    2.16    }
    2.17    ret = _HYPERVISOR_memory_op(hypercall_stubs, XENMEM_maximum_reservation, &domid);
     3.1 --- a/xenpci/xenpci.h	Thu Nov 10 21:04:53 2011 +1100
     3.2 +++ b/xenpci/xenpci.h	Thu Nov 10 21:05:45 2011 +1100
     3.3 @@ -81,6 +81,8 @@ DEFINE_GUID( GUID_XENPCI_DEVCLASS, 0xC82
     3.4  #define BALLOON_UNIT_PAGES ((BALLOON_UNITS_KB << 10) >> PAGE_SHIFT)
     3.5  
     3.6  extern ULONG qemu_protocol_version;
     3.7 +extern USHORT xen_version_major;
     3.8 +extern USHORT xen_version_minor;
     3.9  
    3.10  typedef struct _ev_action_t {
    3.11    PXEN_EVTCHN_SERVICE_ROUTINE ServiceRoutine;