From patchwork Tue Aug 14 10:37:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Mackerras X-Patchwork-Id: 10565307 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E72D91515 for ; Tue, 14 Aug 2018 10:37:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBEDE28AF9 for ; Tue, 14 Aug 2018 10:37:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC41B28B2D; Tue, 14 Aug 2018 10:37:54 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 5F53E28AF9 for ; Tue, 14 Aug 2018 10:37:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731996AbeHNNY1 (ORCPT ); Tue, 14 Aug 2018 09:24:27 -0400 Received: from ozlabs.org ([203.11.71.1]:34699 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728541AbeHNNY1 (ORCPT ); Tue, 14 Aug 2018 09:24:27 -0400 Received: by ozlabs.org (Postfix, from userid 1003) id 41qTZQ5VScz9s7c; Tue, 14 Aug 2018 20:37:50 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1534243070; bh=oBeYQl3eE6NOkjyguaqWWR0daGaTMjZlloT0VhQNaT0=; h=Date:From:To:Cc:Subject:From; b=pVJbw1QIBhjeZf39+OtunYjlfMyWQJcK+9C+E9weVOXCAqt1sv0FHBZQsigvJ/s1V Ctx1h7vR/WnBZJpPjVVcN1Te/IUTLvwXUUBreymxGrqaByJRdeusW4fzdsANsA/boq EtoWSJQTNl+AIyo7YZ4z2PNQ3jjpcrufWj9XQHrdEqTAyW5lfWtI9m+/Pz4vTXlS5B isHUrl60GpHeHqrDLLV1rigjNT9NNlggU8HxzA9I3aPZQaqznkL6DVHtPEqscE1IX9 uMy4TZk1oujFhfMaNWNT+BzbuKD4NG+MMcihcJnLON5nVw32aF1DYBxI0Da+rTlK2t Om6Sp5Z2uXcmg== Date: Tue, 14 Aug 2018 20:37:45 +1000 From: Paul Mackerras To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Cc: David Gibson Subject: [PATCH] KVM: PPC: Book3S HV: Use correct pagesize in kvm_unmap_radix() Message-ID: <20180814103745.GA9860@fergus> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since commit e641a317830b ("KVM: PPC: Book3S HV: Unify dirty page map between HPT and radix", 2017-10-26), kvm_unmap_radix() computes the number of PAGE_SIZEd pages being unmapped and passes it to kvmppc_update_dirty_map(), which expects to be passed the page size instead. Consequently it will only mark one system page dirty even when a large page (for example a THP page) is being unmapped. The consequence of this is that part of the THP page might not get copied during live migration, resulting in memory corruption for the guest. This fixes it by computing and passing the page size in kvm_unmap_radix(). Cc: stable@vger.kernel.org # v4.15+ Fixes: e641a317830b (KVM: PPC: Book3S HV: Unify dirty page map between HPT and radix) Signed-off-by: Paul Mackerras --- arch/powerpc/kvm/book3s_64_mmu_radix.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c b/arch/powerpc/kvm/book3s_64_mmu_radix.c index 176f911ee983..7efc42538ccf 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_radix.c +++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c @@ -738,10 +738,10 @@ int kvm_unmap_radix(struct kvm *kvm, struct kvm_memory_slot *memslot, gpa, shift); kvmppc_radix_tlbie_page(kvm, gpa, shift); if ((old & _PAGE_DIRTY) && memslot->dirty_bitmap) { - unsigned long npages = 1; + unsigned long psize = PAGE_SIZE; if (shift) - npages = 1ul << (shift - PAGE_SHIFT); - kvmppc_update_dirty_map(memslot, gfn, npages); + psize = 1ul << shift; + kvmppc_update_dirty_map(memslot, gfn, psize); } } return 0;