Skip to contentSkip to conversation

ice: do not report CHECKSUM_COMPLETE when an XDP program is attached

PATCH In review Tianyi Gao 3 participants 10 messages Nov 21 – Nov 24

Subsystems (4)
lore
Share & tools
lore

Tianyi Gao

author
#0 lore raw

PATCH 1/1 ice: do not report CHECKSUM_COMPLETE when an XDP program is attached

On E830, ice reports CHECKSUM_COMPLETE with the generic checksum (GCS) that the hardware computes over the received frame. If an XDP program changes the packet and returns XDP_PASS, that checksum no longer matches. The stack then checks the packet again in software and calls netdev_rx_csum_fault().

On Cloudflare servers, an XDP load balancer removes the encapsulation of the packets that it accepts locally. Our production traffic hits netdev_rx_csum_fault() all the time.

Do not use GCS when the ring has an XDP program, as mlx5 has done since commit 5d0bb3bac4b9 ("net/mlx5e: XDP, Avoid checksum complete when XDP prog is loaded").

E830 also sets the L3L4P and checksum error bits, so the packet gets CHECKSUM_UNNECESSARY or CHECKSUM_NONE, as on E810. For example, a zero UDP checksum over IPv6 is marked as bad and gets CHECKSUM_NONE. A zero UDP checksum over IPv4 gets CHECKSUM_UNNECESSARY.

Two pending series [1][2] give XDP access to the checksum status. Neither of them supports CHECKSUM_COMPLETE.

ice_rx_csum() reads rx_ring->xdp_prog again after the poll loop ran XDP. While ICE_VSI_REBUILD_PENDING is set, ice_xdp_setup_prog() can replace the program without stopping NAPI, so the two reads can differ. At worst, a packet in that poll gets CHECKSUM_COMPLETE as before this patch. The pointer is only compared with NULL, so this cannot crash.

---
Tested on an E830 (8086:12d2, board N31483-007, fw.mgmt 7.9.5, DDP ICE COMMS 1.3.63.0) with an XDP program that removes a UDP encapsulation header with bpf_xdp_adjust_head() and returns XDP_PASS. The kernel was based on 6.18.64, where ice_rx_csum() is the same as in net:

- Before: 63322069 netdev_rx_csum_fault() calls in 30 s.
- After: 0.
- Without an XDP program, the port still reports CHECKSUM_COMPLETE.

On an E810, which has no GCS, drivers/net/xdp.py, ping.py and hw/csum.py give the same results with and without this patch.

Request for comment: I also prepared a drv-net selftest for net-next. It removes 16 bytes from the UDP payload with bpf_xdp_adjust_head() and fails if the packet reaches the stack with CHECKSUM_COMPLETE. I am not sure we want to enforce this for all NICs, so asking here.

 drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +1 -0
