RDMA/rxe: Make multicast work
Subsystems (2)
v2 cover RDMA/rxe: Make multicast work
After developing a test program which exercises node to node testing of RoCE multicast it became clear that there are a number of issues with the current rdma_rxe multicast implementation.
The issues seen include:
- There is no support for IPV4 multicast addresses.
- Once a multicast MAC is added it is not removed.
- Multicast packets are sent with the wrong QP number.
- Multicast packets sent from the local node are not loopbacked to local QPs which have joined the same multicast group and were not the sender.
- Multicast IP addresses are not created and without them no multicast packets received on the interface are delivered to the rdma_rxe driver.
- The implementation in rxe_mcast.c is potentially racy if multiple simultaneous attach/detach operations are issued.
This patch set fixes these issues.
---
v2:
Respond to comments by Zhu.
Added more Fixes lines.
Added some more explanation in the commit messages. Fixed an error in rxe_lookup_mcg. Should have checked
the return from rxe_get_mcg().
Bob Pearson (6):
RDMA/rxe: Cleanup rxe_ah/av_chk_attr
RDMA/rxe: Handle loopback of mcast packets
RDMA/rxe: Register IP mcast address
RDMA/rxe: Let rxe_lookup_mcg use rcu_read_lock
RDMA/rxe: Split multicast lock
RDMA/rxe: Cleanup mcg lifetime
drivers/infiniband/sw/rxe/rxe.c | 2 +- drivers/infiniband/sw/rxe/rxe_av.c | 50 +-- drivers/infiniband/sw/rxe/rxe_loc.h | 6 +- drivers/infiniband/sw/rxe/rxe_mcast.c | 519 +++++++++++-------------- drivers/infiniband/sw/rxe/rxe_net.c | 28 +- drivers/infiniband/sw/rxe/rxe_net.h | 1 + drivers/infiniband/sw/rxe/rxe_opcode.h | 2 +- drivers/infiniband/sw/rxe/rxe_qp.c | 4 +- drivers/infiniband/sw/rxe/rxe_recv.c | 11 +- drivers/infiniband/sw/rxe/rxe_req.c | 11 +- drivers/infiniband/sw/rxe/rxe_verbs.c | 5 +- drivers/infiniband/sw/rxe/rxe_verbs.h | 5 +- 12 files changed, 288 insertions(+), 356 deletions(-)
Signature · 1 line
2.40.1
PATCH v2 1/6 RDMA/rxe: Cleanup rxe_ah/av_chk_attr
Replace rxe_ah_chk_attr() and rxe_av_chk_attr() by a single routine rxe_chk_ah_attr().
--- drivers/infiniband/sw/rxe/rxe_av.c | 43 ++++----------------------- drivers/infiniband/sw/rxe/rxe_loc.h | 3 +- drivers/infiniband/sw/rxe/rxe_qp.c | 4 +-- drivers/infiniband/sw/rxe/rxe_verbs.c | 5 ++-- 4 files changed, 12 insertions(+), 43 deletions(-)
drivers/infiniband/sw/rxe/rxe_av.c +6 -37
@@ -14,45 +14,24 @@ void rxe_init_av(struct rdma_ah_attr *attr, struct rxe_av *av)memcpy (av->dmac, attr->roce.dmac,ETH_ALEN ); } -static int chk_attr (void *obj,struct rdma_ah_attr *attr,bool obj_is_ah) +int rxe_chk_ah_attr (struct rxe_dev *rxe,struct rdma_ah_attr *attr) {const struct ib_global_route *grh =rdma_ah_read_grh (attr); -struct rxe_port *port; -struct rxe_dev *rxe; -struct rxe_qp *qp; -struct rxe_ah *ah; +struct rxe_port *port = &rxe->port;int type; -if (obj_is_ah) { - ah = obj; - rxe =to_rdev (ah->ibah.device); - }else { - qp = obj; - rxe =to_rdev (qp->ibqp.device); - } - - port = &rxe->port; -if (rdma_ah_get_ah_flags (attr) &IB_AH_GRH ) {if (grh->sgid_index > port->attr.gid_tbl_len) { -if (obj_is_ah) -rxe_dbg_ah (ah,"invalid sgid index = %d\n" , - grh->sgid_index); -else -rxe_dbg_qp (qp,"invalid sgid index = %d\n" , - grh->sgid_index); +rxe_dbg_dev (rxe,"invalid sgid index = %d\n" , + grh->sgid_index);return -EINVAL ; } type =rdma_gid_attr_network_type (grh->sgid_attr);if (type <RDMA_NETWORK_IPV4 || type >RDMA_NETWORK_IPV6 ) { -if (obj_is_ah) -rxe_dbg_ah (ah,"invalid network type for rdma_rxe = %d\n" , - type); -else -rxe_dbg_qp (qp,"invalid network type for rdma_rxe = %d\n" , - type); +rxe_dbg_dev (rxe,"invalid network type for rdma_rxe = %d\n" , + type);return -EINVAL ; } }
@@ -60,16 +39,6 @@ static int chk_attr(void *obj, struct rdma_ah_attr *attr, bool obj_is_ah)return 0 ; } -int rxe_av_chk_attr (struct rxe_qp *qp,struct rdma_ah_attr *attr) -{ -return chk_attr (qp, attr, false); -} - -int rxe_ah_chk_attr (struct rxe_ah *ah,struct rdma_ah_attr *attr) -{ -return chk_attr (ah, attr, true); -} -void rxe_av_from_attr (u8 port_num,struct rxe_av *av,struct rdma_ah_attr *attr) {
drivers/infiniband/sw/rxe/rxe_loc.h +1 -2
@@ -9,8 +9,7 @@/* rxe_av.c */ void rxe_init_av (struct rdma_ah_attr *attr,struct rxe_av *av); -int rxe_av_chk_attr (struct rxe_qp *qp,struct rdma_ah_attr *attr); -int rxe_ah_chk_attr (struct rxe_ah *ah,struct rdma_ah_attr *attr); +int rxe_chk_ah_attr (struct rxe_dev *rxe,struct rdma_ah_attr *attr);void rxe_av_from_attr (u8 port_num,struct rxe_av *av,struct rdma_ah_attr *attr);void rxe_av_to_attr (struct rxe_av *av,struct rdma_ah_attr *attr);
drivers/infiniband/sw/rxe/rxe_qp.c +2 -2
@@ -456,11 +456,11 @@ int rxe_qp_chk_attr(struct rxe_dev *rxe, struct rxe_qp *qp, goto err1; } -if (mask &IB_QP_AV &&rxe_av_chk_attr (qp, &attr->ah_attr)) +if (mask &IB_QP_AV &&rxe_chk_ah_attr (rxe, &attr->ah_attr)) goto err1;if (mask &IB_QP_ALT_PATH ) { -if (rxe_av_chk_attr (qp, &attr->alt_ah_attr)) +if (rxe_chk_ah_attr (rxe, &attr->alt_ah_attr)) goto err1;if (!rdma_is_port_valid (&rxe->ib_dev, attr->alt_port_num)) {rxe_dbg_qp (qp,"invalid alt port %d\n" , attr->alt_port_num);
drivers/infiniband/sw/rxe/rxe_verbs.c +3 -2
@@ -286,7 +286,7 @@ static int rxe_create_ah(struct ib_ah *ibah,/* create index > 0 */ ah->ah_num = ah->elem.index; - err =rxe_ah_chk_attr (ah, init_attr->ah_attr); + err =rxe_chk_ah_attr (rxe, init_attr->ah_attr);if (err) {rxe_dbg_ah (ah,"bad attr" ); goto err_cleanup;
@@ -322,10 +322,11 @@ static int rxe_create_ah(struct ib_ah *ibah,static int rxe_modify_ah (struct ib_ah *ibah,struct rdma_ah_attr *attr) { +struct rxe_dev *rxe =to_rdev (ibah->device);struct rxe_ah *ah =to_rah (ibah);int err; - err =rxe_ah_chk_attr (ah, attr); + err =rxe_chk_ah_attr (rxe, attr);if (err) {rxe_dbg_ah (ah,"bad attr" ); goto err_out;
Signature · 1 line
2.40.1
PATCH v2 2/6 RDMA/rxe: Handle loopback of mcast packets
In reply to Bob PearsonCurrently the rdma_rxe driver does not send mcast packets correctly. It does not loop mcast packets back to local qp's which belong to the same mcast group. It also uses the wrong qp number for the packets.
Add code to rxe_xmit_packet() to correctly handle mcast packets which must be sent on the wire and also duplicated to any local qp's which may belong the mcast group, but not including the sender.
Add a mask bit to indicate that a multicast packet has been locally sent and use to set the correct qpn for multicast packets and identify mcast packets when sending.
--- drivers/infiniband/sw/rxe/rxe_av.c | 7 +++++++ drivers/infiniband/sw/rxe/rxe_loc.h | 1 + drivers/infiniband/sw/rxe/rxe_net.c | 26 +++++++++++++++++++++++++- drivers/infiniband/sw/rxe/rxe_opcode.h | 2 +- drivers/infiniband/sw/rxe/rxe_recv.c | 4 ++++ drivers/infiniband/sw/rxe/rxe_req.c | 11 +++++++++-- 6 files changed, 47 insertions(+), 4 deletions(-)
drivers/infiniband/sw/rxe/rxe_av.c +7 -0
@@ -7,6 +7,13 @@#include "rxe.h" #include "rxe_loc.h" +bool rxe_is_mcast_av (struct rxe_av *av) +{ +struct in6_addr *daddr = (struct in6_addr *)av->grh.dgid.raw; + +return rdma_is_multicast_addr (daddr); +} +void rxe_init_av (struct rdma_ah_attr *attr,struct rxe_av *av) {rxe_av_from_attr (rdma_ah_get_port_num (attr), av, attr);
drivers/infiniband/sw/rxe/rxe_loc.h +1 -0
@@ -8,6 +8,7 @@#define RXE_LOC_H /* rxe_av.c */ +bool rxe_is_mcast_av (struct rxe_av *av);void rxe_init_av (struct rdma_ah_attr *attr,struct rxe_av *av);int rxe_chk_ah_attr (struct rxe_dev *rxe,struct rdma_ah_attr *attr); void rxe_av_from_attr(u8 port_num, struct rxe_av *av,
drivers/infiniband/sw/rxe/rxe_net.c +25 -1
@@ -412,6 +412,28 @@ static int rxe_loopback(struct sk_buff *skb, struct rxe_pkt_info *pkt)return 0 ; } +/* +* For a multicast packet, must send remotely and looback to any local qps +* that may belong to the mcast group. +*/ +static int rxe_loop_and_send (struct sk_buff *skb,struct rxe_pkt_info *pkt) +{ +struct sk_buff *cskb; +int err, loc_err =0 ; + +if (atomic_read (&pkt->rxe->mcg_num)) { + loc_err = -ENOMEM ; + cskb =skb_clone (skb,GFP_KERNEL ); +if (cskb) + loc_err =rxe_loopback (cskb, pkt); + } + + err =rxe_send (skb, pkt); +if (loc_err) + err = loc_err; +return err; +} +int rxe_xmit_packet (struct rxe_qp *qp,struct rxe_pkt_info *pkt,struct sk_buff *skb) {
@@ -431,7 +453,9 @@ int rxe_xmit_packet(struct rxe_qp *qp, struct rxe_pkt_info *pkt,rxe_icrc_generate (skb, pkt); -if (pkt->mask &RXE_LOOPBACK_MASK ) +if (pkt->mask &RXE_MCAST_MASK ) + err =rxe_loop_and_send (skb, pkt); +else if (pkt->mask &RXE_LOOPBACK_MASK ) err =rxe_loopback (skb, pkt);else err =rxe_send (skb, pkt);
drivers/infiniband/sw/rxe/rxe_opcode.h +1 -1
@@ -85,7 +85,7 @@ enum rxe_hdr_mask {RXE_END_MASK =BIT (NUM_HDR_TYPES +11 ),RXE_LOOPBACK_MASK =BIT (NUM_HDR_TYPES +12 ), - +RXE_MCAST_MASK =BIT (NUM_HDR_TYPES +13 ),RXE_ATOMIC_WRITE_MASK =BIT (NUM_HDR_TYPES +14 ), RXE_READ_OR_ATOMIC_MASK = (RXE_READ_MASK | RXE_ATOMIC_MASK),
drivers/infiniband/sw/rxe/rxe_recv.c +4 -0
@@ -217,6 +217,10 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)list_for_each_entry (mca, &mcg->qp_list, qp_list) { qp = mca->qp; +/* don't reply packet to sender if locally sent */ +if (pkt->mask &RXE_MCAST_MASK &&qp_num (qp) ==deth_sqp (pkt)) +continue ; +/* validate qp for incoming packet */ err =check_type_state (rxe, pkt, qp);if (err)
drivers/infiniband/sw/rxe/rxe_req.c +9 -2
@@ -442,8 +442,12 @@ static struct sk_buff *init_req_packet(struct rxe_qp *qp, (pkt->mask & (RXE_WRITE_MASK |RXE_IMMDT_MASK )) == (RXE_WRITE_MASK | RXE_IMMDT_MASK)); - qp_num = (pkt->mask &RXE_DETH_MASK ) ? ibwr->wr.ud.remote_qpn : - qp->attr.dest_qp_num; +if (pkt->mask &RXE_MCAST_MASK ) + qp_num =IB_MULTICAST_QPN ; +else if (pkt->mask &RXE_DETH_MASK ) + qp_num = ibwr->wr.ud.remote_qpn; +else + qp_num = qp->attr.dest_qp_num; ack_req = ((pkt->mask &RXE_END_MASK ) || (qp->req.noack_pkts++ >RXE_MAX_PKT_PER_ACK ));
@@ -809,6 +813,9 @@ int rxe_requester(struct rxe_qp *qp) goto err; } +if (rxe_is_mcast_av (av)) + pkt.mask |=RXE_MCAST_MASK ; + skb =init_req_packet (qp, av, wqe, opcode, payload, &pkt);if (unlikely (!skb)) {rxe_dbg_qp (qp,"Failed allocating skb\n" );
Signature · 1 line
2.40.1
PATCH v2 3/6 RDMA/rxe: Register IP mcast address
In reply to Bob PearsonCurrently the rdma_rxe driver does not receive mcast packets at all.
Add code to rxe_mcast_add() and rxe_mcast_del() to register/deregister the IP mcast address. This is required for mcast traffic to reach the rxe driver when coming from an external source.
--- drivers/infiniband/sw/rxe/rxe_mcast.c | 112 +++++++++++++++++++++----- drivers/infiniband/sw/rxe/rxe_net.c | 2 +- drivers/infiniband/sw/rxe/rxe_net.h | 1 + drivers/infiniband/sw/rxe/rxe_verbs.h | 1 + 4 files changed, 95 insertions(+), 21 deletions(-)
drivers/infiniband/sw/rxe/rxe_mcast.c +92 -20
@@ -19,38 +19,109 @@* mcast packets in the rxe receive path. */ +#include <linux/igmp.h> +#include "rxe.h" -/** -* rxe_mcast_add - add multicast address to rxe device -* @rxe: rxe device object -* @mgid: multicast address as a gid -* -* Returns 0 on success else an error -*/ -static int rxe_mcast_add (struct rxe_dev *rxe,union ib_gid *mgid) +static int rxe_mcast_add6 (struct rxe_dev *rxe,union ib_gid *mgid) { +struct in6_addr *addr6 = (struct in6_addr *)mgid;unsigned char ll_addr[ETH_ALEN ]; +int err; + +rtnl_lock (); + err =ipv6_sock_mc_join (recv_sockets.sk6->sk, rxe->ndev->ifindex, + addr6); +rtnl_unlock (); +if (err && err != -EADDRINUSE ) + goto err_out;ipv6_eth_mc_map ((struct in6_addr *)mgid->raw, ll_addr); + err =dev_mc_add (rxe->ndev, ll_addr); +if (err) + goto err_drop; + +return 0 ; -return dev_mc_add (rxe->ndev, ll_addr); +err_drop: +rtnl_lock (); +ipv6_sock_mc_drop (recv_sockets.sk6->sk, rxe->ndev->ifindex, addr6); +rtnl_unlock (); +err_out: +return err; } -/** -* rxe_mcast_del - delete multicast address from rxe device -* @rxe: rxe device object -* @mgid: multicast address as a gid -* -* Returns 0 on success else an error -*/ -static int rxe_mcast_del (struct rxe_dev *rxe,union ib_gid *mgid) +static int rxe_mcast_add (struct rxe_mcg *mcg) { +struct rxe_dev *rxe = mcg->rxe; +union ib_gid *mgid = &mcg->mgid;unsigned char ll_addr[ETH_ALEN ]; +struct ip_mreqn imr = {}; +int err; + +if (mcg->is_ipv6) +return rxe_mcast_add6 (rxe, mgid); + + imr.imr_multiaddr = *(struct in_addr *)(mgid->raw +12 ); + imr.imr_ifindex = rxe->ndev->ifindex; +rtnl_lock (); + err =ip_mc_join_group (recv_sockets.sk4->sk, &imr); +rtnl_unlock (); +if (err && err != -EADDRINUSE ) + goto err_out; + +ip_eth_mc_map (imr.imr_multiaddr.s_addr, ll_addr); + err =dev_mc_add (rxe->ndev, ll_addr); +if (err) + goto err_leave; + +return 0 ; + +err_leave: +rtnl_lock (); +ip_mc_leave_group (recv_sockets.sk4->sk, &imr); +rtnl_unlock (); +err_out: +return err; +} + +static int rxe_mcast_del6 (struct rxe_dev *rxe,union ib_gid *mgid) +{ +unsigned char ll_addr[ETH_ALEN ]; +int err, err2;ipv6_eth_mc_map ((struct in6_addr *)mgid->raw, ll_addr); + err =dev_mc_del (rxe->ndev, ll_addr); + +rtnl_lock (); + err2 =ipv6_sock_mc_drop (recv_sockets.sk6->sk, + rxe->ndev->ifindex, (struct in6_addr *)mgid); +rtnl_unlock (); + +return err ?: err2; +} + +static int rxe_mcast_del (struct rxe_mcg *mcg) +{ +struct rxe_dev *rxe = mcg->rxe; +union ib_gid *mgid = &mcg->mgid; +unsigned char ll_addr[ETH_ALEN ]; +struct ip_mreqn imr = {}; +int err, err2; + +if (mcg->is_ipv6) +return rxe_mcast_del6 (rxe, mgid); + + imr.imr_multiaddr = *(struct in_addr *)(mgid->raw +12 ); + imr.imr_ifindex = rxe->ndev->ifindex; +ip_eth_mc_map (imr.imr_multiaddr.s_addr, ll_addr); + err =dev_mc_del (rxe->ndev, ll_addr); + +rtnl_lock (); + err2 =ip_mc_leave_group (recv_sockets.sk4->sk, &imr); +rtnl_unlock (); -return dev_mc_del (rxe->ndev, ll_addr); +return err ?: err2; }/**
@@ -164,6 +235,7 @@ static void __rxe_init_mcg(struct rxe_dev *rxe, union ib_gid *mgid, {kref_init (&mcg->ref_cnt);memcpy (&mcg->mgid, mgid,sizeof (mcg->mgid)); + mcg->is_ipv6 = !ipv6_addr_v4mapped ((struct in6_addr *)mgid);INIT_LIST_HEAD (&mcg->qp_list); mcg->rxe = rxe;
@@ -225,7 +297,7 @@ static struct rxe_mcg *rxe_get_mcg(struct rxe_dev *rxe, union ib_gid *mgid)spin_unlock_bh (&rxe->mcg_lock);/* add mcast address outside of lock */ - err =rxe_mcast_add (rxe, mgid); + err =rxe_mcast_add (mcg);if (!err)return mcg;
@@ -273,7 +345,7 @@ static void __rxe_destroy_mcg(struct rxe_mcg *mcg)static void rxe_destroy_mcg (struct rxe_mcg *mcg) {/* delete mcast address outside of lock */ -rxe_mcast_del (mcg->rxe, &mcg->mgid); +rxe_mcast_del (mcg);spin_lock_bh (&mcg->rxe->mcg_lock);__rxe_destroy_mcg (mcg);
drivers/infiniband/sw/rxe/rxe_net.c +1 -1
@@ -18,7 +18,7 @@#include "rxe_net.h" #include "rxe_loc.h" -static struct rxe_recv_sockets recv_sockets; +struct rxe_recv_sockets recv_sockets; static struct dst_entry *rxe_find_route4(struct rxe_qp *qp, struct net_device *ndev,
drivers/infiniband/sw/rxe/rxe_net.h +1 -0
@@ -15,6 +15,7 @@ struct rxe_recv_sockets {struct socket *sk4;struct socket *sk6; }; +extern struct rxe_recv_sockets recv_sockets;int rxe_net_add (const char *ibdev_name,struct net_device *ndev);
drivers/infiniband/sw/rxe/rxe_verbs.h +1 -0
@@ -352,6 +352,7 @@ struct rxe_mcg {atomic_t qp_num;u32 qkey;u16 pkey; +bool is_ipv6; };struct rxe_mca {
Signature · 1 line
2.40.1
kernel test robot
build botRe: [PATCH for-next v2 3/6] RDMA/rxe: Register IP mcast address
kernel test robot noticed the following build errors:
Hi Bob,
kernel test robot noticed the following build errors:
[auto build test ERROR on rdma/for-next]
[also build test ERROR on linus/master v6.6 next-20231107] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bob-Pearson/RDMA-rxe-Cleanup-rxe_ah-av_chk_attr/20231107-005913 base: https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git for-next patch link: https://lore.kernel.org/r/20231106152928.47869-4-rpearsonhpe%40gmail.com patch subject: [PATCH for-next v2 3/6] RDMA/rxe: Register IP mcast address config: csky-randconfig-002-20231107 (https://download.01.org/0day-ci/archive/20231108/[email protected]/config) compiler: csky-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231108/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
csky-linux-ld: drivers/infiniband/sw/rxe/rxe_mcast.o: in function `rxe_mcast_add':
>> rxe_mcast.c:(.text+0x42): undefined reference to `ipv6_sock_mc_join' >> csky-linux-ld: rxe_mcast.c:(.text+0xa6): undefined reference to `ipv6_sock_mc_drop' csky-linux-ld: drivers/infiniband/sw/rxe/rxe_mcast.o: in function `__rxe_init_mca': rxe_mcast.c:(.text+0x1a8): undefined reference to `ipv6_sock_mc_join' csky-linux-ld: rxe_mcast.c:(.text+0x1b4): undefined reference to `ipv6_sock_mc_drop' csky-linux-ld: drivers/infiniband/sw/rxe/rxe_mcast.o: in function `rxe_attach_mcast': >> rxe_mcast.c:(.text+0x5d6): undefined reference to `ipv6_sock_mc_drop'
csky-linux-ld: rxe_mcast.c:(.text+0x60c): undefined reference to `ipv6_sock_mc_drop'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v2 4/6 RDMA/rxe: Let rxe_lookup_mcg use rcu_read_lock
In reply to Bob PearsonChange locking of read side operations of the mcast group red-black tree to use rcu read locking. This will allow changing the mcast lock in the next patch to be a mutex without breaking rxe_recv.c which runs in an atomic state. It is also a better implementation than the current use of a spin-lock per rdma device since receiving mcast packets will be much more common than registering/deregistering mcast groups.
--- drivers/infiniband/sw/rxe/rxe_mcast.c | 59 +++++++++------------------ drivers/infiniband/sw/rxe/rxe_verbs.h | 1 + 2 files changed, 21 insertions(+), 39 deletions(-)
drivers/infiniband/sw/rxe/rxe_mcast.c +20 -39
@@ -144,13 +144,18 @@ static void __rxe_insert_mcg(struct rxe_mcg *mcg) tmp = rb_entry(node, struct rxe_mcg, node); cmp =memcmp (&tmp->mgid, &mcg->mgid,sizeof (mcg->mgid)); -if (cmp >0 ) +if (cmp >0 ) { link = &(*link)->rb_left; -else + }else if (cmp <0 ) { link = &(*link)->rb_right; + }else { +/* we must delete the old mcg before adding one */ +WARN_ON_ONCE (1 ); +return ; + } } -rb_link_node (&mcg->node, node, link); +rb_link_node_rcu (&mcg->node, node, link);rb_insert_color (&mcg->node, tree); }
@@ -165,15 +170,11 @@ static void __rxe_remove_mcg(struct rxe_mcg *mcg)rb_erase (&mcg->node, &mcg->rxe->mcg_tree); } -/** -* __rxe_lookup_mcg - lookup mcg in rxe->mcg_tree while holding lock -* @rxe: rxe device object -* @mgid: multicast IP address -* -* Context: caller must hold rxe->mcg_lock -* Returns: mcg on success and takes a ref to mcg else NULL +/* +* Lookup mgid in the multicast group red-black tree and try to +* get a ref on it. Return mcg on success else NULL. */ -static struct rxe_mcg *__rxe_lookup_mcg (struct rxe_dev *rxe, +struct rxe_mcg *rxe_lookup_mcg (struct rxe_dev *rxe,union ib_gid *mgid) {struct rb_root *tree = &rxe->mcg_tree;
@@ -181,7 +182,8 @@ static struct rxe_mcg *__rxe_lookup_mcg(struct rxe_dev *rxe,struct rb_node *node;int cmp; - node = tree->rb_node; +rcu_read_lock (); + node =rcu_dereference_raw (tree->rb_node);while (node) { mcg = rb_entry(node, struct rxe_mcg, node);
@@ -189,35 +191,14 @@ static struct rxe_mcg *__rxe_lookup_mcg(struct rxe_dev *rxe, cmp =memcmp (&mcg->mgid, mgid,sizeof (*mgid));if (cmp >0 ) - node = node->rb_left; + node =rcu_dereference_raw (node->rb_left);else if (cmp <0 ) - node = node->rb_right; + node =rcu_dereference_raw (node->rb_right);else break ; } - -if (node) { -kref_get (&mcg->ref_cnt); -return mcg; - } - -return NULL ; -} - -/** -* rxe_lookup_mcg - lookup up mcg in red-back tree -* @rxe: rxe device object -* @mgid: multicast IP address -* -* Returns: mcg if found else NULL -*/ -struct rxe_mcg *rxe_lookup_mcg (struct rxe_dev *rxe,union ib_gid *mgid) -{ -struct rxe_mcg *mcg; - -spin_lock_bh (&rxe->mcg_lock); - mcg =__rxe_lookup_mcg (rxe, mgid); -spin_unlock_bh (&rxe->mcg_lock); + mcg = (node &&kref_get_unless_zero (&mcg->ref_cnt)) ? mcg :NULL ; +rcu_read_unlock ();return mcg; }
@@ -285,7 +266,7 @@ static struct rxe_mcg *rxe_get_mcg(struct rxe_dev *rxe, union ib_gid *mgid)spin_lock_bh (&rxe->mcg_lock);/* re-check to see if someone else just added it */ - tmp =__rxe_lookup_mcg (rxe, mgid); + tmp =rxe_lookup_mcg (rxe, mgid);if (tmp) {spin_unlock_bh (&rxe->mcg_lock);atomic_dec (&rxe->mcg_num);
@@ -315,7 +296,7 @@ void rxe_cleanup_mcg(struct kref *kref) {struct rxe_mcg *mcg =container_of (kref,typeof (*mcg), ref_cnt); -kfree (mcg); +kfree_rcu (mcg, rcu); }/**
drivers/infiniband/sw/rxe/rxe_verbs.h +1 -0
@@ -345,6 +345,7 @@ struct rxe_mw {struct rxe_mcg {struct rb_node node; +struct rcu_head rcu;struct kref ref_cnt;struct rxe_dev *rxe;struct list_head qp_list;
Signature · 1 line
2.40.1
PATCH v2 5/6 RDMA/rxe: Split multicast lock
In reply to Bob PearsonSplit rxe->mcg_lock into two locks. One to protect mcg->qp_list and one to protect rxe->mcg_tree (red-black tree) write side operations and provide serialization between rxe_attach_mcast and rxe_detach_mcast.
Make the qp_list lock a spin_lock_irqsave lock and move to the mcg struct. It protects the qp_list from simultaneous access from rxe_mcast.c and rxe_recv.c when processing incoming multi- cast packets. In theory some ethernet driver could bypass NAPI so an irq lock is better than a bh lock.
Make the mcg_tree lock a mutex since the attach/detach APIs are not called in atomic context. This allows some significant cleanup since we can call kzalloc while holding the mutex so some recheck code can be eliminated.
--- drivers/infiniband/sw/rxe/rxe.c | 2 +- drivers/infiniband/sw/rxe/rxe_mcast.c | 254 ++++++++++---------------- drivers/infiniband/sw/rxe/rxe_recv.c | 5 +- drivers/infiniband/sw/rxe/rxe_verbs.h | 3 +- 4 files changed, 105 insertions(+), 159 deletions(-)
drivers/infiniband/sw/rxe/rxe.c +1 -1
@@ -142,7 +142,7 @@ static void rxe_init(struct rxe_dev *rxe)INIT_LIST_HEAD (&rxe->pending_mmaps);/* init multicast support */ -spin_lock_init (&rxe->mcg_lock); +mutex_init (&rxe->mcg_mutex); rxe->mcg_tree =RB_ROOT ;mutex_init (&rxe->usdev_lock);
drivers/infiniband/sw/rxe/rxe_mcast.c +99 -155
365 lines not on this page · raw message
drivers/infiniband/sw/rxe/rxe_recv.c +3 -2
@@ -194,6 +194,7 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)struct rxe_mca *mca;struct rxe_qp *qp;union ib_gid dgid; +unsigned long flags;int err;if (skb->protocol ==htons (ETH_P_IP ))
@@ -207,7 +208,7 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)if (!mcg) goto drop;/* mcast group not registered */ -spin_lock_bh (&rxe->mcg_lock); +spin_lock_irqsave (&mcg->lock, flags);/* this is unreliable datagram service so we let * failures to deliver a multicast packet to a
@@ -259,7 +260,7 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb) } } -spin_unlock_bh (&rxe->mcg_lock); +spin_unlock_irqrestore (&mcg->lock, flags);kref_put (&mcg->ref_cnt, rxe_cleanup_mcg);
drivers/infiniband/sw/rxe/rxe_verbs.h +2 -1
@@ -351,6 +351,7 @@ struct rxe_mcg {struct list_head qp_list;union ib_gid mgid;atomic_t qp_num; +spinlock_t lock;/* protect qp_list */ u32 qkey;u16 pkey;bool is_ipv6;
@@ -390,7 +391,7 @@ struct rxe_dev {struct rxe_pool mw_pool;/* multicast support */ -spinlock_t mcg_lock; +struct mutex mcg_mutex;struct rb_root mcg_tree;atomic_t mcg_num;atomic_t mcg_attach;
Signature · 1 line
2.40.1
PATCH v2 6/6 RDMA/rxe: Cleanup mcg lifetime
In reply to Bob PearsonCurrently the rdma_rxe driver has two different and not really compatible ways of managing the lifetime of an mcast group, by ref counting the mcg struct and counting the number of attached qp's. They are each doing part of the job of cleaning up an mcg when the last qp is detached and are racy in the process. This patch removes using the use of the number of qp's.
Fix up mcg reference counting so the ref count will drop to zero correctly and move code from rxe_destroy_mcg to rxe_cleanup_mcg since rxe_destroy is no longer needed.
This set of fixes scrambles the code in rxe_mast.c and as a result a lot of cleanup has been done as well.
--- drivers/infiniband/sw/rxe/rxe_loc.h | 2 +- drivers/infiniband/sw/rxe/rxe_mcast.c | 170 +++++++------------------- drivers/infiniband/sw/rxe/rxe_recv.c | 2 +- 3 files changed, 46 insertions(+), 128 deletions(-)
drivers/infiniband/sw/rxe/rxe_loc.h +1 -1
@@ -37,7 +37,7 @@ void rxe_cq_cleanup(struct rxe_pool_elem *elem);struct rxe_mcg *rxe_lookup_mcg (struct rxe_dev *rxe,union ib_gid *mgid);int rxe_attach_mcast (struct ib_qp *ibqp,union ib_gid *mgid,u16 mlid);int rxe_detach_mcast (struct ib_qp *ibqp,union ib_gid *mgid,u16 mlid); -void rxe_cleanup_mcg (struct kref *kref); +int rxe_put_mcg (struct rxe_mcg *mcg);/* rxe_mmap.c */ struct rxe_mmap_info {
drivers/infiniband/sw/rxe/rxe_mcast.c +44 -126
290 lines not on this page · raw message
drivers/infiniband/sw/rxe/rxe_recv.c +1 -1
@@ -262,7 +262,7 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)spin_unlock_irqrestore (&mcg->lock, flags); -kref_put (&mcg->ref_cnt, rxe_cleanup_mcg); +rxe_put_mcg (mcg);if (likely (!skb))return ;
Signature · 1 line
2.40.1
kernel test robot
build botRe: [PATCH for-next v2 6/6] RDMA/rxe: Cleanup mcg lifetime
kernel test robot noticed the following build errors:
Hi Bob,
kernel test robot noticed the following build errors:
[auto build test ERROR on rdma/for-next]
[also build test ERROR on linus/master v6.6 next-20231107] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bob-Pearson/RDMA-rxe-Cleanup-rxe_ah-av_chk_attr/20231107-005913 base: https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git for-next patch link: https://lore.kernel.org/r/20231106152928.47869-7-rpearsonhpe%40gmail.com patch subject: [PATCH for-next v2 6/6] RDMA/rxe: Cleanup mcg lifetime config: csky-randconfig-002-20231107 (https://download.01.org/0day-ci/archive/20231108/[email protected]/config) compiler: csky-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231108/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
csky-linux-ld: drivers/infiniband/sw/rxe/rxe_mcast.o: in function `rxe_mcast_add':
rxe_mcast.c:(.text+0x42): undefined reference to `ipv6_sock_mc_join'
csky-linux-ld: rxe_mcast.c:(.text+0xa6): undefined reference to `ipv6_sock_mc_drop'
csky-linux-ld: drivers/infiniband/sw/rxe/rxe_mcast.o: in function `rxe_cleanup_mcg':
rxe_mcast.c:(.text+0x1a4): undefined reference to `ipv6_sock_mc_drop'
>> csky-linux-ld: rxe_mcast.c:(.text+0x1b8): undefined reference to `ipv6_sock_mc_join'
csky-linux-ld: rxe_mcast.c:(.text+0x1c4): undefined reference to `ipv6_sock_mc_drop'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki