Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1900239rdb; Sun, 19 Nov 2023 15:45:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IHe7sYrYJ+sEBOwvDXhc4JSQWtIfT4M+m6HOuHHYGK8ENvu1S+DhxIQQuF6IQxIaKFNUDXr X-Received: by 2002:a9d:5e92:0:b0:6bd:63b:4b21 with SMTP id f18-20020a9d5e92000000b006bd063b4b21mr5624046otl.15.1700437500992; Sun, 19 Nov 2023 15:45:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700437500; cv=none; d=google.com; s=arc-20160816; b=eWF/zlRU3jXUg6DpIZeDwF90oyrNSPnboBjcmWtIt06yhP9QAGntQRHE55tMz6CtHh hKsZ1lwaiRorb7IPbLPnEsw35VCqSMIanKMuze37ammE28XTnd2Z+RQhK/EaW5bQi/4T ICSCF6TUtUrXti/338886bbPL5XGlAic0xrlaShAiKOvrpWlrJlntgq9FlxvtDG2zNJu JwYMuC+8tl42i8f3ayQyoh6KMpSiXhAqLAMfe1irY14z+YqK/O5c1oGUVKRq/z373rS1 ZO/k1nBVkUiRoI3SBr7swM0RRdLd5MHu8xhL4T771Al1imSe+oOkThWoVjB66StIB26w N3rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:references:in-reply-to:subject :cc:to:from:mime-version:content-transfer-encoding:dkim-signature :dkim-signature; bh=FKWvpIFwXUL0jC0qOJX7qta5V8oK+eGoE06hJqTzW2E=; fh=3cVUqrBlCYKHDH/sVHASgoDP1h1US1q68V5dOsonqkA=; b=I/fPQAagB7blFaSCTxZnYV7ZNeRhC4JMCCw2N8Gz0DRlnCmwgfO8oweBaiZ0Cji8nT qRX2F4wy5Elh/uJnrBdj2FQE33hcV6fvpZGOSjq26qRCTAsg0s6hYRvVxNBCFtdAaTla 2I5zk5XnlXJV4KKm0LUQy+Du9aggsuRTdJEFp/jmaKqKKn30kKH6MmCwlRdlX6R8Kxek U+g9xbTaesO9V8Bmy0JLemB/MSi0Oite2/6KELv+ZrZLBfyIJB1LEKjZZaO99DIv5Iwl UK/RELVfPZJ2IxZH++EPTtJlXCzQDwky4/tuKGSejySdu8jobCntp6awWVVbL5V/fnUu hhXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=JBWylqI+; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=aokmubtg; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id w9-20020a63d749000000b005ab45ee3e7esi6436444pgi.299.2023.11.19.15.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 15:45:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=JBWylqI+; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=aokmubtg; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 83D058061CF4; Sun, 19 Nov 2023 15:44:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229470AbjKSXmD (ORCPT + 99 others); Sun, 19 Nov 2023 18:42:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231607AbjKSXmC (ORCPT ); Sun, 19 Nov 2023 18:42:02 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B495B8 for ; Sun, 19 Nov 2023 15:41:59 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 84E99218F0; Sun, 19 Nov 2023 23:41:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1700437317; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FKWvpIFwXUL0jC0qOJX7qta5V8oK+eGoE06hJqTzW2E=; b=JBWylqI+QMVvscAQWT3y0+vaXGAVIzQq/3M5cAjFrdoJocxPWiSu7Hifk/ancOImJ0fmdH DN7SJkU2GX52jhwnk5DS1avtFisCgcSp6alHwStUsGFb/OQ8SwsiWyl0ptH6+Ljw0DrAPM EjutSrmOb6vh/1RZxlTsAS4F/sVEp14= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1700437317; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FKWvpIFwXUL0jC0qOJX7qta5V8oK+eGoE06hJqTzW2E=; b=aokmubtgwVhYyhkQ8ep9hD8dVa7IMTX71sIcTroNhu87OVlG0jK7VRKAXLriSrTviqhFKZ FWrI0tTGxWxM/zBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 48CA31377F; Sun, 19 Nov 2023 23:41:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4icMO0KdWmX1eAAAMHmgww (envelope-from ); Sun, 19 Nov 2023 23:41:54 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 From: "NeilBrown" To: "Chuck Lever" Cc: "Jeff Layton" , linux-nfs@vger.kernel.org, "Olga Kornievskaia" , "Dai Ngo" , "Tom Talpey" Subject: Re: [PATCH 1/9] nfsd: hold ->cl_lock for hash_delegation_locked() In-reply-to: References: <20231117022121.23310-1-neilb@suse.de>, <20231117022121.23310-2-neilb@suse.de>, <40e1bf417c635ce303f9e42ddb0e3dbd90022477.camel@kernel.org>, <170042987584.19300.7721851585544522693@noble.neil.brown.name>, Date: Mon, 20 Nov 2023 10:41:52 +1100 Message-id: <170043731218.19300.6947617887297970977@noble.neil.brown.name> Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 3.40 X-Spamd-Result: default: False [3.40 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(3.00)[1.000]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_FIVE(0.00)[6]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_SPAM_LONG(3.50)[1.000]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 19 Nov 2023 15:44:58 -0800 (PST) On Mon, 20 Nov 2023, Chuck Lever wrote: > On Mon, Nov 20, 2023 at 08:37:55AM +1100, NeilBrown wrote: > > On Fri, 17 Nov 2023, Jeff Layton wrote: > > > On Fri, 2023-11-17 at 13:18 +1100, NeilBrown wrote: > > > > The protocol for creating a new state in nfsd is to allocated the sta= te > > > > leaving it largely uninitialised, add that state to the ->cl_stateids > > > > idr so as to reserve a state id, then complete initialisation of the > > > > state and only set ->sc_type to non-zero once the state is fully > > > > initialised. > > > >=20 > > > > If a state is found in the idr with ->sc_type =3D=3D 0, it is ignored. > > > > The ->cl_lock list is used to avoid races - it is held while checking > > > > sc_type during lookup, and held when a non-zero value is stored in > > > > ->sc_type. > > > >=20 > > > > ... except... hash_delegation_locked() finalises the initialisation o= f a > > > > delegation state, but does NOT hold ->cl_lock. > > > >=20 > > > > So this patch takes ->cl_lock at the appropriate time w.r.t other loc= ks, > > > > and so ensures there are no races (which are extremely unlikely in any > > > > case). > > > >=20 > > > > Signed-off-by: NeilBrown > > > > --- > > > > fs/nfsd/nfs4state.c | 3 +++ > > > > 1 file changed, 3 insertions(+) > > > >=20 > > > > diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c > > > > index 65fd5510323a..6368788a7d4e 100644 > > > > --- a/fs/nfsd/nfs4state.c > > > > +++ b/fs/nfsd/nfs4state.c > > > > @@ -1317,6 +1317,7 @@ hash_delegation_locked(struct nfs4_delegation *= dp, struct nfs4_file *fp) > > > > =20 > > > > lockdep_assert_held(&state_lock); > > > > lockdep_assert_held(&fp->fi_lock); > > > > + lockdep_assert_held(&clp->cl_lock); > > > > =20 > > > > if (nfs4_delegation_exists(clp, fp)) > > > > return -EAGAIN; > > > > @@ -5609,12 +5610,14 @@ nfs4_set_delegation(struct nfsd4_open *open, = struct nfs4_ol_stateid *stp, > > > > goto out_unlock; > > > > =20 > > > > spin_lock(&state_lock); > > > > + spin_lock(&clp->cl_lock); > > > > spin_lock(&fp->fi_lock); > > > > if (fp->fi_had_conflict) > > > > status =3D -EAGAIN; > > > > else > > > > status =3D hash_delegation_locked(dp, fp); > > > > spin_unlock(&fp->fi_lock); > > > > + spin_unlock(&clp->cl_lock); > > > > spin_unlock(&state_lock); > > > > =20 > > > > if (status) > > >=20 > > > I know it's (supposedly) an unlikely race, but should we send this to > > > stable? > >=20 > > I don't know. Once upon a time, "stable" meant something. There was a > > clear list of rules. Those seem to have been torn up. Now it seems to > > be whatever some machine-learning tool chooses. > > If that tool chooses this patch (which I suspect it will), I won't > > object. But I don't think it is worth encouraging it. >=20 > We've asked Sasha and GregKH not to use AUTOSEL on NFSD patches, > promising that we will explicitly mark anything that should be > back-ported. Oh good - I didn't know that. Thanks. NeilBrown