From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF210C433F5 for ; Thu, 2 Sep 2021 21:54:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AACF9610A0 for ; Thu, 2 Sep 2021 21:54:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347882AbhIBVzp (ORCPT ); Thu, 2 Sep 2021 17:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347832AbhIBVze (ORCPT ); Thu, 2 Sep 2021 17:55:34 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 948FEC061575 for ; Thu, 2 Sep 2021 14:54:35 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id k24so3443742pgh.8 for ; Thu, 02 Sep 2021 14:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=5Npc+X0loZsh5ebO7T770baDNp17eU05nzX/pG10qCo=; b=h3A42v79cQgO+azy+5YH+vjJ8g6uYAnsYVAxuIsSzOXrqrbVeLOBZxRle290QJLD3R lFdCZO9yumPVa81vhm2f1Odf3ZQSJCwMvZ7O65qtGL+8Roh3lm7NbAgEc1ZaznwEN843 hRmrUpy33nXjqZsBo7CZGhlD57rdtXUIXCMs4zAgHLlRg62ydHXJlag5+IwMhxP1cAlq 6n1VuY1scLhK8REOCYmm90Jm9MuVgsXydIgTnEAs4gloOD2UlDB8X4y8RaSWHdj0/HXR Sp5//6CXtNw+T9LdIgNx3doqnOd21g6eydkUmWu7gTjxhli2/CESnKvpCMOYx3iGnz3s ozeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=5Npc+X0loZsh5ebO7T770baDNp17eU05nzX/pG10qCo=; b=oQQjxzEyKNDK079B9auwkD1zSuC9CsqtCwZJBLPPF/aOgK3+8thH6TAUqCYnZqlynb zV7QsHoOoXxy+87qrraXKmV/PitBJZNWHvK61eRxNqsT3SszClQlpVA7QRD5Y1MT1Yi1 oJEKZYuqZk/M/71Yzke9qStn2fsRcAsku0fCuQrkOXWmeJYjV2MlqNHIMve5QrlN0aPF PtJc+BH+QOvSt9kskRj72voEZW849/5vYknuIN7Wx0QPc8GrB+9PClFNxS5G/lfSYmzI Fkp+Y2UujjuS/2vu7MN7VPD6Kz/Cwq7BuBYvpbeAEDDvq+6nsqWFLsFoIxsAVF7zvPqv XyAA== X-Gm-Message-State: AOAM5320QQQVNFVxaHHzEFwe4OOSIVWbVNXVoiq2l2G1/FxcurjtepFP B5R4rogBjC07CEVq5bLeSY/sjA== X-Google-Smtp-Source: ABdhPJzzT23GfE9mw1/czxBhzeVAB4LNx3fUZJgEKB/NnPGHWknIZWKht18G7sQqYokVixxhXvQIlw== X-Received: by 2002:a65:6251:: with SMTP id q17mr463343pgv.416.1630619674901; Thu, 02 Sep 2021 14:54:34 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id i14sm3083842pfd.112.2021.09.02.14.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 14:54:34 -0700 (PDT) Date: Thu, 2 Sep 2021 21:54:30 +0000 From: Sean Christopherson To: Lai Jiangshan Cc: linux-kernel@vger.kernel.org, Paolo Bonzini , Lai Jiangshan , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , kvm@vger.kernel.org Subject: Re: [PATCH 3/7] KVM: X86: Zap the invalid list after remote tlb flushing Message-ID: References: <20210824075524.3354-1-jiangshanlai@gmail.com> <20210824075524.3354-4-jiangshanlai@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210824075524.3354-4-jiangshanlai@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 24, 2021, Lai Jiangshan wrote: > From: Lai Jiangshan > > In mmu_sync_children(), it can zap the invalid list after remote tlb flushing. > Emptifying the invalid list ASAP might help reduce a remote tlb flushing > in some cases. > > Signed-off-by: Lai Jiangshan > --- > arch/x86/kvm/mmu/mmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 987953a901d2..a165eb8713bc 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -2050,7 +2050,7 @@ static bool mmu_sync_children(struct kvm_vcpu *vcpu, > protected |= rmap_write_protect(vcpu, sp->gfn); > > if (protected) { > - kvm_flush_remote_tlbs(vcpu->kvm); > + kvm_mmu_flush_or_zap(vcpu, &invalid_list, true, flush); This can just be kvm_mmu_remote_flush_or_zap(vcpu, &invalid_list, true); since a remote flush always does a local flush too. Related to the tlbs_dirty revert, to avoid overzealous flushing, kvm_sync_page() can pass back a "remote_flush" flag instead of doing the flush itself. Something like the below, or maybe multiplex an 'int' return. diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index ac260e01e9d8..f61de53de55a 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2041,7 +2041,7 @@ static bool mmu_sync_children(struct kvm_vcpu *vcpu, struct mmu_page_path parents; struct kvm_mmu_pages pages; LIST_HEAD(invalid_list); - bool flush = false; + bool flush = false, remote_flush = false; while (mmu_unsync_walk(parent, &pages)) { bool protected = false; @@ -2050,17 +2050,17 @@ static bool mmu_sync_children(struct kvm_vcpu *vcpu, protected |= rmap_write_protect(vcpu, sp->gfn); if (protected) { - kvm_mmu_flush_or_zap(vcpu, &invalid_list, true, flush); - flush = false; + kvm_mmu_remote_flush_or_zap(vcpu, &invalid_list, true); + remote_flush = flush = false; } for_each_sp(pages, sp, parents, i) { kvm_unlink_unsync_page(vcpu->kvm, sp); - flush |= kvm_sync_page(vcpu, sp, &invalid_list); + flush |= kvm_sync_page(vcpu, sp, &invalid_list, &remote_flush); mmu_pages_clear_parents(&parents); } if (need_resched() || rwlock_needbreak(&vcpu->kvm->mmu_lock)) { - kvm_mmu_flush_or_zap(vcpu, &invalid_list, false, flush); + kvm_mmu_flush_or_zap(vcpu, &invalid_list, remote_flush, flush); cond_resched_rwlock_write(&vcpu->kvm->mmu_lock); /* * If @parent is not root, the caller doesn't have @@ -2074,7 +2074,7 @@ static bool mmu_sync_children(struct kvm_vcpu *vcpu, } } - kvm_mmu_flush_or_zap(vcpu, &invalid_list, false, flush); + kvm_mmu_flush_or_zap(vcpu, &invalid_list, remote_flush, flush); return true; } > flush = false; > } > > -- > 2.19.1.6.gb485710b >