Skip to content

Commit 44c1c8c

Browse files
jgunthorpegregkh
authored andcommitted
RDMA/core: Change how failing destroy is handled during uobj abort
[ Upstream commit f553246 ] Currently it triggers a WARN_ON and then goes ahead and destroys the uobject anyhow, leaking any driver memory. The only place that leaks driver memory should be during FD close() in uverbs_destroy_ufile_hw(). Drivers are only allowed to fail destroy uobjects if they guarantee destroy will eventually succeed. uverbs_destroy_ufile_hw() provides the loop to give the driver that chance. Link: https://lore.kernel.org/r/20200902081708.746631-1-leon@kernel.org Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d4ddc5a commit 44c1c8c

2 files changed

Lines changed: 15 additions & 20 deletions

File tree

drivers/infiniband/core/rdma_core.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,6 @@ static int uverbs_destroy_uobject(struct ib_uobject *uobj,
130130
lockdep_assert_held(&ufile->hw_destroy_rwsem);
131131
assert_uverbs_usecnt(uobj, UVERBS_LOOKUP_WRITE);
132132

133-
if (reason == RDMA_REMOVE_ABORT_HWOBJ) {
134-
reason = RDMA_REMOVE_ABORT;
135-
ret = uobj->uapi_object->type_class->destroy_hw(uobj, reason,
136-
attrs);
137-
/*
138-
* Drivers are not permitted to ignore RDMA_REMOVE_ABORT, see
139-
* ib_is_destroy_retryable, cleanup_retryable == false here.
140-
*/
141-
WARN_ON(ret);
142-
}
143-
144133
if (reason == RDMA_REMOVE_ABORT) {
145134
WARN_ON(!list_empty(&uobj->list));
146135
WARN_ON(!uobj->context);
@@ -674,11 +663,22 @@ void rdma_alloc_abort_uobject(struct ib_uobject *uobj,
674663
bool hw_obj_valid)
675664
{
676665
struct ib_uverbs_file *ufile = uobj->ufile;
666+
int ret;
667+
668+
if (hw_obj_valid) {
669+
ret = uobj->uapi_object->type_class->destroy_hw(
670+
uobj, RDMA_REMOVE_ABORT, attrs);
671+
/*
672+
* If the driver couldn't destroy the object then go ahead and
673+
* commit it. Leaking objects that can't be destroyed is only
674+
* done during FD close after the driver has a few more tries to
675+
* destroy it.
676+
*/
677+
if (WARN_ON(ret))
678+
return rdma_alloc_commit_uobject(uobj, attrs);
679+
}
677680

678-
uverbs_destroy_uobject(uobj,
679-
hw_obj_valid ? RDMA_REMOVE_ABORT_HWOBJ :
680-
RDMA_REMOVE_ABORT,
681-
attrs);
681+
uverbs_destroy_uobject(uobj, RDMA_REMOVE_ABORT, attrs);
682682

683683
/* Matches the down_read in rdma_alloc_begin_uobject */
684684
up_read(&ufile->hw_destroy_rwsem);

include/rdma/ib_verbs.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,11 +1463,6 @@ enum rdma_remove_reason {
14631463
RDMA_REMOVE_DRIVER_REMOVE,
14641464
/* uobj is being cleaned-up before being committed */
14651465
RDMA_REMOVE_ABORT,
1466-
/*
1467-
* uobj has been fully created, with the uobj->object set, but is being
1468-
* cleaned up before being comitted
1469-
*/
1470-
RDMA_REMOVE_ABORT_HWOBJ,
14711466
};
14721467

14731468
struct ib_rdmacg_object {

0 commit comments

Comments
 (0)