From patchwork Mon Aug 17 13:48:36 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: oritw@il.ibm.com X-Patchwork-Id: 42037 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 n7HDn1DC029894 for ; Mon, 17 Aug 2009 13:49:01 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752328AbZHQNs6 (ORCPT ); Mon, 17 Aug 2009 09:48:58 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752480AbZHQNs6 (ORCPT ); Mon, 17 Aug 2009 09:48:58 -0400 Received: from mtagate3.uk.ibm.com ([195.212.29.136]:43043 "EHLO mtagate3.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752256AbZHQNs5 (ORCPT ); Mon, 17 Aug 2009 09:48:57 -0400 Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate3.uk.ibm.com (8.14.3/8.13.8) with ESMTP id n7HDmm4S333828 for ; Mon, 17 Aug 2009 13:48:48 GMT Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id n7HDmmX41146966 for ; Mon, 17 Aug 2009 14:48:48 +0100 Received: from d06av04.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n7HDmlQf031214 for ; Mon, 17 Aug 2009 14:48:48 +0100 Received: from localhost.localdomain (cluwyn.haifa.ibm.com [9.148.27.75]) by d06av04.portsmouth.uk.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id n7HDmi6O031147; Mon, 17 Aug 2009 14:48:45 +0100 From: oritw@il.ibm.com To: kvm@vger.kernel.org Cc: benami@il.ibm.com, muli@il.ibm.com, abelg@il.ibm.com, aliguori@us.ibm.com, mdday@us.ibm.com, agraf@suse.de, joerg.roedel@amd.com, Orit Wasserman Subject: [RFC] Nested VMX support - userspace Date: Mon, 17 Aug 2009 16:48:36 +0300 Message-Id: <1250516916-19493-2-git-send-email-oritw@il.ibm.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1250516916-19493-1-git-send-email-oritw@il.ibm.com> References: <1250516916-19493-1-git-send-email-oritw@il.ibm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Orit Wasserman This patch adds nested VMX. It exposes VMX capabilities in the CPU required for running a nested hypervisor. Signed-off-by: Orit Wasserman --- qemu-kvm-x86.c | 37 +++++++++++++++++++++++++++++++++++-- 1 files changed, 35 insertions(+), 2 deletions(-) diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index 492dbc5..92dd184 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -1254,6 +1254,18 @@ static void kvm_trim_features(uint32_t *features, uint32_t supported) } } +static inline void set_bit(int bit, uint32_t *field) +{ + field[bit >> 5] |= 1 << (bit & 0x1F); +} + +static inline int is_vendor_intel(struct kvm_cpuid_entry2 *ent) +{ + return ent->ebx == 0x756e6547 && /* "Genu" */ + ent->ecx == 0x6c65746e && /* "ineI" */ + ent->edx == 0x49656e69; /* "ntel" */ +} + int kvm_arch_qemu_init_env(CPUState *cenv) { struct kvm_cpuid_entry2 cpuid_ent[100]; @@ -1299,6 +1311,9 @@ int kvm_arch_qemu_init_env(CPUState *cenv) kvm_trim_features(&cenv->cpuid_ext3_features, kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_ECX)); + struct kvm_cpuid_entry2 *vmx_ent = NULL; + int is_intel = 0; + copy = *cenv; copy.regs[R_EAX] = 0; @@ -1322,8 +1337,26 @@ int kvm_arch_qemu_init_env(CPUState *cenv) if (i == 0xd && copy.regs[R_EAX] == 0) break; } - } else - do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, 0, ©); + } else { + do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, 0, ©); + /* check if this is intel */ + if (cpuid_ent[cpuid_nent - 1].function == 0x00000000) + is_intel = is_vendor_intel(&cpuid_ent[cpuid_nent - 1]); + else if (cpuid_ent[cpuid_nent - 1].function == 0x00000001) + vmx_ent = &cpuid_ent[cpuid_nent - 1]; + } + } + + /* simulate vmx support for Intel only */ + if (is_intel) { + /* No entry for 0x00000001 function was found ,creating a new one */ + if (!vmx_ent && cpuid_nent < 100) { + vmx_ent = &cpuid_ent[cpuid_nent++]; + memset(vmx_ent, 0, sizeof(*vmx_ent)); + vmx_ent->function = 0x00000001; + } + if (vmx_ent) + set_bit(5, &vmx_ent->ecx); } copy.regs[R_EAX] = 0x80000000;