ia64/xen-unstable

changeset 8464:02cfa3beabba

Avoid xen crash if there is no VMX support. If a platform
doesn't support VMX, creating VMX domain will crash xen
HV.

Signed-off-by: Xin Li <xin.b.li@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Dec 30 17:07:34 2005 +0100 (2005-12-30)
parents 4299f983e8fe
children db510cf1e6f6
files tools/libxc/xc_vmx_build.c tools/python/xen/xend/image.py xen/arch/x86/domain.c
line diff
     1.1 --- a/tools/libxc/xc_vmx_build.c	Fri Dec 30 17:02:30 2005 +0100
     1.2 +++ b/tools/libxc/xc_vmx_build.c	Fri Dec 30 17:07:34 2005 +0100
     1.3 @@ -574,29 +574,6 @@ static int setup_guest(int xc_handle,
     1.4      return -1;
     1.5  }
     1.6  
     1.7 -#define VMX_FEATURE_FLAG 0x20
     1.8 -
     1.9 -static int vmx_identify(void)
    1.10 -{
    1.11 -    int eax, ecx;
    1.12 -
    1.13 -    __asm__ __volatile__ (
    1.14 -#if defined(__i386__)
    1.15 -                          "push %%ebx; cpuid; pop %%ebx"
    1.16 -#elif defined(__x86_64__)
    1.17 -                          "push %%rbx; cpuid; pop %%rbx"
    1.18 -#endif
    1.19 -                          : "=a" (eax), "=c" (ecx)
    1.20 -                          : "0" (1)
    1.21 -                          : "dx");
    1.22 -
    1.23 -    if (!(ecx & VMX_FEATURE_FLAG)) {
    1.24 -        return -1;
    1.25 -    }
    1.26 -
    1.27 -    return 0;
    1.28 -}
    1.29 -
    1.30  int xc_vmx_build(int xc_handle,
    1.31                   uint32_t domid,
    1.32                   int memsize,
    1.33 @@ -613,10 +590,18 @@ int xc_vmx_build(int xc_handle,
    1.34      unsigned long nr_pages;
    1.35      char         *image = NULL;
    1.36      unsigned long image_size;
    1.37 +    xen_capabilities_info_t xen_caps;
    1.38  
    1.39 -    if ( vmx_identify() < 0 )
    1.40 +    if ( (rc = xc_version(xc_handle, XENVER_capabilities, &xen_caps)) != 0 )
    1.41      {
    1.42 -        PERROR("CPU doesn't support VMX Extensions");
    1.43 +        PERROR("Failed to get xen version info");
    1.44 +        goto error_out;
    1.45 +    }
    1.46 +
    1.47 +    if ( !strstr(xen_caps, "hvm") )
    1.48 +    {
    1.49 +        PERROR("CPU doesn't support VMX Extensions or "
    1.50 +               "CPU VMX Extensions are not turned on");
    1.51          goto error_out;
    1.52      }
    1.53  
     2.1 --- a/tools/python/xen/xend/image.py	Fri Dec 30 17:02:30 2005 +0100
     2.2 +++ b/tools/python/xen/xend/image.py	Fri Dec 30 17:07:34 2005 +0100
     2.3 @@ -189,6 +189,10 @@ class VmxImageHandler(ImageHandler):
     2.4      def configure(self, imageConfig, deviceConfig):
     2.5          ImageHandler.configure(self, imageConfig, deviceConfig)
     2.6  
     2.7 +        info = xc.xeninfo()
     2.8 +        if not 'hvm' in info['xen_caps']:
     2.9 +            raise VmError("vmx: not an Intel VT platform, we stop creating!")
    2.10 +
    2.11          self.dmargs = self.parseDeviceModelArgs(imageConfig, deviceConfig)
    2.12          self.device_model = sxp.child_value(imageConfig, 'device_model')
    2.13          if not self.device_model:
     3.1 --- a/xen/arch/x86/domain.c	Fri Dec 30 17:02:30 2005 +0100
     3.2 +++ b/xen/arch/x86/domain.c	Fri Dec 30 17:07:34 2005 +0100
     3.3 @@ -35,7 +35,6 @@
     3.4  #include <xen/console.h>
     3.5  #include <xen/elf.h>
     3.6  #include <asm/vmx.h>
     3.7 -#include <asm/vmx_vmcs.h>
     3.8  #include <asm/msr.h>
     3.9  #include <asm/physdev.h>
    3.10  #include <xen/kernel.h>
    3.11 @@ -348,6 +347,8 @@ int arch_set_info_guest(
    3.12               ((c->user_regs.ss & 3) == 0) )
    3.13              return -EINVAL;
    3.14      }
    3.15 +    else if ( !hvm_enabled )
    3.16 +        return -EINVAL;
    3.17  
    3.18      clear_bit(_VCPUF_fpu_initialised, &v->vcpu_flags);
    3.19      if ( c->flags & VGCF_I387_VALID )