igb: fix race conditions on queuing skb for HW time stamp
authorJakub Kicinski <kubakici@wp.pl>
Sat, 15 Mar 2014 14:55:32 +0000 (14:55 +0000)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Fri, 28 Mar 2014 13:54:02 +0000 (06:54 -0700)
igb has a single set of TX time stamping resources per NIC.
Use a simple bit lock to avoid race conditions and leaking skbs
when multiple TX rings try to claim time stamping.

Signed-off-by: Jakub Kicinski <kubakici@wp.pl>
Tested-by: Aaron Brown <aaron.f.brown@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/igb/igb.h
drivers/net/ethernet/intel/igb/igb_main.c
drivers/net/ethernet/intel/igb/igb_ptp.c

index 411b213c63be4b35edd225e9c49727e81d5c37b6..7fbe1e925143efb7b4af4b9f06c29fa3027d2e7e 100644 (file)
@@ -492,7 +492,8 @@ struct igb_adapter {
 enum e1000_state_t {
        __IGB_TESTING,
        __IGB_RESETTING,
-       __IGB_DOWN
+       __IGB_DOWN,
+       __IGB_PTP_TX_IN_PROGRESS,
 };
 
 enum igb_boards {
index 1fdffa20fe97c1a1d91b46344f0f6a5f1f13fabd..55fc5596e2d045042a3f33251440fdc137214d13 100644 (file)
@@ -4983,7 +4983,8 @@ netdev_tx_t igb_xmit_frame_ring(struct sk_buff *skb,
        if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
                struct igb_adapter *adapter = netdev_priv(tx_ring->netdev);
 
-               if (!(adapter->ptp_tx_skb)) {
+               if (!test_and_set_bit_lock(__IGB_PTP_TX_IN_PROGRESS,
+                                          &adapter->state)) {
                        skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
                        tx_flags |= IGB_TX_FLAGS_TSTAMP;
 
index da55fbb090b23cb6c0746b47d5d5927d125db5ec..2cca8fd5e574feb779be5cbc05f0e176574267da 100644 (file)
@@ -387,6 +387,7 @@ static void igb_ptp_tx_work(struct work_struct *work)
                                   IGB_PTP_TX_TIMEOUT)) {
                dev_kfree_skb_any(adapter->ptp_tx_skb);
                adapter->ptp_tx_skb = NULL;
+               clear_bit_unlock(__IGB_PTP_TX_IN_PROGRESS, &adapter->state);
                adapter->tx_hwtstamp_timeouts++;
                dev_warn(&adapter->pdev->dev, "clearing Tx timestamp hang");
                return;
@@ -480,6 +481,7 @@ static void igb_ptp_tx_hwtstamp(struct igb_adapter *adapter)
        skb_tstamp_tx(adapter->ptp_tx_skb, &shhwtstamps);
        dev_kfree_skb_any(adapter->ptp_tx_skb);
        adapter->ptp_tx_skb = NULL;
+       clear_bit_unlock(__IGB_PTP_TX_IN_PROGRESS, &adapter->state);
 }
 
 /**
@@ -857,6 +859,7 @@ void igb_ptp_stop(struct igb_adapter *adapter)
        if (adapter->ptp_tx_skb) {
                dev_kfree_skb_any(adapter->ptp_tx_skb);
                adapter->ptp_tx_skb = NULL;
+               clear_bit_unlock(__IGB_PTP_TX_IN_PROGRESS, &adapter->state);
        }
 
        if (adapter->ptp_clock) {