Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1860653rdb; Sun, 19 Nov 2023 13:38:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvQyduFL9t5e/OUj7SGaM5aXBkaFnYd6u05tBfej0b8HCz2sTyWwHhu9qpYGgmoi7KbHCK X-Received: by 2002:a05:6830:1488:b0:6cd:2082:bfa0 with SMTP id s8-20020a056830148800b006cd2082bfa0mr6325859otq.28.1700429917044; Sun, 19 Nov 2023 13:38:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700429917; cv=none; d=google.com; s=arc-20160816; b=0WrND+MPQpJ3UeGouLaklt+mAaKtvvdIhSjqdW4wyCn6zgt1EsD+iMA9iki9CcEUdn Pxn78ZEYP6iBqd3CzGwB6uQpLB+QcnQrqoIOiEC5Icb3CzHbqg0Im6gvKhX7pfxEvs31 FYpY+rXaB56iZpxPcdQ1wGW7t2J0jsjrT0Kedm9V9366WdqvkMj0NnKEUBPzyOQlzJSz aC3tqG7NsAK/m4cLXTMcylOaqNkSftBS1nlO58qdHZxJ8SQMUvqa44PHqTsEaHHDIIHO 3Z65/IPEXA9c3gqyCmdxTJyZXw7H7jBEMpUr9ppu74H3IBollLN/JlsQKbUHAAW8z+GR wt3Q== 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=3A+nasy7ddHDwgL4rpwj3l7v6yFMrMbzUKxAMVU/3ck=; fh=HmrqYq5qjk3xA6tidfv4QO0+vHztazMqOteBU1qSCrc=; b=cXDqJhnEv0D1V/+oAPZ+qjXvHnyT8cJBrlxpk5GX6H+Cpg8sYjMgp02dyH6Jh2oIRA fUUejmzNuc26eJcQVvZr8+rUvFrFYUZQsS/Tzy01cXq161A9F3VQrgjR/ytTXwc3jV9p vxuhEhqmmB/X4G0drZWJo37Kzd/x29YcTySRiE5+HNWK61p+kPqRpl8JmBlOeYY1JRqv /oYM71x3YPGMGph43vNRTQyLQof/ur270OjokdZDQpFhs62xuPAoTQ/TzQMtoTVbcDWT Q84cXDByV86a6nKKxwhAEe5X7Y1jzyWmjwIPoNzUOMvEKjQD2PCE8ZAyA3/Aifeq599x /B5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=RAW1KmQ4; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=tLSum1Gt; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id 28-20020a63195c000000b005c21538543esi4897041pgz.433.2023.11.19.13.38.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 13:38:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=RAW1KmQ4; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=tLSum1Gt; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id B3F2C8057949; Sun, 19 Nov 2023 13:38:33 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229555AbjKSViI (ORCPT + 99 others); Sun, 19 Nov 2023 16:38:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231390AbjKSViH (ORCPT ); Sun, 19 Nov 2023 16:38:07 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA54BE5 for ; Sun, 19 Nov 2023 13:38:03 -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 7AE04218EE; Sun, 19 Nov 2023 21:38:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1700429882; 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=3A+nasy7ddHDwgL4rpwj3l7v6yFMrMbzUKxAMVU/3ck=; b=RAW1KmQ4QHqrKEUHzGaN8tdulfdCZjA2AYW1KPQjMtK4BfQv64nKfM45jBCOAiltdekmOE hHeDyZ9EcYh48fRTYXrp9vjLGbEv0hZoMf6SGTuhVP7pymmpSLmGLQ3XhpoKKURb73j9b8 mohi1FeTHzp4pm+pgzfeHUxaVoOdmug= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1700429882; 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=3A+nasy7ddHDwgL4rpwj3l7v6yFMrMbzUKxAMVU/3ck=; b=tLSum1GtI/26dY5sDzj0mghlBrJC59Yfqo5C3o2QHLibVyqpepgSenoZxmkcGkJjISg6si jeChLO3a8tR2BeBA== 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 43166139B7; Sun, 19 Nov 2023 21:37:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kDuRODeAWmXUSAAAMHmgww (envelope-from ); Sun, 19 Nov 2023 21:37:59 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 From: "NeilBrown" To: "Jeff Layton" Cc: "Chuck Lever" , 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: <40e1bf417c635ce303f9e42ddb0e3dbd90022477.camel@kernel.org> References: <20231117022121.23310-1-neilb@suse.de>, <20231117022121.23310-2-neilb@suse.de>, <40e1bf417c635ce303f9e42ddb0e3dbd90022477.camel@kernel.org> Date: Mon, 20 Nov 2023 08:37:55 +1100 Message-id: <170042987584.19300.7721851585544522693@noble.neil.brown.name> Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 6.40 X-Spamd-Result: default: False [6.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(-0.00)[12.48%] 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 agentk.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 (agentk.vger.email [0.0.0.0]); Sun, 19 Nov 2023 13:38:33 -0800 (PST) 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 state > > 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 of a > > delegation state, but does NOT hold ->cl_lock. > >=20 > > So this patch takes ->cl_lock at the appropriate time w.r.t other locks, > > 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, stru= ct 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? 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 > Reviewed-by: Jeff Layton >=20 Thanks, NelBrown