Linux s390 Architecture development
 help / color / mirror / Atom feed
* [PATCH net] net/smc: drop the abort_work reference when the work is cancelled
@ 2026-08-06  8:15 Hidayath Khan
  2026-08-06  9:20 ` Dust Li
  2026-08-07  8:16 ` sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Hidayath Khan @ 2026-08-06  8:15 UTC (permalink / raw)
  To: alibuda, dust.li, sidraya, mjambigi, andrew+netdev
  Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, horms, pasic,
	hidayath, linux-s390, netdev

The schedulers of conn->abort_work hand a socket reference to the work
item and rely on it to give the reference back:

        sock_hold(&smc->sk); /* sock_put in abort_work */
        if (!queue_work(smc_close_wq, &conn->abort_work))
                sock_put(&smc->sk);

The queue_work() failure case is handled, but the cancellation case is
not. smc_conn_free() cancels a still-pending abort_work:

        if (current_work() != &conn->abort_work)
                cancel_work_sync(&conn->abort_work);

and discards the return value.  When cancel_work_sync() returns true the
work was queued but had not started, so smc_conn_abort_work() never runs
and its sock_put() never happens.  The reference is lost.

As in smc_switch_conns(), a leaked sk_refcnt means the smc_sock is never
destroyed: its buffers stay allocated and the network namespace reference
a user socket holds is never released, so the netns cannot be torn down.

smc_cdc_msg_validate() queues abort_work from the receive tasklet when a
peer sends a CDC message with an out-of-order sequence number, so a
remote peer combined with a concurrent local close is enough to reach it.

Drop the reference when the work is cancelled, matching the pattern
smc_close_cancel_work() already uses for conn->close_work:

        if (cancel_work_sync(&smc->conn.close_work))
                sock_put(sk);

The sock_put() is safe here: every caller of smc_conn_free() passes the
connection of a socket it holds a reference to, so this cannot release
the last one.

