From: rusty@rustcorp.com.au
To: lguest@ozlabs.org
Cc: Jes Sorensen <jes@sgi.com>, virtualization@lists.linux-foundation.org
Subject: [patch 24/43] lguest: Change example launcher to use unsigned long not u32
Date: Wed, 26 Sep 2007 16:36:42 +1000 [thread overview]
Message-ID: <20070926063649.450909013@rustcorp.com.au> (raw)
In-Reply-To: 20070926063618.956228976@rustcorp.com.au
[-- Attachment #1: lg-user-datatypes.diff --]
[-- Type: text/plain, Size: 7948 bytes --]
Apply Clue 2x4 to lguest userland<->kernel handling code and the
lguest launcher. Pointers are not to be passed in u32's!
Basic rule of thumb: Anything passing u32's back and forth should be
passing unsigned longs to be portable to 64 bit archs.
For those who forgotten already, I repeat: NO POINTERS IN u32!
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
Documentation/lguest/lguest.c | 29 +++++++++++++++--------------
drivers/lguest/lguest_user.c | 33 +++++++++++++++++----------------
2 files changed, 32 insertions(+), 30 deletions(-)
===================================================================
--- a/Documentation/lguest/lguest.c
+++ b/Documentation/lguest/lguest.c
@@ -473,9 +473,9 @@ static unsigned long setup_pagetables(un
unsigned long initrd_size,
unsigned long page_offset)
{
- u32 *pgdir, *linear;
+ unsigned long *pgdir, *linear;
unsigned int mapped_pages, i, linear_pages;
- unsigned int ptes_per_page = getpagesize()/sizeof(u32);
+ unsigned int ptes_per_page = getpagesize()/sizeof(void *);
/* Ideally we map all physical memory starting at page_offset.
* However, if page_offset is 0xC0000000 we can only map 1G of physical
@@ -505,7 +505,7 @@ static unsigned long setup_pagetables(un
* continue from there. */
for (i = 0; i < mapped_pages; i += ptes_per_page) {
pgdir[(i + page_offset/getpagesize())/ptes_per_page]
- = ((to_guest_phys(linear) + i*sizeof(u32))
+ = ((to_guest_phys(linear) + i*sizeof(void *))
| PAGE_PRESENT);
}
@@ -537,12 +537,13 @@ static void concat(char *dst, char *args
* the base of guest "physical" memory, the top physical page to allow, the
* top level pagetable, the entry point and the page_offset constant for the
* Guest. */
-static int tell_kernel(u32 pgdir, u32 start, u32 page_offset)
-{
- u32 args[] = { LHREQ_INITIALIZE,
- (unsigned long)guest_base,
- guest_limit / getpagesize(),
- pgdir, start, page_offset };
+static int tell_kernel(unsigned long pgdir, unsigned long start,
+ unsigned long page_offset)
+{
+ unsigned long args[] = { LHREQ_INITIALIZE,
+ (unsigned long)guest_base,
+ guest_limit / getpagesize(),
+ pgdir, start, page_offset };
int fd;
verbose("Guest: %p - %p (%#lx)\n",
@@ -586,7 +587,7 @@ static void wake_parent(int pipefd, int
for (;;) {
fd_set rfds = devices->infds;
- u32 args[] = { LHREQ_BREAK, 1 };
+ unsigned long args[] = { LHREQ_BREAK, 1 };
/* Wait until input is ready from one of the devices. */
select(devices->max_infd+1, &rfds, NULL, NULL, NULL);
@@ -684,7 +685,7 @@ static u32 *get_dma_buffer(int fd, void
static u32 *get_dma_buffer(int fd, void *key,
struct iovec iov[], unsigned int *num, u32 *irq)
{
- u32 buf[] = { LHREQ_GETDMA, to_guest_phys(key) };
+ unsigned long buf[] = { LHREQ_GETDMA, to_guest_phys(key) };
unsigned long udma;
u32 *res;
@@ -705,7 +706,7 @@ static u32 *get_dma_buffer(int fd, void
/* This is a convenient routine to send the Guest an interrupt. */
static void trigger_irq(int fd, u32 irq)
{
- u32 buf[] = { LHREQ_IRQ, irq };
+ unsigned long buf[] = { LHREQ_IRQ, irq };
if (write(fd, buf, sizeof(buf)) != 0)
err(1, "Triggering irq %i", irq);
}
@@ -787,7 +788,7 @@ static bool handle_console_input(int fd,
struct timeval now;
gettimeofday(&now, NULL);
if (now.tv_sec <= abort->start.tv_sec+1) {
- u32 args[] = { LHREQ_BREAK, 0 };
+ unsigned long args[] = { LHREQ_BREAK, 0 };
/* Close the fd so Waker will know it has to
* exit. */
close(waker_fd);
@@ -1365,7 +1366,7 @@ run_guest(int lguest_fd, struct device_l
run_guest(int lguest_fd, struct device_list *device_list)
{
for (;;) {
- u32 args[] = { LHREQ_BREAK, 0 };
+ unsigned long args[] = { LHREQ_BREAK, 0 };
unsigned long arr[2];
int readval;
===================================================================
--- a/drivers/lguest/lguest_user.c
+++ b/drivers/lguest/lguest_user.c
@@ -43,7 +43,7 @@ static void setup_regs(struct lguest_reg
/*L:310 To send DMA into the Guest, the Launcher needs to be able to ask for a
* DMA buffer. This is done by writing LHREQ_GETDMA and the key to
* /dev/lguest. */
-static long user_get_dma(struct lguest *lg, const u32 __user *input)
+static long user_get_dma(struct lguest *lg, const unsigned long __user *input)
{
unsigned long key, udma, irq;
@@ -67,7 +67,7 @@ static long user_get_dma(struct lguest *
/*L:315 To force the Guest to stop running and return to the Launcher, the
* Waker sets writes LHREQ_BREAK and the value "1" to /dev/lguest. The
* Launcher then writes LHREQ_BREAK and "0" to release the Waker. */
-static int break_guest_out(struct lguest *lg, const u32 __user *input)
+static int break_guest_out(struct lguest *lg, const unsigned long __user *input)
{
unsigned long on;
@@ -90,9 +90,9 @@ static int break_guest_out(struct lguest
/*L:050 Sending an interrupt is done by writing LHREQ_IRQ and an interrupt
* number to /dev/lguest. */
-static int user_send_irq(struct lguest *lg, const u32 __user *input)
-{
- u32 irq;
+static int user_send_irq(struct lguest *lg, const unsigned long __user *input)
+{
+ unsigned long irq;
if (get_user(irq, input) != 0)
return -EFAULT;
@@ -142,8 +142,8 @@ static ssize_t read(struct file *file, c
return run_guest(lg, (unsigned long __user *)user);
}
-/*L:020 The initialization write supplies 5 32-bit values (in addition to the
- * 32-bit LHREQ_INITIALIZE value). These are:
+/*L:020 The initialization write supplies 5 pointer sized (32 or 64 bit)
+ * values (in addition to the LHREQ_INITIALIZE value). These are:
*
* base: The start of the Guest-physical memory inside the Launcher memory.
*
@@ -162,13 +162,13 @@ static ssize_t read(struct file *file, c
* quickly converted from physical to virtual by adding PAGE_OFFSET. It's
* 0xC0000000 (3G) by default, but it's configurable at kernel build time.
*/
-static int initialize(struct file *file, const u32 __user *input)
+static int initialize(struct file *file, const unsigned long __user *input)
{
/* "struct lguest" contains everything we (the Host) know about a
* Guest. */
struct lguest *lg;
int err;
- u32 args[5];
+ unsigned long args[5];
/* We grab the Big Lguest lock, which protects against multiple
* simultaneous initializations. */
@@ -259,17 +259,18 @@ unlock:
* start with a 32 bit number: for the first write this must be
* LHREQ_INITIALIZE to set up the Guest. After that the Launcher can use
* writes of other values to get DMA buffers and send interrupts. */
-static ssize_t write(struct file *file, const char __user *input,
+static ssize_t write(struct file *file, const char __user *in,
size_t size, loff_t *off)
{
/* Once the guest is initialized, we hold the "struct lguest" in the
* file private data. */
struct lguest *lg = file->private_data;
- u32 req;
+ const unsigned long __user *input = (const unsigned long __user *)in;
+ unsigned long req;
if (get_user(req, input) != 0)
return -EFAULT;
- input += sizeof(req);
+ input++;
/* If you haven't initialized, you must do that first. */
if (req != LHREQ_INITIALIZE && !lg)
@@ -285,13 +286,13 @@ static ssize_t write(struct file *file,
switch (req) {
case LHREQ_INITIALIZE:
- return initialize(file, (const u32 __user *)input);
+ return initialize(file, input);
case LHREQ_GETDMA:
- return user_get_dma(lg, (const u32 __user *)input);
+ return user_get_dma(lg, input);
case LHREQ_IRQ:
- return user_send_irq(lg, (const u32 __user *)input);
+ return user_send_irq(lg, input);
case LHREQ_BREAK:
- return break_guest_out(lg, (const u32 __user *)input);
+ return break_guest_out(lg, input);
default:
return -EINVAL;
}
--
there are those who do and those who hang on and you don't see too
many doers quoting their contemporaries. -- Larry McVoy
next prev parent reply other threads:[~2007-09-26 6:36 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-26 6:36 [patch 00/43] lguest: Patches for 2.6.24 (and patchbomb test) rusty
2007-09-26 6:36 ` [patch 01/43] lguest: lguest example launcher truncates block device file to 0 length on problems rusty
2007-09-26 6:36 ` [patch 02/43] lguest: fix modules oopsing in lguest guests rusty
2007-09-26 6:36 ` [patch 03/43] lguest: Normalize config options for guest support rusty
2007-09-26 6:36 ` [patch 04/43] lguest: Consolidate host virtualization support under Virtualization menu rusty
2007-09-26 6:36 ` [patch 05/43] lguest: Example launcher should include asm/e820.h instead of asm-i386/ rusty
2007-09-26 6:36 ` [patch 06/43] lguest: turn err into errx in lguest call sites rusty
2007-09-26 6:36 ` [patch 07/43] lguest: Use copy_to_user() not put_user for struct timespec rusty
2007-09-26 6:36 ` [patch 08/43] lguest: Lguest currently depends on 32-bit x86, not just x86 rusty
2007-09-26 6:36 ` [patch 09/43] lguest: lguest.txt update rusty
2007-09-26 6:36 ` [patch 10/43] lguest: Make lguest_launcher.h types userspace-friendly rusty
2007-09-26 6:36 ` [patch 11/43] lguest: lguest_devices belongs in lguest_bus.c: its not i386-specific rusty
2007-09-26 6:36 ` [patch 12/43] lguest: Only start khvcd when someone uses hvc_console driver rusty
2007-09-26 6:36 ` [patch 13/43] lguest: Move lguest hcalls to arch-specific header rusty
2007-09-26 6:36 ` [patch 14/43] lguest: Move lguest guest support to arch/i386 where it logically belongs rusty
2007-09-26 6:36 ` [patch 15/43] lguest: Rename switcher.S to i386_switcher.S, since its very i386-specific rusty
2007-09-26 6:36 ` [patch 16/43] lguest: Accept elf files that are valid but have sections that can not be mmaped for some reason rusty
2007-09-26 6:36 ` [patch 17/43] lguest: Introduce guest mem offset, static link example launcher rusty
2007-09-26 6:36 ` [patch 18/43] lguest: Remove fixed limit on number of guests, and lguests array rusty
2007-09-26 6:36 ` [patch 19/43] lguest: Make shadow IDT a complete IDT with 256 entries rusty
2007-09-26 6:36 ` [patch 20/43] lguest: Move i386 part of core.c to i386_core.c rusty
2007-09-26 6:36 ` [patch 21/43] lguest: Reorder guest saved regs to match hyperall order rusty
2007-09-26 6:36 ` [patch 22/43] lguest: Introduce "hcall" pointer to indicate pending hypercall rusty
2007-09-26 6:36 ` [patch 23/43] lguest: Make hypercalls arch-independent rusty
2007-09-26 6:36 ` rusty [this message]
2007-09-26 6:36 ` [patch 25/43] lguest: Move register setup into i386_core.c rusty
2007-09-26 6:36 ` [patch 26/43] lguest: guest.h declares a struct timespec, make it include linux/time.h rusty
2007-09-26 6:36 ` [patch 27/43] lguest: Pagetables to use normal kernel types rusty
2007-09-26 6:36 ` [patch 28/43] lguest: Rename "cr3" to "gpgdir" to avoid x86-specific naming rusty
2007-09-26 6:36 ` [patch 29/43] lguest: Introduce "used_vectors" bitmap which can be used to reserve vectors rusty
2007-09-26 6:36 ` [patch 30/43] lguest: Allow guest to specify syscall vector to use rusty
2007-09-26 6:36 ` [patch 31/43] lguest: Boot with virtual == physical to get closer to native Linux rusty
2007-09-27 0:12 ` Jeremy Fitzhardinge
2007-09-27 0:53 ` [Lguest] " ron minnich
2007-09-29 13:02 ` Rusty Russell
2007-09-26 6:36 ` [patch 32/43] lguest: Virtio interface rusty
2007-10-02 9:03 ` Christian Borntraeger
2007-10-02 12:00 ` Rusty Russell
2007-10-10 8:50 ` Christian Borntraeger
2007-10-10 13:43 ` Glauber de Oliveira Costa
2007-10-10 14:24 ` Arnd Bergmann
2007-10-10 15:31 ` Eric Van Hensbergen
2007-10-10 16:00 ` Arnd Bergmann
2007-10-11 14:17 ` Rusty Russell
2007-09-26 6:36 ` [patch 33/43] lguest: Net driver using virtio rusty
2007-09-26 6:36 ` [patch 34/43] lguest: Block " rusty
2007-09-28 11:32 ` [Lguest] " Chris Malley
2007-09-29 13:26 ` Rusty Russell
2007-09-26 6:36 ` [patch 35/43] lguest: Virtio console driver rusty
2007-09-26 6:36 ` [patch 36/43] lguest: Module autoprobing support for virtio drivers rusty
2007-09-26 6:36 ` [patch 37/43] lguest: Virtio helper routines for a descriptor ringbuffer implementation rusty
2007-09-30 17:03 ` Avi Kivity
2007-10-01 12:03 ` Rusty Russell
2007-10-01 12:13 ` Avi Kivity
2007-10-02 4:21 ` Rusty Russell
2007-10-02 6:02 ` Avi Kivity
2007-09-26 6:36 ` [patch 38/43] lguest: This gets rid of the lguest bus, drivers and DMA mechanism, to make way for a generic virtio mechanism rusty
2007-09-26 6:36 ` [patch 39/43] lguest: This patch gets rid of the old lguest host I/O infrastructure and replaces it with a single hypercall "LHCALL_NOTIFY" which takes an address rusty
2007-09-26 6:36 ` [patch 40/43] lguest: Lguest support for Virtio rusty
2007-09-26 6:36 ` [patch 41/43] lguest: Update example launcher for virtio rusty
2007-09-26 6:37 ` [patch 42/43] lguest: Example launcher handle guests not being ready for input rusty
2007-09-26 6:37 ` [patch 43/43] lguest: generalize lgread_u32/lgwrite_u32 rusty
2007-09-27 13:04 ` [Lguest] " Chris Malley
2007-09-29 13:29 ` Rusty Russell
2007-10-09 20:25 ` [Lguest] [patch 00/43] lguest: Patches for 2.6.24 (and patchbomb test) Eric Van Hensbergen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070926063649.450909013@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=jes@sgi.com \
--cc=lguest@ozlabs.org \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).