After ACRN hypervisor captures the io_request(mmio, IO, PCI access) from
guest OS, it will send the IRQ interrupt to SOS system.
The HYPERVISOR_CALLBACK_VECTOR ISR handler will be executed and it
needs to call the driver-specific ISR handler to dispatch emulated
io_request.
After the emulation of ioreq request is finished, the ACRN hypervisor
is notified and then can resume the execution of guest OS.

Co-developed-by: Jason Chen CJ <jason.cj.c...@intel.com>
Signed-off-by: Jason Chen CJ <jason.cj.c...@intel.com>
Co-developed-by: Mingqiang Chi <mingqiang....@intel.com>
Signed-off-by: Mingqiang Chi <mingqiang....@intel.com>
Co-developed-by: Liu Shuo <shuo.a....@intel.com>
Signed-off-by: Liu Shuo <shuo.a....@intel.com>
Signed-off-by: Zhao Yakui <yakui.z...@intel.com>
---
 drivers/staging/acrn/acrn_dev.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c
index 28258fb..93f45e3 100644
--- a/drivers/staging/acrn/acrn_dev.c
+++ b/drivers/staging/acrn/acrn_dev.c
@@ -18,6 +18,7 @@
 #include <linux/kdev_t.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/mm.h>
 #include <linux/module.h>
@@ -41,6 +42,7 @@ static int    acrn_hsm_inited;
 static int     major;
 static struct class    *acrn_class;
 static struct device   *acrn_device;
+static struct tasklet_struct acrn_io_req_tasklet;
 
 static
 int acrn_dev_open(struct inode *inodep, struct file *filep)
@@ -416,6 +418,16 @@ long acrn_dev_ioctl(struct file *filep,
                break;
        }
        case IC_CLEAR_VM_IOREQ: {
+               /*
+                * we need to flush the current pending ioreq dispatch
+                * tasklet and finish it before clearing all ioreq of this VM.
+                * With tasklet_kill, there still be a very rare race which
+                * might lost one ioreq tasklet for other VMs. So arm one after
+                * the clearing. It's harmless.
+                */
+               tasklet_schedule(&acrn_io_req_tasklet);
+               tasklet_kill(&acrn_io_req_tasklet);
+               tasklet_schedule(&acrn_io_req_tasklet);
                acrn_ioreq_clear_request(vm);
                break;
        }
@@ -449,6 +461,28 @@ static int acrn_dev_release(struct inode *inodep, struct 
file *filep)
        return 0;
 }
 
+static void io_req_tasklet(unsigned long data)
+{
+       struct acrn_vm *vm;
+       /* This is already in tasklet. Use read_lock for list_lock */
+
+       read_lock(&acrn_vm_list_lock);
+       list_for_each_entry(vm, &acrn_vm_list, list) {
+               if (!vm || !vm->req_buf)
+                       break;
+
+               get_vm(vm);
+               acrn_ioreq_distribute_request(vm);
+               put_vm(vm);
+       }
+       read_unlock(&acrn_vm_list_lock);
+}
+
+static void acrn_intr_handler(void)
+{
+       tasklet_schedule(&acrn_io_req_tasklet);
+}
+
 static const struct file_operations fops = {
        .open = acrn_dev_open,
        .release = acrn_dev_release,
@@ -462,6 +496,7 @@ static const struct file_operations fops = {
 
 static int __init acrn_init(void)
 {
+       unsigned long flag;
        struct api_version *api_version;
        acrn_hsm_inited = 0;
        if (x86_hyper_type != X86_HYPER_ACRN)
@@ -518,6 +553,10 @@ static int __init acrn_init(void)
                return PTR_ERR(acrn_device);
        }
 
+       tasklet_init(&acrn_io_req_tasklet, io_req_tasklet, 0);
+       local_irq_save(flag);
+       acrn_setup_intr_irq(acrn_intr_handler);
+       local_irq_restore(flag);
        acrn_ioreq_driver_init();
        pr_info("acrn: ACRN Hypervisor service module initialized\n");
        acrn_hsm_inited = 1;
@@ -529,6 +568,8 @@ static void __exit acrn_exit(void)
        if (!acrn_hsm_inited)
                return;
 
+       tasklet_kill(&acrn_io_req_tasklet);
+       acrn_remove_intr_irq();
        device_destroy(acrn_class, MKDEV(major, 0));
        class_unregister(acrn_class);
        class_destroy(acrn_class);
-- 
2.7.4

_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to