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 --- Documentation/lguest/lguest.c | 48 +++++++++++++++++++++--------------------- drivers/lguest/lguest_user.c | 31 ++++++++++++++------------- 2 files changed, 42 insertions(+), 37 deletions(-) Index: linux-2.6.23-rc4/Documentation/lguest/lguest.c =================================================================== --- linux-2.6.23-rc4.orig/Documentation/lguest/lguest.c +++ linux-2.6.23-rc4/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) +static int tell_kernel(unsigned long pgdir, unsigned long start, + unsigned long page_offset) { - u32 args[] = { LHREQ_INITIALIZE, - (unsigned long)guest_base, - guest_limit / getpagesize(), - pgdir, start, 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); @@ -655,7 +656,8 @@ static void *_check_pointer(unsigned lon /* The Guest has given us the address of a "struct lguest_dma". We check it's * OK and convert it to an iovec (which is a simple array of ptr/size * pairs). */ -static u32 *dma2iov(unsigned long dma, struct iovec iov[], unsigned *num) +static unsigned long * +dma2iov(unsigned long dma, struct iovec iov[], unsigned *num) { unsigned int i; struct lguest_dma *udma; @@ -681,12 +683,12 @@ static u32 *dma2iov(unsigned long dma, s /* This routine gets a DMA buffer from the Guest for a given key, and converts * it to an iovec array. It returns the interrupt the Guest wants when we're * finished, and a pointer to the "used_len" field to fill in. */ -static u32 *get_dma_buffer(int fd, void *key, - struct iovec iov[], unsigned int *num, u32 *irq) +static unsigned long *get_dma_buffer(int fd, void *key, struct iovec iov[], + unsigned int *num, unsigned long *irq) { - u32 buf[] = { LHREQ_GETDMA, to_guest_phys(key) }; + unsigned long buf[] = { LHREQ_GETDMA, to_guest_phys(key) }; unsigned long udma; - u32 *res; + unsigned long *res; /* Ask the kernel for a DMA buffer corresponding to this key. */ udma = write(fd, buf, sizeof(buf)); @@ -703,9 +705,9 @@ 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) +static void trigger_irq(int fd, unsigned long 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); } @@ -742,7 +744,7 @@ struct console_abort /* This is the routine which handles console input (ie. stdin). */ static bool handle_console_input(int fd, struct device *dev) { - u32 irq = 0, *lenp; + unsigned long irq = 0, *lenp; int len; unsigned int num; struct iovec iov[LGUEST_MAX_DMA_SECTIONS]; @@ -787,7 +789,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); @@ -843,7 +845,7 @@ static unsigned long peer_offset(unsigne /* This is where we handle a packet coming in from the tun device */ static bool handle_tun_input(int fd, struct device *dev) { - u32 irq = 0, *lenp; + unsigned long irq = 0, *lenp; int len; unsigned num; struct iovec iov[LGUEST_MAX_DMA_SECTIONS]; @@ -888,7 +890,7 @@ static u32 handle_block_output(int fd, c unsigned num, struct device *dev) { struct lguest_block_page *p = dev->mem; - u32 irq, *lenp; + unsigned long irq, *lenp; unsigned int len, reply_num; struct iovec reply[LGUEST_MAX_DMA_SECTIONS]; off64_t device_len, off = (off64_t)p->sector * 512; @@ -955,7 +957,7 @@ static void handle_output(int fd, unsign struct device_list *devices) { struct device *i; - u32 *lenp; + unsigned long *lenp; struct iovec iov[LGUEST_MAX_DMA_SECTIONS]; unsigned num = 0; @@ -1365,7 +1367,7 @@ static void __attribute__((noreturn)) 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; @@ -1526,7 +1528,7 @@ int main(int argc, char *argv[]) = ((struct e820entry) { 0, mem, E820_RAM }); /* The boot header contains a command line pointer: we put the command * line after the boot header (at address 4096) */ - *(u32 *)(boot + 0x228) = 4096; + *(unsigned long *)(boot + 0x228) = 4096; concat(boot + 4096, argv+optind+2); /* The guest type value of "1" tells the Guest it's under lguest. */ Index: linux-2.6.23-rc4/drivers/lguest/lguest_user.c =================================================================== --- linux-2.6.23-rc4.orig/drivers/lguest/lguest_user.c +++ linux-2.6.23-rc4/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) +static int user_send_irq(struct lguest *lg, const unsigned long __user *input) { - u32 irq; + unsigned long irq; if (get_user(irq, input) != 0) return -EFAULT; @@ -142,8 +142,9 @@ static ssize_t read(struct file *file, c return run_guest(lg, (unsigned long __user *)user); } -/*L:020 The initialization write supplies 4 32-bit values (in addition to the - * 32-bit LHREQ_INITIALIZE value). These are: +/*L:020 The initialization write supplies 4 pointer sized (32 or 64 bit) + * values (in addition to the pointer sized LHREQ_INITIALIZE value). + * These are: * * base: The start of the Guest-physical memory inside the Launcher memory. * @@ -162,13 +163,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,13 +260,15 @@ 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 *__input, 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 *)__input; + unsigned long req; if (get_user(req, input) != 0) return -EFAULT; @@ -285,13 +288,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; }