All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvmet-tcp: fix a memory leak when releasing a queue
@ 2021-10-15  8:26 Maurizio Lombardi
  2021-10-15 21:33 ` Sagi Grimberg
  2021-10-16  4:42 ` Christoph Hellwig
  0 siblings, 2 replies; 3+ messages in thread
From: Maurizio Lombardi @ 2021-10-15  8:26 UTC (permalink / raw)
  To: linux-nvme; +Cc: hch, sagi, hare, chaitanya.kulkarni, jmeneghi

page_frag_free() won't completely release the memory
allocated for the commands, the cache page must be explicitly
freed by calling __page_frag_cache_drain().

This bug can be easily reproduced by repeatedly
executing the following command on the initiator:

$echo 1 > /sys/devices/virtual/nvme-fabrics/ctl/nvme0/reset_controller

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
Reviewed-by: John Meneghini <jmeneghi@redhat.com>
---
 drivers/nvme/target/tcp.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
index 07ee347ea3f3..c33a0464346f 100644
--- a/drivers/nvme/target/tcp.c
+++ b/drivers/nvme/target/tcp.c
@@ -1428,6 +1428,7 @@ static void nvmet_tcp_uninit_data_in_cmds(struct nvmet_tcp_queue *queue)
 
 static void nvmet_tcp_release_queue_work(struct work_struct *w)
 {
+	struct page *page;
 	struct nvmet_tcp_queue *queue =
 		container_of(w, struct nvmet_tcp_queue, release_work);
 
@@ -1447,6 +1448,8 @@ static void nvmet_tcp_release_queue_work(struct work_struct *w)
 		nvmet_tcp_free_crypto(queue);
 	ida_simple_remove(&nvmet_tcp_queue_ida, queue->idx);
 
+	page = virt_to_head_page(queue->pf_cache.va);
+	__page_frag_cache_drain(page, queue->pf_cache.pagecnt_bias);
 	kfree(queue);
 }
 
-- 
2.27.0



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

* Re: [PATCH] nvmet-tcp: fix a memory leak when releasing a queue
  2021-10-15  8:26 [PATCH] nvmet-tcp: fix a memory leak when releasing a queue Maurizio Lombardi
@ 2021-10-15 21:33 ` Sagi Grimberg
  2021-10-16  4:42 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Sagi Grimberg @ 2021-10-15 21:33 UTC (permalink / raw)
  To: Maurizio Lombardi, linux-nvme; +Cc: hch, hare, chaitanya.kulkarni, jmeneghi

> page_frag_free() won't completely release the memory
> allocated for the commands, the cache page must be explicitly
> freed by calling __page_frag_cache_drain().
> 
> This bug can be easily reproduced by repeatedly
> executing the following command on the initiator:
> 
> $echo 1 > /sys/devices/virtual/nvme-fabrics/ctl/nvme0/reset_controller
> 
> Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
> Reviewed-by: John Meneghini <jmeneghi@redhat.com>

This came a long a number of times before, thanks for
fixing this.

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>


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

* Re: [PATCH] nvmet-tcp: fix a memory leak when releasing a queue
  2021-10-15  8:26 [PATCH] nvmet-tcp: fix a memory leak when releasing a queue Maurizio Lombardi
  2021-10-15 21:33 ` Sagi Grimberg
@ 2021-10-16  4:42 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2021-10-16  4:42 UTC (permalink / raw)
  To: Maurizio Lombardi
  Cc: linux-nvme, hch, sagi, hare, chaitanya.kulkarni, jmeneghi

Thanks,

applied to nvme-5.15.


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

end of thread, other threads:[~2021-10-16  4:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-15  8:26 [PATCH] nvmet-tcp: fix a memory leak when releasing a queue Maurizio Lombardi
2021-10-15 21:33 ` Sagi Grimberg
2021-10-16  4:42 ` 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.