mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Kal Cutter Conley <kalcutterc@nvidia.com>,
	Trond Myklebust	 <trondmy@kernel.org>,
	Anna Schumaker <anna@kernel.org>, Chuck Lever	 <cel@kernel.org>,
	NeilBrown <neil@brown.name>,
	Olga Kornievskaia	 <okorniev@redhat.com>,
	Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>
Cc: linux-nfs@vger.kernel.org, netdev@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] sunrpc: fix lost wakeups when stopping service threads
Date: Tue, 03 Nov 2026 06:38:02 -0500	[thread overview]
Message-ID: <e5355fe72c4250e899fdbe26490596af399ad473.camel@kernel.org> (raw)
In-Reply-To: <20261102225358.414367-1-kalcutterc@nvidia.com>

On Mon, 2026-11-02 at 23:53 +0100, Kal Cutter Conley wrote:
> Stopping NFS can leave rpc.nfsd 0 in an uninterruptible wait with
> this stack:
> 
>   svc_stop_kthreads [sunrpc]
>   svc_set_num_threads [sunrpc]
>   nfsd_svc [nfsd]
>   write_threads [nfsd]
>   nfsctl_transaction_write [nfsd]
> 
> SP_NEED_VICTIM and SP_VICTIM_REMAINS remain set while all remaining
> nfsd threads sleep in svc_recv() and none has RQ_VICTIM set.
> 
> The stop request is published with unordered set_bit() operations.
> svc_pool_wake_idle_thread() checks the idle list and task state before
> calling wake_up_process(). If it sees an empty list or TASK_RUNNING,
> it skips the wakeup and its memory barrier. The requester can therefore
> miss a sleeping worker while that worker misses the stop request.
> 
> Use smp_mb__after_atomic() after the flag updates in
> svc_stop_kthreads() and svc_wake_up() to order work publication before
> both lockless checks, even when no wakeup occurs. Pair with
> set_current_state() and llist_add() in svc_thread_wait_for_work(), so
> the worker observes the pending work or the requester observes the
> idle worker and wakes it.
> 
> Fixes: 60749cbe3d8a ("sunrpc: change sp_nrthreads from atomic_t to unsigned int.")
> Signed-off-by: Kal Cutter Conley <kalcutterc@nvidia.com>
> ---
> Changes in v2:
> - Move the barrier into svc_stop_kthreads() and svc_wake_up(), using
>   smp_mb__after_atomic(). This avoids adding a redundant barrier on the
>   transport enqueue path.
> 
> v1: https://lore.kernel.org/r/20261030130629.103716-1-kalcutterc@nvidia.com
> 
>  net/sunrpc/svc.c      | 7 +++++++
>  net/sunrpc/svc_xprt.c | 5 +++++
>  2 files changed, 12 insertions(+)
> 
> diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
> index af8d87c1de83..76232774646c 100644
> --- a/net/sunrpc/svc.c
> +++ b/net/sunrpc/svc.c
> @@ -29,6 +29,8 @@
>  #include <linux/sunrpc/clnt.h>
>  #include <linux/sunrpc/bc_xprt.h>
>  
> +#include <asm/barrier.h>
> +

As Neil said, this is probably not needed.

>  #include <trace/events/sunrpc.h>
>  
>  #include "fail.h"
> @@ -784,6 +786,11 @@ svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
>  	do {
>  		set_bit(SP_VICTIM_REMAINS, &pool->sp_flags);
>  		set_bit(SP_NEED_VICTIM, &pool->sp_flags);
> +		/*
> +		 * Order flag updates before the idle list and task state checks.
> +		 * Pairs with the barriers in svc_thread_wait_for_work().
> +		 */
> +		smp_mb__after_atomic();
>  		svc_pool_wake_idle_thread(pool);
>  		wait_on_bit(&pool->sp_flags, SP_VICTIM_REMAINS, TASK_IDLE);
>  		nrservs++;
> diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
> index 076c624fe675..868e3da57b6c 100644
> --- a/net/sunrpc/svc_xprt.c
> +++ b/net/sunrpc/svc_xprt.c
> @@ -632,6 +632,11 @@ void svc_wake_up(struct svc_serv *serv)
>  	struct svc_pool *pool = &serv->sv_pools[0];
>  
>  	set_bit(SP_TASK_PENDING, &pool->sp_flags);
> +	/*
> +	 * Order flag updates before the idle list and task state checks.
> +	 * Pairs with the barriers in svc_thread_wait_for_work().
> +	 */
> +	smp_mb__after_atomic();
>  	svc_pool_wake_idle_thread(pool);
>  }
>  EXPORT_SYMBOL_GPL(svc_wake_up);
> 
> base-commit: 2d3259f652bb0f1d137ccabecac6763da05064ec

Reviewed-by: Jeff Layton <jlayton@kernel.org>

  parent reply	other threads:[~2026-11-03 11:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 13:06 [PATCH] " Kal Cutter Conley
2026-10-30 21:43 ` Chuck Lever
2026-10-30 22:45 ` NeilBrown
2026-10-31  0:46   ` Hillf Danton
2026-10-31 21:49     ` NeilBrown
2026-10-31 22:57       ` Hillf Danton
2026-10-31 14:01   ` Chuck Lever
2026-11-02 22:53 ` [PATCH v2] " Kal Cutter Conley
2026-11-03  0:06   ` NeilBrown
2026-11-03 11:38   ` Jeff Layton [this message]
2026-11-03 12:19 ` [PATCH v3] " Kal Cutter Conley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e5355fe72c4250e899fdbe26490596af399ad473.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=Dai.Ngo@oracle.com \
    --cc=anna@kernel.org \
    --cc=cel@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kalcutterc@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=netdev@vger.kernel.org \
    --cc=okorniev@redhat.com \
    --cc=pabeni@redhat.com \
    --cc=tom@talpey.com \
    --cc=trondmy@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®