Skip to content

Commit

Permalink
RDMA/rxe: Use standard names for ref counting
Browse files Browse the repository at this point in the history
Rename rxe_add_ref() to rxe_get() and rxe_drop_ref() to rxe_put().
Significantly improves readability for new readers.

Link: https://lore.kernel.org/r/20220304000808.225811-10-rpearsonhpe@gmail.com
Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
  • Loading branch information
Bob Pearson authored and Jason Gunthorpe committed Mar 16, 2022
1 parent 3225717 commit 3197706
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 96 deletions.
4 changes: 2 additions & 2 deletions drivers/infiniband/sw/rxe/rxe_av.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ struct rxe_av *rxe_get_av(struct rxe_pkt_info *pkt, struct rxe_ah **ahp)

if (rxe_ah_pd(ah) != pkt->qp->pd) {
pr_warn("PDs don't match for AH and QP\n");
rxe_drop_ref(ah);
rxe_put(ah);
return NULL;
}

if (ahp)
*ahp = ah;
else
rxe_drop_ref(ah);
rxe_put(ah);

return &ah->av;
}
Expand Down
8 changes: 4 additions & 4 deletions drivers/infiniband/sw/rxe/rxe_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ static void rxe_drain_resp_pkts(struct rxe_qp *qp, bool notify)
struct rxe_queue *q = qp->sq.queue;

while ((skb = skb_dequeue(&qp->resp_pkts))) {
rxe_drop_ref(qp);
rxe_put(qp);
kfree_skb(skb);
ib_device_put(qp->ibqp.device);
}
Expand All @@ -548,7 +548,7 @@ static void free_pkt(struct rxe_pkt_info *pkt)
struct ib_device *dev = qp->ibqp.device;

kfree_skb(skb);
rxe_drop_ref(qp);
rxe_put(qp);
ib_device_put(dev);
}

Expand All @@ -562,7 +562,7 @@ int rxe_completer(void *arg)
enum comp_state state;
int ret = 0;

rxe_add_ref(qp);
rxe_get(qp);

if (!qp->valid || qp->req.state == QP_STATE_ERROR ||
qp->req.state == QP_STATE_RESET) {
Expand Down Expand Up @@ -761,7 +761,7 @@ int rxe_completer(void *arg)
done:
if (pkt)
free_pkt(pkt);
rxe_drop_ref(qp);
rxe_put(qp);

return ret;
}
4 changes: 2 additions & 2 deletions drivers/infiniband/sw/rxe/rxe_mcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ static int __rxe_init_mca(struct rxe_qp *qp, struct rxe_mcg *mcg,

atomic_inc(&qp->mcg_num);

rxe_add_ref(qp);
rxe_get(qp);
mca->qp = qp;

list_add_tail(&mca->qp_list, &mcg->qp_list);
Expand Down Expand Up @@ -389,7 +389,7 @@ static void __rxe_cleanup_mca(struct rxe_mca *mca, struct rxe_mcg *mcg)
atomic_dec(&mcg->qp_num);
atomic_dec(&mcg->rxe->mcg_attach);
atomic_dec(&mca->qp->mcg_num);
rxe_drop_ref(mca->qp);
rxe_put(mca->qp);

kfree(mca);
}
Expand Down
14 changes: 7 additions & 7 deletions drivers/infiniband/sw/rxe/rxe_mr.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ int copy_data(

if (offset >= sge->length) {
if (mr) {
rxe_drop_ref(mr);
rxe_put(mr);
mr = NULL;
}
sge++;
Expand Down Expand Up @@ -504,13 +504,13 @@ int copy_data(
dma->resid = resid;

if (mr)
rxe_drop_ref(mr);
rxe_put(mr);

return 0;

err2:
if (mr)
rxe_drop_ref(mr);
rxe_put(mr);
err1:
return err;
}
Expand Down Expand Up @@ -569,7 +569,7 @@ struct rxe_mr *lookup_mr(struct rxe_pd *pd, int access, u32 key,
(type == RXE_LOOKUP_REMOTE && mr->rkey != key) ||
mr_pd(mr) != pd || (access && !(access & mr->access)) ||
mr->state != RXE_MR_STATE_VALID)) {
rxe_drop_ref(mr);
rxe_put(mr);
mr = NULL;
}

Expand Down Expand Up @@ -613,7 +613,7 @@ int rxe_invalidate_mr(struct rxe_qp *qp, u32 rkey)
ret = 0;

err_drop_ref:
rxe_drop_ref(mr);
rxe_put(mr);
err:
return ret;
}
Expand Down Expand Up @@ -690,8 +690,8 @@ int rxe_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata)
}

mr->state = RXE_MR_STATE_INVALID;
rxe_drop_ref(mr_pd(mr));
rxe_drop_ref(mr);
rxe_put(mr_pd(mr));
rxe_put(mr);

