From patchwork Mon Jan 24 09:02:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 80122 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 2A2B6B7129 for ; Mon, 24 Jan 2011 20:50:55 +1100 (EST) Received: from localhost ([127.0.0.1]:43870 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PhJ4V-0000Ud-V5 for incoming@patchwork.ozlabs.org; Mon, 24 Jan 2011 04:50:52 -0500 Received: from [140.186.70.92] (port=38089 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PhIMX-0008Q2-9W for qemu-devel@nongnu.org; Mon, 24 Jan 2011 04:05:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PhIMQ-0007Fr-34 for qemu-devel@nongnu.org; Mon, 24 Jan 2011 04:05:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:64387) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PhIMP-0007Eu-S2 for qemu-devel@nongnu.org; Mon, 24 Jan 2011 04:05:18 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0O95GAm018987 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 24 Jan 2011 04:05:16 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p0O95GDp015544; Mon, 24 Jan 2011 04:05:16 -0500 Received: from amt.cnet (vpn2-9-29.ams2.redhat.com [10.36.9.29]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p0O95BkL008804; Mon, 24 Jan 2011 04:05:14 -0500 Received: from amt.cnet (localhost.localdomain [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 9545465215E; Mon, 24 Jan 2011 07:04:41 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.4/8.14.4/Submit) id p0O94ciK028423; Mon, 24 Jan 2011 07:04:38 -0200 From: Marcelo Tosatti To: Anthony Liguori Date: Mon, 24 Jan 2011 07:02:36 -0200 Message-Id: <110761987d10c6e6983cc445618acfd158d7ce02.1295859760.git.mtosatti@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Jan Kiszka , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 27/31] kvm: x86: Rework identity map and TSS setup for larger BIOS sizes 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 From: Jan Kiszka In order to support loading BIOSes > 256K, reorder the code, adjusting the base if the kernel supports moving the identity map. Signed-off-by: Jan Kiszka Signed-off-by: Marcelo Tosatti --- target-i386/kvm.c | 63 +++++++++++++++++++++++++--------------------------- 1 files changed, 30 insertions(+), 33 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 1db8227..72f9fdf 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -493,27 +493,9 @@ static int kvm_get_supported_msrs(KVMState *s) return ret; } -static int kvm_init_identity_map_page(KVMState *s) -{ -#ifdef KVM_CAP_SET_IDENTITY_MAP_ADDR - int ret; - uint64_t addr = 0xfffbc000; - - if (!kvm_check_extension(s, KVM_CAP_SET_IDENTITY_MAP_ADDR)) { - return 0; - } - - ret = kvm_vm_ioctl(s, KVM_SET_IDENTITY_MAP_ADDR, &addr); - if (ret < 0) { - fprintf(stderr, "kvm_set_identity_map_addr: %s\n", strerror(ret)); - return ret; - } -#endif - return 0; -} - int kvm_arch_init(KVMState *s) { + uint64_t identity_base = 0xfffbc000; int ret; struct utsname utsname; @@ -525,27 +507,42 @@ int kvm_arch_init(KVMState *s) uname(&utsname); lm_capable_kernel = strcmp(utsname.machine, "x86_64") == 0; - /* create vm86 tss. KVM uses vm86 mode to emulate 16-bit code - * directly. In order to use vm86 mode, a TSS is needed. Since this - * must be part of guest physical memory, we need to allocate it. */ - - /* this address is 3 pages before the bios, and the bios should present - * as unavaible memory. FIXME, need to ensure the e820 map deals with - * this? - */ /* - * Tell fw_cfg to notify the BIOS to reserve the range. + * On older Intel CPUs, KVM uses vm86 mode to emulate 16-bit code directly. + * In order to use vm86 mode, an EPT identity map and a TSS are needed. + * Since these must be part of guest physical memory, we need to allocate + * them, both by setting their start addresses in the kernel and by + * creating a corresponding e820 entry. We need 4 pages before the BIOS. + * + * Older KVM versions may not support setting the identity map base. In + * that case we need to stick with the default, i.e. a 256K maximum BIOS + * size. */ - if (e820_add_entry(0xfffbc000, 0x4000, E820_RESERVED) < 0) { - perror("e820_add_entry() table is full"); - exit(1); +#ifdef KVM_CAP_SET_IDENTITY_MAP_ADDR + if (kvm_check_extension(s, KVM_CAP_SET_IDENTITY_MAP_ADDR)) { + /* Allows up to 16M BIOSes. */ + identity_base = 0xfeffc000; + + ret = kvm_vm_ioctl(s, KVM_SET_IDENTITY_MAP_ADDR, &identity_base); + if (ret < 0) { + return ret; + } } - ret = kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, 0xfffbd000); +#endif + /* Set TSS base one page after EPT identity map. */ + ret = kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, identity_base + 0x1000); + if (ret < 0) { + return ret; + } + + /* Tell fw_cfg to notify the BIOS to reserve the range. */ + ret = e820_add_entry(identity_base, 0x4000, E820_RESERVED); if (ret < 0) { + fprintf(stderr, "e820_add_entry() table is full\n"); return ret; } - return kvm_init_identity_map_page(s); + return 0; } static void set_v8086_seg(struct kvm_segment *lhs, const SegmentCache *rhs)