Skip to contentSkip to conversation

ixgbe: Fix DMA mapping/unmapping issues when HWRSC is enabled on IOMMU enabled kernels

PATCH Applied Jeff Kirsher 7 participants 13 messages Feb 26, 2010 – Mar 2, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 ixgbe: Fix DMA mapping/unmapping issues when HWRSC is enabled on IOMMU enabled kernels

From: Mallikarjuna R Chilakala <[email protected]>

Work around 82599 HW issue when HWRSC is enabled on IOMMU enabled kernels. 82599 HW is updating the header information after setting the descriptor to done, resulting DMA mapping/unmapping issues on IOMMU enabled systems. To work around the issue delay unmapping of first packet that carries the header information until end of packet is reached.

---

 drivers/net/ixgbe/ixgbe_main.c |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)
drivers/net/ixgbe/ixgbe_main.c +29 -3
index 3308790..4a01022 100644
@@ -818,6 +818,12 @@ static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb,
 	return skb;
 }
 
+struct ixgbe_rsc_cb {
+	dma_addr_t dma;
+};
+
+#define IXGBE_RSC_CB(skb) ((struct ixgbe_rsc_cb *)(skb)->cb)
+
 static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
                                struct ixgbe_ring *rx_ring,
                                int *work_done, int work_to_do)
@@ -867,9 +873,21 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
 		rx_buffer_info->skb = NULL;
 
 		if (rx_buffer_info->dma) {
-			pci_unmap_single(pdev, rx_buffer_info->dma,
-			                 rx_ring->rx_buf_len,
-			                 PCI_DMA_FROMDEVICE);
+			if ((adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
+			    (!(staterr & IXGBE_RXD_STAT_EOP)) &&
+				 (!(skb->prev)))
+				/*
+				 * When HWRSC is enabled, delay unmapping
+				 * of the first packet. It carries the
+				 * header information, HW may still
+				 * access the header after the writeback.
+				 * Only unmap it when EOP is reached
+				 */
+				IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
+			else
+				pci_unmap_single(pdev, rx_buffer_info->dma,
+				                 rx_ring->rx_buf_len,
+				                 PCI_DMA_FROMDEVICE);
 			rx_buffer_info->dma = 0;
 			skb_put(skb, len);
 		}
@@ -917,6 +935,10 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
 			if (skb->prev)
 				skb = ixgbe_transform_rsc_queue(skb, &(rx_ring->rsc_count));
 			if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
+				if (IXGBE_RSC_CB(skb)->dma)
+					pci_unmap_single(pdev, IXGBE_RSC_CB(skb)->dma,
+					                 rx_ring->rx_buf_len,
+					                 PCI_DMA_FROMDEVICE);
 				if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)
 					rx_ring->rsc_count += skb_shinfo(skb)->nr_frags;
 				else
@@ -3104,6 +3126,10 @@ static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
 			rx_buffer_info->skb = NULL;
 			do {
 				struct sk_buff *this = skb;
+				if (IXGBE_RSC_CB(this)->dma)
+					pci_unmap_single(pdev, IXGBE_RSC_CB(this)->dma,
+					                 rx_ring->rx_buf_len,
+					                 PCI_DMA_FROMDEVICE);
 				skb = skb->prev;
 				dev_kfree_skb(this);
 			} while (skb);
#1 lore raw

PATCH 2/3 ixgbe: do not stop tx queues in ixgbe_set_tso

From: John Fastabend <[email protected]>

Disabling TSO can cause the dev_watchdog timer to be triggered because when TSO is disabled netif_tx_stop_all_queues is called. If the watchdog timer fires while the queues are stopped and traffic has not recently been sent on a paticular queue this is falsly identified as a hang and ndo_tx_timeout() is called. This is ocossionally seen during testing.

This removes the netif_tx_stop_all_queues() it is not needed. The scheduler submits skb's with dev_hard_start_xmit(), this checks if netif_needs_gso and if so it calls dev_gso_segment. Disabling TSO will cause dev_hard_start_xmit()
to do the gso processing. However ixgbe does not use the features flags to
determine if it needs to use tso or not instead it uses skb->gso_size so ixgbe will process these frames correctly regardless of the netdev features flag.

