From patchwork Fri Sep 10 15:34:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 169692 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 o8AFdcOO003840 for ; Fri, 10 Sep 2010 15:39:41 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755093Ab0IJPjD (ORCPT ); Fri, 10 Sep 2010 11:39:03 -0400 Received: from tx2ehsobe002.messaging.microsoft.com ([65.55.88.12]:1416 "EHLO TX2EHSOBE003.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754648Ab0IJPi7 (ORCPT ); Fri, 10 Sep 2010 11:38:59 -0400 Received: from mail148-tx2-R.bigfish.com (10.9.14.253) by TX2EHSOBE003.bigfish.com (10.9.40.23) with Microsoft SMTP Server id 8.1.340.0; Fri, 10 Sep 2010 15:38:59 +0000 Received: from mail148-tx2 (localhost.localdomain [127.0.0.1]) by mail148-tx2-R.bigfish.com (Postfix) with ESMTP id D67E98180FD; Fri, 10 Sep 2010 15:38:58 +0000 (UTC) X-SpamScore: 1 X-BigFish: VS1(zzzz1202hzz8275bhz32i2a8h87h43h61h) X-Spam-TCS-SCL: 0:0 X-FB-SS: 0, X-FB-DOMAIN-IP-MATCH: fail Received: from mail148-tx2 (localhost.localdomain [127.0.0.1]) by mail148-tx2 (MessageSwitch) id 1284133138570256_12399; Fri, 10 Sep 2010 15:38:58 +0000 (UTC) Received: from TX2EHSMHS034.bigfish.com (unknown [10.9.14.252]) by mail148-tx2.bigfish.com (Postfix) with ESMTP id 7F18F11E804F; Fri, 10 Sep 2010 15:38:58 +0000 (UTC) Received: from ausb3extmailp01.amd.com (163.181.251.8) by TX2EHSMHS034.bigfish.com (10.9.99.134) with Microsoft SMTP Server (TLS) id 14.0.482.44; Fri, 10 Sep 2010 15:38:36 +0000 Received: from ausb3twp02.amd.com ([163.181.250.38]) by ausb3extmailp01.amd.com (Switch-3.2.7/Switch-3.2.7) with SMTP id o8AFaiLY016181; Fri, 10 Sep 2010 10:37:23 -0500 X-WSS-ID: 0L8JF8K-02-JXK-02 X-M-MSG: Received: from sausexhtp01.amd.com (sausexhtp01.amd.com [163.181.3.165]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by ausb3twp02.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 263A1C8B40; Fri, 10 Sep 2010 10:33:56 -0500 (CDT) Received: from storexhtp02.amd.com (172.24.4.4) by sausexhtp01.amd.com (163.181.3.165) with Microsoft SMTP Server (TLS) id 8.3.83.0; Fri, 10 Sep 2010 10:34:01 -0500 Received: from gwo.osrc.amd.com (165.204.16.204) by storexhtp02.amd.com (172.24.4.4) with Microsoft SMTP Server id 8.3.83.0; Fri, 10 Sep 2010 11:33:59 -0400 Received: from lemmy.osrc.amd.com (lemmy.osrc.amd.com [165.204.15.93]) by gwo.osrc.amd.com (Postfix) with ESMTP id 3C6B749C211; Fri, 10 Sep 2010 16:33:59 +0100 (BST) Received: by lemmy.osrc.amd.com (Postfix, from userid 1000) id 5C8A7A05CF; Fri, 10 Sep 2010 17:34:18 +0200 (CEST) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: , Joerg Roedel Subject: [PATCH 2/7] svm: Run tests with NPT enabled if available Date: Fri, 10 Sep 2010 17:34:05 +0200 Message-ID: <1284132850-19302-3-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1284132850-19302-1-git-send-email-joerg.roedel@amd.com> References: <1284132850-19302-1-git-send-email-joerg.roedel@amd.com> MIME-Version: 1.0 X-Reverse-DNS: unknown 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]); Fri, 10 Sep 2010 15:39:41 +0000 (UTC) diff --git a/x86/svm.c b/x86/svm.c index e65360e..0e15819 100644 --- a/x86/svm.c +++ b/x86/svm.c @@ -6,12 +6,66 @@ #include "smp.h" #include "types.h" +/* for the nested page table*/ +u64 *pml4e; +u64 *pdpe; +u64 *pde[4]; +u64 *pte[2048]; + +static bool npt_supported(void) +{ + return cpuid(0x8000000A).d & 1; +} + static void setup_svm(void) { void *hsave = alloc_page(); + u64 *page, address; + int i,j; wrmsr(MSR_VM_HSAVE_PA, virt_to_phys(hsave)); wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_SVME); + + if (!npt_supported()) + return; + + printf("NPT detected - running all tests with NPT enabled\n"); + + /* + * Nested paging supported - Build a nested page table + * Build the page-table bottom-up and map everything with 2M pages + */ + + address = 0; + + /* PTE level */ + for (i = 0; i < 2048; ++i) { + page = alloc_page(); + + for (j = 0; j < 512; ++j, address += 4096) + page[j] = address | 0x067ULL; + + pte[i] = page; + } + + /* PDE level */ + for (i = 0; i < 4; ++i) { + page = alloc_page(); + + for (j = 0; j < 512; ++j) + page[j] = (u64)pte[(i * 514) + j] | 0x027ULL; + + pde[i] = page; + } + + /* PDPe level */ + pdpe = alloc_page(); + for (i = 0; i < 4; ++i) + pdpe[i] = ((u64)(pde[i])) | 0x27; + + /* PML4e level */ + pml4e = alloc_page(); + pml4e[0] = ((u64)pdpe) | 0x27; } static void vmcb_set_seg(struct vmcb_seg *seg, u16 selector, @@ -56,6 +110,11 @@ static void vmcb_ident(struct vmcb *vmcb) save->g_pat = rdmsr(MSR_IA32_CR_PAT); save->dbgctl = rdmsr(MSR_IA32_DEBUGCTLMSR); ctrl->intercept = (1ULL << INTERCEPT_VMRUN) | (1ULL << INTERCEPT_VMMCALL); + + if (npt_supported()) { + ctrl->nested_ctl = 1; + ctrl->nested_cr3 = (u64)pml4e; + } } struct test {