Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1304010pxm; Thu, 3 Mar 2022 14:44:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxtHfkeJbMTjpWEev5stfZzfaJwuKpAnH0kwZEA9gXPAKUyf/p0R156KMIL/8fHeH487qoU X-Received: by 2002:a17:907:3f93:b0:6da:b5e2:f325 with SMTP id hr19-20020a1709073f9300b006dab5e2f325mr491257ejc.120.1646347488095; Thu, 03 Mar 2022 14:44:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646347488; cv=none; d=google.com; s=arc-20160816; b=SyfqL0D3GvVgy6ngpdov+D2nbRUNLiWkR+/Qh49DRxHm90Xti1vLhd+i6pgteyuSXU aBqo4fAjSlQoltAvTqXEOkFiDZBxckBxu0mwgSt3917SYibO5pyz+tdRu/dFGOQ+vila TLArVlQ+T7jE20TG8DiMDN9SDA9/RrbwwalFs3IOXUyTp8a23/Lc1WvfkF8X2DRnD5/o N0hVuYzK48NJutgjiZKS2G6f9LRFVfY2EAzDtg5J1LOzVVQ257Up4RPAzhmJaIDlCiSf OyJRRGhWH3T9wQMzc4HPEQyyi8nYlT15REpMifPCb6H5D/RqFTmwAKX9l6qxIq58pCiX XLgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=4ZWHmx7szIFAdemFtNlU8I4rxfNJcdbQ9/5ouoRecWo=; b=HNf2+u3f6xsJIHuECNbTS53TR0H8ivhpN0ripAsqtJ/6WDbhKMQm2okNaO/yG7nmtk p2jLFQcs0A10qUA8qfR2iqs5XsYIb1XdJz9W6sYQyy6nIXMI9Ibwmjpteei0wKH7uQc7 DOWzV4Q9xE/3IYo+39Y9AIQynWvJubWs2pED6z5PYVksSpM2R9+CBYRYezGZeGnuFCM2 O4j6htTJH5APcB6AJCsfrAPtQ3oYqphkmRXW49McGypAUuspbGn1dof0KELJRhIwH6VK cX7nm97MbjhR1Gvlzd5iNy+EkjhPDzsvY0zQuRq0brL+xjd18PZeC099dkMSmHJlma1H 09lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=WQ0WjqaC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pv18-20020a170907209200b006cd5fc9f21esi2435828ejb.543.2022.03.03.14.44.26; Thu, 03 Mar 2022 14:44:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=WQ0WjqaC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234526AbiCCSZt (ORCPT + 99 others); Thu, 3 Mar 2022 13:25:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232674AbiCCSZs (ORCPT ); Thu, 3 Mar 2022 13:25:48 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1E891A39E0 for ; Thu, 3 Mar 2022 10:25:02 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id gb21so5278518pjb.5 for ; Thu, 03 Mar 2022 10:25:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=4ZWHmx7szIFAdemFtNlU8I4rxfNJcdbQ9/5ouoRecWo=; b=WQ0WjqaCorFcNDc/RJ6X12JdgR0t+nWufEwGfm4dkI+CiEmkvQO71QzvoTaH4xxevS y9ls4zJuMlR6qBtcE2lMqPWHJd0BRxESjEA0IzSDFRTmTMF+HBd2N+V8mdDnyN43rTRj GB+3ktwF1PPetBWSl2GXImn81fdfW+5EvgIL4uA3qfxGIYVb3/xpWG9Dkj7ZwhUiwsHx 9pLPJ1R2L1IxIcAi7FcyPjGLrHCljPThSJZi92/aYFeceyyAa2bOw8jyLldfTATcosne LrEkdixwm7VVCUxr44fMK5b5iIawvZ/ZIhAlnZB4R/QP9OIll5Y/jnVEXzIJIyMkfalE CUpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=4ZWHmx7szIFAdemFtNlU8I4rxfNJcdbQ9/5ouoRecWo=; b=PzvkpV+HGc33MLsv28KApBTpd8mZy94syBTkW9sZ//5+d5pWCRHB+61IFXuG0Cngc6 w9vgvQYh/7c8U9Ud3aZClHFln8TdEOmnM8NscdiKvqs/s21M/TqStUBZ8j8QUjQ+C9AE RpIIBAuxZ2rM245cFpjR9DL3Y1o9fZlzSyDorOUprW/pgww98f0Ero82k9Sa4sojXSEg DvtU52WZRc3GSKYsx23xeSZXxTlTWsHwBvmFRnkZZEML+utNRi+PC4IfgblBynOdZiO1 2yIO/NIJccH5t2Dyp8SshvnVr2DuOIxT+jNO6OAS88nl8P8FeL/91vAj1ZPbW+4xH2R5 3qKw== X-Gm-Message-State: AOAM530Rqpjew5yMg/wFPigMm7lClzaG37OR4FTAgCrCRnHGe8EIOPpp MdEorYchM5dusxz31VtpMEbZWA== X-Received: by 2002:a17:90b:4d90:b0:1be:f6a9:c4d0 with SMTP id oj16-20020a17090b4d9000b001bef6a9c4d0mr6617469pjb.129.1646331902176; Thu, 03 Mar 2022 10:25:02 -0800 (PST) Received: from google.com (226.75.127.34.bc.googleusercontent.com. [34.127.75.226]) by smtp.gmail.com with ESMTPSA id g4-20020a625204000000b004f1063e3d6csm3076565pfb.125.2022.03.03.10.25.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 10:25:01 -0800 (PST) Date: Thu, 3 Mar 2022 18:24:58 +0000 From: Mingwei Zhang To: Sean Christopherson Cc: Paolo Bonzini , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , David Hildenbrand , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Ben Gardon Subject: Re: [PATCH v3 09/28] KVM: x86/mmu: Drop RCU after processing each root in MMU notifier hooks Message-ID: References: <20220226001546.360188-1-seanjc@google.com> <20220226001546.360188-10-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220226001546.360188-10-seanjc@google.com> X-Spam-Status: No, score=-18.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 On Sat, Feb 26, 2022, Sean Christopherson wrote: > Drop RCU protection after processing each root when handling MMU notifier > hooks that aren't the "unmap" path, i.e. aren't zapping. Temporarily > drop RCU to let RCU do its thing between roots, and to make it clear that > there's no special behavior that relies on holding RCU across all roots. > > Currently, the RCU protection is completely superficial, it's necessary > only to make rcu_dereference() of SPTE pointers happy. A future patch > will rely on holding RCU as a proxy for vCPUs in the guest, e.g. to > ensure shadow pages aren't freed before all vCPUs do a TLB flush (or > rather, acknowledge the need for a flush), but in that case RCU needs to > be held until the flush is complete if and only if the flush is needed > because a shadow page may have been removed. And except for the "unmap" > path, MMU notifier events cannot remove SPs (don't toggle PRESENT bit, > and can't change the PFN for a SP). > > Signed-off-by: Sean Christopherson > Reviewed-by: Ben Gardon Reviewed-by: Mingwei Zhang > --- > arch/x86/kvm/mmu/tdp_mmu.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > index 634a2838e117..4f460782a848 100644 > --- a/arch/x86/kvm/mmu/tdp_mmu.c > +++ b/arch/x86/kvm/mmu/tdp_mmu.c > @@ -1100,18 +1100,18 @@ static __always_inline bool kvm_tdp_mmu_handle_gfn(struct kvm *kvm, > struct tdp_iter iter; > bool ret = false; > > - rcu_read_lock(); > - > /* > * Don't support rescheduling, none of the MMU notifiers that funnel > * into this helper allow blocking; it'd be dead, wasteful code. > */ > for_each_tdp_mmu_root(kvm, root, range->slot->as_id) { > + rcu_read_lock(); > + > tdp_root_for_each_leaf_pte(iter, root, range->start, range->end) > ret |= handler(kvm, &iter, range); > - } > > - rcu_read_unlock(); > + rcu_read_unlock(); > + } > > return ret; > } > -- > 2.35.1.574.g5d30c73bfb-goog >