From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jes Sorensen Subject: [PATCH] QEMU-KVM - provide e820 table via fw_cfg Date: Tue, 26 Jan 2010 22:53:51 +0100 Message-ID: <4B5F646F.7040001@redhat.com> References: <4B5DCAF2.3010105@redhat.com> <20100126002447.GA8800@morn.localdomain> <4B5F640C.2030907@redhat.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040706030409010605020205" Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Avi Kivity , Anthony Liguori , seabios@seabios.org, Alexander Graf To: "Kevin O'Connor" Return-path: Received: from mx1.redhat.com ([209.132.183.28]:19354 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753795Ab0AZVyD (ORCPT ); Tue, 26 Jan 2010 16:54:03 -0500 In-Reply-To: <4B5F640C.2030907@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: This is a multi-part message in MIME format. --------------040706030409010605020205 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, This is the QEMU-KVM part of the patch. If we can agree on this approach, I will do a version for upstream QEMU as well. Cheers, Jes --------------040706030409010605020205 Content-Type: text/plain; name="0011-qemu-kvm-e820-table.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0011-qemu-kvm-e820-table.patch" Use qemu-cfg to provide the BIOS with an optional table of e820 entries. Notify the BIOS of the location of the TSS+EPT range to by reserving it via the e820 table. Signed-off-by: Jes Sorensen --- hw/pc.c | 35 +++++++++++++++++++++++++++++++++++ hw/pc.h | 9 +++++++++ qemu-kvm-x86.c | 7 +++++++ target-i386/kvm.c | 7 +++++++ 4 files changed, 58 insertions(+) Index: qemu-kvm/hw/pc.c =================================================================== --- qemu-kvm.orig/hw/pc.c +++ qemu-kvm/hw/pc.c @@ -66,6 +66,7 @@ #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0) #define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1) #define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2) +#define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3) #define MAX_IDE_BUS 2 @@ -74,6 +75,21 @@ static RTCState *rtc_state; static PITState *pit; static PCII440FXState *i440fx_state; +#define E820_NR_ENTRIES 16 + +struct e820_entry { + uint64_t address; + uint64_t length; + uint32_t type; +}; + +struct e820_table { + uint32_t count; + struct e820_entry entry[E820_NR_ENTRIES]; +}; + +static struct e820_table e820_table; + qemu_irq *ioapic_irq_hack; typedef struct isa_irq_state { @@ -444,6 +460,23 @@ static void bochs_bios_write(void *opaqu } } +int e820_add_entry(uint64_t address, uint64_t length, uint32_t type) +{ + int index = e820_table.count; + struct e820_entry *entry; + + if (index >= E820_NR_ENTRIES) + return -EBUSY; + entry = &e820_table.entry[index]; + + entry->address = address; + entry->length = length; + entry->type = type; + + e820_table.count++; + return e820_table.count; +} + static void *bochs_bios_init(void) { void *fw_cfg; @@ -475,6 +508,8 @@ static void *bochs_bios_init(void) if (smbios_table) fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES, smbios_table, smbios_len); + fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE, (uint8_t *)&e820_table, + sizeof(struct e820_table)); /* allocate memory for the NUMA channel: one (64bit) word for the number * of nodes, one word for each VCPU->node and one word for each node to Index: qemu-kvm/hw/pc.h =================================================================== --- qemu-kvm.orig/hw/pc.h +++ qemu-kvm/hw/pc.h @@ -169,4 +169,13 @@ void extboot_init(BlockDriverState *bs, int cpu_is_bsp(CPUState *env); +/* e820 types */ +#define E820_RAM 1 +#define E820_RESERVED 2 +#define E820_ACPI 3 +#define E820_NVS 4 +#define E820_UNUSABLE 5 + +int e820_add_entry(uint64_t, uint64_t, uint32_t); + #endif Index: qemu-kvm/qemu-kvm-x86.c =================================================================== --- qemu-kvm.orig/qemu-kvm-x86.c +++ qemu-kvm/qemu-kvm-x86.c @@ -37,6 +37,13 @@ int kvm_set_tss_addr(kvm_context_t kvm, { #ifdef KVM_CAP_SET_TSS_ADDR int r; + /* + * Tell fw_cfg to notify the BIOS to reserve the range. + */ + if (e820_add_entry(addr, 0x4000, E820_RESERVED) < 0) { + perror("e820_add_entry() table is full"); + exit(1); + } r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR); if (r > 0) { Index: qemu-kvm/target-i386/kvm.c =================================================================== --- qemu-kvm.orig/target-i386/kvm.c +++ qemu-kvm/target-i386/kvm.c @@ -298,6 +298,13 @@ int kvm_arch_init(KVMState *s, int smp_c * as unavaible memory. FIXME, need to ensure the e820 map deals with * this? */ + /* + * Tell fw_cfg to notify the BIOS to reserve the range. + */ + if (e820_add_entry(0xfffbc000, 0x4000, E820_RESERVED) < 0) { + perror("e820_add_entry() table is full"); + exit(1); + } return kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, 0xfffbd000); } --------------040706030409010605020205-- From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NZtMK-00066G-EZ for qemu-devel@nongnu.org; Tue, 26 Jan 2010 16:54:04 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NZtMF-00062h-K5 for qemu-devel@nongnu.org; Tue, 26 Jan 2010 16:54:04 -0500 Received: from [199.232.76.173] (port=45075 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZtMF-00062X-Ca for qemu-devel@nongnu.org; Tue, 26 Jan 2010 16:53:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46472) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NZtMF-0007wS-2r for qemu-devel@nongnu.org; Tue, 26 Jan 2010 16:53:59 -0500 Message-ID: <4B5F646F.7040001@redhat.com> Date: Tue, 26 Jan 2010 22:53:51 +0100 From: Jes Sorensen MIME-Version: 1.0 References: <4B5DCAF2.3010105@redhat.com> <20100126002447.GA8800@morn.localdomain> <4B5F640C.2030907@redhat.com> In-Reply-To: <4B5F640C.2030907@redhat.com> Content-Type: multipart/mixed; boundary="------------040706030409010605020205" Subject: [Qemu-devel] [PATCH] QEMU-KVM - provide e820 table via fw_cfg List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin O'Connor Cc: Anthony Liguori , kvm@vger.kernel.org, seabios@seabios.org, Alexander Graf , qemu-devel@nongnu.org, Avi Kivity This is a multi-part message in MIME format. --------------040706030409010605020205 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, This is the QEMU-KVM part of the patch. If we can agree on this approach, I will do a version for upstream QEMU as well. Cheers, Jes --------------040706030409010605020205 Content-Type: text/plain; name="0011-qemu-kvm-e820-table.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0011-qemu-kvm-e820-table.patch" Use qemu-cfg to provide the BIOS with an optional table of e820 entries. Notify the BIOS of the location of the TSS+EPT range to by reserving it via the e820 table. Signed-off-by: Jes Sorensen --- hw/pc.c | 35 +++++++++++++++++++++++++++++++++++ hw/pc.h | 9 +++++++++ qemu-kvm-x86.c | 7 +++++++ target-i386/kvm.c | 7 +++++++ 4 files changed, 58 insertions(+) Index: qemu-kvm/hw/pc.c =================================================================== --- qemu-kvm.orig/hw/pc.c +++ qemu-kvm/hw/pc.c @@ -66,6 +66,7 @@ #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0) #define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1) #define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2) +#define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3) #define MAX_IDE_BUS 2 @@ -74,6 +75,21 @@ static RTCState *rtc_state; static PITState *pit; static PCII440FXState *i440fx_state; +#define E820_NR_ENTRIES 16 + +struct e820_entry { + uint64_t address; + uint64_t length; + uint32_t type; +}; + +struct e820_table { + uint32_t count; + struct e820_entry entry[E820_NR_ENTRIES]; +}; + +static struct e820_table e820_table; + qemu_irq *ioapic_irq_hack; typedef struct isa_irq_state { @@ -444,6 +460,23 @@ static void bochs_bios_write(void *opaqu } } +int e820_add_entry(uint64_t address, uint64_t length, uint32_t type) +{ + int index = e820_table.count; + struct e820_entry *entry; + + if (index >= E820_NR_ENTRIES) + return -EBUSY; + entry = &e820_table.entry[index]; + + entry->address = address; + entry->length = length; + entry->type = type; + + e820_table.count++; + return e820_table.count; +} + static void *bochs_bios_init(void) { void *fw_cfg; @@ -475,6 +508,8 @@ static void *bochs_bios_init(void) if (smbios_table) fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES, smbios_table, smbios_len); + fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE, (uint8_t *)&e820_table, + sizeof(struct e820_table)); /* allocate memory for the NUMA channel: one (64bit) word for the number * of nodes, one word for each VCPU->node and one word for each node to Index: qemu-kvm/hw/pc.h =================================================================== --- qemu-kvm.orig/hw/pc.h +++ qemu-kvm/hw/pc.h @@ -169,4 +169,13 @@ void extboot_init(BlockDriverState *bs, int cpu_is_bsp(CPUState *env); +/* e820 types */ +#define E820_RAM 1 +#define E820_RESERVED 2 +#define E820_ACPI 3 +#define E820_NVS 4 +#define E820_UNUSABLE 5 + +int e820_add_entry(uint64_t, uint64_t, uint32_t); + #endif Index: qemu-kvm/qemu-kvm-x86.c =================================================================== --- qemu-kvm.orig/qemu-kvm-x86.c +++ qemu-kvm/qemu-kvm-x86.c @@ -37,6 +37,13 @@ int kvm_set_tss_addr(kvm_context_t kvm, { #ifdef KVM_CAP_SET_TSS_ADDR int r; + /* + * Tell fw_cfg to notify the BIOS to reserve the range. + */ + if (e820_add_entry(addr, 0x4000, E820_RESERVED) < 0) { + perror("e820_add_entry() table is full"); + exit(1); + } r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR); if (r > 0) { Index: qemu-kvm/target-i386/kvm.c =================================================================== --- qemu-kvm.orig/target-i386/kvm.c +++ qemu-kvm/target-i386/kvm.c @@ -298,6 +298,13 @@ int kvm_arch_init(KVMState *s, int smp_c * as unavaible memory. FIXME, need to ensure the e820 map deals with * this? */ + /* + * Tell fw_cfg to notify the BIOS to reserve the range. + */ + if (e820_add_entry(0xfffbc000, 0x4000, E820_RESERVED) < 0) { + perror("e820_add_entry() table is full"); + exit(1); + } return kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, 0xfffbd000); } --------------040706030409010605020205--