qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] CONFIG_QEMU patch


From: Rusty Russell
Subject: [Qemu-devel] CONFIG_QEMU patch
Date: Thu, 10 Jul 2003 15:46:24 +1000

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).

diff -urpN --exclude TAGS -X 
/home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal 
linux-2.5.74-bk7/arch/i386/Kconfig 
working-2.5.74-bk7-qemu-page-offset/arch/i386/Kconfig
--- linux-2.5.74-bk7/arch/i386/Kconfig  2003-07-10 10:55:41.000000000 +1000
+++ working-2.5.74-bk7-qemu-page-offset/arch/i386/Kconfig       2003-07-10 
11:58:27.000000000 +1000
@@ -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
 #
diff -urpN --exclude TAGS -X 
/home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal 
linux-2.5.74-bk7/arch/i386/vmlinux.lds.S 
working-2.5.74-bk7-qemu-page-offset/arch/i386/vmlinux.lds.S
--- linux-2.5.74-bk7/arch/i386/vmlinux.lds.S    2003-06-15 11:29:47.000000000 
+1000
+++ working-2.5.74-bk7-qemu-page-offset/arch/i386/vmlinux.lds.S 2003-07-10 
11:58:27.000000000 +1000
@@ -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 : {
diff -urpN --exclude TAGS -X 
/home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal 
linux-2.5.74-bk7/fs/namespace.c 
working-2.5.74-bk7-qemu-page-offset/fs/namespace.c
--- linux-2.5.74-bk7/fs/namespace.c     2003-07-10 10:55:46.000000000 +1000
+++ working-2.5.74-bk7-qemu-page-offset/fs/namespace.c  2003-07-10 
15:05:22.000000000 +1000
@@ -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 voi
        if (!(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;
 }
diff -urpN --exclude TAGS -X 
/home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal 
linux-2.5.74-bk7/include/asm-i386/fixmap.h 
working-2.5.74-bk7-qemu-page-offset/include/asm-i386/fixmap.h
--- linux-2.5.74-bk7/include/asm-i386/fixmap.h  2003-06-15 11:30:06.000000000 
+1000
+++ working-2.5.74-bk7-qemu-page-offset/include/asm-i386/fixmap.h       
2003-07-10 11:58:27.000000000 +1000
@@ -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)
 
diff -urpN --exclude TAGS -X 
/home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal 
linux-2.5.74-bk7/include/asm-i386/page.h 
working-2.5.74-bk7-qemu-page-offset/include/asm-i386/page.h
--- linux-2.5.74-bk7/include/asm-i386/page.h    2003-04-08 11:14:55.000000000 
+1000
+++ working-2.5.74-bk7-qemu-page-offset/include/asm-i386/page.h 2003-07-10 
11:58:27.000000000 +1000
@@ -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)
diff -urpN --exclude TAGS -X 
/home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal 
linux-2.5.74-bk7/include/asm-i386/param.h 
working-2.5.74-bk7-qemu-page-offset/include/asm-i386/param.h
--- linux-2.5.74-bk7/include/asm-i386/param.h   2003-01-02 12:07:44.000000000 
+1100
+++ working-2.5.74-bk7-qemu-page-offset/include/asm-i386/param.h        
2003-07-10 11:58:27.000000000 +1000
@@ -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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]