From patchwork Mon Aug 22 23:24:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9294707 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 09D59608A7 for ; Mon, 22 Aug 2016 23:40:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9F6D28B1C for ; Mon, 22 Aug 2016 23:40:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD18C28B0B; Mon, 22 Aug 2016 23:40:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2264A28B0B for ; Mon, 22 Aug 2016 23:40:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756880AbcHVXja (ORCPT ); Mon, 22 Aug 2016 19:39:30 -0400 Received: from mail-dm3nam03on0059.outbound.protection.outlook.com ([104.47.41.59]:2944 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756869AbcHVXjX (ORCPT ); Mon, 22 Aug 2016 19:39:23 -0400 X-Greylist: delayed 814 seconds by postgrey-1.27 at vger.kernel.org; Mon, 22 Aug 2016 19:39:22 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=r3gN4bLoEvXwZB47ID6JtbSfrmLRHjgosp0FC712CtM=; b=TjA/eamC1mxF8wqMDOHvvZTYZ4KxtdiSTvSNsNZxZQI7VAxCT7CSZ09IwkNmAyNM/Fq+aF+FQsEh98iFLwXn1/hVjOOgoyALk7vhmQvtHyRpJxfQPkiYcM/G7UQ4Wp5w3W6rlHDKFbSoiBzAnJcOl3f4Rsd8AEpaP7676sudldo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by SN1PR12MB0670.namprd12.prod.outlook.com (10.163.208.28) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.549.15; Mon, 22 Aug 2016 23:24:11 +0000 Subject: [RFC PATCH v1 03/28] kvm: svm: Use the hardware provided GPA instead of page walk From: Brijesh Singh To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Date: Mon, 22 Aug 2016 19:24:07 -0400 Message-ID: <147190824754.9523.13923968456167130181.stgit@brijesh-build-machine> In-Reply-To: <147190820782.9523.4967724730957229273.stgit@brijesh-build-machine> References: <147190820782.9523.4967724730957229273.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CY1PR20CA0085.namprd20.prod.outlook.com (10.164.213.139) To SN1PR12MB0670.namprd12.prod.outlook.com (10.163.208.28) X-MS-Office365-Filtering-Correlation-Id: 38510a67-1560-4c59-6d31-08d3cae36da7 X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0670; 2:Uph5CLrpPqjaKsmt4XLNoFqfYkbRJT9Z4CFPi8fvASxQk9wLSqiYg8a25NoKCFnGQ7mXA7YB38VFEjPEnyPOeiC1qISHoqkGXFqqOSIi5g344ZEA/DYx9mGsBnloDMk3FwdrItagm9vCk76xAVZz3zotV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Bdtn4rnS9yeJXzi9SZu9rk2WrnHgg/WHZqGhyLU1apyYrkT+rHTqrouhf1PynvgdIc1Vt4WEro5kaYbYnl6EDni/QsZyPmSln5FRUgsbxQAuQ6IL/61l4zaj/MCfPeuXU9J1GfnTYX+YrdzR47fk+xUbKALCswLZv0F7P61M9IFNKAtVbLmdpngapniaXpr82SviK39e86piqKhiyusbOlC+wE9WHLgcF+ZVb6JsxSO2bP/vQ4XGyKwoPQI0vZBgBJLHFSZAlwgN7bG6tdOG79ttoSBSk+BEdidEeFuv9PYbBQiiwWhsRADZ2A7+iN1Y2m1GK5XxeUo/9zRKYtiuehM/Kf8ouptoprs/IvOBJqflyqfswdxkIq X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:SN1PR12MB0670; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0670; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0670; 4:OcobekDVUk5jwOBS4rDOdo9jSbnntEv9VyJmPqYT8pTFzxR+Weu0L9+H0IlWsHBxaWjKGwSSAnLKqUu13gX9EgaKYB3/g2KhGbXmLjyHeOJVXeUUGVr52E3etEP6rqb74AJEKdK6G7IyWmJpi9xxrob3xz9Hefx82IeFtKp42PWnxN3MN9ftboVELeU6uaoDnftZu97mU0I6om3Gjc6EnM3vPaLnPLjuAYBwIxGVGHP3/qlUKfRAW67BebeBo65caqMkAQ6oSfcqKLiUOcrWpePFaBuvGtS8OC3ACeaMq3Cnb8jmvFI5bIV7mH/yHTt1bb9Ts28OsJKNuNZjBDWlhiidecg64rd5Y2HnmUi3uOaf9eI+WP8zw1AC017dPs0h2EYVLXr+j3DA6gd6L6CHyJV30wTR2jMn8llCbXbjrKnrxwU6bPcIQnMLd/hFGA6U X-Forefront-PRVS: 00429279BA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(189002)(199003)(92566002)(83506001)(50466002)(4001350100001)(19580405001)(97736004)(19580395003)(107886002)(189998001)(5001770100001)(305945005)(7846002)(7736002)(101416001)(66066001)(33646002)(2201001)(50986999)(23676002)(86362001)(229853001)(47776003)(106356001)(7416002)(54356999)(7406005)(76176999)(5660300001)(9686002)(81156014)(586003)(81166006)(8676002)(230700001)(2906002)(3846002)(42186005)(2950100001)(68736007)(6116002)(77096005)(33716001)(105586002)(103116003)(921003)(217873001)(1121003)(83996005)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0670; H:[127.0.1.1]; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtTTjFQUjEyTUIwNjcwOzIzOnBqWjNwLzM4SG5maTlHa0dnZmw5VThXWTky?= =?utf-8?B?OE53V3ZCYlIvKzB5OFVCUCtwbEE4OSs4ck9UZm9wYzNDekgrb2lZYy8xZklN?= =?utf-8?B?UXJ2VkhrYVNWYU1FblhoZFNsRnlHQ21kdzV2MElYZWIxSktVd2pLOEF0d1lF?= =?utf-8?B?NytuZkM0MzhQU0RVQmxPSXI5Vm9hZ05pK1gzS2R2RVZwSmFYUXNFZW9hdlNl?= =?utf-8?B?aGtJNVFOOHJISVIzaGx6WStIOWVBeTRtdWViUTR5RUVvQTNvQ252a1MyT2Iy?= =?utf-8?B?cENabXBrUkxINVBYb3J6K09oWm0xa0lrOHVoY2dyenhTSjhpLy9PR3A1cm0z?= =?utf-8?B?Z2NweVRXcXdVcmY0bTQyMTRZclJRcEhWaGIvS3hvTmU0U1BRN0dpa3lkMXJt?= =?utf-8?B?UmlZVWhSL01QdmhzWnp2bnlDVVZtWkJOYzB0RWlIL0RXdjFCUU45ZWxiS0Ir?= =?utf-8?B?Z1BCZWI4RWtRZ1l6SjV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iYO8ByOQx+y41WljSVjitWk2MxI1XQqyeDpo/DDF2uYmeR2WhzrkrBRdaaHZNsS0+E=; 7:6sCG25aLBrn5hS8ShCnAmCn1bSWNjustg5445K/540ZxHvf092jc5T/MO0u6Ml3EDTDTfSUm53cnamOEPInDcvSmjWzgO2GHrlH2mm7DqpWSCwqnPRzsO9qt7KtL93GAjbdlUb8QXRDQTw9HTVOOyEA6hmg0lJLGS41BlZKXJhn/CE+5n1OceE0ZtMgL+IwWzcbjUGbunNVKsAYFruFtgZql/leEjxMtJisOoRyGPNakWL2zs9NsYYAmfzqnmmf3 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0670; 20:b2GBLprySnvVvFvi8YyVuJQuzxhZHbao6uBcPykHAei4BbYdAJYLHdFrb/USI/LBez5Yiw2NUGmTNMGLz4LaAn9M6IXDa0U1/e0Yo912530qzWWm6uMscWE1y+SJ8iPxITBSozVAO7CZvsgWSsmdijaw7tEMWD8LoQh0BSlIf7WqkNjwkEyWvxGWbxz24lghQGbr0O3x8eaUdb5FKW0YbISrtpxOzYtjVrQEL+VJBHCBS486rRHKZctqN5oNvY42 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2016 23:24:11.1358 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0670 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tom Lendacky When a guest causes a NPF which requires emulation, KVM sometimes walks the guest page tables to translate the GVA to a GPA. This is unnecessary most of the time on AMD hardware since the hardware provides the GPA in EXITINFO2. The only exception cases involve string operations involving rep or operations that use two memory locations. With rep, the GPA will only be the value of the initial NPF and with dual memory locations we won't know which memory address was translated into EXITINFO2. Signed-off-by: Tom Lendacky Reviewed-by: Borislav Petkov --- arch/x86/include/asm/kvm_emulate.h | 3 +++ arch/x86/include/asm/kvm_host.h | 3 +++ arch/x86/kvm/svm.c | 2 ++ arch/x86/kvm/x86.c | 17 ++++++++++++++++- 4 files changed, 24 insertions(+), 1 deletion(-) -- 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/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h index e9cd7be..2d1ac09 100644 --- a/arch/x86/include/asm/kvm_emulate.h +++ b/arch/x86/include/asm/kvm_emulate.h @@ -344,6 +344,9 @@ struct x86_emulate_ctxt { struct read_cache mem_read; }; +/* String operation identifier (matches the definition in emulate.c) */ +#define CTXT_STRING_OP (1 << 13) + /* Repeat String Operation Prefix */ #define REPE_PREFIX 0xf3 #define REPNE_PREFIX 0xf2 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index c38f878..b1dd673 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -667,6 +667,9 @@ struct kvm_vcpu_arch { int pending_ioapic_eoi; int pending_external_vector; + + /* GPA available (AMD only) */ + bool gpa_available; }; struct kvm_lpage_info { diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index fd5a9a8..9b2de7c 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -4055,6 +4055,8 @@ static int handle_exit(struct kvm_vcpu *vcpu) trace_kvm_exit(exit_code, vcpu, KVM_ISA_SVM); + vcpu->arch.gpa_available = (exit_code == SVM_EXIT_NPF); + if (!is_cr_intercept(svm, INTERCEPT_CR0_WRITE)) vcpu->arch.cr0 = svm->vmcb->save.cr0; if (npt_enabled) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 78295b0..d6f2f4b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4382,7 +4382,19 @@ static int vcpu_mmio_gva_to_gpa(struct kvm_vcpu *vcpu, unsigned long gva, return 1; } - *gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, exception); + /* + * If the exit was due to a NPF we may already have a GPA. + * If the GPA is present, use it to avoid the GVA to GPA table + * walk. Note, this cannot be used on string operations since + * string operation using rep will only have the initial GPA + * from when the NPF occurred. + */ + if (vcpu->arch.gpa_available && + !(vcpu->arch.emulate_ctxt.d & CTXT_STRING_OP)) + *gpa = exception->address; + else + *gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, + exception); if (*gpa == UNMAPPED_GVA) return -1; @@ -5504,6 +5516,9 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, } restart: + /* Save the faulting GPA (cr2) in the address field */ + ctxt->exception.address = cr2; + r = x86_emulate_insn(ctxt); if (r == EMULATION_INTERCEPTED)