OSDN Git Service

i40evf: fix crash when changing ring sizes
authorMitch Williams <mitch.a.williams@intel.com>
Thu, 24 Apr 2014 06:41:37 +0000 (06:41 +0000)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Thu, 5 Jun 2014 09:13:01 +0000 (02:13 -0700)
i40evf_set_ringparam was broken in several ways. First, it only changed
the size of the first ring, and second, changing the ring size would
often result in a panic because it would change the count before
deallocating resources, causing the driver to either free nonexistent
buffers, or leak leftover buffers.

Fix this by storing the descriptor count in the adapter structure, and
updating the count for each ring each time we allocate them. This
ensures that we always free the right size ring, and always end up with
the requested count when the device is (re)opened.

Change-ID: I298396cd3d452ba8509d9f2d33a93f25868a9a55
Signed-off-by: Mitch Williams <mitch.a.williams@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/i40evf/i40evf.h
drivers/net/ethernet/intel/i40evf/i40evf_ethtool.c
drivers/net/ethernet/intel/i40evf/i40evf_main.c

index bfd8542..30ef519 100644 (file)
@@ -196,10 +196,12 @@ struct i40evf_adapter {
        struct i40e_ring *tx_rings[I40E_MAX_VSI_QP];
        u32 tx_timeout_count;
        struct list_head mac_filter_list;
+       u32 tx_desc_count;
 
        /* RX */
        struct i40e_ring *rx_rings[I40E_MAX_VSI_QP];
        u64 hw_csum_rx_error;
+       u32 rx_desc_count;
        int num_msix_vectors;
        struct msix_entry *msix_entries;
 
index 9cd381a..8d41a88 100644 (file)
@@ -224,13 +224,11 @@ static void i40evf_get_ringparam(struct net_device *netdev,
                                  struct ethtool_ringparam *ring)
 {
        struct i40evf_adapter *adapter = netdev_priv(netdev);
-       struct i40e_ring *tx_ring = adapter->tx_rings[0];
-       struct i40e_ring *rx_ring = adapter->rx_rings[0];
 
        ring->rx_max_pending = I40EVF_MAX_RXD;
        ring->tx_max_pending = I40EVF_MAX_TXD;
-       ring->rx_pending = rx_ring->count;
-       ring->tx_pending = tx_ring->count;
+       ring->rx_pending = adapter->rx_desc_count;
+       ring->tx_pending = adapter->tx_desc_count;
 }
 
 /**
@@ -246,7 +244,6 @@ static int i40evf_set_ringparam(struct net_device *netdev,
 {
        struct i40evf_adapter *adapter = netdev_priv(netdev);
        u32 new_rx_count, new_tx_count;
-       int i;
 
        if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
                return -EINVAL;
@@ -262,17 +259,16 @@ static int i40evf_set_ringparam(struct net_device *netdev,
        new_rx_count = ALIGN(new_rx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
 
        /* if nothing to do return success */
-       if ((new_tx_count == adapter->tx_rings[0]->count) &&
-           (new_rx_count == adapter->rx_rings[0]->count))
+       if ((new_tx_count == adapter->tx_desc_count) &&
+           (new_rx_count == adapter->rx_desc_count))
                return 0;
 
-       for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
-               adapter->tx_rings[0]->count = new_tx_count;
-               adapter->rx_rings[0]->count = new_rx_count;
-       }
+       adapter->tx_desc_count = new_tx_count;
+       adapter->rx_desc_count = new_rx_count;
 
        if (netif_running(netdev))
                i40evf_reinit_locked(adapter);
+
        return 0;
 }
 
index 632c2b3..d24f40f 100644 (file)
@@ -1091,14 +1091,14 @@ static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
                tx_ring->queue_index = i;
                tx_ring->netdev = adapter->netdev;
                tx_ring->dev = &adapter->pdev->dev;
-               tx_ring->count = I40EVF_DEFAULT_TXD;
+               tx_ring->count = adapter->tx_desc_count;
                adapter->tx_rings[i] = tx_ring;
 
                rx_ring = &tx_ring[1];
                rx_ring->queue_index = i;
                rx_ring->netdev = adapter->netdev;
                rx_ring->dev = &adapter->pdev->dev;
-               rx_ring->count = I40EVF_DEFAULT_RXD;
+               rx_ring->count = adapter->rx_desc_count;
                adapter->rx_rings[i] = rx_ring;
        }
 
@@ -1669,6 +1669,7 @@ static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
        int i, err = 0;
 
        for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
+               adapter->tx_rings[i]->count = adapter->tx_desc_count;
                err = i40evf_setup_tx_descriptors(adapter->tx_rings[i]);
                if (!err)
                        continue;
@@ -1696,6 +1697,7 @@ static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
        int i, err = 0;
 
        for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
+               adapter->rx_rings[i]->count = adapter->rx_desc_count;
                err = i40evf_setup_rx_descriptors(adapter->rx_rings[i]);
                if (!err)
                        continue;
@@ -2092,6 +2094,8 @@ static void i40evf_init_task(struct work_struct *work)
        adapter->watchdog_timer.data = (unsigned long)adapter;
        mod_timer(&adapter->watchdog_timer, jiffies + 1);
 
+       adapter->tx_desc_count = I40EVF_DEFAULT_TXD;
+       adapter->rx_desc_count = I40EVF_DEFAULT_RXD;
        err = i40evf_init_interrupt_scheme(adapter);
        if (err)
                goto err_sw_init;