From patchwork Fri Feb 20 22:44:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Schopp X-Patchwork-Id: 5858721 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 39CFFBF440 for ; Fri, 20 Feb 2015 22:41:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 39CC220456 for ; Fri, 20 Feb 2015 22:41:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 45F7120454 for ; Fri, 20 Feb 2015 22:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754974AbbBTWl2 (ORCPT ); Fri, 20 Feb 2015 17:41:28 -0500 Received: from mail-bn1bon0135.outbound.protection.outlook.com ([157.56.111.135]:42432 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754613AbbBTWl1 (ORCPT ); Fri, 20 Feb 2015 17:41:27 -0500 X-Greylist: delayed 14708 seconds by postgrey-1.27 at vger.kernel.org; Fri, 20 Feb 2015 17:41:26 EST Received: from BLUPR02MB035.namprd02.prod.outlook.com (10.242.191.21) by BLUPR02MB100.namprd02.prod.outlook.com (10.242.188.26) with Microsoft SMTP Server (TLS) id 15.1.87.18; Fri, 20 Feb 2015 22:41:23 +0000 Received: from BN1PR02CA0029.namprd02.prod.outlook.com (10.141.56.29) by BLUPR02MB035.namprd02.prod.outlook.com (10.242.191.21) with Microsoft SMTP Server (TLS) id 15.1.87.18; Fri, 20 Feb 2015 22:41:21 +0000 Received: from BL2FFO11FD015.protection.gbl (2a01:111:f400:7c09::187) by BN1PR02CA0029.outlook.office365.com (2a01:111:e400:2a::29) with Microsoft SMTP Server (TLS) id 15.1.93.16 via Frontend Transport; Fri, 20 Feb 2015 22:41:20 +0000 Received: from atltwp01.amd.com (165.204.84.221) by BL2FFO11FD015.mail.protection.outlook.com (10.173.160.223) with Microsoft SMTP Server id 15.1.99.6 via Frontend Transport; Fri, 20 Feb 2015 22:41:19 +0000 X-WSS-ID: 0NK3DOU-07-755-02 X-M-MSG: Received: from satlvexedge01.amd.com (satlvexedge01.amd.com [10.177.96.28]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by atltwp01.amd.com (Axway MailGate 5.3.1) with ESMTPS id 2514C12C0019; Fri, 20 Feb 2015 16:41:18 -0600 (CST) Received: from SATLEXDAG01.amd.com (10.181.40.3) by satlvexedge01.amd.com (10.177.96.28) with Microsoft SMTP Server (TLS) id 14.3.195.1; Fri, 20 Feb 2015 16:41:23 -0600 Received: from joelvmguard2.amd.com (10.180.168.240) by SATLEXDAG01.amd.com (10.181.40.3) with Microsoft SMTP Server (TLS) id 14.3.195.1; Fri, 20 Feb 2015 17:41:17 -0500 Subject: [PATCH] x86: svm: don't intercept CR0 TS or MP bit write From: Joel Schopp To: Gleb Natapov , Paolo Bonzini , CC: Joerg Roedel , Borislav Petkov , , David Kaplan Date: Fri, 20 Feb 2015 16:44:45 -0600 Message-ID: <20150220224445.2875.66846.stgit@joelvmguard2.amd.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-EOPAttributedMessage: 0 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Authentication-Results: spf=none (sender IP is 165.204.84.221) smtp.mailfrom=Joel.Schopp@amd.com; 8bytes.org; dkim=none (message not signed) header.d=none; X-Forefront-Antispam-Report: CIP:165.204.84.221; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(428002)(189002)(199003)(64706001)(62966003)(105586002)(77156002)(86362001)(575784001)(47776003)(19580405001)(19580395003)(83506001)(97736003)(229853001)(33646002)(68736005)(77096005)(92566002)(87936001)(106466001)(50986999)(54356999)(46102003)(53416004)(23676002)(103116003)(97746001)(101416001)(50466002)(71626003); DIR:OUT; SFP:1102; SCL:1; SRVR:BLUPR02MB035; H:atltwp01.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Antispam: UriScan:;UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:BLUPR02MB035; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005003); SRVR:BLUPR02MB035; X-Forefront-PRVS: 0493852DA9 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:BLUPR02MB035; X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2015 22:41:19.9283 (UTC) X-MS-Exchange-CrossTenant-Id: fde4dada-be84-483f-92cc-e026cbee8e96 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fde4dada-be84-483f-92cc-e026cbee8e96; Ip=[165.204.84.221] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR02MB035 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:BLUPR02MB100; X-OriginatorOrg: amd4.onmicrosoft.com Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: David Kaplan Reduce the number of exits by avoiding exiting when the guest writes TS or MP bits of CR0. INTERCEPT_CR0_WRITE intercepts all writes to CR0 including TS and MP bits. It intercepts these even if INTERCEPT_SELECTIVE_CR0 is set. What we should be doing is setting INTERCEPT_SELECTIVE_CR0 and not setting INTERCEPT_CR0_WRITE. Signed-off-by: David Kaplan [added remove of clr_cr_intercept in init_vmcb, fixed check in handle_exit, added emulation on interception back in, forward ported, tested] Signed-off-by: Joel Schopp --- arch/x86/kvm/svm.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index d319e0c..55822e5 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -1093,7 +1093,6 @@ static void init_vmcb(struct vcpu_svm *svm) set_cr_intercept(svm, INTERCEPT_CR0_READ); set_cr_intercept(svm, INTERCEPT_CR3_READ); set_cr_intercept(svm, INTERCEPT_CR4_READ); - set_cr_intercept(svm, INTERCEPT_CR0_WRITE); set_cr_intercept(svm, INTERCEPT_CR3_WRITE); set_cr_intercept(svm, INTERCEPT_CR4_WRITE); set_cr_intercept(svm, INTERCEPT_CR8_WRITE); @@ -1539,10 +1538,8 @@ static void update_cr0_intercept(struct vcpu_svm *svm) if (gcr0 == *hcr0 && svm->vcpu.fpu_active) { clr_cr_intercept(svm, INTERCEPT_CR0_READ); - clr_cr_intercept(svm, INTERCEPT_CR0_WRITE); } else { set_cr_intercept(svm, INTERCEPT_CR0_READ); - set_cr_intercept(svm, INTERCEPT_CR0_WRITE); } } @@ -2940,7 +2937,11 @@ static int cr_interception(struct vcpu_svm *svm) return emulate_on_interception(svm); reg = svm->vmcb->control.exit_info_1 & SVM_EXITINFO_REG_MASK; - cr = svm->vmcb->control.exit_code - SVM_EXIT_READ_CR0; + + if (svm->vmcb->control.exit_code == SVM_EXIT_CR0_SEL_WRITE) + cr = 16; + else + cr = svm->vmcb->control.exit_code - SVM_EXIT_READ_CR0; err = 0; if (cr >= 16) { /* mov to cr */ @@ -3325,7 +3326,7 @@ static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = { [SVM_EXIT_READ_CR3] = cr_interception, [SVM_EXIT_READ_CR4] = cr_interception, [SVM_EXIT_READ_CR8] = cr_interception, - [SVM_EXIT_CR0_SEL_WRITE] = emulate_on_interception, + [SVM_EXIT_CR0_SEL_WRITE] = cr_interception, [SVM_EXIT_WRITE_CR0] = cr_interception, [SVM_EXIT_WRITE_CR3] = cr_interception, [SVM_EXIT_WRITE_CR4] = cr_interception, @@ -3502,7 +3503,7 @@ static int handle_exit(struct kvm_vcpu *vcpu) struct kvm_run *kvm_run = vcpu->run; u32 exit_code = svm->vmcb->control.exit_code; - if (!is_cr_intercept(svm, INTERCEPT_CR0_WRITE)) + if (!is_cr_intercept(svm, INTERCEPT_SELECTIVE_CR0)) vcpu->arch.cr0 = svm->vmcb->save.cr0; if (npt_enabled) vcpu->arch.cr3 = svm->vmcb->save.cr3;