From patchwork Wed Jan 10 06:04:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 10154027 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 597EC602D8 for ; Wed, 10 Jan 2018 06:05:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CBB1274D0 for ; Wed, 10 Jan 2018 06:05:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4148B28068; Wed, 10 Jan 2018 06:05:01 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 EFA1F274D0 for ; Wed, 10 Jan 2018 06:05:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933440AbeAJGEp (ORCPT ); Wed, 10 Jan 2018 01:04:45 -0500 Received: from ozlabs.org ([103.22.144.67]:41559 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933289AbeAJGEo (ORCPT ); Wed, 10 Jan 2018 01:04:44 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 3zGdky2NHlz9sNV; Wed, 10 Jan 2018 17:04:42 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1515564282; bh=zvT3TluNRa2HMhT5jw6sRklslXagVAc5vVWPrOOMSg4=; h=From:To:Cc:Subject:Date:From; b=PqAVqXU4KP50rN/sbVX/VUETLXBLebRTU/umbX/zVulRk+sytodDdUc/whdXJCZX5 88aSjQLc4Pily4ctc7oo5nFuFpahBi5djzatgGNu/CdM88HpLGmcJp9Xe8Vj5fgzop BsURfh/EFn9S+ejpyZVbVfS9/FQONglAzFSfKLF0= From: David Gibson To: paulus@samba.org, surajjs@au1.ibm.com, spopovyc@redhat.com Cc: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, linux-kernel@vger.kernel.org, David Gibson Subject: [PATCH] KVM: PPC: Book3S HV: Always flush TLB in kvmppc_alloc_reset_hpt() Date: Wed, 10 Jan 2018 17:04:39 +1100 Message-Id: <20180110060439.21822-1-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.14.3 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The KVM_PPC_ALLOCATE_HTAB ioctl(), implemented by kvmppc_alloc_reset_hpt() is supposed to completely clear and reset a guest's Hashed Page Table (HPT) allocating or re-allocating it if necessary. In the case where an HPT of the right size already exists and it just zeroes it, it forces a TLB flush on all guest CPUs, to remove any stale TLB entries loaded from the old HPT. However, that situation can arise when the HPT is resizing as well - or even when switching from an RPT to HPT - so those cases need a TLB flush as well. So, move the TLB flush to trigger in all cases except for errors. Signed-off-by: David Gibson --- arch/powerpc/kvm/book3s_64_mmu_hv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) Paul, this is based on Paolo's KVM tree, but it should apply without modification to pretty much any vaguely current tree. It's a pretty nasty bug - the case we've found hitting it in the wild is a bit esoteric, but it could in theory affect other situations as well. Please apply ASAP, and should probably be queued for the stable branches as well. diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c index 966097232d21..51a275cc8a4d 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c @@ -159,8 +159,6 @@ long kvmppc_alloc_reset_hpt(struct kvm *kvm, int order) * Reset all the reverse-mapping chains for all memslots */ kvmppc_rmap_reset(kvm); - /* Ensure that each vcpu will flush its TLB on next entry. */ - cpumask_setall(&kvm->arch.need_tlb_flush); err = 0; goto out; } @@ -176,6 +174,10 @@ long kvmppc_alloc_reset_hpt(struct kvm *kvm, int order) kvmppc_set_hpt(kvm, &info); out: + if (err == 0) + /* Ensure that each vcpu will flush its TLB on next entry. */ + cpumask_setall(&kvm->arch.need_tlb_flush); + mutex_unlock(&kvm->lock); return err; }