Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2138046pxb; Mon, 12 Apr 2021 15:43:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7zkE57GKHLF5pFU3VL78EvsoXzsrG8a1I2qOjXBjde/GowLT8JslAGdS/2rhUjYj7QW1r X-Received: by 2002:a17:902:e549:b029:e6:6b3a:49f7 with SMTP id n9-20020a170902e549b02900e66b3a49f7mr29933651plf.52.1618267435905; Mon, 12 Apr 2021 15:43:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618267435; cv=none; d=google.com; s=arc-20160816; b=QuvVdduJkvhSvpuizH6sXJtkYbEL/odMtFu1kITKSrGa3K3ppJ8UYhzp0TxlHkbT4t 7SIu9epvORjeeXbbm08GMbHJriSdPfCPvSd8lcedf+2FACP+EKC30WlL6pGzGSFg/uk5 lXZixZ8SMSUHu4iZ7t6nuRprcZgxcIdnoIKkB9V2mGjI7qQ+wJXrcmm6s5cU8CZPV5Ur 2Mya2lGvi1x1mI38hXEcRI5snmYJSoqy14zlrIuMRoHxp6N9kK8iWBWm59sxwu+SSCwf Pg1IdsSUuc7HUfiGaba08M+J9tW0LPx4dj0XbqQ10KKEJX2A+KaQ1r+W/iagl44j1hQw Y4Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7DWArChiyB78YDUxF5bIQb/Qm+zPu3G2NqFkMdkcp74=; b=Jy92U8mpmsOB5wjnHA3f7YtDz5pPUws19LYVeTWnPTN8TaxnIMpYrZ0yXKSMIgYlqD /R5umutxTzI6E11EOCwWGU9ag0OuXhBm7VLy8Ml319TtUwtj5jzAuDpGT+gkifrBQkuW X06skJIM9ixKWNCqEfi0JH2o0PbkNuv7QOQmhPPiIA27xxaZ6QQGCqi7lk58FhTtYwKD 9v9O1yO6SgqzAHAXtdF/TvLLnjuv/ZBUxIU4MSck3Zb58vihnyT8DQUipn2wlrmOpG5n yd/yB/+2cx5KDOGn5thm5ZLSTLcrgUmkvMXK2z3Zs1B7F0Q8jJJCg4SbLVFGa8nsID/8 rUtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=a5Y2QJMS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e3si14082617plj.4.2021.04.12.15.43.42; Mon, 12 Apr 2021 15:43:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=a5Y2QJMS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240470AbhDLJeI (ORCPT + 99 others); Mon, 12 Apr 2021 05:34:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:34282 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239149AbhDLJI4 (ORCPT ); Mon, 12 Apr 2021 05:08:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6C64C6127B; Mon, 12 Apr 2021 09:04:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618218263; bh=IbOyEbpWUouyXBq6fIqgytZcI8CAoGvw2S9oFP74e4E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a5Y2QJMSgVXZ+On54VOKnb5GaPnWyxRd1yoWBul1pGDNjjuj3A6CSHNp26k98oorc /GKvQxn82RABTZIY3azw7l/uaWi6fNj8799+VkDgaZTxF6PVnu6Bb1DjduDiOyVb6T kfHpIB2H4R8GtURVkjQCQ6qlnu7KKSzyUL1D7mEw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ben Gardon , Sean Christopherson , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.11 097/210] KVM: x86/mmu: Ensure TLBs are flushed for TDP MMU during NX zapping Date: Mon, 12 Apr 2021 10:40:02 +0200 Message-Id: <20210412084019.250174693@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210412084016.009884719@linuxfoundation.org> References: <20210412084016.009884719@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson [ Upstream commit 048f49809c526348775425420fb5b8e84fd9a133 ] Honor the "flush needed" return from kvm_tdp_mmu_zap_gfn_range(), which does the flush itself if and only if it yields (which it will never do in this particular scenario), and otherwise expects the caller to do the flush. If pages are zapped from the TDP MMU but not the legacy MMU, then no flush will occur. Fixes: 29cf0f5007a2 ("kvm: x86/mmu: NX largepage recovery for TDP MMU") Cc: stable@vger.kernel.org Cc: Ben Gardon Signed-off-by: Sean Christopherson Message-Id: <20210325200119.1359384-3-seanjc@google.com> Reviewed-by: Ben Gardon Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/mmu/mmu.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index ed861245ecf0..64ac8ae4f7a1 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -5985,6 +5985,8 @@ static void kvm_recover_nx_lpages(struct kvm *kvm) struct kvm_mmu_page *sp; unsigned int ratio; LIST_HEAD(invalid_list); + bool flush = false; + gfn_t gfn_end; ulong to_zap; rcu_idx = srcu_read_lock(&kvm->srcu); @@ -6006,19 +6008,20 @@ static void kvm_recover_nx_lpages(struct kvm *kvm) lpage_disallowed_link); WARN_ON_ONCE(!sp->lpage_disallowed); if (sp->tdp_mmu_page) - kvm_tdp_mmu_zap_gfn_range(kvm, sp->gfn, - sp->gfn + KVM_PAGES_PER_HPAGE(sp->role.level)); - else { + gfn_end = sp->gfn + KVM_PAGES_PER_HPAGE(sp->role.level); + flush = kvm_tdp_mmu_zap_gfn_range(kvm, sp->gfn, gfn_end); + } else { kvm_mmu_prepare_zap_page(kvm, sp, &invalid_list); WARN_ON_ONCE(sp->lpage_disallowed); } if (need_resched() || spin_needbreak(&kvm->mmu_lock)) { - kvm_mmu_commit_zap_page(kvm, &invalid_list); + kvm_mmu_remote_flush_or_zap(kvm, &invalid_list, flush); cond_resched_lock(&kvm->mmu_lock); + flush = false; } } - kvm_mmu_commit_zap_page(kvm, &invalid_list); + kvm_mmu_remote_flush_or_zap(kvm, &invalid_list, flush); spin_unlock(&kvm->mmu_lock); srcu_read_unlock(&kvm->srcu, rcu_idx); -- 2.30.2