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.


added state checks for VM control commands
[palacios.releases.git] / palacios / src / palacios / vmm_intr.c
index 48e46ea..06d5254 100644 (file)
@@ -98,6 +98,11 @@ void v3_deinit_intr_routers(struct v3_vm_info * vm) {
 void * v3_register_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * priv_data) {
     struct intr_controller * ctrlr = (struct intr_controller *)V3_Malloc(sizeof(struct intr_controller));
 
+    if (!ctrlr) {
+       PrintError("Cannot allocate in registering an interrupt controller\n");
+       return NULL;
+    }
+
     ctrlr->priv_data = priv_data;
     ctrlr->ctrl_ops = ops;
 
@@ -131,6 +136,11 @@ void v3_remove_intr_controller(struct guest_info * core, void * handle) {
 void * v3_register_intr_router(struct v3_vm_info * vm, struct intr_router_ops * ops, void * priv_data) {
     struct intr_router * router = (struct intr_router *)V3_Malloc(sizeof(struct intr_router));
 
+    if (!router) {
+       PrintError("Cannot allocate in registering an interrupt router\n");
+       return NULL;
+    }
+
     router->priv_data = priv_data;
     router->router_ops = ops;
 
@@ -175,12 +185,15 @@ int v3_hook_irq(struct v3_vm_info * vm,
 {
     struct v3_irq_hook * hook = (struct v3_irq_hook *)V3_Malloc(sizeof(struct v3_irq_hook));
 
+
     if (hook == NULL) { 
+       PrintError("Cannot allocate when hooking an irq\n");
        return -1; 
     }
 
     if (get_irq_hook(vm, irq) != NULL) {
        PrintError("IRQ %d already hooked\n", irq);
+       V3_Free(hook);
        return -1;
     }
 
@@ -191,6 +204,8 @@ int v3_hook_irq(struct v3_vm_info * vm,
 
     if (V3_Hook_Interrupt(vm, irq)) { 
        PrintError("hook_irq: failed to hook irq %d\n", irq);
+       vm->intr_routers.hooks[irq] = NULL;
+       V3_Free(hook);
        return -1;
     } else {
        PrintDebug("hook_irq: hooked irq %d\n", irq);
@@ -347,7 +362,15 @@ v3_intr_type_t v3_intr_pending(struct guest_info * info) {
     //  PrintDebug("[intr_pending]\n");
     addr_t irq_state = v3_lock_irqsave(intr_state->irq_lock);
 
-    // VIRQs have priority
+    // External IRQs have lowest priority
+    list_for_each_entry(ctrl, &(intr_state->controller_list), ctrl_node) {
+       if (ctrl->ctrl_ops->intr_pending(info, ctrl->priv_data) == 1) {
+           ret = V3_EXTERNAL_IRQ;
+           break;
+       }
+    }   
+
+    // VIRQs have 2nd priority
     for (i = 0; i < MAX_IRQ / 8; i++) {
        if (intr_state->virq_map[i] != 0) {   
            ret = V3_VIRTUAL_IRQ;
@@ -355,16 +378,7 @@ v3_intr_type_t v3_intr_pending(struct guest_info * info) {
        }
     }
 
-    if (ret == V3_INVALID_INTR) {
-       list_for_each_entry(ctrl, &(intr_state->controller_list), ctrl_node) {
-           if (ctrl->ctrl_ops->intr_pending(info, ctrl->priv_data) == 1) {
-               ret = V3_EXTERNAL_IRQ;
-               break;
-           }
-       }
-    }
-    
-    /* for swintr injection */
+    /* SWINTRs have highest */
     if (intr_state->swintr_posted == 1) {
         ret = V3_SOFTWARE_INTR;
     }