From patchwork Fri Aug 30 07:03:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 13784391 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 96DC915442F for ; Fri, 30 Aug 2024 07:07:19 +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=1725001641; cv=none; b=YJGw2oHcyHGefLXqwpblswO2PO5hI1LfruKUARIeDGPDYX2WM2glbz3wI5F/ncKfHp4PQrdUVSOBwDD7bnd1LuQDNheGyi1psAOCMHf87uvK4gdBXfZTGmu0DTTnDz69NzKif6UhEGjz9L4JKnl0WDJx7JPSyL0kUR4qes4N4P8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725001641; c=relaxed/simple; bh=exfot3F62PKOwBoQ9/teqmxe83yyE2XpNqy02Lcm3yo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jX46n5N0wokytk02NXWbebuQWPhhOCQxX/uzbzLf6ZSeQFkre8Qu4Ex1t6U4w/1pifF5pM0dSbJbZQ1Y/ygaLYn6b20uzGf+zW1iFetOQ09pNh1U49ifrX2F1U7riyn169Q3kkttHDC+jE/sqPs9cFWxcnj6cF9MAGpL6DKASfI= 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=KsGcEFhW; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=txOczBw7; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=KsGcEFhW; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=txOczBw7; 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="KsGcEFhW"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="txOczBw7"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="KsGcEFhW"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="txOczBw7" Received: from imap1.dmz-prg2.suse.org (unknown [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 B54171F7A6; Fri, 30 Aug 2024 07:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725001637; 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=lRs3bOKCCLfqMCIpV5OncLVAksUc75DeLbCf3ohIa5A=; b=KsGcEFhWCUqRe6U7aLrxC98/Bu06lmrFu+jpukqC2LI9WTiedW1Cy6ndBl+LOW23XT2Utu oDWLIwQBowQpAxEMcycb9/XJYH0Djy8jhWEFsSzPOrwl82eNYlizcL9BphNyRLRN8oWP1S ybcns6jn050dmSZt2AWFj8PZNzi5+co= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725001637; 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=lRs3bOKCCLfqMCIpV5OncLVAksUc75DeLbCf3ohIa5A=; b=txOczBw7rcNsnfDBg4OwRsDwVjfydYowDbPv4zFhLnQbpL4tAK7CqL28+X1utfCsEZegOx w8pR9fW++FkRlKCQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725001637; 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=lRs3bOKCCLfqMCIpV5OncLVAksUc75DeLbCf3ohIa5A=; b=KsGcEFhWCUqRe6U7aLrxC98/Bu06lmrFu+jpukqC2LI9WTiedW1Cy6ndBl+LOW23XT2Utu oDWLIwQBowQpAxEMcycb9/XJYH0Djy8jhWEFsSzPOrwl82eNYlizcL9BphNyRLRN8oWP1S ybcns6jn050dmSZt2AWFj8PZNzi5+co= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725001637; 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=lRs3bOKCCLfqMCIpV5OncLVAksUc75DeLbCf3ohIa5A=; b=txOczBw7rcNsnfDBg4OwRsDwVjfydYowDbPv4zFhLnQbpL4tAK7CqL28+X1utfCsEZegOx w8pR9fW++FkRlKCQ== 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 712DB13A44; Fri, 30 Aug 2024 07:07:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id r0oICqRv0WZ/XAAAD6G6ig (envelope-from ); Fri, 30 Aug 2024 07:07:16 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org Subject: [PATCH 1/2] nfsd: use clear_and_wake_up_bit() Date: Fri, 30 Aug 2024 17:03:16 +1000 Message-ID: <20240830070653.7326-2-neilb@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240830070653.7326-1-neilb@suse.de> References: <20240830070653.7326-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-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Level: nfsd has two places that open-code clear_and_wake_up_bit(). One has the required memory barriers. The other does not. Change both to use clear_and_wake_up_bit() so with have the barriers without the noise. Signed-off-by: NeilBrown --- fs/nfsd/nfs4recover.c | 5 +---- fs/nfsd/nfs4state.c | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c index 67d8673a9391..b10cfb217fa2 100644 --- a/fs/nfsd/nfs4recover.c +++ b/fs/nfsd/nfs4recover.c @@ -1895,10 +1895,7 @@ nfsd4_cltrack_upcall_lock(struct nfs4_client *clp) static void nfsd4_cltrack_upcall_unlock(struct nfs4_client *clp) { - smp_mb__before_atomic(); - clear_bit(NFSD4_CLIENT_UPCALL_LOCK, &clp->cl_flags); - smp_mb__after_atomic(); - wake_up_bit(&clp->cl_flags, NFSD4_CLIENT_UPCALL_LOCK); + clear_and_wake_up_bit(&clp->cl_flags, NFSD4_CLIENT_UPCALL_LOCK); } static void diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index b67f151837c1..3f85575ee0db 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -3076,8 +3076,7 @@ nfsd4_cb_getattr_release(struct nfsd4_callback *cb) container_of(ncf, struct nfs4_delegation, dl_cb_fattr); nfs4_put_stid(&dp->dl_stid); - clear_bit(CB_GETATTR_BUSY, &ncf->ncf_cb_flags); - wake_up_bit(&ncf->ncf_cb_flags, CB_GETATTR_BUSY); + clear_and_wake_up_bit(&ncf->ncf_cb_flags, CB_GETATTR_BUSY); } static const struct nfsd4_callback_ops nfsd4_cb_recall_any_ops = { From patchwork Fri Aug 30 07:03:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 13784392 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 4037015217F for ; Fri, 30 Aug 2024 07:07:28 +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=1725001649; cv=none; b=dH+vFlp5IhramIssq/y8ybUpnnhnysfim7ynd2t9zquxR5H+TO1vYXMx4A+a9JyWyUP4CsR41gRdJgGOzD91j+wAGCek6Nv49XU7KlrKD9RjGqweQl1U4CSGKoWod1+/ei4uYKH3ESpPd31cwh3fPMrmWg8eKpKZ8dUKaoMyYZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725001649; c=relaxed/simple; bh=PBUTJen2Q4DVHp52PjELVYdcjX5lCDjY+VBSg9ydpwM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ts67FccsCvH6XTYS+amnbAICo4//nRH6FkKC85/UCI9CFcAw44/D84OxIv/EmRZ1p6hmx+zoHepfDh+J5g/dfGSzdktrLKmF3LyZbpArm07xxiWt+Vez6RvXvtV/++scDuS+tK6U4tjTlq2eLyEJrgHQ2RgoaMEiV+Hrrau3jw8= 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=of2lln6O; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Po/ACOgJ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=of2lln6O; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Po/ACOgJ; 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="of2lln6O"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Po/ACOgJ"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="of2lln6O"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Po/ACOgJ" 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 635FF1F7A6; Fri, 30 Aug 2024 07:07:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725001646; 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=xP6QlC6xdlKSppJOB39Ms9+EaaX+eN2/jBiAoAOlUxA=; b=of2lln6OnQowBH1EIlVg/MzkBuPeeUzB3ZomlMC9fQnomgrRugEn40lN5GgFBQGIP7Vi4T pSaTMWdfxKUaqxSHwrXV7Xxh5/tASQ6rY+PqYtuVtx7UMPagvQuQxbqiVxwTWdvrOiSdKr on1XEln99EgFTl36uM1km3gWg7ov3qQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725001646; 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=xP6QlC6xdlKSppJOB39Ms9+EaaX+eN2/jBiAoAOlUxA=; b=Po/ACOgJ/nIB69rfhZR0ZmmYy0lZ/vFTAz6oNi9MLB/8TIJ/J7KZS9sZvXRXg5RQX/4WUO rY6+Jmx4u0AoytBg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=of2lln6O; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="Po/ACOgJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725001646; 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=xP6QlC6xdlKSppJOB39Ms9+EaaX+eN2/jBiAoAOlUxA=; b=of2lln6OnQowBH1EIlVg/MzkBuPeeUzB3ZomlMC9fQnomgrRugEn40lN5GgFBQGIP7Vi4T pSaTMWdfxKUaqxSHwrXV7Xxh5/tASQ6rY+PqYtuVtx7UMPagvQuQxbqiVxwTWdvrOiSdKr on1XEln99EgFTl36uM1km3gWg7ov3qQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725001646; 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=xP6QlC6xdlKSppJOB39Ms9+EaaX+eN2/jBiAoAOlUxA=; b=Po/ACOgJ/nIB69rfhZR0ZmmYy0lZ/vFTAz6oNi9MLB/8TIJ/J7KZS9sZvXRXg5RQX/4WUO rY6+Jmx4u0AoytBg== 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 307DE13A44; Fri, 30 Aug 2024 07:07:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id WRDYNaxv0WaFXAAAD6G6ig (envelope-from ); Fri, 30 Aug 2024 07:07:24 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org Subject: [PATCH 2/2] nfsd: avoid races with wake_up_var() Date: Fri, 30 Aug 2024 17:03:17 +1000 Message-ID: <20240830070653.7326-3-neilb@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240830070653.7326-1-neilb@suse.de> References: <20240830070653.7326-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-Rspamd-Queue-Id: 635FF1F7A6 X-Spam-Level: X-Spamd-Result: default: False [-5.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[suse.de:+]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,suse.de:mid] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -5.01 X-Spam-Flag: NO wake_up_var() needs a barrier after the important change is made in the var and before wake_up_var() is called, else it is possible that a wake up won't be sent when it should. In each case here the var is changed in an "atomic" manner, so smb_mb__after_atomic() is sufficient. In one case the important change (removing the lease) is performed *after* the wake_up, which is backwards. The code survives in part because the wait_var_event is given a timeout. This patch adds the required barriers and calls destroy_delegation() *before* waking any threads waiting for the delegation to be destroyed. Signed-off-by: NeilBrown --- fs/nfsd/nfs4state.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 3f85575ee0db..10e3a46289a1 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4700,6 +4700,7 @@ void nfsd4_cstate_clear_replay(struct nfsd4_compound_state *cstate) if (so != NULL) { cstate->replay_owner = NULL; atomic_set(&so->so_replay.rp_locked, RP_UNLOCKED); + smb_mb__after_atomic(); wake_up_var(&so->so_replay.rp_locked); nfs4_put_stateowner(so); } @@ -5000,6 +5001,7 @@ move_to_close_lru(struct nfs4_ol_stateid *s, struct net *net) * so tell them to stop waiting. */ atomic_set(&oo->oo_owner.so_replay.rp_locked, RP_UNHASHED); + smb_mb__after_atomic(); wake_up_var(&oo->oo_owner.so_replay.rp_locked); wait_event(close_wq, refcount_read(&s->st_stid.sc_count) == 2); @@ -7469,8 +7471,9 @@ nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto put_stateid; trace_nfsd_deleg_return(stateid); - wake_up_var(d_inode(cstate->current_fh.fh_dentry)); destroy_delegation(dp); + smb_mb__after_atomic(); + wake_up_var(d_inode(cstate->current_fh.fh_dentry)); put_stateid: nfs4_put_stid(&dp->dl_stid); out: