linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvmet-tcp: fixup hang in nvmet_tcp_listen_data_ready()
@ 2025-08-18  9:32 hare
  2025-08-19  4:46 ` Yi Zhang
  0 siblings, 1 reply; 2+ messages in thread
From: hare @ 2025-08-18  9:32 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Sagi Grimberg, Keith Busch, linux-nvme, Hannes Reinecke, Yi Zhang

From: Hannes Reinecke <hare@kernel.org>

When the socket is closed while in TCP_LISTEN a callback is run to
flush all outstanding packets, which in turns calls
nvmet_tcp_listen_data_ready() with the sk_callback_lock held.
So we need to check if we are in TCP_LISTEN before attempting
to get the sk_callback_lock() to avoid a deadlock.

Signed-off-by: Hannes Reinecke <hare@kernel.org>
Tested-by:  Yi Zhang <yi.zhang@redhat.com>
---
 drivers/nvme/target/tcp.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
index 470bf37e5a63..2e9a3e698b70 100644
--- a/drivers/nvme/target/tcp.c
+++ b/drivers/nvme/target/tcp.c
@@ -1992,14 +1992,13 @@ static void nvmet_tcp_listen_data_ready(struct sock *sk)
 
 	trace_sk_data_ready(sk);
 
+	if (sk->sk_state != TCP_LISTEN)
+		return;
+
 	read_lock_bh(&sk->sk_callback_lock);
 	port = sk->sk_user_data;
-	if (!port)
-		goto out;
-
-	if (sk->sk_state == TCP_LISTEN)
+	if (port)
 		queue_work(nvmet_wq, &port->accept_work);
-out:
 	read_unlock_bh(&sk->sk_callback_lock);
 }
 
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] nvmet-tcp: fixup hang in nvmet_tcp_listen_data_ready()
  2025-08-18  9:32 [PATCH] nvmet-tcp: fixup hang in nvmet_tcp_listen_data_ready() hare
@ 2025-08-19  4:46 ` Yi Zhang
  0 siblings, 0 replies; 2+ messages in thread
From: Yi Zhang @ 2025-08-19  4:46 UTC (permalink / raw)
  To: hare; +Cc: Christoph Hellwig, Sagi Grimberg, Keith Busch, linux-nvme

Hi Hannes

Thanks for the patch fix.
Could you also add the bug report link to this patch so that we can
get more info, like the reproducer?

On Mon, Aug 18, 2025 at 5:38 PM <hare@kernel.org> wrote:
>
> From: Hannes Reinecke <hare@kernel.org>
>
> When the socket is closed while in TCP_LISTEN a callback is run to
> flush all outstanding packets, which in turns calls
> nvmet_tcp_listen_data_ready() with the sk_callback_lock held.
> So we need to check if we are in TCP_LISTEN before attempting
> to get the sk_callback_lock() to avoid a deadlock.
>
> Signed-off-by: Hannes Reinecke <hare@kernel.org>
> Tested-by:  Yi Zhang <yi.zhang@redhat.com>
> ---
>  drivers/nvme/target/tcp.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
> index 470bf37e5a63..2e9a3e698b70 100644
> --- a/drivers/nvme/target/tcp.c
> +++ b/drivers/nvme/target/tcp.c
> @@ -1992,14 +1992,13 @@ static void nvmet_tcp_listen_data_ready(struct sock *sk)
>
>         trace_sk_data_ready(sk);
>
> +       if (sk->sk_state != TCP_LISTEN)
> +               return;
> +
>         read_lock_bh(&sk->sk_callback_lock);
>         port = sk->sk_user_data;
> -       if (!port)
> -               goto out;
> -
> -       if (sk->sk_state == TCP_LISTEN)
> +       if (port)
>                 queue_work(nvmet_wq, &port->accept_work);
> -out:
>         read_unlock_bh(&sk->sk_callback_lock);
>  }
>
> --
> 2.43.0
>


-- 
Best Regards,
  Yi Zhang



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-19  4:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-18  9:32 [PATCH] nvmet-tcp: fixup hang in nvmet_tcp_listen_data_ready() hare
2025-08-19  4:46 ` Yi Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).