From patchwork Fri Sep 10 15:34:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 169662 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 o8AFdcOJ003840 for ; Fri, 10 Sep 2010 15:39:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755021Ab0IJPin (ORCPT ); Fri, 10 Sep 2010 11:38:43 -0400 Received: from tx2ehsobe002.messaging.microsoft.com ([65.55.88.12]:58806 "EHLO TX2EHSOBE003.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754970Ab0IJPil (ORCPT ); Fri, 10 Sep 2010 11:38:41 -0400 Received: from mail162-tx2-R.bigfish.com (10.9.14.238) by TX2EHSOBE003.bigfish.com (10.9.40.23) with Microsoft SMTP Server id 8.1.340.0; Fri, 10 Sep 2010 15:38:40 +0000 Received: from mail162-tx2 (localhost.localdomain [127.0.0.1]) by mail162-tx2-R.bigfish.com (Postfix) with ESMTP id 7E9C726067E; Fri, 10 Sep 2010 15:38:40 +0000 (UTC) X-SpamScore: 1 X-BigFish: VS1(zzzz1202hzz8275bhz32i87h2a8h43h61h) X-Spam-TCS-SCL: 0:0 X-FB-DOMAIN-IP-MATCH: fail Received: from mail162-tx2 (localhost.localdomain [127.0.0.1]) by mail162-tx2 (MessageSwitch) id 1284133119965154_24918; Fri, 10 Sep 2010 15:38:39 +0000 (UTC) Received: from TX2EHSMHS044.bigfish.com (unknown [10.9.14.238]) by mail162-tx2.bigfish.com (Postfix) with ESMTP id D7FAA160056; Fri, 10 Sep 2010 15:38:39 +0000 (UTC) Received: from ausb3extmailp01.amd.com (163.181.251.8) by TX2EHSMHS044.bigfish.com (10.9.99.144) with Microsoft SMTP Server (TLS) id 14.0.482.44; Fri, 10 Sep 2010 15:38:28 +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 o8AFZdiI015851; Fri, 10 Sep 2010 10:37:05 -0500 X-WSS-ID: 0L8JF8L-02-JXR-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 289CBC8B55; Fri, 10 Sep 2010 10:33:57 -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 6313B49C258; Fri, 10 Sep 2010 16:33:59 +0100 (BST) Received: by lemmy.osrc.amd.com (Postfix, from userid 1000) id 96BFAA00C1; Fri, 10 Sep 2010 17:34:18 +0200 (CEST) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: , Joerg Roedel Subject: [PATCH 4/7] svm: Add test for US bit check in emulated NPT Date: Fri, 10 Sep 2010 17:34:07 +0200 Message-ID: <1284132850-19302-5-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:40 +0000 (UTC) diff --git a/x86/svm.c b/x86/svm.c index 0fa9fec..a0f465f 100644 --- a/x86/svm.c +++ b/x86/svm.c @@ -11,6 +11,7 @@ u64 *pml4e; u64 *pdpe; u64 *pde[4]; u64 *pte[2048]; +u64 *scratch_page; static bool npt_supported(void) { @@ -27,6 +28,8 @@ static void setup_svm(void) wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_SVME); wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_NX); + scratch_page = alloc_page(); + if (!npt_supported()) return; @@ -485,6 +488,33 @@ static bool npt_nx_check(struct test *test) && (test->vmcb->control.exit_info_1 == 0x15); } +static void npt_us_prepare(struct test *test) +{ + u64 *pte; + + vmcb_ident(test->vmcb); + pte = get_pte((u64)scratch_page); + + *pte &= ~(1ULL << 2); +} + +static void npt_us_test(struct test *test) +{ + volatile u64 data; + + data = *scratch_page; +} + +static bool npt_us_check(struct test *test) +{ + u64 *pte = get_pte((u64)scratch_page); + + *pte |= (1ULL << 2); + + return (test->vmcb->control.exit_code == SVM_EXIT_NPF) + && (test->vmcb->control.exit_info_1 == 0x05); +} + static struct test tests[] = { { "null", default_supported, default_prepare, null_test, default_finished, null_check }, @@ -508,7 +538,9 @@ static struct test tests[] = { { "sel_cr0", default_supported, sel_cr0_prepare, sel_cr0_test, sel_cr0_finished, sel_cr0_check }, { "npt_nx", npt_supported, npt_nx_prepare, null_test, - default_finished, npt_nx_check } + default_finished, npt_nx_check }, + { "npt_us", npt_supported, npt_us_prepare, npt_us_test, + default_finished, npt_us_check }, }; int main(int ac, char **av)