Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932752AbcLHTAq (ORCPT ); Thu, 8 Dec 2016 14:00:46 -0500 Received: from mail-bl2nam02on0049.outbound.protection.outlook.com ([104.47.38.49]:6527 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932291AbcLHTAl (ORCPT ); Thu, 8 Dec 2016 14:00:41 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Subject: Re: [PATCH v2 3/3] kvm: svm: Use the hardware provided GPA instead of page walk To: Paolo Bonzini , References: <147992048887.27638.17559991037474542240.stgit@brijesh-build-machine> <147992052008.27638.18095073174935903705.stgit@brijesh-build-machine> <65a10dd8-5fae-350f-b597-f8f0261da766@redhat.com> <9820037d-e3ca-0131-3b04-2e51f2abc883@amd.com> CC: , , , , , , , , , From: Brijesh Singh Message-ID: Date: Thu, 8 Dec 2016 13:00:26 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <9820037d-e3ca-0131-3b04-2e51f2abc883@amd.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR18CA0046.namprd18.prod.outlook.com (10.173.208.32) To BLUPR12MB0657.namprd12.prod.outlook.com (10.163.217.27) X-MS-Office365-Filtering-Correlation-Id: 921a663a-0f79-4dd9-4ae7-08d41f9c7d3e X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BLUPR12MB0657; X-Microsoft-Exchange-Diagnostics: 1;BLUPR12MB0657;3:XYGUGzL9uZWbETqyzLZC/04IzJnD2lKHp6y+70eKCMA6qpOf3jwLRF+SDlEIjVUfxlSYh0jeZ3qBqrxFRaJTtJ/xGxukDQW1XauEfaC5N9peEUGe9w3+1inyO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Diagnostics: 1;BLUPR12MB0657;31:Gd45tYxb4UiHMDNVzvrFCkIH/Iibxe08QHHMHoeVORFWCicuqyvZJbkFPV1PMpNWXGy+HYZBSt2PgyMt8ZVfyhjBiC++v8DkjUpk45e1iSt9b+Ci/1FdQwFm08PXHvd0L7sfAflvGRGpxPM/wEx6Rf52I1DC0MCG6Hgna++hYU2N7MMxxmGDdm0Fl60Z8s4ULt4JPSct2G1i4PvdmpungLgOw1bkm04uQNOYVXLMGEbxVVwit2RGjUML1VQ3kN0TJr9eJMn7cfpo403+nIrJzQ==;20:mcWEtuemZ+F/2WaJLrmwV+3ugKZ7hCgk/w9wNnw+qPXAbd+CYtKAgFbVLKqt6bj595ejDZDMooFqMjhxNRoRVoe8xw+hO2pcIF9GkSdSHhOwZuJr349dLxtLXauTHcxa3DGLUXNBQ5eqJC5yIPNTtpMwib/6ZRqKx/bznL7kEfungUJuYe3nfGFtSbTEhMa4TEJpsSOLrDjQOF9f6I34vCpWyhZr4BIvokUHn/Qbd8B7jV5rcJZNtu6pg5IhXLy5t93MWin8JdsNauI8veLCRs9hQHKmJNYV3aMtotiCsYf+Qs9RWRj0RecBEJthyG71m7ChK92thc3Td6X2212GiFqJfGt26E+jdduC9XivUaD73PZhIIlVLhN8fsUKq+ogICHlfAO7+WUFDMn4l8IIiIvTUjKAXk1gM/+wjzb/KLC5ujCpn8A7JwGzQjwZ6nreZgWHaLdzQacH9BEHJCFjiR+xBxdpdbBspCrdyOsgEQyKXjZir3n/hjizCRHH/hdI X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123562025)(20161123564025)(20161123555025)(6072148);SRVR:BLUPR12MB0657;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0657; X-Microsoft-Exchange-Diagnostics: 1;BLUPR12MB0657;4:KhX3hS25SSU2fEnoASCRlsAM/zxZQzfCVwJAMjV0ykOSH5pOC8kopyjPOL+dXAYOoPbdW3OZ1zZ93wxX812T1x9UUSKvBiVycECycFkUuhh8O1nkZg8f4m4IjNqJ7soU+a9zgK7HhI9veNTGyJEAX9vkzl/fcblWFv/Y2f1UvH9kyt3u9fIvL/1gvnFivE/8jCiIerX6NYKPmZTt8vgFBc/HnmdnF6pg88kZ60fd0fv7PqrzQwdOk/Jv24uA8ZyKf9nShpSIDXrsshLj11322MSCU3GnF0zyN4kYKfU8wTdjgzH3dJa1pF9PrpdvbJDSUS9DngKf0CEE48a2H1Q0/h46CuGnEblSJb+KXYswJ5DVW7vMSNzAo+ursWZajDsJaac/JJwdbA+Zq/FhPjOHlOiO8BOa3hqmUi4gj+74ou9aknugRDnes9vlo2rnchQlZ/y71SvHGjukMC41fkHOC5EnMawAo4DI48oMTRjxcixmClXC7oXl7skutmw5FfIIy/zmJgYhxr7om42HdhDg0wDOVFRFDO6xVQFPVNX4zmcGvgEZ0EakqBsnNCDMQ1s4VoYGbhG0Yq8HwO2KpkqNy5MHwJ+zTXU53v9gssDKwyo02SxqWMrYuB/qmRCRNB0yCH7GfAKtaKrPCcwWZ4ybJtNSc+NacI6D+mIi7fZ6w7M= X-Forefront-PRVS: 0150F3F97D X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6049001)(6009001)(7916002)(39850400002)(39450400003)(39860400002)(39410400002)(39840400002)(199003)(189002)(24454002)(377454003)(65826007)(3846002)(7416002)(2906002)(4326007)(189998001)(6116002)(230700001)(6666003)(2950100002)(83506001)(92566002)(33646002)(93886004)(5660300001)(105586002)(23676002)(65956001)(65806001)(42186005)(31686004)(106356001)(101416001)(47776003)(38730400001)(64126003)(50466002)(5001770100001)(8676002)(77096006)(4001350100001)(7846002)(50986999)(86362001)(76176999)(36756003)(305945005)(68736007)(31696002)(7736002)(6486002)(97736004)(229853002)(90366009)(54356999)(81166006)(66066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GRTZaw6OjPFtC/eQhzBItqWvfS3YZJXoczy2qegchMD0QIaPmhxHmaok=;24:XNTqjzk+uZVHntHOknrkp6bSe/rzrblV5YOBmUmQlPJy+RwBnSxIt5gwkP8j9OjofoqRxmibPxI7SzJDfMM3FhOaXuASpYYtGPPBqovvzMs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BLUPR12MB0657;7:X6jcEMUp+LGcAV7nrr8ihJzWBi8Jxi6hn+IiK6oC/Va5HL3wP/2Wpuw+Hifur+tQOd0C1dKuyhsw3/6BJe5esfIxOEzpzAUWtVtId0+P9ajUdKq+OwPuplM30/7AF9d6WB2XHeCu/gu8YPmnu70PbIxJRTuXMjXzpQ0szx+rHA7DUxyOIMgZ+BVRnZVglQu4+ZSe2qT5F5pkeexl0EHTiicDWIPSNLnnXtlUQvubceRLnPRAJlrjYR7NjrIWAlgbmEQoaUMFfVLBIRwxvsskpRuBOh6CRXr9DzLncA02x1Ls/z/XUgov8ofNwBJvNkU4w5KbnEJyuMTKStA51wxz0PbEfzDQ7Ob37ZuhHuSPUExixJlFR61XYRF5qYeSSMUjbow5O9d2QJS5hZlBl6PyzmVzlnFihRqVk+rVEG4R2UrfQnitO2CadZcVya/xd9533r3uY51U481mr9NIPLBAog==;20:4lVhelyd6GnX6sd9FSoDE/yXwsvtf5wDv/W7cePVRepXaDw9YV9dQYWxg2CQW1j9pkjvMDtjaf7ISZbtArxkVYzxAmmE3AO1JkgQ2anNSD3TOGl1qxWPAizNqoauZgywduINbw5nxNwxsvEiaP1/Tju9J0qZ35broyih1PQL1pd8vi+TrjAE+ufmdfKKYr50NLmEBqSArf0lgNZ4adJgoM2xlYvcpOKHNF1vJpQiVedxwfQf9zB6kDy2JyETAbLD X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2016 19:00:33.3959 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0657 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6412 Lines: 186 Hi Paolo, On 12/08/2016 09:39 AM, Brijesh Singh wrote: > Hi Paolo, > > On 12/08/2016 08:52 AM, Paolo Bonzini wrote: >> >> >> On 23/11/2016 18:02, Brijesh Singh wrote: >>> 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 >> >> Tom, Brijesh, >> >> I would like to confirm that you have run kvm-unit-tests with this patch? >> I haven't yet tried AMD (will do before sending the pull request to >> Linus), >> but a similar patch for Intel gives me these 4 failures on emulator.flat: >> >> FAIL: push mem >> FAIL: pop mem >> FAIL: cross-page mmio read >> FAIL: cross-page mmio write >> > > I did not ran kvm-unit-tests. However, I was able to boot Linux > guest and run some stress test. I will run kvm-unit-tests and let > you know soon. > I am able to reproduce it on AMD HW using kvm-unit-tests. Looking at test, the initial thought is "push mem" has two operands (the memory being pushed and the stack pointer). The provided GPA could be either one of those. If we can detect those cases, we should not set the gpa_available on them (like what we do with string move). We probably haven't hit this case in guest booting. Will investigate bit further and provide a updated patch to handle it. > -Brijesh >> The VMX patch to set gpa_available is just this: >> >> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c >> index 25d48380c312..5d7b60d4795b 100644 >> --- a/arch/x86/kvm/vmx.c >> +++ b/arch/x86/kvm/vmx.c >> @@ -6393,6 +6393,7 @@ static int handle_ept_violation(struct kvm_vcpu >> *vcpu) >> /* ept page table is present? */ >> error_code |= (exit_qualification & 0x38) != 0; >> >> + vcpu->arch.gpa_available = true; >> vcpu->arch.exit_qualification = exit_qualification; >> >> return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0); >> @@ -6410,6 +6411,7 @@ static int handle_ept_misconfig(struct kvm_vcpu >> *vcpu) >> } >> >> ret = handle_mmio_page_fault(vcpu, gpa, true); >> + vcpu->arch.gpa_available = true; >> if (likely(ret == RET_MMIO_PF_EMULATE)) >> return x86_emulate_instruction(vcpu, gpa, 0, NULL, 0) == >> EMULATE_DONE; >> @@ -8524,6 +8526,7 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu) >> u32 vectoring_info = vmx->idt_vectoring_info; >> >> trace_kvm_exit(exit_reason, vcpu, KVM_ISA_VMX); >> + vcpu->arch.gpa_available = false; >> >> /* >> * Flush logged GPAs PML buffer, this will make dirty_bitmap more >> >> Thanks, >> >> Paolo >> >>> --- >>> 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(-) >>> >>> 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) >>> >>> -- >>> 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 >>>