From patchwork Fri Sep 10 15:34:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 169762 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 o8AFencP004485 for ; Fri, 10 Sep 2010 15:40:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754980Ab0IJPjr (ORCPT ); Fri, 10 Sep 2010 11:39:47 -0400 Received: from tx2ehsobe003.messaging.microsoft.com ([65.55.88.13]:12590 "EHLO TX2EHSOBE005.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754660Ab0IJPjq (ORCPT ); Fri, 10 Sep 2010 11:39:46 -0400 Received: from mail47-tx2-R.bigfish.com (10.9.14.250) by TX2EHSOBE005.bigfish.com (10.9.40.25) with Microsoft SMTP Server id 8.1.340.0; Fri, 10 Sep 2010 15:39:46 +0000 Received: from mail47-tx2 (localhost.localdomain [127.0.0.1]) by mail47-tx2-R.bigfish.com (Postfix) with ESMTP id 4180415D05EC; Fri, 10 Sep 2010 15:39:46 +0000 (UTC) X-SpamScore: 1 X-BigFish: VS1(zzzz1202hzz8275bhz32i87h2a8h43h) X-FB-SS: 0, X-FB-DOMAIN-IP-MATCH: fail Received: from mail47-tx2 (localhost.localdomain [127.0.0.1]) by mail47-tx2 (MessageSwitch) id 1284133138209342_28852; Fri, 10 Sep 2010 15:38:58 +0000 (UTC) Received: from TX2EHSMHS015.bigfish.com (unknown [10.9.14.248]) by mail47-tx2.bigfish.com (Postfix) with ESMTP id 2F7601A38051; Fri, 10 Sep 2010 15:38:58 +0000 (UTC) Received: from ausb3extmailp01.amd.com (163.181.251.8) by TX2EHSMHS015.bigfish.com (10.9.99.115) 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 o8AFaiIX016175; Fri, 10 Sep 2010 10:37:23 -0500 X-WSS-ID: 0L8JF8K-02-JXQ-02 X-M-MSG: Received: from sausexhtp02.amd.com (sausexhtp02.amd.com [163.181.3.152]) (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 29A38C86BB; Fri, 10 Sep 2010 10:33:55 -0500 (CDT) Received: from storexhtp01.amd.com (172.24.4.3) by sausexhtp02.amd.com (163.181.3.152) with Microsoft SMTP Server (TLS) id 8.3.83.0; Fri, 10 Sep 2010 10:34:00 -0500 Received: from gwo.osrc.amd.com (165.204.16.204) by storexhtp01.amd.com (172.24.4.3) 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 188FA49C14A; Fri, 10 Sep 2010 16:33:59 +0100 (BST) Received: by lemmy.osrc.amd.com (Postfix, from userid 1000) id 4DE8FA00C1; Fri, 10 Sep 2010 17:34:18 +0200 (CEST) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: , Joerg Roedel Subject: [PATCH 1/7] svm: Add test for selective cr0 intercept Date: Fri, 10 Sep 2010 17:34:04 +0200 Message-ID: <1284132850-19302-2-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:40:50 +0000 (UTC) diff --git a/x86/svm.c b/x86/svm.c index 2f1c900..e65360e 100644 --- a/x86/svm.c +++ b/x86/svm.c @@ -357,6 +357,40 @@ static bool check_asid_zero(struct test *test) return test->vmcb->control.exit_code == SVM_EXIT_ERR; } +static void sel_cr0_prepare(struct test *test) +{ + vmcb_ident(test->vmcb); + test->vmcb->control.intercept |= (1ULL << INTERCEPT_SELECTIVE_CR0); +} + +static bool sel_cr0_finished(struct test *test) +{ + return true; +} + +static void sel_cr0_test(struct test *test) +{ + unsigned long cr0; + + /* read cr0, clear CD, and write back */ + cr0 = read_cr0(); + cr0 |= (1UL << 30); + write_cr0(cr0); + + /* + * If we are here the test failed, not sure what to do now because we + * are not in guest-mode anymore so we can't trigger an intercept. + * Trigger a tripple-fault for now. + */ + printf("sel_cr0 test failed. Can not recover from this - exiting\n"); + exit(1); +} + +static bool sel_cr0_check(struct test *test) +{ + return test->vmcb->control.exit_code == SVM_EXIT_CR0_SEL_WRITE; +} + static struct test tests[] = { { "null", default_supported, default_prepare, null_test, default_finished, null_check }, @@ -377,7 +411,8 @@ static struct test tests[] = { mode_switch_finished, check_mode_switch }, { "asid_zero", default_supported, prepare_asid_zero, test_asid_zero, default_finished, check_asid_zero }, - + { "sel_cr0", default_supported, sel_cr0_prepare, sel_cr0_test, + sel_cr0_finished, sel_cr0_check }, }; int main(int ac, char **av)