Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp732060pxm; Fri, 25 Feb 2022 18:37:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJwqFHrDFPbesXgltwXyhkUto+DxwwLoo4wClJOfvYe8mJ14ZFM6E3t06Me3Gy3BdRULlLJX X-Received: by 2002:a17:902:bc8a:b0:14f:1acb:4487 with SMTP id bb10-20020a170902bc8a00b0014f1acb4487mr10550644plb.107.1645843024090; Fri, 25 Feb 2022 18:37:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645843024; cv=none; d=google.com; s=arc-20160816; b=Blrdusq+W+QcfzyPHFfNSaGS/KlxdIfhgPMNzhpo4u43P128IUiHHLJpOOf/JDaL18 JSWrmn4XnXUI7DU8ZZHuNJXaZwzyRxDFrxgyJU+69cl1LxJiHJZwPZM5J+yhvTY5Dcvy HRQjenrRUN0AxWcnRD/E8wQhhsBS6C73U6ywDIeeEa5DpudIOm4MGBaU/vSpFoPA1meV XsLBdAdy+XG9be+bIyKr8a23reg2tWzj7PYo5K37LOc4VK7Zme49YxuDhN4wX2qstJXy N4lgstqup8960bZDhBPuelqCS1ey9Tpr0mRuXNQ8Ia3HHJssPVZQXIj1boK9hOgESh79 c7Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=JDThRSqN0byFLKsQYI89Co7AKmuBCHnME5v6WomODDw=; b=hLpDydKt7ulWpAs4lPydoN7Zhw+wa5ugJSKtBJdzuoyuOMvVkW3goU7YLj4NTv1UyG o5hZbFmc0Z7+es4n+tE/kMneWyoCujVaBdZzWyeQGqLWeqzzIAQNx0hwTrZ2QYbNysX1 FWpyAPlsT9N/Ipg1rEixRG7oqwOg3InO4JYGFVgDlh6hMoj75zooMU4wYvTMzVWLf3sk P0Ztvx59Xfr8dOYaaLOnPnzd7YdMQy04/HtQiWxvDAV8Xk86YxVJYJfO9SJyu5LnO3x0 DdGX+jXgWbrvQ4pl+cyrYRzc6XVdOqIMN2pAa9e4eTR7LX84FGq8Bxsb9cSdEj+F919b 2VJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=KnNEuHSD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id bd11-20020a656e0b000000b0037449f3fb1asi3122363pgb.663.2022.02.25.18.37.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 18:37:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=KnNEuHSD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1E7352A2CEC; Fri, 25 Feb 2022 18:02:16 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240761AbiBZASJ (ORCPT + 99 others); Fri, 25 Feb 2022 19:18:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240459AbiBZARC (ORCPT ); Fri, 25 Feb 2022 19:17:02 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 835AC2261DE for ; Fri, 25 Feb 2022 16:16:25 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id t134-20020a62788c000000b004e1367caccaso3948321pfc.14 for ; Fri, 25 Feb 2022 16:16:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=JDThRSqN0byFLKsQYI89Co7AKmuBCHnME5v6WomODDw=; b=KnNEuHSDYY9Qpv8Sc7pMTFoKsQ1o1irShtKNr/STHSxYwJLaYyi5K1uzyhNvsRIB+t GmneOFlCNqt6+D5k8U9urB6oYaTV70HwxQqPey79vYIYg2VXQBvVhwTPKie/2bAcGEen yw0Omtgx2d7PvTH+1z372LtMBDGvi4yvNRQ3516OqK89vTJfmn98v81FAVz13FI/gcb0 FMOYaSUSX8sDJ4F/5NY/WaHzV00pF8Aw3qeWDHuBihAGUcaxx+SaNk6vPwupm8BgvMUt YT9pjc7hdVJFH6fBi0ci5quzkscOsEQIKLLvKn6WqvEuBmzO92jF8ncfBNTNQJv6r1rA c1fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=JDThRSqN0byFLKsQYI89Co7AKmuBCHnME5v6WomODDw=; b=1MuTGzLSHzllG89cTQ/JijHzkbluiFX9kc7wjCh4HXD0P4gjogp04bPLR7resKjXqA 579kwLibJG0NILt+kwlzNdVfNlwkidiepaaILsp98m4/uuCaWDv5wEvIpfExy5Lh3Vf7 gXVvK5OwzDJyXUgeSjcSNdzLCjPtUCs0TZxqAQ243APz+3+vocl93y3Y9aApfOtQPd5k l3fF5sXJh/Pa2smszh6aIGUCnYnmIksGtp74OlewXOguoTPgb1PdCxneK/39v1qXw2P+ CO5NblzfPioykmM0uAa2a2LODGJWe3jJW4hb3yPyuv4+e5gSqsFxynRK6nMAsAU6PygL Mnjg== X-Gm-Message-State: AOAM5307PA1SKaZNR3GEVgb7bli9QfjsO0KguGNejMnHcCcUAOr1s6KL q35D8t3MXAvTTmVgH1mLYz2MgjrvyEo= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:b906:b0:14f:76a0:ad48 with SMTP id bf6-20020a170902b90600b0014f76a0ad48mr9902830plb.79.1645834584804; Fri, 25 Feb 2022 16:16:24 -0800 (PST) Reply-To: Sean Christopherson Date: Sat, 26 Feb 2022 00:15:32 +0000 In-Reply-To: <20220226001546.360188-1-seanjc@google.com> Message-Id: <20220226001546.360188-15-seanjc@google.com> Mime-Version: 1.0 References: <20220226001546.360188-1-seanjc@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 14/28] KVM: x86/mmu: Skip remote TLB flush when zapping all of TDP MMU From: Sean Christopherson To: Paolo Bonzini , Christian Borntraeger , Janosch Frank , Claudio Imbrenda Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , David Hildenbrand , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Ben Gardon , Mingwei Zhang Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Don't flush the TLBs when zapping all TDP MMU pages, as the only time KVM uses the slow version of "zap everything" is when the VM is being destroyed or the owning mm has exited. In either case, KVM_RUN is unreachable for the VM, i.e. the guest TLB entries cannot be consumed. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index c231b60e1726..87706e9cc6f3 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -874,14 +874,15 @@ bool __kvm_tdp_mmu_zap_gfn_range(struct kvm *kvm, int as_id, gfn_t start, void kvm_tdp_mmu_zap_all(struct kvm *kvm) { - bool flush = false; int i; + /* + * A TLB flush is unnecessary, KVM zaps everything if and only the VM + * is being destroyed or the userspace VMM has exited. In both cases, + * KVM_RUN is unreachable, i.e. no vCPUs will ever service the request. + */ for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) - flush = kvm_tdp_mmu_zap_gfn_range(kvm, i, 0, -1ull, flush); - - if (flush) - kvm_flush_remote_tlbs(kvm); + (void)kvm_tdp_mmu_zap_gfn_range(kvm, i, 0, -1ull, false); } /* -- 2.35.1.574.g5d30c73bfb-goog