[PATCH] Seabios - read e820 reserve from qemu_cfg

2010-01-25 Thread Jes Sorensen

Hi,

Right now KVM/QEMU relies on hard coded values in Seabios for the
reserved area for the TSS pages and the EPT page.

I'd like to suggest we change this to pass the value from QEMU via
qemu-cfg making it possible to move it around dynamically in the future.

Attached is a patch to Seabios for this, which defaults to the current
hard coded value if no value is provided by qemu-cfg. We can remove
the backwards compatibility later.

I'll post the QEMU patches for upstream QEMU and QEMU-KVM in a minute.

Comments most welcome!

Cheers,
Jes

Read location and size of KVM switch area from qemu-cfg

Read location of KVM's switch area (VMX TSS pages and EPT) from QEMU
via qemu-cfg instead of relying on hard coded values.

For now, fall back to the old hard coded values for compatibility
reasons. Compatibility code can be removed in the future.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com

---
 src/paravirt.c |9 +
 src/paravirt.h |7 +++
 src/post.c |   14 ++
 3 files changed, 26 insertions(+), 4 deletions(-)

Index: seabios/src/paravirt.c
===
--- seabios.orig/src/paravirt.c
+++ seabios/src/paravirt.c
@@ -132,6 +132,15 @@ u16 qemu_cfg_smbios_entries(void)
 return cnt;
 }
 
+int qemu_cfg_read_e820_reserve(struct qemu_cfg_e820_reserve *reserve)
+{
+if (!qemu_cfg_present)
+return 0;
+
+qemu_cfg_read((void *)reserve, sizeof(*reserve));
+return reserve-length;
+}
+
 struct smbios_header {
 u16 length;
 u8 type;
Index: seabios/src/paravirt.h
===
--- seabios.orig/src/paravirt.h
+++ seabios/src/paravirt.h
@@ -36,6 +36,7 @@ static inline int kvm_para_available(voi
 #define QEMU_CFG_ACPI_TABLES   (QEMU_CFG_ARCH_LOCAL + 0)
 #define QEMU_CFG_SMBIOS_ENTRIES(QEMU_CFG_ARCH_LOCAL + 1)
 #define QEMU_CFG_IRQ0_OVERRIDE (QEMU_CFG_ARCH_LOCAL + 2)
+#define QEMU_CFG_E820_RESERVE  (QEMU_CFG_ARCH_LOCAL + 3)
 
 extern int qemu_cfg_present;
 
@@ -61,8 +62,14 @@ typedef struct QemuCfgFile {
 char name[56];
 } QemuCfgFile;
 
+struct qemu_cfg_e820_reserve {
+u32 addr;
+u32 length;
+};
+
 u16 qemu_cfg_first_file(QemuCfgFile *entry);
 u16 qemu_cfg_next_file(QemuCfgFile *entry);
 u32 qemu_cfg_read_file(QemuCfgFile *entry, void *dst, u32 maxlen);
+int qemu_cfg_read_e820_reserve(struct qemu_cfg_e820_reserve *reserve);
 
 #endif
Index: seabios/src/post.c
===
--- seabios.orig/src/post.c
+++ seabios/src/post.c
@@ -135,10 +135,16 @@ ram_probe(void)
  , E820_RESERVED);
 add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED);
 
-if (kvm_para_available())
-// 4 pages before the bios, 3 pages for vmx tss pages, the
-// other page for EPT real mode pagetable
-add_e820(0xfffbc000, 4*4096, E820_RESERVED);
+if (kvm_para_available()) {
+struct qemu_cfg_e820_reserve e820_reserve;
+if (qemu_cfg_read_e820_reserve(e820_reserve))
+add_e820(e820_reserve.addr, e820_reserve.length, E820_RESERVED);
+else {
+// 4 pages before the bios, 3 pages for vmx tss pages, the
+// other page for EPT real mode pagetable
+add_e820(0xfffbc000, 4*4096, E820_RESERVED);
+}
+}
 
 dprintf(1, Ram Size=0x%08x (0x%08x%08x high)\n
 , RamSize, (u32)(RamSizeOver4G  32), (u32)RamSizeOver4G);


Re: [PATCH] Seabios - read e820 reserve from qemu_cfg

2010-01-25 Thread Kevin O'Connor
On Mon, Jan 25, 2010 at 05:46:42PM +0100, Jes Sorensen wrote:
 Hi,
 
 Right now KVM/QEMU relies on hard coded values in Seabios for the
 reserved area for the TSS pages and the EPT page.
 
 I'd like to suggest we change this to pass the value from QEMU via
 qemu-cfg making it possible to move it around dynamically in the future.
 
 Attached is a patch to Seabios for this, which defaults to the current
 hard coded value if no value is provided by qemu-cfg. We can remove
 the backwards compatibility later.
 
 I'll post the QEMU patches for upstream QEMU and QEMU-KVM in a minute.
 
 Comments most welcome!

I like the idea, but I think it would be better to pass a list of e820
entries explicitly.  That is, pass an array of:

struct e820entry {
u64 start;
u64 size;
u32 type;
};

where 'type' uses the standard e820 definitions.  That way, SeaBIOS
can just walk through the list and add them to its e820 map.  BTW,
this is what SeaBIOS does when running under coreboot (coreboot passes
a memory map as part of the coreboot tables).  SeaBIOS is already
smart enough to not use any high memory addresses marked as reserved.

-Kevin
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html