Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp163442rdb; Sun, 28 Jan 2024 19:37:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMX4Y2IY5w9WevTgU2VgZ5EPadOeThvJ3bBwpv6rJXFtGGd0e8+UrngjahwmCLmJmpPDIg X-Received: by 2002:a05:620a:2:b0:783:3638:2586 with SMTP id j2-20020a05620a000200b0078336382586mr4507331qki.125.1706499428439; Sun, 28 Jan 2024 19:37:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706499428; cv=pass; d=google.com; s=arc-20160816; b=GuH4al1fGU/Wg9fLH4HfPhoshLvX+aM55z/c/m/2Fg60fkk6R/V+Bq6sVyhaYnhC/F 17klgo+5dyuhsnCC8SLgcrcp1XZtcKN4QhpNoByzQ6vWfPJJ+RBJ49WP9iH4G8m6Y3Dp Fm8HX6bybUnZ4bpBYiC/w0nrtH5kZO+ZmYNimxmk+BDTRFE6T3Cam9RHtNNXuxJRbvYx Uo5elxETtZm5X8ifQMUbSNuTFTBUZt6loBaaUwcalNhes4Rq1fLTZnAhzVK2JOZyIUYd 5D6WxABkO99CjPJEEl8OCN+JRIh5WxzrW70UfP6G0Q0QuD7NFjYDoQgPxBLhkJ6jSi64 DbOg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature :dkim-signature:dkim-signature; bh=TaQNrZdrJQ2oiXWurcfSf0wVHBYCdcL/aS+CMuWjn3E=; fh=DPK+PwXoUUGZcwbQK6Acek0sHLUTB6JOgAucPVabbeA=; b=ch7efZUN+GKAkVowUXgC1WXZlbC3JioG8W4p7w089tU+ah+BAebKFziaMDQHcA/yXf JTplYcteQaGVB4gDaIWgVaJubfjm2m1L8RpoEcnXG4y6zzrlSw5IvxdryHbUyi4zAIsl 3om/69kouri5KCc1fu40fDL2T52+FZdHNOSTy711BDF0R1SHvmLTpi3GQpGFcPsgjweR m9t4URy5Y3N2hub5CNuPQDgfIiC/3BVxawdUAt5Zu6ewThmAtUa5B1jgOIZlbSWY8NDE Lgfj7hFlh+o5CJxRK0wESjMRy8PzM62+nhMRKzXxoatni+0TrRdHfYnUIh1Gzg+TtKcN 5DLw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=h9TB+dHb; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=bVdqZP1K; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=h9TB+dHb; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=bVdqZP1K; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-nfs+bounces-1517-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-nfs+bounces-1517-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id dc50-20020a05620a523200b007838dfdd174si6698636qkb.251.2024.01.28.19.37.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 19:37:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-1517-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=h9TB+dHb; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=bVdqZP1K; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=h9TB+dHb; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=bVdqZP1K; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-nfs+bounces-1517-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-nfs+bounces-1517-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 13A011C21CA7 for ; Mon, 29 Jan 2024 03:37:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D65411718; Mon, 29 Jan 2024 03:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="h9TB+dHb"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="bVdqZP1K"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="h9TB+dHb"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="bVdqZP1K" X-Original-To: linux-nfs@vger.kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C82001172C for ; Mon, 29 Jan 2024 03:37:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706499425; cv=none; b=ow4GFZpPHDP17RxrGYFi0F5gZQhjV4iE/1UPpzt4At3HmdKj3RHQjNYtDyvI2Dm2q6OPXLwu6PeMhxgpXwLx1hHmNtBEc3mJH9KWkd1+ueYmFC/18ULRf7KwqmVPM/IJMszz1N0jQXzxPyUNUIx5HQcbIgCzBBPHK722o1ZoKTI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706499425; c=relaxed/simple; bh=u4MXg5CWiDWN5wVVGu+mJ/GxNHKILONuEXxAMifFi6U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fucRWZp4FUrnZ74fbR/g6xzN2lMCHqPPfQ01VacUg7eGYGjdgJSU6L9crGUvFrkgExWHFDmZ2JNLhkSRtLdxoKW/Uq55g7v2Ej5ZwAZPB7Xamty4MTu7MYpAT8JTE4jzz6KDK5/lq9wN3+llYcOVvFcs8SnOAicaRayJ8RDsYZM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=h9TB+dHb; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=bVdqZP1K; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=h9TB+dHb; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=bVdqZP1K; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1079C1F7C9; Mon, 29 Jan 2024 03:37:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706499422; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TaQNrZdrJQ2oiXWurcfSf0wVHBYCdcL/aS+CMuWjn3E=; b=h9TB+dHbYGDoMYHdyqpaUvBftdrslxHxD1VREiTyeq6Lq/qPppuCZVl+gOiclOu5r6PAfO dMe/AGtzFBIE2HB6hPatFS/g45ILeMPmTEAakcY2/XE837Bs9+meDfFqBM/jht7dQXLCJA /TApawZ76ZbJ2fINUycsDZ/cgjLdqiA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706499422; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TaQNrZdrJQ2oiXWurcfSf0wVHBYCdcL/aS+CMuWjn3E=; b=bVdqZP1Kd9Is/q6Jghd6BVK8EqHw8QXVb6Zo2l/5u/ZwMiMubWQm9UesuC5My+9IAmsYiY e067Au9ceW4MZsCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706499422; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TaQNrZdrJQ2oiXWurcfSf0wVHBYCdcL/aS+CMuWjn3E=; b=h9TB+dHbYGDoMYHdyqpaUvBftdrslxHxD1VREiTyeq6Lq/qPppuCZVl+gOiclOu5r6PAfO dMe/AGtzFBIE2HB6hPatFS/g45ILeMPmTEAakcY2/XE837Bs9+meDfFqBM/jht7dQXLCJA /TApawZ76ZbJ2fINUycsDZ/cgjLdqiA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706499422; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TaQNrZdrJQ2oiXWurcfSf0wVHBYCdcL/aS+CMuWjn3E=; b=bVdqZP1Kd9Is/q6Jghd6BVK8EqHw8QXVb6Zo2l/5u/ZwMiMubWQm9UesuC5My+9IAmsYiY e067Au9ceW4MZsCg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7054913867; Mon, 29 Jan 2024 03:36:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id owpLClsdt2UYKgAAD6G6ig (envelope-from ); Mon, 29 Jan 2024 03:36:59 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia , Dai Ngo , Tom Talpey , Christoph Hellwig , Tom Haynes Subject: [PATCH 02/13] nfsd: hold ->cl_lock for hash_delegation_locked() Date: Mon, 29 Jan 2024 14:29:24 +1100 Message-ID: <20240129033637.2133-3-neilb@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240129033637.2133-1-neilb@suse.de> References: <20240129033637.2133-1-neilb@suse.de> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [4.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[vger.kernel.org,netapp.com,oracle.com,talpey.com,lst.de,gmail.com]; RCVD_TLS_ALL(0.00)[] X-Spam-Level: **** X-Spam-Score: 4.90 X-Spam-Flag: NO The protocol for creating a new state in nfsd is to allocate 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. If a state is found in the idr with ->sc_type == 0, it is ignored. The ->cl_lock lock 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. ... except... hash_delegation_locked() finalises the initialisation of a delegation state, but does NOT hold ->cl_lock. 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). As ->fi_lock is often taken when ->cl_lock is held, we need to take ->cl_lock first of those two. Currently ->cl_lock and state_lock are never both taken at the same time. We need both for this patch so an arbitrary choice is needed concerning which to take first. As state_lock is more global, it might be more contended, so take it first. Reviewed-by: Jeff Layton Signed-off-by: NeilBrown --- fs/nfsd/nfs4state.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index d377a0a56e45..051c3e99fac6 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1312,6 +1312,7 @@ hash_delegation_locked(struct nfs4_delegation *dp, struct nfs4_file *fp) lockdep_assert_held(&state_lock); lockdep_assert_held(&fp->fi_lock); + lockdep_assert_held(&clp->cl_lock); if (nfs4_delegation_exists(clp, fp)) return -EAGAIN; @@ -5557,12 +5558,14 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, goto out_unlock; spin_lock(&state_lock); + spin_lock(&clp->cl_lock); spin_lock(&fp->fi_lock); if (fp->fi_had_conflict) status = -EAGAIN; else status = hash_delegation_locked(dp, fp); spin_unlock(&fp->fi_lock); + spin_unlock(&clp->cl_lock); spin_unlock(&state_lock); if (status) -- 2.43.0