return 0;
}
Expand Down
30 changes: 15 additions & 15 deletions drivers/infiniband/sw/rxe/rxe_mw.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ int rxe_alloc_mw(struct ib_mw *ibmw, struct ib_udata *udata)
struct rxe_dev *rxe = to_rdev(ibmw->device);
int ret;

rxe_add_ref(pd);
rxe_get(pd);

ret = rxe_add_to_pool(&rxe->mw_pool, mw);
if (ret) {
rxe_drop_ref(pd);
rxe_put(pd);
return ret;
}

Expand All @@ -35,14 +35,14 @@ static void rxe_do_dealloc_mw(struct rxe_mw *mw)

mw->mr = NULL;
atomic_dec(&mr->num_mw);
rxe_drop_ref(mr);
rxe_put(mr);
}

if (mw->qp) {
struct rxe_qp *qp = mw->qp;

mw->qp = NULL;
rxe_drop_ref(qp);
rxe_put(qp);
}

mw->access = 0;
Expand All @@ -60,8 +60,8 @@ int rxe_dealloc_mw(struct ib_mw *ibmw)
rxe_do_dealloc_mw(mw);
spin_unlock_bh(&mw->lock);

rxe_drop_ref(mw);
rxe_drop_ref(pd);
rxe_put(mw);
rxe_put(pd);

return 0;
}
Expand Down Expand Up @@ -170,19 +170,19 @@ static void rxe_do_bind_mw(struct rxe_qp *qp, struct rxe_send_wqe *wqe,
mw->length = wqe->wr.wr.mw.length;

if (mw->mr) {
rxe_drop_ref(mw->mr);
rxe_put(mw->mr);
atomic_dec(&mw->mr->num_mw);
mw->mr = NULL;
}

if (mw->length) {
mw->mr = mr;
atomic_inc(&mr->num_mw);
rxe_add_ref(mr);
rxe_get(mr);
}

if (mw->ibmw.type == IB_MW_TYPE_2) {
rxe_add_ref(qp);
rxe_get(qp);
mw->qp = qp;
}
}
Expand Down Expand Up @@ -233,9 +233,9 @@ int rxe_bind_mw(struct rxe_qp *qp, struct rxe_send_wqe *wqe)
spin_unlock_bh(&mw->lock);
err_drop_mr:
if (mr)
rxe_drop_ref(mr);
rxe_put(mr);
err_drop_mw:
rxe_drop_ref(mw);
rxe_put(mw);
err:
return ret;
}
Expand All @@ -260,13 +260,13 @@ static void rxe_do_invalidate_mw(struct rxe_mw *mw)
/* valid type 2 MW will always have a QP pointer */
qp = mw->qp;
mw->qp = NULL;
rxe_drop_ref(qp);
rxe_put(qp);

/* valid type 2 MW will always have an MR pointer */
mr = mw->mr;
mw->mr = NULL;
atomic_dec(&mr->num_mw);
rxe_drop_ref(mr);
rxe_put(mr);

mw->access = 0;
mw->addr = 0;
Expand Down Expand Up @@ -301,7 +301,7 @@ int rxe_invalidate_mw(struct rxe_qp *qp, u32 rkey)
err_unlock:
spin_unlock_bh(&mw->lock);
err_drop_ref:
rxe_drop_ref(mw);
rxe_put(mw);
err:
return ret;
}
Expand All @@ -322,7 +322,7 @@ struct rxe_mw *rxe_lookup_mw(struct rxe_qp *qp, int access, u32 rkey)
(mw->length == 0) ||
(access && !(access & mw->access)) ||
mw->state != RXE_MW_STATE_VALID)) {
rxe_drop_ref(mw);
rxe_put(mw);
return NULL;
}

Expand Down
6 changes: 3 additions & 3 deletions drivers/infiniband/sw/rxe/rxe_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static void rxe_skb_tx_dtor(struct sk_buff *skb)
skb_out < RXE_INFLIGHT_SKBS_PER_QP_LOW))
rxe_run_task(&qp->req.task, 1);

rxe_drop_ref(qp);
rxe_put(qp);
}

static int rxe_send(struct sk_buff *skb, struct rxe_pkt_info *pkt)
Expand All @@ -358,7 +358,7 @@ static int rxe_send(struct sk_buff *skb, struct rxe_pkt_info *pkt)
skb->destructor = rxe_skb_tx_dtor;
skb->sk = pkt->qp->sk->sk;

rxe_add_ref(pkt->qp);
rxe_get(pkt->qp);
atomic_inc(&pkt->qp->skb_out);

