Skip to contentSkip to conversation

: PVH xen: create PVH vmcs and initialization

RFC PATCH In review Mukesh Rathor 2 participants 3 messages Jan 12, 2013 – Jan 16, 2013

lore
Share & tools
lore
#0 lore raw

RFC PATCH 9/16 : PVH xen: create PVH vmcs and initialization

This patch mainly contains code to create a VMCS for PVH guest, and HVM specific vcpu/domain creation code.

xen/arch/x86/hvm/hvm.c +76 -2
diff -r e51e48fd1d20 -r eca698a4e733 xen/arch/x86/hvm/hvm.c
@@ -331,6 +331,9 @@ void hvm_do_resume(struct vcpu *v)
 {
     ioreq_t *p;
 
+    if ( is_pvh_vcpu(v) )
+        return;
+
     pt_restore_timer(v);
 
     check_wakeup_from_wait();
@@ -499,6 +502,29 @@ static int hvm_print_line(
     return X86EMUL_OKAY;
 }
 
+static noinline int hvm_pvh_dom_initialise(struct domain *d)
+{
+    int rc;
+
+    if (!d->arch.hvm_domain.hap_enabled)
+        return -EINVAL;
+
+    spin_lock_init(&d->arch.hvm_domain.irq_lock);
+    hvm_init_guest_time(d);
+
+    hvm_init_cacheattr_region_list(d);
+
+    if ( (rc=paging_enable(d, PG_refcounts|PG_translate|PG_external)) != 0 )
+        goto fail1;
+
+    if ( (rc = hvm_funcs.domain_initialise(d)) == 0 )
+        return 0;
+
+fail1:
+    hvm_destroy_cacheattr_region_list(d);
+    return rc;
+}
+
 int hvm_domain_initialise(struct domain *d)
 {
     int rc;
@@ -509,6 +535,8 @@ int hvm_domain_initialise(struct domain 
                  "on a non-VT/AMDV platform.\n");
         return -EINVAL;
     }
+    if ( is_pvh_domain(d) )
+        return hvm_pvh_dom_initialise(d);
 
     spin_lock_init(&d->arch.hvm_domain.pbuf_lock);
     spin_lock_init(&d->arch.hvm_domain.irq_lock);
@@ -572,6 +600,11 @@ int hvm_domain_initialise(struct domain 
 
 void hvm_domain_relinquish_resources(struct domain *d)
 {
+    if ( is_pvh_domain(d) ) 
+    {
+        pit_deinit(d);
+        return;
+    }
     if ( hvm_funcs.nhvm_domain_relinquish_resources )
         hvm_funcs.nhvm_domain_relinquish_resources(d);
 
@@ -597,10 +630,16 @@ void hvm_domain_relinquish_resources(str
 void hvm_domain_destroy(struct domain *d)
 {
     hvm_funcs.domain_destroy(d);
+    hvm_destroy_cacheattr_region_list(d);
+
+    if ( is_pvh_domain(d) ) {
+        printk("PVH:skippoing stuff in hvm_domain_destroy(). reexamine me\n");
+        return;
+    }
+
     rtc_deinit(d);
     stdvga_deinit(d);
     vioapic_deinit(d);
-    hvm_destroy_cacheattr_region_list(d);
 }
 
 static int hvm_save_tsc_adjust(struct domain *d, hvm_domain_context_t *h)
@@ -1054,12 +1093,44 @@ static int __init __hvm_register_CPU_XSA
 }
 __initcall(__hvm_register_CPU_XSAVE_save_and_restore);
 
+static noinline int hvm_pvh_vcpu_initialise(struct vcpu *v)
+{
+    int rc;
+
+    if ( (rc = hvm_funcs.vcpu_initialise(v)) != 0 )
+        return rc;
+
+    softirq_tasklet_init( &v->arch.hvm_vcpu.assert_evtchn_irq_tasklet,
+                          (void(*)(unsigned long))hvm_assert_evtchn_irq,
+                          (unsigned long)v );
+
+    v->arch.hvm_vcpu.hvm_pvh.pvh_vcpu_info_mfn = INVALID_MFN;
+    v->arch.user_regs.eflags = 2;
+    v->arch.hvm_vcpu.inject_trap.vector = -1;
+
+    if ( (rc=hvm_vcpu_cacheattr_init(v)) != 0 ) {
+        hvm_funcs.vcpu_destroy(v);
+        return rc;
+    }
+
+    /* during domain shutdown: pvh_vmx_vmexit_handler->emulate_privileged_op
+     * -> guest_io_read -> pv_pit_handler -> handle_speaker_io -> _spin_lock
+     *  so we call pit_init to initialize the spin lock */
+    if ( v->vcpu_id == 0 )
+        pit_init(v, cpu_khz);
+
+    return 0;
+}
+
 int hvm_vcpu_initialise(struct vcpu *v)
 {
     int rc;
 
     hvm_asid_flush_vcpu(v);
 
+    if ( is_pvh_vcpu(v) )
+        return hvm_pvh_vcpu_initialise(v);
+
     if ( (rc = vlapic_init(v)) != 0 )
         goto fail1;
 
@@ -1149,7 +1220,10 @@ void hvm_vcpu_destroy(struct vcpu *v)
 
     tasklet_kill(&v->arch.hvm_vcpu.assert_evtchn_irq_tasklet);
     hvm_vcpu_cacheattr_destroy(v);
-    vlapic_destroy(v);
+
+    if ( !is_pvh_vcpu(v) )
+        vlapic_destroy(v);
+
     hvm_funcs.vcpu_destroy(v);
 
     /* Event channel is already freed by evtchn_destroy(). */
xen/arch/x86/hvm/vmx/vmcs.c +256 -4

302 lines not on this page · raw message

xen/arch/x86/hvm/vmx/vmx.c +35 -0
diff -r e51e48fd1d20 -r eca698a4e733 xen/arch/x86/hvm/vmx/vmx.c
@@ -92,6 +92,9 @@ static int vmx_domain_initialise(struct 
     if ( !zalloc_cpumask_var(&d->arch.hvm_domain.vmx.ept_synced) )
         return -ENOMEM;
 
+    if ( is_pvh_domain(d) )
+        return 0;
+
     if ( (rc = vmx_alloc_vlapic_mapping(d)) != 0 )
     {
         free_cpumask_var(d->arch.hvm_domain.vmx.ept_synced);
@@ -106,6 +109,10 @@ static void vmx_domain_destroy(struct do
     if ( paging_mode_hap(d) )
         on_each_cpu(__ept_sync_domain, d, 1);
     free_cpumask_var(d->arch.hvm_domain.vmx.ept_synced);
+
+    if ( is_pvh_domain(d) )
+        return;
+
     vmx_free_vlapic_mapping(d);
 }
 
@@ -129,6 +136,12 @@ static int vmx_vcpu_initialise(struct vc
 
     vpmu_initialise(v);
 
+    if (is_pvh_vcpu(v) ) 
+    {
+        /* this for hvm_long_mode_enabled(v) */
+        v->arch.hvm_vcpu.guest_efer = EFER_SCE | EFER_LMA | EFER_LME;
+        return 0;
+    }
     vmx_install_vlapic_mapping(v);
 
     /* %eax == 1 signals full real-mode support to the guest loader. */
@@ -1051,6 +1064,23 @@ static void vmx_update_host_cr3(struct v
     vmx_vmcs_exit(v);
 }
 
+static noinline void vmx_update_pvh_cr(struct vcpu *v, unsigned int cr)
+{
+    vmx_vmcs_enter(v);
+    switch ( cr )
+    {
+        case 3:
+            __vmwrite(GUEST_CR3, v->arch.hvm_vcpu.guest_cr[3]);
+            hvm_asid_flush_vcpu(v);
+            break;
+
+        default:
+            printk("pvh: d%d v%d unexpected cr%d rip:%lx update\n", 
+                   v->domain->domain_id, v->vcpu_id, cr, __vmread(GUEST_RIP));
+    }
+    vmx_vmcs_exit(v);
+}
+
 void vmx_update_debug_state(struct vcpu *v)
 {
     unsigned long mask;
@@ -1070,6 +1100,11 @@ void vmx_update_debug_state(struct vcpu 
 
 static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
 {
+    if ( is_pvh_vcpu(v) ) {
+        vmx_update_pvh_cr(v, cr);
+        return;
+    }
+
     vmx_vmcs_enter(v);
 
     switch ( cr )
#1 lore raw

xen/arch/x86/hvm/hvm.c void hvm_do_resume(struct vcpu *v) · line 335

Quoted 9 lines
Quoted 1 line
Quoted 1 line · Mukesh Rathor
xen/arch/x86/hvm/hvm.c +2 -0
@@ -331,6 +331,9 @@ void hvm_do_resume(struct vcpu *v)
 {
     ioreq_t *p;
 
+    if ( is_pvh_vcpu(v) )
+        return;

Better avoid the call at the call site?

xen/arch/x86/hvm/hvm.c void vmx_vmcs_switch(struct vmcs_struct · line 701

Quoted 6 lines
xen/arch/x86/hvm/hvm.c +2 -0
@@ -697,6 +697,246 @@ void vmx_vmcs_switch(struct vmcs_struct 
     spin_unlock(&vmx->vmcs_lock);
 }
 
+static noinline int pvh_construct_vmcs(struct vcpu *v)
+{

This looks a lot like the "normal" HVM function - can't those be folded reasonably, to reduce redundancy?

xen/arch/x86/hvm/hvm.c void vmx_do_resume(struct vcpu *v) · line 1408

Quoted 6 lines
xen/arch/x86/hvm/hvm.c +2 -0
@@ -1156,6 +1404,9 @@ void vmx_do_resume(struct vcpu *v)
         hvm_asid_flush_vcpu(v);
     }
 
+    if ( is_pvh_vcpu(v) )
+        goto skip_inteLdbgr;   /* PVH supports gdbsx and gdb inside PVH */

What do "inte", "L", and "dbgr" stand for here? Also, to me the comment doesn't really explain anything.

Jan

#2 lore raw
Quoted 8 lines · On Mon, 14 Jan 2013 11:56:39 +0000 "Jan Beulich" <[email protected]> wrote:
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

On 12.01.13 at 02:59, Mukesh Rathor <[email protected]> wrote:

xen/arch/x86/hvm/hvm.c +0 -0
@@ -331,6 +331,9 @@ void hvm_do_resume(struct vcpu *v)
 {
     ioreq_t *p;
 
Quoted 4 lines

xen/arch/x86/hvm/hvm.c void hvm_do_resume(struct vcpu *v) · line 335

Quoted 2 lines
xen/arch/x86/hvm/hvm.c +2 -0
+    if ( is_pvh_vcpu(v) )
+        return;

Better avoid the call at the call site?

Done.

Quoted 14 lines

xen/arch/x86/hvm/hvm.c void vmx_vmcs_switch(struct vmcs_struct · line 701

Quoted 6 lines
xen/arch/x86/hvm/hvm.c +2 -0
@@ -697,6 +697,246 @@ void vmx_vmcs_switch(struct vmcs_struct 
     spin_unlock(&vmx->vmcs_lock);
 }
 
+static noinline int pvh_construct_vmcs(struct vcpu *v)
+{

This looks a lot like the "normal" HVM function - can't those be folded reasonably, to reduce redundancy?

Quoted 4 lines
xen/arch/x86/hvm/hvm.c +0 -0
@@ -1156,6 +1404,9 @@ void vmx_do_resume(struct vcpu *v)
         hvm_asid_flush_vcpu(v);
     }
 
Quoted 6 lines
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +2 -0
+    if ( is_pvh_vcpu(v) )
+        goto skip_inteLdbgr;   /* PVH supports gdbsx and gdb

inside PVH */

What do "inte", "L", and "dbgr" stand for here? Also, to me the comment doesn't really explain anything.

I understand the code is for some external intel debugger. I meant intel_dbgr. PVH, btw, is supported at the moment by gdbsx and gdb running inside the PVH guest. Anyways, got rid of the label:

    if ( is_pvh_vcpu(v)
            reset_stack_and_jump(vmx_asm_do_vmentry);

    debug_state = v->domain->debugger_attached

......

thanks,
Mukesh