Fixes: b286a0651e44 ("net/smc: handle incoming CDC validation message")
Cc: stable@vger.kernel.org
Reviewed-by: Mahanta Jambigi <mjambigi@linux.ibm.com>
Reviewed-by: Sidraya Jayagond <sidraya@linux.ibm.com>
Signed-off-by: Hidayath Khan <hidayath@linux.ibm.com>
---
 net/smc/smc_core.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index c0027d2fe4e8..dd9fffbe41e0 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -1254,6 +1254,7 @@ static void smc_buf_unuse(struct smc_connection *conn,
 /* remove a finished connection from its link group */
 void smc_conn_free(struct smc_connection *conn)
 {
+	struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
 	struct smc_link_group *lgr = conn->lgr;
 
 	if (!lgr || conn->freed)
@@ -1277,8 +1278,13 @@ void smc_conn_free(struct smc_connection *conn)
 		tasklet_kill(&conn->rx_tsklet);
 	} else {
 		smc_cdc_wait_pend_tx_wr(conn);
-		if (current_work() != &conn->abort_work)
-			cancel_work_sync(&conn->abort_work);
+		/* If the work was pending (cancel returns true) it never ran,
+		 * so the sock_hold taken by its scheduler was never released.
+		 */
+		if (current_work() != &conn->abort_work) {
+			if (cancel_work_sync(&conn->abort_work))
+				sock_put(&smc->sk);
+		}
 	}
 	if (!list_empty(&lgr->list)) {
 		smc_buf_unuse(conn, lgr); /* allow buffer reuse */

base-commit: 2b1c2bc2355fd59cc75045e42d9dc5470ef5fa9a
-- 
2.52.0


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

* Re: [PATCH net] net/smc: drop the abort_work reference when the work is cancelled
  2026-08-06  8:15 [PATCH net] net/smc: drop the abort_work reference when the work is cancelled Hidayath Khan
@ 2026-08-06  9:20 ` Dust Li
  2026-08-07  8:16 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: Dust Li @ 2026-08-06  9:20 UTC (permalink / raw)
  To: Hidayath Khan, alibuda, sidraya, mjambigi, andrew+netdev
  Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, horms, pasic,
	linux-s390, netdev

On 2026-08-06 10:15:49, Hidayath Khan wrote:
>The schedulers of conn->abort_work hand a socket reference to the work
>item and rely on it to give the reference back:
>
>        sock_hold(&smc->sk); /* sock_put in abort_work */
>        if (!queue_work(smc_close_wq, &conn->abort_work))
>                sock_put(&smc->sk);
>
>The queue_work() failure case is handled, but the cancellation case is
>not. smc_conn_free() cancels a still-pending abort_work:
>
>        if (current_work() != &conn->abort_work)
>                cancel_work_sync(&conn->abort_work);
>
>and discards the return value.  When cancel_work_sync() returns true the
>work was queued but had not started, so smc_conn_abort_work() never runs
>and its sock_put() never happens.  The reference is lost.
>
>As in smc_switch_conns(), a leaked sk_refcnt means the smc_sock is never
>destroyed: its buffers stay allocated and the network namespace reference
>a user socket holds is never released, so the netns cannot be torn down.
>
>smc_cdc_msg_validate() queues abort_work from the receive tasklet when a
>peer sends a CDC message with an out-of-order sequence number, so a
>remote peer combined with a concurrent local close is enough to reach it.
>
>Drop the reference when the work is cancelled, matching the pattern
>smc_close_cancel_work() already uses for conn->close_work:
>
>        if (cancel_work_sync(&smc->conn.close_work))
>                sock_put(sk);
>
>The sock_put() is safe here: every caller of smc_conn_free() passes the
>connection of a socket it holds a reference to, so this cannot release
>the last one.
>
>Fixes: b286a0651e44 ("net/smc: handle incoming CDC validation message")
>Cc: stable@vger.kernel.org
>Reviewed-by: Mahanta Jambigi <mjambigi@linux.ibm.com>
>Reviewed-by: Sidraya Jayagond <sidraya@linux.ibm.com>
>Signed-off-by: Hidayath Khan <hidayath@linux.ibm.com>

Reviewed-by: Dust Li <dust.li@linux.alibaba.com>

Best regards,
Dust

>---
> net/smc/smc_core.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
>diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
>index c0027d2fe4e8..dd9fffbe41e0 100644
>--- a/net/smc/smc_core.c
>+++ b/net/smc/smc_core.c
>@@ -1254,6 +1254,7 @@ static void smc_buf_unuse(struct smc_connection *conn,
> /* remove a finished connection from its link group */
> void smc_conn_free(struct smc_connection *conn)
> {
>+	struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
> 	struct smc_link_group *lgr = conn->lgr;
> 
> 	if (!lgr || conn->freed)
>@@ -1277,8 +1278,13 @@ void smc_conn_free(struct smc_connection *conn)
> 		tasklet_kill(&conn->rx_tsklet);
> 	} else {
> 		smc_cdc_wait_pend_tx_wr(conn);
>-		if (current_work() != &conn->abort_work)
>-			cancel_work_sync(&conn->abort_work);
>+		/* If the work was pending (cancel returns true) it never ran,
>+		 * so the sock_hold taken by its scheduler was never released.
>+		 */
>+		if (current_work() != &conn->abort_work) {
>+			if (cancel_work_sync(&conn->abort_work))
>+				sock_put(&smc->sk);
>+		}
> 	}
> 	if (!list_empty(&lgr->list)) {
> 		smc_buf_unuse(conn, lgr); /* allow buffer reuse */
>
>base-commit: 2b1c2bc2355fd59cc75045e42d9dc5470ef5fa9a
>-- 
>2.52.0

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

* Re: [PATCH net] net/smc: drop the abort_work reference when the work is cancelled
  2026-08-06  8:15 [PATCH net] net/smc: drop the abort_work reference when the work is cancelled Hidayath Khan
  2026-08-06  9:20 ` Dust Li
@ 2026-08-07  8:16 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-08-07  8:16 UTC (permalink / raw)
  To: Hidayath Khan
  Cc: Alexander Gordeev, Heiko Carstens, linux-s390, Vasily Gorbik

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] AB-BA deadlock between `smc_conn_free()` and `smc_conn_abort_work()` caused by calling `cancel_work_sync()` while holding the socket lock.
--

--- Patch [1]: [PATCH net] net/smc: drop the abort_work reference when the work is cancelled ---
commit 1b6cdab59cd811b97297f9b5597cac1aa3e420d9
Author: Hidayath Khan <hidayath@linux.ibm.com>

net/smc: drop the abort_work reference when the work is cancelled

This commit fixes a socket reference leak that occurs when an abort_work
item is cancelled before it runs. It drops the socket reference if
cancel_work_sync() returns true, ensuring the socket can be properly
destroyed.

> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index b4208cb186c5e..3d4a86d99dd6b 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c
[ ... ]
> @@ -1275,8 +1276,13 @@ void smc_conn_free(struct smc_connection *conn)
>  		tasklet_kill(&conn->rx_tsklet);
>  	} else {
>  		smc_cdc_wait_pend_tx_wr(conn);
> -		if (current_work() != &conn->abort_work)
> -			cancel_work_sync(&conn->abort_work);
> +		/* If the work was pending (cancel returns true) it never ran,
> +		 * so the sock_hold taken by its scheduler was never released.
> +		 */
> +		if (current_work() != &conn->abort_work) {
> +			if (cancel_work_sync(&conn->abort_work))
> +				sock_put(&smc->sk);

[Severity: High]
This isn't a bug introduced by this patch, but can calling cancel_work_sync()
here cause an AB-BA deadlock with the workqueue thread?

If a thread initiates a socket close, such as via smc_release() or
smc_close_passive_work(), it acquires the socket lock:

smc_release()
  lock_sock(&smc->sk);
  ...
  smc_conn_free()
    cancel_work_sync(&conn->abort_work);

If a remote peer concurrently sends an out-of-order CDC message, abort_work
is queued. The workqueue thread starts executing smc_conn_abort_work() and
attempts to acquire the same socket lock:

smc_conn_abort_work()
  lock_sock(&smc->sk);
  smc_conn_kill(conn, true);
  release_sock(&smc->sk);

Could this result in the workqueue thread blocking on the socket lock, while
the socket release thread blocks indefinitely in cancel_work_sync() waiting
for the workqueue thread to finish?

> +		}
>  	}
>  	if (!list_empty(&lgr->list)) {
>  		smc_buf_unuse(conn, lgr); /* allow buffer reuse */

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260806081549.595001-1-hidayath@linux.ibm.com?part=1

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

end of thread, other threads:[~2026-08-07  8:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-06  8:15 [PATCH net] net/smc: drop the abort_work reference when the work is cancelled Hidayath Khan
2026-08-06  9:20 ` Dust Li
2026-08-07  8:16 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox