lguest: add infrastructure for userspace to deliver a trap to the guest.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 11 Feb 2015 04:45:09 +0000 (15:15 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 11 Feb 2015 06:17:30 +0000 (16:47 +1030)
This is required for instruction emulation to move to userspace.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
drivers/lguest/lguest_user.c
include/linux/lguest_launcher.h

index dcf9efd94cf4094195d98d41a354b9cc474b2f06..be996d1736151882575a4f500a4dba4fa045775d 100644 (file)
@@ -243,6 +243,23 @@ static int user_send_irq(struct lg_cpu *cpu, const unsigned long __user *input)
        return 0;
 }
 
+/*L:053
+ * Deliver a trap: this is used by the Launcher if it can't emulate
+ * an instruction.
+ */
+static int trap(struct lg_cpu *cpu, const unsigned long __user *input)
+{
+       unsigned long trapnum;
+
+       if (get_user(trapnum, input) != 0)
+               return -EFAULT;
+
+       if (!deliver_trap(cpu, trapnum))
+               return -EINVAL;
+
+       return 0;
+}
+
 /*L:040
  * Once our Guest is initialized, the Launcher makes it run by reading
  * from /dev/lguest.
@@ -487,6 +504,8 @@ static ssize_t write(struct file *file, const char __user *in,
                return getreg_setup(cpu, input);
        case LHREQ_SETREG:
                return setreg(cpu, input);
+       case LHREQ_TRAP:
+               return trap(cpu, input);
        default:
                return -EINVAL;
        }
index c4451ebece4713e320c5336a99df3713a556b067..3c402b843e03c2a0343b3fe025ee2254e1c4eb32 100644 (file)
@@ -65,6 +65,7 @@ enum lguest_req
        LHREQ_EVENTFD, /* + address, fd. */
        LHREQ_GETREG, /* + offset within struct pt_regs (then read value). */
        LHREQ_SETREG, /* + offset within struct pt_regs, value. */
+       LHREQ_TRAP, /* + trap number to deliver to guest. */
 };
 
 /*