Skip to content

Commit a02e399

Browse files
committed
Merge branch 'mscc-skb-lists'
Yangbo Lu says: ==================== net: mscc: ocelot: fix potential issues accessing skbs list Fix two prtential issues accessing skbs list. - Break the matching loop when find the matching skb to avoid consuming more skbs incorrectly. The timestamp ID is only from 0 to 3 while the FIFO supports 128 timestamps at most. - Convert to use skb queue instead of the list of skbs to provide protect with lock. Changes for v2: - Split into two patches. - Converted to use skb queue. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents a95069e + b049da1 commit a02e399

File tree

2 files changed

+20
-44
lines changed

2 files changed

+20
-44
lines changed

drivers/net/ethernet/mscc/ocelot.c

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -583,18 +583,10 @@ int ocelot_port_add_txtstamp_skb(struct ocelot_port *ocelot_port,
583583

584584
if (ocelot->ptp && shinfo->tx_flags & SKBTX_HW_TSTAMP &&
585585
ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) {
586-
struct ocelot_skb *oskb =
587-
kzalloc(sizeof(struct ocelot_skb), GFP_ATOMIC);
588-
589-
if (unlikely(!oskb))
590-
return -ENOMEM;
591-
592586
shinfo->tx_flags |= SKBTX_IN_PROGRESS;
593-
594-
oskb->skb = skb;
595-
oskb->id = ocelot_port->ts_id % 4;
596-
597-
list_add_tail(&oskb->head, &ocelot_port->skbs);
587+
/* Store timestamp ID in cb[0] of sk_buff */
588+
skb->cb[0] = ocelot_port->ts_id % 4;
589+
skb_queue_tail(&ocelot_port->tx_skbs, skb);
598590
return 0;
599591
}
600592
return -ENODATA;
@@ -704,12 +696,11 @@ void ocelot_get_txtstamp(struct ocelot *ocelot)
704696
int budget = OCELOT_PTP_QUEUE_SZ;
705697

706698
while (budget--) {
699+
struct sk_buff *skb, *skb_tmp, *skb_match = NULL;
707700
struct skb_shared_hwtstamps shhwtstamps;
708-
struct list_head *pos, *tmp;
709-
struct sk_buff *skb = NULL;
710-
struct ocelot_skb *entry;
711701
struct ocelot_port *port;
712702
struct timespec64 ts;
703+
unsigned long flags;
713704
u32 val, id, txport;
714705

715706
val = ocelot_read(ocelot, SYS_PTP_STATUS);
@@ -727,21 +718,22 @@ void ocelot_get_txtstamp(struct ocelot *ocelot)
727718
/* Retrieve its associated skb */
728719
port = ocelot->ports[txport];
729720

730-
list_for_each_safe(pos, tmp, &port->skbs) {
731-
entry = list_entry(pos, struct ocelot_skb, head);
732-
if (entry->id != id)
733-
continue;
734-
735-
skb = entry->skb;
721+
spin_lock_irqsave(&port->tx_skbs.lock, flags);
736722

737-
list_del(pos);
738-
kfree(entry);
723+
skb_queue_walk_safe(&port->tx_skbs, skb, skb_tmp) {
724+
if (skb->cb[0] != id)
725+
continue;
726+
__skb_unlink(skb, &port->tx_skbs);
727+
skb_match = skb;
728+
break;
739729
}
740730

731+
spin_unlock_irqrestore(&port->tx_skbs.lock, flags);
732+
741733
/* Next ts */
742734
ocelot_write(ocelot, SYS_PTP_NXT_PTP_NXT, SYS_PTP_NXT);
743735

744-
if (unlikely(!skb))
736+
if (unlikely(!skb_match))
745737
continue;
746738

747739
/* Get the h/w timestamp */
@@ -750,9 +742,9 @@ void ocelot_get_txtstamp(struct ocelot *ocelot)
750742
/* Set the timestamp into the skb */
751743
memset(&shhwtstamps, 0, sizeof(shhwtstamps));
752744
shhwtstamps.hwtstamp = ktime_set(ts.tv_sec, ts.tv_nsec);
753-
skb_tstamp_tx(skb, &shhwtstamps);
745+
skb_tstamp_tx(skb_match, &shhwtstamps);
754746

755-
dev_kfree_skb_any(skb);
747+
dev_kfree_skb_any(skb_match);
756748
}
757749
}
758750
EXPORT_SYMBOL(ocelot_get_txtstamp);
@@ -2205,7 +2197,7 @@ void ocelot_init_port(struct ocelot *ocelot, int port)
22052197
{
22062198
struct ocelot_port *ocelot_port = ocelot->ports[port];
22072199

2208-
INIT_LIST_HEAD(&ocelot_port->skbs);
2200+
skb_queue_head_init(&ocelot_port->tx_skbs);
22092201

22102202
/* Basic L2 initialization */
22112203

@@ -2490,9 +2482,7 @@ EXPORT_SYMBOL(ocelot_init);
24902482

24912483
void ocelot_deinit(struct ocelot *ocelot)
24922484
{
2493-
struct list_head *pos, *tmp;
24942485
struct ocelot_port *port;
2495-
struct ocelot_skb *entry;
24962486
int i;
24972487

24982488
cancel_delayed_work(&ocelot->stats_work);
@@ -2502,14 +2492,7 @@ void ocelot_deinit(struct ocelot *ocelot)
25022492

25032493
for (i = 0; i < ocelot->num_phys_ports; i++) {
25042494
port = ocelot->ports[i];
2505-
2506-
list_for_each_safe(pos, tmp, &port->skbs) {
2507-
entry = list_entry(pos, struct ocelot_skb, head);
2508-
2509-
list_del(pos);
2510-
dev_kfree_skb_any(entry->skb);
2511-
kfree(entry);
2512-
}
2495+
skb_queue_purge(&port->tx_skbs);
25132496
}
25142497
}
25152498
EXPORT_SYMBOL(ocelot_deinit);

include/soc/mscc/ocelot.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,6 @@ struct ocelot_ops {
406406
int (*reset)(struct ocelot *ocelot);
407407
};
408408

409-
struct ocelot_skb {
410-
struct list_head head;
411-
struct sk_buff *skb;
412-
u8 id;
413-
};
414-
415-
416409
struct ocelot_port {
417410
struct ocelot *ocelot;
418411

@@ -425,7 +418,7 @@ struct ocelot_port {
425418
u16 vid;
426419

427420
u8 ptp_cmd;
428-
struct list_head skbs;
421+
struct sk_buff_head tx_skbs;
429422
u8 ts_id;
430423
};
431424

0 commit comments

Comments
 (0)