Fix -kernel with SeaBIOS v2
cover Fix -kernel with SeaBIOS v2
SeaBIOS clears RAM between we write our -kernel image to RAM and the int19 handler gets triggered.
So in order to work around that, I sat down and implemented Avi's suggestion of "downloading" all blobs in runtime from the fw_cfg interface
Thanks to glommer who talked me into doing it ;-).
v1 -> v2:
- rename copy_rom -> rom_copy
- introduce fw_cfg compat loader for loadvm
Alexander Graf (6):
Make fw_cfg interface 32-bit aware Introduce rom_rom
Convert multiboot to fw_cfg backed data storage Move common option rom code to header file Convert linux bootrom to external rom and fw_cfg Add linuxboot to BLOBS
Makefile | 2 +- hw/fw_cfg.c | 30 ++++++-- hw/fw_cfg.h | 13 +++- hw/loader.c | 38 +++++++++ hw/loader.h | 1 + hw/pc.c | 169 +++++++++++++---------------------------- pc-bios/optionrom/Makefile | 2 +- pc-bios/optionrom/linuxboot.S | 140 ++++++++++++++++++++++++++++++++++ pc-bios/optionrom/multiboot.S | 108 ++++++++++----------------- pc-bios/optionrom/optionrom.h | 107 ++++++++++++++++++++++++++ 10 files changed, 416 insertions(+), 194 deletions(-) create mode 100644 pc-bios/optionrom/linuxboot.S create mode 100644 pc-bios/optionrom/optionrom.h
PATCH 1/6 Make fw_cfg interface 32-bit aware
The fw_cfg interface can only handle up to 16 bits of data for its streams. While that isn't too much of a problem when handling integers, we would like to stream full kernel images over that interface!
So let's extend it to 32 bit length variables.
---
v1 -> v2:
- add savevm compat code (untested!)
--- hw/fw_cfg.c | 30 ++++++++++++++++++++++++------ hw/fw_cfg.h | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-)
hw/fw_cfg.c +24 -6
@@ -39,7 +39,7 @@#define FW_CFG_SIZE 2 typedef struct _FWCfgEntry { - uint16_t len; + uint32_t len; uint8_t *data; void *callback_opaque; FWCfgCallback callback;
@@ -48,7 +48,7 @@ typedef struct _FWCfgEntry {typedef struct _FWCfgState {FWCfgEntry entries[2 ][FW_CFG_MAX_ENTRY ];uint16_t cur_entry; -uint16_t cur_offset; +uint32_t cur_offset; }FWCfgState ;static void fw_cfg_write (FWCfgState *s,uint8_t value)
@@ -164,19 +164,37 @@ static void fw_cfg_reset(void *opaque)fw_cfg_select (s,0 ); } +static int fw_cfg_load_old (QEMUFile *f,void *opaque,int version_id) +{ +FWCfgState *s = opaque; +uint16_t cur_offset; + +if (version_id !=1 ) +return -EINVAL ; + +qemu_get_be16s (f, &s->cur_entry); + +/* Convert old 16 bit value to new 32 bit width */ +qemu_get_be16s (f, &cur_offset); + s->cur_offset = cur_offset; + +return 0 ; +} +static const VMStateDescription vmstate_fw_cfg = { .name ="fw_cfg" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .minimum_version_id_old =1 , + .load_state_old = fw_cfg_load_old, .fields = (VMStateField []) {VMSTATE_UINT16 (cur_entry, FWCfgState), -VMSTATE_UINT16 (cur_offset, FWCfgState), +VMSTATE_UINT32 (cur_offset, FWCfgState),VMSTATE_END_OF_LIST () } }; -int fw_cfg_add_bytes (void *opaque,uint16_t key,uint8_t *data,uint16_t len) +int fw_cfg_add_bytes (void *opaque,uint16_t key,uint8_t *data,uint32_t len) {FWCfgState *s = opaque;int arch = !!(key &FW_CFG_ARCH_LOCAL );
hw/fw_cfg.h +1 -1
@@ -28,7 +28,7 @@#ifndef NO_QEMU_PROTOS typedef void (*FWCfgCallback )(void *opaque,uint8_t *data); -int fw_cfg_add_bytes (void *opaque,uint16_t key,uint8_t *data,uint16_t len); +int fw_cfg_add_bytes (void *opaque,uint16_t key,uint8_t *data,uint32_t len);int fw_cfg_add_i16 (void *opaque,uint16_t key,uint16_t value);int fw_cfg_add_i32 (void *opaque,uint16_t key,uint32_t value);int fw_cfg_add_i64 (void *opaque,uint16_t key,uint64_t value);
Signature · 1 line
1.6.0.2
[Qemu-devel] Re: [PATCH 1/6] Make fw_cfg interface 32-bit aware
Quoted 66 lines · Alexander Graf
The
fw_cfginterface can only handle up to 16 bits of data for its streams. While that isn't too much of a problem when handling integers, we would like to stream full kernel images over that interface!So let's extend it to 32 bit length variables.
Signed-off-by Alexander Graf <[email protected]>---
v1 -> v2:
- add savevm compat code (untested!)
--- hw/fw_cfg.c | 30 ++++++++++++++++++++++++------ hw/fw_cfg.h | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-)hw/fw_cfg.c +20
-4@@ -39,7 +39,7 @@#define FW_CFG_SIZE 2 typedef struct _FWCfgEntry { - uint16_t len; + uint32_t len; uint8_t *data; void *callback_opaque; FWCfgCallback callback;@@ -48,7 +48,7 @@ typedef struct _FWCfgEntry {typedef struct _FWCfgState {FWCfgEntry entries[2 ][FW_CFG_MAX_ENTRY ];uint16_t cur_entry; -uint16_t cur_offset; +uint32_t cur_offset; }FWCfgState ;static void fw_cfg_write (FWCfgState *s,uint8_t value)@@ -164,19 +164,37 @@ static void fw_cfg_reset(void *opaque)fw_cfg_select (s,0 ); } +static int fw_cfg_load_old (QEMUFile *f,void *opaque,int version_id) +{ +FWCfgState *s = opaque; +uint16_t cur_offset; + +if (version_id !=1 ) +return -EINVAL ; + +qemu_get_be16s (f, &s->cur_entry); + +/* Convert old 16 bit value to new 32 bit width */ +qemu_get_be16s (f, &cur_offset); + s->cur_offset = cur_offset; + +return 0 ; +} +static const VMStateDescription vmstate_fw_cfg = { .name ="fw_cfg" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 ,
hw/fw_cfg.c static void fw_cfg_reset(void *opaque) · line 195
Quoted 10 lines
hw/fw_cfg.c +3
-1+ .minimum_version_id = 2, .minimum_version_id_old = 1, + .load_state_old = fw_cfg_load_old, .fields = (VMStateField []) {VMSTATE_UINT16 (cur_entry, FWCfgState), -VMSTATE_UINT16 (cur_offset, FWCfgState), +VMSTATE_UINT32 (cur_offset, FWCfgState),VMSTATE_END_OF_LIST () } };
Why don't we just add another field for the upper bits, and add it through VMSTATE_UINT16_V ?
[Qemu-devel] Re: [PATCH 1/6] Make fw_cfg interface 32-bit aware
Quoted 73 lines · Glauber Costa
Quoted 72 lines · Alexander Graf
The
fw_cfginterface can only handle up to 16 bits of data for its streams. While that isn't too much of a problem when handling integers, we would like to stream full kernel images over that interface!So let's extend it to 32 bit length variables.
Signed-off-by Alexander Graf <[email protected]>---
v1 -> v2:
- add savevm compat code (untested!)
---hw/fw_cfg.c| 30 ++++++++++++++++++++++++------hw/fw_cfg.h| 2 +-2 files changed, 25 insertions(+), 7 deletions(-)hw/fw_cfg.c +22
-4@@ -39,7 +39,7 @@#define FW_CFG_SIZE 2 typedef struct _FWCfgEntry { - uint16_t len; + uint32_t len; uint8_t *data; void *callback_opaque; FWCfgCallback callback;@@ -48,7 +48,7 @@ typedef struct _FWCfgEntry {typedef struct _FWCfgState {FWCfgEntry entries[2 ][FW_CFG_MAX_ENTRY ];uint16_t cur_entry; -uint16_t cur_offset; +uint32_t cur_offset; }FWCfgState ;static void fw_cfg_write (FWCfgState *s,uint8_t value)@@ -164,19 +164,37 @@ static void fw_cfg_reset(void *opaque)fw_cfg_select (s,0 ); } +static int fw_cfg_load_old (QEMUFile *f,void *opaque,int version_id) +{ +FWCfgState *s = opaque; +uint16_t cur_offset; + +if (version_id !=1 ) +return -EINVAL ; + +qemu_get_be16s (f, &s->cur_entry); + +/* Convert old 16 bit value to new 32 bit width */ +qemu_get_be16s (f, &cur_offset); + s->cur_offset = cur_offset; + +return 0 ; +} +static const VMStateDescription vmstate_fw_cfg = { .name ="fw_cfg" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .minimum_version_id_old =1 , + .load_state_old = fw_cfg_load_old, .fields = (VMStateField []) {VMSTATE_UINT16 (cur_entry, FWCfgState),
Quoted 8 lines
hw/fw_cfg.c static void fw_cfg_reset(void *opaque) · line 195
Quoted 5 lines
hw/fw_cfg.c +1
-1-VMSTATE_UINT16 (cur_offset, FWCfgState), +VMSTATE_UINT32 (cur_offset, FWCfgState), VMSTATE_END_OF_LIST() } };Why don't we just add another field for the upper bits, and add it through
VMSTATE_UINT16_V?
Because that would mean I'd have to deal with it in the code later on and I don't see the point of writing code that's not in the load/save cycle because of limitations there.
Alex
[Qemu-devel] Re: [PATCH 1/6] Make fw_cfg interface 32-bit aware
Quoted 4 lines · Alexander Graf
On 13.11.2009, at 01:48, Glauber Costa wrote:
Because that would mean I'd have to deal with it in the code later on and I don't see the point of writing code that's not in the load/save cycle because of limitations there.
Hi
could you take a look at this one?
This don't use the old_state function and should work as well. I haven't tested it yet (test machine down), but will do a bit later.
Later, Juan.
PD. Yeap, I would have to add the HACK types to hw.h as several places
have decided to change the size of several fields.
Quoted 1 line
From
25f7a6e401d72a0584fa4630a9dc97ce34520f7bMon Sep 17 00:00:00 2001
From: Juan Quintela <[email protected]>
Date: Fri, 13 Nov 2009 11:56:38 +0100
Subject: [PATCH] fw_cfg: change cur_offset to 32 bits
--- hw/fw_cfg.c | 44 +++++++++++++++++++++++++++++++++++++++----- hw/fw_cfg.h | 2 +- 2 files changed, 40 insertions(+), 6 deletions(-)
hw/fw_cfg.c +39 -5
@@ -39,7 +39,7 @@#define FW_CFG_SIZE 2 typedef struct _FWCfgEntry { - uint16_t len; + uint32_t len; uint8_t *data; void *callback_opaque; FWCfgCallback callback;
@@ -48,7 +48,7 @@ typedef struct _FWCfgEntry {typedef struct _FWCfgState {FWCfgEntry entries[2 ][FW_CFG_MAX_ENTRY ];uint16_t cur_entry; -uint16_t cur_offset; +uint32_t cur_offset; }FWCfgState ;static void fw_cfg_write (FWCfgState *s,uint8_t value)
@@ -164,19 +164,53 @@ static void fw_cfg_reset(void *opaque)fw_cfg_select (s,0 ); } +/* Save restore 32 bit int as uint16_t +This is a Big hack, but it is how the old state did it. +Or we broke compatibility in the state, or we can't use struct tm +*/ + +static int get_uint32_as_uint16 (QEMUFile *f,void *pv,size_t size) +{ +uint32_t *v = pv; + *v =qemu_get_be16 (f); +return 0 ; +} + +static void put_unused (QEMUFile *f,void *pv,size_t size) +{ +fprintf (stderr,"uint32_as_uint16 is only used for backward compatibilty.\n" ); +fprintf (stderr,"This functions shouldn't be called.\n" ); +} + +const VMStateInfo vmstate_hack_uint32_as_uint16 = { + .name ="int32_as_uint16" , + .get = get_uint32_as_uint16, + .put = put_unused, +}; + +#define VMSTATE_UINT16_HACK (_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_hack_uint32_as_uint16, uint32_t) + + +static bool is_version_1 (void *opaque,int version_id) +{ +return version_id ==1 ; +} +static const VMStateDescription vmstate_fw_cfg = { .name ="fw_cfg" , - .version_id =1 , + .version_id =2 , .minimum_version_id =1 , .minimum_version_id_old =1 , .fields = (VMStateField []) {VMSTATE_UINT16 (cur_entry, FWCfgState), -VMSTATE_UINT16 (cur_offset, FWCfgState), +VMSTATE_UINT16_HACK (cur_offset, FWCfgState, is_version_1), +VMSTATE_UINT32_V (cur_offset, FWCfgState,2 ),VMSTATE_END_OF_LIST () } }; -int fw_cfg_add_bytes (void *opaque,uint16_t key,uint8_t *data,uint16_t len) +int fw_cfg_add_bytes (void *opaque,uint16_t key,uint8_t *data,uint32_t len) {FWCfgState *s = opaque;int arch = !!(key &FW_CFG_ARCH_LOCAL );
hw/fw_cfg.h +1 -1
@@ -28,7 +28,7 @@#ifndef NO_QEMU_PROTOS typedef void (*FWCfgCallback )(void *opaque,uint8_t *data); -int fw_cfg_add_bytes (void *opaque,uint16_t key,uint8_t *data,uint16_t len); +int fw_cfg_add_bytes (void *opaque,uint16_t key,uint8_t *data,uint32_t len);int fw_cfg_add_i16 (void *opaque,uint16_t key,uint16_t value);int fw_cfg_add_i32 (void *opaque,uint16_t key,uint32_t value);int fw_cfg_add_i64 (void *opaque,uint16_t key,uint64_t value);
Signature · 1 line
1.6.2.5
[Qemu-devel] Re: [PATCH 1/6] Make fw_cfg interface 32-bit aware
Am 13.11.2009 um 11:59 schrieb Juan Quintela <[email protected]>:
Quoted 6 lines
Quoted 4 lines · Alexander Graf
On 13.11.2009, at 01:48, Glauber Costa wrote:
Because that would mean I'd have to deal with it in the code later on and I don't see the point of writing code that's not in the load/save cycle because of limitations there.
Quoted 6 lines
Hi
could you take a look at this one?
This don't use the
old_statefunction and should work as well. I haven't tested it yet (test machine down), but will do a bit later.
Well I suppose your untested is better than my untested :-).
When it comes to save/restore please take anything from Juan rather than my patch.
I don't have access to a PC until Monday anyways and IMHO -kernel is a pretty important feature for developers that sholdn't stay vroken for too long in HEAD.
Alex
PATCH 2/6 Introduce rom_rom
In reply to Alexander GrafWe have several rom helpers currently, but none of them can get us code that spans several roms into a pointer.
This patch introduces a function that copies over rom contents.
---
v1 -> v2:
- rename copy_rom -> rom_copy
--- hw/loader.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/loader.h | 1 + 2 files changed, 39 insertions(+), 0 deletions(-)
hw/loader.c +38 -0
@@ -701,6 +701,44 @@ static Rom *find_rom(target_phys_addr_t addr)return NULL ; } +int rom_copy (uint8_t *dest,target_phys_addr_t addr,size_t size) +{ +target_phys_addr_t end = addr + size; +uint8_t *s, *d = dest; +size_t l =0 ; +Rom *rom; + + QTAILQ_FOREACH(rom, &roms, next) { +if (rom->max) +continue ; +if (rom->min > addr) +continue ; +if (rom->min + rom->romsize < addr) +continue ; +if (rom->min > end) +break ; +if (!rom->data) +continue ; + + d = dest + (rom->min - addr); + s = rom->data; + l = rom->romsize; + +if (rom->min < addr) { + d = dest; + s += (addr - rom->min); + l -= (addr - rom->min); + } +if ((d + l) > (dest + size)) { + l = dest - d; + } + +memcpy (d, s, l); + } + +return (d + l) - dest; +} +void *rom_ptr (target_phys_addr_t addr) {Rom *rom;
hw/loader.h +1 -0
@@ -24,6 +24,7 @@ int rom_add_file(const char *file,int rom_add_blob (const char *name,const void *blob,size_t len,target_phys_addr_t min,target_phys_addr_t max,int align);int rom_load_all (void ); +int rom_copy (uint8_t *dest,target_phys_addr_t addr,size_t size);void *rom_ptr (target_phys_addr_t addr);void do_info_roms (Monitor *mon);
Signature · 1 line
1.6.0.2
PATCH 3/6 Convert multiboot to fw_cfg backed data storage
In reply to Alexander GrafRight now we load the guest kernel to RAM, fire off the BIOS, hope it doesn't clobber memory and run an option rom that jumps into the kernel.
That breaks with SeaBIOS, as that clears memory. So let's read all kernel, module etc. data using the fw_cfg interface when in the int19 handler.
This patch implements said mechanism for multiboot.
---
v1 -> v2:
- rename copy_rom -> rom_copy
--- hw/fw_cfg.h | 5 ++- hw/pc.c | 43 ++++++++++++++++------- pc-bios/optionrom/multiboot.S | 77 ++++++++++++++++++++++++++++++++--------- 3 files changed, 94 insertions(+), 31 deletions(-)
hw/fw_cfg.h +4 -1
@@ -17,7 +17,10 @@#define FW_CFG_NUMA 0x0d#define FW_CFG_BOOT_MENU 0x0e#define FW_CFG_MAX_CPUS 0x0f -#define FW_CFG_MAX_ENTRY 0x10 +#define FW_CFG_KERNEL_ENTRY 0x10 +#define FW_CFG_KERNEL_DATA 0x11 +#define FW_CFG_INITRD_DATA 0x12 +#define FW_CFG_MAX_ENTRY 0x13#define FW_CFG_WRITE_CHANNEL 0x4000#define FW_CFG_ARCH_LOCAL 0x8000
hw/pc.c +30 -13
83 lines not on this page · raw message
pc-bios/optionrom/multiboot.S +60 -17
140 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 4/6 Move common option rom code to header file
In reply to Alexander GrafWe will have a linux boot option rom soon, so let's take all functionality that might be useful for both to a header file that both roms can include.
That way we only have to write fw_cfg access code once.
--- pc-bios/optionrom/multiboot.S | 79 +----------------------------- pc-bios/optionrom/optionrom.h | 107 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 76 deletions(-) create mode 100644 pc-bios/optionrom/optionrom.h
pc-bios/optionrom/multiboot.S +3 -76
@@ -18,86 +18,15 @@ * Authors: Alexander Graf <[email protected]> */ -#define NO_QEMU_PROTOS -#include "../../hw/fw_cfg.h" - -#define BIOS_CFG_IOPORT_CFG 0x510 -#define BIOS_CFG_IOPORT_DATA 0x511 +#include "optionrom.h" #define MULTIBOOT_MAGIC 0x2badb002 #define GS_PROT_JUMP 0 #define GS_GDT_DESC 6 -/* Break the translation block flow so -d cpu shows us values */ -#define DEBUG_HERE \ - jmp 1f; \ - 1: - -/* Read a variable from the fw_cfg device. - Clobbers: %edx - Out: %eax */ -.macro read_fw VAR - mov $\VAR, %ax - mov $BIOS_CFG_IOPORT_CFG, %dx - outw %ax, (%dx) - mov $BIOS_CFG_IOPORT_DATA, %dx - inb (%dx), %al - shl $8, %eax - inb (%dx), %al - shl $8, %eax - inb (%dx), %al - shl $8, %eax - inb (%dx), %al - bswap %eax -.endm -/* - * Read a blob from the fw_cfg device. - * Requires _ADDR, _SIZE and _DATA values for the parameter. - * - * Clobbers: %eax, %edx, %es, %ecx, %edi - */ -#define read_fw_blob(var) \ - read_fw var ## _ADDR; \ - mov %eax, %edi; \ - read_fw var ## _SIZE; \ - mov %eax, %ecx; \ - mov $var ## _DATA, %ax; \ - mov $BIOS_CFG_IOPORT_CFG, %edx; \ - outw %ax, (%dx); \ - mov $BIOS_CFG_IOPORT_DATA, %dx; \ - cld; \ - DEBUG_HERE \ - rep insb (%dx), %es:(%edi); - -.code16 -.text - .global _start -_start: - .short 0xaa55 - .byte (_end - _start) / 512 - push %eax - push %ds - - /* setup ds so we can access the IVT */ - xor %ax, %ax - mov %ax, %ds - - /* install our int 19 handler */ - movw $int19_handler, (0x19*4) - mov %cs, (0x19*4+2) - - pop %ds - pop %eax - lret - -int19_handler: - /* DS = CS */ - movw %cs, %ax - movw %ax, %ds - - /* fall through */ +BOOT_ROM_START run_multiboot:
@@ -249,6 +178,4 @@ gdt_desc: .short (5 * 8) - 1 .long gdt -.align 512, 0 -_end: - +BOOT_ROM_END
pc-bios/optionrom/optionrom.h new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 5/6 Convert linux bootrom to external rom and fw_cfg
In reply to Alexander GrafWe already have a working multiboot implementation that uses fw_cfg to get its kernel module etc. data in int19 runtime now.
So what's missing is a working linux boot option rom. While at it I figured it would be a good idea to take the opcode generator out of pc.c and instead use a proper option rom, like we do with multiboot.
So here it is - an fw_cfg using option rom for -kernel with linux!
--- hw/fw_cfg.h | 8 ++- hw/pc.c | 126 +++++++------------------------------ pc-bios/optionrom/Makefile | 2 +- pc-bios/optionrom/linuxboot.S | 140 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 172 insertions(+), 104 deletions(-) create mode 100644 pc-bios/optionrom/linuxboot.S
hw/fw_cfg.h +7 -1
@@ -20,7 +20,13 @@#define FW_CFG_KERNEL_ENTRY 0x10#define FW_CFG_KERNEL_DATA 0x11#define FW_CFG_INITRD_DATA 0x12 -#define FW_CFG_MAX_ENTRY 0x13 +#define FW_CFG_CMDLINE_ADDR 0x13 +#define FW_CFG_CMDLINE_SIZE 0x14 +#define FW_CFG_CMDLINE_DATA 0x15 +#define FW_CFG_SETUP_ADDR 0x16 +#define FW_CFG_SETUP_SIZE 0x17 +#define FW_CFG_SETUP_DATA 0x18 +#define FW_CFG_MAX_ENTRY 0x19#define FW_CFG_WRITE_CHANNEL 0x4000#define FW_CFG_ARCH_LOCAL 0x8000
hw/pc.c +24 -102
158 lines not on this page · raw message
pc-bios/optionrom/Makefile +1 -1
@@ -13,7 +13,7 @@ CFLAGS += -I$(SRC_PATH) CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector) QEMU_CFLAGS = $(CFLAGS) -build-all: multiboot.bin +build-all: multiboot.bin linuxboot.bin %.img: %.o $(call quiet-command,$(LD) -Ttext 0 -e _start -s -o $@ $<," Building $(TARGET_DIR)$@")
pc-bios/optionrom/linuxboot.S new file +140 -0
140 lines not on this page · raw message
Signature · 1 line
1.6.0.2
[Qemu-devel] Re: [PATCH 5/6] Convert linux bootrom to external rom and fw_cfg
pc-bios/optionrom/linuxboot.S line 87
Quoted 6 lines · Alexander Graf
pc-bios/optionrom/linuxboot.S new file +6
-0+ /* Set DS to SS+SP - 0x10, so we can write our GDT descriptor there */ + mov %ss, %eax + shl $4, %eax + add %esp, %eax + sub $0x10, %eax + shr $4, %eax
Dead code? Or wrong comment and missing mov %eax, %gs?
Also, I know this is running with disabled interrupts, but why set %gs just below the stack instead of decrementing %esp?
pc-bios/optionrom/linuxboot.S line 90
Quoted 2 lines
pc-bios/optionrom/linuxboot.S new file +2
-0+ /* Now create the GDT descriptor */ + mov %cs, %eax
Paolo
Re: [Qemu-devel] Re: [PATCH 5/6] Convert linux bootrom to external rom and fw_cfg
Quoted 9 lines · Paolo Bonzini
pc-bios/optionrom/linuxboot.S line 87
Quoted 6 lines · Alexander Graf
pc-bios/optionrom/linuxboot.S new file +6
-0+ /* Set DS to SS+SP - 0x10, so we can write our GDT descriptor there */ + mov %ss, %eax + shl $4, %eax + add %esp, %eax + sub $0x10, %eax + shr $4, %eaxDead code? Or wrong comment and missing mov %eax, %gs?
The latter.
Quoted 1 line
Also, I know this is running with disabled interrupts, but why set %gs just below the stack instead of decrementing %esp?
Uh. Decrementing %esp should work too I guess. That's just what I came up with.
Alex
PATCH 1/1 Fix thinko in linuxboot.S
The %gs segment that was used was not matching the comments. I just moved the GDT descriptor on the stack instead.
--- pc-bios/optionrom/linuxboot.S | 20 ++++++++------------ 1 files changed, 8 insertions(+), 12 deletions(-)
pc-bios/optionrom/linuxboot.S +8 -12
@@ -79,24 +79,20 @@ copy_kernel: mode, so let's get into 32 bit mode, write the kernel and jump back again. */ - /* Set DS to SS+SP - 0x10, so we can write our GDT descriptor there */ - mov %ss, %eax - shl $4, %eax - add %esp, %eax - sub $0x10, %eax - shr $4, %eax + /* Reserve space on the stack for our GDT descriptor. */ + mov %esp, %ebp + sub $16, %esp /* Now create the GDT descriptor */ + movw $((3 * 8) - 1), -16(%bp) mov %cs, %eax shl $4, %eax - movw $((3 * 8) - 1), %bx - movw %bx, %gs:0 - movl $gdt, %ebx - add %eax, %ebx - movl %ebx, %gs:2 + addl $gdt, %ebx + movl %ebx, -14(%bp) /* And load the GDT */ - data32 lgdt %gs:0 + data32 lgdt -16(%bp) + mov %ebp, %esp /* Get us to protected mode now */ mov $1, %eax
Signature · 1 line
1.6.5.2
[Qemu-devel] Re: [PATCH] Fix thinko in linuxboot.S
Quoted 4 lines · Paolo Bonzini
The %gs segment that was used was not matching the comments. I just moved the GDT descriptor on the stack instead.
Signed-off-by Paolo Bonzini <[email protected]>
Looks good. Have you verified it works? :-)
Alex
[Qemu-devel] Re: [PATCH] Fix thinko in linuxboot.S
Quoted 7 lines · Alexander Graf
Quoted 4 lines · Paolo Bonzini
The %gs segment that was used was not matching the comments. I just moved the GDT descriptor on the stack instead.
Signed-off-by Paolo Bonzini <[email protected]>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 1 line
Looks good. Have you verified it works? :-)
Yes. :-)
Paolo
PATCH 6/6 Add linuxboot to BLOBS
In reply to Alexander GrafWe should install linuxboot.bin too, so let's add it to the to-be-installed blobs.
--- Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
@@ -256,7 +256,7 @@ video.x openbios-sparc32 openbios-sparc64 openbios-ppc \ pxe-ne2k_pci.bin pxe-rtl8139.bin pxe-pcnet.bin pxe-e1000.bin \ pxe-virtio.bin pxe-eepro100.bin pxe-pcnet.bin \ bamboo.dtb petalogix-s3adsp1800.dtb \ -multiboot.bin +multiboot.bin linuxboot.bin else BLOBS= endif
Signature · 1 line
1.6.0.2
It seems like this series is now in qemu.git, but I still can't boot using -kernel.
I'm starting qemu as:
/opt/qemu/bin/qemu-system-x86_64 \ -m 1500 -enable-kvm \ -kernel arch/x86/boot/bzImage \ -drive file=/dev/vg00/qemu-root,if=virtio,media=disk,cache=none,aio=threads \ -drive file=/dev/vg00/qemu-data,if=virtio,media=disk,cache=none,aio=threads \ -drive file=/root/test1.img,if=scsi,media=disk,cache=none \ -append "root=/dev/vda console=tty0 console=ttyS0,38400n8"
and it simply hangs with a black screen once the SDL window opens
Quoted 5 lines · Christoph Hellwig
It seems like this series is now in qemu.git, but I still can't boot using -kernel.
I'm starting qemu as:
Quoted 8 lines
/opt/qemu/bin/qemu-system-x86_64 \ -m 1500 -enable-kvm \ -kernel arch/x86/boot/bzImage \ -drive file=/dev/vg00/qemu-root,if=virtio,media=disk,cache=none,aio=threads \ -drive file=/dev/vg00/qemu-data,if=virtio,media=disk,cache=none,aio=threads \ -drive file=/root/test1.img,if=scsi,media=disk,cache=none \ -append "root=/dev/vda console=tty0 console=ttyS0,38400n8"
Did you rebuild qemu and make sure the new BIOS/roms were installed?
Quoted 2 lines
and it simply hangs with a black screen once the SDL window opens
I had this problem because I had not rebuilt qemu.
Regards,
Anhtony Liguori
Quoted 6 lines · Anthony Liguori
Did you rebuild qemu and make sure the new BIOS/roms were installed?
Quoted 2 lines
and it simply hangs with a black screen once the SDL window opens
I had this problem because I had not rebuilt qemu.
I did a make clean; ./configure; make; make install over a previously working backrev installation. Anything special require in addition to that?
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Anthony Liguori
Did you rebuild qemu and make sure the new BIOS/roms were installed?
Quoted 3 lines
and it simply hangs with a black screen once the SDL window opens
Quoted 7 lines
Quoted 2 lines
I had this problem because I had not rebuilt qemu.
I did a make clean; ./configure; make; make install over a previously working backrev installation. Anything special require in addition to that?
I assume you set prefix with your configure as opposed to make install DESTDIR? If so, can you post your kernel/initrd somewhere so we can try to reproduce?
Regards,
Anthony Liguori
Quoted 2 lines · Anthony Liguori
I assume you set prefix with your configure as opposed to make install DESTDIR?
Yes. It's configured the following way:
./configure \
--target-list=x86_64-softmmu \
--kerneldir=/home/hch/work/linux-2.6 \
--prefix=/opt/qemuQuoted 2 lines
If so, can you post your kernel/initrd somewhere so we can try to reproduce?
No initrd, and the kernel is here:
http://www.kernel.org/pub/linux/kernel/people/hch/misc/bzImage
Quoted 11 lines · Christoph Hellwig
Quoted 2 lines · Anthony Liguori
I assume you set prefix with your configure as opposed to make install DESTDIR?
Yes. It's configured the following way:
./configure \ --target-list=x86_64-softmmu \ --kerneldir=/home/hch/work/linux-2.6 \ --prefix=/opt/qemu
Quoted 8 lines
Quoted 2 lines
If so, can you post your kernel/initrd somewhere so we can try to reproduce?
No initrd, and the kernel is here:
http://www.kernel.org/pub/linux/kernel/people/hch/misc/bzImage
Works great here:
./x86_64-softmmu/qemu-system-x86_64 -nographic -kernel ../bzImage -append console=ttyS0 -L pc-bios
Are you sure you also have the follow-up linuxboot patch applied? The one "fixing BOCHS bios support". If it still doesn't work, make sure booting works at all without -kernel.
Alex
Quoted 8 lines · Alexander Graf
Works great here:
./x86_64-softmmu/qemu-system-x86_64 -nographic -kernel ../bzImage - append console=ttyS0 -L pc-bios
Are you sure you also have the follow-up linuxboot patch applied? The one "fixing BOCHS bios support". If it still doesn't work, make sure booting works at all without -kernel.
Hmm. Tried without -enable-kvm and then it works, so it seems it's only broken when using KVM support.
Btw, it seems like seabios takes quite a bit longer than pc bios to load the kernel, mostly while the gPXE line is displayed.
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Alexander Graf
Works great here:
./x86_64-softmmu/qemu-system-x86_64 -nographic -kernel ../bzImage - append console=ttyS0 -L pc-bios
Quoted 6 lines
Quoted 3 lines
Are you sure you also have the follow-up linuxboot patch applied? The one "fixing BOCHS bios support". If it still doesn't work, make sure booting works at all without -kernel.
Hmm. Tried without -enable-kvm and then it works, so it seems it's only broken when using KVM support.
Works here as well:
agraf@busu:~/work/qemu-late-int19/qemu> ./x86_64-softmmu/qemu-system-x86_64 -nographic -kernel ../bzImage -append console=ttyS0 -L pc-bios -enable-kvm
[ 0.000000] Linux version 2.6.32-rc7 (hch@brick) (gcc version 4.3.4 (Debian 4.3.4-5) ) #448 SMP Wed Nov 18 18:01:25 CET 2009
Quoted 2 lines
Btw, it seems like seabios takes quite a bit longer than pc bios to load the kernel, mostly while the gPXE line is displayed.
Yeah, I really wish we could disable gPXE for default boots. Usually nobody wants to -boot n anyways, and if they do they can specify that IMHO.
Alex
Quoted 4 lines · Alexander Graf
Quoted 2 lines
Btw, it seems like seabios takes quite a bit longer than pc bios to load the kernel, mostly while the gPXE line is displayed.
Yeah, I really wish we could disable gPXE for default boots. Usually nobody wants to -boot n anyways, and if they do they can specify that IMHO.
Time it with and without gPXE roms getting loaded and if there's a significant difference, it's worth thinking about.
Regards,
Anthony Liguori
Quoted 2 lines
Alex
Quoted 5 lines · Alexander Graf
agraf@busu:~/work/qemu-late-int19/qemu> ./x86_64-softmmu/qemu-system-
x86_64-nographic -kernel ../bzImage -append console=ttyS0 -L pc-bios - enable-kvm[ 0.000000] Linux version 2.6.32-rc7 (hch@brick) (gcc version 4.3.4(Debian 4.3.4-5) ) #448 SMP Wed Nov 18 18:01:25 CET 2009
Is this on an x86_64 box or i386? I can boot the same kernel with upstream qemu on another box with an x86_64 kernel and qemu.
Am 23.11.2009 um 21:21 schrieb Christoph Hellwig <[email protected]>:
Quoted 9 lines · Alexander Graf
Quoted 5 lines
agraf@busu:~/work/qemu-late-int19/qemu> ./x86_64-softmmu/qemu-system-
x86_64-nographic -kernel ../bzImage -append console=ttyS0 -L pc-bios - enable-kvm[ 0.000000] Linux version 2.6.32-rc7 (hch@brick) (gcc version 4.3.4(Debian 4.3.4-5) ) #448 SMP Wed Nov 18 18:01:25 CET 2009
Is this on an
x86_64box or i386? I can boot the same kernel with upstream qemu on another box with anx86_64kernel and qemu.
I only test things on x86_64. so you're saying it breaks on an i586 host?
Alex
Quoted 1 line
Quoted 5 lines · Alexander Graf
Quoted 2 lines
Is this on an
x86_64box or i386? I can boot the same kernel with upstream qemu on another box with anx86_64kernel and qemu.I only test things on
x86_64. so you're saying it breaks on an i586 host?
Yes, both guest and host are 32 bit.
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Alexander Graf
Quoted 3 lines
Is this on an
x86_64box or i386? I can boot the same kernel with upstream qemu on another box with anx86_64kernel and qemu.I only test things on
x86_64. so you're saying it breaks on an i586 host?Yes, both guest and host are 32 bit.
Ok I just tried to reproduce this using my netbook (32 bits only) and your kernel:
alex@linux-dpw4:~/git/qemu> uname -a
Linux linux-dpw4 2.6.27.37-0.1-pae #1 SMP 2009-10-15 14:56:58 +0200 i686 i686 i386 GNU/Linux
alex@linux-dpw4:~/git/qemu> ./i386-softmmu/qemu -enable-kvm -kernel /tmp/bzImage -append "console=ttyS0" -nographic -L pc-bios
[ 0.000000] Linux version 2.6.32-rc7 (hch@brick) (gcc version 4.3.4 (Debian 4.3.4-5) ) #448 SMP Wed Nov 18 18:01:25 CET 2009 [ 0.000000] KERNEL supported cpus: [ 0.000000] Intel GenuineIntel [ 0.000000] AMD AuthenticAMD [ 0.000000] NSC Geode by NSC [ 0.000000] Cyrix CyrixInstead [ 0.000000] Centaur CentaurHauls [ 0.000000] Transmeta GenuineTMx86 [ 0.000000] Transmeta TransmetaCPU [ 0.000000] UMC UMC UMC UMC [ 0.000000] BIOS-provided physical RAM map: [ 0.000000] BIOS-e820: 0000000000000000 - 000000000009f400 (usable) [ 0.000000] BIOS-e820: 000000000009f400 - 00000000000a0000 (reserved) [ 0.000000] BIOS-e820: 00000000000f0000 - 0000000000100000 (reserved) [ 0.000000] BIOS-e820: 0000000000100000 - 0000000007ffd000 (usable) [ 0.000000] BIOS-e820: 0000000007ffd000 - 0000000008000000 (reserved) [ 0.000000] BIOS-e820: 00000000fffc0000 - 0000000100000000 (reserved) [ 0.000000] DMI 2.4 present.
...
I don't see any breakage here.
Alex
Quoted 2 lines · Alexander Graf
Ok I just tried to reproduce this using my netbook (32 bits only) and your kernel:
Still seeing it using latests qemu.git. Any idea about other information that might help sorting it out?
I'm running Linux 2.6.31 on the host, btw.
Quoted 9 lines · Christoph Hellwig
Quoted 3 lines · Alexander Graf
Ok I just tried to reproduce this using my netbook (32 bits only) and your kernel:
Still seeing it using latests qemu.git. Any idea about other information that might help sorting it out?
Hm - are you using -L pc-bios? Also, maybe there's something in dmesg telling you about an invalid instruction or the likes?
Alex
Quoted 1 line · Alexander Graf
Hm - are you using -L pc-bios?
No. I use an installed qemu (./configure --prefix=/opt/qemu) and there's no pc-bios directorie in my kernel source tree where I start it from.
Quoted 2 lines
Also, maybe there's something in dmesg telling you about an invalid instruction or the likes?
[ 5928.948615] kvm: 14584: cpu0 unhandled wrmsr: 0xc0000083 data 0 [ 5929.309486] kvm: 14584: cpu0 unhandled wrmsr: 0xc0000083 data 0 [ 5929.309530] kvm: 14584: cpu0 unhandled rdmsr: 0xc0000083 [ 5929.311763] kvm: 14584: cpu0 unhandled wrmsr: 0xc0000083 data 0 [ 5929.311856] kvm: 14584: cpu0 unhandled wrmsr: 0xc0000083 data 0 [ 5929.311899] kvm: 14584: cpu0 unhandled rdmsr: 0xc0000083 [ 5929.313408] kvm: 14584: cpu0 unhandled wrmsr: 0xc0000083 data 0
Quoted 9 lines · Christoph Hellwig
Quoted 2 lines · Alexander Graf
Hm - are you using -L pc-bios?
No. I use an installed qemu (./configure --prefix=/opt/qemu) and there's no pc-bios directorie in my kernel source tree where I start it from.
Hm - maybe worth a try to give it a -L to the source pc-bios directory anyways.
Quoted 4 lines
Quoted 3 lines
Also, maybe there's something in dmesg telling you about an invalid instruction or the likes?
Quoted 8 lines
[ 5928.948615] kvm: 14584: cpu0 unhandled wrmsr: 0xc0000083 data 0 [ 5929.309486] kvm: 14584: cpu0 unhandled wrmsr: 0xc0000083 data 0 [ 5929.309530] kvm: 14584: cpu0 unhandled rdmsr: 0xc0000083 [ 5929.311763] kvm: 14584: cpu0 unhandled wrmsr: 0xc0000083 data 0 [ 5929.311856] kvm: 14584: cpu0 unhandled wrmsr: 0xc0000083 data 0 [ 5929.311899] kvm: 14584: cpu0 unhandled rdmsr: 0xc0000083 [ 5929.313408] kvm: 14584: cpu0 unhandled wrmsr: 0xc0000083 data 0
/include/asm/msr-index.h:#define MSR_CSTAR 0xc0000083 /* compat
mode SYSCALL target */
Sounds like your guest kernel is trying to access an x86_64 register?
You can of cause try insmod'ing kvm.ko with ignore_msrs=1. You hopefully don't need syscalls until you get into user space.
Alex
Quoted 2 lines · Alexander Graf
Hm - maybe worth a try to give it a -L to the source pc-bios directory anyways.
Doesn't change a thing.
Quoted 4 lines
Sounds like your guest kernel is trying to access an
x86_64register?You can of cause try insmod'ing kvm.ko with ignore_msrs=1. You hopefully don't need syscalls until you get into user space.
The option doesn't exist yet in 2.6.31 which I'm running on this box because 2.6.32-rc has massive regressions for my workload. I booted into it again anyway to test the option - and interestingly enough qemu with -enable-kvm boots just fine even without ignore_msrs=1.
Looks like the problem only happens with older kernels.
Quoted 6 lines · Christoph Hellwig
Quoted 6 lines
Sounds like your guest kernel is trying to access an
x86_64register?You can of cause try insmod'ing kvm.ko with ignore_msrs=1. You hopefully don't need syscalls until you get into user space.
Quoted 7 lines
The option doesn't exist yet in 2.6.31 which I'm running on this box because 2.6.32-rc has massive regressions for my workload. I booted into it again anyway to test the option - and interestingly enough qemu with -enable-kvm boots just fine even without ignore_msrs=1.
Looks like the problem only happens with older kernels.
Strange - qemu -kernel has zero interaction with the host kernel. It's a totally normal boot process.
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
Quoted 2 lines · Avi Kivity
Strange - qemu -kernel has zero interaction with the host kernel. It's a totally normal boot process.
Well, it's entirely reproducable. Any idea how to make progress on this? It really keeps me from making progress on doing any qemu development. Note that simply reverting bios.bin and pcbios.bin to the old pcbios binaries does not fix the latests git tree anymore.