Skip to contentSkip to conversation

Hyper-V guest interface support with small set of enlightenments

PATCH New Keir Fraser 1 participant 1 message Oct 13, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Hyper-V guest interface support with small set of enlightenments

A minimal implementation of the Viridian (Hyper-V) guest interface. The only enlightenments advertised and supported are vAPIC MSRs and long-spin-wait notifications. The set of enlightenments can easily be extended in future, as they are found to provide a performance win, and configured via an extended HVM_PARAM_VIRIDIAN hvm parameter.

tools/firmware/hvmloader/hvmloader.c +19 -13
diff -r e66cecb66b1e tools/firmware/hvmloader/hvmloader.c
@@ -101,30 +101,36 @@ asm (
 
 static enum { VGA_none, VGA_std, VGA_cirrus } virtual_vga = VGA_none;
 
-static void
-init_hypercalls(void)
+static void init_hypercalls(void)
 {
     uint32_t eax, ebx, ecx, edx;
     unsigned long i;
     char signature[13];
     xen_extraversion_t extraversion;
-
-    cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
-
-    *(uint32_t *)(signature + 0) = ebx;
-    *(uint32_t *)(signature + 4) = ecx;
-    *(uint32_t *)(signature + 8) = edx;
-    signature[12] = '\0';
-
-    BUG_ON(strcmp("XenVMMXenVMM", signature) || (eax < 0x40000002));
+    uint32_t base;
+
+    for ( base = 0x40000000; base < 0x40001000; base += 0x100 )
+    {
+        cpuid(base, &eax, &ebx, &ecx, &edx);
+
+        *(uint32_t *)(signature + 0) = ebx;
+        *(uint32_t *)(signature + 4) = ecx;
+        *(uint32_t *)(signature + 8) = edx;
+        signature[12] = '\0';
+
+        if ( !strcmp("XenVMMXenVMM", signature) )
+            break;
+    }
+
+    BUG_ON(strcmp("XenVMMXenVMM", signature) || ((eax - base) < 2));
 
     /* Fill in hypercall transfer pages. */
-    cpuid(0x40000002, &eax, &ebx, &ecx, &edx);
+    cpuid(base + 2, &eax, &ebx, &ecx, &edx);
     for ( i = 0; i < eax; i++ )
         wrmsr(ebx, HYPERCALL_PHYSICAL_ADDRESS + (i << 12) + i);
 
     /* Print version information. */
-    cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
+    cpuid(base + 1, &eax, &ebx, &ecx, &edx);
     hypercall_xen_version(XENVER_extraversion, extraversion);
     printf("Detected Xen v%u.%u%s\n", eax >> 16, eax & 0xffff, extraversion);
 }
tools/python/xen/xend/XendConfig.py +3 -0
diff -r e66cecb66b1e tools/python/xen/xend/XendConfig.py
@@ -155,6 +155,7 @@ XENAPI_PLATFORM_CFG_TYPES = {
     'vncdisplay': int,
     'vnclisten': str,
     'timer_mode': int,
+    'viridian': int,
     'vncpasswd': str,
     'vncunused': int,
     'xauthority': str,
@@ -442,6 +443,8 @@ class XendConfig(dict):
         if self.is_hvm():
             if 'timer_mode' not in self['platform']:
                 self['platform']['timer_mode'] = 1
+            if 'viridian' not in self['platform']:
+                self['platform']['viridian'] = 0
             if 'rtc_timeoffset' not in self['platform']:
                 self['platform']['rtc_timeoffset'] = 0
             if 'hpet' not in self['platform']:
tools/python/xen/xend/XendConstants.py +4 -3
diff -r e66cecb66b1e tools/python/xen/xend/XendConstants.py
@@ -43,9 +43,10 @@ HVM_PARAM_PAE_ENABLED  = 4
 HVM_PARAM_PAE_ENABLED  = 4
 HVM_PARAM_IOREQ_PFN    = 5
 HVM_PARAM_BUFIOREQ_PFN = 6
-HVM_PARAM_NVRAM_FD     = 7
-HVM_PARAM_VHPT_SIZE    = 8
-HVM_PARAM_BUFPIOREQ_PFN = 9
+HVM_PARAM_NVRAM_FD     = 7 # ia64
+HVM_PARAM_VHPT_SIZE    = 8 # ia64
+HVM_PARAM_BUFPIOREQ_PFN = 9 # ia64
+HVM_PARAM_VIRIDIAN     = 9 # x86
 HVM_PARAM_TIMER_MODE   = 10
 HVM_PARAM_HPET_ENABLED = 11
 HVM_PARAM_ACPI_S_STATE = 14
tools/python/xen/xend/XendDomainInfo.py +5 -0
diff -r e66cecb66b1e tools/python/xen/xend/XendDomainInfo.py
@@ -2078,6 +2078,11 @@ class XendDomainInfo:
             xc.hvm_set_param(self.domid, HVM_PARAM_TIMER_MODE,
                              long(timer_mode))
 
+        # Set Viridian interface configuration of domain
+        viridian = self.info["platform"].get("viridian")
+        if arch.type == "x86" and hvm and viridian is not None:
+            xc.hvm_set_param(self.domid, HVM_PARAM_VIRIDIAN, long(viridian))
+
         # Optionally enable virtual HPET
         hpet = self.info["platform"].get("hpet")
         if hvm and hpet is not None:
tools/python/xen/xm/create.py +7 -1
diff -r e66cecb66b1e tools/python/xen/xm/create.py
@@ -217,6 +217,11 @@ gopts.var('timer_mode', val='TIMER_MODE'
           fn=set_int, default=1,
           use="""Timer mode (0=delay virtual time when ticks are missed;
           1=virtual time is always wallclock time.""")
+
+gopts.var('viridian', val='VIRIDIAN',
+          fn=set_int, default=0,
+          use="""Expose Viridian interface to x86 HVM guest?
+          (Default is 0).""")
 
 gopts.var('acpi', val='ACPI',
           fn=set_int, default=1,
@@ -856,7 +861,8 @@ def configure_hvm(config_image, vals):
              'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten',
              'sdl', 'display', 'xauthority', 'rtc_timeoffset', 'monitor',
              'acpi', 'apic', 'usb', 'usbdevice', 'keymap', 'pci', 'hpet',
-             'guest_os_type', 'hap', 'opengl', 'cpuid', 'cpuid_check']
+             'guest_os_type', 'hap', 'opengl', 'cpuid', 'cpuid_check',
+             'viridian' ]
 
     for a in args:
         if a in vals.__dict__ and vals.__dict__[a] is not None:
tools/python/xen/xm/xenapi_create.py +1 -0
diff -r e66cecb66b1e tools/python/xen/xm/xenapi_create.py
@@ -969,6 +969,7 @@ class sxp2xml:
             'usbdevice',
             'hpet',
             'timer_mode',
+            'viridian',
             'vhpt',
             'guest_os_type',
             'hap',
unmodified_drivers/linux-2.6/platform-pci/platform-pci.c +32 -27

83 lines not on this page · raw message

xen/arch/x86/hvm/Makefile +1 -0
diff -r e66cecb66b1e xen/arch/x86/hvm/Makefile
@@ -18,3 +18,4 @@ obj-y += save.o
 obj-y += save.o
 obj-y += vmsi.o
 obj-y += stdvga.o
+obj-y += viridian.o
xen/arch/x86/hvm/hvm.c +10 -0
diff -r e66cecb66b1e xen/arch/x86/hvm/hvm.c
@@ -1636,6 +1636,9 @@ void hvm_cpuid(unsigned int input, unsig
 {
     struct vcpu *v = current;
 
+    if ( cpuid_viridian_leaves(input, eax, ebx, ecx, edx) )
+        return;
+
     if ( cpuid_hypervisor_leaves(input, eax, ebx, ecx, edx) )
         return;
 
@@ -1953,6 +1956,9 @@ int hvm_do_hypercall(struct cpu_user_reg
     case 0:
         break;
     }
+
+    if ( (eax & 0x80000000) && is_viridian_domain(curr->domain) )
+        return viridian_hypercall(regs);
 
     if ( (eax >= NR_hypercalls) || !hvm_hypercall32_table[eax] )
     {
@@ -2378,6 +2384,10 @@ long do_hvm_op(unsigned long op, XEN_GUE
                 break;
             case HVM_PARAM_TIMER_MODE:
                 if ( a.value > HVMPTM_one_missed_tick_pending )
+                    rc = -EINVAL;
+                break;
+            case HVM_PARAM_VIRIDIAN:
+                if ( a.value > 1 )
                     rc = -EINVAL;
                 break;
             case HVM_PARAM_IDENT_PT:
xen/arch/x86/hvm/svm/svm.c +5 -1
diff -r e66cecb66b1e xen/arch/x86/hvm/svm/svm.c
@@ -1005,7 +1005,8 @@ static int svm_msr_read_intercept(struct
         break;
 
     default:
-        if ( rdmsr_hypervisor_regs(ecx, &eax, &edx) ||
+        if ( rdmsr_viridian_regs(ecx, &eax, &edx) ||
+             rdmsr_hypervisor_regs(ecx, &eax, &edx) ||
              rdmsr_safe(ecx, eax, edx) == 0 )
         {
             regs->eax = eax;
@@ -1073,6 +1074,9 @@ static int svm_msr_write_intercept(struc
         break;
 
     default:
+        if ( wrmsr_viridian_regs(ecx, regs->eax, regs->edx) )
+            break;
+
         switch ( long_mode_do_msr_write(regs) )
         {
         case HNDL_unhandled:
xen/arch/x86/hvm/vlapic.c +1 -1
diff -r e66cecb66b1e xen/arch/x86/hvm/vlapic.c
@@ -417,7 +417,7 @@ void vlapic_EOI_set(struct vlapic *vlapi
     hvm_dpci_msi_eoi(current->domain, vector);
 }
 
-static int vlapic_ipi(
+int vlapic_ipi(
     struct vlapic *vlapic, uint32_t icr_low, uint32_t icr_high)
 {
     unsigned int dest =         GET_xAPIC_DEST_FIELD(icr_high);
xen/arch/x86/hvm/vmx/vmx.c +6 -1
diff -r e66cecb66b1e xen/arch/x86/hvm/vmx/vmx.c
@@ -1677,7 +1677,8 @@ static int vmx_msr_read_intercept(struct
             break;
         }
 
-        if ( rdmsr_hypervisor_regs(ecx, &eax, &edx) ||
+        if ( rdmsr_viridian_regs(ecx, &eax, &edx) ||
+             rdmsr_hypervisor_regs(ecx, &eax, &edx) ||
              rdmsr_safe(ecx, eax, edx) == 0 )
         {
             regs->eax = eax;
@@ -1852,6 +1853,10 @@ static int vmx_msr_write_intercept(struc
     default:
         if ( vpmu_do_wrmsr(regs) )
             return X86EMUL_OKAY;
+
+        if ( wrmsr_viridian_regs(ecx, regs->eax, regs->edx) ) 
+            break;
+
         switch ( long_mode_do_msr_write(regs) )
         {
             case HNDL_unhandled:
xen/arch/x86/traps.c +19 -7
diff -r e66cecb66b1e xen/arch/x86/traps.c
@@ -577,7 +577,11 @@ int rdmsr_hypervisor_regs(
 int rdmsr_hypervisor_regs(
     uint32_t idx, uint32_t *eax, uint32_t *edx)
 {
-    idx -= 0x40000000;
+    struct domain *d = current->domain;
+    /* Optionally shift out of the way of Viridian architectural MSRs. */
+    uint32_t base = is_viridian_domain(d) ? 0x40000200 : 0x40000000;
+
+    idx -= base;
     if ( idx > 0 )
         return 0;
 
@@ -599,8 +603,10 @@ int wrmsr_hypervisor_regs(
     uint32_t idx, uint32_t eax, uint32_t edx)
 {
     struct domain *d = current->domain;
-
-    idx -= 0x40000000;
+    /* Optionally shift out of the way of Viridian architectural MSRs. */
+    uint32_t base = is_viridian_domain(d) ? 0x40000200 : 0x40000000;
+
+    idx -= base;
     if ( idx > 0 )
         return 0;
 
@@ -628,7 +634,7 @@ int wrmsr_hypervisor_regs(
         {
             gdprintk(XENLOG_WARNING,
                      "Bad GMFN %lx (MFN %lx) to MSR %08x\n",
-                     gmfn, mfn, 0x40000000);
+                     gmfn, mfn, base + idx);
             return 0;
         }
 
@@ -650,14 +656,18 @@ int cpuid_hypervisor_leaves(
 int cpuid_hypervisor_leaves(
     uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
 {
-    idx -= 0x40000000;
-    if ( idx > 2 )
+    struct domain *d = current->domain;
+    /* Optionally shift out of the way of Viridian architectural leaves. */
+    uint32_t base = is_viridian_domain(d) ? 0x40000100 : 0x40000000;
+
+    idx -= base;
+    if ( idx > 2 ) 
         return 0;
 
     switch ( idx )
     {
     case 0:
-        *eax = 0x40000002; /* Largest leaf */
+        *eax = base + 2; /* Largest leaf */
         *ebx = XEN_CPUID_SIGNATURE_EBX;
         *ecx = XEN_CPUID_SIGNATURE_ECX;
         *edx = XEN_CPUID_SIGNATURE_EDX;
@@ -673,6 +683,8 @@ int cpuid_hypervisor_leaves(
     case 2:
         *eax = 1;          /* Number of hypercall-transfer pages */
         *ebx = 0x40000000; /* MSR base address */
+        if ( is_viridian_domain(d) )
+            *ebx = 0x40000200;
         *ecx = 0;          /* Features 1 */
         *edx = 0;          /* Features 2 */
         if ( !is_hvm_vcpu(current) )
xen/include/asm-x86/hvm/domain.h +3 -0
diff -r e66cecb66b1e xen/include/asm-x86/hvm/domain.h
@@ -28,6 +28,7 @@
 #include <asm/hvm/vioapic.h>
 #include <asm/hvm/io.h>
 #include <xen/hvm/iommu.h>
+#include <asm/hvm/viridian.h>
 #include <asm/hvm/vmx/vmcs.h>
 #include <asm/hvm/svm/vmcb.h>
 #include <public/hvm/params.h>
@@ -74,6 +75,8 @@ struct hvm_domain {
     /* Pass-through */
     struct hvm_iommu       hvm_iommu;
 
+    struct viridian_domain viridian;
+
     bool_t                 hap_enabled;
     bool_t                 qemu_mapcache_invalidate;
     bool_t                 is_s3_suspended;
xen/include/asm-x86/hvm/hvm.h +3 -0
diff -r e66cecb66b1e xen/include/asm-x86/hvm/hvm.h
@@ -219,6 +219,9 @@ hvm_set_segment_register(struct vcpu *v,
     hvm_funcs.set_segment_register(v, seg, reg);
 }
 
+#define is_viridian_domain(_d)                                             \
+ (is_hvm_domain(_d) && ((_d)->arch.hvm_domain.params[HVM_PARAM_VIRIDIAN]))
+
 void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx,
                                    unsigned int *ecx, unsigned int *edx);
 void hvm_migrate_timers(struct vcpu *v);
xen/include/asm-x86/hvm/vlapic.h +4 -0
diff -r e66cecb66b1e xen/include/asm-x86/hvm/vlapic.h
@@ -98,4 +98,8 @@ struct vlapic *apic_round_robin(
 
 int vlapic_match_logical_addr(struct vlapic *vlapic, uint8_t mda);
 
+void vlapic_EOI_set(struct vlapic *vlapic);
+
+int vlapic_ipi(struct vlapic *vlapic, uint32_t icr_low, uint32_t icr_high);
+
 #endif /* __ASM_X86_HVM_VLAPIC_H__ */
xen/include/asm-x86/perfc_defn.h +16 -0
diff -r e66cecb66b1e xen/include/asm-x86/perfc_defn.h
@@ -111,4 +111,20 @@ PERFCOUNTER(shadow_unsync_evict,   "shad
 PERFCOUNTER(shadow_unsync_evict,   "shadow OOS evictions")
 PERFCOUNTER(shadow_resync,         "shadow OOS resyncs")
 
+PERFCOUNTER(mshv_call_sw_addr_space,    "MS Hv Switch Address Space")
+PERFCOUNTER(mshv_call_flush_tlb_list,   "MS Hv Flush TLB list")
+PERFCOUNTER(mshv_call_flush_tlb_all,    "MS Hv Flush TLB all")
+PERFCOUNTER(mshv_call_long_wait,        "MS Hv Notify long wait")
+PERFCOUNTER(mshv_rdmsr_osid,            "MS Hv rdmsr Guest OS ID")
+PERFCOUNTER(mshv_rdmsr_hc_page,         "MS Hv rdmsr hypercall page")
+PERFCOUNTER(mshv_rdmsr_vp_index,        "MS Hv rdmsr vp index")
+PERFCOUNTER(mshv_rdmsr_icr,             "MS Hv rdmsr icr")
+PERFCOUNTER(mshv_rdmsr_tpr,             "MS Hv rdmsr tpr")
+PERFCOUNTER(mshv_wrmsr_osid,            "MS Hv wrmsr Guest OS ID")
+PERFCOUNTER(mshv_wrmsr_hc_page,         "MS Hv wrmsr hypercall page")
+PERFCOUNTER(mshv_wrmsr_vp_index,        "MS Hv wrmsr vp index")
+PERFCOUNTER(mshv_wrmsr_icr,             "MS Hv wrmsr icr")
+PERFCOUNTER(mshv_wrmsr_tpr,             "MS Hv wrmsr tpr")
+PERFCOUNTER(mshv_wrmsr_eoi,             "MS Hv wrmsr eoi")
+
 /*#endif*/ /* __XEN_PERFC_DEFN_H__ */
xen/include/public/arch-x86/hvm/save.h +12 -1
diff -r e66cecb66b1e xen/include/public/arch-x86/hvm/save.h
@@ -421,9 +421,20 @@ struct hvm_hw_mtrr {
 
 DECLARE_HVM_SAVE_TYPE(MTRR, 14, struct hvm_hw_mtrr);
 
+/*
+ * Viridian hypervisor context.
+ */
+
+struct hvm_viridian_context {
+    uint64_t hypercall_gpa;
+    uint64_t guest_os_id;
+};
+
+DECLARE_HVM_SAVE_TYPE(VIRIDIAN, 15, struct hvm_viridian_context);
+
 /* 
  * Largest type-code in use
  */
-#define HVM_SAVE_CODE_MAX 14
+#define HVM_SAVE_CODE_MAX 15
 
 #endif /* __XEN_PUBLIC_HVM_SAVE_X86_H__ */
xen/include/public/hvm/params.h +7 -0
diff -r e66cecb66b1e xen/include/public/hvm/params.h
@@ -51,9 +51,16 @@
 #define HVM_PARAM_BUFIOREQ_PFN 6
 
 #ifdef __ia64__
+
 #define HVM_PARAM_NVRAM_FD     7
 #define HVM_PARAM_VHPT_SIZE    8
 #define HVM_PARAM_BUFPIOREQ_PFN	9
+
+#elif defined(__i386__) || defined(__x86_64__)
+
+/* Expose Viridian interfaces to this HVM guest? */
+#define HVM_PARAM_VIRIDIAN     9
+
 #endif
 
 /*
xen/arch/x86/hvm/viridian.c new file +350 -0

350 lines not on this page · raw message

xen/include/asm-x86/hvm/viridian.h new file +65 -0

65 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel