Send IPI using function in vmx.c through pwrite to #cons/vmtcl at offset 4096 is...
authorGanShun <ganshun@gmail.com>
Sat, 26 Sep 2015 22:20:20 +0000 (15:20 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 3 Nov 2015 15:53:13 +0000 (10:53 -0500)
We now get an IPI sent by the consin thread automatically when we press enter

Signed-off-by: GanShun <ganshun@gmail.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/arch/x86/vmm/intel/vmx.c
kern/arch/x86/vmm/vmm.c
kern/arch/x86/vmm/vmm.h
kern/drivers/dev/cons.c
tests/vmm/vmrunkernel.c

index 74ea41b..86ccf58 100644 (file)
@@ -1769,6 +1769,12 @@ static void vmx_set_posted_interrupt(int vector)
 
 */
 
+int vmx_interrupt_notify(struct vmctl *v) {
+       int vm_core = v->core;
+       send_ipi(vm_core, 0xE5);
+       return 0;
+}
+
 /**
  * vmx_launch - the main loop for a VMX Dune process
  * @conf: the launch configuration
@@ -1790,6 +1796,8 @@ int vmx_launch(struct vmctl *v) {
                return -ENOMEM;
        }
 
+       v->core = core_id();
+       printk("Core Id: %d\n", v->core);
        /* We need to prep the host's autoload region for our current core.  Right
         * now, the only autoloaded MSR that varies at runtime (in this case per
         * core is the KERN_GS_BASE). */
index 6d95351..937e140 100644 (file)
@@ -68,6 +68,17 @@ void vmm_pcpu_init(void)
        printk("vmm_pcpu_init failed\n");
 }
 
+int vm_post_interrupt(struct vmctl *v)
+{
+       int vmx_interrupt_notify(struct vmctl *v);
+       if (current->vmm.amd) {
+               return -1;
+       } else {
+               return vmx_interrupt_notify(v);
+       }
+       return -1;
+}
+
 int vm_run(struct vmctl *v)
 {
        int vmx_launch(struct vmctl *v);
index d1965fb..2325e38 100644 (file)
@@ -47,6 +47,7 @@ void vmm_pcpu_init(void);
 int vmm_struct_init(struct proc *p, unsigned int nr_guest_pcores, int flags);
 void __vmm_struct_cleanup(struct proc *p);
 
+int vm_post_interrupt(struct vmctl *v);
 int vm_run(struct vmctl *);
 int intel_vmx_start(int id);
 int intel_vmx_setup(int nvmcs);
index 27431aa..dd25aa5 100644 (file)
@@ -39,6 +39,7 @@
 #include <pmap.h>
 #include <smp.h>
 #include <ip.h>
+#include <monitor.h>
 #include <ros/vmm.h>
 
 struct dev consdevtab;
@@ -1040,10 +1041,17 @@ static long conswrite(struct chan *c, void *va, long n, int64_t offset)
 #endif
                case Qvmctl:
                        memmove(&vmctl, a, sizeof(vmctl));
-                       ret = vm_run(&vmctl);
-                       printd("vm_run returns %d\n", ret);
-                       n = ret;
-                       memmove(a, &vmctl, sizeof(vmctl));
+                       if ((offset >> 12) ==1) {
+                               ret = vm_post_interrupt(&vmctl);
+                               n = ret;
+                               printk("vm_interrupt_notify returns %d\n", ret);
+                       }
+                       else {
+                               ret = vm_run(&vmctl);
+                               printd("vm_run returns %d\n", ret);
+                               n = ret;
+                               memmove(a, &vmctl, sizeof(vmctl));
+                       }
                        break;
                case Qsysctl:
                        //if (!iseve()) error(EPERM, NULL);
index 6046cb0..9262d86 100644 (file)
@@ -242,6 +242,8 @@ void *consin(void *arg)
        uint32_t vv;
        int i;
        int num;
+
+       int fd = open("#cons/vmctl", O_RDWR), ret;
        
        if (debug) fprintf(stderr, "Spin on console being read, print num queues, halt\n");
 
@@ -281,6 +283,8 @@ void *consin(void *arg)
                // Send spurious for testing (Gan)
                set_posted_interrupt(0xE5);
                virtio_mmio_set_vring_irq();
+
+               pwrite(fd, &vmctl, sizeof(vmctl), 1<<12);
        }
        fprintf(stderr, "All done\n");
        return NULL;
@@ -426,7 +430,9 @@ fprintf(stderr, "%p %p %p %p\n", PGSIZE, PGSHIFT, PML1_SHIFT, PML1_PTE_REACH);
        }
 
        memset(a_page, 0, 4096);
-       ((uint32_t *)a_page)[0x30/4] = 0x01060015;
+       //((uint32_t *)a_page)[0x30/4] = 0x01060015;
+       ((uint32_t *)a_page)[0x30/4] = 0xDEADBEEF;
+
 
        if (fd < 0) {
                perror("#cons/sysctl");
@@ -652,7 +658,7 @@ fprintf(stderr, "%p %p %p %p\n", PGSIZE, PGSHIFT, PML1_SHIFT, PML1_PTE_REACH);
        
        vapic_status_dump(stderr, (void *)vmctl.vapic);
 
-       ret = write(fd, &vmctl, sizeof(vmctl));
+       ret = pwrite(fd, &vmctl, sizeof(vmctl), 0);
 
        vapic_status_dump(stderr, (void *)vmctl.vapic);
 
@@ -773,7 +779,7 @@ fprintf(stderr, "%p %p %p %p\n", PGSIZE, PGSHIFT, PML1_SHIFT, PML1_PTE_REACH);
                                vapic_status_dump(stderr, (void *)vmctl.vapic);
                                if (debug)fprintf(stderr, "Resume with consdata ...\n");
                                vmctl.regs.tf_rip += 3;
-                               ret = write(fd, &vmctl, sizeof(vmctl));
+                               ret = pwrite(fd, &vmctl, sizeof(vmctl), 0);
                                if (ret != sizeof(vmctl)) {
                                        perror(cmd);
                                }
@@ -789,7 +795,7 @@ fprintf(stderr, "%p %p %p %p\n", PGSIZE, PGSHIFT, PML1_SHIFT, PML1_PTE_REACH);
                                //debug = 1;
                                if (debug)fprintf(stderr, "Resume with consdata ...\n");
                                vmctl.regs.tf_rip += 1;
-                               ret = write(fd, &vmctl, sizeof(vmctl));
+                               ret = pwrite(fd, &vmctl, sizeof(vmctl), 0);
                                if (ret != sizeof(vmctl)) {
                                        perror(cmd);
                                }
@@ -842,7 +848,7 @@ fprintf(stderr, "%p %p %p %p\n", PGSIZE, PGSHIFT, PML1_SHIFT, PML1_PTE_REACH);
                        vmctl.command = RESUME;
                }
                if (debug) fprintf(stderr, "NOW DO A RESUME\n");
-               ret = write(fd, &vmctl, sizeof(vmctl));
+               ret = pwrite(fd, &vmctl, sizeof(vmctl), 0);
                if (ret != sizeof(vmctl)) {
                        perror(cmd);
                }