5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Mason [ Upstream commit 86ae3841aea4e29d7ac08d5614ca3823dc8dfbc9 ] nvmet_rdma_remove_one() disconnects the queues of a device and flushes nvmet-wq, but since commit a3dd7d0022c3 it returns right away if the device isn't on device_list. nvmet_rdma_free_dev(), run by the release work of the last queue, takes the device off that list first and frees the SRQs and the PD afterwards. A device removal in between finds nothing on the list, returns, and the RDMA core frees the device under ib_dealloc_pd(). Free the SRQs and the PD first and unlist the device last, so the remove callback finds it and its flush waits for the release work. Fixes: a3dd7d0022c3 ("nvmet-rdma: Don't flush system_wq by default during remove_one") Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig Signed-off-by: Chris Mason Signed-off-by: Jens Axboe Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/target/rdma.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c index 6f72d4fc9b87e..7a7aeac657819 100644 --- a/drivers/nvme/target/rdma.c +++ b/drivers/nvme/target/rdma.c @@ -1197,13 +1197,18 @@ static void nvmet_rdma_free_dev(struct kref *ref) struct nvmet_rdma_device *ndev = container_of(ref, struct nvmet_rdma_device, ref); + nvmet_rdma_destroy_srqs(ndev); + ib_dealloc_pd(ndev->pd); + + /* + * Only delete from the device list once all RDMA resources are torn + * down because nvmet_rdma_remove_one waits for the release work only + * if the device still is on the list. + */ mutex_lock(&device_list_mutex); list_del(&ndev->entry); mutex_unlock(&device_list_mutex); - nvmet_rdma_destroy_srqs(ndev); - ib_dealloc_pd(ndev->pd); - kfree(ndev); } -- 2.53.0