index e695a664e53d..ad22d855436e 100644
@@ -123,6 +123,7 @@ ice_rx_csum(struct ice_rx_ring *ring, struct sk_buff *skb,
 	rx_status1 = le16_to_cpu(rx_desc->wb.status_error1);
 
 	if ((ring->flags & ICE_RX_FLAGS_RING_GCS) &&
+	    !READ_ONCE(ring->xdp_prog) &&
 	    rx_desc->wb.rxdid == ICE_RXDID_FLEX_NIC &&
 	    (decoded.inner_prot == LIBETH_RX_PT_INNER_TCP ||
 	     decoded.inner_prot == LIBETH_RX_PT_INNER_UDP ||

base-commit: 92e97d7cffc7ec6adfa4699203c18b1ab0c8b314

Signature · 1 line
2.56.0
Acked-by on v1 1/1
#1 lore raw
Quoted 28 lines · Tianyi Gao

On E830, ice reports CHECKSUM_COMPLETE with the generic checksum (GCS) that the hardware computes over the received frame. If an XDP program changes the packet and returns XDP_PASS, that checksum no longer matches. The stack then checks the packet again in software and calls netdev_rx_csum_fault().

On Cloudflare servers, an XDP load balancer removes the encapsulation of the packets that it accepts locally. Our production traffic hits netdev_rx_csum_fault() all the time.

Do not use GCS when the ring has an XDP program, as mlx5 has done since commit 5d0bb3bac4b9 ("net/mlx5e: XDP, Avoid checksum complete when XDP prog is loaded").

E830 also sets the L3L4P and checksum error bits, so the packet gets CHECKSUM_UNNECESSARY or CHECKSUM_NONE, as on E810. For example, a zero UDP checksum over IPv6 is marked as bad and gets CHECKSUM_NONE. A zero UDP checksum over IPv4 gets CHECKSUM_UNNECESSARY.

Two pending series [1][2] give XDP access to the checksum status. Neither of them supports CHECKSUM_COMPLETE.

ice_rx_csum() reads rx_ring->xdp_prog again after the poll loop ran XDP. While ICE_VSI_REBUILD_PENDING is set, ice_xdp_setup_prog() can replace the program without stopping NAPI, so the two reads can differ. At worst, a packet in that poll gets CHECKSUM_COMPLETE as before this patch. The pointer is only compared with NULL, so this cannot crash.

Quoted 5 lines
Quoted 10 lines

---
Tested on an E830 (8086:12d2, board N31483-007, fw.mgmt 7.9.5, DDP ICE COMMS 1.3.63.0) with an XDP program that removes a UDP encapsulation header with bpf_xdp_adjust_head() and returns XDP_PASS. The kernel was based on 6.18.64, where ice_rx_csum() is the same as in net:

- Before: 63322069 netdev_rx_csum_fault() calls in 30 s.
- After: 0.
- Without an XDP program, the port still reports CHECKSUM_COMPLETE.

Quoted 7 lines

On an E810, which has no GCS, drivers/net/xdp.py, ping.py and hw/csum.py give the same results with and without this patch.

Request for comment: I also prepared a drv-net selftest for net-next. It removes 16 bytes from the UDP payload with bpf_xdp_adjust_head() and fails if the packet reaches the stack with CHECKSUM_COMPLETE. I am not sure we want to enforce this for all NICs, so asking here.

Anyone else besides mlx5 behaving this way?

Quoted 22 lines
 drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +1 -0
index e695a664e53d..ad22d855436e 100644
@@ -123,6 +123,7 @@ ice_rx_csum(struct ice_rx_ring *ring, struct sk_buff *skb,
 	rx_status1 = le16_to_cpu(rx_desc->wb.status_error1);
 
 	if ((ring->flags & ICE_RX_FLAGS_RING_GCS) &&
+	    !READ_ONCE(ring->xdp_prog) &&
 	    rx_desc->wb.rxdid == ICE_RXDID_FLEX_NIC &&
 	    (decoded.inner_prot == LIBETH_RX_PT_INNER_TCP ||
 	     decoded.inner_prot == LIBETH_RX_PT_INNER_UDP ||

base-commit: 92e97d7cffc7ec6adfa4699203c18b1ab0c8b314

Signature · 1 line
2.56.0
author
#2 lore raw
Quoted 1 line · Maciej Fijalkowski

Anyone else besides mlx5 behaving this way?

Thanks for the ack, Maciej.

From roughly analyzing the code, no. At least fbnic, gve, idpf, enetc, ionic, mlx4 and nfp report CHECKSUM_COMPLETE with an XDP program attached too, and I am not sure this list is exhaustive. So I am wondering whether we should enforce it for all drivers, with the drv-net selftest I mentioned.

The existing tests in xdp.py (test_xdp_native_adjst_head_* and test_xdp_native_adjst_tail_*) already change the frame and return XDP_PASS, but they only check the payload. A stale CHECKSUM_COMPLETE is only reported silently as "hw csum failure" in dmesg, so they still pass. Could you check the dmesg of the ice-E830-XXV2 NIPA runner?

#3 lore raw
In reply to Tianyi Gao
Quoted 67 lines · Tianyi Gao

On E830, ice reports CHECKSUM_COMPLETE with the generic checksum (GCS) that the hardware computes over the received frame. If an XDP program changes the packet and returns XDP_PASS, that checksum no longer matches. The stack then checks the packet again in software and calls netdev_rx_csum_fault().

On Cloudflare servers, an XDP load balancer removes the encapsulation of the packets that it accepts locally. Our production traffic hits netdev_rx_csum_fault() all the time.

Do not use GCS when the ring has an XDP program, as mlx5 has done since commit 5d0bb3bac4b9 ("net/mlx5e: XDP, Avoid checksum complete when XDP prog is loaded").

E830 also sets the L3L4P and checksum error bits, so the packet gets CHECKSUM_UNNECESSARY or CHECKSUM_NONE, as on E810. For example, a zero UDP checksum over IPv6 is marked as bad and gets CHECKSUM_NONE. A zero UDP checksum over IPv4 gets CHECKSUM_UNNECESSARY.

Two pending series [1][2] give XDP access to the checksum status. Neither of them supports CHECKSUM_COMPLETE.

ice_rx_csum() reads rx_ring->xdp_prog again after the poll loop ran XDP. While ICE_VSI_REBUILD_PENDING is set, ice_xdp_setup_prog() can replace the program without stopping NAPI, so the two reads can differ. At worst, a packet in that poll gets CHECKSUM_COMPLETE as before this patch. The pointer is only compared with NULL, so this cannot crash.

---
Tested on an E830 (8086:12d2, board N31483-007, fw.mgmt 7.9.5, DDP ICE COMMS 1.3.63.0) with an XDP program that removes a UDP encapsulation header with bpf_xdp_adjust_head() and returns XDP_PASS. The kernel was based on 6.18.64, where ice_rx_csum() is the same as in net:

- Before: 63322069 netdev_rx_csum_fault() calls in 30 s.
- After: 0.
- Without an XDP program, the port still reports CHECKSUM_COMPLETE.

On an E810, which has no GCS, drivers/net/xdp.py, ping.py and hw/csum.py give the same results with and without this patch.

Request for comment: I also prepared a drv-net selftest for net-next. It removes 16 bytes from the UDP payload with bpf_xdp_adjust_head() and fails if the packet reaches the stack with CHECKSUM_COMPLETE. I am not sure we want to enforce this for all NICs, so asking here.

 drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +1 -0
index e695a664e53d..ad22d855436e 100644
@@ -123,6 +123,7 @@ ice_rx_csum(struct ice_rx_ring *ring, struct sk_buff *skb,
 	rx_status1 = le16_to_cpu(rx_desc->wb.status_error1);
 
 	if ((ring->flags & ICE_RX_FLAGS_RING_GCS) &&
+	    !READ_ONCE(ring->xdp_prog) &&
 	    rx_desc->wb.rxdid == ICE_RXDID_FLEX_NIC &&
 	    (decoded.inner_prot == LIBETH_RX_PT_INNER_TCP ||
 	     decoded.inner_prot == LIBETH_RX_PT_INNER_UDP ||
Quoted 1 line

base-commit: 92e97d7cffc7ec6adfa4699203c18b1ab0c8b314

I'm not sure this is the best fix for this. If we are needing all NICs that support CHECKSUM_COMPLETE *and* XDP to report CHECKSUM_NONE in the event of a frame being modified by XDP it really feels like we should probably look at moving this further up the stack.

Otherwise the proper fix for this is probably going to need to be spread out to far more drivers as I suspect the intersection of the two is likely not that uncommon.

Also even if we go the multiple driver fix route I wonder if we shouldn't look at adding a new XDP return type to indicate that we are passing a modified frame so that we don't have every XDP program out there forcing NICs into a state where they have to start turning off various offloads across the board when they don't need to.

What we are going to end up with this current path is one group of XDP programs dragging down the performance of others since they will take the penalty for the ones that are making the dirty modifications.

author
#4 lore raw
Quoted 4 lines · Alexander H Duyck

I'm not sure this is the best fix for this. If we are needing all NICs that support CHECKSUM_COMPLETE *and* XDP to report CHECKSUM_NONE in the event of a frame being modified by XDP it really feels like we should probably look at moving this further up the stack.

Thanks for the review, Alex.

IMHO we should first make sure XDP programs do not cause "hw csum failure" in current kernels. Whatever an XDP program does, it should not be able to trigger a hw csum failure. It's not an uncommon use case, e.g., Katran from Meta [3] and Cloudflare's load balancer. And existing selftests already do it (test_xdp_native_adjst_head_* and test_xdp_native_adjst_tail_* in tools/testing/selftests/drivers/net/xdp.py).

Quoted 3 lines

Also even if we go the multiple driver fix route I wonder if we shouldn't look at adding a new XDP return type to indicate that we are passing a modified frame

IMHO that is for net-next. There we can add optimizations, such as a way to keep CHECKSUM_COMPLETE for programs that do not change the frame, potentially after [1] or [2] is accepted.

[3] https://github.com/facebookincubator/katran/blob/13a0d69221e43b4941b81303e6726ddc61a12169/katran/lib/bpf/pckt_encap.h#L137

#5 lore raw
Quoted 9 lines · Tianyi Gao
Quoted 4 lines · Alexander H Duyck

I'm not sure this is the best fix for this. If we are needing all NICs that support CHECKSUM_COMPLETE *and* XDP to report CHECKSUM_NONE in the event of a frame being modified by XDP it really feels like we should probably look at moving this further up the stack.

Thanks for the review, Alex.

Quoted 7 lines

IMHO we should first make sure XDP programs do not cause "hw csum failure" in current kernels. Whatever an XDP program does, it should not be able to trigger a hw csum failure. It's not an uncommon use case, e.g., Katran from Meta [3] and Cloudflare's load balancer. And existing selftests already do it (test_xdp_native_adjst_head_* and test_xdp_native_adjst_tail_* in tools/testing/selftests/drivers/net/xdp.py).

That is exactly my point though. What we have is a divergence between a number of the existing drivers in how they handle these things. As a result the behavior is currently different depending on which NIC is in use.

For example, one recent one I saw was an issue on the Tx side where an outgoing XDP program was modifying the frame and actually not updating the pseudoheader checksum. As a result it was breaking Tx checksum offloads for NICs that were using the HW_CSUM that used that checksum header. We could have fixed it by forcing all the drivers to recalculate the pseudo-header checksum, but instead we pushed back on the program that was making that change.

Quoted 7 lines
Quoted 3 lines

Also even if we go the multiple driver fix route I wonder if we shouldn't look at adding a new XDP return type to indicate that we are passing a modified frame

IMHO that is for net-next. There we can add optimizations, such as a way to keep CHECKSUM_COMPLETE for programs that do not change the frame, potentially after [1] or [2] is accepted.

The point is you are fixing things for your use case, but anybody who is using the CHECKSUM_COMPLETE to compute the checksum on the frames and using XDP without changing the frames will see this as a significant performance regression.

author
#6 lore raw
Quoted 7 lines · Alexander H Duyck

For example, one recent one I saw was an issue on the Tx side where an outgoing XDP program was modifying the frame and actually not updating the pseudoheader checksum. As a result it was breaking Tx checksum offloads for NICs that were using the HW_CSUM that used that checksum header. We could have fixed it by forcing all the drivers to recalculate the pseudo-header checksum, but instead we pushed back on the program that was making that change.

Thank you for the explanation, Alex.

On Tx the checksum is in the frame, so the program can fix it. On Rx the program can't touch skb->csum at all, so there is nothing to push back on.

Quoted 4 lines

The point is you are fixing things for your use case, but anybody who is using the CHECKSUM_COMPLETE to compute the checksum on the frames and using XDP without changing the frames will see this as a significant performance regression.

Without GCS, TCP and UDP still get CHECKSUM_UNNECESSARY, same as E810. GCS only came in v6.15, so this just puts E830 with XDP back to where it was.

The cases I can think of that are truly impacted are IPv6 with extension headers, and UDP tunnels that the NIC does not parse and that have a zero outer checksum. These fall back to software checksum.

And programs that do change the frame are worse off today. Every packet gets summed again in software, plus the "hw csum failure".

I don't see a fix that meets all of these:

1. It is small enough and can be backported to stable.
2. It fixes the problem fully. We could drop CHECKSUM_COMPLETE only when the program moved data or data_end, but some in-place writes, e.g. NAT or the IPv6 hop limit, would still trigger "hw csum failure". IMO that brings more problems.
3. It keeps CHECKSUM_COMPLETE for programs that do not change the frame. But that looks like a bigger change, which doesn't fit net.

If you have one, I am happy to take it. Otherwise, as I understand it, the choice is between:

1. A performance regression for some programs, but no "hw csum failure".
2. No regression for those programs, but "hw csum failure" stays for programs that change the frame.

I would like to know how the community normally decides between these.

#7 lore raw
Quoted 47 lines · Tianyi Gao
Quoted 7 lines · Alexander H Duyck

For example, one recent one I saw was an issue on the Tx side where an outgoing XDP program was modifying the frame and actually not updating the pseudoheader checksum. As a result it was breaking Tx checksum offloads for NICs that were using the HW_CSUM that used that checksum header. We could have fixed it by forcing all the drivers to recalculate the pseudo-header checksum, but instead we pushed back on the program that was making that change.

Thank you for the explanation, Alex.

On Tx the checksum is in the frame, so the program can fix it. On Rx the program can't touch skb->csum at all, so there is nothing to push back on.

Quoted 4 lines

The point is you are fixing things for your use case, but anybody who is using the CHECKSUM_COMPLETE to compute the checksum on the frames and using XDP without changing the frames will see this as a significant performance regression.

Without GCS, TCP and UDP still get CHECKSUM_UNNECESSARY, same as E810. GCS only came in v6.15, so this just puts E830 with XDP back to where it was.

The cases I can think of that are truly impacted are IPv6 with extension headers, and UDP tunnels that the NIC does not parse and that have a zero outer checksum. These fall back to software checksum.

And programs that do change the frame are worse off today. Every packet gets summed again in software, plus the "hw csum failure".

I don't see a fix that meets all of these:

1. It is small enough and can be backported to stable.
2. It fixes the problem fully. We could drop CHECKSUM_COMPLETE only when the program moved data or data_end, but some in-place writes, e.g. NAT or the IPv6 hop limit, would still trigger "hw csum failure". IMO that brings more problems.
3. It keeps CHECKSUM_COMPLETE for programs that do not change the frame. But that looks like a bigger change, which doesn't fit net.

If you have one, I am happy to take it. Otherwise, as I understand it, the choice is between:

Quoted 7 lines

1. A performance regression for some programs, but no "hw csum failure".
2. No regression for those programs, but "hw csum failure" stays for programs that change the frame.

I would like to know how the community normally decides between these.

The thing is your fix isn't really complete. As I said it is primarily just addressing your use case and sweeping follow-on issues under the rug. In the mlx5e case they were disabling the feature via the private control flag if it was enabled. In the case of your change you are just disabling it without exposing that it is disabled.

From what I can tell you are just bypassing the checksum complete logic, but you don't exit out of the function as a result. What effects is that having on frames that would have been normally checksum complete? Specifically, is it being treated as though the frame is unrecognized, or is it falling through into the CHECKSUM_UNNECESSARY path with all the indications that a tunnel was still there even though you stripped the header?

The issue is that the driver is making a number of assumptions about what is there based on what the hardware parsed for headers and such. With the headers being stripped and/or replaced those aren't correct anymore. That is why we should probably be looking at dropping more of the existing logic or forcing a rescan of the packet once the headers are replaced to update the descriptor data for the skb configuration.

author
#8 lore raw

Hi Alex,

Thank you for being so responsive, and I really appreciate it.

Quoted 3 lines · Alexander Duyck

In the mlx5e case they were disabling the feature via the private control flag if it was enabled. In the case of your change you are just disabling it without exposing that it is disabled.

mlx5 does not change the private flag when a program is attached. It sets MLX5E_RQ_STATE_NO_CSUM_COMPLETE on the RQ, and rx_no_csum_complete keeps its value ("off" by default).

Quoted 3 lines

is it falling through into the CHECKSUM_UNNECESSARY path with all the indications that a tunnel was still there even though you stripped the header?

Yes, the same path as E810, and mlx5 does the same with a program attached.

Quoted 2 lines

The issue is that the driver is making a number of assumptions about what is there based on what the hardware parsed for headers and such.

This was discussed in the thread of [1], including the decap problem with csum_level. The summary there was that reporting CHECKSUM_COMPLETE on the XDP-to-skb path is unsafe, and that the safest option for now is CHECKSUM_UNNECESSARY only [3]. The decap case with CHECKSUM_UNNECESSARY was left open as a known problem.

I am also working on the long-term design in [2], though there is still a long way to go. Please take a look if you are interested.

For this patch, my aim is simple: stop the "hw csum failure", and make E830 with XDP report RX checksums the same way as E810, i.e. as before GCS was added.

[3] https://lore.kernel.org/all/[email protected]/

Thanks,
Tianyi

#9 lore raw
Quoted 33 lines · Tianyi Gao

Hi Alex,

Thank you for being so responsive, and I really appreciate it.

Quoted 3 lines · Alexander Duyck

In the mlx5e case they were disabling the feature via the private control flag if it was enabled. In the case of your change you are just disabling it without exposing that it is disabled.

mlx5 does not change the private flag when a program is attached. It sets MLX5E_RQ_STATE_NO_CSUM_COMPLETE on the RQ, and rx_no_csum_complete keeps its value ("off" by default).

Quoted 3 lines

is it falling through into the CHECKSUM_UNNECESSARY path with all the indications that a tunnel was still there even though you stripped the header?

Yes, the same path as E810, and mlx5 does the same with a program attached.

Quoted 2 lines

The issue is that the driver is making a number of assumptions about what is there based on what the hardware parsed for headers and such.

This was discussed in the thread of [1], including the decap problem with csum_level. The summary there was that reporting CHECKSUM_COMPLETE on the XDP-to-skb path is unsafe, and that the safest option for now is CHECKSUM_UNNECESSARY only [3]. The decap case with CHECKSUM_UNNECESSARY was left open as a known problem.

I am also working on the long-term design in [2], though there is still a long way to go. Please take a look if you are interested.

Quoted 8 lines

For this patch, my aim is simple: stop the "hw csum failure", and make E830 with XDP report RX checksums the same way as E810, i.e. as before GCS was added.

[3] https://lore.kernel.org/all/[email protected]/

Thanks,
Tianyi

Any reason why you couldn't just strip the GCS enable flags from the rings when you add the XDP program in ndo_bpf instead of having to add a check for every packet if the XDP program is present? That would be closer to what they did for the Mellanox NIC and wouldn't be adding code to the hot path. Then it is just a matter of also adding an info message that you are disabling this in the log so if somebody does have to figure out a regression it should be more obvious.

Thinking in terms of what the final fix for this might look like, currently the drivers are already starting to carry stuff for frags to determine if they support jumbo frames via frags or not. I suspect we will likely need to do something similar when the time comes indicating if the program can avoid corrupting a checksum or not when it is stripping headers.

I am not super thrilled with the idea of this becoming standardized. In theory this would be much better if there was some way to pass the data out that the frame was mangled and what the checksum adjustment is to the total frame. As it stands we are probably going to be getting CHECKSUM_UNNECESSARY on everything even if we don't expect it. For example I don't know what will happen with an ICMP frame sent over this tunnel. I assume it is likely just discaring the CHECKSUM_UNECESSARY since it isn't used.