Skip to contentSkip to conversation

ixgbe: Don't call kmap() on page allocated with GFP_ATOMIC

PATCH Superseded Fabio M. De Francesco 4 participants 4 messages Jul 4, 2022 – Aug 4, 2022

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

PATCH 1/1 ixgbe: Don't call kmap() on page allocated with GFP_ATOMIC

Pages allocated with GFP_ATOMIC cannot come from Highmem. This is why there is no need to call kmap() on them.

Therefore, don't call kmap() on rx_buffer->page() and instead use a plain page_address() to get the kernel address.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +1 -3
index 628d0eb0599f..71196fd92f81 100644
@@ -1966,15 +1966,13 @@ static bool ixgbe_check_lbtest_frame(struct ixgbe_rx_buffer *rx_buffer,
 
 	frame_size >>= 1;
 
-	data = kmap(rx_buffer->page) + rx_buffer->page_offset;
+	data = page_address(rx_buffer->page) + rx_buffer->page_offset;
 
 	if (data[3] != 0xFF ||
 	    data[frame_size + 10] != 0xBE ||
 	    data[frame_size + 12] != 0xAF)
 		match = false;
 
-	kunmap(rx_buffer->page);
-
 	return match;
 }
 
Signature · 1 line
2.36.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Fabio M. De Francesco

Pages allocated with GFP_ATOMIC cannot come from Highmem. This is why there is no need to call kmap() on them.

I'm still not 100% sure where this page gets allocated but AFAICT it is allocated in ixgbe_alloc_mapped_page() which calls dev_alloc_pages() for the allocation which is where the GFP_ATOMIC is specified.

I think I would add this detail here.

That said, and assuming my analysis is correct, the code looks fine so:

Quoted 35 lines

Therefore, don't call kmap() on rx_buffer->page() and instead use a plain page_address() to get the kernel address.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +1 -3
index 628d0eb0599f..71196fd92f81 100644
@@ -1966,15 +1966,13 @@ static bool ixgbe_check_lbtest_frame(struct ixgbe_rx_buffer *rx_buffer,
 
 	frame_size >>= 1;
 
-	data = kmap(rx_buffer->page) + rx_buffer->page_offset;
+	data = page_address(rx_buffer->page) + rx_buffer->page_offset;
 
 	if (data[3] != 0xFF ||
 	    data[frame_size + 10] != 0xBE ||
 	    data[frame_size + 12] != 0xAF)
 		match = false;
 
-	kunmap(rx_buffer->page);
-
 	return match;
 }
 
Signature · 1 line
2.36.1
Reviewed-by
#2 lore raw
Quoted 5 lines · Ira Weiny
Quoted 2 lines · Fabio M. De Francesco

Pages allocated with GFP_ATOMIC cannot come from Highmem. This is why there is no need to call kmap() on them.

Quoted 7 lines

I'm still not 100% sure where this page gets allocated but AFAICT it is allocated in ixgbe_alloc_mapped_page() which calls dev_alloc_pages() for the allocation which is where the GFP_ATOMIC is specified.

I think I would add this detail here.

That said, and assuming my analysis is correct, the code looks fine so:

Yeah, this is actually called out in other spots in the buffer cleaning path. This is just something I had overlooked and left in place back a few refactors ago.. :-)

https://elixir.bootlin.com/linux/latest/source/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c#L1795

Tested-by on v1 1/1
#3 lore raw
In reply to Fabio M. De Francesco
Quoted 25 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Fabio M. De Francesco
Sent: Monday, July 4, 2022 7:31 PM
To: Brandeburg, Jesse <[email protected]>; Nguyen, Anthony L <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Alexei Starovoitov <[email protected]>; Daniel Borkmann <[email protected]>; Jesper Dangaard Brouer <[email protected]>; John Fastabend <[email protected]>; intel- [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: Weiny, Ira <[email protected]>; Fabio M. De Francesco <[email protected]>
Subject: [Intel-wired-lan] [PATCH] ixgbe: Don't call kmap() on page allocated with GFP_ATOMIC

Pages allocated with GFP_ATOMIC cannot come from Highmem. This is why there is no need to call kmap() on them.

Therefore, don't call kmap() on rx_buffer->page() and instead use a plain page_address() to get the kernel address.

Quoted 7 lines
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)