From patchwork Tue Jun 8 18:33:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 105009 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o58IYxsY014963 for ; Tue, 8 Jun 2010 18:34:59 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752292Ab0FHSe5 (ORCPT ); Tue, 8 Jun 2010 14:34:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11596 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751961Ab0FHSe5 (ORCPT ); Tue, 8 Jun 2010 14:34:57 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o58IYupE020366 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 8 Jun 2010 14:34:56 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o58IYtSG004396; Tue, 8 Jun 2010 14:34:56 -0400 Received: from amt.cnet (vpn-11-249.rdu.redhat.com [10.11.11.249]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o58IYsQg031148; Tue, 8 Jun 2010 14:34:55 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id C065C68A8F4; Tue, 8 Jun 2010 15:34:45 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o58IXT8Z012763; Tue, 8 Jun 2010 15:33:29 -0300 Date: Tue, 8 Jun 2010 15:33:29 -0300 From: Marcelo Tosatti To: kvm Cc: Avi Kivity Subject: kvm test: vmexit: enable NX Message-ID: <20100608183329.GA12737@amt.cnet> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-08-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 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 (demeter.kernel.org [140.211.167.41]); Tue, 08 Jun 2010 18:34:59 +0000 (UTC) diff --git a/kvm/test/x86/vmexit.c b/kvm/test/x86/vmexit.c index c3a01e0..f267a19 100644 --- a/kvm/test/x86/vmexit.c +++ b/kvm/test/x86/vmexit.c @@ -45,6 +45,24 @@ static void vmcall(void) asm volatile ("vmcall" : "+a"(a), "=b"(b), "=c"(c), "=d"(d)); } +#define MSR_EFER 0xc0000080 +#define EFER_NX_MASK (1ull << 11) + +unsigned long long rdmsr(unsigned index) +{ + unsigned a, d; + + asm volatile("rdmsr" : "=a"(a), "=d"(d) : "c"(index)); + return ((unsigned long long)d << 32) | a; +} + +void wrmsr(unsigned index, unsigned long long val) +{ + unsigned a = val, d = val >> 32; + + asm volatile("wrmsr" : : "a"(a), "d"(d), "c"(index)); +} + static void mov_from_cr8(void) { unsigned long cr8; @@ -151,12 +169,20 @@ static void do_test(struct test *test) #define ARRAY_SIZE(_x) (sizeof(_x) / sizeof((_x)[0])) +static void enable_nx(void *junk) +{ + wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_NX_MASK); +} + int main(void) { int i; smp_init(); + for (i = cpu_count(); i > 0; i--) + on_cpu(i-1, enable_nx, 0); + for (i = 0; i < ARRAY_SIZE(tests); ++i) do_test(&tests[i]);