e1000e: fix Rx bugs
Subsystems (4)
cover e1000e: fix Rx bugs
Fix some longstanding bugs in Rx.
The first two patches address DMA mapping failure handling, eliminating some conditions which would result in DMA_MAPPING_ERROR being sent to h/w or to dma_unmap_page() or dma_unmap_single(). A teardown leak in the packet-splitting path is also fixed in the process.
The third patch fixes buffer overruns when RXALL is set.
Matt Vollrath (3):
e1000e: fix Rx skb DMA map error sentinel
e1000e: fix ps_pages DMA map error sentinel
e1000e: fix NETIF_F_RXALL buffer overrun
drivers/net/ethernet/intel/e1000e/netdev.c | 75 ++++++++++++++-------- 1 file changed, 47 insertions(+), 28 deletions(-)
base-commit: 1d2929d0850fff683b8aff051275945e65f082c8
Signature · 1 line
2.43.0
PATCH 1/3 e1000e: fix Rx skb DMA map error sentinel
Upon encountering a DMA_MAPPING_ERROR during skb allocation and mapping, the driver would leave DMA_MAPPING_ERROR in the buffer_info->dma field. This would lead several buffer_info->dma == 0 conditions down unwanted paths:
* In e1000_alloc_jumbo_rx_buffers(), it would not re-attempt the failed mapping and instead write DMA_MAPPING_ERROR to the h/w descriptor on the next allocation call. On cleaning or teardown it would attempt to dma_unmap_page() DMA_MAPPING_ERROR. This case would only be reachable at MTU > 1518 and page size > 16K.
* In e1000_clean_rx_ring(), it would attempt to dma_unmap_page/single() DMA_MAPPING_ERROR (unless cleaned by the jumbo path first). This case would be reachable at any combination of MTU and page size.
Use buffer_info->dma = 0 as the sentinel for "DMA is not mapped." Set it immediately upon detecting the failure.
--- drivers/net/ethernet/intel/e1000e/netdev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/intel/e1000e/netdev.c +3 -0
@@ -691,6 +691,7 @@ static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring, adapter->rx_buffer_len, DMA_FROM_DEVICE);if (dma_mapping_error (&pdev->dev, buffer_info->dma)) { + buffer_info->dma =0 ;dev_err (&pdev->dev,"Rx DMA map failed\n" ); adapter->rx_dma_failed++;break ;
@@ -791,6 +792,7 @@ static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring, adapter->rx_ps_bsize0, DMA_FROM_DEVICE);if (dma_mapping_error (&pdev->dev, buffer_info->dma)) { + buffer_info->dma =0 ;dev_err (&pdev->dev,"Rx DMA map failed\n" ); adapter->rx_dma_failed++;/* cleanup skb */
@@ -877,6 +879,7 @@ static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,PAGE_SIZE , DMA_FROM_DEVICE);if (dma_mapping_error (&pdev->dev, buffer_info->dma)) { + buffer_info->dma =0 ; adapter->alloc_rx_buff_failed++;break ; }
Signature · 1 line
2.43.0
PATCH 2/3 e1000e: fix ps_pages DMA map error sentinel
In reply to Matt VollrathWhile allocating packet-split buffer pages, a failed DMA mapping would leave DMA_MAPPING_ERROR in the ps_page->dma field.
This would have two consequences:
* The next attempt to allocate that buffer would write DMA_MAPPING_ERROR to h/w if all pages are allocated. If the h/w uses that buffer and is handling a frame large enough to touch the affected page, it would cause a DMA fault and be dropped. The driver would then call dma_unmap_page() on DMA_MAPPING_ERROR and unknowingly send the uninitialized page up the stack as part of the frame payload.
* On ring teardown, dma_unmap_page() would be called on DMA_MAPPING_ERROR.
This condition is only reachable when MTU > 1500 and PAGE_SIZE <= 16K.
Fix this by setting ps_page->dma = 0 upon mapping failure and separately testing ->page and ->dma during allocation and teardown.
The rewrite of the ps_pages section of e1000_clean_rx_ring was necessary to recognize the case of a mapped page without a valid DMA mapping. It also fixes a separate bug which would potentially leak pages on ring teardown. The cleaner stops cleaning pages when h/w reported that it did not write to a page in the sequence, leaving the following pages allocated and mapped. The teardown would then break early and leak the unused mapped pages. If the ring is re-allocated with similar configuration, it would reclaim those lost pages. This would only affect configurations with rx_ps_pages >= 2 (MTU > PAGE_SIZE) and the same condition of MTU > 1500 and PAGE_SIZE <= 16K.
--- drivers/net/ethernet/intel/e1000e/netdev.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/e1000e/netdev.c +12 -7
@@ -759,12 +759,15 @@ static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring, adapter->alloc_rx_buff_failed++; goto no_buffers; } + } +if (!ps_page->dma) { ps_page->dma =dma_map_page (&pdev->dev, ps_page->page,0 ,PAGE_SIZE ,DMA_FROM_DEVICE );if (dma_mapping_error (&pdev->dev, ps_page->dma)) { + ps_page->dma =0 ;dev_err (&adapter->pdev->dev,"Rx DMA page map failed\n" ); adapter->rx_dma_failed++;
@@ -1722,13 +1725,15 @@ static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)for (j =0 ; j <PS_PAGE_BUFFERS ; j++) { ps_page = &buffer_info->ps_pages[j]; -if (!ps_page->page) -break ; -dma_unmap_page (&pdev->dev, ps_page->dma,PAGE_SIZE , -DMA_FROM_DEVICE ); - ps_page->dma =0 ; -put_page (ps_page->page); - ps_page->page =NULL ; +if (ps_page->dma) { +dma_unmap_page (&pdev->dev, ps_page->dma, +PAGE_SIZE ,DMA_FROM_DEVICE ); + ps_page->dma =0 ; + } +if (ps_page->page) { +put_page (ps_page->page); + ps_page->page =NULL ; + } } }
Signature · 1 line
2.43.0
PATCH 3/3 e1000e: fix NETIF_F_RXALL buffer overrun
In reply to Matt VollrathWhen SBP is set, the card may deliver frames which would otherwise be filtered out by LPE being unset. This would allow the device to write up to 526 bytes beyond the skb's data allocation: over its own shinfo, and beyond. This bug is reachable only when MTU <= 1500 and NETIF_F_RXALL is set ("ethtool -K <dev> rx-all on").
Ensure that buffers are large enough for an entire 2048 byte chunk when NETIF_F_RXALL is set. Do this by moving final rx_buffer_len determination to one place, right before RCTL.BSIZE is determined. This will correctly re-evaluate every time the adapter is configured, not just on MTU change.
--- drivers/net/ethernet/intel/e1000e/netdev.c | 53 +++++++++++++--------- 1 file changed, 32 insertions(+), 21 deletions(-)
drivers/net/ethernet/intel/e1000e/netdev.c +32 -21
@@ -3036,6 +3036,33 @@ static void e1000_configure_tx(struct e1000_adapter *adapter)#define PAGE_USE_COUNT (S ) (((S) >> PAGE_SHIFT) + \ (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) +/** +* e1000_set_rx_buffer_len - determine the Rx buffer size +* @adapter: Board private structure +**/ +static void e1000_set_rx_buffer_len (struct e1000_adapter *adapter) +{ +struct net_device *netdev = adapter->netdev; +u32 max_frame = adapter->max_frame_size; + +/* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN +* means we reserve 2 more, this pushes us to allocate from the next +* larger slab size. +* i.e. RXBUFFER_2048 --> size-4096 slab +* However with the new *_jumbo_rx* routines, jumbo receives will use +* fragmented skbs +*/ +if (max_frame <=2048 ) + adapter->rx_buffer_len =2048 ; +else + adapter->rx_buffer_len =4096 ; + +/* adjust allocation if LPE protects us, and we aren't using SBP */ +if (max_frame <= (VLAN_ETH_FRAME_LEN +ETH_FCS_LEN ) && + !(netdev->features &NETIF_F_RXALL )) + adapter->rx_buffer_len =VLAN_ETH_FRAME_LEN +ETH_FCS_LEN ; +} +/** * e1000_setup_rctl - configure the receive control registers * @adapter: Board private structure
@@ -3102,6 +3129,8 @@ static void e1000_setup_rctl(struct e1000_adapter *adapter)e1e_wphy (hw,22 , phy_data); } +e1000_set_rx_buffer_len (adapter); +/* Setup buffer sizes */ rctl &= ~E1000_RCTL_SZ_4096 ; rctl |=E1000_RCTL_BSEX ;
@@ -6087,30 +6116,12 @@ static int e1000_change_mtu(struct net_device *netdev, int new_mtu)pm_runtime_get_sync (netdev->dev.parent); -if (netif_running (netdev)) +if (netif_running (netdev)) {e1000e_down (adapter, true); - -/* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN -* means we reserve 2 more, this pushes us to allocate from the next -* larger slab size. -* i.e. RXBUFFER_2048 --> size-4096 slab -* However with the new *_jumbo_rx* routines, jumbo receives will use -* fragmented skbs -*/ - -if (max_frame <=2048 ) - adapter->rx_buffer_len =2048 ; -else - adapter->rx_buffer_len =4096 ; - -/* adjust allocation if LPE protects us, and we aren't using SBP */ -if (max_frame <= (VLAN_ETH_FRAME_LEN +ETH_FCS_LEN )) - adapter->rx_buffer_len =VLAN_ETH_FRAME_LEN +ETH_FCS_LEN ; - -if (netif_running (netdev))e1000e_up (adapter); -else + }else {e1000e_reset (adapter); + }pm_runtime_put_sync (netdev->dev.parent);
Signature · 1 line
2.43.0
Re: [PATCH iwl-net 3/3] e1000e: fix NETIF_F_RXALL buffer overrun
Quoted 69 lines · Matt Vollrath
When SBP is set, the card may deliver frames which would otherwise be filtered out by LPE being unset. This would allow the device to write up to 526 bytes beyond the skb's data allocation: over its own shinfo, and beyond. This bug is reachable only when MTU <= 1500 and
NETIF_F_RXALLis set ("ethtool -K <dev> rx-all on").Ensure that buffers are large enough for an entire 2048 byte chunk when
NETIF_F_RXALLis set. Do this by moving finalrx_buffer_lendetermination to one place, right before RCTL.BSIZE is determined. This will correctly re-evaluate every time the adapter is configured, not just on MTU change.Signed-off-by Matt Vollrath <[email protected]>Suggested-by Jakub Kicinski <[email protected]>Assisted-by Claude:claude-5-fableFixes cf955e6c96cb ("e1000e: Support RXALL feature flag.")--- drivers/net/ethernet/intel/e1000e/netdev.c | 53 +++++++++++++--------- 1 file changed, 32 insertions(+), 21 deletions(-)drivers/net/ethernet/intel/e1000e/netdev.c +29
-0@@ -3036,6 +3036,33 @@ static void e1000_configure_tx(struct e1000_adapter *adapter)#define PAGE_USE_COUNT (S ) (((S) >> PAGE_SHIFT) + \ (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) +/** +* e1000_set_rx_buffer_len - determine the Rx buffer size +* @adapter: Board private structure +**/ +static void e1000_set_rx_buffer_len (struct e1000_adapter *adapter) +{ +struct net_device *netdev = adapter->netdev; +u32 max_frame = adapter->max_frame_size; + +/* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN +* means we reserve 2 more, this pushes us to allocate from the next +* larger slab size. +* i.e. RXBUFFER_2048 --> size-4096 slab +* However with the new *_jumbo_rx* routines, jumbo receives will use +* fragmented skbs +*/ +if (max_frame <=2048 ) + adapter->rx_buffer_len =2048 ; +else + adapter->rx_buffer_len =4096 ; + +/* adjust allocation if LPE protects us, and we aren't using SBP */ +if (max_frame <= (VLAN_ETH_FRAME_LEN +ETH_FCS_LEN ) && + !(netdev->features &NETIF_F_RXALL )) + adapter->rx_buffer_len =VLAN_ETH_FRAME_LEN +ETH_FCS_LEN ; +} +/** * e1000_setup_rctl - configure the receive control registers * @adapter: Board private structure @@ -3102,6 +3129,8 @@ static void e1000_setup_rctl(struct e1000_adapter *adapter)e1e_wphy (hw,22 , phy_data); } +e1000_set_rx_buffer_len (adapter); +/* Setup buffer sizes */ rctl &= ~E1000_RCTL_SZ_4096 ; rctl |=E1000_RCTL_BSEX ;
drivers/net/ethernet/intel/e1000e/netdev.c static int e1000_change_mtu(struct net_device *netdev, int new_mtu) · line 6119
Quoted 5 lines
drivers/net/ethernet/intel/e1000e/netdev.c +1
-1@@ -6087,30 +6116,12 @@ static int e1000_change_mtu(struct net_device *netdev, int new_mtu)pm_runtime_get_sync (netdev->dev.parent); -if (netif_running (netdev)) +if (netif_running (netdev)) {
I see now that I should not have collapsed this to one netif_running check.
Quoted 28 lines
drivers/net/ethernet/intel/e1000e/netdev.c +2
-20e1000e_down (adapter, true); - -/* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN -* means we reserve 2 more, this pushes us to allocate from the next -* larger slab size. -* i.e. RXBUFFER_2048 --> size-4096 slab -* However with the new *_jumbo_rx* routines, jumbo receives will use -* fragmented skbs -*/ - -if (max_frame <=2048 ) - adapter->rx_buffer_len =2048 ; -else - adapter->rx_buffer_len =4096 ; - -/* adjust allocation if LPE protects us, and we aren't using SBP */ -if (max_frame <= (VLAN_ETH_FRAME_LEN +ETH_FCS_LEN )) - adapter->rx_buffer_len =VLAN_ETH_FRAME_LEN +ETH_FCS_LEN ; - -if (netif_running (netdev))e1000e_up (adapter); -else + }else {e1000e_reset (adapter); + }pm_runtime_put_sync (netdev->dev.parent);