* [PATCH 0/3] fix refcount leak in smb2_async_readv() and smb2_async_writev()
@ 2026-12-04 8:41 Youling Tang
2026-12-04 8:41 ` [PATCH 1/3] smb/client: factor out smb2_release_io_mr() Youling Tang
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Youling Tang @ 2026-12-04 8:41 UTC (permalink / raw)
To: linkinjeon, pc, ronniesahlberg, sprasad, tom, bharathsm, metze,
chenxiaosong
Cc: linux-cifs, Youling Tang
From: Youling Tang <tangyouling@kylinos.cn>
Youling Tang (3):
smb/client: factor out smb2_release_io_mr()
smb/client: fix refcount leak in smb2_async_readv() and
smb2_async_writev()
smb/client: remove redundant MR release from cifs_free_subrequest()
fs/smb/client/file.c | 9 ---------
fs/smb/client/smb2pdu.c | 40 ++++++++++++++++------------------------
2 files changed, 16 insertions(+), 33 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] smb/client: factor out smb2_release_io_mr()
2026-12-04 8:41 [PATCH 0/3] fix refcount leak in smb2_async_readv() and smb2_async_writev() Youling Tang
@ 2026-12-04 8:41 ` Youling Tang
2026-12-04 8:41 ` [PATCH 2/3] smb/client: fix refcount leak in smb2_async_readv() and smb2_async_writev() Youling Tang
2026-12-04 8:41 ` [PATCH 3/3] smb/client: remove redundant MR release from cifs_free_subrequest() Youling Tang
2 siblings, 0 replies; 4+ messages in thread
From: Youling Tang @ 2026-12-04 8:41 UTC (permalink / raw)
To: linkinjeon, pc, ronniesahlberg, sprasad, tom, bharathsm, metze,
chenxiaosong
Cc: linux-cifs, Youling Tang, ChenXiaoSong
From: Youling Tang <tangyouling@kylinos.cn>
Preparation for the next patch. It can also be folded into the next patch.
Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
fs/smb/client/smb2pdu.c | 37 +++++++++++++------------------------
1 file changed, 13 insertions(+), 24 deletions(-)
diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index dc2d0915268f..74309e063403 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -4775,6 +4775,17 @@ int smb2_new_read_req(void **buf, unsigned int *total_len,
return rc;
}
+/* Return the MR to the pool before netfs can retry the subrequest. */
+static void smb2_release_io_mr(struct cifs_io_subrequest *subreq)
+{
+#ifdef CONFIG_CIFS_SMB_DIRECT
+ if (subreq->mr) {
+ smbd_deregister_mr(subreq->mr);
+ subreq->mr = NULL;
+ }
+#endif
+}
+
static void
smb2_readv_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
{
@@ -4864,17 +4875,7 @@ smb2_readv_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
mid->mid_state);
break;
}
-#ifdef CONFIG_CIFS_SMB_DIRECT
- /*
- * If this rdata has a memory registered, the MR can be freed
- * MR needs to be freed as soon as I/O finishes to prevent deadlock
- * because they have limited number and are used for future I/Os
- */
- if (rdata->mr) {
- smbd_deregister_mr(rdata->mr);
- rdata->mr = NULL;
- }
-#endif
+ smb2_release_io_mr(rdata);
if (rdata->result && rdata->result != -ENODATA) {
cifs_stats_fail_inc(tcon, SMB2_READ_HE);
trace_smb3_read_err(rdata->rreq->debug_id,
@@ -5221,19 +5222,7 @@ smb2_writev_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
mid->mid_state);
break;
}
-#ifdef CONFIG_CIFS_SMB_DIRECT
- /*
- * If this wdata has a memory registered, the MR can be freed
- * The number of MRs available is limited, it's important to recover
- * used MR as soon as I/O is finished. Hold MR longer in the later
- * I/O process can possibly result in I/O deadlock due to lack of MR
- * to send request on I/O retry
- */
- if (wdata->mr) {
- smbd_deregister_mr(wdata->mr);
- wdata->mr = NULL;
- }
-#endif
+ smb2_release_io_mr(wdata);
if (result) {
wdata->result = result;
cifs_stats_fail_inc(tcon, SMB2_WRITE_HE);
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] smb/client: fix refcount leak in smb2_async_readv() and smb2_async_writev()
2026-12-04 8:41 [PATCH 0/3] fix refcount leak in smb2_async_readv() and smb2_async_writev() Youling Tang
2026-12-04 8:41 ` [PATCH 1/3] smb/client: factor out smb2_release_io_mr() Youling Tang
@ 2026-12-04 8:41 ` Youling Tang
2026-12-04 8:41 ` [PATCH 3/3] smb/client: remove redundant MR release from cifs_free_subrequest() Youling Tang
2 siblings, 0 replies; 4+ messages in thread
From: Youling Tang @ 2026-12-04 8:41 UTC (permalink / raw)
To: linkinjeon, pc, ronniesahlberg, sprasad, tom, bharathsm, metze,
chenxiaosong
Cc: linux-cifs, Youling Tang, ChenXiaoSong
From: Youling Tang <tangyouling@kylinos.cn>
See the procedure below:
netfs_prepare_write
netfs_alloc_subrequest
refcount_set(&subreq->ref, 2) // one for the list, one for I/O
smb2_async_writev
wdata->mr = smbd_register_mr(...)
adjust_credits // fails before submission
__set_bit(NETFS_SREQ_NEED_RETRY, ...)
cifs_write_subrequest_terminated // MR still registered
netfs_write_subrequest_terminated
netfs_put_subrequest // drop this I/O's reference
__refcount_dec_and_test // 2 -> 1, returns false
netfs_collect_write_results
if (test_bit(NETFS_SREQ_NEED_RETRY, ...)
netfs_retry_writes
netfs_retry_write_stream
netfs_get_subrequest // take an I/O reference for the retry (1 -> 2)
netfs_reissue_write
netfs_do_issue_write
cifs_issue_write // stream->issue_write()
__cifs_issue_write
smb2_async_writev // wdata->server->ops->async_writev()
wdata->mr = smbd_register_mr(...) // old MR reference leaks
Fixes: 69c3c023af25 ("cifs: Implement netfslib hooks")
Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
fs/smb/client/smb2pdu.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index 74309e063403..8defc8bc7ae8 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -5017,6 +5017,8 @@ smb2_async_readv(struct cifs_io_subrequest *rdata)
async_readv_out:
cifs_small_buf_release(buf);
+ if (rc)
+ smb2_release_io_mr(rdata);
out:
/* if the send error is retryable, let netfs know about it */
@@ -5439,6 +5441,7 @@ smb2_async_writev(struct cifs_io_subrequest *wdata)
}
if (rc) {
+ smb2_release_io_mr(wdata);
trace_smb3_rw_credits(wdata->rreq->debug_id,
wdata->subreq.debug_index,
wdata->credits.value,
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] smb/client: remove redundant MR release from cifs_free_subrequest()
2026-12-04 8:41 [PATCH 0/3] fix refcount leak in smb2_async_readv() and smb2_async_writev() Youling Tang
2026-12-04 8:41 ` [PATCH 1/3] smb/client: factor out smb2_release_io_mr() Youling Tang
2026-12-04 8:41 ` [PATCH 2/3] smb/client: fix refcount leak in smb2_async_readv() and smb2_async_writev() Youling Tang
@ 2026-12-04 8:41 ` Youling Tang
2 siblings, 0 replies; 4+ messages in thread
From: Youling Tang @ 2026-12-04 8:41 UTC (permalink / raw)
To: linkinjeon, pc, ronniesahlberg, sprasad, tom, bharathsm, metze,
chenxiaosong
Cc: linux-cifs, Youling Tang, ChenXiaoSong
From: Youling Tang <tangyouling@kylinos.cn>
See the procedure below:
smb2_readv_callback // I/O completes
smb2_release_io_mr
smbd_deregister_mr(subreq->mr);
subreq->mr = NULL;
smb2_async_readv // submission fails
smb2_release_io_mr
smbd_deregister_mr(subreq->mr);
subreq->mr = NULL;
netfs_put_subrequest // last reference
netfs_free_subrequest
cifs_free_subrequest // MR pointer is NULL
Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
fs/smb/client/file.c | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index fc63b238391d..c7bb478d8baa 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -769,15 +769,6 @@ static void cifs_free_subrequest(struct netfs_io_subrequest *subreq)
container_of(subreq, struct cifs_io_subrequest, subreq);
int rc = subreq->error;
- if (rdata->subreq.source == NETFS_DOWNLOAD_FROM_SERVER) {
-#ifdef CONFIG_CIFS_SMB_DIRECT
- if (rdata->mr) {
- smbd_deregister_mr(rdata->mr);
- rdata->mr = NULL;
- }
-#endif
- }
-
if (rdata->credits.value != 0) {
trace_smb3_rw_credits(rdata->rreq->debug_id,
rdata->subreq.debug_index,
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-04 8:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 8:41 [PATCH 0/3] fix refcount leak in smb2_async_readv() and smb2_async_writev() Youling Tang
2026-12-04 8:41 ` [PATCH 1/3] smb/client: factor out smb2_release_io_mr() Youling Tang
2026-12-04 8:41 ` [PATCH 2/3] smb/client: fix refcount leak in smb2_async_readv() and smb2_async_writev() Youling Tang
2026-12-04 8:41 ` [PATCH 3/3] smb/client: remove redundant MR release from cifs_free_subrequest() Youling Tang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox