Skip to content

Commit 0c53cdb

Browse files
vladimirolteankuba-moo
authored andcommitted
net: mscc: ocelot: ocelot->ts_id_lock and ocelot_port->tx_skbs.lock are IRQ-safe
ocelot_get_txtstamp() is a threaded IRQ handler, requested explicitly as such by both ocelot_ptp_rdy_irq_handler() and vsc9959_irq_handler(). As such, it runs with IRQs enabled, and not in hardirq context. Thus, ocelot_port_add_txtstamp_skb() has no reason to turn off IRQs, it cannot be preempted by ocelot_get_txtstamp(). For the same reason, dev_kfree_skb_any_reason() will always evaluate as kfree_skb_reason() in this calling context, so just simplify the dev_kfree_skb_any() call to kfree_skb(). Also, ocelot_port_txtstamp_request() runs from NET_TX softirq context, not with hardirqs enabled. Thus, ocelot_get_txtstamp() which shares the ocelot_port->tx_skbs.lock lock with it, has no reason to disable hardirqs. This is part of a larger rework of the TX timestamping procedure. A logical subportion of the rework has been split into a separate change. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Link: https://patch.msgid.link/20241205145519.1236778-4-vladimir.oltean@nxp.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent b6fba4b commit 0c53cdb

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

drivers/net/ethernet/mscc/ocelot_ptp.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,12 @@ static int ocelot_port_add_txtstamp_skb(struct ocelot *ocelot, int port,
607607
struct sk_buff *clone)
608608
{
609609
struct ocelot_port *ocelot_port = ocelot->ports[port];
610-
unsigned long flags;
611610

612-
spin_lock_irqsave(&ocelot->ts_id_lock, flags);
611+
spin_lock(&ocelot->ts_id_lock);
613612

614613
if (ocelot_port->ptp_skbs_in_flight == OCELOT_MAX_PTP_ID ||
615614
ocelot->ptp_skbs_in_flight == OCELOT_PTP_FIFO_SIZE) {
616-
spin_unlock_irqrestore(&ocelot->ts_id_lock, flags);
615+
spin_unlock(&ocelot->ts_id_lock);
617616
return -EBUSY;
618617
}
619618

@@ -630,7 +629,7 @@ static int ocelot_port_add_txtstamp_skb(struct ocelot *ocelot, int port,
630629

631630
skb_queue_tail(&ocelot_port->tx_skbs, clone);
632631

633-
spin_unlock_irqrestore(&ocelot->ts_id_lock, flags);
632+
spin_unlock(&ocelot->ts_id_lock);
634633

635634
return 0;
636635
}
@@ -749,7 +748,6 @@ void ocelot_get_txtstamp(struct ocelot *ocelot)
749748
u32 val, id, seqid, txport;
750749
struct ocelot_port *port;
751750
struct timespec64 ts;
752-
unsigned long flags;
753751

754752
val = ocelot_read(ocelot, SYS_PTP_STATUS);
755753

@@ -773,7 +771,7 @@ void ocelot_get_txtstamp(struct ocelot *ocelot)
773771

774772
/* Retrieve its associated skb */
775773
try_again:
776-
spin_lock_irqsave(&port->tx_skbs.lock, flags);
774+
spin_lock(&port->tx_skbs.lock);
777775

778776
skb_queue_walk_safe(&port->tx_skbs, skb, skb_tmp) {
779777
if (OCELOT_SKB_CB(skb)->ts_id != id)
@@ -783,7 +781,7 @@ void ocelot_get_txtstamp(struct ocelot *ocelot)
783781
break;
784782
}
785783

786-
spin_unlock_irqrestore(&port->tx_skbs.lock, flags);
784+
spin_unlock(&port->tx_skbs.lock);
787785

788786
if (WARN_ON(!skb_match))
789787
goto next_ts;
@@ -792,7 +790,7 @@ void ocelot_get_txtstamp(struct ocelot *ocelot)
792790
dev_err_ratelimited(ocelot->dev,
793791
"port %d received stale TX timestamp for seqid %d, discarding\n",
794792
txport, seqid);
795-
dev_kfree_skb_any(skb);
793+
kfree_skb(skb);
796794
goto try_again;
797795
}
798796

0 commit comments

Comments
 (0)