diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2007-10-21 21:03:26 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2007-10-23 01:49:50 -0400 |
commit | 3c6b5bfa3cf3b4057788e08482a468cc3bc00780 (patch) | |
tree | f0d67890f6f8c9d0840c9b19a483ec06cbf822ef /drivers/lguest/core.c | |
parent | 6649bb7af6a819b675bfcf22ab704737e905645a (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/core.c')
-rw-r--r-- | drivers/lguest/core.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c index a0788c12b392..eb95860cf098 100644 --- a/drivers/lguest/core.c +++ b/drivers/lguest/core.c | |||
@@ -325,8 +325,8 @@ static int emulate_insn(struct lguest *lg) | |||
325 | * Dealing With Guest Memory. | 325 | * Dealing With Guest Memory. |
326 | * | 326 | * |
327 | * When the Guest gives us (what it thinks is) a physical address, we can use | 327 | * When the Guest gives us (what it thinks is) a physical address, we can use |
328 | * the normal copy_from_user() & copy_to_user() on that address: remember, | 328 | * the normal copy_from_user() & copy_to_user() on the corresponding place in |
329 | * Guest physical == Launcher virtual. | 329 | * the memory region allocated by the Launcher. |
330 | * | 330 | * |
331 | * But we can't trust the Guest: it might be trying to access the Launcher | 331 | * But we can't trust the Guest: it might be trying to access the Launcher |
332 | * code. We have to check that the range is below the pfn_limit the Launcher | 332 | * code. We have to check that the range is below the pfn_limit the Launcher |
@@ -348,8 +348,8 @@ u32 lgread_u32(struct lguest *lg, unsigned long addr) | |||
348 | 348 | ||
349 | /* Don't let them access lguest binary. */ | 349 | /* Don't let them access lguest binary. */ |
350 | if (!lguest_address_ok(lg, addr, sizeof(val)) | 350 | if (!lguest_address_ok(lg, addr, sizeof(val)) |
351 | || get_user(val, (u32 __user *)addr) != 0) | 351 | || get_user(val, (u32 *)(lg->mem_base + addr)) != 0) |
352 | kill_guest(lg, "bad read address %#lx", addr); | 352 | kill_guest(lg, "bad read address %#lx: pfn_limit=%u membase=%p", addr, lg->pfn_limit, lg->mem_base); |
353 | return val; | 353 | return val; |
354 | } | 354 | } |
355 | 355 | ||
@@ -357,7 +357,7 @@ u32 lgread_u32(struct lguest *lg, unsigned long addr) | |||
357 | void lgwrite_u32(struct lguest *lg, unsigned long addr, u32 val) | 357 | void lgwrite_u32(struct lguest *lg, unsigned long addr, u32 val) |
358 | { | 358 | { |
359 | if (!lguest_address_ok(lg, addr, sizeof(val)) | 359 | if (!lguest_address_ok(lg, addr, sizeof(val)) |
360 | || put_user(val, (u32 __user *)addr) != 0) | 360 | || put_user(val, (u32 *)(lg->mem_base + addr)) != 0) |
361 | kill_guest(lg, "bad write address %#lx", addr); | 361 | kill_guest(lg, "bad write address %#lx", addr); |
362 | } | 362 | } |
363 | 363 | ||
@@ -367,7 +367,7 @@ void lgwrite_u32(struct lguest *lg, unsigned long addr, u32 val) | |||
367 | void lgread(struct lguest *lg, void *b, unsigned long addr, unsigned bytes) | 367 | void lgread(struct lguest *lg, void *b, unsigned long addr, unsigned bytes) |
368 | { | 368 | { |
369 | if (!lguest_address_ok(lg, addr, bytes) | 369 | if (!lguest_address_ok(lg, addr, bytes) |
370 | || copy_from_user(b, (void __user *)addr, bytes) != 0) { | 370 | || copy_from_user(b, lg->mem_base + addr, bytes) != 0) { |
371 | /* copy_from_user should do this, but as we rely on it... */ | 371 | /* copy_from_user should do this, but as we rely on it... */ |
372 | memset(b, 0, bytes); | 372 | memset(b, 0, bytes); |
373 | kill_guest(lg, "bad read address %#lx len %u", addr, bytes); | 373 | kill_guest(lg, "bad read address %#lx len %u", addr, bytes); |
@@ -379,7 +379,7 @@ void lgwrite(struct lguest *lg, unsigned long addr, const void *b, | |||
379 | unsigned bytes) | 379 | unsigned bytes) |
380 | { | 380 | { |
381 | if (!lguest_address_ok(lg, addr, bytes) | 381 | if (!lguest_address_ok(lg, addr, bytes) |
382 | || copy_to_user((void __user *)addr, b, bytes) != 0) | 382 | || copy_to_user(lg->mem_base + addr, b, bytes) != 0) |
383 | kill_guest(lg, "bad write address %#lx len %u", addr, bytes); | 383 | kill_guest(lg, "bad write address %#lx len %u", addr, bytes); |
384 | } | 384 | } |
385 | /* (end of memory access helper routines) :*/ | 385 | /* (end of memory access helper routines) :*/ |
@@ -616,11 +616,9 @@ int run_guest(struct lguest *lg, unsigned long __user *user) | |||
616 | * | 616 | * |
617 | * Note that if the Guest were really messed up, this | 617 | * Note that if the Guest were really messed up, this |
618 | * could happen before it's done the INITIALIZE | 618 | * could happen before it's done the INITIALIZE |
619 | * hypercall, so lg->lguest_data will be NULL, so | 619 | * hypercall, so lg->lguest_data will be NULL */ |
620 | * &lg->lguest_data->cr2 will be address 8. Writing | 620 | if (lg->lguest_data |
621 | * into that address won't hurt the Host at all, | 621 | && put_user(cr2, &lg->lguest_data->cr2)) |
622 | * though. */ | ||
623 | if (put_user(cr2, &lg->lguest_data->cr2)) | ||
624 | kill_guest(lg, "Writing cr2"); | 622 | kill_guest(lg, "Writing cr2"); |
625 | break; | 623 | break; |
626 | case 7: /* We've intercepted a Device Not Available fault. */ | 624 | case 7: /* We've intercepted a Device Not Available fault. */ |