[PATCH] nvmet-tcp: fix page fragment cache leak in error path
Geliang Tang
geliang at kernel.org
Mon May 25 02:50:19 PDT 2026
From: Geliang Tang <tanggeliang at 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 at 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
More information about the Linux-nvme
mailing list