[PATCH WIP/RFC v3 3/6] nvme_rdma: keep a ref on the ctrl during delete/flush

Steve Wise swise at opengridcomputing.com
Wed Aug 31 07:29:29 PDT 2016


> >
> > At the top of nvme_rdma_device_unplug(), we change the ctrl state to
DELETING.
> > If that succeeded, and thus we own the delete process, and are about to kref
the
> > controller, how could the controller ref be 0?  If it is, it is probably
freed
> > which means we're in a bad way...
> 
> I meant in the del_ctrl part...
> 

Oh. :)

Does this fully avoid the race?

@@ -1671,7 +1671,8 @@ static int nvme_rdma_del_ctrl(struct nvme_ctrl *nctrl)
         * Keep a reference until all work is flushed since
         * __nvme_rdma_del_ctrl can free the ctrl mem
         */
-       kref_get(&ctrl->ctrl.kref);
+       if (!kref_get_unless_zero(&ctrl->ctrl.kref))
+               return -ENOMEM;
        ret = __nvme_rdma_del_ctrl(ctrl);
        if (!ret)
                flush_work(&ctrl->delete_work);





More information about the Linux-nvme mailing list