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/io.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/io.c')
-rw-r--r-- | drivers/lguest/io.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/drivers/lguest/io.c b/drivers/lguest/io.c index ea68613b43f6..3a845335fee8 100644 --- a/drivers/lguest/io.c +++ b/drivers/lguest/io.c | |||
@@ -186,7 +186,7 @@ int bind_dma(struct lguest *lg, | |||
186 | * we're doing this. */ | 186 | * we're doing this. */ |
187 | mutex_lock(&lguest_lock); | 187 | mutex_lock(&lguest_lock); |
188 | down_read(fshared); | 188 | down_read(fshared); |
189 | if (get_futex_key((u32 __user *)ukey, fshared, &key) != 0) { | 189 | if (get_futex_key(lg->mem_base + ukey, fshared, &key) != 0) { |
190 | kill_guest(lg, "bad dma key %#lx", ukey); | 190 | kill_guest(lg, "bad dma key %#lx", ukey); |
191 | goto unlock; | 191 | goto unlock; |
192 | } | 192 | } |
@@ -247,7 +247,8 @@ static int lgread_other(struct lguest *lg, | |||
247 | void *buf, u32 addr, unsigned bytes) | 247 | void *buf, u32 addr, unsigned bytes) |
248 | { | 248 | { |
249 | if (!lguest_address_ok(lg, addr, bytes) | 249 | if (!lguest_address_ok(lg, addr, bytes) |
250 | || access_process_vm(lg->tsk, addr, buf, bytes, 0) != bytes) { | 250 | || access_process_vm(lg->tsk, (unsigned long)lg->mem_base + addr, |
251 | buf, bytes, 0) != bytes) { | ||
251 | memset(buf, 0, bytes); | 252 | memset(buf, 0, bytes); |
252 | kill_guest(lg, "bad address in registered DMA struct"); | 253 | kill_guest(lg, "bad address in registered DMA struct"); |
253 | return 0; | 254 | return 0; |
@@ -261,8 +262,8 @@ static int lgwrite_other(struct lguest *lg, u32 addr, | |||
261 | const void *buf, unsigned bytes) | 262 | const void *buf, unsigned bytes) |
262 | { | 263 | { |
263 | if (!lguest_address_ok(lg, addr, bytes) | 264 | if (!lguest_address_ok(lg, addr, bytes) |
264 | || (access_process_vm(lg->tsk, addr, (void *)buf, bytes, 1) | 265 | || access_process_vm(lg->tsk, (unsigned long)lg->mem_base + addr, |
265 | != bytes)) { | 266 | (void *)buf, bytes, 1) != bytes) { |
266 | kill_guest(lg, "bad address writing to registered DMA"); | 267 | kill_guest(lg, "bad address writing to registered DMA"); |
267 | return 0; | 268 | return 0; |
268 | } | 269 | } |
@@ -318,7 +319,7 @@ static u32 copy_data(struct lguest *srclg, | |||
318 | * copy_to_user_page(), and some arch's seem to need special | 319 | * copy_to_user_page(), and some arch's seem to need special |
319 | * flushes. x86 is fine. */ | 320 | * flushes. x86 is fine. */ |
320 | if (copy_from_user(maddr + (dst->addr[di] + dstoff)%PAGE_SIZE, | 321 | if (copy_from_user(maddr + (dst->addr[di] + dstoff)%PAGE_SIZE, |
321 | (void __user *)src->addr[si], len) != 0) { | 322 | srclg->mem_base+src->addr[si], len) != 0) { |
322 | /* If a copy failed, it's the source's fault. */ | 323 | /* If a copy failed, it's the source's fault. */ |
323 | kill_guest(srclg, "bad address in sending DMA"); | 324 | kill_guest(srclg, "bad address in sending DMA"); |
324 | totlen = 0; | 325 | totlen = 0; |
@@ -377,7 +378,8 @@ static u32 do_dma(struct lguest *srclg, const struct lguest_dma *src, | |||
377 | * number of pages. Note that we're holding the destination's | 378 | * number of pages. Note that we're holding the destination's |
378 | * mmap_sem, as get_user_pages() requires. */ | 379 | * mmap_sem, as get_user_pages() requires. */ |
379 | if (get_user_pages(dstlg->tsk, dstlg->mm, | 380 | if (get_user_pages(dstlg->tsk, dstlg->mm, |
380 | dst->addr[i], 1, 1, 1, pages+i, NULL) | 381 | (unsigned long)dstlg->mem_base+dst->addr[i], |
382 | 1, 1, 1, pages+i, NULL) | ||
381 | != 1) { | 383 | != 1) { |
382 | /* This means the destination gave us a bogus buffer */ | 384 | /* This means the destination gave us a bogus buffer */ |
383 | kill_guest(dstlg, "Error mapping DMA pages"); | 385 | kill_guest(dstlg, "Error mapping DMA pages"); |
@@ -493,7 +495,7 @@ again: | |||
493 | mutex_lock(&lguest_lock); | 495 | mutex_lock(&lguest_lock); |
494 | down_read(fshared); | 496 | down_read(fshared); |
495 | /* Get the futex key for the key the Guest gave us */ | 497 | /* Get the futex key for the key the Guest gave us */ |
496 | if (get_futex_key((u32 __user *)ukey, fshared, &key) != 0) { | 498 | if (get_futex_key(lg->mem_base + ukey, fshared, &key) != 0) { |
497 | kill_guest(lg, "bad sending DMA key"); | 499 | kill_guest(lg, "bad sending DMA key"); |
498 | goto unlock; | 500 | goto unlock; |
499 | } | 501 | } |
@@ -584,7 +586,7 @@ unsigned long get_dma_buffer(struct lguest *lg, | |||
584 | 586 | ||
585 | /* This can fail if it's not a valid address, or if the address is not | 587 | /* This can fail if it's not a valid address, or if the address is not |
586 | * divisible by 4 (the futex code needs that, we don't really). */ | 588 | * divisible by 4 (the futex code needs that, we don't really). */ |
587 | if (get_futex_key((u32 __user *)ukey, fshared, &key) != 0) { | 589 | if (get_futex_key(lg->mem_base + ukey, fshared, &key) != 0) { |
588 | kill_guest(lg, "bad registered DMA buffer"); | 590 | kill_guest(lg, "bad registered DMA buffer"); |
589 | goto unlock; | 591 | goto unlock; |
590 | } | 592 | } |