From patchwork Tue Jan 26 21:53:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jes Sorensen X-Patchwork-Id: 43750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C4D1BB7CD5 for ; Wed, 27 Jan 2010 08:59:18 +1100 (EST) Received: from localhost ([127.0.0.1]:43707 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZtOr-0006oH-Lv for incoming@patchwork.ozlabs.org; Tue, 26 Jan 2010 16:56:41 -0500 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 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0QLruUb009766 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Jan 2010 16:53:56 -0500 Received: from [10.36.4.211] (vpn1-4-211.ams2.redhat.com [10.36.4.211]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0QLrqCG005502; Tue, 26 Jan 2010 16:53:52 -0500 Message-ID: <4B5F646F.7040001@redhat.com> Date: Tue, 26 Jan 2010 22:53:51 +0100 From: Jes Sorensen User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.5) Gecko/20091209 Fedora/3.0-4.fc12 Lightning/1.0pre Thunderbird/3.0 MIME-Version: 1.0 To: "Kevin O'Connor" References: <4B5DCAF2.3010105@redhat.com> <20100126002447.GA8800@morn.localdomain> <4B5F640C.2030907@redhat.com> In-Reply-To: <4B5F640C.2030907@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Anthony Liguori , kvm@vger.kernel.org, seabios@seabios.org, Alexander Graf , qemu-devel@nongnu.org, Avi Kivity Subject: [Qemu-devel] [PATCH] QEMU-KVM - provide e820 table via fw_cfg X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 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); }