[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1432184707-27252-1-git-send-email-sfeldma@gmail.com>
Date: Wed, 20 May 2015 22:05:07 -0700
From: sfeldma@...il.com
To: netdev@...r.kernel.org
Cc: jiri@...nulli.us, simon.horman@...ronome.com,
makita.toshiaki@....ntt.co.jp
Subject: [PATCH net-next] rocker: move netevent neigh update to processes context
From: Scott Feldman <sfeldma@...il.com>
In review of Simon's patchset "rocker: transaction fixes". it was noted
that rocker->neigh_tbl_next_index was unprotected in the call path below
and could race with other contexts calling rocker_port_ipv4_neigh():
arp_process()
neigh_update()
rocker_neigh_update()
rocker_port_ipv4_neigh()
To fix, move the neigh_update() event processing to process contexts and
hold rtnl_lock to call rocker_port_ipv4_neigh(). This will protect
rocker->neigh_tbl_next_index accesses and is more consistent with the rest
of the driver code where non-I/O processing is done under process context
with rtnl_lock held.
Signed-off-by: Scott Feldman <sfeldma@...il.com>
---
drivers/net/ethernet/rocker/rocker.c | 52 +++++++++++++++++++++++++++++-----
1 file changed, 45 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/rocker/rocker.c b/drivers/net/ethernet/rocker/rocker.c
index 0f5e962..4cff2f6 100644
--- a/drivers/net/ethernet/rocker/rocker.c
+++ b/drivers/net/ethernet/rocker/rocker.c
@@ -5240,14 +5240,52 @@ static struct notifier_block rocker_netdevice_nb __read_mostly = {
* Net event notifier event handler
************************************/
-static int rocker_neigh_update(struct net_device *dev, struct neighbour *n)
+struct rocker_neigh_update_work {
+ struct work_struct work;
+ struct rocker_port *rocker_port;
+ int flags;
+ __be32 ip_addr;
+ unsigned char ha[ALIGN(MAX_ADDR_LEN, sizeof(unsigned long))];
+};
+
+static void rocker_event_neigh_update_work(struct work_struct *work)
{
- struct rocker_port *rocker_port = netdev_priv(dev);
- int flags = (n->nud_state & NUD_VALID) ? 0 : ROCKER_OP_FLAG_REMOVE;
- __be32 ip_addr = *(__be32 *)n->primary_key;
+ struct rocker_neigh_update_work *nw =
+ container_of(work, struct rocker_neigh_update_work, work);
+ int err;
+
+ rtnl_lock();
+ err = rocker_port_ipv4_neigh(nw->rocker_port, SWITCHDEV_TRANS_NONE,
+ nw->flags, nw->ip_addr, nw->ha);
+ rtnl_unlock();
+
+ if (err)
+ netdev_warn(nw->rocker_port->dev,
+ "failed to handle neigh %pI4 update (err %d)\n",
+ &nw->ip_addr, err);
- return rocker_port_ipv4_neigh(rocker_port, SWITCHDEV_TRANS_NONE,
- flags, ip_addr, n->ha);
+ kfree(work);
+}
+
+static int rocker_event_neigh_update(struct net_device *dev,
+ struct neighbour *n)
+{
+ struct rocker_neigh_update_work *nw;
+
+ nw = kmalloc(sizeof(*nw), GFP_ATOMIC);
+ if (!nw)
+ return -ENOMEM;
+
+ INIT_WORK(&nw->work, rocker_event_neigh_update_work);
+
+ nw->rocker_port = netdev_priv(dev);
+ nw->flags = (n->nud_state & NUD_VALID) ? 0 : ROCKER_OP_FLAG_REMOVE;
+ nw->ip_addr = *(__be32 *)n->primary_key;
+ memcpy(nw->ha, n->ha, sizeof(nw->ha));
+
+ schedule_work(&nw->work);
+
+ return 0;
}
static int rocker_netevent_event(struct notifier_block *unused,
@@ -5264,7 +5302,7 @@ static int rocker_netevent_event(struct notifier_block *unused,
dev = n->dev;
if (!rocker_port_dev_check(dev))
return NOTIFY_DONE;
- err = rocker_neigh_update(dev, n);
+ err = rocker_event_neigh_update(dev, n);
if (err)
netdev_warn(dev,
"failed to handle neigh update (err %d)\n",
--
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists