Skip to contentSkip to conversation

Supporting Enlightened Windows 2008Server

RFC PATCH Ky Srinivasan 3 participants 6 messages Apr 4, 2008 – Apr 14, 2008 2 messages not in the archive Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line

On Fri, Mar 7, 2008 at 8:30 AM, in message

<C3F6F3FB.1DAE5%[email protected]>, Keir Fraser

Quoted 24 lines · <[email protected]> wrote:
Quoted 1 line · Ky Srinivasan

I agree that there is no need to isolate the shim's dependence on the base

Xen

Quoted 1 line

code (xen_call_vector_t). I implemented this shim a year ago and at that

point

Quoted 1 line

it was not clear what Microsoft might do with the Veridian specification.

So,

Quoted 1 line

clearly some of the design choices that I made a year ago may not be the

right

Quoted 1 line

choice today. However, I still think that having an intercept framework

where

Quoted 2 lines

one can implement Veridian specific functionality without cluttering up the base Xen code is still the right approach.

Clearly putting the Viridian hypercall shims in a different file/directory makes sense. But I think the shims would need to go on a diet. The TLB flushing implementation is a good example -- the useful extra features of the Viridian flush hypercall (if there are any, when partnered with Xen's shadow code) should be pushed into core Xen HVM TLB-flush handling code. Otherwise it sits out on the periphery with a correspndingly greater tendency to rot, and for no benefit (certainly I would strongly argue it is not cleaner!).

Quoted 1 line

-- Keir

Kier,

Based on the feedback I got from you and Tim, I am enclosing the next version of the patches to support enlightened win2008 server. Here are the changes I have made:

1) I have put the shim on a low calorie diet - I have gotten rid of the framework infrastructure and to the extent possible integrated the shim code with xen.

2) I have tried to cleanup the code. I am sure more work will be needed here.

3) I am not advertising the TLB related enlightenments. We can revisit this later if needed.

Regards,

K. Y

Quoted 6 lines

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

tools/python/xen/lowlevel/xc/xc.c +5 -4
Index: xen-unstable.hg/tools/python/xen/lowlevel/xc/xc.c
===================================================================
@@ -622,14 +622,14 @@
     int i;
 #endif
     char *image;
-    int memsize, vcpus = 1, acpi = 0, apic = 1;
+    int memsize, vcpus = 1, acpi = 0, apic = 1, extid = 0;
 
     static char *kwd_list[] = { "domid",
-				"memsize", "image", "vcpus", "acpi",
+				"memsize", "image", "vcpus", "extid", "acpi",
 				"apic", NULL };
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iis|iii", kwd_list,
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iis|iiii", kwd_list,
                                       &dom, &memsize,
-                                      &image, &vcpus, &acpi, &apic) )
+                                      &image, &vcpus, &extid, &acpi, &apic) )
         return NULL;
 
     if ( xc_hvm_build(self->xc_handle, dom, memsize, image) != 0 )
@@ -654,6 +654,7 @@
     va_hvm->checksum = -sum;
     munmap(va_map, XC_PAGE_SIZE);
 #endif
+    xc_set_hvm_param(self->xc_handle, dom, HVM_PARAM_EXTEND_HYPERVISOR, extid);
 
     return Py_BuildValue("{}");
 }
tools/python/xen/xend/XendConfig.py +1 -0
Index: xen-unstable.hg/tools/python/xen/xend/XendConfig.py
===================================================================
@@ -139,6 +139,7 @@
     'monitor': int,
     'nographic': int,
     'pae' : int,
+    'extid': int, 
     'rtc_timeoffset': int,
     'serial': str,
     'sdl': int,
tools/python/xen/xend/image.py +3 -0
Index: xen-unstable.hg/tools/python/xen/xend/image.py
===================================================================
@@ -508,6 +508,7 @@
 
         self.apic = int(vmConfig['platform'].get('apic', 0))
         self.acpi = int(vmConfig['platform'].get('acpi', 0))
+	self.extid  = int(vmConfig['platform'].get('extid',  0))
         self.guest_os_type = vmConfig['platform'].get('guest_os_type')
 
     # Return a list of cmd line args to the device models based on the
@@ -607,6 +608,7 @@
         log.debug("store_evtchn   = %d", store_evtchn)
         log.debug("memsize        = %d", mem_mb)
         log.debug("vcpus          = %d", self.vm.getVCpuCount())
+	log.debug("extid          = %d", self.extid)
         log.debug("acpi           = %d", self.acpi)
         log.debug("apic           = %d", self.apic)
 
@@ -614,6 +616,7 @@
                           image          = self.loader,
                           memsize        = mem_mb,
                           vcpus          = self.vm.getVCpuCount(),
+			  extid          = self.extid,
                           acpi           = self.acpi,
                           apic           = self.apic)
         rc['notes'] = { 'SUSPEND_CANCEL': 1 }
tools/python/xen/xm/create.py +5 -1
Index: xen-unstable.hg/tools/python/xen/xm/create.py
===================================================================
@@ -207,6 +207,10 @@
           use="""Timer mode (0=delay virtual time when ticks are missed;
           1=virtual time is always wallclock time.""")
 
+gopts.var('extid', val='EXTID',
+          fn=set_int, default=0,
+          use="Specify extention ID for a HVM domain.")
+
 gopts.var('acpi', val='ACPI',
           fn=set_int, default=1,
           use="Disable or enable ACPI of HVM domain.")
@@ -750,7 +754,7 @@
 def configure_hvm(config_image, vals):
     """Create the config for HVM devices.
     """
