CONFIG_QEMU patch
Hi all,
Convenience patch for 2.5.74 (should apply to most 2.5
kernels) which adds a CONFIG_QEMU option. This does all the frobbing listed in the documentation, and also avoids a user access trap in copy_mount_options() which OOPSes under QEMU.
This boots and runs for me, using the .config from vl-0.4.2.
Cheers,
Rusty.
Name: QEMU CONFIG Patch
Author: Rusty Russell
Status: Tested on 2.5.74-bk7
D: Convenient patch based on Fabrice Bellard's documentation on how to
D: boot an x86 kernel under qemu 0.4. Adjusts PAGE_OFFSET, HZ, FIXADDR_TOP
D: and the arg copying code in namespace.c (which QEMU up to 0.4.2 doesn't
D: seem to handle correctly).
arch/i386/Kconfig +8 -0
@@ -307,6 +307,14 @@ config X86_GENERIC when it has moderate overhead. This is intended for generic distributions kernels. +config QEMU + bool "Kernel to run under QEMU" + depends on EXPERIMENTAL + help + Select this if you want to boot the kernel inside qemu, the + x86 emulator. See http://fabrice.bellard.free.fr/qemu/. + Say N. + # # Define implied options from the CPU selection here #
arch/i386/vmlinux.lds.S +3 -2
@@ -3,14 +3,15 @@ */ #include <asm-generic/vmlinux.lds.h> - +#include <asm/page.h> + OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") OUTPUT_ARCH(i386) ENTRY(startup_32) jiffies = jiffies_64; SECTIONS { - . = 0xC0000000 + 0x100000; + . = __PAGE_OFFSET + 0x100000; /* read-only */ _text = .; /* Text and read-only data */ .text : {
fs/namespace.c +7 -13
@@ -676,7 +676,6 @@ out:static int copy_mount_options (const void __user *data,unsigned long *where) { -int i;unsigned long page;unsigned long size;
@@ -687,22 +686,17 @@ static int copy_mount_options (const voiif (!(page =__get_free_page (GFP_KERNEL )))return -ENOMEM ; -/* We only care that *some* data at the address the user -* gave us is valid. Just in case, we'll zero -* the remainder of the page. -*/ -/* copy_from_user cannot cross TASK_SIZE ! */ - size =TASK_SIZE - (unsigned long )data; -if (size >PAGE_SIZE ) - size =PAGE_SIZE ; + size =strnlen_user (data,PAGE_SIZE -1 ); +if (size ==0 ) { +free_page (page); +return -EFAULT ; + } - i = size -copy_from_user ((void *)page, data, size); -if (!i) { +if (copy_from_user ((void *)page, data, size) !=0 ) {free_page (page);return -EFAULT ; } -if (i !=PAGE_SIZE ) -memset ((char *)page + i,0 ,PAGE_SIZE - i); +memset ((char *)page + size,0 ,PAGE_SIZE - size); *where = page;return 0 ; }
include/asm-i386/fixmap.h +4 -0
@@ -100,7 +100,11 @@ extern void __set_fixmap (enum fixed_add* Leave one empty page between vmalloc'ed areas and * the start of the fixmap. */ +#ifdef CONFIG_QEMU +#define FIXADDR_TOP (0xa7fff000UL) +#else #define FIXADDR_TOP (0xfffff000UL) +#endif #define __FIXADDR_SIZE (__end_of_permanent_fixed_addresses << PAGE_SHIFT)#define FIXADDR_START (FIXADDR_TOP - __FIXADDR_SIZE)
include/asm-i386/page.h +10 -3
@@ -10,10 +10,10 @@#define LARGE_PAGE_SIZE (1UL << PMD_SHIFT)#ifdef __KERNEL__ -#ifndef __ASSEMBLY__ -#include <linux/config.h> +#ifndef __ASSEMBLY__ +#ifdef CONFIG_X86_USE_3DNOW #include <asm/mmx.h>
@@ -115,12 +115,19 @@ static __inline__ int get_order(unsigned#endif /* __ASSEMBLY__ */ #ifdef __ASSEMBLY__ +#ifdef CONFIG_QEMU +#define __PAGE_OFFSET (0x90000000) +#else #define __PAGE_OFFSET (0xC0000000) +#endif /* QEMU */ +#else +#ifdef CONFIG_QEMU +#define __PAGE_OFFSET (0x90000000UL)#else #define __PAGE_OFFSET (0xC0000000UL) +#endif /* QEMU */ #endif -#define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)#define VMALLOC_RESERVE ((unsigned long)__VMALLOC_RESERVE)#define MAXMEM (-__PAGE_OFFSET-__VMALLOC_RESERVE)
include/asm-i386/param.h +6 -1
@@ -2,7 +2,12 @@#define _ASMi386_PARAM_H#ifdef __KERNEL__ -# define HZ 1000/* Internal kernel timer frequency */ +# include <linux/config.h> +# ifdef CONFIG_QEMU +# define HZ 100 +# else +# define HZ 1000/* Internal kernel timer frequency */ +# endif # define USER_HZ 100/* .. some user interfaces are in "ticks" */ # define CLOCKS_PER_SEC (USER_HZ)/* like times() */ #endif
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
From: Rusty Russell <[email protected]>
Date: Thu, 10 Jul 2003 15:46:24 +1000
and also avoids a user access trap in
copy_mount_options() which OOPSes under QEMU.
Is this a bug in this kernel code or a QEMU issue?
In message <[email protected]> you write:
Quoted 7 lines
From: Rusty Russell <[email protected]>
Date: Thu, 10 Jul 2003 15:46:24 +1000and also avoids a user access trap in
copy_mount_options()which OOPSes under QEMU.Is this a bug in this kernel code or a QEMU issue?
QEMU, definitely. copy_mount_options() is the only place where the copy_from_user regularly fails. That's mainly because it's bad code, but it's a useful canary for exactly this readson.
Cheers,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.