if (skb->protocol == htons(ETH_P_IP)) {
Expand All @@ -368,7 +368,7 @@ static int rxe_send(struct sk_buff *skb, struct rxe_pkt_info *pkt)
} else {
pr_err("Unknown layer 3 protocol: %d\n", skb->protocol);
atomic_dec(&pkt->qp->skb_out);
rxe_drop_ref(pkt->qp);
rxe_put(pkt->qp);
kfree_skb(skb);
return -EINVAL;
}
Expand Down
8 changes: 3 additions & 5 deletions drivers/infiniband/sw/rxe/rxe_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_elem *elem);
/* lookup an indexed object from index. takes a reference on object */
void *rxe_pool_get_index(struct rxe_pool *pool, u32 index);

/* take a reference on an object */
int __rxe_get(struct rxe_pool_elem *elem);

#define rxe_add_ref(obj) __rxe_get(&(obj)->elem)
#define rxe_get(obj) __rxe_get(&(obj)->elem)

/* drop a reference on an object */
int __rxe_put(struct rxe_pool_elem *elem);

#define rxe_drop_ref(obj) __rxe_put(&(obj)->elem)
#define rxe_put(obj) __rxe_put(&(obj)->elem)

#define rxe_read_ref(obj) kref_read(&(obj)->elem.ref_cnt)
#define rxe_read(obj) kref_read(&(obj)->elem.ref_cnt)

#endif /* RXE_POOL_H */
28 changes: 14 additions & 14 deletions drivers/infiniband/sw/rxe/rxe_qp.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ int rxe_qp_from_init(struct rxe_dev *rxe, struct rxe_qp *qp, struct rxe_pd *pd,
struct rxe_cq *scq = to_rcq(init->send_cq);
struct rxe_srq *srq = init->srq ? to_rsrq(init->srq) : NULL;

rxe_add_ref(pd);
rxe_add_ref(rcq);
rxe_add_ref(scq);
rxe_get(pd);
rxe_get(rcq);
rxe_get(scq);
if (srq)
rxe_add_ref(srq);
rxe_get(srq);

qp->pd = pd;
qp->rcq = rcq;
Expand Down Expand Up @@ -359,10 +359,10 @@ int rxe_qp_from_init(struct rxe_dev *rxe, struct rxe_qp *qp, struct rxe_pd *pd,
qp->srq = NULL;

if (srq)
rxe_drop_ref(srq);
rxe_drop_ref(scq);
rxe_drop_ref(rcq);
rxe_drop_ref(pd);
rxe_put(srq);
rxe_put(scq);
rxe_put(rcq);
rxe_put(pd);

return err;
}
Expand Down Expand Up @@ -521,7 +521,7 @@ static void rxe_qp_reset(struct rxe_qp *qp)
qp->resp.sent_psn_nak = 0;

if (qp->resp.mr) {
rxe_drop_ref(qp->resp.mr);
rxe_put(qp->resp.mr);
qp->resp.mr = NULL;
}

Expand Down Expand Up @@ -809,20 +809,20 @@ static void rxe_qp_do_cleanup(struct work_struct *work)
rxe_queue_cleanup(qp->sq.queue);

if (qp->srq)
rxe_drop_ref(qp->srq);
rxe_put(qp->srq);

if (qp->rq.queue)
rxe_queue_cleanup(qp->rq.queue);

if (qp->scq)
rxe_drop_ref(qp->scq);
rxe_put(qp->scq);
if (qp->rcq)
rxe_drop_ref(qp->rcq);
rxe_put(qp->rcq);
if (qp->pd)
rxe_drop_ref(qp->pd);
rxe_put(qp->pd);

if (qp->resp.mr)
rxe_drop_ref(qp->resp.mr);
rxe_put(qp->resp.mr);

if (qp_type(qp) == IB_QPT_RC)
sk_dst_reset(qp->sk->sk);
Expand Down
8 changes: 4 additions & 4 deletions drivers/infiniband/sw/rxe/rxe_recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static int hdr_check(struct rxe_pkt_info *pkt)
return 0;

err2:
rxe_drop_ref(qp);
rxe_put(qp);
err1:
return -EINVAL;
}
Expand Down Expand Up @@ -288,11 +288,11 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)

cpkt = SKB_TO_PKT(cskb);
cpkt->qp = qp;
rxe_add_ref(qp);
rxe_get(qp);
rxe_rcv_pkt(cpkt, cskb);
} else {
pkt->qp = qp;
rxe_add_ref(qp);
rxe_get(qp);
rxe_rcv_pkt(pkt, skb);
skb = NULL; /* mark consumed */
}
Expand Down Expand Up @@ -397,7 +397,7 @@ void rxe_rcv(struct sk_buff *skb)

drop:
if (pkt->qp)
rxe_drop_ref(pkt->qp);
rxe_put(pkt->qp);

kfree_skb(skb);
ib_device_put(&rxe->ib_dev);
Expand Down
Loading

0 comments on commit 3197706

Please sign in to comment.