From patchwork Fri Jul 17 08:11:13 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 35993 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 n6H8BeqA014342 for ; Fri, 17 Jul 2009 08:11:40 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934203AbZGQILi (ORCPT ); Fri, 17 Jul 2009 04:11:38 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S934202AbZGQILi (ORCPT ); Fri, 17 Jul 2009 04:11:38 -0400 Received: from mga01.intel.com ([192.55.52.88]:10322 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934179AbZGQILh (ORCPT ); Fri, 17 Jul 2009 04:11:37 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 17 Jul 2009 00:56:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.42,416,1243839600"; d="scan'208";a="475728034" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.13.29]) by fmsmga002.fm.intel.com with ESMTP; 17 Jul 2009 01:04:42 -0700 Received: from yasker by syang10-desktop with local (Exim 4.69) (envelope-from ) id 1MRiXB-0007k2-Lc; Fri, 17 Jul 2009 16:11:13 +0800 From: Sheng Yang To: Marcelo Tosatti Cc: kvm@vger.kernel.org, jordan.l.justen@intel.com, Sheng Yang Subject: [PATCH 2/2] kvm: allow qemu to set EPT identity mapping address Date: Fri, 17 Jul 2009 16:11:13 +0800 Message-Id: <1247818273-29737-2-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.6.0.4 In-Reply-To: <1247818273-29737-1-git-send-email-sheng@linux.intel.com> References: <1247818273-29737-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. 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..9161595 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 _IO(KVMIO, 0x48) /* * 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..8ec4e4c 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;