From patchwork Mon Mar 4 22:45:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 13581325 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 062A23C28 for ; Mon, 4 Mar 2024 22:47:36 +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=1709592458; cv=none; b=Cua6dGpqDL6J0XdJ+CQIVPqktsbnJydasmlm83qBtJzvoCGqAEV4x4RP3CxlGEDaHBft3tqOWapqLNbi0UZIDOAS9n39bolDq/2Ux8iHpWCAurx3mB5pbt5t8WlU0sPPguebXZ0bJh63WllrX2AwxKeNFSH+TJPGN2gdITn4PH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709592458; c=relaxed/simple; bh=sId/eKh+dcs/8FAWjUVdKOTw9dlG0CuykFXJJHFxTJw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lO5ENn56XDysuy6flJ0sfI1sj4da8ciOsqwD2AfA/llQraEe4KTmM7l6RKb2stAd3TArP0jAIQwiaWqjJaBi2YZ4n+fXq7Om1vHid5lSG5ee8jbkaY53HtlvWzQEK5XtYL/EkyfYH5ejyG82Zc9Ypi68BsHGuGeSS6Lpc4ChqXk= 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=n2I1Jxdy; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=bDuHn61l; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=n2I1Jxdy; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=bDuHn61l; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="n2I1Jxdy"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="bDuHn61l"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="n2I1Jxdy"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="bDuHn61l" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 18AA420D66; Mon, 4 Mar 2024 22:47:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709592455; 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=CpsLy1ROmmZPQNnbDUqjl3UQJzQpt8usQ2K4vI/HzaI=; b=n2I1JxdyGpqrS8lmNRnZrbJu7XIhTTURj9qt+wwq4hSXx/d0W05ioEQ6cM3rEbe6O12Xxo nkUahlMu74M/qNHmRdcIR1tsbPW8LfIn/lgSsQ13IBSZBp+y4v4xkE9rq5Zt4UJIpgClRR orsjJlJbg6Sm5eJ1xDELwxx9qfKhLew= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709592455; 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=CpsLy1ROmmZPQNnbDUqjl3UQJzQpt8usQ2K4vI/HzaI=; b=bDuHn61lvIGSaaxItKbBUJL/JL1gjScD5KA2Sz431bvcG+tVF8W0z07jQB42NjkL+mBzVc 0bw18eNL1QRUYuAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709592455; 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=CpsLy1ROmmZPQNnbDUqjl3UQJzQpt8usQ2K4vI/HzaI=; b=n2I1JxdyGpqrS8lmNRnZrbJu7XIhTTURj9qt+wwq4hSXx/d0W05ioEQ6cM3rEbe6O12Xxo nkUahlMu74M/qNHmRdcIR1tsbPW8LfIn/lgSsQ13IBSZBp+y4v4xkE9rq5Zt4UJIpgClRR orsjJlJbg6Sm5eJ1xDELwxx9qfKhLew= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709592455; 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=CpsLy1ROmmZPQNnbDUqjl3UQJzQpt8usQ2K4vI/HzaI=; b=bDuHn61lvIGSaaxItKbBUJL/JL1gjScD5KA2Sz431bvcG+tVF8W0z07jQB42NjkL+mBzVc 0bw18eNL1QRUYuAw== 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 7908413A5B; Mon, 4 Mar 2024 22:47:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id 10iDB4RP5mUYYgAAD6G6ig (envelope-from ); Mon, 04 Mar 2024 22:47:32 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia , Dai Ngo , Tom Talpey Subject: [PATCH 1/4] nfsd: move nfsd4_cstate_assign_replay() earlier in open handling. Date: Tue, 5 Mar 2024 09:45:21 +1100 Message-ID: <20240304224714.10370-2-neilb@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240304224714.10370-1-neilb@suse.de> References: <20240304224714.10370-1-neilb@suse.de> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: * X-Spamd-Bar: + Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=n2I1Jxdy; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=bDuHn61l X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [1.04 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[6]; DWL_DNSWL_LOW(-1.00)[suse.de:dkim]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email]; NEURAL_HAM_LONG(-1.00)[-1.000]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; NEURAL_HAM_SHORT(-0.04)[-0.212]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-1.61)[92.50%] X-Spam-Score: 1.04 X-Rspamd-Queue-Id: 18AA420D66 X-Spam-Flag: NO Rather than taking the rp_mutex in nfsd4_cleanup_open_state() (which seems counter-intuitive), take it and assign rp_owner as soon as possible. This will support a future change when nfsd4_cstate_assign_replay() might fail. Signed-off-by: NeilBrown --- fs/nfsd/nfs4state.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index ee9aa4843443..b9b3a2601675 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5333,15 +5333,15 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate, strhashval = ownerstr_hashval(&open->op_owner); oo = find_openstateowner_str(strhashval, open, clp); open->op_openowner = oo; - if (!oo) { + if (!oo) goto new_owner; - } if (!(oo->oo_flags & NFS4_OO_CONFIRMED)) { /* Replace unconfirmed owners without checking for replay. */ release_openowner(oo); open->op_openowner = NULL; goto new_owner; } + nfsd4_cstate_assign_replay(cstate, &oo->oo_owner); status = nfsd4_check_seqid(cstate, &oo->oo_owner, open->op_seqid); if (status) return status; @@ -5351,6 +5351,7 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate, if (oo == NULL) return nfserr_jukebox; open->op_openowner = oo; + nfsd4_cstate_assign_replay(cstate, &oo->oo_owner); alloc_stateid: open->op_stp = nfs4_alloc_open_stateid(clp); if (!open->op_stp) @@ -6122,12 +6123,8 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf void nfsd4_cleanup_open_state(struct nfsd4_compound_state *cstate, struct nfsd4_open *open) { - if (open->op_openowner) { - struct nfs4_stateowner *so = &open->op_openowner->oo_owner; - - nfsd4_cstate_assign_replay(cstate, so); - nfs4_put_stateowner(so); - } + if (open->op_openowner) + nfs4_put_stateowner(&open->op_openowner->oo_owner); if (open->op_file) kmem_cache_free(file_slab, open->op_file); if (open->op_stp) From patchwork Mon Mar 4 22:45:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 13581326 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 7A08F3C28 for ; Mon, 4 Mar 2024 22:47:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709592465; cv=none; b=XljgKGLymxaO4k801Kr/Jv5j410+kRcNfZN+9HdiHBNwwCtsIaZXbMnYHTLu4IxtECI7aWkv+JJ989gj8Tg/k81ha2CnJeixhePirBIhN43iCjcPR1Mj5GFjDjYS9bJI6qrK9SgkYKOVSi6O6DUXZrAh1PeZye25o10PX6zoqw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709592465; c=relaxed/simple; bh=Ojz2m/aihoD2V28qa5vcDoHUqGnvXDekCokJNqUSFo4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gtD+l+RTOj8NkS6d13D8n6snpai0u6tnFWECbJ/VIx8rU7PV4oVRa6f4hAWaZQAotDpkaYsEikr2A4+mfY2CZo9gbFsVlY0NdkGzUm7bpHLEAqhlJieUpe9TrltsfouwXu8onPys6akv8CZNSS6BpdDpBYVHKvyYcM4yu1AzZDw= 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=C4IGSP65; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=tlt1/t+V; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=C4IGSP65; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=tlt1/t+V; arc=none smtp.client-ip=195.135.223.130 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="C4IGSP65"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="tlt1/t+V"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="C4IGSP65"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="tlt1/t+V" 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-out1.suse.de (Postfix) with ESMTPS id DE50734F96; Mon, 4 Mar 2024 22:47:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709592461; 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=nq4x/pVuOAzwaezzzlCkndJfR0i/ykU8Td+cXfm1ARw=; b=C4IGSP65dq6qVv81XqRCuZPzNIkNrbSWBC3OvFeqvW+UlTM82yXo0kcXyCm8YWRaWSfcC1 FdULpIlOwcELL64XPkR9lESLtpTNDopv80MRyFknyJvnc9mS0FQGhqvoxv12CuCiJ+VkQd K1EqBCp+ORhA26Rq/jT3UHNRePvTMKg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709592461; 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=nq4x/pVuOAzwaezzzlCkndJfR0i/ykU8Td+cXfm1ARw=; b=tlt1/t+V5KfbDnFghL8+wz0NZ328wJWbHS6rZiDTBEKpzsuPohlramIXxHFdGXI9PCIihX EsSvcJOlmz26g5BQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709592461; 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=nq4x/pVuOAzwaezzzlCkndJfR0i/ykU8Td+cXfm1ARw=; b=C4IGSP65dq6qVv81XqRCuZPzNIkNrbSWBC3OvFeqvW+UlTM82yXo0kcXyCm8YWRaWSfcC1 FdULpIlOwcELL64XPkR9lESLtpTNDopv80MRyFknyJvnc9mS0FQGhqvoxv12CuCiJ+VkQd K1EqBCp+ORhA26Rq/jT3UHNRePvTMKg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709592461; 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=nq4x/pVuOAzwaezzzlCkndJfR0i/ykU8Td+cXfm1ARw=; b=tlt1/t+V5KfbDnFghL8+wz0NZ328wJWbHS6rZiDTBEKpzsuPohlramIXxHFdGXI9PCIihX EsSvcJOlmz26g5BQ== 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 4A75C13A5B; Mon, 4 Mar 2024 22:47:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id UTbHN4pP5mUrYgAAD6G6ig (envelope-from ); Mon, 04 Mar 2024 22:47:38 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia , Dai Ngo , Tom Talpey Subject: [PATCH 2/4] nfsd: perform all find_openstateowner_str calls in the one place. Date: Tue, 5 Mar 2024 09:45:22 +1100 Message-ID: <20240304224714.10370-3-neilb@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240304224714.10370-1-neilb@suse.de> References: <20240304224714.10370-1-neilb@suse.de> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: *** X-Spam-Score: 3.59 X-Spamd-Result: default: False [3.59 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_SPAM_SHORT(2.69)[0.895]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[6]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; 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:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO Currently find_openstateowner_str looks are done both in nfsd4_process_open1() and alloc_init_open_stateowner() - the latter possibly being a surprise based on its name. It would be easier to follow, and more conformant to common patterns, if the lookup was all in the one place. So replace alloc_init_open_stateowner() with find_or_alloc_open_stateowner() and use the latter in nfsd4_process_open1() without any calls to find_openstateowner_str(). This means all finds are find_openstateowner_str_locked() and find_openstateowner_str() is no longer needed. So discard find_openstateowner_str() and rename find_openstateowner_str_locked() to find_openstateowner_str(). Signed-off-by: NeilBrown --- fs/nfsd/nfs4state.c | 93 +++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 53 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index b9b3a2601675..0c1058e8cc4b 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -541,7 +541,7 @@ same_owner_str(struct nfs4_stateowner *sop, struct xdr_netobj *owner) } static struct nfs4_openowner * -find_openstateowner_str_locked(unsigned int hashval, struct nfsd4_open *open, +find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open, struct nfs4_client *clp) { struct nfs4_stateowner *so; @@ -558,18 +558,6 @@ find_openstateowner_str_locked(unsigned int hashval, struct nfsd4_open *open, return NULL; } -static struct nfs4_openowner * -find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open, - struct nfs4_client *clp) -{ - struct nfs4_openowner *oo; - - spin_lock(&clp->cl_lock); - oo = find_openstateowner_str_locked(hashval, open, clp); - spin_unlock(&clp->cl_lock); - return oo; -} - static inline u32 opaque_hashval(const void *ptr, int nbytes) { @@ -4855,34 +4843,46 @@ nfsd4_find_and_lock_existing_open(struct nfs4_file *fp, struct nfsd4_open *open) } static struct nfs4_openowner * -alloc_init_open_stateowner(unsigned int strhashval, struct nfsd4_open *open, - struct nfsd4_compound_state *cstate) +find_or_alloc_open_stateowner(unsigned int strhashval, struct nfsd4_open *open, + struct nfsd4_compound_state *cstate) { struct nfs4_client *clp = cstate->clp; - struct nfs4_openowner *oo, *ret; + struct nfs4_openowner *oo, *new = NULL; - oo = alloc_stateowner(openowner_slab, &open->op_owner, clp); - if (!oo) - return NULL; - oo->oo_owner.so_ops = &openowner_ops; - oo->oo_owner.so_is_open_owner = 1; - oo->oo_owner.so_seqid = open->op_seqid; - oo->oo_flags = 0; - if (nfsd4_has_session(cstate)) - oo->oo_flags |= NFS4_OO_CONFIRMED; - oo->oo_time = 0; - oo->oo_last_closed_stid = NULL; - INIT_LIST_HEAD(&oo->oo_close_lru); - spin_lock(&clp->cl_lock); - ret = find_openstateowner_str_locked(strhashval, open, clp); - if (ret == NULL) { - hash_openowner(oo, clp, strhashval); - ret = oo; - } else - nfs4_free_stateowner(&oo->oo_owner); + while (1) { + spin_lock(&clp->cl_lock); + oo = find_openstateowner_str(strhashval, open, clp); + if (oo && !(oo->oo_flags & NFS4_OO_CONFIRMED)) { + /* Replace unconfirmed owners without checking for replay. */ + release_openowner(oo); + oo = NULL; + } + if (oo) { + spin_unlock(&clp->cl_lock); + if (new) + nfs4_free_stateowner(&new->oo_owner); + return oo; + } + if (new) { + hash_openowner(new, clp, strhashval); + spin_unlock(&clp->cl_lock); + return new; + } + spin_unlock(&clp->cl_lock); - spin_unlock(&clp->cl_lock); - return ret; + new = alloc_stateowner(openowner_slab, &open->op_owner, clp); + if (!new) + return NULL; + new->oo_owner.so_ops = &openowner_ops; + new->oo_owner.so_is_open_owner = 1; + new->oo_owner.so_seqid = open->op_seqid; + new->oo_flags = 0; + if (nfsd4_has_session(cstate)) + new->oo_flags |= NFS4_OO_CONFIRMED; + new->oo_time = 0; + new->oo_last_closed_stid = NULL; + INIT_LIST_HEAD(&new->oo_close_lru); + } } static struct nfs4_ol_stateid * @@ -5331,28 +5331,15 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate, clp = cstate->clp; strhashval = ownerstr_hashval(&open->op_owner); - oo = find_openstateowner_str(strhashval, open, clp); + oo = find_or_alloc_open_stateowner(strhashval, open, cstate); open->op_openowner = oo; if (!oo) - goto new_owner; - if (!(oo->oo_flags & NFS4_OO_CONFIRMED)) { - /* Replace unconfirmed owners without checking for replay. */ - release_openowner(oo); - open->op_openowner = NULL; - goto new_owner; - } + return nfserr_jukebox; nfsd4_cstate_assign_replay(cstate, &oo->oo_owner); status = nfsd4_check_seqid(cstate, &oo->oo_owner, open->op_seqid); if (status) return status; - goto alloc_stateid; -new_owner: - oo = alloc_init_open_stateowner(strhashval, open, cstate); - if (oo == NULL) - return nfserr_jukebox; - open->op_openowner = oo; - nfsd4_cstate_assign_replay(cstate, &oo->oo_owner); -alloc_stateid: + open->op_stp = nfs4_alloc_open_stateid(clp); if (!open->op_stp) return nfserr_jukebox; From patchwork Mon Mar 4 22:45:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 13581327 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 5F28D3C28 for ; Mon, 4 Mar 2024 22:47:50 +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=1709592472; cv=none; b=VWvCey5ny6NgNroGCOKF6txDmFdIz9g36AIol9GJtE2aIqef4xa8UPzxD2EYspk7MrgE2k2tqeUYQJjmY6DhqF12DKtmojYBNbiRyMLsIZp8/9hHpkKIKDJR30UbYqj6+7D8qImrfyNtljsujumhlqQCmApXA5Uq+5c4A8czMyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709592472; c=relaxed/simple; bh=V1hcneIotSeCrFpbAmjAwhDv7pfINQYDCyNKY5q+0Sk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iWvaenWCpYrA8mWrE65FqNRWn0mFB+bSPxFbkTnYmsfbif626X58FDqU0Lp6m3vmSL0lWW6H1rNMwWaQvYD+8CXdGcVHd/GB/ypY38yFJXxZZNpDTYARLF2x63l4PXeaBoQxuatpX0Hjwo/HfoYiQ8m6VVGEWjOg6RF6J2Ggj1o= 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=V8shjRLM; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=pTuUrile; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=V8shjRLM; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=pTuUrile; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="V8shjRLM"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="pTuUrile"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="V8shjRLM"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="pTuUrile" 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 B6A6720D1A; Mon, 4 Mar 2024 22:47:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709592468; 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=YnqQWOAjh9G3g8aEhgj8k1CV1fcCF81WwpX6/O/o5Nc=; b=V8shjRLMFqAvfzl+QLMx0+ptXEPshSawXFAFga0KKolbQUuq/IFJa8Vw/sI5QL845djk6w gVU7yF7byBosroaHmoS5oO6Nkg1RohuoVaNsrUJG2CVBIEcxF8g74Grmi+TocpxzSKBw5k neYJp0Z426erRJbnXJaBEbC/gdQs9gQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709592468; 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=YnqQWOAjh9G3g8aEhgj8k1CV1fcCF81WwpX6/O/o5Nc=; b=pTuUrilemZAJhAG3ujGnQz+ReIs4FkYR8a9KHq0hNM4AHea9HVoZ3BP2iKJwfmd7b2mp+A xdXdxsulNnrqf+Bg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709592468; 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=YnqQWOAjh9G3g8aEhgj8k1CV1fcCF81WwpX6/O/o5Nc=; b=V8shjRLMFqAvfzl+QLMx0+ptXEPshSawXFAFga0KKolbQUuq/IFJa8Vw/sI5QL845djk6w gVU7yF7byBosroaHmoS5oO6Nkg1RohuoVaNsrUJG2CVBIEcxF8g74Grmi+TocpxzSKBw5k neYJp0Z426erRJbnXJaBEbC/gdQs9gQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709592468; 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=YnqQWOAjh9G3g8aEhgj8k1CV1fcCF81WwpX6/O/o5Nc=; b=pTuUrilemZAJhAG3ujGnQz+ReIs4FkYR8a9KHq0hNM4AHea9HVoZ3BP2iKJwfmd7b2mp+A xdXdxsulNnrqf+Bg== 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 1F8D513A5B; Mon, 4 Mar 2024 22:47:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id iepHLZFP5mU0YgAAD6G6ig (envelope-from ); Mon, 04 Mar 2024 22:47:45 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia , Dai Ngo , Tom Talpey Subject: [PATCH 3/4] nfsd: replace rp_mutex to avoid deadlock in move_to_close_lru() Date: Tue, 5 Mar 2024 09:45:23 +1100 Message-ID: <20240304224714.10370-4-neilb@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240304224714.10370-1-neilb@suse.de> References: <20240304224714.10370-1-neilb@suse.de> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: *** X-Spam-Score: 3.59 X-Spamd-Result: default: False [3.59 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_SPAM_SHORT(2.69)[0.896]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[6]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; 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:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO move_to_close_lru() waits for sc_count to become zero while holding rp_mutex. This can deadlock if another thread holds a reference and is waiting for rp_mutex. By the time we get to move_to_close_lru() the openowner is unhashed and cannot be found any more. So code waiting for the mutex can safely retry the lookup if move_to_close_lru() has started. So change rp_mutex to an atomic_t with three states: RP_UNLOCK - state is still hashed, not locked for reply RP_LOCKED - state is still hashed, is locked for reply RP_UNHASHED - state is not hashed, no code can get a lock. Use wait_var_event() to wait for either a lock, or for the owner to be unhashed. In the latter case, retry the lookup. Signed-off-by: NeilBrown --- fs/nfsd/nfs4state.c | 43 ++++++++++++++++++++++++++++++++++++------- fs/nfsd/state.h | 2 +- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 0c1058e8cc4b..52838db0c46e 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4639,21 +4639,37 @@ nfsd4_init_leases_net(struct nfsd_net *nn) atomic_set(&nn->nfsd_courtesy_clients, 0); } +enum rp_lock { + RP_UNLOCKED, + RP_LOCKED, + RP_UNHASHED, +}; + static void init_nfs4_replay(struct nfs4_replay *rp) { rp->rp_status = nfserr_serverfault; rp->rp_buflen = 0; rp->rp_buf = rp->rp_ibuf; - mutex_init(&rp->rp_mutex); + atomic_set(&rp->rp_locked, RP_UNLOCKED); } -static void nfsd4_cstate_assign_replay(struct nfsd4_compound_state *cstate, - struct nfs4_stateowner *so) +static int nfsd4_cstate_assign_replay(struct nfsd4_compound_state *cstate, + struct nfs4_stateowner *so) { if (!nfsd4_has_session(cstate)) { - mutex_lock(&so->so_replay.rp_mutex); + /* + * rp_locked is an open-coded mutex which is unlocked in + * nfsd4_cstate_clear_replay() or aborted in + * move_to_close_lru(). + */ + wait_var_event(&so->so_replay.rp_locked, + atomic_cmpxchg(&so->so_replay.rp_locked, + RP_UNLOCKED, RP_LOCKED) != RP_LOCKED); + if (atomic_read(&so->so_replay.rp_locked) == RP_UNHASHED) + return -EAGAIN; cstate->replay_owner = nfs4_get_stateowner(so); } + return 0; } void nfsd4_cstate_clear_replay(struct nfsd4_compound_state *cstate) @@ -4662,7 +4678,8 @@ void nfsd4_cstate_clear_replay(struct nfsd4_compound_state *cstate) if (so != NULL) { cstate->replay_owner = NULL; - mutex_unlock(&so->so_replay.rp_mutex); + atomic_set(&so->so_replay.rp_locked, RP_UNLOCKED); + wake_up_var(&so->so_replay.rp_locked); nfs4_put_stateowner(so); } } @@ -4958,7 +4975,11 @@ move_to_close_lru(struct nfs4_ol_stateid *s, struct net *net) * Wait for the refcount to drop to 2. Since it has been unhashed, * there should be no danger of the refcount going back up again at * this point. + * Some threads with a reference might be waiting for rp_locked, + * so tell them to stop waiting. */ + atomic_set(&oo->oo_owner.so_replay.rp_locked, RP_UNHASHED); + wake_up_var(&oo->oo_owner.so_replay.rp_locked); wait_event(close_wq, refcount_read(&s->st_stid.sc_count) == 2); release_all_access(s); @@ -5331,11 +5352,15 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate, clp = cstate->clp; strhashval = ownerstr_hashval(&open->op_owner); +retry: oo = find_or_alloc_open_stateowner(strhashval, open, cstate); open->op_openowner = oo; if (!oo) return nfserr_jukebox; - nfsd4_cstate_assign_replay(cstate, &oo->oo_owner); + if (nfsd4_cstate_assign_replay(cstate, &oo->oo_owner) == -EAGAIN) { + nfs4_put_stateowner(&oo->oo_owner); + goto retry; + } status = nfsd4_check_seqid(cstate, &oo->oo_owner, open->op_seqid); if (status) return status; @@ -7175,12 +7200,16 @@ nfs4_preprocess_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid, trace_nfsd_preprocess(seqid, stateid); *stpp = NULL; +retry: status = nfsd4_lookup_stateid(cstate, stateid, typemask, statusmask, &s, nn); if (status) return status; stp = openlockstateid(s); - nfsd4_cstate_assign_replay(cstate, stp->st_stateowner); + if (nfsd4_cstate_assign_replay(cstate, stp->st_stateowner) == -EAGAIN) { + nfs4_put_stateowner(stp->st_stateowner); + goto retry; + } status = nfs4_seqid_op_checks(cstate, stateid, seqid, stp); if (!status) diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 01c6f3445646..0400441c87c1 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -486,7 +486,7 @@ struct nfs4_replay { unsigned int rp_buflen; char *rp_buf; struct knfsd_fh rp_openfh; - struct mutex rp_mutex; + atomic_t rp_locked; char rp_ibuf[NFSD4_REPLAY_ISIZE]; }; From patchwork Mon Mar 4 22:45:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 13581328 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 3A3B83C28 for ; Mon, 4 Mar 2024 22:47:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709592478; cv=none; b=WDbyc1/buLhMM2v6gNd1FolBdNnvtutZgkS5TtU6uFUanwN6Y5OU6iMdkqPFdeK9jV9inTY8sWBoPmUIUDXbnB3Wphu/2XVg5GgDSDSPG4nozoNv0ov5XuflhoqqLFJbOcZ9xEFKDd8QB/2pIhtF3Q47YgWbdJ45WsCxfq6KmiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709592478; c=relaxed/simple; bh=wm6k4oTysTrJoRcKvgWjRD6LEyaSk8e5XrdE00SW3ew=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rI8L+Yi74pzLHjHxJu02TgihxfnZzGhkKvdI4EfEAN0OAnc6xau6W5KX6s1WJgNqyG+9guig1BEkeuS0HSI3AYjn0Jx0Tkq6ZzFilvSvWagW/gOkWz6x0Eu2ci0PJXt8upKZ/xLsmpIodYeETxR9haDOWoSc41jjW6n1S23XCNI= 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=hAQOX0Nk; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=h6VdxyJG; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=hAQOX0Nk; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=h6VdxyJG; arc=none smtp.client-ip=195.135.223.130 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="hAQOX0Nk"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="h6VdxyJG"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="hAQOX0Nk"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="h6VdxyJG" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out1.suse.de (Postfix) with ESMTPS id 91F3734F96; Mon, 4 Mar 2024 22:47:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709592475; 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=0eoIE+UN4zBuhf6EatwmMK9QXKjrLqJjK1+U2+HjYP0=; b=hAQOX0NkOhWq0n7U/bGj3fnSGMIwXXYvv25OWqR4f8sCu1el1u74jZux5eB3ii6CeU5AIW 7WZPx6N3+IY3PkvIhd7qm2POA2hIjnsxmTjdMPSq1ns8hvwL7MwNwaXthTjAqflptL0MAq WtEW7/37b9GjulM5GMZnXFFAvB6UMXo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709592475; 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=0eoIE+UN4zBuhf6EatwmMK9QXKjrLqJjK1+U2+HjYP0=; b=h6VdxyJG9/cjUisORrdjP2SVX76CK8tEzbqBZS5rM6R+5FOOu2e/FafaxtHcj1fuHM87Eb dz4lywZM98NTpWAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709592475; 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=0eoIE+UN4zBuhf6EatwmMK9QXKjrLqJjK1+U2+HjYP0=; b=hAQOX0NkOhWq0n7U/bGj3fnSGMIwXXYvv25OWqR4f8sCu1el1u74jZux5eB3ii6CeU5AIW 7WZPx6N3+IY3PkvIhd7qm2POA2hIjnsxmTjdMPSq1ns8hvwL7MwNwaXthTjAqflptL0MAq WtEW7/37b9GjulM5GMZnXFFAvB6UMXo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709592475; 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=0eoIE+UN4zBuhf6EatwmMK9QXKjrLqJjK1+U2+HjYP0=; b=h6VdxyJG9/cjUisORrdjP2SVX76CK8tEzbqBZS5rM6R+5FOOu2e/FafaxtHcj1fuHM87Eb dz4lywZM98NTpWAg== 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 EEA9713A5B; Mon, 4 Mar 2024 22:47:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id HRNGJJhP5mU5YgAAD6G6ig (envelope-from ); Mon, 04 Mar 2024 22:47:52 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia , Dai Ngo , Tom Talpey Subject: [PATCH 4/4] nfsd: drop st_mutex_mutex before calling move_to_close_lru() Date: Tue, 5 Mar 2024 09:45:24 +1100 Message-ID: <20240304224714.10370-5-neilb@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240304224714.10370-1-neilb@suse.de> References: <20240304224714.10370-1-neilb@suse.de> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=hAQOX0Nk; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=h6VdxyJG X-Spamd-Result: default: False [0.69 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[6]; DWL_DNSWL_LOW(-1.00)[suse.de:dkim]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[oracle.com:email,suse.de:dkim,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Score: 0.69 X-Rspamd-Queue-Id: 91F3734F96 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Bar: / move_to_close_lru() is currently called with ->st_mutex held. This can lead to a deadlock as move_to_close_lru() waits for sc_count to drop to 2, and some threads holding a reference might be waiting for the mutex. These references will never be dropped so sc_count will never reach 2. There can be no harm in dropping ->st_mutex before move_to_close_lru() because the only place that takes the mutex is nfsd4_lock_ol_stateid(), and it quickly aborts if sc_type is NFS4_CLOSED_STID, which it will be before move_to_close_lru() is called. See also https://lore.kernel.org/lkml/4dd1fe21e11344e5969bb112e954affb@jd.com/T/ where this problem was raised but not successfully resolved. Signed-off-by: NeilBrown Reviewed-by: Jeff Layton Signed-off-by: Chuck Lever --- fs/nfsd/nfs4state.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 52838db0c46e..13cb91d704fd 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -7351,7 +7351,7 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp, return status; } -static void nfsd4_close_open_stateid(struct nfs4_ol_stateid *s) +static bool nfsd4_close_open_stateid(struct nfs4_ol_stateid *s) { struct nfs4_client *clp = s->st_stid.sc_client; bool unhashed; @@ -7368,11 +7368,11 @@ static void nfsd4_close_open_stateid(struct nfs4_ol_stateid *s) list_for_each_entry(stp, &reaplist, st_locks) nfs4_free_cpntf_statelist(clp->net, &stp->st_stid); free_ol_stateid_reaplist(&reaplist); + return false; } else { spin_unlock(&clp->cl_lock); free_ol_stateid_reaplist(&reaplist); - if (unhashed) - move_to_close_lru(s, clp->net); + return unhashed; } } @@ -7388,6 +7388,7 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfs4_ol_stateid *stp; struct net *net = SVC_NET(rqstp); struct nfsd_net *nn = net_generic(net, nfsd_net_id); + bool need_move_to_close_list; dprintk("NFSD: nfsd4_close on file %pd\n", cstate->current_fh.fh_dentry); @@ -7412,8 +7413,10 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, */ nfs4_inc_and_copy_stateid(&close->cl_stateid, &stp->st_stid); - nfsd4_close_open_stateid(stp); + need_move_to_close_list = nfsd4_close_open_stateid(stp); mutex_unlock(&stp->st_mutex); + if (need_move_to_close_list) + move_to_close_lru(stp, net); /* v4.1+ suggests that we send a special stateid in here, since the * clients should just ignore this anyway. Since this is not useful