---

 drivers/net/ixgbe/ixgbe_ethtool.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
drivers/net/ixgbe/ixgbe_ethtool.c +0 -2
index 0d23434..7949a44 100644
@@ -441,10 +441,8 @@ static int ixgbe_set_tso(struct net_device *netdev, u32 data)
 		netdev->features |= NETIF_F_TSO;
 		netdev->features |= NETIF_F_TSO6;
 	} else {
-		netif_tx_stop_all_queues(netdev);
 		netdev->features &= ~NETIF_F_TSO;
 		netdev->features &= ~NETIF_F_TSO6;
-		netif_tx_start_all_queues(netdev);
 	}
 	return 0;
 }
maintainer Applied
#2 lore raw

Re: [net-next-2.6 PATCH 2/3] ixgbe: do not stop tx queues in ixgbe_set_tso

From: Jeff Kirsher <[email protected]>
Date: Fri, 26 Feb 2010 01:14:58 -0800

Quoted 16 lines

From: John Fastabend <[email protected]>

Disabling TSO can cause the dev_watchdog timer to be triggered because when TSO is disabled netif_tx_stop_all_queues is called. If the watchdog timer fires while the queues are stopped and traffic has not recently been sent on a paticular queue this is falsly identified as a hang and ndo_tx_timeout() is called. This is ocossionally seen during testing.

This removes the netif_tx_stop_all_queues() it is not needed. The scheduler submits skb's with dev_hard_start_xmit(), this checks if netif_needs_gso and if so it calls dev_gso_segment. Disabling TSO will cause dev_hard_start_xmit()
to do the gso processing. However ixgbe does not use the features flags to
determine if it needs to use tso or not instead it uses skb->gso_size so ixgbe will process these frames correctly regardless of the netdev features flag.

Quoted 3 lines

Applied.

#3 lore raw

PATCH 3/3 ixgbe: Do not allocate too many netdev txqueues

In reply to Jeff Kirsher

From: John Fastabend <[email protected]>

Instead of allocating 128 struct netdev_queue per device, use the minimum value between 128 and the number of possible txq's, to reduce ram usage and "tc -s -d class shod dev .." output.

This patch fixes Eric Dumazet's patch to set the TX queues to the correct minimum.

---

 drivers/net/ixgbe/ixgbe_main.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
drivers/net/ixgbe/ixgbe_main.c +13 -1
index 4a01022..a961da2 100644
@@ -5996,6 +5996,7 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,
 	const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
 	static int cards_found;
 	int i, err, pci_using_dac;
+	unsigned int indices = num_possible_cpus();
 #ifdef IXGBE_FCOE
 	u16 device_caps;
 #endif
@@ -6034,7 +6035,18 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,
 	pci_set_master(pdev);
 	pci_save_state(pdev);
 
