Commit 9c50e2b
igc: Fix race condition in PTP tx code
Currently, the igc driver supports timestamping only one tx packet at a
time. During the transmission flow, the skb that requires hardware
timestamping is saved in adapter->ptp_tx_skb. Once hardware has the
timestamp, an interrupt is delivered, and adapter->ptp_tx_work is
scheduled. In igc_ptp_tx_work(), we read the timestamp register, update
adapter->ptp_tx_skb, and notify the network stack.
While the thread executing the transmission flow (the user process
running in kernel mode) and the thread executing ptp_tx_work don't
access adapter->ptp_tx_skb concurrently, there are two other places
where adapter->ptp_tx_skb is accessed: igc_ptp_tx_hang() and
igc_ptp_suspend().
igc_ptp_tx_hang() is executed by the adapter->watchdog_task worker
thread which runs periodically so it is possible we have two threads
accessing ptp_tx_skb at the same time. Consider the following scenario:
right after __IGC_PTP_TX_IN_PROGRESS is set in igc_xmit_frame_ring(),
igc_ptp_tx_hang() is executed. Since adapter->ptp_tx_start hasn't been
written yet, this is considered a timeout and adapter->ptp_tx_skb is
cleaned up.
This patch fixes the issue described above by adding the ptp_tx_lock to
protect access to ptp_tx_skb and ptp_tx_start fields from igc_adapter.
Since igc_xmit_frame_ring() called in atomic context by the networking
stack, ptp_tx_lock is defined as a spinlock, and the irq safe variants
of lock/unlock are used.
With the introduction of the ptp_tx_lock, the __IGC_PTP_TX_IN_PROGRESS
flag doesn't provide much of a use anymore so this patch gets rid of it.
Fixes: 2c344ae ("igc: Add support for TX timestamping")
Signed-off-by: Andre Guedes <andre.guedes@intel.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Reviewed-by: Kurt Kanzenbach <kurt@linutronix.de>
Tested-by: Naama Meir <naamax.meir@linux.intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>1 parent 2ba7e7e commit 9c50e2b
3 files changed
Lines changed: 41 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
232 | 236 | | |
233 | 237 | | |
234 | 238 | | |
| |||
401 | 405 | | |
402 | 406 | | |
403 | 407 | | |
404 | | - | |
405 | 408 | | |
406 | 409 | | |
407 | 410 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1590 | 1590 | | |
1591 | 1591 | | |
1592 | 1592 | | |
1593 | | - | |
1594 | | - | |
1595 | | - | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
1596 | 1597 | | |
1597 | 1598 | | |
1598 | 1599 | | |
| |||
1601 | 1602 | | |
1602 | 1603 | | |
1603 | 1604 | | |
| 1605 | + | |
| 1606 | + | |
1604 | 1607 | | |
1605 | 1608 | | |
1606 | 1609 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
603 | 603 | | |
604 | 604 | | |
605 | 605 | | |
| 606 | + | |
606 | 607 | | |
607 | 608 | | |
608 | 609 | | |
609 | 610 | | |
610 | 611 | | |
611 | 612 | | |
612 | 613 | | |
613 | | - | |
614 | 614 | | |
615 | 615 | | |
616 | 616 | | |
617 | 617 | | |
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
621 | | - | |
622 | | - | |
| 621 | + | |
623 | 622 | | |
624 | | - | |
625 | | - | |
| 623 | + | |
626 | 624 | | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
635 | 635 | | |
636 | 636 | | |
637 | 637 | | |
| |||
641 | 641 | | |
642 | 642 | | |
643 | 643 | | |
| 644 | + | |
| 645 | + | |
644 | 646 | | |
645 | 647 | | |
646 | 648 | | |
| |||
676 | 678 | | |
677 | 679 | | |
678 | 680 | | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | 681 | | |
685 | | - | |
686 | 682 | | |
687 | 683 | | |
688 | 684 | | |
| |||
693 | 689 | | |
694 | 690 | | |
695 | 691 | | |
696 | | - | |
697 | | - | |
| 692 | + | |
| 693 | + | |
698 | 694 | | |
699 | 695 | | |
700 | 696 | | |
701 | 697 | | |
702 | 698 | | |
703 | 699 | | |
| 700 | + | |
704 | 701 | | |
705 | 702 | | |
706 | | - | |
707 | | - | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
708 | 707 | | |
709 | 708 | | |
710 | | - | |
711 | | - | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
712 | 714 | | |
713 | 715 | | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
714 | 719 | | |
715 | 720 | | |
716 | 721 | | |
| |||
959 | 964 | | |
960 | 965 | | |
961 | 966 | | |
| 967 | + | |
962 | 968 | | |
963 | 969 | | |
964 | 970 | | |
| |||
1023 | 1029 | | |
1024 | 1030 | | |
1025 | 1031 | | |
1026 | | - | |
1027 | 1032 | | |
1028 | 1033 | | |
1029 | 1034 | | |
| |||
0 commit comments