Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel' of palacios@newskysaw.cs.northwestern.edu:/home/palacios/palacio...
[palacios.git] / linux_module / palacios-dev.c
index 585e807..f640403 100644 (file)
 #include "palacios.h"
 #include "palacios-mm.h"
 #include "palacios-vm.h"
-#include "palacios-stream.h"
-#include "palacios-file.h"
-#include "palacios-serial.h"
+
+#include "linux-exts.h"
+
+
 
 MODULE_LICENSE("GPL");
 
+int mod_allocs = 0;
+int mod_frees = 0;
+
 
 static int v3_major_num = 0;
 
@@ -36,9 +40,6 @@ static u8 v3_minor_map[MAX_VMS / 8] = {[0 ... (MAX_VMS / 8) - 1] = 0};
 struct class * v3_class = NULL;
 static struct cdev ctrl_dev;
 
-void * v3_base_addr = NULL;
-unsigned int v3_pages = 0;
-
 static int register_vm( void ) {
     int i, j = 0;
     int avail = 0;
@@ -46,7 +47,7 @@ static int register_vm( void ) {
     for (i = 0; i < sizeof(v3_minor_map); i++) {
        if (v3_minor_map[i] != 0xff) {
            for (j = 0; j < 8; j++) {
-               if (!v3_minor_map[i] & (0x1 << j)) {
+               if (!(v3_minor_map[i] & (0x1 << j))) {
                    avail = 1;
                    v3_minor_map[i] |= (0x1 << j);
                    break;
@@ -76,9 +77,9 @@ static long v3_dev_ioctl(struct file * filp,
 
     switch (ioctl) {
        case V3_START_GUEST:{
+           int vm_minor = 0;
            struct v3_guest_img user_image;
            struct v3_guest * guest = kmalloc(sizeof(struct v3_guest), GFP_KERNEL);
-           int vm_minor = 0;
 
            if (IS_ERR(guest)) {
                printk("Error allocating Kernel guest_image\n");
@@ -106,7 +107,7 @@ static long v3_dev_ioctl(struct file * filp,
            guest->img_size = user_image.size;
 
            printk("Allocating kernel memory for guest image (%llu bytes)\n", user_image.size);
-           guest->img = kmalloc(guest->img_size, GFP_KERNEL);
+           guest->img = vmalloc(guest->img_size);
 
            if (IS_ERR(guest->img)) {
                printk("Error: Could not allocate space for guest image\n");
@@ -122,14 +123,32 @@ static long v3_dev_ioctl(struct file * filp,
 
            printk("Launching VM\n");
 
-           INIT_LIST_HEAD(&(guest->streams));
-           INIT_LIST_HEAD(&(guest->files));
-           INIT_LIST_HEAD(&(guest->sockets));
+           INIT_LIST_HEAD(&(guest->exts));
+
+           init_completion(&(guest->start_done));
            init_completion(&(guest->thread_done));
 
-           kthread_run(start_palacios_vm, guest, guest->name);
+           { 
+               struct task_struct * launch_thread = NULL;
+               // At some point we're going to want to allow the user to specify a CPU mask
+               // But for now, well just launch from the local core, and rely on the global cpu mask
+
+               preempt_disable();
+               launch_thread = kthread_create(start_palacios_vm, guest, guest->name);
+               
+               if (IS_ERR(launch_thread)) {
+                   preempt_enable();
+                   printk("Palacios error creating launch thread for vm (%s)\n", guest->name);
+                   return -EFAULT;
+               }
+
+               kthread_bind(launch_thread, smp_processor_id());
+               preempt_enable();
 
-           wait_for_completion(&(guest->thread_done));
+               wake_up_process(launch_thread);
+           }
+
+           wait_for_completion(&(guest->start_done));
 
            return guest->vm_dev;
            break;
@@ -151,16 +170,9 @@ static long v3_dev_ioctl(struct file * filp,
                return -EFAULT;
            }
 
-           // Mem test...
-           /*
-             {
-             void * vaddr = __va(alloc_palacios_pgs(131072, 4096));
-             memset(vaddr, 0xfe492fe2, mem.num_pages * 4096);
-             }
-           */
-
            break;
        }
+
        default: 
            printk("\tUnhandled\n");
            return -EINVAL;
@@ -178,8 +190,6 @@ static struct file_operations v3_ctrl_fops = {
 };
 
 
-extern unsigned int v3_pages;
-extern void * v3_base_addr;
 
 static int __init v3_init(void) {
     dev_t dev = MKDEV(0, 0); // We dynamicallly assign the major number
@@ -188,6 +198,16 @@ static int __init v3_init(void) {
 
     palacios_init_mm();
 
+
+    // Initialize Palacios
+    
+    palacios_vmm_init();
+
+
+    // initialize extensions
+    init_lnx_extensions();
+
+
     v3_class = class_create(THIS_MODULE, "vms");
     if (IS_ERR(v3_class)) {
        printk("Failed to register V3 VM device class\n");
@@ -221,18 +241,6 @@ static int __init v3_init(void) {
        goto failure1;
     }
 
-    if ((v3_pages > 0) && (v3_base_addr != NULL)) {
-       add_palacios_memory(__pa(v3_base_addr), v3_pages);
-    }
-
-    // Initialize Palacios
-    
-    palacios_vmm_init();
-
-    palacios_init_stream();
-    palacios_file_init();
-    palacios_init_console();
-    
 
 
     return 0;
@@ -245,25 +253,61 @@ static int __init v3_init(void) {
     return ret;
 }
 
+
 static void __exit v3_exit(void) {
     extern u32 pg_allocs;
     extern u32 pg_frees;
     extern u32 mallocs;
     extern u32 frees;
 
+
+    // should probably try to stop any guests
+
+
+
+    dev_t dev = MKDEV(v3_major_num, MAX_VMS + 1);
+
     printk("Removing V3 Control device\n");
 
-    palacios_vmm_exit();
 
+    palacios_vmm_exit();
 
     printk("Palacios Mallocs = %d, Frees = %d\n", mallocs, frees);
     printk("Palacios Page Allocs = %d, Page Frees = %d\n", pg_allocs, pg_frees);
 
-
     unregister_chrdev_region(MKDEV(v3_major_num, 0), MAX_VMS + 1);
+
+    cdev_del(&ctrl_dev);
+
+    device_destroy(v3_class, dev);
+    class_destroy(v3_class);
+
+
+    deinit_lnx_extensions();
+
+    palacios_deinit_mm();
+
+    printk("Palacios Module Mallocs = %d, Frees = %d\n", mod_allocs, mod_frees);
 }
 
 
 
 module_init(v3_init);
 module_exit(v3_exit);
+
+
+
+void * trace_malloc(size_t size, gfp_t flags) {
+    void * addr = NULL;
+
+    mod_allocs++;
+    addr = kmalloc(size, flags);
+
+    return addr;
+}
+
+
+void trace_free(const void * objp) {
+    mod_frees++;
+    kfree(objp);
+}