aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2015-02-10 23:45:09 -0500
committerRusty Russell <rusty@rustcorp.com.au>2015-02-11 01:17:30 -0500
commit8ed313001a892f240269dea05d4b925cbd150492 (patch)
tree340461d5b381ffc3b939bb6d414f20a732ff85c5
parent69a09dc1742ffbb3b02f3a1e03da4801e96452e9 (diff)
lguest: add infrastructure for userspace to deliver a trap to the guest.
This is required for instruction emulation to move to userspace. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r--drivers/lguest/lguest_user.c19
-rw-r--r--include/linux/lguest_launcher.h1
2 files changed, 20 insertions, 0 deletions
diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
index dcf9efd94cf4..be996d173615 100644
--- a/drivers/lguest/lguest_user.c
+++ b/drivers/lguest/lguest_user.c
@@ -243,6 +243,23 @@ static int user_send_irq(struct lg_cpu *cpu, const unsigned long __user *input)
243 return 0; 243 return 0;
244} 244}
245 245
246/*L:053
247 * Deliver a trap: this is used by the Launcher if it can't emulate
248 * an instruction.
249 */
250static int trap(struct lg_cpu *cpu, const unsigned long __user *input)
251{
252 unsigned long trapnum;
253
254 if (get_user(trapnum, input) != 0)
255 return -EFAULT;
256
257 if (!deliver_trap(cpu, trapnum))
258 return -EINVAL;
259
260 return 0;
261}
262
246/*L:040 263/*L:040
247 * Once our Guest is initialized, the Launcher makes it run by reading 264 * Once our Guest is initialized, the Launcher makes it run by reading
248 * from /dev/lguest. 265 * from /dev/lguest.
@@ -487,6 +504,8 @@ static ssize_t write(struct file *file, const char __user *in,
487 return getreg_setup(cpu, input); 504 return getreg_setup(cpu, input);
488 case LHREQ_SETREG: 505 case LHREQ_SETREG:
489 return setreg(cpu, input); 506 return setreg(cpu, input);
507 case LHREQ_TRAP:
508 return trap(cpu, input);
490 default: 509 default:
491 return -EINVAL; 510 return -EINVAL;
492 } 511 }
diff --git a/include/linux/lguest_launcher.h b/include/linux/lguest_launcher.h
index c4451ebece47..3c402b843e03 100644
--- a/include/linux/lguest_launcher.h
+++ b/include/linux/lguest_launcher.h
@@ -65,6 +65,7 @@ enum lguest_req
65 LHREQ_EVENTFD, /* + address, fd. */ 65 LHREQ_EVENTFD, /* + address, fd. */
66 LHREQ_GETREG, /* + offset within struct pt_regs (then read value). */ 66 LHREQ_GETREG, /* + offset within struct pt_regs (then read value). */
67 LHREQ_SETREG, /* + offset within struct pt_regs, value. */ 67 LHREQ_SETREG, /* + offset within struct pt_regs, value. */
68 LHREQ_TRAP, /* + trap number to deliver to guest. */
68}; 69};
69 70
70/* 71/*