]> err.no Git - linux-2.6/blobdiff - drivers/lguest/lguest_user.c
lguest: per-vcpu lguest timers
[linux-2.6] / drivers / lguest / lguest_user.c
index 9d716fa42cad39f00dc2e20cdc364c752679409e..f231b9be0b643bc0784d7976cb3980b7974f961b 100644 (file)
@@ -55,11 +55,19 @@ static int user_send_irq(struct lguest *lg, const unsigned long __user *input)
 static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o)
 {
        struct lguest *lg = file->private_data;
+       struct lg_cpu *cpu;
+       unsigned int cpu_id = *o;
 
        /* You must write LHREQ_INITIALIZE first! */
        if (!lg)
                return -EINVAL;
 
+       /* Watch out for arbitrary vcpu indexes! */
+       if (cpu_id >= lg->nr_cpus)
+               return -EINVAL;
+
+       cpu = &lg->cpus[cpu_id];
+
        /* If you're not the task which owns the Guest, go away. */
        if (current != lg->tsk)
                return -EPERM;
@@ -85,7 +93,20 @@ static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o)
                lg->pending_notify = 0;
 
        /* Run the Guest until something interesting happens. */
-       return run_guest(lg, (unsigned long __user *)user);
+       return run_guest(cpu, (unsigned long __user *)user);
+}
+
+static int lg_cpu_start(struct lg_cpu *cpu, unsigned id, unsigned long start_ip)
+{
+       if (id >= NR_CPUS)
+               return -EINVAL;
+
+       cpu->id = id;
+       cpu->lg = container_of((cpu - id), struct lguest, cpus[0]);
+       cpu->lg->nr_cpus++;
+       init_clockdev(cpu);
+
+       return 0;
 }
 
 /*L:020 The initialization write supplies 4 pointer sized (32 or 64 bit)
@@ -134,6 +155,11 @@ static int initialize(struct file *file, const unsigned long __user *input)
        lg->mem_base = (void __user *)(long)args[0];
        lg->pfn_limit = args[1];
 
+       /* This is the first cpu */
+       err = lg_cpu_start(&lg->cpus[0], 0, args[3]);
+       if (err)
+               goto release_guest;
+
        /* We need a complete page for the Guest registers: they are accessible
         * to the Guest and we can only grant it access to whole pages. */
        lg->regs_page = get_zeroed_page(GFP_KERNEL);
@@ -155,9 +181,6 @@ static int initialize(struct file *file, const unsigned long __user *input)
         * address. */
        lguest_arch_setup_regs(lg, args[3]);
 
-       /* The timer for lguest's clock needs initialization. */
-       init_clockdev(lg);
-
        /* We keep a pointer to the Launcher task (ie. current task) for when
         * other Guests want to wake this one (inter-Guest I/O). */
        lg->tsk = current;
@@ -184,7 +207,7 @@ static int initialize(struct file *file, const unsigned long __user *input)
 free_regs:
        free_page(lg->regs_page);
 release_guest:
-       memset(lg, 0, sizeof(*lg));
+       kfree(lg);
 unlock:
        mutex_unlock(&lguest_lock);
        return err;
@@ -202,14 +225,21 @@ static ssize_t write(struct file *file, const char __user *in,
        struct lguest *lg = file->private_data;
        const unsigned long __user *input = (const unsigned long __user *)in;
        unsigned long req;
+       struct lg_cpu *cpu;
+       unsigned int cpu_id = *off;
 
        if (get_user(req, input) != 0)
                return -EFAULT;
        input++;
 
        /* If you haven't initialized, you must do that first. */
-       if (req != LHREQ_INITIALIZE && !lg)
-               return -EINVAL;
+       if (req != LHREQ_INITIALIZE) {
+               if (!lg || (cpu_id >= lg->nr_cpus))
+                       return -EINVAL;
+               cpu = &lg->cpus[cpu_id];
+               if (!cpu)
+                       return -EINVAL;
+       }
 
        /* Once the Guest is dead, all you can do is read() why it died. */
        if (lg && lg->dead)
@@ -241,6 +271,7 @@ static ssize_t write(struct file *file, const char __user *in,
 static int close(struct inode *inode, struct file *file)
 {
        struct lguest *lg = file->private_data;
+       unsigned int i;
 
        /* If we never successfully initialized, there's nothing to clean up */
        if (!lg)
@@ -249,8 +280,9 @@ static int close(struct inode *inode, struct file *file)
        /* We need the big lock, to protect from inter-guest I/O and other
         * Launchers initializing guests. */
        mutex_lock(&lguest_lock);
-       /* Cancels the hrtimer set via LHCALL_SET_CLOCKEVENT. */
-       hrtimer_cancel(&lg->hrt);
+       for (i = 0; i < lg->nr_cpus; i++)
+               /* Cancels the hrtimer set via LHCALL_SET_CLOCKEVENT. */
+               hrtimer_cancel(&lg->cpus[i].hrt);
        /* Free up the shadow page tables for the Guest. */
        free_guest_pagetable(lg);
        /* Now all the memory cleanups are done, it's safe to release the