Ok I refactored the whole thing to make it less invasive and keep more functionality in ipoib_multicast.c. Since you are working on it it would be best for you to have the newest version. I split this into two patches: One preparatory and one that implements the actual logic. Both attached. The patch that implements the join is inline here:
Subject: ipoib multicast: Expire MC groups when the address expires Upon address expiration do the proper thing to also expire the sendonly multicast group. Signed-off-by: Christoph Lameter <c...@linux.com> Index: linux/drivers/infiniband/ulp/ipoib/ipoib.h =================================================================== --- linux.orig/drivers/infiniband/ulp/ipoib/ipoib.h 2015-09-28 11:56:59.779764388 -0500 +++ linux/drivers/infiniband/ulp/ipoib/ipoib.h 2015-09-28 11:57:16.291764857 -0500 @@ -548,6 +548,8 @@ int ipoib_mcast_attach(struct net_device *dev, u16 mlid, union ib_gid *mgid, int set_qkey); +void ipoib_mcast_remove_mc_list(struct net_device *dev, struct list_head *list); +void ipoib_mcast_detach_sendonly(struct ipoib_dev_priv *priv, u8 *mgid, struct list_head *list); int ipoib_init_qp(struct net_device *dev); int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca); Index: linux/drivers/infiniband/ulp/ipoib/ipoib_main.c =================================================================== --- linux.orig/drivers/infiniband/ulp/ipoib/ipoib_main.c 2015-09-28 11:56:59.779764388 -0500 +++ linux/drivers/infiniband/ulp/ipoib/ipoib_main.c 2015-09-28 11:56:59.775764388 -0500 @@ -1149,6 +1149,8 @@ unsigned long dt; unsigned long flags; int i; + LIST_HEAD(remove_list); + struct net_device *dev = priv->dev; if (test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags)) return; @@ -1176,6 +1178,9 @@ lockdep_is_held(&priv->lock))) != NULL) { /* was the neigh idle for two GC periods */ if (time_after(neigh_obsolete, neigh->alive)) { + + ipoib_mcast_detach_sendonly(priv, neigh->daddr + 4, &remove_list); + rcu_assign_pointer(*np, rcu_dereference_protected(neigh->hnext, lockdep_is_held(&priv->lock))); @@ -1191,6 +1196,7 @@ out_unlock: spin_unlock_irqrestore(&priv->lock, flags); + ipoib_mcast_remove_mc_list(dev, &remove_list); } static void ipoib_reap_neigh(struct work_struct *work) Index: linux/drivers/infiniband/ulp/ipoib/ipoib_multicast.c =================================================================== --- linux.orig/drivers/infiniband/ulp/ipoib/ipoib_multicast.c 2015-09-28 11:56:59.779764388 -0500 +++ linux/drivers/infiniband/ulp/ipoib/ipoib_multicast.c 2015-09-28 11:56:59.775764388 -0500 @@ -800,6 +800,23 @@ } } +/* + * Check if this is a sendonly multicast group. If so remove it from the list and put it + * onto the given list for final removal. + */ +void ipoib_mcast_detach_sendonly(struct ipoib_dev_priv *priv, u8 *mgid, struct list_head *remove_list) +{ + struct ipoib_mcast *mcast; + + /* Is this multicast ? */ + if (mcast_auto_create && *mgid == 0xff) { + mcast = __ipoib_mcast_find(priv->dev, mgid); + + if (mcast && test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) + ipoib_detach_mc_group(priv, mcast, remove_list); + } +} + void ipoib_mcast_dev_flush(struct net_device *dev) { struct ipoib_dev_priv *priv = netdev_priv(dev);
From: Christoph Lameter <c...@linux.com> Subject: ipoib multicast: Extract two function from ipoib_mcast_flush We need these two functions later to do the implicit leave when the address handle expires so refactor the code. Signed-off-by: Christoph Lameter <c...@linux.com> Index: linux/drivers/infiniband/ulp/ipoib/ipoib_multicast.c =================================================================== --- linux.orig/drivers/infiniband/ulp/ipoib/ipoib_multicast.c 2015-09-28 11:20:05.387701463 -0500 +++ linux/drivers/infiniband/ulp/ipoib/ipoib_multicast.c 2015-09-28 11:20:53.819702839 -0500 @@ -775,6 +775,31 @@ spin_unlock_irqrestore(&priv->lock, flags); } +/* + * Detach a multicast group from the devices multicast tree and move it + * to a list for future removal + */ +static void ipoib_detach_mc_group(struct ipoib_dev_priv *priv, + struct ipoib_mcast *mcast, struct list_head *remove_list) +{ + list_del(&mcast->list); + rb_erase(&mcast->rb_node, &priv->multicast_tree); + list_add_tail(&mcast->list, remove_list); +} + +/* + * Remove a list of multicast groups that has been detached and free them + */ +void ipoib_mcast_remove_mc_list(struct net_device *dev, struct list_head *remove_list) +{ + struct ipoib_mcast *mcast, *tmcast; + + list_for_each_entry_safe(mcast, tmcast, remove_list, list) { + ipoib_mcast_leave(dev, mcast); + ipoib_mcast_free(mcast); + } +} + void ipoib_mcast_dev_flush(struct net_device *dev) { struct ipoib_dev_priv *priv = netdev_priv(dev); @@ -786,11 +811,8 @@ spin_lock_irqsave(&priv->lock, flags); - list_for_each_entry_safe(mcast, tmcast, &priv->multicast_list, list) { - list_del(&mcast->list); - rb_erase(&mcast->rb_node, &priv->multicast_tree); - list_add_tail(&mcast->list, &remove_list); - } + list_for_each_entry_safe(mcast, tmcast, &priv->multicast_list, list) + ipoib_detach_mc_group(priv, mcast, &remove_list); if (priv->broadcast) { rb_erase(&priv->broadcast->rb_node, &priv->multicast_tree); @@ -808,10 +830,7 @@ if (test_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags)) wait_for_completion(&mcast->done); - list_for_each_entry_safe(mcast, tmcast, &remove_list, list) { - ipoib_mcast_leave(dev, mcast); - ipoib_mcast_free(mcast); - } + ipoib_mcast_remove_mc_list(dev, &remove_list); } static int ipoib_mcast_addr_is_valid(const u8 *addr, const u8 *broadcast)
Subject: ipoib multicast: Expire MC groups when the address expires Upon address expiration do the proper thing to also expire the sendonly multicast group. Signed-off-by: Christoph Lameter <c...@linux.com> Index: linux/drivers/infiniband/ulp/ipoib/ipoib.h =================================================================== --- linux.orig/drivers/infiniband/ulp/ipoib/ipoib.h 2015-09-28 11:56:59.779764388 -0500 +++ linux/drivers/infiniband/ulp/ipoib/ipoib.h 2015-09-28 11:57:16.291764857 -0500 @@ -548,6 +548,8 @@ int ipoib_mcast_attach(struct net_device *dev, u16 mlid, union ib_gid *mgid, int set_qkey); +void ipoib_mcast_remove_mc_list(struct net_device *dev, struct list_head *list); +void ipoib_mcast_detach_sendonly(struct ipoib_dev_priv *priv, u8 *mgid, struct list_head *list); int ipoib_init_qp(struct net_device *dev); int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca); Index: linux/drivers/infiniband/ulp/ipoib/ipoib_main.c =================================================================== --- linux.orig/drivers/infiniband/ulp/ipoib/ipoib_main.c 2015-09-28 11:56:59.779764388 -0500 +++ linux/drivers/infiniband/ulp/ipoib/ipoib_main.c 2015-09-28 11:56:59.775764388 -0500 @@ -1149,6 +1149,8 @@ unsigned long dt; unsigned long flags; int i; + LIST_HEAD(remove_list); + struct net_device *dev = priv->dev; if (test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags)) return; @@ -1176,6 +1178,9 @@ lockdep_is_held(&priv->lock))) != NULL) { /* was the neigh idle for two GC periods */ if (time_after(neigh_obsolete, neigh->alive)) { + + ipoib_mcast_detach_sendonly(priv, neigh->daddr + 4, &remove_list); + rcu_assign_pointer(*np, rcu_dereference_protected(neigh->hnext, lockdep_is_held(&priv->lock))); @@ -1191,6 +1196,7 @@ out_unlock: spin_unlock_irqrestore(&priv->lock, flags); + ipoib_mcast_remove_mc_list(dev, &remove_list); } static void ipoib_reap_neigh(struct work_struct *work) Index: linux/drivers/infiniband/ulp/ipoib/ipoib_multicast.c =================================================================== --- linux.orig/drivers/infiniband/ulp/ipoib/ipoib_multicast.c 2015-09-28 11:56:59.779764388 -0500 +++ linux/drivers/infiniband/ulp/ipoib/ipoib_multicast.c 2015-09-28 11:56:59.775764388 -0500 @@ -800,6 +800,23 @@ } } +/* + * Check if this is a sendonly multicast group. If so remove it from the list and put it + * onto the given list for final removal. + */ +void ipoib_mcast_detach_sendonly(struct ipoib_dev_priv *priv, u8 *mgid, struct list_head *remove_list) +{ + struct ipoib_mcast *mcast; + + /* Is this multicast ? */ + if (mcast_auto_create && *mgid == 0xff) { + mcast = __ipoib_mcast_find(priv->dev, mgid); + + if (mcast && test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) + ipoib_detach_mc_group(priv, mcast, remove_list); + } +} + void ipoib_mcast_dev_flush(struct net_device *dev) { struct ipoib_dev_priv *priv = netdev_priv(dev);