* [PATCH] nvmet-tcp: fix page fragment cache leak in error path
@ 2026-05-25 9:50 Geliang Tang
2026-05-26 7:12 ` Christoph Hellwig
0 siblings, 1 reply; 2+ messages in thread
From: Geliang Tang @ 2026-05-25 9:50 UTC (permalink / raw)
To: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni,
Roy Shterman, Solganik Alexander, Hannes Reinecke
Cc: Geliang Tang, linux-nvme
From: Geliang Tang <tanggeliang@kylinos.cn>
In nvmet_tcp_alloc_queue(), when a connection is closed during the
allocation process (e.g., nvmet_tcp_set_queue_sock() returns -ENOTCONN),
the error handling jumps to out_free_queue without draining the page
fragment cache.
Although nvmet_tcp_free_cmd() is called in some error paths to release
individual page fragments, the underlying page cache reference held by
queue->pf_cache is never released. This results in a page leak each time
a connection fails during allocation, which could lead to memory
exhaustion over time if connections are repeatedly opened and closed.
Fix this by calling page_frag_cache_drain() before freeing the queue
structure in the out_free_queue label.
Fixes: 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
drivers/nvme/target/tcp.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
index 20f150d17a96..8b8ec533e352 100644
--- a/drivers/nvme/target/tcp.c
+++ b/drivers/nvme/target/tcp.c
@@ -2002,6 +2002,7 @@ static void nvmet_tcp_alloc_queue(struct nvmet_tcp_port *port,
out_sock:
fput(queue->sock->file);
out_free_queue:
+ page_frag_cache_drain(&queue->pf_cache);
kfree(queue);
out_release:
pr_err("failed to allocate queue, error %d\n", ret);
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] nvmet-tcp: fix page fragment cache leak in error path
2026-05-25 9:50 [PATCH] nvmet-tcp: fix page fragment cache leak in error path Geliang Tang
@ 2026-05-26 7:12 ` Christoph Hellwig
0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2026-05-26 7:12 UTC (permalink / raw)
To: Geliang Tang
Cc: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni,
Roy Shterman, Solganik Alexander, Hannes Reinecke, Geliang Tang,
linux-nvme
On Mon, May 25, 2026 at 05:50:19PM +0800, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> In nvmet_tcp_alloc_queue(), when a connection is closed during the
> allocation process (e.g., nvmet_tcp_set_queue_sock() returns -ENOTCONN),
> the error handling jumps to out_free_queue without draining the page
> fragment cache.
nvmet_tcp_set_queue_sock jumps to out_destroy_sq.
> Although nvmet_tcp_free_cmd() is called in some error paths to release
> individual page fragments, the underlying page cache reference held by
> queue->pf_cache is never released. This results in a page leak each time
> a connection fails during allocation, which could lead to memory
> exhaustion over time if connections are repeatedly opened and closed.
>
> Fix this by calling page_frag_cache_drain() before freeing the queue
> structure in the out_free_queue label.
The first allocation using pf_cache is the call to nvmet_tcp_alloc_cmd
after ida_alloc. So afaik this drain should at the out_ida_remove
label. And given how obscure this is, maybe a comment would not
hurt either?
Otherwise this looks good.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-26 7:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-25 9:50 [PATCH] nvmet-tcp: fix page fragment cache leak in error path Geliang Tang
2026-05-26 7:12 ` Christoph Hellwig
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.