nvmet-tcp: fixup hang in nvmet_tcp_listen_data_ready()
Subsystems (2)
PATCH 1/1 nvmet-tcp: fixup hang in nvmet_tcp_listen_data_ready()
From: Hannes Reinecke <[email protected]>
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.
--- drivers/nvme/target/tcp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/nvme/target/tcp.c +4 -5
@@ -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); }
Signature · 1 line
2.43.0
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?
Quoted 41 lines · On Mon, Aug 18, 2025 at 5:38 PM <[email protected]> wrote:
From: Hannes Reinecke <[email protected]>
When the socket is closed while in
TCP_LISTENa callback is run to flush all outstanding packets, which in turns callsnvmet_tcp_listen_data_ready()with thesk_callback_lockheld. So we need to check if we are inTCP_LISTENbefore attempting to get thesk_callback_lock()to avoid a deadlock.Signed-off-by Hannes Reinecke <[email protected]>Tested-by Yi Zhang <[email protected]>--- drivers/nvme/target/tcp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/nvme/target/tcp.c +4
-6@@ -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
Signature · 2 lines
Best Regards, Yi Zhang
Quoted 7 lines · hare
From: Hannes Reinecke <[email protected]>
When the socket is closed while in
TCP_LISTENa callback is run to flush all outstanding packets, which in turns callsnvmet_tcp_listen_data_ready()with thesk_callback_lockheld. So we need to check if we are inTCP_LISTENbefore attempting to get thesk_callback_lock()to avoid a deadlock.
Ping, I guess this patch has been forgotten
Maurizio
Quoted 30 lines
Signed-off-by Hannes Reinecke <[email protected]>Tested-by Yi Zhang <[email protected]>--- drivers/nvme/target/tcp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/nvme/target/tcp.c +4
-5@@ -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); }
Quoted 4 lines · Maurizio Lombardi
Quoted 2 lines · hare
From: Hannes Reinecke <[email protected]>
Quoted 9 lines
Quoted 5 lines
When the socket is closed while in
TCP_LISTENa callback is run to flush all outstanding packets, which in turns callsnvmet_tcp_listen_data_ready()with thesk_callback_lockheld. So we need to check if we are inTCP_LISTENbefore attempting to get thesk_callback_lock()to avoid a deadlock.Ping, I guess this patch has been forgotten
Here is the patch fixed bug report:
https://lore.kernel.org/linux-nvme/CAHj4cs-zu7eVB78yUpFjVe2UqMWFkLk8p+DaS3qj+uiGCXBAoA@mail.gmail.com/
Quoted 34 lines
Maurizio
Quoted 30 lines
Signed-off-by Hannes Reinecke <[email protected]>Tested-by Yi Zhang <[email protected]>--- drivers/nvme/target/tcp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/nvme/target/tcp.c +4
-5@@ -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); }
Signature · 2 lines
Best Regards, Yi Zhang
Sagi? Could you review this please?
Thanks,
Maurizio
po 18. 8. 2025 v 15:41 odesílatel <[email protected]> napsal:
Quoted 42 lines
From: Hannes Reinecke <[email protected]>
When the socket is closed while in
TCP_LISTENa callback is run to flush all outstanding packets, which in turns callsnvmet_tcp_listen_data_ready()with thesk_callback_lockheld. So we need to check if we are inTCP_LISTENbefore attempting to get thesk_callback_lock()to avoid a deadlock.Signed-off-by Hannes Reinecke <[email protected]>Tested-by Yi Zhang <[email protected]>--- drivers/nvme/target/tcp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/nvme/target/tcp.c +4
-6@@ -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
This looks good,
Quoted 7 lines · On Mon, Aug 18, 2025 at 11:32:45AM +0200, [email protected] wrote:
From: Hannes Reinecke <[email protected]>
When the socket is closed while in
TCP_LISTENa callback is run to flush all outstanding packets, which in turns callsnvmet_tcp_listen_data_ready()with thesk_callback_lockheld. So we need to check if we are inTCP_LISTENbefore attempting to get thesk_callback_lock()to avoid a deadlock.
Thanks, applied to nvme-6.19.