From: sfeldma@gmail.com
To: netdev@vger.kernel.org
Cc: jiri@resnulli.us, simon.horman@netronome.com,
makita.toshiaki@lab.ntt.co.jp
Subject: [PATCH net-next] rocker: move netevent neigh update to processes context
Date: Wed, 20 May 2015 22:05:07 -0700 [thread overview]
Message-ID: <1432184707-27252-1-git-send-email-sfeldma@gmail.com> (raw)
From: Scott Feldman <sfeldma@gmail.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@gmail.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
next reply other threads:[~2015-05-21 5:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-21 5:05 sfeldma [this message]
2015-05-21 7:37 ` [PATCH net-next] rocker: move netevent neigh update to processes context Simon Horman
2015-05-21 8:00 ` Jiri Pirko
2015-05-21 8:53 ` Toshiaki Makita
2015-05-22 3:29 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1432184707-27252-1-git-send-email-sfeldma@gmail.com \
--to=sfeldma@gmail.com \
--cc=jiri@resnulli.us \
--cc=makita.toshiaki@lab.ntt.co.jp \
--cc=netdev@vger.kernel.org \
--cc=simon.horman@netronome.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).