RDMA/rxe: Make multicast actually work
Subsystems (4)
cover RDMA/rxe: Make multicast actually work
After developing a test program which exercises node to node testing of RoCE multicast it bacame 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.
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 | 511 +++++++++++-------------- drivers/infiniband/sw/rxe/rxe_net.c | 27 +- 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, 285 insertions(+), 350 deletions(-)
Signature · 1 line
2.40.1
PATCH 2/6 RDMA/rxe: Handle loopback of mcast packets
Add a mask bit to indicate that a multicast packet has been locally sent and use to set the correct qpn for multicast packets.
Add code to rxe_xmit_packet() to correctly handle multicast packets which must be sent on the wire and also duplicated to any local qps which may belong the multicast group, but not including the sender.
--- drivers/infiniband/sw/rxe/rxe_av.c | 7 +++++++ drivers/infiniband/sw/rxe/rxe_loc.h | 1 + drivers/infiniband/sw/rxe/rxe_net.c | 25 ++++++++++++++++++++++++- 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, 46 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 +24 -1
@@ -412,6 +412,27 @@ 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 +452,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 4/6 RDMA/rxe: Let rxe_lookup_mcg use rcu_read_lock
In reply to Bob PearsonChange locking of read side operations of the multicast group red-black tree to use rcu read locking. This will allow changing the mcast lock in the next patch to be changed to a mutex without breaking rxe_recv.c.
--- drivers/infiniband/sw/rxe/rxe_mcast.c | 35 +++++++-------------------- drivers/infiniband/sw/rxe/rxe_verbs.h | 1 + 2 files changed, 10 insertions(+), 26 deletions(-)
drivers/infiniband/sw/rxe/rxe_mcast.c +9 -26
@@ -148,7 +148,7 @@ static void __rxe_insert_mcg(struct rxe_mcg *mcg) link = &(*link)->rb_right; } -rb_link_node (&mcg->node, node, link); +rb_link_node_rcu (&mcg->node, node, link);rb_insert_color (&mcg->node, tree); }
@@ -164,14 +164,13 @@ static void __rxe_remove_mcg(struct rxe_mcg *mcg) }/** -* __rxe_lookup_mcg - lookup mcg in rxe->mcg_tree while holding lock +* 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 */ -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;
@@ -179,7 +178,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);
@@ -187,12 +187,13 @@ 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 ; } +rcu_read_unlock ();if (node) {kref_get (&mcg->ref_cnt);
@@ -202,24 +203,6 @@ static struct rxe_mcg *__rxe_lookup_mcg(struct rxe_dev *rxe,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); - -return mcg; -} -/** * __rxe_init_mcg - initialize a new mcg * @rxe: rxe device
@@ -313,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 3/6 RDMA/rxe: Register IP mcast address
In reply to Bob PearsonAdd code to rxe_mcast_add() and rxe_mcast_del() to register/deregister the IP multicast address. This is required for multicast traffic to reach the rxe driver.
--- drivers/infiniband/sw/rxe/rxe_mcast.c | 110 +++++++++++++++++++++----- 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, 93 insertions(+), 21 deletions(-)
drivers/infiniband/sw/rxe/rxe_mcast.c +90 -20
@@ -19,38 +19,107 @@* 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) +/* register mcast IP and MAC addresses with net stack */ +static int rxe_mcast_add6 (struct rxe_dev *rxe,union ib_gid *mgid) {unsigned char ll_addr[ETH_ALEN ]; +struct in6_addr *addr6 = (struct in6_addr *)mgid; +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: +ipv6_sock_mc_drop (recv_sockets.sk6->sk, rxe->ndev->ifindex, addr6); +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; +struct ip_mreqn imr = {};unsigned char ll_addr[ETH_ALEN ]; +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: +ip_mc_leave_group (recv_sockets.sk4->sk, &imr); +err_out: +return err; +} + +/* deregister mcast IP and MAC addresses with net stack */ +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; +struct ip_mreqn imr = {}; +unsigned char ll_addr[ETH_ALEN ]; +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 +233,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 +295,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 +343,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
PATCH 1/6 RDMA/rxe: Cleanup rxe_ah/av_chk_attr
In reply to Bob PearsonReplace 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 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.
Use rcu to protect mcg_tree read side operations as set up in the previous patch. rxe_recv_mcast_pkt which does run in an atomic context now does not use the mcg_mutex lock.
--- drivers/infiniband/sw/rxe/rxe.c | 2 +- drivers/infiniband/sw/rxe/rxe_mcast.c | 256 ++++++++++---------------- drivers/infiniband/sw/rxe/rxe_recv.c | 5 +- drivers/infiniband/sw/rxe/rxe_verbs.h | 3 +- 4 files changed, 106 insertions(+), 160 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 +100 -156
366 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 6/6 RDMA/rxe: Cleanup mcg lifetime
In reply to Bob PearsonFix 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.
Also general code cleanup. Drop comments on statics, etc.
--- drivers/infiniband/sw/rxe/rxe_loc.h | 2 +- drivers/infiniband/sw/rxe/rxe_mcast.c | 190 ++++++++------------------ drivers/infiniband/sw/rxe/rxe_recv.c | 2 +- 3 files changed, 58 insertions(+), 136 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 +56 -134
323 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
Re: [PATCH for-next 2/6] RDMA/rxe: Handle loopback of mcast packets
In reply to Bob PearsonQuoted 53 lines · Bob Pearson
Add a mask bit to indicate that a multicast packet has been locally sent and use to set the correct qpn for multicast packets.
Add code to
rxe_xmit_packet()to correctly handle multicast packets which must be sent on the wire and also duplicated to any local qps which may belong the multicast group, but not including the sender.Fixes 6090a0c4c7c6 ("RDMA/rxe: Cleanup rxe_mcast.c")Signed-off-by Bob Pearson <[email protected]>--- drivers/infiniband/sw/rxe/rxe_av.c | 7 +++++++ drivers/infiniband/sw/rxe/rxe_loc.h | 1 + drivers/infiniband/sw/rxe/rxe_net.c | 25 ++++++++++++++++++++++++- 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, 46 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 +0
-0
drivers/infiniband/sw/rxe/rxe_net.c static int rxe_loopback(struct sk_buff *skb, struct rxe_pkt_info *pkt) · line 417
Quoted 6 lines
drivers/infiniband/sw/rxe/rxe_net.c +3
-0@@ -412,6 +412,27 @@ 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 +*/
https://www.kernel.org/doc/html/v4.15/process/coding-style.html
Please follow the preferred style for long (multi-line) comments in the above link.
Zhu Yanjun
Quoted 89 lines
drivers/infiniband/sw/rxe/rxe_net.c +21
-1+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 +452,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" );
Re: [PATCH for-next 3/6] RDMA/rxe: Register IP mcast address
In reply to Bob PearsonQuoted 29 lines · Bob Pearson
Add code to
rxe_mcast_add()andrxe_mcast_del()to register/deregister the IP multicast address. This is required for multicast traffic to reach the rxe driver.Fixes 6090a0c4c7c6 ("RDMA/rxe: Cleanup rxe_mcast.c")Signed-off-by Bob Pearson <[email protected]>--- drivers/infiniband/sw/rxe/rxe_mcast.c | 110 +++++++++++++++++++++----- 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, 93 insertions(+), 21 deletions(-)drivers/infiniband/sw/rxe/rxe_mcast.c +2
-4@@ -19,38 +19,107 @@* 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
drivers/infiniband/sw/rxe/rxe_mcast.c line 31
Quoted 10 lines
drivers/infiniband/sw/rxe/rxe_mcast.c +4
-4-* -* Returns 0 on success else an error -*/ -static int rxe_mcast_add (struct rxe_dev *rxe,union ib_gid *mgid) +/* register mcast IP and MAC addresses with net stack */ +static int rxe_mcast_add6 (struct rxe_dev *rxe,union ib_gid *mgid) {unsigned char ll_addr[ETH_ALEN ]; +struct in6_addr *addr6 = (struct in6_addr *)mgid; +int err;
Using reverse fir tree, a.k.a. reverse Christmas tree or reverse XMAS tree, for
variable declarations isn't strictly required, though it is still preferred.
Zhu Yanjun
Quoted 167 lines
drivers/infiniband/sw/rxe/rxe_mcast.c +84
-12+ +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: +ipv6_sock_mc_drop (recv_sockets.sk6->sk, rxe->ndev->ifindex, addr6); +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; +struct ip_mreqn imr = {};unsigned char ll_addr[ETH_ALEN ]; +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: +ip_mc_leave_group (recv_sockets.sk4->sk, &imr); +err_out: +return err; +} + +/* deregister mcast IP and MAC addresses with net stack */ +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; +struct ip_mreqn imr = {}; +unsigned char ll_addr[ETH_ALEN ]; +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 +233,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 +295,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 +343,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 {
Re: [PATCH for-next 3/6] RDMA/rxe: Register IP mcast address
Quoted 8 lines · Zhu Yanjun
Using reverse fir tree, a.k.a. reverse Christmas tree or reverse XMAS tree, for
variable declarations isn't strictly required, though it is still preferred.
Zhu Yanjun
Yeah. I usually follow that style for new code (except if there are dependencies) but mostly add new variables at the end of the list together because it makes the patch simpler to read. At least it does for me. If you care, I am happy to fix this.
Bob
Re: [PATCH for-next 3/6] RDMA/rxe: Register IP mcast address
Quoted 9 lines · Bob Pearson
Quoted 5 lines · Zhu Yanjun
Using reverse fir tree, a.k.a. reverse Christmas tree or reverse XMAS tree, for
variable declarations isn't strictly required, though it is still preferred.
Quoted 7 lines
Quoted 3 lines
Zhu Yanjun
Yeah. I usually follow that style for new code (except if there are dependencies) but mostly add new variables at the end of the list together because it makes the patch simpler to read. At least it does for me. If you care, I am happy to fix this.
Yes. It is good to fix it.
And your commits add mcast address supports. And I think you
should have the test case in the rdma-core to verify these commits.
Can you share the test case in the rdma maillist? ^_^
Zhu Yanjun
Quoted 2 lines
Bob
Re: [PATCH for-next 3/6] RDMA/rxe: Register IP mcast address
Quoted 21 lines · Zhu Yanjun
Quoted 9 lines · Bob Pearson
Quoted 5 lines · Zhu Yanjun
Using reverse fir tree, a.k.a. reverse Christmas tree or reverse XMAS tree, for
variable declarations isn't strictly required, though it is still preferred.
Quoted 7 lines
Quoted 3 lines
Zhu Yanjun
Yeah. I usually follow that style for new code (except if there are dependencies) but mostly add new variables at the end of the list together because it makes the patch simpler to read. At least it does for me. If you care, I am happy to fix this.
Yes. It is good to fix it.
Quoted 10 lines
And your commits add mcast address supports. And I think you
should have the test case in the rdma-core to verify these commits.
Can you share the test case in the rdma maillist? ^_^
Zhu Yanjun
Quoted 2 lines
Bob
I could share it but it's not really in a good shape to publish. I have to modify the limits in rxe_param.h to test max_etc. And currently I need to hand edit the send/recv versions to do node to node. In other words just enough to (by hand) work through the use cases enough to convince myself it works using ip maddr and wireshark along with the program.
What you are asking for is a bunch of work to make the test program more like iperf or ib_send_bw. Ideally it should either reload the driver or do something else to let each test case be a clean start.
In an ideal world there would be a two node version of pyverbs. :-)
Bob
Re: [PATCH for-next 3/6] RDMA/rxe: Register IP mcast address
Quoted 42 lines · Bob Pearson
Quoted 21 lines · Zhu Yanjun
Quoted 9 lines · Bob Pearson
Quoted 5 lines · Zhu Yanjun
Using reverse fir tree, a.k.a. reverse Christmas tree or reverse XMAS tree, for
variable declarations isn't strictly required, though it is still preferred.
Quoted 7 lines
Quoted 3 lines
Zhu Yanjun
Yeah. I usually follow that style for new code (except if there are dependencies) but mostly add new variables at the end of the list together because it makes the patch simpler to read. At least it does for me. If you care, I am happy to fix this.
Yes. It is good to fix it.
Quoted 10 lines
And your commits add mcast address supports. And I think you
should have the test case in the rdma-core to verify these commits.
Can you share the test case in the rdma maillist? ^_^
Zhu Yanjun
Quoted 2 lines
Bob
I could share it but it's not really in a good shape to publish. I have to modify the limits in
rxe_param.hto testmax_etc. And currently I need to hand edit the send/recv versions to do node to node. In other words just enough to (by hand) work through the use cases enough to convince myself it works using ip maddr and wireshark along with the program.
Quoted 3 lines
What you are asking for is a bunch of work to make the test program more like iperf or
ib_send_bw. Ideally it should either reload the driver or do something else to let each test case be a clean start.
Got it.
Anyway, a test case in rdma-core is needed to make tests with this feature.
And this feature is related with mcast. So please also send these commits to NETDEV maillist. NETDEV people can also give us a lot of good advice.
Thanks,
Zhu Yanjun
Quoted 4 lines
In an ideal world there would be a two node version of pyverbs. :-)
Bob