-    args = [ 'device_model', 'pae', 'vcpus', 'boot', 'fda', 'fdb', 'timer_mode',
+    args = [ 'device_model', 'pae', 'extid', 'vcpus', 'boot', 'fda', 'fdb', 'timer_mode',
              'localtime', 'serial', 'stdvga', 'isa', 'nographic', 'soundhw',
              'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten',
              'sdl', 'display', 'xauthority', 'rtc_timeoffset', 'monitor',

%patch

xen/arch/x86/hvm/svm/svm.c +13 -2
Index: xen-unstable.hg/xen/arch/x86/hvm/svm/svm.c
===================================================================
@@ -50,6 +50,7 @@
 #include <asm/hvm/vpt.h>
 #include <asm/hvm/trace.h>
 #include <asm/hap.h>
+#include <asm/hvm/hvm_extensions.h>
 
 u32 svm_feature_flags;
 
@@ -950,7 +951,7 @@
 
 static void svm_vmexit_do_cpuid(struct cpu_user_regs *regs)
 {
-    unsigned int eax, ebx, ecx, edx, inst_len;
+    unsigned int eax, ebx, ecx, edx, inst_len, input;
 
     inst_len = __get_instruction_length(current, INSTR_CPUID, NULL);
     if ( inst_len == 0 ) 
@@ -960,6 +961,7 @@
     ebx = regs->ebx;
     ecx = regs->ecx;
     edx = regs->edx;
+    input = eax;
 
     svm_cpuid_intercept(&eax, &ebx, &ecx, &edx);
 
@@ -968,6 +970,7 @@
     regs->ecx = ecx;
     regs->edx = edx;
 
+    hyperx_intercept_do_cpuid(input, regs);
     __update_guest_eip(regs, inst_len);
 }
 
@@ -984,6 +987,10 @@
     struct vcpu *v = current;
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
 
+    if (hyperx_intercept_do_msr_read(ecx, regs))
+    {
+            goto done;
+    }
     switch ( ecx )
     {
     case MSR_IA32_TSC:
@@ -1085,6 +1092,10 @@
     msr_content = (u32)regs->eax | ((u64)regs->edx << 32);
 
     hvmtrace_msr_write(v, ecx, msr_content);
+    if (hyperx_intercept_do_msr_write(ecx, regs))
+    {
+            goto done_msr_write;
+    }
 
     switch ( ecx )
     {
@@ -1141,7 +1152,7 @@
         }
         break;
     }
-
+done_msr_write:
     return X86EMUL_OKAY;
 
  gpf:
xen/arch/x86/hvm/vmx/vmx.c +10 -1
Index: xen-unstable.hg/xen/arch/x86/hvm/vmx/vmx.c
===================================================================
@@ -49,6 +49,7 @@
 #include <asm/hvm/vpt.h>
 #include <public/hvm/save.h>
 #include <asm/hvm/trace.h>
+#include <asm/hvm/hvm_extensions.h>
 
 enum handler_return { HNDL_done, HNDL_unhandled, HNDL_exception_raised };
 
@@ -1225,12 +1226,13 @@
 
 static void vmx_do_cpuid(struct cpu_user_regs *regs)
 {
-    unsigned int eax, ebx, ecx, edx;
+    unsigned int eax, ebx, ecx, edx, input;
 
     eax = regs->eax;
     ebx = regs->ebx;
     ecx = regs->ecx;
     edx = regs->edx;
+    input = eax;
 
     vmx_cpuid_intercept(&eax, &ebx, &ecx, &edx);
 
@@ -1238,6 +1240,7 @@
     regs->ebx = ebx;
     regs->ecx = ecx;
     regs->edx = edx;
+    hyperx_intercept_do_cpuid(input, regs);
 }
 
 static void vmx_dr_access(unsigned long exit_qualification,
@@ -1506,6 +1509,9 @@
 
     HVM_DBG_LOG(DBG_LEVEL_1, "ecx=%x", ecx);
 
+    if (hyperx_intercept_do_msr_read(ecx, regs))
+        goto done;
+
     switch ( ecx )
     {
     case MSR_IA32_TSC:
@@ -1699,6 +1705,9 @@
     HVM_DBG_LOG(DBG_LEVEL_1, "ecx=%x, eax=%x, edx=%x",
                 ecx, (u32)regs->eax, (u32)regs->edx);
 
+    if (hyperx_intercept_do_msr_write(ecx, regs)) 
+        return X86EMUL_OKAY;
+
     msr_content = (u32)regs->eax | ((u64)regs->edx << 32);
 
     hvmtrace_msr_write(v, ecx, msr_content);
xen/include/asm-x86/hvm/domain.h +1 -0
Index: xen-unstable.hg/xen/include/asm-x86/hvm/domain.h
===================================================================
@@ -79,6 +79,7 @@
 #endif
     bool_t                 hap_enabled;
     bool_t                 qemu_mapcache_invalidate;
+    void                   *hyperv_handle; /* will be NULL on creation (memset)*/
 };
 
 #endif /* __ASM_X86_HVM_DOMAIN_H__ */
xen/arch/x86/hvm/Makefile +1 -0
Index: xen-unstable.hg/xen/arch/x86/hvm/Makefile
===================================================================
@@ -1,5 +1,6 @@
 subdir-y += svm
 subdir-y += vmx
+subdir-y += hyperv 
 
 obj-y += emulate.o
 obj-y += hvm.o
xen/arch/x86/hvm/hvm.c +20 -0
Index: xen-unstable.hg/xen/arch/x86/hvm/hvm.c
===================================================================
@@ -43,6 +43,7 @@
 #include <asm/mc146818rtc.h>
 #include <asm/spinlock.h>
 #include <asm/hvm/hvm.h>
+#include <asm/hvm/hvm_extensions.h>
 #include <asm/hvm/vpt.h>
 #include <asm/hvm/support.h>
 #include <asm/hvm/cacheattr.h>
@@ -156,6 +157,7 @@
     rtc_migrate_timers(v);
     hpet_migrate_timers(v);
     pt_migrate(v);
+    hyperx_intercept_do_migrate_timers(v);
 }
 
 void hvm_do_resume(struct vcpu *v)
@@ -342,6 +344,7 @@
 
 void hvm_domain_destroy(struct domain *d)
 {
+    hyperx_intercept_domain_destroy(d);
     hvm_funcs.domain_destroy(d);
     vioapic_deinit(d);
     hvm_destroy_cacheattr_region_list(d);
@@ -625,8 +628,14 @@
 {
     int rc;
 
+    if ((rc = hyperx_intercept_vcpu_initialize(v)) != 0)
+        goto fail1;
+
     if ( (rc = vlapic_init(v)) != 0 )
+    {
+        hyperx_intercept_vcpu_destroy(v);
         goto fail1;
+    }
 
     if ( (rc = hvm_funcs.vcpu_initialise(v)) != 0 )
         goto fail2;
@@ -674,12 +683,14 @@
     hvm_funcs.vcpu_destroy(v);
  fail2:
     vlapic_destroy(v);
+    hyperx_intercept_vcpu_destroy(v);
  fail1:
     return rc;
 }
 
 void hvm_vcpu_destroy(struct vcpu *v)
 {
+    hyperx_intercept_vcpu_destroy(v);
     vlapic_destroy(v);
     hvm_funcs.vcpu_destroy(v);
 
@@ -1823,6 +1834,10 @@
     case 0:
         break;
     }
+    if (hyperx_intercept_do_hypercall(regs)) 
+    {
+        return HVM_HCALL_completed;
+    }
 
     if ( (eax >= NR_hypercalls) || !hvm_hypercall32_table[eax] )
     {
@@ -1964,6 +1979,7 @@
         vcpu_wake(v);
 
     gdprintk(XENLOG_INFO, "AP %d bringup succeeded.\n", vcpuid);
+    hyperx_intercept_vcpu_up(v);
     return 0;
 }
 
@@ -2210,6 +2226,10 @@
                 if ( a.value > HVMPTM_one_missed_tick_pending )
                     goto param_fail;
                 break;
+            case HVM_PARAM_EXTEND_HYPERVISOR:
+printk("KYS: EXTEND hypervisor id is %d\n", (int)a.value);
+                if ((a.value == 1) && hyperv_initialize(d)) 
+                    goto param_fail;
             }
             d->arch.hvm_domain.params[a.index] = a.value;
             rc = 0;
xen/arch/x86/hvm/save.c +2 -0
Index: xen-unstable.hg/xen/arch/x86/hvm/save.c
===================================================================
@@ -23,6 +23,8 @@
 
 #include <asm/hvm/support.h>
 #include <public/hvm/save.h>
+#include <public/hvm/params.h>
+#include <asm/hvm/hvm_extensions.h>
 
 void arch_hvm_save(struct domain *d, struct hvm_save_header *hdr)
 {
xen/include/public/arch-x86/hvm/save.h +23 -2
Index: xen-unstable.hg/xen/include/public/arch-x86/hvm/save.h
===================================================================
@@ -38,7 +38,7 @@
     uint32_t version;           /* File format version */
     uint64_t changeset;         /* Version of Xen that saved this file */
     uint32_t cpuid;             /* CPUID[0x01][%eax] on the saving machine */
-    uint32_t pad0;
+    uint32_t pad0;		/* extension ID */
 };
 
 DECLARE_HVM_SAVE_TYPE(HEADER, 1, struct hvm_save_header);
@@ -421,9 +421,30 @@
 
 DECLARE_HVM_SAVE_TYPE(MTRR, 14, struct hvm_hw_mtrr);
 
+struct hvm_hyperv_dom {
+    uint64_t guestid_msr;
+    uint64_t hypercall_msr;
+    uint32_t long_mode;
+    uint32_t ext_id;
+};
+DECLARE_HVM_SAVE_TYPE(HYPERV_DOM, 15, struct hvm_hyperv_dom);
+
+struct hvm_hyperv_cpu {
+    uint64_t control_msr;
+    uint64_t version_msr;
+    uint64_t sief_msr;
+    uint64_t simp_msr;
+    uint64_t eom_msr;
+    uint64_t int_msr[16];
+    struct {
+        uint64_t config;
+        uint64_t count;
+    } timers[4];
+};
+DECLARE_HVM_SAVE_TYPE(HYPERV_CPU, 16, struct hvm_hyperv_cpu);
 /* 
  * Largest type-code in use
  */
-#define HVM_SAVE_CODE_MAX 14
+#define HVM_SAVE_CODE_MAX 16
 
 #endif /* __XEN_PUBLIC_HVM_SAVE_X86_H__ */
xen/include/public/hvm/params.h +2 -1
Index: xen-unstable.hg/xen/include/public/hvm/params.h
===================================================================
@@ -83,7 +83,8 @@
 
 /* Boolean: Enable virtual HPET (high-precision event timer)? (x86-only) */
 #define HVM_PARAM_HPET_ENABLED 11
+#define HVM_PARAM_EXTEND_HYPERVISOR 12
 
-#define HVM_NR_PARAMS          12
+#define HVM_NR_PARAMS          13
 
 #endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */

%patch

xen/include/asm-x86/hvm/hvm_extensions.h new file +166 -0

166 lines not on this page · raw message

xen/arch/x86/hvm/hyperv/Makefile new file +2 -0
Index: xen-unstable.hg/xen/arch/x86/hvm/hyperv/Makefile
===================================================================
@@ -0,0 +1,2 @@
+obj-y += hv_intercept.o  
+obj-y += hv_hypercall.o  
xen/arch/x86/hvm/hyperv/hv_errno.h new file +62 -0

62 lines not on this page · raw message

xen/arch/x86/hvm/hyperv/hv_hypercall.c new file +747 -0

747 lines not on this page · raw message

xen/arch/x86/hvm/hyperv/hv_hypercall.h new file +126 -0

126 lines not on this page · raw message

xen/arch/x86/hvm/hyperv/hv_intercept.c new file +1695 -0

1,578 lines not on this page · raw message

xen/arch/x86/hvm/hyperv/hv_shim.h new file +326 -0

326 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

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

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 31 lines · Ky Srinivasan

Based on the feedback I got from you and Tim, I am enclosing the next version of the patches to support enlightened win2008
server. Here are the changes I have made:

1) I have put the shim on a low calorie diet - I have gotten rid of the framework infrastructure and to the extent possible integrated the shim code with xen.

2) I have tried to cleanup the code. I am sure more work will be needed here.

3) I am not advertising the TLB related enlightenments. We can revisit this later if needed.

Index: xen-unstable.hg/tools/python/xen/xm/create.py
===================================================================

tools/python/xen/xm/create.py +4 -0
@@ -207,6 +207,10 @@
           use="""Timer mode (0=delay virtual time when ticks are missed;
           1=virtual time is always wallclock time.""")
 
+gopts.var('extid', val='EXTID',
+          fn=set_int, default=0,
+          use="Specify extention ID for a HVM domain.")
+
 gopts.var('acpi', val='ACPI',
           fn=set_int, default=1,
           use="Disable or enable ACPI of HVM domain.")

tools/python/xen/xm/create.py line 760

Quoted 8 lines
tools/python/xen/xm/create.py +1 -1
@@ -750,7 +754,7 @@
 def configure_hvm(config_image, vals):
     """Create the config for HVM devices.
     """
-    args = [ 'device_model', 'pae', 'vcpus', 'boot', 'fda', 'fdb', 'timer_mode',
+    args = [ 'device_model', 'pae', 'extid', 'vcpus', 'boot', 'fda', 'fdb', 'timer_mode',
              'localtime', 'serial', 'stdvga', 'isa', 'nographic', 'soundhw',
              'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten',
              'sdl', 'display', 'xauthority', 'rtc_timeoffset', 'monitor',

I'd still like to see the userspace tools side changed to not expose the integrate 'extid' value to administrators configuring guests, and instead use some semanatically meaningful string param

http://lists.xensource.com/archives/html/xen-devel/2008-03/msg00165.html

Regards,
Daniel.

Signature · 4 lines
|: Red Hat, Engineering, Boston   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#2 lore raw
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On Sat, Apr 5, 2008 at 11:17 AM, in message

<[email protected]>, "Daniel P. Berrange" <[email protected]>

Quoted 47 lines · wrote:
Quoted 11 lines · Ky Srinivasan

Based on the feedback I got from you and Tim, I am enclosing the next version of the patches to support enlightened win2008
server. Here are the changes I have made:

1) I have put the shim on a low calorie diet - I have gotten rid of the framework infrastructure and to the extent possible integrated the shim code with xen.

2) I have tried to cleanup the code. I am sure more work will be needed here.

