From patchwork Tue Jan 4 08:32:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 450081 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p048WoTL005428 for ; Tue, 4 Jan 2011 08:33:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752439Ab1ADIcr (ORCPT ); Tue, 4 Jan 2011 03:32:47 -0500 Received: from fmmailgate03.web.de ([217.72.192.234]:37480 "EHLO fmmailgate03.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752351Ab1ADIco (ORCPT ); Tue, 4 Jan 2011 03:32:44 -0500 Received: from smtp04.web.de ( [172.20.0.225]) by fmmailgate03.web.de (Postfix) with ESMTP id 2999118392933; Tue, 4 Jan 2011 09:32:44 +0100 (CET) Received: from [88.64.22.98] (helo=localhost.localdomain) by smtp04.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #2) id 1Pa2Jw-00050n-00; Tue, 04 Jan 2011 09:32:44 +0100 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH v3 18/21] kvm: x86: Rework identity map and TSS setup for larger BIOS sizes Date: Tue, 4 Jan 2011 09:32:30 +0100 Message-Id: <2efcebfac8252a2ee8908890519f88684626f9ad.1294129949.git.jan.kiszka@web.de> X-Mailer: git-send-email 1.7.1 In-Reply-To: References: In-Reply-To: References: X-Sender: jan.kiszka@web.de X-Provags-ID: V01U2FsdGVkX189cdXkPgcLndZ2ORm6UiDKGcs3kI34RyG9jWl0 6OXPJfkzicCuiYPuJSHzhRX0q337ghkeftN4h7UErxSDGvYDSQ obbKNLrbE= Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 04 Jan 2011 08:33:24 +0000 (UTC) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 58122d9..50d8ec8 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -578,27 +578,9 @@ static int kvm_get_supported_msrs(void) return ret; } -static int kvm_init_identity_map_page(void) -{ -#ifdef KVM_CAP_SET_IDENTITY_MAP_ADDR - int ret; - uint64_t addr = 0xfffbc000; - - if (!kvm_check_extension(KVM_CAP_SET_IDENTITY_MAP_ADDR)) { - return 0; - } - - ret = kvm_vm_ioctl(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(void) { + uint64_t identity_base = 0xfffbc000; int ret; struct utsname utsname; @@ -614,27 +596,42 @@ int kvm_arch_init(void) 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(KVM_CAP_SET_IDENTITY_MAP_ADDR)) { + /* Allows up to 16M BIOSes. */ + identity_base = 0xfeffc000; + + ret = kvm_vm_ioctl(KVM_SET_IDENTITY_MAP_ADDR, &identity_base); + if (ret < 0) { + return ret; + } } - ret = kvm_vm_ioctl(KVM_SET_TSS_ADDR, 0xfffbd000); +#endif + /* Set TSS base one page after EPT identity map. */ + ret = kvm_vm_ioctl(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(); + return 0; } static void set_v8086_seg(struct kvm_segment *lhs, const SegmentCache *rhs)