From patchwork Tue Nov 29 18:01:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9452891 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 00E1C60756 for ; Tue, 29 Nov 2016 18:02:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDE62283E9 for ; Tue, 29 Nov 2016 18:02:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2849283F1; Tue, 29 Nov 2016 18:02:18 +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=ham 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 26A46283E9 for ; Tue, 29 Nov 2016 18:02:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933391AbcK2SBw (ORCPT ); Tue, 29 Nov 2016 13:01:52 -0500 Received: from mail-by2nam03on0078.outbound.protection.outlook.com ([104.47.42.78]:51200 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933318AbcK2SBo (ORCPT ); Tue, 29 Nov 2016 13:01:44 -0500 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=MRfH+g+GZFSFn+1gH3aVV60mNpPIIXAwu5JUfCT6UaA=; b=CXtdMuiv/YKAd+ffo4pQ6MHYnWnwjtiz1JzyAa8n1Lokyf9iOe+xSS0F2MP3i5RwagnIrQjufIZVL9x99RNaOCZDqisO4YC6dJqwiwfn+70RgsC0KHbDW1QcjuH//40xB9kdZC3HKkwA6N+Cd3PGP57ORbDS7PKOadpVpWrh4Cg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by SN1PR12MB0671.namprd12.prod.outlook.com (10.163.208.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.747.13; Tue, 29 Nov 2016 18:01:35 +0000 Subject: [PATCH v3] kvm: svm: Use the hardware provided GPA instead of page walk From: Brijesh Singh To: CC: , , , , , , , , , Date: Tue, 29 Nov 2016 13:01:31 -0500 Message-ID: <148044249174.29544.4194514184644021170.stgit@brijesh-build-machine> In-Reply-To: <148044248179.29544.16863706762469812354.stgit@brijesh-build-machine> References: <148044248179.29544.16863706762469812354.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR09CA0040.namprd09.prod.outlook.com (10.172.184.154) To SN1PR12MB0671.namprd12.prod.outlook.com (10.163.208.29) X-MS-Office365-Filtering-Correlation-Id: 9a710588-3f64-40d4-cb4e-08d41881c25e X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:SN1PR12MB0671; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0671; 3:Ik+l8AtfKjTq38pCDF3OHD9NDA0DflA2T9KPQLEgV/FIYBvpYbAQmVymo2fyYB6UJMK7pmbPY0DV+ibvqsUfyNEPbfEwOPAGxts2n0E7ufjqyjfH8u1X9HaWa8xyt6pds0piN4/8gUpzxnD4+tRXOkw5S7cQg+OOpcIMBV94WqBIsK2j9/wpqXwf/WSV562tdB2CMwvo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NJst/2HeaSDNn3E2E7FYMUSSQBvrNPPxH2YT0Ez5A4esmeOl8eIWn8CxBrrakMGuD2nC5sYFb9LLx/9KTAfbHv0q5adGrUHL1wEbjVllzcuTpKYtBI3pUZjFj7DsxXA==; 20:1sLyDtCBxRMaWM35V/mEOyLlkXSc/QE4VzkZso6nkSTZTIBl1M+ivOfWS97ce1NDbxUlAzD+F7IhTVqRjDOpqIxD7yMzfSX8bPGjVnXyWuYB/X5/SCmmVNlaMISrBD48oxcaYjELcVlMCbFW+eQ5AOgIaU+bGxQ3EszXWLLUWSVEakATNLvZWoKE5MAdiDSHFjp4OC/PwqJFRjqxCPmM10s8YGi/UYIMbWStU0oxezmsQb080ebsAsYv9+/v1FPDuXUQvqmkS5kw4+7cIfG0kZumid1v3o3zHnKmt14aQufj7MPQ3YxmQynzwUel+oxktWfrdNDDN3LEitIuHJ6B7QDTZo1weKNa863pGxKjoOON+RrzI2a4GpOyJLYpd6caKa+qvEfPQvHGKPirtsfjah3zfxIyic9o91WkACDsSE1w8qW+QFtwuZB7Kg2SczmYpUvy2gWUcEcS4MkU2O34ZMyMvgAMAymF96HpRqwPM6aZiEwGmXpQcsDkCdzIU8As X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6060326)(6040361)(6045199)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6041248)(6061324)(20161123564025)(20161123562025)(20161123560025)(20161123555025)(6072148); SRVR:SN1PR12MB0671; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0671; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0671; 4:dkVekEXTA6usb4Jp0f2cvVqRosTlWRM1u2dly/QWPGVzNxCuyiyg19waDtTzVgA71a0ytCNn5mX7xMAN/rufRNZk53XEcK5uMYQFDJrjGpQV6SdFyQSgTR/UO8eCHaY8nMLi4tfiYuiW44ud1jxB0s8f4stDgWhVpAvnFnEun6hDTG6bqUTwApUenVJGPpiHwaI1xxp4DYAFr6qzuvpqL8R+7IXSGdn9EiT/Tn9KwnqPth/2W3SKuPk4K6hF09uVAVFKhQAWwTY9h95FJQfNq+xQ7F1do+bC70/YEIro7/4gEE+FrLP6o7xTt/Yt5JDi58vSoUKiqrovy3S5qdx/XsOn4u7fvtaWsxf8nv3k0ogokoel2LyUnr4aNV03ktSV0kQnbtqTSndNUkKcHskFRVvoQ1WmU52xPetnFUwlojrZ8/sNljqDmJTL6+NDEPuvUx5MDJfa51dmdTFBLFs8nmfn5GnEg7y0mOQCaM8/VLWAA3lErSjcxN4okgZQaElEgYsh5mTg26z/VPazO/xnNABQ5bX9qamre9aGbOs1KcfvNjGeZIuthuqWIDi7tKfmm+q5f4DZc9NV3EkGVpFCm08g5wN10Aain8U0HJkEoJXzUt7hEZVlEYWN/mYKoVfKw+K1ZhJPEwz18NNOEQUt/NIiSHk9+kd7bvR4V/YRCllOlDWB5nMy78kfvueQR3JV X-Forefront-PRVS: 01415BB535 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(979002)(6009001)(6049001)(7916002)(199003)(189002)(4326007)(101416001)(54356999)(3846002)(97736004)(6116002)(50986999)(76176999)(92566002)(4001350100001)(7736002)(733004)(68736007)(103116003)(9686002)(39400400001)(39410400001)(39380400001)(39450400002)(38730400001)(105586002)(77096006)(6486002)(106356001)(7846002)(305945005)(2906002)(42186005)(189998001)(230700001)(23676002)(2351001)(50466002)(6666003)(47776003)(81166006)(66066001)(5660300001)(8676002)(33716001)(83506001)(33646002)(7416002)(110136003)(6916009)(2950100002)(81156014)(86362001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0671; H:[127.0.1.1]; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?M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Gs+zQyxFIK9OZ6Lm0HSDjxwBVxa2FTiIV1+GZZBHO/i0QcgJ+mBJhbrQm+JfIaDtQwAp4IlnASkry/HIYNTBRxnAdC8ADOPKZwwzsndFu7G36pSy5JxBXJXVHnyRdJ+WPin2Kf3w7g24p3K70A2bs366ujsE9XDJWVhaSe+MTgAgE9liAXtX0RRT5E/tkn8Pa9PJbPKNas8b5BMIpDU49Vcq7E9lL/PRdJpmys3Xod5pWqaKmDWAToxR/9l5L9lpbKKvEIjRYsrfN9YkTQ8bQkaDBmeXanHMAAE7iQVkEbDpHSuoYYqi57Gz4BjIVM+XWlcZydYaL0WJmHuaawB6mnPT7BlCc4DVrMLK+Zn7vQusVL6fuI6yE/6oqf1jNrYkNR05j9vgqMJF/e48/S/k1zgk+DRijS9uhhqlLoVqTUAjgvzgrwW/K7ucjVUtMva6js1kEH29WRKfpg==; 20:7X0lorLS6svDVpU3PswM2YNHO9n3dtWt19aihuOOgBffDEKikPtxo3wO7o/hZWogA03smEDYUyLp7vBGNb62HxVyKlFGU4sxUYKXdPX6NUZPZc+h+M36WQX9MG4vgNrTU5+ibxXrr6Yt80++ZvEsCvDmXVjthLwICwJX80CTkirDLUgyiSDkK1nWwN5heW4IqJD/YnQ0LuU9B52Nj4NjAChvGCv/l/2y8rUGYKDiGRlajrztvZg7vnDIO+4CAKl/ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2016 18:01:35.1097 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0671 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 Signed-off-by: Brijesh Singh Reviewed-by: Paolo Bonzini --- arch/x86/include/asm/kvm_emulate.h | 1 + arch/x86/include/asm/kvm_host.h | 3 ++ arch/x86/kvm/emulate.c | 8 +++++++ arch/x86/kvm/svm.c | 2 ++ arch/x86/kvm/x86.c | 44 ++++++++++++++++++++++++++++-------- 5 files changed, 48 insertions(+), 10 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/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h index e9cd7be..777eea2 100644 --- a/arch/x86/include/asm/kvm_emulate.h +++ b/arch/x86/include/asm/kvm_emulate.h @@ -441,5 +441,6 @@ int emulator_task_switch(struct x86_emulate_ctxt *ctxt, int emulate_int_real(struct x86_emulate_ctxt *ctxt, int irq); void emulator_invalidate_register_cache(struct x86_emulate_ctxt *ctxt); void emulator_writeback_register_cache(struct x86_emulate_ctxt *ctxt); +bool emulator_is_string_op(struct x86_emulate_ctxt *ctxt); #endif /* _ASM_X86_KVM_X86_EMULATE_H */ diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 77cb3f9..fd5b1c8 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -668,6 +668,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/emulate.c b/arch/x86/kvm/emulate.c index a3ce9d2..0ea543e 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -5483,3 +5483,11 @@ void emulator_writeback_register_cache(struct x86_emulate_ctxt *ctxt) { writeback_registers(ctxt); } + +bool emulator_is_string_op(struct x86_emulate_ctxt *ctxt) +{ + if (ctxt->d & String) + return true; + + return false; +} diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 5e64e656..e9b3555 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -4188,6 +4188,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 c30f62dc..507c75c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4420,6 +4420,21 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt, } EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system); +static int vcpu_is_mmio_gpa(struct kvm_vcpu *vcpu, unsigned long gva, + gpa_t gpa, bool write) +{ + /* For APIC access vmexit */ + if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE) + return 1; + + if (vcpu_match_mmio_gpa(vcpu, gpa)) { + trace_vcpu_match_mmio(gva, gpa, write, true); + return 1; + } + + return 0; +} + static int vcpu_mmio_gva_to_gpa(struct kvm_vcpu *vcpu, unsigned long gva, gpa_t *gpa, struct x86_exception *exception, bool write) @@ -4446,16 +4461,7 @@ static int vcpu_mmio_gva_to_gpa(struct kvm_vcpu *vcpu, unsigned long gva, if (*gpa == UNMAPPED_GVA) return -1; - /* For APIC access vmexit */ - if ((*gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE) - return 1; - - if (vcpu_match_mmio_gpa(vcpu, *gpa)) { - trace_vcpu_match_mmio(gva, *gpa, write, true); - return 1; - } - - return 0; + return vcpu_is_mmio_gpa(vcpu, gva, *gpa, write); } int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa, @@ -4552,6 +4558,21 @@ static int emulator_read_write_onepage(unsigned long addr, void *val, int handled, ret; bool write = ops->write; struct kvm_mmio_fragment *frag; + struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; + + /* + * 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 the NPF + * occurred. + */ + if (vcpu->arch.gpa_available && + !emulator_is_string_op(ctxt) && + vcpu_is_mmio_gpa(vcpu, addr, exception->address, write)) { + gpa = exception->address; + goto mmio; + } ret = vcpu_mmio_gva_to_gpa(vcpu, addr, &gpa, exception, write); @@ -5563,6 +5584,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)