Quoted 7 lines

3) I am not advertising the TLB related enlightenments. We can revisit this later if needed.

Index: xen-unstable.hg/tools/python/xen/xm/create.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xm/create.py 2008-04-04

13:01:01.000000000 -0400

Quoted 1 line

+++ xen-unstable.hg/tools/python/xen/xm/create.py 2008-04-04 13:45:08.000000000

-0400

Quoted 12 lines
tools/python/xen/xm/create.py +4 -0
@@ -207,6 +207,10 @@
           use="""Timer mode (0=delay virtual time when ticks are missed;
           1=virtual time is always wallclock time.""")
 
+gopts.var('extid', val='EXTID',
+          fn=set_int, default=0,
+          use="Specify extention ID for a HVM domain.")
+
 gopts.var('acpi', val='ACPI',
           fn=set_int, default=1,
           use="Disable or enable ACPI of HVM domain.")

tools/python/xen/xm/create.py line 753

Quoted 4 lines
tools/python/xen/xm/create.py +0 -1
@@ -750,7 +754,7 @@
 def configure_hvm(config_image, vals):
     """Create the config for HVM devices.
     """
-    args = [ 'device_model', 'pae', 'vcpus', 'boot', 'fda', 'fdb', 

'timer_mode',

Review line 757

Quoted 1 line
(quoted diff) +1 -0
+    args = [ 'device_model', 'pae', 'extid', 'vcpus', 'boot', 'fda', 'fdb', 

'timer_mode',

Review line 758

Quoted 1 line
(quoted diff) +0 -0
              'localtime', 'serial', 'stdvga', 'isa', 'nographic', 

'soundhw',

tools/python/xen/xm/create.py line 760

Quoted 2 lines
tools/python/xen/xm/create.py +0 -0
              'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten',
              'sdl', 'display', 'xauthority', 'rtc_timeoffset', 'monitor',
Quoted 5 lines

I'd still like to see the userspace tools side changed to not expose the integrate 'extid' value to administrators configuring guests, and instead use some semanatically meaningful string param

http://lists.xensource.com/archives/html/xen-devel/2008-03/msg00165.html

Absolutely. I will fix this in the next revision.

Regards,

K. Y

Quoted 3 lines

Regards,
Daniel.

#3 lore raw
In reply to Daniel P. Berrange
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On Sat, Apr 5, 2008 at 11:17 AM, in message

<[email protected]>, "Daniel P. Berrange" <[email protected]>

Quoted 47 lines · wrote:
Quoted 11 lines · Ky Srinivasan

Based on the feedback I got from you and Tim, I am enclosing the next version of the patches to support enlightened win2008
server. Here are the changes I have made:

1) I have put the shim on a low calorie diet - I have gotten rid of the framework infrastructure and to the extent possible integrated the shim code with xen.

2) I have tried to cleanup the code. I am sure more work will be needed here.

Quoted 7 lines

3) I am not advertising the TLB related enlightenments. We can revisit this later if needed.

Index: xen-unstable.hg/tools/python/xen/xm/create.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xm/create.py 2008-04-04

13:01:01.000000000 -0400

Quoted 1 line

+++ xen-unstable.hg/tools/python/xen/xm/create.py 2008-04-04 13:45:08.000000000

-0400

Quoted 12 lines
tools/python/xen/xm/create.py +4 -0
@@ -207,6 +207,10 @@
           use="""Timer mode (0=delay virtual time when ticks are missed;
           1=virtual time is always wallclock time.""")
 
+gopts.var('extid', val='EXTID',
+          fn=set_int, default=0,
+          use="Specify extention ID for a HVM domain.")
+
 gopts.var('acpi', val='ACPI',
           fn=set_int, default=1,
           use="Disable or enable ACPI of HVM domain.")

tools/python/xen/xm/create.py line 753

Quoted 4 lines
tools/python/xen/xm/create.py +0 -1
@@ -750,7 +754,7 @@
 def configure_hvm(config_image, vals):
     """Create the config for HVM devices.
     """
