linux_dsm_epyc7002/drivers/nvme/target
Sagi Grimberg 64f5e9cdd7 nvmet: fix memory leak when removing namespaces and controllers concurrently
When removing a namespace, we add an NS_CHANGE async event, however if
the controller admin queue is removed after the event was added but not
yet processed, we won't free the aens, resulting in the below memory
leak [1].

Fix that by moving nvmet_async_event_free to the final controller
release after it is detached from subsys->ctrls ensuring no async
events are added, and modify it to simply remove all pending aens.

--
$ cat /sys/kernel/debug/kmemleak
unreferenced object 0xffff888c1af2c000 (size 32):
  comm "nvmetcli", pid 5164, jiffies 4295220864 (age 6829.924s)
  hex dump (first 32 bytes):
    28 01 82 3b 8b 88 ff ff 28 01 82 3b 8b 88 ff ff  (..;....(..;....
    02 00 04 65 76 65 6e 74 5f 66 69 6c 65 00 00 00  ...event_file...
  backtrace:
    [<00000000217ae580>] nvmet_add_async_event+0x57/0x290 [nvmet]
    [<0000000012aa2ea9>] nvmet_ns_changed+0x206/0x300 [nvmet]
    [<00000000bb3fd52e>] nvmet_ns_disable+0x367/0x4f0 [nvmet]
    [<00000000e91ca9ec>] nvmet_ns_free+0x15/0x180 [nvmet]
    [<00000000a15deb52>] config_item_release+0xf1/0x1c0
    [<000000007e148432>] configfs_rmdir+0x555/0x7c0
    [<00000000f4506ea6>] vfs_rmdir+0x142/0x3c0
    [<0000000000acaaf0>] do_rmdir+0x2b2/0x340
    [<0000000034d1aa52>] do_syscall_64+0xa5/0x4d0
    [<00000000211f13bc>] entry_SYSCALL_64_after_hwframe+0x6a/0xdf

Fixes: a07b4970f4 ("nvmet: add a generic NVMe target")
Reported-by: David Milburn <dmilburn@redhat.com>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Tested-by: David Milburn <dmilburn@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
2020-05-27 07:12:40 +02:00
..
admin-cmd.c nvmet: add metadata/T10-PI support 2020-05-27 07:12:40 +02:00
configfs.c nvmet: add metadata/T10-PI support 2020-05-27 07:12:40 +02:00
core.c nvmet: fix memory leak when removing namespaces and controllers concurrently 2020-05-27 07:12:40 +02:00
discovery.c nvmet: rename nvmet_check_data_len to nvmet_check_transfer_len 2020-05-27 07:12:39 +02:00
fabrics-cmd.c nvmet: add metadata/T10-PI support 2020-05-27 07:12:40 +02:00
fc.c nvmet-fc: slight cleanup for kbuild test warnings 2020-05-09 16:18:35 -06:00
fcloop.c nvme-fcloop: add target to host LS request support 2020-05-09 16:18:34 -06:00
io-cmd-bdev.c nvmet: add metadata support for block devices 2020-05-27 07:12:40 +02:00
io-cmd-file.c nvmet: rename nvmet_check_data_len to nvmet_check_transfer_len 2020-05-27 07:12:39 +02:00
Kconfig nvmet: add metadata characteristics for a namespace 2020-05-27 07:12:39 +02:00
loop.c nvme: Make nvme_uninit_ctrl symmetric to nvme_init_ctrl 2020-03-26 04:51:56 +09:00
Makefile nvmet: introduce target-side trace 2019-06-21 11:15:46 +02:00
nvmet.h nvmet: add metadata support for block devices 2020-05-27 07:12:40 +02:00
rdma.c nvmet-rdma: add metadata/T10-PI support 2020-05-27 07:12:40 +02:00
tcp.c nvmet-tcp: move send/recv error handling in the send/recv methods instead of call-sites 2020-05-27 07:12:37 +02:00
trace.c nvmet: trace: parse Get LBA Status command in detail 2019-08-29 12:55:01 -07:00
trace.h nvmet: add async event tracing support 2020-05-27 07:12:38 +02:00