Skip to content

Commit 7dd7864

Browse files
jgunthorpedledford
authored andcommitted
IB/core: Make ib_dealloc_pd return void
The majority of callers never check the return value, and even if they did, they can't do anything about a failure. All possible failure cases represent a bug in the caller, so just WARN_ON inside the function instead. This fixes a few random errors: net/rd/iw.c infinite loops while it fails. (racing with EBUSY?) This also lays the ground work to get rid of error return from the drivers. Most drivers do not error, the few that do are broken since it cannot be handled. Since uverbs can legitimately make use of EBUSY, open code the check. Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> Reviewed-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent 03f6fb9 commit 7dd7864

File tree

7 files changed

+41
-26
lines changed

7 files changed

+41
-26
lines changed

drivers/infiniband/core/uverbs_cmd.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file,
606606
{
607607
struct ib_uverbs_dealloc_pd cmd;
608608
struct ib_uobject *uobj;
609+
struct ib_pd *pd;
609610
int ret;
610611

611612
if (copy_from_user(&cmd, buf, sizeof cmd))
@@ -614,15 +615,20 @@ ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file,
614615
uobj = idr_write_uobj(&ib_uverbs_pd_idr, cmd.pd_handle, file->ucontext);
615616
if (!uobj)
616617
return -EINVAL;
618+
pd = uobj->object;
617619

618-
ret = ib_dealloc_pd(uobj->object);
619-
if (!ret)
620-
uobj->live = 0;
621-
622-
put_uobj_write(uobj);
620+
if (atomic_read(&pd->usecnt)) {
621+
ret = -EBUSY;
622+
goto err_put;
623+
}
623624

625+
ret = pd->device->dealloc_pd(uobj->object);
626+
WARN_ONCE(ret, "Infiniband HW driver failed dealloc_pd");
624627
if (ret)
625-
return ret;
628+
goto err_put;
629+
630+
uobj->live = 0;
631+
put_uobj_write(uobj);
626632

627633
idr_remove_uobj(&ib_uverbs_pd_idr, uobj);
628634

@@ -633,6 +639,10 @@ ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file,
633639
put_uobj(uobj);
634640

635641
return in_len;
642+
643+
err_put:
644+
put_uobj_write(uobj);
645+
return ret;
636646
}
637647

638648
struct xrcd_table_entry {

drivers/infiniband/core/verbs.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,18 +260,32 @@ struct ib_pd *ib_alloc_pd(struct ib_device *device)
260260
}
261261
EXPORT_SYMBOL(ib_alloc_pd);
262262

263-
int ib_dealloc_pd(struct ib_pd *pd)
263+
/**
264+
* ib_dealloc_pd - Deallocates a protection domain.
265+
* @pd: The protection domain to deallocate.
266+
*
267+
* It is an error to call this function while any resources in the pd still
268+
* exist. The caller is responsible to synchronously destroy them and
269+
* guarantee no new allocations will happen.
270+
*/
271+
void ib_dealloc_pd(struct ib_pd *pd)
264272
{
273+
int ret;
274+
265275
if (pd->local_mr) {
266-
if (ib_dereg_mr(pd->local_mr))
267-
return -EBUSY;
276+
ret = ib_dereg_mr(pd->local_mr);
277+
WARN_ON(ret);
268278
pd->local_mr = NULL;
269279
}
270280

271-
if (atomic_read(&pd->usecnt))
272-
return -EBUSY;
281+
/* uverbs manipulates usecnt with proper locking, while the kabi
282+
requires the caller to guarantee we can't race here. */
283+
WARN_ON(atomic_read(&pd->usecnt));
273284

274-
return pd->device->dealloc_pd(pd);
285+
/* Making delalloc_pd a void return is a WIP, no driver should return
286+
an error here. */
287+
ret = pd->device->dealloc_pd(pd);
288+
WARN_ONCE(ret, "Infiniband HW driver failed dealloc_pd");
275289
}
276290
EXPORT_SYMBOL(ib_dealloc_pd);
277291

drivers/infiniband/ulp/ipoib/ipoib_verbs.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,7 @@ void ipoib_transport_dev_cleanup(struct net_device *dev)
280280
priv->wq = NULL;
281281
}
282282

283-
if (ib_dealloc_pd(priv->pd))
284-
ipoib_warn(priv, "ib_dealloc_pd failed\n");
285-
283+
ib_dealloc_pd(priv->pd);
286284
}
287285

288286
void ipoib_event(struct ib_event_handler *handler,

drivers/infiniband/ulp/iser/iser_verbs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static void iser_free_device_ib_res(struct iser_device *device)
185185

186186
(void)ib_unregister_event_handler(&device->event_handler);
187187
(void)ib_dereg_mr(device->mr);
188-
(void)ib_dealloc_pd(device->pd);
188+
ib_dealloc_pd(device->pd);
189189

190190
kfree(device->comps);
191191
device->comps = NULL;

include/rdma/ib_verbs.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,11 +2196,7 @@ int ib_find_pkey(struct ib_device *device,
21962196

21972197
struct ib_pd *ib_alloc_pd(struct ib_device *device);
21982198

2199-
/**
2200-
* ib_dealloc_pd - Deallocates a protection domain.
2201-
* @pd: The protection domain to deallocate.
2202-
*/
2203-
int ib_dealloc_pd(struct ib_pd *pd);
2199+
void ib_dealloc_pd(struct ib_pd *pd);
22042200

22052201
/**
22062202
* ib_create_ah - Creates an address handle for the given address vector.

net/rds/iw.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ static void rds_iw_remove_one(struct ib_device *device, void *client_data)
148148
if (rds_iwdev->mr)
149149
ib_dereg_mr(rds_iwdev->mr);
150150

151-
while (ib_dealloc_pd(rds_iwdev->pd)) {
152-
rdsdebug("Failed to dealloc pd %p\n", rds_iwdev->pd);
153-
msleep(1);
154-
}
151+
ib_dealloc_pd(rds_iwdev->pd);
155152

156153
list_del(&rds_iwdev->list);
157154
kfree(rds_iwdev);

net/sunrpc/xprtrdma/verbs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ rpcrdma_ia_close(struct rpcrdma_ia *ia)
624624

625625
/* If the pd is still busy, xprtrdma missed freeing a resource */
626626
if (ia->ri_pd && !IS_ERR(ia->ri_pd))
627-
WARN_ON(ib_dealloc_pd(ia->ri_pd));
627+
ib_dealloc_pd(ia->ri_pd);
628628
}
629629

630630
/*

0 commit comments

Comments
 (0)