Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sagi Grimberg <sagi@grimberg.me>
To: Maurizio Lombardi <mlombard@redhat.com>, Yi Zhang <yi.zhang@redhat.com>
Cc: "open list:NVM EXPRESS DRIVER" <linux-nvme@lists.infradead.org>,
	Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>,
	Hannes Reinecke <hare@suse.de>
Subject: Re: blktests nvme 041,042 leak memory
Date: Wed, 29 May 2024 15:51:09 +0300	[thread overview]
Message-ID: <ff85fd7f-efc7-40d3-8c9a-e0189e3d71f2@grimberg.me> (raw)
In-Reply-To: <CAFL455mZMka2J8d008JH+WQhDxP6D4dweFOWVQc58rOQk2ybzw@mail.gmail.com>



On 29/05/2024 12:08, Maurizio Lombardi wrote:
> út 28. 5. 2024 v 11:44 odesílatel Maurizio Lombardi
> <mlombard@redhat.com> napsal:
>> This patch fixes the problem for TCP, it should also work for loop but
>> I've not tested it.
>>
>> http://bsdbackstore.eu/misc/0001-nvme-fix-memory-leak-when-nvme_init_ctrl-fails.patch
> I updated it to fix all the fabrics, with the exception of apple's driver
> because I am not sure I fully understand its probe process.

It'd be better if we didn't propagate this issue to the transport drivers.

Seems that the asymmetric part is the device_private allocated in device_add
but only removed in device_release (last reference).

A hack like this would also make the issue go away:
--
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f62fd49c1411..8a9d51e1ccd6 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -4702,6 +4702,14 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct 
device *dev,
         nvme_fault_inject_fini(&ctrl->fault_inject);
         dev_pm_qos_hide_latency_tolerance(ctrl->device);
         cdev_device_del(&ctrl->cdev, ctrl->device);
+       /*
+        * this is nasty hack, but device_add allocated a device private
+        * dev->p, which is freed assymmetricly in device_release, and
+        * in order to cleanup after ourselves, and not rely on the device
+        * .release handler (which also calls the nvme transport free 
handler)
+        * we explicitly free the device private.
+        */
+       kfree(ctrl->device->p);
  out_free_name:
         nvme_put_ctrl(ctrl);
         kfree_const(ctrl->device->kobj.name)
--

But this is ugly...


  reply	other threads:[~2024-05-29 12:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-26 19:47 blktests nvme 041,042 leak memory Sagi Grimberg
2024-05-27  1:11 ` Yi Zhang
2024-05-28  9:44   ` Maurizio Lombardi
2024-05-29  9:08     ` Maurizio Lombardi
2024-05-29 12:51       ` Sagi Grimberg [this message]
2024-05-29 13:45         ` Maurizio Lombardi
2024-05-29 16:25         ` Keith Busch
2024-05-29 16:48           ` Keith Busch
2024-05-30  6:59           ` Sagi Grimberg
2024-05-30  7:25             ` Maurizio Lombardi
2024-05-30 16:29               ` Keith Busch
2024-05-30 17:40                 ` Maurizio Lombardi
2024-05-31 11:55                   ` Maurizio Lombardi
2024-05-31 14:37                     ` Maurizio Lombardi
2024-06-03  8:37                       ` Hannes Reinecke
2024-06-03  8:52                         ` Maurizio Lombardi
2024-06-03  9:33                           ` Hannes Reinecke
2024-06-03  9:38                             ` Maurizio Lombardi
2024-06-03  9:35                         ` Maurizio Lombardi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ff85fd7f-efc7-40d3-8c9a-e0189e3d71f2@grimberg.me \
    --to=sagi@grimberg.me \
    --cc=hare@suse.de \
    --cc=linux-nvme@lists.infradead.org \
    --cc=mlombard@redhat.com \
    --cc=shinichiro.kawasaki@wdc.com \
    --cc=yi.zhang@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox