Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6612320rwi; Mon, 24 Oct 2022 04:01:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5CLoBkMpeJmyGTNoN5jV4pbhIoxT41HuF/1dz42K4f9zErzpvIr0wLC4moJ8ay1IuFmxZR X-Received: by 2002:a17:906:844f:b0:78d:8bd1:ee8c with SMTP id e15-20020a170906844f00b0078d8bd1ee8cmr28140818ejy.262.1666609274206; Mon, 24 Oct 2022 04:01:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666609274; cv=none; d=google.com; s=arc-20160816; b=zeEG4pvAXJul8mFk8VKVfsThpofHz9bBS2BLt0YfV6qFqJ4g8FrELxSaoH8P0acjdK RiUqrtmuFl5FKgcGi3tKaWH+bRIHmpTFH/beaGG6mzf574Vx4M7s0oQAq4hIV3d65P6J XVdV1545uexwdHkhftW7cruFWjbLQcYiqn5N45c30/ITCwhymdHApJLAZrSzUU0Bdtzr iJf0KGOw9sYh2a+5/YAGc4RfFww4xc4F1ssnYpp5MVSE1KOjVItC7uhpJ8AWISaulBk/ pZLhVAYDxI8Zvy49nKP1EQiI+sMsXbTe816g0q9S7N/LDWhRwIAdhMl3Q9F9/dCQ0cdp xgBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=jS1u9cQdfdp5Ly//O731OneOZY6n7Nyrz194SJQxkJo=; b=jycCVqEDD16tNuR+IMeL1hxy98Myxbxi2Img1YZFgphQ5SceaJg+F35ucdJqeiXr+p WY28KNxRof/eDlyVSaH3Sj93lT1+wtJa8YuqJHn7dUhpvJssxBCWgYQND8lHeKuRqVk9 5dMZThD/7OjZUPx8dIm6lnTtPabRPOEsU/xbFTvwq27wkSb3f+A9Tv8UjNqeFIJP4fcs KL3oRUQ2bLfSEzLXuiuc2laE+yrCdKIMi3scce9JnrxdUl0mDM9KTEHgWQkNTgu5Pk+y mRj6KVDpPAdYM7CVr/s9EI0VbLMlGRzMLsQQJDnh42l9FxKw4V5+sU8oArLpNZ+8uqaQ dAEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qGkal+2q; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f20-20020a056402161400b00461af57d736si3216614edv.278.2022.10.24.04.00.47; Mon, 24 Oct 2022 04:01:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=@kernel.org header.s=k20201202 header.b=qGkal+2q; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230075AbiJXK7T (ORCPT + 99 others); Mon, 24 Oct 2022 06:59:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230202AbiJXK7C (ORCPT ); Mon, 24 Oct 2022 06:59:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F6E15F997 for ; Mon, 24 Oct 2022 03:58:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E74FFB810E5 for ; Mon, 24 Oct 2022 10:57:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3EE97C433C1; Mon, 24 Oct 2022 10:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666609077; bh=8zjscNgRX1pwsOzFMCNp5SBDcYWmEXpxRyHAWeo5f3g=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=qGkal+2quaZP6KOaaf4qp1avH+KkLzzG9PVfH8RWeyOmCqE1+vg62dAadRu6WCuBs 9rDWALqC8cYMFaR3hUft+qWkk+YV8ri6SNU2yMnkgUO6w2fFHTseKKYrnrhW64ouu9 xu+cWp19S4cFk/RJdHWj4EB/SGlPGWlvt1X5P/w5ymGj/QzIYaoZrsGIJtL6FK/tql VDRmi4jZ0ySjL2iMq3Jy29Za7LvpNSXCEXSK1nd1YdzckGd66gBZXK8k2pmamT1gX0 GIybU6sASFVvJMPyC7LRMiT9Q6CZIZivCt3PmE8QEqVMrZ3q4gLcNE583XtZ4tnoBQ tdCqLHlq9LATw== Message-ID: <6af5e6b60fcac271b4bb37dec2ffe25adfef80df.camel@kernel.org> Subject: Re: [PATCH v4 5/7] NFSD: Use rhashtable for managing nfs4_file objects From: Jeff Layton To: NeilBrown , Chuck Lever III Cc: Linux NFS Mailing List Date: Mon, 24 Oct 2022 06:57:55 -0400 In-Reply-To: <166657723034.12462.8422170607830380805@noble.neil.brown.name> References: <166612295223.1291.11761205673682408148.stgit@manet.1015granger.net> , <166612313084.1291.5764156173845222109.stgit@manet.1015granger.net> , , <1DE04392-E8C9-4D39-BF23-BD1A59DB4FE3@oracle.com> <166657723034.12462.8422170607830380805@noble.neil.brown.name> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-nfs@vger.kernel.org On Mon, 2022-10-24 at 13:07 +1100, NeilBrown wrote: > On Thu, 20 Oct 2022, Chuck Lever III wrote: > >=20 > > > On Oct 19, 2022, at 7:39 AM, Jeff Layton wr= ote: > > >=20 > > > > - fp =3D find_or_add_file(open->op_file, current_fh); > > > > + rcu_read_lock(); > > > > + fp =3D insert_nfs4_file(open->op_file, current_fh); > > > > + rcu_read_unlock(); > > >=20 > > > It'd probably be better to push this rcu_read_lock down into > > > insert_nfs4_file. You don't need to hold it over the actual insertion= , > > > since that requires the state_lock. > >=20 > > I used this arrangement because: > >=20 > > insert_nfs4_file() invokes only find_nfs4_file() and the > > insert_file() helper. Both find_nfs4_file() and the > > insert_file() helper invoke rhltable_lookup(), which > > must be called with the RCU read lock held. > >=20 > > And this is the reason why put_nfs4_file() no longer takes > > the state_lock: it would take the state_lock first and > > then the RCU read lock (which is implicitly taken in > > rhltable_remove()), which results in a lock inversion > > relative to insert_nfs4_file(), which takes the RCU read > > lock first, then the state_lock. >=20 > It doesn't make any sense to talk about lock inversion with > rcu_read_lock(). It isn't really a lock in any traditional sense in > that it can never block (which is what cause lock-inversion problems). > I prefer to think for rcu_read_lock() as taking a reference on some > global state. >=20 Right. To be clear, you can deadlock with synchronize_rcu if you use it improperly, but the rcu_read_lock itself never blocks. > >=20 > >=20 > > I'm certainly not an expert, so I'm willing to listen to > > alternative approaches. Can we rely on only the RCU read > > lock for exclusion on hash insertion? >=20 > Probably we can. I'll read through all the patches now and provide some > review. >=20 The rcu_read_lock provides _no_ exclusion whatsoever, so it's not usually suitable for things that need exclusive access (like a hash insertion). If each rhl hash chain has its own lock though, then we may not require other locking to serialize insertions. --=20 Jeff Layton