Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Vladimir Oltean and committed by
Jakub Kicinski
0c53cdb9 b6fba4b3

+6 -8
+6 -8
drivers/net/ethernet/mscc/ocelot_ptp.c
··· 607 607 struct sk_buff *clone) 608 608 { 609 609 struct ocelot_port *ocelot_port = ocelot->ports[port]; 610 - unsigned long flags; 611 610 612 - spin_lock_irqsave(&ocelot->ts_id_lock, flags); 611 + spin_lock(&ocelot->ts_id_lock); 613 612 614 613 if (ocelot_port->ptp_skbs_in_flight == OCELOT_MAX_PTP_ID || 615 614 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); 617 616 return -EBUSY; 618 617 } 619 618 ··· 629 630 630 631 skb_queue_tail(&ocelot_port->tx_skbs, clone); 631 632 632 - spin_unlock_irqrestore(&ocelot->ts_id_lock, flags); 633 + spin_unlock(&ocelot->ts_id_lock); 633 634 634 635 return 0; 635 636 } ··· 748 749 u32 val, id, seqid, txport; 749 750 struct ocelot_port *port; 750 751 struct timespec64 ts; 751 - unsigned long flags; 752 752 753 753 val = ocelot_read(ocelot, SYS_PTP_STATUS); 754 754 ··· 771 773 772 774 /* Retrieve its associated skb */ 773 775 try_again: 774 - spin_lock_irqsave(&port->tx_skbs.lock, flags); 776 + spin_lock(&port->tx_skbs.lock); 775 777 776 778 skb_queue_walk_safe(&port->tx_skbs, skb, skb_tmp) { 777 779 if (OCELOT_SKB_CB(skb)->ts_id != id) ··· 781 783 break; 782 784 } 783 785 784 - spin_unlock_irqrestore(&port->tx_skbs.lock, flags); 786 + spin_unlock(&port->tx_skbs.lock); 785 787 786 788 if (WARN_ON(!skb_match)) 787 789 goto next_ts; ··· 790 792 dev_err_ratelimited(ocelot->dev, 791 793 "port %d received stale TX timestamp for seqid %d, discarding\n", 792 794 txport, seqid); 793 - dev_kfree_skb_any(skb); 795 + kfree_skb(skb); 794 796 goto try_again; 795 797 } 796 798