All of lore.kernel.org
 help / color / mirror / Atom feed
* [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

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.