From patchwork Wed Nov 23 17:02:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9443879 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 5F68760778 for ; Wed, 23 Nov 2016 17:02:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6662B27C0C for ; Wed, 23 Nov 2016 17:02:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B16E27C7A; Wed, 23 Nov 2016 17:02:41 +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 B033927C0C for ; Wed, 23 Nov 2016 17:02:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757021AbcKWRCQ (ORCPT ); Wed, 23 Nov 2016 12:02:16 -0500 Received: from mail-sn1nam02on0061.outbound.protection.outlook.com ([104.47.36.61]:61856 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756982AbcKWRCN (ORCPT ); Wed, 23 Nov 2016 12:02:13 -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=XsHzZfnWAcSHHYM+b2tYJwlzVv/hsMoqzDCw5GFVvtk=; b=BAgIK8MDtJUWXu+ulkg6TtzEWdWd0lox6wzxTDG+xPbn4QeNjpWWfFdjj4PS9SJCmJ9fqdoQ4ddRHoRZXzQejqL/ti6+eYHpO6TOfVEmbPQfvNmpUzJn/YeVKRwThujqGwTfaoghHiBvy/jBeIEMJmIYxodBVq92fWdMUJ6NHyw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [127.0.1.1] (165.204.77.1) by BLUPR12MB0658.namprd12.prod.outlook.com (10.163.217.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.734.8; Wed, 23 Nov 2016 17:02:04 +0000 Subject: [PATCH v2 3/3] kvm: svm: Use the hardware provided GPA instead of page walk From: Brijesh Singh To: CC: , , , , , , , , , Date: Wed, 23 Nov 2016 12:02:00 -0500 Message-ID: <147992052008.27638.18095073174935903705.stgit@brijesh-build-machine> In-Reply-To: <147992048887.27638.17559991037474542240.stgit@brijesh-build-machine> References: <147992048887.27638.17559991037474542240.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR13CA0027.namprd13.prod.outlook.com (10.171.172.13) To BLUPR12MB0658.namprd12.prod.outlook.com (10.163.217.28) X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0658; 2:cSL0FIaDN/SOzoADKcnkNR5HSPQe+kYi0Ndez9J0CHPUwJxUJc8FKVjzE6b1SmUEI+yHEpihfrhCWisCi8dwTJAV2zK6930rBo4FTTUdVGzU/9vuXBX6/yy5J0j1ci8loQgBAduaqM6xyNhAvHe1009qZmnseCWIUZWo3+i3JmE=; 3:zo301S1qlTY1RzKpnchP+HrxvqIN7lagoX7IyD5av3rKRoJpWuN9E1a24vyoNd+I/k9rhbb8soDvMd1P9IVRD6kEzJLdsC5alUd2xL0aPwtkqVTipSH6lt4V/niDoW9C5IHRag97/LzxphyiLHHHuzLxJa/7aKBTW/xYK2KfgGg= X-MS-Office365-Filtering-Correlation-Id: 42c0dfae-1440-4295-1ac9-08d413c2736d X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BLUPR12MB0658; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0658; 25:YCdF9TB8Zn+1SzE2qc6YddMkxibcjjCU7FhUnELzjlqQbw3BV+yMWoqwIEDPeEGybWolTNFUMtpjDw6BsS+tinmZ2KUJuAWVIpAQgQgYWsk6VKQdY2Mgit2uBTU7+4ZxJzuD1+GRmwE6CZCh9NVrirOGGRm/K+wbYpvf2b3ljBEX6hwZNrLAzHQqMygABNVx/MFHgtpH5M2k17bpLYzE3h/mZ9cU7a8Kc4dLXEkZhx2TVMo8p0GBFnW1efzE3VON2xxLEZ5rpnN0bOaCyLKeNB5kemxgBWlTnm64cVRZFBLtAH1FBJo1syoCFuKNd0SbLgNoKtVF6l8zoY6bVV+S3jZjMJ8T4Z5UYYJe9jMZtYEi3XRj3uXIvvSEC5ah5aRqvVUJrEfmPuI+5wcAeRd84IJ3ikiMW/DjHOwdG3NMpr7ehZXuVudk3q/FLVM3br5CNjrBPtijZDDarx6KYnQbzXBUe1SDPDUOjKMgmMcvXBEtW1GZ9EohMiIu0Zh/b2r16NAZXANMtTy6qT40MCTSqDZ69fM3WatvOnjZ0JUP+7eGUlao6fWzccRM3Stxx86BuCwyJXXEVINru6QeUqCceTU5QY5hca7d/VWzN5aIbsQNk9wADpxUm1PlzqOnX1FLFnSTbNtjrAxpWbSuZb+8iedqlre6yCWGfhue6AyNu9BrCJNnEdDs5droyfyYzl4ShHbIZPH4AdjBQLGKubGTRsTKAjye7KOG++bfzQOsBx9zoT61W4A0QSSA150QhvEA X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0658; 31:4qVVXaqhfGqabxn8lgVYEuImc8h/goq0/QdzEBawa/MFjai7ymX5+Y4tMRuoTpNCOvW2l8CvjsKopGDb4egXYAMMm15Oxb/T91ddzb5PhZYFG5xSV9Kk/UwphvnVOfBCnjdTr3Utz2DEfUEtymF6KRQjcWisWZ9kg/hUWcP93WJT8VSUYvT8n9Lvi4h4HZbu/ul6tsw+5047vfwAH7BwENldokUyiiyGicNs6jKIJtfnnON+Z3vP9ZT7S9zb8GnDfBzERRXqboyDuKtB5DkG7w==; 20:t4ABXhIodiL5FTNYKulPynkl6zUeGlUnUmOThgGvCJU+6GdIFPnsfS1bQdGuew5wykZP06nKUUKte8YcPmtFLN2+bocMxvJF1p/cG6Z+XtL5OEhFJzy5Q1Nim/7X1P2RYt8GWNEfVnZq0N9J+fA4nzMQYuXQ0gdYakWOtqCBR1A2zz25je3lOjh0CcDO9vxCpTxftl7Z0HA+J8snhth2mwJqRAyNZ7OjUU9b6KiJPisxpE/na7GwrNDPedZWiDOIvRYs1siQSeiS91krjdMl247LjXPlZI8QKmnb78CpjI6bIYNlRy4n2sLiL/s26VATN9/xYZvR3/GXBPYWL/iSaBXOaNKmLM58TR94lEMyRkbZhYDbSZBpKGia5yKZ6XXfGxmwm/xfRL2Wgjdp7JoDvVKLOpZLU9NVDzC5RPEGygcrYRs8cSsjnZoqQBt7hDABwGQqjwHw4ISwi4oT/Wdm24fgzuzaKzRC0b6uYCL8YBbMgeOgV0t0otKgMgGrChuz X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040307)(6060326)(6045199)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6061324)(6041248)(6042181)(6072148); SRVR:BLUPR12MB0658; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0658; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0658; 4:qJSjxrxcyhxUcCSl13jwzG7BXyu2V+r9PNUya3N6P1dcLBZW+CL7RnuJfClw5HH93L/s5KiB/+zP0WtpEqKW+iSM7iZVSc5I7HvS2OI7+DjPjBTZoU8b32/bzpDU9R7199iH9Wyutgwvkn5zH4jL3KHJVkTFb9pgxKnB/HL1P3VOvqkU8tNmrDQit/vcZacjoAHsPR2cPkLWcaBSGf7s95+2FTHVuFv1amkg7Zry01/ZO7QR+HgdQg6K4p2isRM0vHxeDx4vn9tr9bM9xifdrJ9igvNW/ZdjruC0hXA2RL0lcqMgz2IA9u5KPXj0fxuAkcRWIBPPooFEGdcz4iYvLoIqkDVY4N+bzK3R7YS+SPwxxVVrfyBLw6htrGQvCsg/hLR3mm6eXG92Rn2iU2E98Zrf9d0SIqBwPRkmVzWD0sf+54YtA2gPFQZzKA8IKKlrXUQ2N+9H6LMjx5fV3Hl24N6Cy3+YsZRVK+58IJLz32uoUtQFPdD5luy8EpUZPuZ1Y6J8CIom0Ec8gS053i8f9wd1AZ+TpLPeGAH1gu9Hitoi26S0YF2RgovxH4fEmgtd X-Forefront-PRVS: 013568035E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(7916002)(199003)(189002)(33716001)(54356999)(7736002)(6116002)(23676002)(50986999)(76176999)(81166006)(7416002)(81156014)(3846002)(68736007)(110136003)(7846002)(50466002)(305945005)(33646002)(2950100002)(86362001)(77096005)(103116003)(101416001)(5660300001)(6666003)(4326007)(2906002)(230700001)(47776003)(42186005)(66066001)(9686002)(83506001)(106356001)(97736004)(38730400001)(105586002)(4001350100001)(2351001)(92566002)(189998001)(8676002)(6916009); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0658; 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?MTtCTFVQUjEyTUIwNjU4OzIzOjIrVzlnYzNOKzFJZnFIZ3pNelZwR0JLQ2E0?= =?utf-8?B?b2VubSswcWtnWnR4dEdVVEllMUFCRFpRMFNTNC95a1FFS25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9REG//smADU/v/hC5pYacA X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Nov 2016 17:02:04.0499 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0658 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 --- 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 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/svm.c b/arch/x86/kvm/svm.c index 5e64e656..1bbd04c 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -4246,6 +4246,8 @@ static int handle_exit(struct kvm_vcpu *vcpu) return 1; } + vcpu->arch.gpa_available = (exit_code == SVM_EXIT_NPF); + return svm_exit_handlers[exit_code](svm); } diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c30f62dc..5002eea 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4441,7 +4441,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; @@ -5563,6 +5575,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)