Bugfixes in Microsemi Ocelot switch driver
Subsystems (4)
Vladimir Oltean
maintainerPATCH 4/7 net: mscc: ocelot: check for errors on memory allocation of ports
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Do not proceed probing if we couldn't allocate memory for the ports array, just error out.
--- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/mscc/ocelot_vsc7514.c +2 -0
@@ -993,6 +993,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev) ocelot->ports =devm_kcalloc (&pdev->dev, ocelot->num_phys_ports,sizeof (struct ocelot_port *),GFP_KERNEL ); +if (!ocelot->ports) +return -ENOMEM ; ocelot->vcap_is2_keys = vsc7514_vcap_is2_keys; ocelot->vcap_is2_actions = vsc7514_vcap_is2_actions;
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH 2/7 net: mscc: ocelot: add locking for the port TX timestamp ID
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
The ocelot_port->ts_id is used to:
- populate skb->cb[0] for matching the TX timestamp in the PTP IRQ with an skb.
- populate the REW_OP from the injection header of the ongoing skb. Only then is ocelot_port->ts_id incremented.
This is a problem because, at least theoretically, another timestampable skb might use the same ocelot_port->ts_id before that is incremented. So the logic of using and incrementing the timestamp id should be atomic per port.
The solution is to use the global ocelot_port->ts_id only while protected by the associated ocelot_port->ts_id_lock. That's where we populate skb->cb[0]. Note that for ocelot, ocelot_port_add_txtstamp_skb() is called for the actual skb, but for felix, it is called for the skb's clone. That is something which will also be changed.
--- drivers/net/ethernet/mscc/ocelot.c | 13 ++++++++++++- drivers/net/ethernet/mscc/ocelot_net.c | 6 ++---- include/soc/mscc/ocelot.h | 1 + net/dsa/tag_ocelot.c | 11 +++++++---- 4 files changed, 22 insertions(+), 9 deletions(-)
drivers/net/ethernet/mscc/ocelot.c +12 -1
@@ -421,10 +421,15 @@ int ocelot_port_add_txtstamp_skb(struct ocelot_port *ocelot_port,if (ocelot->ptp && shinfo->tx_flags &SKBTX_HW_TSTAMP && ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) { +spin_lock (&ocelot_port->ts_id_lock); + shinfo->tx_flags |=SKBTX_IN_PROGRESS ;/* Store timestamp ID in cb[0] of sk_buff */ - skb->cb[0 ] = ocelot_port->ts_id %4 ; + skb->cb[0 ] = ocelot_port->ts_id; + ocelot_port->ts_id = (ocelot_port->ts_id +1 ) %4 ;skb_queue_tail (&ocelot_port->tx_skbs, skb); + +spin_unlock (&ocelot_port->ts_id_lock);return 0 ; }return -ENODATA ;
@@ -1443,6 +1448,12 @@ int ocelot_init(struct ocelot *ocelot)if (!ocelot->stats_queue)return -ENOMEM ; +for (port =0 ; port < ocelot->num_phys_ports; port++) { +struct ocelot_port *ocelot_port = ocelot->ports[port]; + +spin_lock_init (&ocelot_port->ts_id_lock); + } +INIT_LIST_HEAD (&ocelot->multicast);ocelot_mact_init (ocelot);ocelot_vlan_init (ocelot);
drivers/net/ethernet/mscc/ocelot_net.c +2 -4
@@ -349,10 +349,8 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)if (ocelot->ptp && shinfo->tx_flags &SKBTX_HW_TSTAMP ) { info.rew_op = ocelot_port->ptp_cmd; -if (ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) { - info.rew_op |= (ocelot_port->ts_id %4 ) <<3 ; - ocelot_port->ts_id++; - } +if (ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) + info.rew_op |= skb->cb[0 ] <<3 ; }ocelot_gen_ifh (ifh, &info);
include/soc/mscc/ocelot.h +1 -0
@@ -566,6 +566,7 @@ struct ocelot_port {u8 ptp_cmd;struct sk_buff_head tx_skbs;u8 ts_id; +spinlock_t ts_id_lock;phy_interface_t phy_mode;
net/dsa/tag_ocelot.c +7 -4
@@ -160,11 +160,14 @@ static struct sk_buff *ocelot_xmit(struct sk_buff *skb,packing (injection, &qos_class,19 ,17 ,OCELOT_TAG_LEN ,PACK ,0 );if (ocelot->ptp && (skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP )) { +struct sk_buff *clone =DSA_SKB_CB (skb)->clone; + rew_op = ocelot_port->ptp_cmd; -if (ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) { - rew_op |= (ocelot_port->ts_id %4 ) <<3 ; - ocelot_port->ts_id++; - } +/* Retrieve timestamp ID populated inside skb->cb[0] of the +* clone by ocelot_port_add_txtstamp_skb +*/ +if (ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) + rew_op |= clone->cb[0 ] <<3 ;packing (injection, &rew_op,125 ,117 ,OCELOT_TAG_LEN ,PACK ,0 ); }
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH 5/7 net: mscc: ocelot: error checking when calling ocelot_init()
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
ocelot_init() allocates memory, resets the switch and polls for a status register, things which can fail. Stop probing the driver in that case, and propagate the error result.
--- drivers/net/dsa/ocelot/felix.c | 5 ++++- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/net/dsa/ocelot/felix.c +4 -1
@@ -571,7 +571,10 @@ static int felix_setup(struct dsa_switch *ds)if (err)return err; -ocelot_init (ocelot); + err =ocelot_init (ocelot); +if (err) +return err; +if (ocelot->ptp) { err =ocelot_init_timestamp (ocelot, &ocelot_ptp_clock_info);if (err) {
drivers/net/ethernet/mscc/ocelot_vsc7514.c +4 -1
@@ -1000,7 +1000,10 @@ static int mscc_ocelot_probe(struct platform_device *pdev) ocelot->vcap_is2_actions = vsc7514_vcap_is2_actions; ocelot->vcap = vsc7514_vcap_props; -ocelot_init (ocelot); + err =ocelot_init (ocelot); +if (err) +return err; +if (ocelot->ptp) { err =ocelot_init_timestamp (ocelot, &ocelot_ptp_clock_info);if (err) {
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH 7/7 net: mscc: ocelot: unregister net devices on unbind
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
This driver was not unregistering its network interfaces on unbind. Now it is.
--- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/net/ethernet/mscc/ocelot_vsc7514.c +22 -0
@@ -896,6 +896,26 @@ static struct ptp_clock_info ocelot_ptp_clock_info = { .enable = ocelot_ptp_enable, }; +static void mscc_ocelot_release_ports (struct ocelot *ocelot) +{ +int port; + +for (port =0 ; port < ocelot->num_phys_ports; port++) { +struct ocelot_port_private *priv; +struct ocelot_port *ocelot_port; + + ocelot_port = ocelot->ports[port]; +if (!ocelot_port) +continue ; + + priv = container_of(ocelot_port, struct ocelot_port_private, + port); + +unregister_netdev (priv->dev); +free_netdev (priv->dev); + } +} +static int mscc_ocelot_init_ports (struct platform_device *pdev) {struct ocelot *ocelot =platform_get_drvdata (pdev);
@@ -1008,6 +1028,7 @@ static int mscc_ocelot_init_ports(struct platform_device *pdev) out_put_ports:of_node_put (ports); +mscc_ocelot_release_ports (ocelot);return err; }
@@ -1132,6 +1153,7 @@ static int mscc_ocelot_remove(struct platform_device *pdev)struct ocelot *ocelot =platform_get_drvdata (pdev);ocelot_deinit_timestamp (ocelot); +mscc_ocelot_release_ports (ocelot);ocelot_deinit (ocelot);unregister_switchdev_blocking_notifier (&ocelot_switchdev_blocking_nb);unregister_switchdev_notifier (&ocelot_switchdev_nb);
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH 6/7 net: mscc: ocelot: refactor ports parsing code into a dedicated function
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
mscc_ocelot_probe() is already pretty large and hard to follow. So move the code for parsing ports in a separate function.
This makes it easier for the next patch to just call mscc_ocelot_release_ports from the error path of mscc_ocelot_init_ports.
--- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 223 +++++++++++---------- 1 file changed, 118 insertions(+), 105 deletions(-)
drivers/net/ethernet/mscc/ocelot_vsc7514.c +118 -105
@@ -896,123 +896,26 @@ static struct ptp_clock_info ocelot_ptp_clock_info = { .enable = ocelot_ptp_enable, }; -static int mscc_ocelot_probe (struct platform_device *pdev) +static int mscc_ocelot_init_ports (struct platform_device *pdev) { -struct device_node *np = pdev->dev.of_node; +struct ocelot *ocelot =platform_get_drvdata (pdev); +struct device_node *np = ocelot->dev->of_node;struct device_node *ports, *portnp; -int err, irq_xtr, irq_ptp_rdy; -struct ocelot *ocelot; -struct regmap *hsio; -unsigned int i; - -struct { -enum ocelot_target id; -char *name; -u8 optional:1 ; - } io_target[] = { - {SYS ,"sys" }, - {REW ,"rew" }, - {QSYS ,"qsys" }, - {ANA ,"ana" }, - {QS ,"qs" }, - {S2 ,"s2" }, - {PTP ,"ptp" ,1 }, - }; - -if (!np && !pdev->dev.platform_data) -return -ENODEV ; - - ocelot =devm_kzalloc (&pdev->dev,sizeof (*ocelot),GFP_KERNEL ); -if (!ocelot) -return -ENOMEM ; - -platform_set_drvdata (pdev, ocelot); - ocelot->dev = &pdev->dev; - -for (i =0 ; i <ARRAY_SIZE (io_target); i++) { -struct regmap *target; -struct resource *res; - - res =platform_get_resource_byname (pdev,IORESOURCE_MEM , - io_target[i].name); - - target =ocelot_regmap_init (ocelot, res); -if (IS_ERR (target)) { -if (io_target[i].optional) { - ocelot->targets[io_target[i].id] =NULL ; -continue ; - } -return PTR_ERR (target); - } - - ocelot->targets[io_target[i].id] = target; - } - - hsio =syscon_regmap_lookup_by_compatible ("mscc,ocelot-hsio" ); -if (IS_ERR (hsio)) { -dev_err (&pdev->dev,"missing hsio syscon\n" ); -return PTR_ERR (hsio); - } - - ocelot->targets[HSIO ] = hsio; - - err =ocelot_chip_init (ocelot, &ocelot_ops); -if (err) -return err; - - irq_xtr =platform_get_irq_byname (pdev,"xtr" ); -if (irq_xtr <0 ) -return -ENODEV ; - - err =devm_request_threaded_irq (&pdev->dev, irq_xtr,NULL , - ocelot_xtr_irq_handler,IRQF_ONESHOT , -"frame extraction" , ocelot); -if (err) -return err; - - irq_ptp_rdy =platform_get_irq_byname (pdev,"ptp_rdy" ); -if (irq_ptp_rdy >0 && ocelot->targets[PTP ]) { - err =devm_request_threaded_irq (&pdev->dev, irq_ptp_rdy,NULL , - ocelot_ptp_rdy_irq_handler, -IRQF_ONESHOT ,"ptp ready" , - ocelot); -if (err) -return err; - -/* Both the PTP interrupt and the PTP bank are available */ - ocelot->ptp =1 ; - } +int err; ports =of_get_child_by_name (np,"ethernet-ports" );if (!ports) { -dev_err (&pdev->dev,"no ethernet-ports child node found\n" ); +dev_err (ocelot->dev,"no ethernet-ports child node found\n" );return -ENODEV ; } ocelot->num_phys_ports =of_get_child_count (ports); - ocelot->ports =devm_kcalloc (&pdev->dev, ocelot->num_phys_ports, + ocelot->ports =devm_kcalloc (ocelot->dev, ocelot->num_phys_ports,sizeof (struct ocelot_port *),GFP_KERNEL );if (!ocelot->ports)return -ENOMEM ; - ocelot->vcap_is2_keys = vsc7514_vcap_is2_keys; - ocelot->vcap_is2_actions = vsc7514_vcap_is2_actions; - ocelot->vcap = vsc7514_vcap_props; - - err =ocelot_init (ocelot); -if (err) -return err; - -if (ocelot->ptp) { - err =ocelot_init_timestamp (ocelot, &ocelot_ptp_clock_info); -if (err) { -dev_err (ocelot->dev, -"Timestamp initialization failed\n" ); - ocelot->ptp =0 ; - } - } -/* No NPI port */ ocelot_configure_cpu (ocelot,-1 ,OCELOT_TAG_PREFIX_NONE ,OCELOT_TAG_PREFIX_NONE );
@@ -1103,14 +1006,124 @@ static int mscc_ocelot_probe(struct platform_device *pdev) priv->serdes = serdes; } +out_put_ports: +of_node_put (ports); +return err; +} + +static int mscc_ocelot_probe (struct platform_device *pdev) +{ +struct device_node *np = pdev->dev.of_node; +int err, irq_xtr, irq_ptp_rdy; +struct ocelot *ocelot; +struct regmap *hsio; +unsigned int i; + +struct { +enum ocelot_target id; +char *name; +u8 optional:1 ; + } io_target[] = { + {SYS ,"sys" }, + {REW ,"rew" }, + {QSYS ,"qsys" }, + {ANA ,"ana" }, + {QS ,"qs" }, + {S2 ,"s2" }, + {PTP ,"ptp" ,1 }, + }; + +if (!np && !pdev->dev.platform_data) +return -ENODEV ; + + ocelot =devm_kzalloc (&pdev->dev,sizeof (*ocelot),GFP_KERNEL ); +if (!ocelot) +return -ENOMEM ; + +platform_set_drvdata (pdev, ocelot); + ocelot->dev = &pdev->dev; + +for (i =0 ; i <ARRAY_SIZE (io_target); i++) { +struct regmap *target; +struct resource *res; + + res =platform_get_resource_byname (pdev,IORESOURCE_MEM , + io_target[i].name); + + target =ocelot_regmap_init (ocelot, res); +if (IS_ERR (target)) { +if (io_target[i].optional) { + ocelot->targets[io_target[i].id] =NULL ; +continue ; + } +return PTR_ERR (target); + } + + ocelot->targets[io_target[i].id] = target; + } + + hsio =syscon_regmap_lookup_by_compatible ("mscc,ocelot-hsio" ); +if (IS_ERR (hsio)) { +dev_err (&pdev->dev,"missing hsio syscon\n" ); +return PTR_ERR (hsio); + } + + ocelot->targets[HSIO ] = hsio; + + err =ocelot_chip_init (ocelot, &ocelot_ops); +if (err) +return err; + + irq_xtr =platform_get_irq_byname (pdev,"xtr" ); +if (irq_xtr <0 ) +return -ENODEV ; + + err =devm_request_threaded_irq (&pdev->dev, irq_xtr,NULL , + ocelot_xtr_irq_handler,IRQF_ONESHOT , +"frame extraction" , ocelot); +if (err) +return err; + + irq_ptp_rdy =platform_get_irq_byname (pdev,"ptp_rdy" ); +if (irq_ptp_rdy >0 && ocelot->targets[PTP ]) { + err =devm_request_threaded_irq (&pdev->dev, irq_ptp_rdy,NULL , + ocelot_ptp_rdy_irq_handler, +IRQF_ONESHOT ,"ptp ready" , + ocelot); +if (err) +return err; + +/* Both the PTP interrupt and the PTP bank are available */ + ocelot->ptp =1 ; + } + + ocelot->vcap_is2_keys = vsc7514_vcap_is2_keys; + ocelot->vcap_is2_actions = vsc7514_vcap_is2_actions; + ocelot->vcap = vsc7514_vcap_props; + + err =ocelot_init (ocelot); +if (err) +return err; + + err =mscc_ocelot_init_ports (pdev); +if (err) +return err; + +if (ocelot->ptp) { + err =ocelot_init_timestamp (ocelot, &ocelot_ptp_clock_info); +if (err) { +dev_err (ocelot->dev, +"Timestamp initialization failed\n" ); + ocelot->ptp =0 ; + } + } +register_netdevice_notifier (&ocelot_netdevice_nb);register_switchdev_notifier (&ocelot_switchdev_nb);register_switchdev_blocking_notifier (&ocelot_switchdev_blocking_nb);dev_info (&pdev->dev,"Ocelot switch probed\n" ); -out_put_ports: -of_node_put (ports);return err; }
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH 3/7 net: dsa: seville: fix buffer size of the queue system
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
The VSC9953 Seville switch has 2 megabits of buffer split into 4360 words of 60 bytes each.
--- drivers/net/dsa/ocelot/seville_vsc9953.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/ocelot/seville_vsc9953.c +1 -1
@@ -1018,7 +1018,7 @@ static const struct felix_info seville_info_vsc9953 = { .vcap_is2_keys = vsc9953_vcap_is2_keys, .vcap_is2_actions = vsc9953_vcap_is2_actions, .vcap = vsc9953_vcap_props, - .shared_queue_sz = 128 * 1024, + .shared_queue_sz = 2048 * 1024, .num_mact_rows = 2048, .num_ports = 10, .mdio_bus_alloc = vsc9953_mdio_bus_alloc,
Signature · 1 line
2.25.1
Vladimir Oltean
maintainercover Bugfixes in Microsemi Ocelot switch driver
From: Vladimir Oltean <[email protected]>
This is a series of 7 assorted patches for "net", on the drivers for the VSC7514 MIPS switch (Ocelot-1), the VSC9953 PowerPC (Seville), and a few more that are common to all supported devices since they are in the common library portion.
Vladimir Oltean (7):
net: mscc: ocelot: fix race condition with TX timestamping
net: mscc: ocelot: add locking for the port TX timestamp ID
net: dsa: seville: fix buffer size of the queue system
net: mscc: ocelot: check for errors on memory allocation of ports
net: mscc: ocelot: error checking when calling ocelot_init()
net: mscc: ocelot: refactor ports parsing code into a dedicated
function
net: mscc: ocelot: unregister net devices on unbind
drivers/net/dsa/ocelot/felix.c | 5 +- drivers/net/dsa/ocelot/seville_vsc9953.c | 2 +- drivers/net/ethernet/mscc/ocelot.c | 13 +- drivers/net/ethernet/mscc/ocelot_net.c | 12 +- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 234 ++++++++++++--------- include/soc/mscc/ocelot.h | 1 + net/dsa/tag_ocelot.c | 11 +- 7 files changed, 168 insertions(+), 110 deletions(-)
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH 1/7 net: mscc: ocelot: fix race condition with TX timestamping
From: Vladimir Oltean <[email protected]>
The TX-timestampable skb is added late to the ocelot_port->tx_skbs. It is in a race with the TX timestamp IRQ, which checks that queue trying to match the timestamp with the skb by the ts_id. The skb should be added to the queue before the IRQ can fire.
--- drivers/net/ethernet/mscc/ocelot_net.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/ethernet/mscc/ocelot_net.c +8 -6
@@ -330,6 +330,7 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)u8 grp =0 ;/* Send everything on CPU group 0 */ unsigned int i, count, last;int port = priv->chip_port; +bool do_tstamp; val =ocelot_read (ocelot,QS_INJ_STATUS ); if (!(val & QS_INJ_STATUS_FIFO_RDY(BIT(grp))) ||
@@ -344,10 +345,14 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev) info.vid =skb_vlan_tag_get (skb);/* Check if timestamping is needed */ + do_tstamp = (ocelot_port_add_txtstamp_skb (ocelot_port, skb) ==0 ); +if (ocelot->ptp && shinfo->tx_flags &SKBTX_HW_TSTAMP ) { info.rew_op = ocelot_port->ptp_cmd; -if (ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) +if (ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) { info.rew_op |= (ocelot_port->ts_id %4 ) <<3 ; + ocelot_port->ts_id++; + } }ocelot_gen_ifh (ifh, &info);
@@ -380,12 +385,9 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev) dev->stats.tx_packets++; dev->stats.tx_bytes += skb->len; -if (!ocelot_port_add_txtstamp_skb (ocelot_port, skb)) { - ocelot_port->ts_id++; -return NETDEV_TX_OK ; - } +if (!do_tstamp) +dev_kfree_skb_any (skb); -dev_kfree_skb_any (skb);return NETDEV_TX_OK ; }
Signature · 1 line
2.25.1
Quoted 7 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
This is a series of 7 assorted patches for "net", on the drivers for the VSC7514 MIPS switch (Ocelot-1), the VSC9953 PowerPC (Seville), and a few more that are common to all supported devices since they are in the common library portion.
I have looked over ocelot changes and they look fine to me.
Quoted 23 lines
Vladimir Oltean (7):
net: mscc: ocelot: fix race condition with TX timestamping
net: mscc: ocelot: add locking for the port TX timestamp ID
net: dsa: seville: fix buffer size of the queue system
net: mscc: ocelot: check for errors on memory allocation of ports
net: mscc: ocelot: error checking when callingocelot_init()
net: mscc: ocelot: refactor ports parsing code into a dedicated
function
net: mscc: ocelot: unregister net devices on unbinddrivers/net/dsa/ocelot/felix.c | 5 +- drivers/net/dsa/ocelot/seville_vsc9953.c | 2 +- drivers/net/ethernet/mscc/ocelot.c | 13 +- drivers/net/ethernet/mscc/ocelot_net.c | 12 +- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 234 ++++++++++++--------- include/soc/mscc/ocelot.h | 1 + net/dsa/tag_ocelot.c | 11 +- 7 files changed, 168 insertions(+), 110 deletions(-)--
2.25.1
Signature · 1 line
/Horatiu
Hi,
Quoted 17 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
This is a series of 7 assorted patches for "net", on the drivers for the VSC7514 MIPS switch (Ocelot-1), the VSC9953 PowerPC (Seville), and a few more that are common to all supported devices since they are in the common library portion.
Vladimir Oltean (7):
net: mscc: ocelot: fix race condition with TX timestamping
net: mscc: ocelot: add locking for the port TX timestamp ID
net: dsa: seville: fix buffer size of the queue system
net: mscc: ocelot: check for errors on memory allocation of ports
net: mscc: ocelot: error checking when callingocelot_init()
net: mscc: ocelot: refactor ports parsing code into a dedicated
function
net: mscc: ocelot: unregister net devices on unbind
Quoted 9 lines
drivers/net/dsa/ocelot/felix.c | 5 +- drivers/net/dsa/ocelot/seville_vsc9953.c | 2 +- drivers/net/ethernet/mscc/ocelot.c | 13 +- drivers/net/ethernet/mscc/ocelot_net.c | 12 +- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 234 ++++++++++++--------- include/soc/mscc/ocelot.h | 1 + net/dsa/tag_ocelot.c | 11 +- 7 files changed, 168 insertions(+), 110 deletions(-)
This series is leading to multiple crashes on my vc7524 board. I'm trying to pinpoint the problematic commits
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Vladimir Oltean
maintainerRe: [PATCH net 2/7] net: mscc: ocelot: add locking for the port TX timestamp ID
In reply to Alexandre BelloniQuoted 6 lines · Alexandre Belloni
drivers/net/ethernet/mscc/ocelot.c int ocelot_init(struct ocelot *ocelot) · line 1453
Quoted 3 lines
drivers/net/ethernet/mscc/ocelot.c +3
-0+for (port =0 ; port < ocelot->num_phys_ports; port++) { +struct ocelot_port *ocelot_port = ocelot->ports[port]; +At this point,
ocelot_portis NULL becauseocelot_initis called before the port structures are allocated inmscc_ocelot_probe
Yikes, you're right, thanks for testing!
-Vladimir
Re: [PATCH net 2/7] net: mscc: ocelot: add locking for the port TX timestamp ID
In reply to Vladimir OlteanQuoted 50 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
The
ocelot_port->ts_idis used to:
- populate skb->cb[0] for matching the TX timestamp in the PTP IRQ with an skb.
- populate theREW_OPfrom the injection header of the ongoing skb. Only then isocelot_port->ts_idincremented.This is a problem because, at least theoretically, another timestampable skb might use the same
ocelot_port->ts_idbefore that is incremented. So the logic of using and incrementing the timestamp id should be atomic per port.The solution is to use the global
ocelot_port->ts_idonly while protected by the associatedocelot_port->ts_id_lock. That's where we populate skb->cb[0]. Note that for ocelot,ocelot_port_add_txtstamp_skb()is called for the actual skb, but for felix, it is called for the skb's clone. That is something which will also be changed.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/ethernet/mscc/ocelot.c | 13 ++++++++++++- drivers/net/ethernet/mscc/ocelot_net.c | 6 ++---- include/soc/mscc/ocelot.h | 1 + net/dsa/tag_ocelot.c | 11 +++++++---- 4 files changed, 22 insertions(+), 9 deletions(-)drivers/net/ethernet/mscc/ocelot.c +6
-1@@ -421,10 +421,15 @@ int ocelot_port_add_txtstamp_skb(struct ocelot_port *ocelot_port,if (ocelot->ptp && shinfo->tx_flags &SKBTX_HW_TSTAMP && ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) { +spin_lock (&ocelot_port->ts_id_lock); + shinfo->tx_flags |=SKBTX_IN_PROGRESS ;/* Store timestamp ID in cb[0] of sk_buff */ - skb->cb[0 ] = ocelot_port->ts_id %4 ; + skb->cb[0 ] = ocelot_port->ts_id; + ocelot_port->ts_id = (ocelot_port->ts_id +1 ) %4 ;skb_queue_tail (&ocelot_port->tx_skbs, skb); + +spin_unlock (&ocelot_port->ts_id_lock);return 0 ; }return -ENODATA ;
drivers/net/ethernet/mscc/ocelot.c int ocelot_init(struct ocelot *ocelot) · line 1453
Quoted 6 lines
drivers/net/ethernet/mscc/ocelot.c +3
-0@@ -1443,6 +1448,12 @@ int ocelot_init(struct ocelot *ocelot)if (!ocelot->stats_queue)return -ENOMEM ; +for (port =0 ; port < ocelot->num_phys_ports; port++) { +struct ocelot_port *ocelot_port = ocelot->ports[port]; +
At this point, ocelot_port is NULL because ocelot_init is called before the port structures are allocated in mscc_ocelot_probe
Quoted 61 lines
drivers/net/ethernet/mscc/ocelot.c +3
-0+spin_lock_init (&ocelot_port->ts_id_lock); + } +INIT_LIST_HEAD (&ocelot->multicast);ocelot_mact_init (ocelot);ocelot_vlan_init (ocelot);drivers/net/ethernet/mscc/ocelot_net.c +2
-4@@ -349,10 +349,8 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)if (ocelot->ptp && shinfo->tx_flags &SKBTX_HW_TSTAMP ) { info.rew_op = ocelot_port->ptp_cmd; -if (ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) { - info.rew_op |= (ocelot_port->ts_id %4 ) <<3 ; - ocelot_port->ts_id++; - } +if (ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) + info.rew_op |= skb->cb[0 ] <<3 ; }ocelot_gen_ifh (ifh, &info);include/soc/mscc/ocelot.h +1
-0@@ -566,6 +566,7 @@ struct ocelot_port {u8 ptp_cmd;struct sk_buff_head tx_skbs;u8 ts_id; +spinlock_t ts_id_lock;phy_interface_t phy_mode;net/dsa/tag_ocelot.c +7
-4@@ -160,11 +160,14 @@ static struct sk_buff *ocelot_xmit(struct sk_buff *skb,packing (injection, &qos_class,19 ,17 ,OCELOT_TAG_LEN ,PACK ,0 );if (ocelot->ptp && (skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP )) { +struct sk_buff *clone =DSA_SKB_CB (skb)->clone; + rew_op = ocelot_port->ptp_cmd; -if (ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) { - rew_op |= (ocelot_port->ts_id %4 ) <<3 ; - ocelot_port->ts_id++; - } +/* Retrieve timestamp ID populated inside skb->cb[0] of the +* clone by ocelot_port_add_txtstamp_skb +*/ +if (ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) + rew_op |= clone->cb[0 ] <<3 ;packing (injection, &rew_op,125 ,117 ,OCELOT_TAG_LEN ,PACK ,0 ); }Signature · 1 line
2.25.1
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
David Miller
maintainerRe: [PATCH net 2/7] net: mscc: ocelot: add locking for the port TX timestamp ID
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Date: Tue, 15 Sep 2020 21:22:24 +0300
Quoted 4 lines
This is a problem because, at least theoretically, another timestampable skb might use the same
ocelot_port->ts_idbefore that is incremented. So the logic of using and incrementing the timestamp id should be atomic per port.
Have you actually observed this race in practice?
All transmit calls are serialized by the netdev transmit spinlock.
Let's not add locking if it is not actually necessary.
David Miller
maintainerRe: [PATCH net 4/7] net: mscc: ocelot: check for errors on memory allocation of ports
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Date: Tue, 15 Sep 2020 21:22:26 +0300
drivers/net/ethernet/mscc/ocelot_vsc7514.c static int mscc_ocelot_probe(struct platform_device *pdev) · line 997
Quoted 6 lines
drivers/net/ethernet/mscc/ocelot_vsc7514.c +2
-0@@ -993,6 +993,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev) ocelot->ports =devm_kcalloc (&pdev->dev, ocelot->num_phys_ports,sizeof (struct ocelot_port *),GFP_KERNEL ); +if (!ocelot->ports) +return -ENOMEM ;
This leaks the reference to OF node 'ports'.
David Miller
maintainerRe: [PATCH net 5/7] net: mscc: ocelot: error checking when calling ocelot_init()
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Date: Tue, 15 Sep 2020 21:22:27 +0300
drivers/net/ethernet/mscc/ocelot_vsc7514.c static int mscc_ocelot_probe(struct platform_device *pdev) · line 1006
Quoted 13 lines
drivers/net/ethernet/mscc/ocelot_vsc7514.c +4
-1@@ -1000,7 +1000,10 @@ static int mscc_ocelot_probe(struct platform_device *pdev) ocelot->vcap_is2_actions = vsc7514_vcap_is2_actions; ocelot->vcap = vsc7514_vcap_props; -ocelot_init (ocelot); + err =ocelot_init (ocelot); +if (err) +return err; +
This also leaks the OF device 'ports' object.
Vladimir Oltean
maintainerRe: [PATCH net 2/7] net: mscc: ocelot: add locking for the port TX timestamp ID
In reply to David MillerQuoted 8 lines · David Miller
From: Vladimir Oltean <[email protected]>
Date: Tue, 15 Sep 2020 21:22:24 +0300Quoted 4 lines
This is a problem because, at least theoretically, another timestampable skb might use the same
ocelot_port->ts_idbefore that is incremented. So the logic of using and incrementing the timestamp id should be atomic per port.
Quoted 5 lines
Have you actually observed this race in practice?
All transmit calls are serialized by the netdev transmit spinlock.
Let's not add locking if it is not actually necessary.
It's a bit more complicated.
This code is also used from DSA, and DSA now declares NETIF_F_LLTX.
David Miller
maintainerRe: [PATCH net 2/7] net: mscc: ocelot: add locking for the port TX timestamp ID
From: Vladimir Oltean <[email protected]>
Date: Fri, 18 Sep 2020 02:43:40 +0300
Quoted 9 lines · David Miller
Quoted 8 lines
From: Vladimir Oltean <[email protected]>
Date: Tue, 15 Sep 2020 21:22:24 +0300Quoted 4 lines
This is a problem because, at least theoretically, another timestampable skb might use the same
ocelot_port->ts_idbefore that is incremented. So the logic of using and incrementing the timestamp id should be atomic per port.
Quoted 8 lines
Quoted 5 lines
Have you actually observed this race in practice?
All transmit calls are serialized by the netdev transmit spinlock.
Let's not add locking if it is not actually necessary.
It's a bit more complicated.
This code is also used from DSA, and DSA now declaresNETIF_F_LLTX.
Please document that in the commit log message, thank you.