-	netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
+	if (ii->mac == ixgbe_mac_82598EB)
+		indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
+	else
+		indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
+
+	indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
+#ifdef IXGBE_FCOE
+	indices += min_t(unsigned int, num_possible_cpus(),
+			 IXGBE_MAX_FCOE_INDICES);
+#endif
+	indices = min_t(unsigned int, indices, MAX_TX_QUEUES);
+	netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
 	if (!netdev) {
 		err = -ENOMEM;
 		goto err_alloc_etherdev;
maintainer Applied
#4 lore raw

Re: [net-next-2.6 PATCH 3/3] ixgbe: Do not allocate too many netdev txqueues

From: Jeff Kirsher <[email protected]>
Date: Fri, 26 Feb 2010 01:15:21 -0800

Quoted 11 lines

From: John Fastabend <[email protected]>

Instead of allocating 128 struct netdev_queue per device, use the minimum value between 128 and the number of possible txq's, to reduce ram usage and "tc -s -d class shod dev .." output.

This patch fixes Eric Dumazet's patch to set the TX queues to the correct minimum.

Applied.

#5 lore raw

Re: [net-next-2.6 PATCH 3/3] ixgbe: Do not allocate too many netdev txqueues

In reply to Jeff Kirsher
Quoted 39 lines · Jeff Kirsher

From: John Fastabend <[email protected]>

Instead of allocating 128 struct netdev_queue per device, use the minimum value between 128 and the number of possible txq's, to reduce ram usage and "tc -s -d class shod dev .." output.

This patch fixes Eric Dumazet's patch to set the TX queues to the correct minimum.

---

 drivers/net/ixgbe/ixgbe_main.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
drivers/net/ixgbe/ixgbe_main.c +6 -1
index 4a01022..a961da2 100644
@@ -5996,6 +5996,7 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,
 	const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
 	static int cards_found;
 	int i, err, pci_using_dac;
+	unsigned int indices = num_possible_cpus();
 #ifdef IXGBE_FCOE
 	u16 device_caps;
 #endif
@@ -6034,7 +6035,18 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,
 	pci_set_master(pdev);
 	pci_save_state(pdev);
 
-	netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
+	if (ii->mac == ixgbe_mac_82598EB)
+		indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
+	else
+		indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
+

drivers/net/ixgbe/ixgbe_main.c static int __devinit ixgbe_probe(struct pci_dev *pdev, · line 6052

Quoted 10 lines
drivers/net/ixgbe/ixgbe_main.c +7 -0
+	indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
+#ifdef IXGBE_FCOE
+	indices += min_t(unsigned int, num_possible_cpus(),
+			 IXGBE_MAX_FCOE_INDICES);
+#endif
+	indices = min_t(unsigned int, indices, MAX_TX_QUEUES);
+	netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
 	if (!netdev) {
 		err = -ENOMEM;
 		goto err_alloc_etherdev;

Thanks Jeff, but what is the reason for limiting to MAX_TX_QUEUES ? Is it a hardware issue ?

#6 lore raw

Re: [net-next-2.6 PATCH 3/3] ixgbe: Do not allocate too many netdev txqueues

Quoted 45 lines · Eric Dumazet
Quoted 44 lines · Jeff Kirsher

From: John Fastabend <[email protected]>

Instead of allocating 128 struct netdev_queue per device, use the minimum value between 128 and the number of possible txq's, to reduce ram usage and "tc -s -d class shod dev .." output.

This patch fixes Eric Dumazet's patch to set the TX queues to the correct minimum.

---

 drivers/net/ixgbe/ixgbe_main.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
drivers/net/ixgbe/ixgbe_main.c +12 -1
index 4a01022..a961da2 100644
@@ -5996,6 +5996,7 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,
 	const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
 	static int cards_found;
 	int i, err, pci_using_dac;
+	unsigned int indices = num_possible_cpus();
 #ifdef IXGBE_FCOE
 	u16 device_caps;
 #endif
@@ -6034,7 +6035,18 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,
 	pci_set_master(pdev);
 	pci_save_state(pdev);
 
-	netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
+	if (ii->mac == ixgbe_mac_82598EB)
+		indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
+	else
+		indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
+
+	indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
+#ifdef IXGBE_FCOE
+	indices += min_t(unsigned int, num_possible_cpus(),
+			 IXGBE_MAX_FCOE_INDICES);
+#endif
+	indices = min_t(unsigned int, indices, MAX_TX_QUEUES);
Quoted 9 lines

drivers/net/ixgbe/ixgbe_main.c static int __devinit ixgbe_probe(struct pci_dev *pdev, · line 6052

Quoted 5 lines
drivers/net/ixgbe/ixgbe_main.c +1 -0
+	netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
 	if (!netdev) {
 		err = -ENOMEM;
 		goto err_alloc_etherdev;

Thanks Jeff, but what is the reason for limiting to MAX_TX_QUEUES ? Is it a hardware issue ?

MAX_TX_QUEUES is 128, which is the maximum the 82599 device supports in hardware (82598 supports 32 Tx queues). I'm not sure why you'd ever want to have more Tx queues than what you have in the network device. Perhaps I don't understand the question?

Cheers,
-PJ

#7 lore raw

Re: [net-next-2.6 PATCH 3/3] ixgbe: Do not allocate too many netdev txqueues

Quoted 23 lines · Peter P Waskiewicz Jr
Quoted 12 lines · Eric Dumazet
Quoted 11 lines · Jeff Kirsher
drivers/net/ixgbe/ixgbe_main.c +11 -0
+	if (ii->mac == ixgbe_mac_82598EB)
+		indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
+	else
+		indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
+
+	indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
+#ifdef IXGBE_FCOE
+	indices += min_t(unsigned int, num_possible_cpus(),
+			 IXGBE_MAX_FCOE_INDICES);
+#endif
+	indices = min_t(unsigned int, indices, MAX_TX_QUEUES);
Quoted 9 lines

drivers/net/ixgbe/ixgbe_main.c static int __devinit ixgbe_probe(struct pci_dev *pdev, · line 6052

Quoted 5 lines
drivers/net/ixgbe/ixgbe_main.c +1 -0
+	netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
 	if (!netdev) {
 		err = -ENOMEM;
 		goto err_alloc_etherdev;

Thanks Jeff, but what is the reason for limiting to MAX_TX_QUEUES ? Is it a hardware issue ?

Quoted 3 lines

MAX_TX_QUEUES is 128, which is the maximum the 82599 device supports in hardware (82598 supports 32 Tx queues). I'm not sure why you'd ever want to have more Tx queues than what you have in the network device.

I was not sure MAX_TX_QUEUES capping was still necessary after the block :

if (ii->mac == ixgbe_mac_82598EB)

          indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);

else
indices = min_t(unsigned int, indices,
IXGBE_MAX_FDIR_INDICES);

indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);

#ifdef IXGBE_FCOE
	indices += min_t(unsigned int, num_possible_cpus(),
                    IXGBE_MAX_FCOE_INDICES);

#endif

So I asked to be sure that MAX_TX_QUEUES was not a leftover from the previous default allocation.

Thanks

#8 lore raw

Re: [net-next-2.6 PATCH 3/3] ixgbe: Do not allocate too many netdev txqueues

Quoted 41 lines · Eric Dumazet
Quoted 23 lines · Peter P Waskiewicz Jr
Quoted 12 lines · Eric Dumazet
Quoted 11 lines · Jeff Kirsher
drivers/net/ixgbe/ixgbe_main.c +11 -0
+	if (ii->mac == ixgbe_mac_82598EB)
+		indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
+	else
+		indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
+
+	indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
+#ifdef IXGBE_FCOE
+	indices += min_t(unsigned int, num_possible_cpus(),
+			 IXGBE_MAX_FCOE_INDICES);
+#endif
+	indices = min_t(unsigned int, indices, MAX_TX_QUEUES);
Quoted 9 lines

drivers/net/ixgbe/ixgbe_main.c static int __devinit ixgbe_probe(struct pci_dev *pdev, · line 6052

Quoted 5 lines
drivers/net/ixgbe/ixgbe_main.c +1 -0
+	netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
 	if (!netdev) {
 		err = -ENOMEM;
 		goto err_alloc_etherdev;

Thanks Jeff, but what is the reason for limiting to MAX_TX_QUEUES ? Is it a hardware issue ?

Quoted 3 lines

MAX_TX_QUEUES is 128, which is the maximum the 82599 device supports in hardware (82598 supports 32 Tx queues). I'm not sure why you'd ever want to have more Tx queues than what you have in the network device.

I was not sure MAX_TX_QUEUES capping was still necessary after the block :

if (ii->mac == ixgbe_mac_82598EB)

          indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);

else
indices = min_t(unsigned int, indices,
IXGBE_MAX_FDIR_INDICES);

indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);

#ifdef IXGBE_FCOE
	indices += min_t(unsigned int, num_possible_cpus(),
                    IXGBE_MAX_FCOE_INDICES);
Quoted 6 lines

#endif

So I asked to be sure that MAX_TX_QUEUES was not a leftover from the previous default allocation.

Thanks

I see what you're getting at now. The most we could have from this codepath is 72 indices for 82599, and 24 for 82598, so yeah, this is probably unneeded.

We can get the patch cleaned up.

Cheers,
-PJ

#9 lore raw

Re: [net-next-2.6 PATCH 3/3] ixgbe: Do not allocate too many netdev txqueues

Quoted 54 lines · Peter P
Quoted 44 lines · Eric Dumazet
Quoted 25 lines · Peter P Waskiewicz Jr
Quoted 13 lines · Eric Dumazet
Quoted 11 lines · Jeff Kirsher
drivers/net/ixgbe/ixgbe_main.c +11 -0
+	if (ii->mac == ixgbe_mac_82598EB)
+		indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
+	else
+		indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
+
+	indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
+#ifdef IXGBE_FCOE
+	indices += min_t(unsigned int, num_possible_cpus(),
+			 IXGBE_MAX_FCOE_INDICES);
+#endif
+	indices = min_t(unsigned int, indices, MAX_TX_QUEUES);
Quoted 10 lines

drivers/net/ixgbe/ixgbe_main.c static int __devinit ixgbe_probe(struct pci_dev *pdev, · line 6052

Quoted 6 lines
drivers/net/ixgbe/ixgbe_main.c +1 -0
+	netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
 	if (!netdev) {
 		err = -ENOMEM;
 		goto err_alloc_etherdev;

Thanks Jeff, but what is the reason for limiting to MAX_TX_QUEUES ? Is it a hardware issue ?

Quoted 4 lines

MAX_TX_QUEUES is 128, which is the maximum the 82599 device supports in hardware (82598 supports 32 Tx queues). I'm not sure why you'd ever want to have more Tx queues than what you have in the network device.

I was not sure MAX_TX_QUEUES capping was still necessary after the block :

if (ii->mac == ixgbe_mac_82598EB)

          indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);

else
indices = min_t(unsigned int, indices,
IXGBE_MAX_FDIR_INDICES);

indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);

#ifdef IXGBE_FCOE
	indices += min_t(unsigned int, num_possible_cpus(),
                    IXGBE_MAX_FCOE_INDICES);
Quoted 7 lines

#endif

So I asked to be sure that MAX_TX_QUEUES was not a leftover from the previous default allocation.

Thanks

Quoted 10 lines

I see what you're getting at now. The most we could have from this codepath is 72 indices for 82599, and 24 for 82598, so yeah, this is probably unneeded.

We can get the patch cleaned up.

Cheers,
-PJ

Thanks for catching this. I'll submit another patch to clean this up. Additionally, we can probably remove MAX_TX_QUEUES all together and use the above values instead. No reason to have a tx_ring array larger then we are ever going to use.

thanks
john.

maintainer Applied
#10 lore raw
In reply to Jeff Kirsher

From: Jeff Kirsher <[email protected]>
Date: Fri, 26 Feb 2010 01:14:37 -0800

Quoted 10 lines

From: Mallikarjuna R Chilakala <[email protected]>

Work around 82599 HW issue when HWRSC is enabled on IOMMU enabled kernels. 82599 HW is updating the header information after setting the descriptor to done, resulting DMA mapping/unmapping issues on IOMMU enabled systems. To work around the issue delay unmapping of first packet that carries the header information until end of packet is reached.

Applied.

#11 lore raw
In reply to Jeff Kirsher
Quoted 58 lines · Jeff Kirsher

From: Mallikarjuna R Chilakala <[email protected]>

Work around 82599 HW issue when HWRSC is enabled on IOMMU enabled kernels. 82599 HW is updating the header information after setting the descriptor to done, resulting DMA mapping/unmapping issues on IOMMU enabled systems. To work around the issue delay unmapping of first packet that carries the header information until end of packet is reached.

---

 drivers/net/ixgbe/ixgbe_main.c |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)
drivers/net/ixgbe/ixgbe_main.c +21 -3
index 3308790..4a01022 100644
@@ -818,6 +818,12 @@ static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb,
 	return skb;
 }
 
+struct ixgbe_rsc_cb {
+	dma_addr_t dma;
+};
+
+#define IXGBE_RSC_CB(skb) ((struct ixgbe_rsc_cb *)(skb)->cb)
+
 static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
                                struct ixgbe_ring *rx_ring,
                                int *work_done, int work_to_do)
@@ -867,9 +873,21 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
 		rx_buffer_info->skb = NULL;
 
 		if (rx_buffer_info->dma) {
-			pci_unmap_single(pdev, rx_buffer_info->dma,
-			                 rx_ring->rx_buf_len,
-			                 PCI_DMA_FROMDEVICE);
+			if ((adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
+			    (!(staterr & IXGBE_RXD_STAT_EOP)) &&
+				 (!(skb->prev)))
+				/*
+				 * When HWRSC is enabled, delay unmapping
+				 * of the first packet. It carries the
+				 * header information, HW may still
+				 * access the header after the writeback.
+				 * Only unmap it when EOP is reached
+				 */
+				IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
+			else
+				pci_unmap_single(pdev, rx_buffer_info->dma,
+				                 rx_ring->rx_buf_len,
+				                 PCI_DMA_FROMDEVICE);
 			rx_buffer_info->dma = 0;
 			skb_put(skb, len);
 		}

drivers/net/ixgbe/ixgbe_main.c static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, · line 941

Quoted 7 lines
drivers/net/ixgbe/ixgbe_main.c +4 -0
@@ -917,6 +935,10 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
 			if (skb->prev)
 				skb = ixgbe_transform_rsc_queue(skb, &(rx_ring->rsc_count));
 			if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
+				if (IXGBE_RSC_CB(skb)->dma)
+					pci_unmap_single(pdev, IXGBE_RSC_CB(skb)->dma,
+					                 rx_ring->rx_buf_len,
+					                 PCI_DMA_FROMDEVICE);

Does IXGBE_RSC_CB(skb)->dma need to be set to NULL here to avoid a double-free in ixgbe_clean_rx_ring() ?

Quoted 19 lines
drivers/net/ixgbe/ixgbe_main.c +4 -1
 				if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)
 					rx_ring->rsc_count += skb_shinfo(skb)->nr_frags;
 				else
@@ -3104,6 +3126,10 @@ static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
 			rx_buffer_info->skb = NULL;
 			do {
 				struct sk_buff *this = skb;
+				if (IXGBE_RSC_CB(this)->dma)
+					pci_unmap_single(pdev, IXGBE_RSC_CB(this)->dma,
+					                 rx_ring->rx_buf_len,
+					                 PCI_DMA_FROMDEVICE);
 				skb = skb->prev;
 				dev_kfree_skb(this);
 			} while (skb);
 
--

To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw
Quoted 72 lines

-----Original Message-----
From: Simon Horman [mailto:[email protected]]
Sent: Monday, March 01, 2010 4:29 PM
To: Kirsher, Jeffrey T
Cc: [email protected]; [email protected]; [email protected]; Chilakala, Mallikarjuna
Subject: Re: [net-next-2.6 PATCH 1/3] ixgbe: Fix DMA mapping/unmapping issues when HWRSC is enabled on IOMMU enabled kernels

Quoted 8 lines · Jeff Kirsher

From: Mallikarjuna R Chilakala <[email protected]>

Work around 82599 HW issue when HWRSC is enabled on IOMMU enabled kernels. 82599 HW is updating the header information after setting the descriptor to done, resulting DMA mapping/unmapping issues on IOMMU enabled systems. To work around the issue delay unmapping of first packet that carries the header information until end of packet is reached.

Review

Quoted 8 lines

---

 drivers/net/ixgbe/ixgbe_main.c |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ixgbe/ixgbe_main.c

drivers/net/ixgbe/ixgbe_main.c static inline struct sk_buff

Quoted 4 lines

index 3308790..4a01022 100644

drivers/net/ixgbe/ixgbe_main.c +0 -0
@@ -818,6 +818,12 @@ static inline struct sk_buff

*ixgbe_transform_rsc_queue(struct sk_buff *skb,

drivers/net/ixgbe/ixgbe_main.c static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector

Quoted 13 lines
drivers/net/ixgbe/ixgbe_main.c +6 -0
 	return skb;
 }
 
+struct ixgbe_rsc_cb {
+	dma_addr_t dma;
+};
+
+#define IXGBE_RSC_CB(skb) ((struct ixgbe_rsc_cb *)(skb)->cb)
+
 static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
                                struct ixgbe_ring *rx_ring,
                                int *work_done, int work_to_do)
@@ -867,9 +873,21 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector

*q_vector,

drivers/net/ixgbe/ixgbe_main.c static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector

Quoted 25 lines
drivers/net/ixgbe/ixgbe_main.c +15 -3
 		rx_buffer_info->skb = NULL;
 
 		if (rx_buffer_info->dma) {
-			pci_unmap_single(pdev, rx_buffer_info->dma,
-			                 rx_ring->rx_buf_len,
-			                 PCI_DMA_FROMDEVICE);
+			if ((adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
+			    (!(staterr & IXGBE_RXD_STAT_EOP)) &&
+				 (!(skb->prev)))
+				/*
+				 * When HWRSC is enabled, delay unmapping
+				 * of the first packet. It carries the
+				 * header information, HW may still
+				 * access the header after the writeback.
+				 * Only unmap it when EOP is reached
+				 */
+				IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
+			else
+				pci_unmap_single(pdev, rx_buffer_info->dma,
+				                 rx_ring->rx_buf_len,
+				                 PCI_DMA_FROMDEVICE);
 			rx_buffer_info->dma = 0;
 			skb_put(skb, len);
 		}
@@ -917,6 +935,10 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector

*q_vector,

Quoted 12 lines

drivers/net/ixgbe/ixgbe_main.c static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, · line 941

Quoted 8 lines
drivers/net/ixgbe/ixgbe_main.c +4 -0
 			if (skb->prev)
 				skb = ixgbe_transform_rsc_queue(skb, &(rx_ring-
 rsc_count));
 			if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
+				if (IXGBE_RSC_CB(skb)->dma)
+					pci_unmap_single(pdev, IXGBE_RSC_CB(skb)->dma,
+					                 rx_ring->rx_buf_len,
+					                 PCI_DMA_FROMDEVICE);

Does IXGBE_RSC_CB(skb)->dma need to be set to NULL here to avoid a double-free in ixgbe_clean_rx_ring() ?

It shouldn't happen, but it is good to set it to NULL. I'll send out a patch to fix this issue. Thanks for your review Horman.

Quoted 23 lines

drivers/net/ixgbe/ixgbe_main.c static void ixgbe_clean_rx_ring(struct

Quoted 6 lines
drivers/net/ixgbe/ixgbe_main.c +0 -0
 				if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)
 					rx_ring->rsc_count += skb_shinfo(skb)-

nr_frags;

drivers/net/ixgbe/ixgbe_main.c +0 -0
 				else
@@ -3104,6 +3126,10 @@ static void ixgbe_clean_rx_ring(struct

ixgbe_adapter *adapter,

Quoted 16 lines
drivers/net/ixgbe/ixgbe_main.c +4 -0
 			rx_buffer_info->skb = NULL;
 			do {
 				struct sk_buff *this = skb;
+				if (IXGBE_RSC_CB(this)->dma)
+					pci_unmap_single(pdev, IXGBE_RSC_CB(this)-
 dma,
+					                 rx_ring->rx_buf_len,
+					                 PCI_DMA_FROMDEVICE);
 				skb = skb->prev;
 				dev_kfree_skb(this);

} while (skb);

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html