From patchwork Tue Jul 21 02:42:49 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 36439 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n6L2hGnm017391 for ; Tue, 21 Jul 2009 02:43:16 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754717AbZGUCnM (ORCPT ); Mon, 20 Jul 2009 22:43:12 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754578AbZGUCnM (ORCPT ); Mon, 20 Jul 2009 22:43:12 -0400 Received: from mga02.intel.com ([134.134.136.20]:22667 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754564AbZGUCnK (ORCPT ); Mon, 20 Jul 2009 22:43:10 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 20 Jul 2009 19:32:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.43,238,1246863600"; d="scan'208";a="431885212" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.13.29]) by orsmga002.jf.intel.com with ESMTP; 20 Jul 2009 19:49:59 -0700 Received: from yasker by syang10-desktop with local (Exim 4.69) (envelope-from ) id 1MT5JZ-0000Vu-3L; Tue, 21 Jul 2009 10:42:49 +0800 From: Sheng Yang To: Marcelo Tosatti Cc: kvm@vger.kernel.org, Avi Kivity , Sheng Yang Subject: [PATCH 2/2][v2] kvm: allow qemu to set EPT identity mapping address Date: Tue, 21 Jul 2009 10:42:49 +0800 Message-Id: <1248144169-1952-2-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.6.0.4 In-Reply-To: <1248144169-1952-1-git-send-email-sheng@linux.intel.com> References: <1248144169-1952-1-git-send-email-sheng@linux.intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org If we use larger BIOS image than current 256KB, we would need move reserved TSS and EPT identity mapping pages. Currently TSS support this, but not EPT. (change from v1, use parameter address instead of value for ioctl) Signed-off-by: Sheng Yang --- kvm/include/linux/kvm.h | 2 ++ qemu-kvm-x86.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 0 deletions(-) diff --git a/kvm/include/linux/kvm.h b/kvm/include/linux/kvm.h index 790601d..079df62 100644 --- a/kvm/include/linux/kvm.h +++ b/kvm/include/linux/kvm.h @@ -465,6 +465,7 @@ struct kvm_trace_rec { #define KVM_CAP_JOIN_MEMORY_REGIONS_WORKS 30 #define KVM_CAP_PIT2 33 #define KVM_CAP_PIT_STATE2 35 +#define KVM_CAP_SET_IDENTITY_MAP_ADDR 37 #ifdef KVM_CAP_IRQ_ROUTING @@ -513,6 +514,7 @@ struct kvm_irq_routing { #define KVM_SET_USER_MEMORY_REGION _IOW(KVMIO, 0x46,\ struct kvm_userspace_memory_region) #define KVM_SET_TSS_ADDR _IO(KVMIO, 0x47) +#define KVM_SET_IDENTITY_MAP_ADDR _IOW(KVMIO, 0x48, __u64) /* * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns * a vcpu fd. diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index daf60b6..0e17ac8 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -74,6 +74,47 @@ static int kvm_init_tss(kvm_context_t kvm) return 0; } +static int kvm_set_identity_map_addr(kvm_context_t kvm, unsigned long addr) +{ +#ifdef KVM_CAP_SET_IDENTITY_MAP_ADDR + int r; + + r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_IDENTITY_MAP_ADDR); + if (r > 0) { + r = ioctl(kvm->vm_fd, KVM_SET_IDENTITY_MAP_ADDR, &addr); + if (r == -1) { + fprintf(stderr, "kvm_set_identity_map_addr: %m\n"); + return -errno; + } + return 0; + } +#endif + return -ENOSYS; +} + +static int kvm_init_identity_map_page(kvm_context_t kvm) +{ +#ifdef KVM_CAP_SET_IDENTITY_MAP_ADDR + int r; + + r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_IDENTITY_MAP_ADDR); + if (r > 0) { + /* + * this address is 4 pages before the bios, and the bios should present + * as unavaible memory + */ + r = kvm_set_identity_map_addr(kvm, 0xfffbc000); + if (r < 0) { + fprintf(stderr, "kvm_init_identity_map_page: " + "unable to set identity mapping addr\n"); + return r; + } + + } +#endif + return 0; +} + static int kvm_create_pit(kvm_context_t kvm) { #ifdef KVM_CAP_PIT @@ -105,6 +146,10 @@ int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes, if (r < 0) return r; + r = kvm_init_identity_map_page(kvm); + if (r < 0) + return r; + r = kvm_create_pit(kvm); if (r < 0) return r;