Initialize guest xcr0, save and restore xcr0 between guest and Akaros
authorMichael Taufen <mtaufen@gmail.com>
Mon, 22 Feb 2016 22:42:31 +0000 (14:42 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 26 Feb 2016 16:28:20 +0000 (11:28 -0500)
Signed-off-by: Michael Taufen <mtaufen@gmail.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/arch/x86/vmm/intel/vmx.c
kern/arch/x86/vmm/vmm.c

index 7d173af..90ee085 100644 (file)
@@ -1131,6 +1131,7 @@ struct guest_pcore *create_guest_pcore(struct proc *p,
        vmx_setup_vmcs(gpc);
        ret = vmx_setup_initial_guest_state(p, gpci);
        vmx_unload_guest_pcore(gpc);
+       gpc->xcr0 = x86_default_xcr0;
 
        gpc->posted_irq_desc = gpci->posted_irq_desc;
 
index 9a13dbf..808bad6 100644 (file)
@@ -185,6 +185,8 @@ struct guest_pcore *load_guest_pcore(struct proc *p, int guest_pcoreid)
        pcpui->guest_pcoreid = guest_pcoreid;
        ept_sync_context(gpc_get_eptp(gpc));
        vmx_load_guest_pcore(gpc);
+       /* Load guest's xcr0 */
+       lxcr0(gpc->xcr0);
        return gpc;
 }
 
@@ -200,6 +202,11 @@ void unload_guest_pcore(struct proc *p, int guest_pcoreid)
        ept_sync_context(gpc_get_eptp(gpc));
        vmx_unload_guest_pcore(gpc);
        gpc->cpu = -1;
+
+       /* Save guest's xcr0 and restore Akaros's default. */
+       gpc->xcr0 = rxcr0();
+       lxcr0(x86_default_xcr0);
+
        /* As soon as we unlock, this gpc can be started on another core */
        spin_unlock(&p->vmm.lock);
        pcpui->guest_pcoreid = -1;