-    args = [ 'device_model', 'pae', 'vcpus', 'boot', 'fda', 'fdb', 

'timer_mode',

Review line 757

Quoted 1 line
(quoted diff) +1 -0
+    args = [ 'device_model', 'pae', 'extid', 'vcpus', 'boot', 'fda', 'fdb', 

'timer_mode',

Review line 758

Quoted 1 line
(quoted diff) +0 -0
              'localtime', 'serial', 'stdvga', 'isa', 'nographic', 

'soundhw',

tools/python/xen/xm/create.py line 760

Quoted 2 lines
tools/python/xen/xm/create.py +0 -0
              'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten',
              'sdl', 'display', 'xauthority', 'rtc_timeoffset', 'monitor',
Quoted 5 lines

I'd still like to see the userspace tools side changed to not expose the integrate 'extid' value to administrators configuring guests, and instead use some semanatically meaningful string param

http://lists.xensource.com/archives/html/xen-devel/2008-03/msg00165.html

Absolutely. I will fix this in the next revision.

Regards,

K. Y

Quoted 3 lines

Regards,
Daniel.

#5 lore raw
In reply to a message not in the archive

Steven,

Thanks for the detailed review. I will address the issues you have raised as part of my next cleanup of these patches. I have responded to your comments in-line.

Regards,

K. Y

Quoted 6 lines
Quoted 1 line
Quoted 1 line

Steven Smith <[email protected]> 04/10/08 7:23 AM >>>

I have a couple of comments on the new patches:

Would you mind generating diffs with -p, please? It makes them a fair bit easier to read.

Will do.

Quoted 18 lines

static void svm_vmexit_do_cpuid(struct cpu_user_regs *regs) {

xen/arch/x86/hvm/svm/svm.c +2 -1
-    unsigned int eax, ebx, ecx, edx, inst_len;
+    unsigned int eax, ebx, ecx, edx, inst_len, input;
 
     inst_len = __get_instruction_length(current, INSTR_CPUID, NULL);
     if ( inst_len == 0 ) 
...
@@ -968,6 +970,7 @@
     regs->ecx = ecx;
     regs->edx = edx;
 
+    hyperx_intercept_do_cpuid(input, regs);
     __update_guest_eip(regs, inst_len);
 }
 
Quoted 3 lines

Would it be easier to put this bit in hvm_cpuid, or maybe cpuid_hypervisor_leaves? That would avoid needing to make the same change to both the VMX and SVM CPUID infrastructure.

Good point. I will look into it.

Quoted 12 lines
xen/arch/x86/hvm/svm/svm.c +4 -0
@@ -984,6 +987,10 @@
     struct vcpu *v = current;
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
 
+    if (hyperx_intercept_do_msr_read(ecx, regs))
+    {
+            goto done;
+    }
     switch ( ecx )
     {
     case MSR_IA32_TSC:
Quoted 2 lines

Likewise, it seems like that could be done better in rdmsr_hypervisor_regs().

Yep.

Quoted 12 lines
xen/arch/x86/hvm/svm/svm.c +4 -0
@@ -1085,6 +1092,10 @@
     msr_content = (u32)regs->eax | ((u64)regs->edx << 32);
 
     hvmtrace_msr_write(v, ecx, msr_content);
+    if (hyperx_intercept_do_msr_write(ecx, regs))
+    {
+            goto done_msr_write;
+    }
 
     switch ( ecx )
     {
Quoted 1 line

Or wrmsr_hypervisor_regs().

Will do.

Quoted 13 lines
xen/arch/x86/hvm/hvm.c +4 -0
@@ -2210,6 +2226,10 @@
                 if ( a.value > HVMPTM_one_missed_tick_pending )
                     goto param_fail;
                 break;
+            case HVM_PARAM_EXTEND_HYPERVISOR:
+printk("KYS: EXTEND hypervisor id is %d\n", (int)a.value);
+                if ((a.value == 1) && hyperv_initialize(d)) 
+                    goto param_fail;
             }
             d->arch.hvm_domain.params[a.index] = a.value;
             rc = 0;
Quoted 4 lines

It might be a good idea to fail with -EINVAL or something if a.value > 1, so that if anyone ever introduces another hypervisor extension it's easy for the tools to tell whether it's available or not.

Will do.

Quoted 15 lines

Index: xen-unstable.hg/xen/arch/x86/hvm/save.c
===================================================================

xen/arch/x86/hvm/save.c2008-04-04 14:28:44.000000000 -0400 renamed from xen/arch/x86/hvm/save.c2008-04-04 14:28:26.000000000 -0400 +2 -0
@@ -23,6 +23,8 @@
 
 #include <asm/hvm/support.h>
 #include <public/hvm/save.h>
+#include <public/hvm/params.h>
+#include <asm/hvm/hvm_extensions.h>
 
 void arch_hvm_save(struct domain *d, struct hvm_save_header *hdr)
 {
Quoted 2 lines

The only change made to this file was to add some #include's. Why were they necessary?

This was necessary at some point in the past. This is the vestiges of a partial cleanup! This will be fixed.

Quoted 14 lines

Index: xen-unstable.hg/xen/include/public/arch-x86/hvm/save.h
===================================================================

xen/include/public/arch-x86/hvm/save.h2008-04-04 14:28:44.000000000 -0400 renamed from xen/include/public/arch-x86/hvm/save.h2008-04-04 14:28:26.000000000 -0400 +1 -1
@@ -38,7 +38,7 @@
     uint32_t version;           /* File format version */
     uint64_t changeset;         /* Version of Xen that saved this file */
     uint32_t cpuid;             /* CPUID[0x01][%eax] on the saving machine */
-    uint32_t pad0;
+    uint32_t pad0;/* extension ID */
 };
 
 DECLARE_HVM_SAVE_TYPE(HEADER, 1, struct hvm_save_header);
Quoted 3 lines

I think it might be a good idea to give the field a more descriptive name than ``pad0'' if it's being used for something other than padding.

This again is the result of a partial cleanup. I was stashing away the extension ID and Tim rightly pointed out that we had enough state and did not need the extension ID in the save record. This will be cleaned up.

Quoted 4 lines

It might be an even better idea to move the ID out of the header entirely and put it in its own HVM_SAVE_TYPE. You already have hvm_hyperv_dom; can you use that to identify the presence or absence of the extensions?

I will look into this.

Quoted 3 lines
xen/arch/x86/hvm/hyperv/hv_errno.h2008-03-26 13:56:39.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +0 -0
@@ -0,0 +1,4 @@

...

Quoted 6 lines

+/*
+ * hv_errno.h
+ * Error codes for the Novell Shim.

Quoted 2 lines

These are just the Viridian error codes, aren't they, rather than something specific to the Novell shim?

Yes. This will be fixed.

Quoted 12 lines

+ *
+ * Engineering Contact: K. Y. Srinivasan
+ */

xen/arch/x86/hvm/hyperv/hv_errno.h2008-03-26 13:56:39.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +9 -0
+
+#ifndef HV_ERRNO_H
+#define HV_ERRNO_H
+
+#define HV_STATUS_SUCCESS0x0000
+#define HV_STATUS_INVALID_HYPERCALL_CODE0x0002
+#define HV_STATUS_INVALID_HYPERCALL_INPUT0x0003
+#define HV_STATUS_INVALID_ALIGNMENT0x0004
+#define HV_STATUS_INVALID_PARAMETER0x0005

...

Quoted 6 lines

+#endif
Index: xen-unstable.hg/xen/arch/x86/hvm/hyperv/hv_hypercall.c
===================================================================

xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +0 -0
@@ -0,0 +1,13 @@

...

Quoted 12 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +12 -0
+void hv_collect_stats(int event, hv_vcpu_stats_t *statsp)
+{
+switch (event) {
+case HV_CSWITCH:
+statsp->num_switches++;
+return;
+case HV_FLUSH_VA:
+statsp->num_flushes++;
+return;
+case HV_FLUSH_RANGE:
+statsp->num_flush_ranges++;
+return;
Quoted 2 lines

That looks a bit pointless. Would it not be easier to just inline this whole function?

Now that, I have dropped all the TLB flush enlightenments, I will clean this up.

...

Quoted 1 line

+}

...

Quoted 21 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +21 -0
+static int
+hv_get_vp_registers(paddr_t input, paddr_t output)
+{
+hv_vcpu_t        *vcpup, *targetp;
+hv_partition_t   *curp = hv_get_current_partition();
+get_vp_registers_input_t*inbuf;
+get_vp_registers_output_t*outbuf;
+struct vcpu_guest_context*vcpu_ctx;
+u32*reg_indexp;
+get_vp_registers_output_t*out_regp;
+u32num_output_bytes = 0;
+
+        vcpup = &curp->vcpu_state[hv_get_current_vcpu_index()];
+inbuf = vcpup->input_buffer;
+outbuf = vcpup->output_buffer;
+out_regp = outbuf;
+/*
+ * Copy the input data to the per-cpu input buffer.
+ * This may be an overkill; obviously it is better to only
+ * copy what we need. XXXKYS: Check with Mike.
+ */
Quoted 1 line

Who's Mike? What did he say?

Mike is the MSFT contact.

Quoted 3 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +3 -0
+if (hvm_copy_from_guest_phys(inbuf, input, PAGE_SIZE)) {
+return (HV_STATUS_INVALID_ALIGNMENT);
+}

...

Quoted 13 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +12 -0
+/*
+ * Now that we have the register state; select what we want and
+ * populate the output buffer.
+ */
+reg_indexp = &inbuf->reg_index;
+while (*reg_indexp != 0) {
+switch(*reg_indexp) {
+/*
+ * XXXKYS: need mapping code here; populate
+ * outbuf.
+ */
+panic("hv_get_vp_registers not supported\n");
Quoted 3 lines

Yeah, that's not really good enough. It would be better to just not support this hypercall at all than have an implementation which always crashes Xen.

Early on, I decided what Hypercalls I would support; and from this list I wanted
to only support those that were used by windows 2008 server. I had put in a bunch of panics to trap all the hypercalls that the guest would invoke. This hypercall is not used. Thus the implementation is incomplete. I will clean this up.

Quoted 11 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +10 -0
+}
+reg_indexp++;
+out_regp++ ;/*128 bit registers */
+num_output_bytes +=16;
+if ((char *)reg_indexp > ((char *)inbuf + PAGE_SIZE)) {
+/*
+ *input list not reminated correctly; bail out.
+ */
+panic("hv_get_vp_registers:input list not terminated\n"); 
+break;
Quoted 2 lines

It would be nice if this caused the hypercall to fail, rather than crashing Xen.

Will be cleaned up.

Quoted 7 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +5 -0
+}
+}
+if (hvm_copy_to_guest_phys(output, outbuf, num_output_bytes)) {
+/* Some problem copying data out*/
+panic("hv_get_vp_registers:copyout problem\n");

And again.

Will be cleaned up.

Quoted 7 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +4 -0
+}
+xfree(vcpu_ctx);
+return (HV_STATUS_SUCCESS);
+}

Has this hypercall had any testing at all? If it hasn't, then what is it doing here?

As I noted earlier, win2k8 does not currently use this API. I will clean this up.

Quoted 7 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +3 -0
+
+static int
+hv_set_vp_registers(paddr_t input, paddr_t output)

Again, I don't believe this function has ever been called. That suggests that this may not be a high-value optimisation suitable for inclusion in an initial version.

As I noted earlier, win2k8 does not currently use this API. I will clean this up.

...

Quoted 19 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +17 -0
+static int
+hv_switch_va(paddr_t input)
+{
+hv_partition_t   *curp = hv_get_current_partition();
+        hv_vcpu_t *vcpup = &curp->vcpu_state[hv_get_current_vcpu_index()];
+
+/*
+ * XXXKYS: the spec sys the asID is passed via memory at offset 0 of 
+ * the page whose GPA is in the input register. However, it appears 
+ * the current build of longhorn (longhorn-2007-02-06-x86_64-fv-02)
+ * passes the asID in the input register instead. Need to check if 
+ * future builds do this.
+ */
+hvm_set_cr3(input); 
+HV_STATS_COLLECT(HV_CSWITCH, &vcpup->stats);
+return (HV_STATUS_SUCCESS);
+}
Quoted 5 lines

Do you have any evidence that this is actually faster than just doing the CR3 write in the guest? It's a win on real Viridian because you avoid blowing the shadow page table cache, but I don't think that applies on Xen's current shadow page table implementation.

As I noted earlier, initially I identified all the hypercalls that made for a win2k8 guest on our platform. From this list I implemented those that the guest actually invoked. I implemented all the hypercalls that the guest was invoking without regard to the performance value of the enlightenment. I agree with you that this may be more important on Veridian than on our platform.

Quoted 3 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +3 -0
+static int
+hv_flush_va(paddr_t input)
+{

...

Quoted 18 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +17 -0
+/*
+ * Now operate on what we are given
+ * XXXKYS: For now we are ignoring as_id and fushGlobal flag.
+ * May have to revisit this. But first stash away the processed 
+ * parameters for subsequent use.
+ */
+flush_argp->as_handle = as_id;
+flush_argp->flags = flush_global;
+flush_argp->v_mask = vcpu_mask;
+
+
+ret_val = hv_build_hcall_retval(HV_STATUS_SUCCESS, 0);
+hv_set_syscall_retval(guest_cpu_user_regs(),
+                                   curp->long_mode_guest,
+                                   ret_val);
+HV_STATS_COLLECT(HV_FLUSH_VA_STAT, &cur_vcpup->stats);
+panic("hv_flush_va not supported\n"); 
Quoted 2 lines

So if this hypercall is ever correctly used by the guest, Xen will crash?

In the original patches that I posted, this hypercall was implemented. As part of my first round of cleanup, I removed the support for the TLB flush hypercalls. As part of this cleanup, I also disabled TLB related enlightenments. This will be cleaned up.

Quoted 7 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +7 -0
+return (HV_STATUS_SUCCESS);
+}
+
+static int
+hv_flush_va_range(paddr_t input, unsigned short start_index, 
+unsigned short rep_count, unsigned short *reps_done)
+{

...

Quoted 10 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +8 -0
+ret_val = hv_build_hcall_retval(HV_STATUS_SUCCESS, rep_count);
+hv_set_syscall_retval(guest_cpu_user_regs(),
+                                   curp->long_mode_guest,
+                                   ret_val);
+
+
+HV_STATS_COLLECT(HV_FLUSH_RANGE, &cur_vcpup->stats);
+panic("hv_flush_vaRange not supported\n");

And again.

Will be cleaned up.

Quoted 8 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +6 -0
+return (HV_STATUS_SUCCESS);
+}
+
+void
+hv_handle_hypercall(u64 opcode, u64 input, u64 output, 
+  u64 *ret_val)

Would it be easier to just return the return value?

Perhaps.

Quoted 1 line

+{

...

Quoted 17 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +16 -0
+verb = (short)(opcode & 0xffff);
+rep_count = (short)((opcode >>32) & 0xfff);
+start_index = (short)((opcode >> 48) & 0xfff);
+switch (verb) {
+case HV_CREATE_PARTITION:
+/*
+ * Xen only allows dom0 to create domains.
+ */
+*ret_val = hv_build_hcall_retval(HV_STATUS_ACCESS_DENIED, 0);
+return;
+case HV_INITIALIZE_PARTITION:
+/*
+ * We don't support this.
+ */
+*ret_val = hv_build_hcall_retval(HV_STATUS_ACCESS_DENIED, 0);
+return;
Quoted 5 lines

Would it be easier to just make HV_STATUS_ACCESS_DENIED the default? Actually, my reading of the spec is that you should return HV_STATUS_INVALID_HYPERCALL_CODE if the guest makes a hypercall which you don't support, but I can't imagine it makes a great deal of difference.

Perhaps not.

...

Quoted 15 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +14 -0
+case HV_GET_PARTITION_ID:
+if (!hv_privilege_check(curp, HV_ACCESS_PARTITION_ID)) {
+*ret_val = 
+hv_build_hcall_retval(HV_STATUS_ACCESS_DENIED, 0);
+return;
+}
+partition_id = (u64)current->domain->domain_id;
+if (hvm_copy_to_guest_phys(output, 
+&partition_id, 8)) {
+/*
+ * Invalid output area.
+ */
+*ret_val = 
+hv_build_hcall_retval(HV_STATUS_ACCESS_DENIED, 0);
Quoted 1 line

I think you mean HV_STATUS_INVALID_ALIGNMENT.

Agreed.

Quoted 12 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +11 -0
+return;
+}
+*ret_val = hv_build_hcall_retval(HV_STATUS_SUCCESS, 0);
+return;
 
+case HV_GET_VP_REGISTERS:
+*ret_val = hv_build_hcall_retval(
+hv_get_vp_registers(input, output), 0);
+return;
+case HV_SET_VP_REGISTERS:
+*ret_val = hv_build_hcall_retval(
+hv_set_vp_registers(input, output), 0);

...

Quoted 10 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +9 -0
+case HV_FLUSH_VA:
+*ret_val = 
+hv_build_hcall_retval(hv_flush_va(input), 0);
+return;
+case HV_FLUSH_VA_LIST:
+value  = hv_flush_va_range(input, start_index, 
+rep_count, &reps_done);
+*ret_val = hv_build_hcall_retval(value, reps_done);  
+return;
Quoted 2 lines

As mentioned above, your implementations of these hypercalls are really quite broken.

These hypercalls are not invoked by the guest and that is the reason they are broken. I will clean it up though.

...

Quoted 32 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c2008-03-26 14:18:32.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +2 -0
+}
+}

Index: xen-unstable.hg/xen/arch/x86/hvm/hyperv/hv_hypercall.h
===================================================================

xen/arch/x86/hvm/hyperv/hv_hypercall.h2008-03-26 13:56:39.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +21 -0
@@ -0,0 +1,21 @@
+
+/*
+ * nshypercall.h
+ * Memory layouts for the various hypercalls supported. 
+ *
+ * Engineering Contact: K. Y. Srinivasan
+ */
+
+#ifndef HV_HYPERCALL_H
+#define HV_HYPERCALL_H
+
+#include <xen/cpumask.h>
+
+
+typedef struct get_vp_registers_input {
+u64partition_id;
+u64vp_index;
+u32reg_index;
+u32pad1;
+u64pad2;
+} get_vp_registers_input_t;

My reading of the 0.83 specification is that this should have been:

Quoted 8 lines

typedef struct get_vp_registers_input {
u64 partition_id;
u32 vp_index;
u32 pad;
u32 reg_index[0];
} get_vp_registers_input_t;

Is my copy of the specification out of date?

Nope.

Quoted 14 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.h2008-03-26 13:56:39.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +13 -0
+typedef struct set_vp_register_spec {
+u32reg_name;
+u32pad;
+u64pad1;
+u64low_value;
+u64high_value;
+} set_vp_register_spec_t;
+
+typedef struct set_vp_registers_input {
+u64partition_id;
+u64vp_index;
+set_vp_register_spec_treg_spec;
+} set_vp_registers_input_t;
Quoted 2 lines

Again, the 0.83 spec says that vp_index should be a u32, and should be followed by a u32 MBZ pad.

Right.

Quoted 26 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.h2008-03-26 13:56:39.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +13 -0
+
+
+typedef struct flush_va {
+u64as_handle;
+u64flags;
+union  {
+u64processor_mask;
+cpumask_t vcpu_mask;
+} proc_mask;
+#define p_mask proc_mask.processor_mask
+#define v_maskproc_mask.vcpu_mask
+u64gva;
+} flush_va_t;

Is there something wrong with anonymous unions?

xen/arch/x86/hvm/hyperv/hv_hypercall.h2008-03-26 13:56:39.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +7 -0
+/*
+ * Hypercall verbs.
+ */
+
+#define HV_CREATE_PARTITION 0x0010
+#define HV_INITIALIZE_PARTITION 0x0011
+#define HV_DELETE_PARTITION0x0014
Quoted 2 lines

Is it really necesary to include #define's for hypercalls which we don't support and will probably never support?

No; I will clean this file up.

Quoted 19 lines

Index: xen-unstable.hg/xen/arch/x86/hvm/hyperv/hv_intercept.c
===================================================================

xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +12 -0
@@ -0,0 +1,0 @@
 
+/*
+ * Local includes; extension specific.
+ */
+#include "hv_errno.h"
+#include "hv_shim.h"
+
+
+/*
+ * Implement the Hyperv Shim.
+ */
+
+extern struct cpuinfo_x86 boot_cpu_data;
Quoted 1 line

Is there something wrong with processor.h?

This will be fixed.

Quoted 3 lines

+extern struct hvm_mmio_handler vlapic_mmio_handler;

We should probably move that to a header file somewhere.

Will do.

Quoted 10 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +9 -0
+static inline void *
+get_virt_from_gmfn(struct domain *d, unsigned long gmfn)
+{
+unsigned long mfn = gmfn_to_mfn(d, gmfn);
+if (mfn == INVALID_MFN) {
+return (NULL);
+}
+return (map_domain_page_global(mfn));
+}
Quoted 3 lines

Is it really necessary to use map_domain_page_global() here? map_domain_page() is usually quite a bit faster. To be honest, I'm not convinced that this wrapper function has any real value anyway.

I will look into this.

Quoted 11 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +8 -0
+static inline unsigned long
+get_mfn_from_gva(unsigned long va)
+{
+uint32_t pfec = PFEC_page_present;
+unsigned long gfn;
+gfn = paging_gva_to_gfn(current, va, &pfec);
+return (gmfn_to_mfn((current->domain), gfn));
+}

That's only valid if you can guarantee that the resulting MFN will never be written to.

Yes. I use this to figure out if the hypercall is from the PV drivers in the guest or the hyparcall from the guest.

Quoted 5 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +5 -0
+static inline void 
+hv_write_hypercall_msr(hv_partition_t *curp,
+  hv_vcpu_t*cur_vcpu,
+  u64msr_content)
+{

...

Quoted 8 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +5 -0
+hv_hypercall_page_initialize(hypercall_page, curp);
+curp->hypercall_mfn = gmfn_to_mfn(d, gmfn);
+#ifdef CONFIG_DOMAIN_PAGE
+unmap_domain_page_global(hypercall_page);
+#endif

unmap_domain_page_global() is #define'd to nothing #ifndef CONFIG_DOMAIN_PAGE, so you don't need the #ifdef.

Yes.

Quoted 10 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +10 -0
+curp->hypercall_msr = msr_content;
+spin_unlock(&curp->lock);
+cur_vcpu->flags |= HV_VCPU_UP;
+}
+
+
+static inline void hv_write_sx_msr(uint32_t idx, hv_partition_t *curp,
+  hv_vcpu_t*cur_vcpu,
+  u64msr_content)
+{

...

Quoted 8 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +7 -0
+sx_page = get_virt_from_gmfn(d, gmfn);
+if (sx_page == NULL) {
+/*
+ * The guest specified a bogus GPA; inject a GP fault
+ * into the guest.
+ */
+hv_inject_exception(TRAP_gp_fault);
Quoted 4 lines

The spec says tha SIEFP can be outside the physical address space, and you're just supposed to deal with it. The guest will be unable to access the frame, but the MSR write is supposed to succeed (section 14.6.3 of version 0.83). Likewise the SIMP (14.6.4).

You are right. As it turns out, the win2k8 guest on our platform never runs into this situation. I will fix this.

Quoted 23 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +22 -0
+return;
+}
+switch (idx) {
+case HV_MSR_SIEFP:
+hv_init_event_page(sx_page);
+cur_vcpu->siefp_msr = msr_content; 
+cur_vcpu->sief_page = sx_page; 
+break;
+case HV_MSR_SIMP:
+hv_init_message_page(sx_page);
+cur_vcpu->simp_msr = msr_content;
+cur_vcpu->sim_page = sx_page;
+break;
+}
+
+}
+
 
+
+/*
+ * Time this domain booted.
+ */
+s_time_t hv_domain_boot_time;
Quoted 2 lines

Time which domain booted? What if you have two domains which both use the HyperV extensions?

Oops! Will fix this.

Quoted 6 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +5 -0
+static inline void
+hv_inject_exception(int trap)
+{
+hvm_funcs.inject_exception(trap, 0, 0);
+}

hvm_inject_exception() might be a better choice.

Ok.

Quoted 15 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +8 -0
+static inline void 
+hv_set_partition_privileges(hv_partition_t *hvpp)
+{
+/*
+ * This is based on the hypervisor spec under section 5.2.3. 
+ */
+hvpp->privileges = 0x000000020000007f;
+}

So you allow AccessVpRuntime, AccessTimeCounters, AccessSynicMsrs, AccessSyntheticTimers, AccessApicMsrs, AccessHypercallMsrs, AccessVpIndex, and AccessSelfPartitionId? That sounds like a pretty reasonable set, but it'd be nice if you'd documented the fact rather than just dropping in a magic number. Something like this, maybe:

Quoted 3 lines

hvpp->privileges = HV_PRIV_ACCESS_VP_RUNTIME |
HV_PRIV_ACCESS_TIME_COUNTERS |
HV_PRIV_ACCESS_SYNIC_MSRS |

                   ...

Ok.

Quoted 20 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +19 -0
+static inline u32
+hv_get_recommendations(void)
+{
+/*
+ *For now we recommend all the features. Need to validate.
+ */
+if ( paging_mode_hap(current->domain)) {
+/*
+ * If HAP is enabled; the guest should not use TLB flush
+ * related enlightenments.
+ */
+return (0x19);
+} else {
+/*
+ * For now disable TLB flush enlightenments.
+ */
+return (0x19); 
+}
+}
Quoted 4 lines

So you recommend the use of hypercalls for address switches, MSRs for APIC registers, and MSRs for rebooting? The first two make sense, but I'm not so sure that enlightened reboot is a useful optimisation.

Originally, I had implemented TLB flush enlightenments as well. Based on some of the performance analysis we are currently doing, I may re-introduce them. As I noted earlier, I just wanted to implement all the features that made sense for the guest on our platform - hence I implemented reboot as well!

Quoted 2 lines

Again, it would have been useful if the actual set of features was documented rather than just using a magic number.

Yep.

Quoted 8 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +5 -0
+static inline void 
+hv_set_partition_features(hv_partition_t *hvpp)
+{
+hvpp->supported_features = 0x1f;
+}

i.e. VP_RUNTIME | PARTITION_REF_COUNT | SYNIC MSRS | SYNTHETIC_TIMERS |
APIC_MSRS | HYPERCALL_MSRS.

Quoted 6 lines

It's kind of surprising that you recommend guests use the reboot MSRs, but then don't claim to support it. Was that deliberate?

Actually, looking some more, it doesn't look like you ever use the supported_features field, and have instead hardcoded the value to 0xff everywhere you need it.

Will fix this.

Quoted 19 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +19 -0
+
+static inline u16 
+hv_get_guest_major(void)
+{
+//KYS: Check!
+return (0);
+}
+static inline u16
+hv_get_guest_minor(void)
+{
+//KYS: Check!
+return (0);
+}
+static inline u32
+hv_get_guest_service_pack(void)
+{
+//KYS: Check!
+return (0);
+}
Quoted 2 lines

Err... are these supposed to return the guest major/minor/sp reported in the identification MSR?

Yep. Was not quite sure what numbers made sense!

Quoted 2 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +2 -0
+static inline void
+hv_read_icr(u64 *icr_content)

...

Quoted 2 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +2 -0
+static inline void
+hv_read_tpr(u64 *tpr_content)

...

Quoted 2 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +2 -0
+static inline void
+hv_write_eoi(u64 msr_content)

...

Quoted 2 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +2 -0
+static inline void
+hv_write_icr(u64 msr_content)

...

Quoted 2 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +2 -0
+static inline void
+hv_write_tpr(u64 msr_content)

...

Quoted 2 lines

These all have really weird implementations and lots of gratuitous use of hardcoded magic numbers (have a look at apicdef.h).

Will fix it.

Quoted 3 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +3 -0
+static void
+hv_timeout_handler(void *arg)
+{

...

Quoted 11 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +7 -0
+/*
+ * First post the message and then optionally deal with the 
+ * interrupt notification.
+ */
+if (cur_vcpu->sim_page == NULL) {
+panic("Novell Shim: Sim page not setup\n");
+}

So if a guest requests a timeout before they've set up the sim page, Xen crashes? What if they clear the sim page after setting up a timeout, but before it fires?

I will fix this. As I noted earlier, win2k8 currently does not use any of these features.

...

Quoted 15 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +13 -0
+}
+
 
+int
+hyperv_do_hypercall(struct cpu_user_regs *pregs)
+{
+hv_partition_t*curp = hv_get_current_partition();
+hv_vcpu_t        *vcpup;
+intlong_mode_guest = curp->long_mode_guest;
+unsigned long hypercall_mfn;
+unsigned long gmfn;
+gmfn = (curp->hypercall_msr >> 12);
+
+hypercall_mfn = get_mfn_from_gva(pregs->eip);
Quoted 2 lines

That's exciting. Do you expect that guests will make hypercalls from anywhere other than the Viridian hypercall page?

We support PV drivers for win2k8 guests. Given that both HyperV and Xen use the same hypercall numbers to implement different functionality, I needed a way to differentiate HyperV hypercalls. I use the mfn of the hypercall page to figure out who should handle the hypercall.

...

Quoted 3 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +3 -0
+int
+hyperv_vcpu_initialize(struct vcpu *v)
+{

...

Quoted 6 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +6 -0
+/*
+ * Setup the input page for handling hypercalls.
+ *
+ */
+vcpup->input_buffer_page = 
+alloc_domheap_page(NULL);

...

Quoted 2 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +2 -0
+vcpup->input_buffer =
+get_virt_from_page_ptr(vcpup->input_buffer_page);

...

Quoted 2 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +2 -0
+vcpup->output_buffer_page = 
+alloc_domheap_page(NULL);

...

Quoted 6 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +2 -0
+vcpup->output_buffer =
+get_virt_from_page_ptr(vcpup->output_buffer_page);

What exactly are these used for? The only place I can see it referenced are immediately before a panic(), which seems a bit pointless.

These were used in implementing TLB flush enlightenments. I got rid of those hypercalls in the current patch set. I will clean these up.

Quoted 22 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +21 -0
+vcpup->xen_vcpu = v; 
+
+return (0);
+}
+
 
+
+static int 
+hyperv_dom_restore(struct domain *d, hvm_domain_context_t *h)
+{
+struct hvm_hyperv_dom ctxt;
+hv_partition_t*curp;
+
+if ( hvm_load_entry(HYPERV_DOM, h, &ctxt) != 0 )
+        return -22;
+d->arch.hvm_domain.params[HVM_PARAM_EXTEND_HYPERVISOR] = ctxt.ext_id;
+if ((ctxt.ext_id == 0) || (ctxt.ext_id > 1)) {
+return 0;
+}
+if (hyperv_initialize(d)) {
+return -22;
+}
Quoted 1 line

???? Did you mean -EINVAL there?

Yep.

Quoted 45 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +34 -0
+curp = d->arch.hvm_domain.hyperv_handle;
+
+curp->guest_id_msr = ctxt.guestid_msr;
+curp->hypercall_msr = ctxt.hypercall_msr;
+curp->long_mode_guest = ctxt.long_mode;
+curp->hypercall_mfn =
+gmfn_to_mfn(d, (ctxt.hypercall_msr >> 12));
+
+return 0; 
+}
+
 
+static int
+hv_preprocess_cpuid_leaves(unsigned int input, struct cpu_user_regs *regs)
+{
+uint32_t idx;
+struct domain*d = current->domain;
+intextid = d->arch.hvm_domain.params[HVM_PARAM_EXTEND_HYPERVISOR];
+
+if (extid == 1) {
+/*
+ * Enlightened Windows guest; need to remap and handle 
+ * leaves used by PV front-end drivers.
+ */
+if ((input >= 0x40000000) && (input <= 0x40000005)) {
+return (0);
+}
+/*
+ * PV drivers use cpuid to query the hypervisor for details. On
+ * Windows we will use the following leaves for this:
+ *
+ * 4096: VMM Sinature (corresponds to 0x40000000 on Linux)
+ * 4097: VMM Version (corresponds to 0x40000001 on Linux)
+ * 4098: Hypercall details (corresponds to 0x40000002 on Linux)
+ */

I think it would be better to just unconditionally duplicate the Xen leaves at 0x40001000, regardless of whether the viridian enlightenments are enabled. That would make it much easier to write PV drivers which work regardless of whether the enlightenments are enabled, and if we can do that then it might (in a few years' time) be possible to default to enlightments-on for all domains. That isn't really an option when there's no common Xen API.

Quoted 2 lines

This would also mean that you don't need to duplicate the whole of hypervisor_cpuid_leaves() in the Viridian implementation.

I will look into cleaning this up.

...

Quoted 24 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +23 -0
+}
+
+int 
+hyperv_do_cpu_id(unsigned int input, struct cpu_user_regs *regs)
+{
+uint32_t idx;
+
+/*
+ * hvmloader uses cpuid to set up a hypercall page; we don't want to
+ * intercept calls coming from the bootstrap (bios) code in the HVM 
+ * guest; we discriminate based on the instruction pointer.
+ */
+if (hv_call_from_bios(regs)) {
+/*
+ * We don't intercept this.
+ */
+return (0);
+}
+
+if (input == 0x00000001) { 
+regs->ecx = (regs->ecx | 0x80000000);
+return (1);
+} 
Quoted 5 lines

I think we should be doing this even when the shim is disabled. That bit is supposed to indicate ``running on a VMM'', not ``running on a Viridian-compatible VMM'', and it has the side effect of making Windows much more tolerant of vcpus getting scheduled at different rates.

Good point.

Quoted 16 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +15 -0
+if (hv_preprocess_cpuid_leaves(input, regs)) {
+return (0);
+}
+idx = (input - 0x40000000);
+
+switch (idx) {
+case 0:
+/*
+ * 0x40000000: Hypervisor identification. 
+ */
+regs->eax = 0x40000005; /* For now clamp this */
+regs->ebx = 0x65766f4e; /* "Nove" */ 
+regs->ecx = 0x68536c6c; /* "llSh" */
+regs->edx = 0x76486d69; /* "imHv" */ 
+break;
Quoted 2 lines

I think this is supposed to identify the hypervisor (Xen), rather than the Viridian implementation (Novell shim).

You are right.

...

Quoted 9 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +8 -0
+case 5:
+/*
+ * 0x40000005: Implementation limits.
+ * Currently we retrieve maximum number of vcpus and 
+ * logical processors (hardware threads) supported.
+ */
+regs->eax = hv_get_max_vcpus_supported();
 
+regs->ebx = hv_get_max_lcpus_supported();
Quoted 3 lines

a) ebx is marked as reserved in the specification, and
b) it doesn't make a great deal of sense to expose the maximum number of physical CPUs to a virtualised guest anyway.

I thought this is what the spec mandated. I will look into this.

Quoted 17 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +17 -0
+regs->ecx = 0; /* Reserved */
+regs->edx = 0; /* Reserved */
+break; 
+
+default:
+/*
+ * We don't handle this leaf.
+ */
+return (0);
+
+}
+return (1);
+}
+
+int
+hyperv_do_rd_msr(uint32_t idx, struct cpu_user_regs *regs)
+{

...

Quoted 15 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +14 -0
+if (extid > 1) {
+/*
+ * For now this is all other "Enlightened" operating systems
+ * other than Longhorn.
+ */
+if (idx == 0x40000000) {
+/*
+ * PV driver hypercall setup. Let xen handle this.
+ */
+return (0);
+}
+if (idx == 0x40001000) {
+idx = 0x40000000;
+}
Quoted 1 line

Eh? What's this doing?

At one point, I was planning to support other enlightened operating systems. I will clean it up.

Quoted 2 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +2 -0
+}
+switch (idx) {

...

Quoted 13 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +12 -0
+case HV_MSR_TIMER0_COUNT:
+timer = 0;
+goto process_timer_count_read;
+case HV_MSR_TIMER1_COUNT:
+timer = 1;
+goto process_timer_count_read;
+case HV_MSR_TIMER2_COUNT:
+timer = 2;
+goto process_timer_count_read;
+case HV_MSR_TIMER3_COUNT:
+timer = 3;
+process_timer_count_read:
Quoted 3 lines

How much does timer support actually buy you? It's pretty complicated all by itself, and it also seems to be the only reason you need SYNIC support.

The feature is not used currently by the win2k8 guest. I may choose to get rid of this body of code.

Quoted 3 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +3 -0
+if (!hv_privilege_check(curp, HV_ACCESS_SYNC_TIMERS)) {
+goto msr_read_error;
+}

...

Quoted 5 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +5 -0
+}
+
+int
+hyperv_do_wr_msr(uint32_t idx, struct cpu_user_regs *regs)
+{

...

Quoted 1 line

+switch (idx) {

...

Quoted 11 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +7 -0
+case HV_MSR_SEOM:
+if (!hv_privilege_check(curp, HV_ACCESS_SYNC_MSRS)) {
+goto msr_write_error;
+}
+cur_vcpu->eom_msr = msr_content; 
+hv_process_message_q(curp, cur_vcpu);
+break;

You don't support queued messages, so there's not much point in supporting the SEOM MSR either. Also, eom_msr never seems to get read, except for saving it when you do a suspend.

Right.

Quoted 27 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c2008-03-26 14:26:38.000000000 -0400 renamed from dev/null1970-01-01 00:00:00.000000000 +0000 +26 -0
+case HV_MSR_TIMER3_CONFIG:
+timer = 3;
+process_timer_config:
+if (!hv_privilege_check(curp, HV_ACCESS_SYNC_TIMERS)) {
+goto msr_write_error;
+}
+/*
+ * Assume that the client is going to write the whole msr. 
+ */
+if (!(msr_content & 0x9)) {
+/*
+ * We are neither setting Auto Enable or Enable; 
+ * silently exit.
+ * Should this be considered to turn off a 
+ * timer that may be currently 
+ * active; XXXKYS: Check. For now we are 
+ * not doing anything here.
+ */
+break;
+}
+if (!(((u32)(msr_content >> 16)) & 0x0000000f)) {
+/*
+ * sintx is 0; clear the enable bit(s).
+ */
+msr_content &= ~(0x1);
+}
Quoted 2 lines

Again, some #define's would make these magic numbers a bit more clear.

I will fix the code.

Regards,

K. Y

Quoted 1 line

Steven.

#7 lore raw
In reply to a message not in the archive
Quoted 3 lines
Quoted 2 lines

Would you mind generating diffs with -p, please? It makes them a fair bit easier to read.

Will do.

Thanks.

Quoted 17 lines
Quoted 16 lines

static void svm_vmexit_do_cpuid(struct cpu_user_regs *regs) {

xen/arch/x86/hvm/svm/svm.c +2 -1
-    unsigned int eax, ebx, ecx, edx, inst_len;
+    unsigned int eax, ebx, ecx, edx, inst_len, input;
 
     inst_len = __get_instruction_length(current, INSTR_CPUID, NULL);
     if ( inst_len == 0 ) 
...
@@ -968,6 +970,7 @@
     regs->ecx = ecx;
     regs->edx = edx;
 
+    hyperx_intercept_do_cpuid(input, regs);
     __update_guest_eip(regs, inst_len);
 }
 
Quoted 4 lines
Quoted 3 lines

Would it be easier to put this bit in hvm_cpuid, or maybe cpuid_hypervisor_leaves? That would avoid needing to make the same change to both the VMX and SVM CPUID infrastructure.

Good point. I will look into it.

Thanks.

Quoted 15 lines
Quoted 15 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c new file +15 -0
+static int
+hv_get_vp_registers(paddr_t input, paddr_t output)
+{
+hv_vcpu_t        *vcpup, *targetp;
+hv_partition_t   *curp = hv_get_current_partition();
+get_vp_registers_input_t*inbuf;
+get_vp_registers_output_t*outbuf;
+struct vcpu_guest_context*vcpu_ctx;
+u32*reg_indexp;
+get_vp_registers_output_t*out_regp;
+u32num_output_bytes = 0;
+
+        vcpup = &curp->vcpu_state[hv_get_current_vcpu_index()];
+inbuf = vcpup->input_buffer;
+outbuf = vcpup->output_buffer;
Quoted 8 lines
Quoted 7 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c new file +6 -0
+out_regp = outbuf;
+/*
+ * Copy the input data to the per-cpu input buffer.
+ * This may be an overkill; obviously it is better to only
+ * copy what we need. XXXKYS: Check with Mike.
+ */

Who's Mike? What did he say?

Mike is the MSFT contact.

Ah, okay. I think we'd rather not have comments which are meaningless to other people reading the code, so it'd be better to get rid of that sort of thing.

Quoted 17 lines
Quoted 3 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c new file +3 -0
+if (hvm_copy_from_guest_phys(inbuf, input, PAGE_SIZE)) {
+return (HV_STATUS_INVALID_ALIGNMENT);
+}

...

Quoted 12 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c new file +12 -0
+/*
+ * Now that we have the register state; select what we want and
+ * populate the output buffer.
+ */
+reg_indexp = &inbuf->reg_index;
+while (*reg_indexp != 0) {
+switch(*reg_indexp) {
+/*
+ * XXXKYS: need mapping code here; populate
+ * outbuf.
+ */
+panic("hv_get_vp_registers not supported\n");
Quoted 8 lines
Quoted 3 lines

Yeah, that's not really good enough. It would be better to just not support this hypercall at all than have an implementation which always crashes Xen.

Early on, I decided what Hypercalls I would support; and from this list I wanted to only support those that were used by windows 2008 server. I had put in a bunch of panics to trap all the hypercalls that the guest would invoke. This hypercall is not used. Thus the implementation is incomplete. I will clean this up.

If the hypercall is never made, it'd probably be best to just remove it rather than trying to clean it up.

Quoted 20 lines
Quoted 20 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c new file +17 -0
+static int
+hv_switch_va(paddr_t input)
+{
+hv_partition_t   *curp = hv_get_current_partition();
+        hv_vcpu_t *vcpup = &curp->vcpu_state[hv_get_current_vcpu_index()];
+
+/*
+ * XXXKYS: the spec sys the asID is passed via memory at offset 0 of 
+ * the page whose GPA is in the input register. However, it appears 
+ * the current build of longhorn (longhorn-2007-02-06-x86_64-fv-02)
+ * passes the asID in the input register instead. Need to check if 
+ * future builds do this.
+ */
+hvm_set_cr3(input); 
+HV_STATS_COLLECT(HV_CSWITCH, &vcpup->stats);
+return (HV_STATUS_SUCCESS);
+}

Do you have any evidence that this is actually faster than just doing the CR3 write in the guest? It's a win on real Viridian because you avoid blowing the shadow page table cache, but I don't

Quoted 8 lines
Quoted 2 lines

think that applies on Xen's current shadow page table implementation.

As I noted earlier, initially I identified all the hypercalls that made for a win2k8 guest on our platform. From this list I implemented those that the guest actually invoked. I implemented all the hypercalls that the guest was invoking without regard to the performance value of the enlightenment. I agree with you that this may be more important on Veridian than on our platform.

Generally, small patches are easier to merge than big ones. That suggests that you should start with a minimal implementation and then add things which have demonstrated value, rather than trying to get everything working in the initial merge.

Quoted 22 lines
Quoted 3 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c new file +3 -0
+static int
+hv_flush_va(paddr_t input)
+{

...

Quoted 17 lines
xen/arch/x86/hvm/hyperv/hv_hypercall.c new file +17 -0
+/*
+ * Now operate on what we are given
+ * XXXKYS: For now we are ignoring as_id and fushGlobal flag.
+ * May have to revisit this. But first stash away the processed 
+ * parameters for subsequent use.
+ */
+flush_argp->as_handle = as_id;
+flush_argp->flags = flush_global;
+flush_argp->v_mask = vcpu_mask;
+
+
+ret_val = hv_build_hcall_retval(HV_STATUS_SUCCESS, 0);
+hv_set_syscall_retval(guest_cpu_user_regs(),
+                                   curp->long_mode_guest,
+                                   ret_val);
+HV_STATS_COLLECT(HV_FLUSH_VA_STAT, &cur_vcpup->stats);
+panic("hv_flush_va not supported\n"); 
Quoted 6 lines
Quoted 2 lines

So if this hypercall is ever correctly used by the guest, Xen will crash?

In the original patches that I posted, this hypercall was implemented. As part of my first round of cleanup, I removed the support for the TLB flush hypercalls. As part of this cleanup, I also disabled TLB related enlightenments. This will be cleaned up.

Thank you.

Quoted 9 lines
Quoted 8 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +8 -0
+static inline unsigned long
+get_mfn_from_gva(unsigned long va)
+{
+uint32_t pfec = PFEC_page_present;
+unsigned long gfn;
+gfn = paging_gva_to_gfn(current, va, &pfec);
+return (gmfn_to_mfn((current->domain), gfn));
+}
Quoted 4 lines
Quoted 2 lines

That's only valid if you can guarantee that the resulting MFN will never be written to.

Yes. I use this to figure out if the hypercall is from the PV drivers in the guest or the hyparcall from the guest.

If it's only used in one place, it might be easier to remove the foot-shooting potential completely and inline it at its call site.

Quoted 19 lines
Quoted 10 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +10 -0
+curp->hypercall_msr = msr_content;
+spin_unlock(&curp->lock);
+cur_vcpu->flags |= HV_VCPU_UP;
+}
+
+
+static inline void hv_write_sx_msr(uint32_t idx, hv_partition_t *curp,
+  hv_vcpu_t*cur_vcpu,
+  u64msr_content)
+{

...

Quoted 7 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +7 -0
+sx_page = get_virt_from_gmfn(d, gmfn);
+if (sx_page == NULL) {
+/*
+ * The guest specified a bogus GPA; inject a GP fault
+ * into the guest.
+ */
+hv_inject_exception(TRAP_gp_fault);
Quoted 6 lines
Quoted 4 lines

The spec says tha SIEFP can be outside the physical address space, and you're just supposed to deal with it. The guest will be unable to access the frame, but the MSR write is supposed to succeed (section 14.6.3 of version 0.83). Likewise the SIMP (14.6.4).

You are right. As it turns out, the win2k8 guest on our platform
never runs into this situation. I will fix this.

Thank you.

Quoted 18 lines
Quoted 18 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +18 -0
+static inline u32
+hv_get_recommendations(void)
+{
+/*
+ *For now we recommend all the features. Need to validate.
+ */
+if ( paging_mode_hap(current->domain)) {
+/*
+ * If HAP is enabled; the guest should not use TLB flush
+ * related enlightenments.
+ */
+return (0x19);
+} else {
+/*
+ * For now disable TLB flush enlightenments.
+ */
+return (0x19); 
+}
Quoted 8 lines
Quoted 5 lines

+}
So you recommend the use of hypercalls for address switches, MSRs for APIC registers, and MSRs for rebooting? The first two make sense, but I'm not so sure that enlightened reboot is a useful optimisation.

Originally, I had implemented TLB flush enlightenments as well. Based on some of the performance analysis we are currently doing, I may re-introduce them.

Sure.

Quoted 3 lines

As I noted earlier, I just wanted to implement all the features that made sense for the guest on our platform - hence I implemented reboot as well!

I think the interesting question, when deciding whether to implement a feature, is less ``does this feature make sense?'', and more ``does this feature need to be accelerated?''. We're never going to be able to remove the un-enlightened reboot support, and so there needs to be some compelling advantage to justify duplicating the functionality like this. For hot-path operations, like page table updates, that justification is performance, but it's not worth the extra code, with all its attendant bug potential and maintenance cost, just to shave a few milliseconds off reboot times.

Quoted 8 lines
Quoted 7 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +5 -0
+static inline void 
+hv_set_partition_features(hv_partition_t *hvpp)
+{
+hvpp->supported_features = 0x1f;
+}

i.e. VP_RUNTIME | PARTITION_REF_COUNT | SYNIC MSRS | SYNTHETIC_TIMERS |
APIC_MSRS | HYPERCALL_MSRS.

Quoted 7 lines
Quoted 6 lines

It's kind of surprising that you recommend guests use the reboot MSRs, but then don't claim to support it. Was that deliberate?

Actually, looking some more, it doesn't look like you ever use the supported_features field, and have instead hardcoded the value to 0xff everywhere you need it.

Will fix this.

Thanks.

Quoted 15 lines
Quoted 15 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +14 -0
+
+static inline u16 
+hv_get_guest_major(void)
+{
+//KYS: Check!
+return (0);
+}
+static inline u16
+hv_get_guest_minor(void)
+{
+//KYS: Check!
+return (0);
+}
+static inline u32
Quoted 8 lines
Quoted 7 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +5 -0
+hv_get_guest_service_pack(void)
+{
+//KYS: Check!
+return (0);
+}

Err... are these supposed to return the guest major/minor/sp reported in the identification MSR?

Yep. Was not quite sure what numbers made sense!

The guest should tell you what numbers to use when it does interface discovery. See section 3.6 of the spec.

Of course, it really isn't obvious why the guest would ever need to ask the hypervisor what operating system it's running, but that's a problem with the specification rather than with this particular implementation.

Quoted 12 lines
Quoted 2 lines
(quoted diff) +2 -0
+static inline void
+hv_read_icr(u64 *icr_content)

...

Quoted 2 lines
(quoted diff) +2 -0
+static inline void
+hv_read_tpr(u64 *tpr_content)

...

Quoted 2 lines
(quoted diff) +2 -0
+static inline void
+hv_write_eoi(u64 msr_content)

...

Quoted 2 lines
(quoted diff) +2 -0
+static inline void
+hv_write_icr(u64 msr_content)

...

Quoted 7 lines
Quoted 2 lines
(quoted diff) +2 -0
+static inline void
+hv_write_tpr(u64 msr_content)

...

Quoted 2 lines

These all have really weird implementations and lots of gratuitous use of hardcoded magic numbers (have a look at apicdef.h).

Will fix it.

Thanks.

Quoted 12 lines
Quoted 11 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +11 -0
+int
+hyperv_do_hypercall(struct cpu_user_regs *pregs)
+{
+hv_partition_t*curp = hv_get_current_partition();
+hv_vcpu_t        *vcpup;
+intlong_mode_guest = curp->long_mode_guest;
+unsigned long hypercall_mfn;
+unsigned long gmfn;
+gmfn = (curp->hypercall_msr >> 12);
+
+hypercall_mfn = get_mfn_from_gva(pregs->eip);
Quoted 7 lines
Quoted 2 lines

That's exciting. Do you expect that guests will make hypercalls from anywhere other than the Viridian hypercall page?

We support PV drivers for win2k8 guests. Given that both HyperV and Xen use the same hypercall numbers to implement different functionality, I needed a way to differentiate HyperV hypercalls. I use the mfn of the hypercall page to figure out who should handle the hypercall.

Is there any reason you can't make that decision based on eax or some such?

The Viridian spec only specifies the interface between the guest and the hypercall stub page, and not the interface between the stub page and the hypervisor proper. There's no reason why your stub page couldn't do something like this:

orl $0x80000000, %eax
vmmcall

rather than just doing a vmmcall directly. That would allow you to distinguish Viridian hypercalls from Xen ones just by looking at eax[1], which seems a bit cleaner to me.

[1] Assuming that neither Xen nor Viridian ever define hypercall numbers above 0x80000000, which seems likely.

Quoted 17 lines
Quoted 3 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +3 -0
+int
+hyperv_vcpu_initialize(struct vcpu *v)
+{

...

Quoted 6 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +6 -0
+/*
+ * Setup the input page for handling hypercalls.
+ *
+ */
+vcpup->input_buffer_page = 
+alloc_domheap_page(NULL);

...

Quoted 2 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +2 -0
+vcpup->input_buffer =
+get_virt_from_page_ptr(vcpup->input_buffer_page);

...

Quoted 2 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +2 -0
+vcpup->output_buffer_page = 
+alloc_domheap_page(NULL);

...

Quoted 8 lines
Quoted 6 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +2 -0
+vcpup->output_buffer =
+get_virt_from_page_ptr(vcpup->output_buffer_page);

What exactly are these used for? The only place I can see it referenced are immediately before a panic(), which seems a bit pointless.

These were used in implementing TLB flush enlightenments. I got rid of those hypercalls in the current patch set. I will clean these up.

Thanks.

Quoted 33 lines
Quoted 32 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +23 -0
+static int
+hv_preprocess_cpuid_leaves(unsigned int input, struct cpu_user_regs *regs)
+{
+uint32_t idx;
+struct domain*d = current->domain;
+intextid = d->arch.hvm_domain.params[HVM_PARAM_EXTEND_HYPERVISOR];
+
+if (extid == 1) {
+/*
+ * Enlightened Windows guest; need to remap and handle 
+ * leaves used by PV front-end drivers.
+ */
+if ((input >= 0x40000000) && (input <= 0x40000005)) {
+return (0);
+}
+/*
+ * PV drivers use cpuid to query the hypervisor for details. On
+ * Windows we will use the following leaves for this:
+ *
+ * 4096: VMM Sinature (corresponds to 0x40000000 on Linux)
+ * 4097: VMM Version (corresponds to 0x40000001 on Linux)
+ * 4098: Hypercall details (corresponds to 0x40000002 on Linux)
+ */

I think it would be better to just unconditionally duplicate the Xen leaves at 0x40001000, regardless of whether the viridian enlightenments are enabled. That would make it much easier to write PV drivers which work regardless of whether the enlightenments are enabled, and if we can do that then it might (in a few years' time) be possible to default to enlightments-on for all domains. That isn't really an option when there's no common Xen API.

Quoted 4 lines
Quoted 2 lines

This would also mean that you don't need to duplicate the whole of hypervisor_cpuid_leaves() in the Viridian implementation.

I will look into cleaning this up.

Thanks.

Quoted 16 lines
Quoted 2 lines
(quoted diff) +2 -0
+}
+switch (idx) {

...

Quoted 12 lines
xen/arch/x86/hvm/hyperv/hv_intercept.c new file +12 -0
+case HV_MSR_TIMER0_COUNT:
+timer = 0;
+goto process_timer_count_read;
+case HV_MSR_TIMER1_COUNT:
+timer = 1;
+goto process_timer_count_read;
+case HV_MSR_TIMER2_COUNT:
+timer = 2;
+goto process_timer_count_read;
+case HV_MSR_TIMER3_COUNT:
+timer = 3;
+process_timer_count_read:
Quoted 5 lines
Quoted 3 lines

How much does timer support actually buy you? It's pretty complicated all by itself, and it also seems to be the only reason you need SYNIC support.

The feature is not used currently by the win2k8 guest. I may choose to get rid of this body of code.

Please do. If it's not used then it can't possibly be buying you anything, and it's a lot of code to carry just on the off chance that it'll be useful later.

Steven.

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