aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/lguest/lguest_user.c
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2007-10-21 21:03:26 -0400
committerRusty Russell <rusty@rustcorp.com.au>2007-10-23 01:49:50 -0400
commit3c6b5bfa3cf3b4057788e08482a468cc3bc00780 (patch)
treef0d67890f6f8c9d0840c9b19a483ec06cbf822ef /drivers/lguest/lguest_user.c
parent6649bb7af6a819b675bfcf22ab704737e905645a (diff)
Introduce guest mem offset, static link example launcher
In order to avoid problematic special linking of the Launcher, we give the Host an offset: this means we can use any memory region in the Launcher as Guest memory rather than insisting on mmap() at 0. The result is quite pleasing: a number of casts are replaced with simple additions. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/lguest/lguest_user.c')
-rw-r--r--drivers/lguest/lguest_user.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
index 80d1b58c7698..816d4d12a801 100644
--- a/drivers/lguest/lguest_user.c
+++ b/drivers/lguest/lguest_user.c
@@ -1,9 +1,9 @@
1/*P:200 This contains all the /dev/lguest code, whereby the userspace launcher 1/*P:200 This contains all the /dev/lguest code, whereby the userspace launcher
2 * controls and communicates with the Guest. For example, the first write will 2 * controls and communicates with the Guest. For example, the first write will
3 * tell us the memory size, pagetable, entry point and kernel address offset. 3 * tell us the Guest's memory layout, pagetable, entry point and kernel address
4 * A read will run the Guest until a signal is pending (-EINTR), or the Guest 4 * offset. A read will run the Guest until something happens, such as a signal
5 * does a DMA out to the Launcher. Writes are also used to get a DMA buffer 5 * or the Guest doing a DMA out to the Launcher. Writes are also used to get a
6 * registered by the Guest and to send the Guest an interrupt. :*/ 6 * DMA buffer registered by the Guest and to send the Guest an interrupt. :*/
7#include <linux/uaccess.h> 7#include <linux/uaccess.h>
8#include <linux/miscdevice.h> 8#include <linux/miscdevice.h>
9#include <linux/fs.h> 9#include <linux/fs.h>
@@ -142,9 +142,11 @@ static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o)
142 return run_guest(lg, (unsigned long __user *)user); 142 return run_guest(lg, (unsigned long __user *)user);
143} 143}
144 144
145/*L:020 The initialization write supplies 4 32-bit values (in addition to the 145/*L:020 The initialization write supplies 5 32-bit values (in addition to the
146 * 32-bit LHREQ_INITIALIZE value). These are: 146 * 32-bit LHREQ_INITIALIZE value). These are:
147 * 147 *
148 * base: The start of the Guest-physical memory inside the Launcher memory.
149 *
148 * pfnlimit: The highest (Guest-physical) page number the Guest should be 150 * pfnlimit: The highest (Guest-physical) page number the Guest should be
149 * allowed to access. The Launcher has to live in Guest memory, so it sets 151 * allowed to access. The Launcher has to live in Guest memory, so it sets
150 * this to ensure the Guest can't reach it. 152 * this to ensure the Guest can't reach it.
@@ -166,7 +168,7 @@ static int initialize(struct file *file, const u32 __user *input)
166 * Guest. */ 168 * Guest. */
167 struct lguest *lg; 169 struct lguest *lg;
168 int err, i; 170 int err, i;
169 u32 args[4]; 171 u32 args[5];
170 172
171 /* We grab the Big Lguest lock, which protects the global array 173 /* We grab the Big Lguest lock, which protects the global array
172 * "lguests" and multiple simultaneous initializations. */ 174 * "lguests" and multiple simultaneous initializations. */
@@ -194,8 +196,9 @@ static int initialize(struct file *file, const u32 __user *input)
194 196
195 /* Populate the easy fields of our "struct lguest" */ 197 /* Populate the easy fields of our "struct lguest" */
196 lg->guestid = i; 198 lg->guestid = i;
197 lg->pfn_limit = args[0]; 199 lg->mem_base = (void __user *)(long)args[0];
198 lg->page_offset = args[3]; 200 lg->pfn_limit = args[1];
201 lg->page_offset = args[4];
199 202
200 /* We need a complete page for the Guest registers: they are accessible 203 /* We need a complete page for the Guest registers: they are accessible
201 * to the Guest and we can only grant it access to whole pages. */ 204 * to the Guest and we can only grant it access to whole pages. */
@@ -210,13 +213,13 @@ static int initialize(struct file *file, const u32 __user *input)
210 /* Initialize the Guest's shadow page tables, using the toplevel 213 /* Initialize the Guest's shadow page tables, using the toplevel
211 * address the Launcher gave us. This allocates memory, so can 214 * address the Launcher gave us. This allocates memory, so can
212 * fail. */ 215 * fail. */
213 err = init_guest_pagetable(lg, args[1]); 216 err = init_guest_pagetable(lg, args[2]);
214 if (err) 217 if (err)
215 goto free_regs; 218 goto free_regs;
216 219
217 /* Now we initialize the Guest's registers, handing it the start 220 /* Now we initialize the Guest's registers, handing it the start
218 * address. */ 221 * address. */
219 setup_regs(lg->regs, args[2]); 222 setup_regs(lg->regs, args[3]);
220 223
221 /* There are a couple of GDT entries the Guest expects when first 224 /* There are a couple of GDT entries the Guest expects when first
222 * booting. */ 225 * booting. */