Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1144229pxm; Thu, 3 Mar 2022 11:10:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJy6LNuwzOzHtAHpox3ujrOeI95udeOL/ZU0BvFbsMFnicw+gfRibC9VAAv7wVLaDA893PQQ X-Received: by 2002:a05:6402:1e8b:b0:3da:58e6:9a09 with SMTP id f11-20020a0564021e8b00b003da58e69a09mr35353713edf.155.1646334604591; Thu, 03 Mar 2022 11:10:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646334604; cv=none; d=google.com; s=arc-20160816; b=EwCkdh274+8QR9/7QToxxOHB0n4Aff5Ywiguu99YiunZtZ6Lk48UlhN40m/W0PXUEW WQCNcizECbzGW4veUgCr7DI5zrzxqvr5keibd/5jTbvrRPfQ9V2StV8TGW51V6MA7y47 2+i+1c1mLdx33q8cesnQN3+XFdjVr4BCS7fyCYG0RdTwyWD6aspwSdV+bst+WyZE5aFi QwAhrZlqLbtfGQJsSBCw7J84ABZQZ06PO8bYCHR9TPlTLm+LFA7C/X9uiQuUYyHr7WeY jbS41di4SpkVz8XfxedvLM/lBB37G6kwISgRuYm3YoXbnAO10KDRpGeXnSiliNR9DvtU 3FmQ== 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=qlq96R215BtY25bFBdaZHI6jV8wr7yu7isAUDVtrQE0=; b=oAlIf1APgiQW6ocNqW9on3ASSdkZlsZ5rmOsdwIBzyJ0lRxpGZfhUIkrN5lg1YKZNP kp4KZ9EY7pQ8hyH9NL8/XRYlr0/Hb8e3RV5VpUEanIDr8hpb5kR2vxWzzaLS007yXgyI 6Z1JREMFFZODlpYBzV0MpzrtzHDXh9rVOsEUyKBhMeN8LsiPD6BN5TiEMpKJtLEM/Wo7 +Hv8+20U0CgCcfGpzy9CbjwCqwFpgVetr6yVvYz89yj9k54kvyfrs8c7OTeLumlhSE+c zc2q5p/By5yya66BYDEEOdmg2/wSZqbeMP8Sez7jiK7D+1UIGXE+3VWOIuigDQP/uhUY LwMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qAfGtS76; 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 t19-20020a1709060c5300b006d0285c6780si1566034ejf.790.2022.03.03.11.09.41; Thu, 03 Mar 2022 11:10:04 -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=qAfGtS76; 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 S233137AbiCCSdZ (ORCPT + 99 others); Thu, 3 Mar 2022 13:33:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230374AbiCCSdY (ORCPT ); Thu, 3 Mar 2022 13:33:24 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9374151E63 for ; Thu, 3 Mar 2022 10:32:38 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id mr24-20020a17090b239800b001bf0a375440so3094113pjb.4 for ; Thu, 03 Mar 2022 10:32:38 -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=qlq96R215BtY25bFBdaZHI6jV8wr7yu7isAUDVtrQE0=; b=qAfGtS76c92RQqU8Iu7Z5bVP+avIc0p+d2zENWbdn2G9bzL8wRAZa77fg3x4PC4SG8 nnhLA6bqf1frGFlJoe9B4ilFPtAwKxRWT+ViTNtEiTQ4rnoZ1zzV9kC5nHYCEchPRVfW zFEzcSpmeeiA+j4AjC3h1FZ4W4hu51mKJT/YMdzohotDMndW6Fs4fD4uXssbYlFgdQ8i HIsMeWytVwJrgQ8LgwKqigJRePl7S6bhW8OFJO9acXsGKWlpEG4sk6Jl4gy3Dzjjsakc bB36HsveW28/R2iEtgxjhROweEiXlWXJLkCI6N9CyK1Ertupe2Rsb23JQLSpQgGPCkYZ 7Z/g== 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=qlq96R215BtY25bFBdaZHI6jV8wr7yu7isAUDVtrQE0=; b=dCoL3tUaDUbiN3u8ZcZj2JO84mDyd1u6gFn1d0HHaJmKJ3F+iWmv/7SLwp8hxvWKzh 0CufxbgzRIzlxVoHI8lLDyOTvTCLxzUyKfeMsgSD5v2OBMFfi8JOwwfsPmhU5MxriwyZ BiaA9w+hlSZhaOAdjq+Iz00786od8tgjgvyxdGSXFHkcaNnkmeT7jwHfWikmrLuokhGy kjoyjbemcsg4HUaCMqoy4eMPKwaflm9AaaVBj4uZuWWeKMXusCr+kegKdBBXPnebye+Q CDpQabQ4dYN93AKGe9ovl17mGi2y0tdBn+fJ1yQ6eFVbzSge5N01SKFu3SpmaHv+Kvpu Y54w== X-Gm-Message-State: AOAM530n1mvVwxt9W5F9WHyjIZxEniItM00GLqxLFmxOAUup11gJwrVq rzciuLeRnifxz94LJnf5PLv3bQ== X-Received: by 2002:a17:902:8b87:b0:14b:47b3:c0a2 with SMTP id ay7-20020a1709028b8700b0014b47b3c0a2mr37003074plb.51.1646332357832; Thu, 03 Mar 2022 10:32:37 -0800 (PST) Received: from google.com (226.75.127.34.bc.googleusercontent.com. [34.127.75.226]) by smtp.gmail.com with ESMTPSA id il17-20020a17090b165100b001bcd92fd355sm2932280pjb.28.2022.03.03.10.32.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 10:32:37 -0800 (PST) Date: Thu, 3 Mar 2022 18:32:33 +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 >