net: mscc: ocelot: install MAC addresses in .ndo_set_rx_mode from process context
authorVladimir Oltean <vladimir.oltean@nxp.com>
Sat, 12 Dec 2020 19:16:12 +0000 (21:16 +0200)
committerJakub Kicinski <kuba@kernel.org>
Tue, 15 Dec 2020 03:28:22 +0000 (19:28 -0800)
Currently ocelot_set_rx_mode calls ocelot_mact_learn directly, which has
a very nice ocelot_mact_wait_for_completion at the end. Introduced in
commit 639c1b2625af ("net: mscc: ocelot: Register poll timeout should be
wall time not attempts"), this function uses readx_poll_timeout which
triggers a lot of lockdep warnings and is also dangerous to use from
atomic context, potentially leading to lockups and panics.

Steen Hegelund added a poll timeout of 100 ms for checking the MAC
table, a duration which is clearly absurd to poll in atomic context.
So we need to defer the MAC table access to process context, which we do
via a dynamically allocated workqueue which contains all there is to
know about the MAC table operation it has to do.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Link: https://lore.kernel.org/r/20201212191612.222019-1-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mscc/ocelot.c
drivers/net/ethernet/mscc/ocelot_net.c
include/soc/mscc/ocelot.h

index abea8dd2b0cbbf70640941e2c708bb18b6fd0981..0b9992bd66262935f2c00adefdfe52f6cdd7d603 100644 (file)
@@ -1513,6 +1513,12 @@ int ocelot_init(struct ocelot *ocelot)
        if (!ocelot->stats_queue)
                return -ENOMEM;
 
+       ocelot->owq = alloc_ordered_workqueue("ocelot-owq", 0);
+       if (!ocelot->owq) {
+               destroy_workqueue(ocelot->stats_queue);
+               return -ENOMEM;
+       }
+
        INIT_LIST_HEAD(&ocelot->multicast);
        INIT_LIST_HEAD(&ocelot->pgids);
        ocelot_mact_init(ocelot);
@@ -1619,6 +1625,7 @@ void ocelot_deinit(struct ocelot *ocelot)
 {
        cancel_delayed_work(&ocelot->stats_work);
        destroy_workqueue(ocelot->stats_queue);
+       destroy_workqueue(ocelot->owq);
        mutex_destroy(&ocelot->stats_lock);
 }
 EXPORT_SYMBOL(ocelot_deinit);
index c65ae6f75a160593c3ab279877223bf85b99f313..2bd2840d88bdc89835f08a56fd7c35581492162c 100644 (file)
@@ -414,13 +414,81 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)
        return NETDEV_TX_OK;
 }
 
+enum ocelot_action_type {
+       OCELOT_MACT_LEARN,
+       OCELOT_MACT_FORGET,
+};
+
+struct ocelot_mact_work_ctx {
+       struct work_struct work;
+       struct ocelot *ocelot;
+       enum ocelot_action_type type;
+       union {
+               /* OCELOT_MACT_LEARN */
+               struct {
+                       unsigned char addr[ETH_ALEN];
+                       u16 vid;
+                       enum macaccess_entry_type entry_type;
+                       int pgid;
+               } learn;
+               /* OCELOT_MACT_FORGET */
+               struct {
+                       unsigned char addr[ETH_ALEN];
+                       u16 vid;
+               } forget;
+       };
+};
+
+#define ocelot_work_to_ctx(x) \
+       container_of((x), struct ocelot_mact_work_ctx, work)
+
+static void ocelot_mact_work(struct work_struct *work)
+{
+       struct ocelot_mact_work_ctx *w = ocelot_work_to_ctx(work);
+       struct ocelot *ocelot = w->ocelot;
+
+       switch (w->type) {
+       case OCELOT_MACT_LEARN:
+               ocelot_mact_learn(ocelot, w->learn.pgid, w->learn.addr,
+                                 w->learn.vid, w->learn.entry_type);
+               break;
+       case OCELOT_MACT_FORGET:
+               ocelot_mact_forget(ocelot, w->forget.addr, w->forget.vid);
+               break;
+       default:
+               break;
+       };
+
+       kfree(w);
+}
+
+static int ocelot_enqueue_mact_action(struct ocelot *ocelot,
+                                     const struct ocelot_mact_work_ctx *ctx)
+{
+       struct ocelot_mact_work_ctx *w = kmemdup(ctx, sizeof(*w), GFP_ATOMIC);
+
+       if (!w)
+               return -ENOMEM;
+
+       w->ocelot = ocelot;
+       INIT_WORK(&w->work, ocelot_mact_work);
+       queue_work(ocelot->owq, &w->work);
+
+       return 0;
+}
+
 static int ocelot_mc_unsync(struct net_device *dev, const unsigned char *addr)
 {
        struct ocelot_port_private *priv = netdev_priv(dev);
        struct ocelot_port *ocelot_port = &priv->port;
        struct ocelot *ocelot = ocelot_port->ocelot;
+       struct ocelot_mact_work_ctx w;
+
+       ether_addr_copy(w.forget.addr, addr);
+       w.forget.vid = ocelot_port->pvid_vlan.vid;
+       w.type = OCELOT_MACT_FORGET;
 
-       return ocelot_mact_forget(ocelot, addr, ocelot_port->pvid_vlan.vid);
+       return ocelot_enqueue_mact_action(ocelot, &w);
 }
 
 static int ocelot_mc_sync(struct net_device *dev, const unsigned char *addr)
@@ -428,9 +496,15 @@ static int ocelot_mc_sync(struct net_device *dev, const unsigned char *addr)
        struct ocelot_port_private *priv = netdev_priv(dev);
        struct ocelot_port *ocelot_port = &priv->port;
        struct ocelot *ocelot = ocelot_port->ocelot;
+       struct ocelot_mact_work_ctx w;
+
+       ether_addr_copy(w.learn.addr, addr);
+       w.learn.vid = ocelot_port->pvid_vlan.vid;
+       w.learn.pgid = PGID_CPU;
+       w.learn.entry_type = ENTRYTYPE_LOCKED;
+       w.type = OCELOT_MACT_LEARN;
 
-       return ocelot_mact_learn(ocelot, PGID_CPU, addr,
-                                ocelot_port->pvid_vlan.vid, ENTRYTYPE_LOCKED);
+       return ocelot_enqueue_mact_action(ocelot, &w);
 }
 
 static void ocelot_set_rx_mode(struct net_device *dev)
index 731116611390ff332a1f2531440a8c11910b64f1..2f4cd3288bccc5ab86e0c7584d29efc41a315a26 100644 (file)
@@ -650,6 +650,8 @@ struct ocelot {
        struct delayed_work             stats_work;
        struct workqueue_struct         *stats_queue;
 
+       struct workqueue_struct         *owq;
+
        u8                              ptp:1;
        struct ptp_clock                *ptp_clock;
        struct ptp_clock_info           ptp_info;