Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

IB/core: Use qp->usecnt to track multicast attach/detach

Just as we don't allow PDs, CQs, etc. to be destroyed if there are QPs
that are attached to them, don't let a QP be destroyed if there are
multicast group(s) attached to it. Use the existing usecnt field of
struct ib_qp which was added by commit 0e0ec7e ("RDMA/core: Export
ib_open_qp() to share XRC TGT QPs") to track this.

Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>

authored by

Or Gerlitz and committed by
Roland Dreier
c3bccbfb d48b97b4

+13 -3
+12 -2
drivers/infiniband/core/verbs.c
··· 1183 1183 1184 1184 int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid) 1185 1185 { 1186 + int ret; 1187 + 1186 1188 if (!qp->device->attach_mcast) 1187 1189 return -ENOSYS; 1188 1190 if (gid->raw[0] != 0xff || qp->qp_type != IB_QPT_UD) 1189 1191 return -EINVAL; 1190 1192 1191 - return qp->device->attach_mcast(qp, gid, lid); 1193 + ret = qp->device->attach_mcast(qp, gid, lid); 1194 + if (!ret) 1195 + atomic_inc(&qp->usecnt); 1196 + return ret; 1192 1197 } 1193 1198 EXPORT_SYMBOL(ib_attach_mcast); 1194 1199 1195 1200 int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid) 1196 1201 { 1202 + int ret; 1203 + 1197 1204 if (!qp->device->detach_mcast) 1198 1205 return -ENOSYS; 1199 1206 if (gid->raw[0] != 0xff || qp->qp_type != IB_QPT_UD) 1200 1207 return -EINVAL; 1201 1208 1202 - return qp->device->detach_mcast(qp, gid, lid); 1209 + ret = qp->device->detach_mcast(qp, gid, lid); 1210 + if (!ret) 1211 + atomic_dec(&qp->usecnt); 1212 + return ret; 1203 1213 } 1204 1214 EXPORT_SYMBOL(ib_detach_mcast); 1205 1215
+1 -1
include/rdma/ib_verbs.h
··· 964 964 struct ib_srq *srq; 965 965 struct ib_xrcd *xrcd; /* XRC TGT QPs only */ 966 966 struct list_head xrcd_list; 967 - atomic_t usecnt; /* count times opened */ 967 + atomic_t usecnt; /* count times opened, mcast attaches */ 968 968 struct list_head open_list; 969 969 struct ib_qp *real_qp; 970 970 struct ib_uobject *uobject;