Skip to contentSkip to conversation

hw/net/net_tx_pkt: Fix virtio header without checksum offloading

PATCH Superseded Akihiko Odaki 2 participants 11 messages Mar 24, 2024 – Mar 27, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/net/net_tx_pkt: Fix virtio header without checksum offloading

It is incorrect to have the VIRTIO_NET_HDR_F_NEEDS_CSUM set when checksum offloading is disabled so clear the bit. Set the VIRTIO_NET_HDR_F_DATA_VALID bit instead to tell the checksum is valid.

TCP/UDP checksum is usually offloaded when the peer requires virtio headers because they can instruct the peer to compute checksum. However, igb disables TX checksum offloading when a VF is enabled whether the peer requires virtio headers because a transmitted packet can be routed to it and it expects the packet has a proper checksum. Therefore, it is necessary to have a correct virtio header even when checksum offloading is disabled.

A real TCP/UDP checksum will be computed and saved in the buffer when checksum offloading is disabled. The virtio specification requires to set the packet checksum stored in the buffer to the TCP/UDP pseudo header when the VIRTIO_NET_HDR_F_NEEDS_CSUM bit is set so the bit must be cleared in that case.

The VIRTIO_NET_HDR_F_NEEDS_CSUM bit also tells to skip checksum validation. Even if checksum offloading is disabled, it is desirable to skip checksum validation because the checksum is always correct. Use the VIRTIO_NET_HDR_F_DATA_VALID bit to claim the validity of the checksum.

Fixes ffbd2dbd8e64 ("e1000e: Perform software segmentation for loopback")
---
 hw/net/net_tx_pkt.c | 3 +++
 1 file changed, 3 insertions(+)
hw/net/net_tx_pkt.c +3 -0
index 2e5f58b3c9cc..c225cf706513 100644
@@ -833,6 +833,9 @@ bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload,
 
     if (offload || gso_type == VIRTIO_NET_HDR_GSO_NONE) {
         if (!offload && pkt->virt_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
+            pkt->virt_hdr.flags =
+                (pkt->virt_hdr.flags & ~VIRTIO_NET_HDR_F_NEEDS_CSUM) |
+                VIRTIO_NET_HDR_F_DATA_VALID;
             net_tx_pkt_do_sw_csum(pkt, &pkt->vec[NET_TX_PKT_L2HDR_FRAG],
                                   pkt->payload_frags + NET_TX_PKT_PL_START_FRAG - 1,
                                   pkt->payload_len);

---
base-commit: ba49d760eb04630e7b15f423ebecf6c871b8f77b
change-id: 20240324-tx-c57d3c22ad73

Best regards,

Signature · 1 line
Akihiko Odaki <[email protected]>
#1 lore raw
Quoted 36 lines · Akihiko Odaki

It is incorrect to have the VIRTIO_NET_HDR_F_NEEDS_CSUM set when checksum offloading is disabled so clear the bit. Set the VIRTIO_NET_HDR_F_DATA_VALID bit instead to tell the checksum is valid.

TCP/UDP checksum is usually offloaded when the peer requires virtio headers because they can instruct the peer to compute checksum. However, igb disables TX checksum offloading when a VF is enabled whether the peer requires virtio headers because a transmitted packet can be routed to it and it expects the packet has a proper checksum. Therefore, it is necessary to have a correct virtio header even when checksum offloading is disabled.

A real TCP/UDP checksum will be computed and saved in the buffer when checksum offloading is disabled. The virtio specification requires to set the packet checksum stored in the buffer to the TCP/UDP pseudo header when the VIRTIO_NET_HDR_F_NEEDS_CSUM bit is set so the bit must be cleared in that case.

The VIRTIO_NET_HDR_F_NEEDS_CSUM bit also tells to skip checksum validation. Even if checksum offloading is disabled, it is desirable to skip checksum validation because the checksum is always correct. Use the VIRTIO_NET_HDR_F_DATA_VALID bit to claim the validity of the checksum.

Fixes ffbd2dbd8e64 ("e1000e: Perform software segmentation for loopback")
---
 hw/net/net_tx_pkt.c | 3 +++
 1 file changed, 3 insertions(+)
hw/net/net_tx_pkt.c +0 -0
index 2e5f58b3c9cc..c225cf706513 100644

hw/net/net_tx_pkt.c bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload, · line 838

Quoted 6 lines
hw/net/net_tx_pkt.c +3 -0
@@ -833,6 +833,9 @@ bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload,
 
     if (offload || gso_type == VIRTIO_NET_HDR_GSO_NONE) {
         if (!offload && pkt->virt_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
+            pkt->virt_hdr.flags =
+                (pkt->virt_hdr.flags & ~VIRTIO_NET_HDR_F_NEEDS_CSUM) |
+                VIRTIO_NET_HDR_F_DATA_VALID;

Why VIRTIO_NET_HDR_F_DATA_VALID is used in TX path?

Thanks

Quoted 12 lines
hw/net/net_tx_pkt.c +0 -1
             net_tx_pkt_do_sw_csum(pkt, &pkt->vec[NET_TX_PKT_L2HDR_FRAG],
                                   pkt->payload_frags + NET_TX_PKT_PL_START_FRAG - 1,
                                   pkt->payload_len);
 
---

base-commit: ba49d760eb04630e7b15f423ebecf6c871b8f77b
change-id: 20240324-tx-c57d3c22ad73

Best regards,
--
Akihiko Odaki <[email protected]>

#2 lore raw
Quoted 38 lines · Jason Wang
Quoted 37 lines · Akihiko Odaki

It is incorrect to have the VIRTIO_NET_HDR_F_NEEDS_CSUM set when checksum offloading is disabled so clear the bit. Set the VIRTIO_NET_HDR_F_DATA_VALID bit instead to tell the checksum is valid.

TCP/UDP checksum is usually offloaded when the peer requires virtio headers because they can instruct the peer to compute checksum. However, igb disables TX checksum offloading when a VF is enabled whether the peer requires virtio headers because a transmitted packet can be routed to it and it expects the packet has a proper checksum. Therefore, it is necessary to have a correct virtio header even when checksum offloading is disabled.

A real TCP/UDP checksum will be computed and saved in the buffer when checksum offloading is disabled. The virtio specification requires to set the packet checksum stored in the buffer to the TCP/UDP pseudo header when the VIRTIO_NET_HDR_F_NEEDS_CSUM bit is set so the bit must be cleared in that case.

The VIRTIO_NET_HDR_F_NEEDS_CSUM bit also tells to skip checksum validation. Even if checksum offloading is disabled, it is desirable to skip checksum validation because the checksum is always correct. Use the VIRTIO_NET_HDR_F_DATA_VALID bit to claim the validity of the checksum.

Fixes ffbd2dbd8e64 ("e1000e: Perform software segmentation for loopback")
---
  hw/net/net_tx_pkt.c | 3 +++
  1 file changed, 3 insertions(+)
hw/net/net_tx_pkt.c +0 -0
index 2e5f58b3c9cc..c225cf706513 100644
@@ -833,6 +833,9 @@ bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload,
 
Quoted 7 lines

hw/net/net_tx_pkt.c bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload, · line 838

Quoted 5 lines
hw/net/net_tx_pkt.c +3 -0
      if (offload || gso_type == VIRTIO_NET_HDR_GSO_NONE) {
          if (!offload && pkt->virt_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
+            pkt->virt_hdr.flags =
+                (pkt->virt_hdr.flags & ~VIRTIO_NET_HDR_F_NEEDS_CSUM) |
+                VIRTIO_NET_HDR_F_DATA_VALID;

Why VIRTIO_NET_HDR_F_DATA_VALID is used in TX path?

On igb, a packet sent from a PCI function may be routed to another function. The virtio header updated here will be directly provided to the RX path in such a case.

Regards,
Akihiko Odaki

Quoted 16 lines

Thanks

Quoted 12 lines
hw/net/net_tx_pkt.c +0 -1
              net_tx_pkt_do_sw_csum(pkt, &pkt->vec[NET_TX_PKT_L2HDR_FRAG],
                                    pkt->payload_frags + NET_TX_PKT_PL_START_FRAG - 1,
                                    pkt->payload_len);
 
---

base-commit: ba49d760eb04630e7b15f423ebecf6c871b8f77b
change-id: 20240324-tx-c57d3c22ad73

Best regards,
--
Akihiko Odaki <[email protected]>

#3 lore raw
Quoted 48 lines · Akihiko Odaki
Quoted 38 lines · Jason Wang
Quoted 37 lines · Akihiko Odaki

It is incorrect to have the VIRTIO_NET_HDR_F_NEEDS_CSUM set when checksum offloading is disabled so clear the bit. Set the VIRTIO_NET_HDR_F_DATA_VALID bit instead to tell the checksum is valid.

TCP/UDP checksum is usually offloaded when the peer requires virtio headers because they can instruct the peer to compute checksum. However, igb disables TX checksum offloading when a VF is enabled whether the peer requires virtio headers because a transmitted packet can be routed to it and it expects the packet has a proper checksum. Therefore, it is necessary to have a correct virtio header even when checksum offloading is disabled.

A real TCP/UDP checksum will be computed and saved in the buffer when checksum offloading is disabled. The virtio specification requires to set the packet checksum stored in the buffer to the TCP/UDP pseudo header when the VIRTIO_NET_HDR_F_NEEDS_CSUM bit is set so the bit must be cleared in that case.

The VIRTIO_NET_HDR_F_NEEDS_CSUM bit also tells to skip checksum validation. Even if checksum offloading is disabled, it is desirable to skip checksum validation because the checksum is always correct. Use the VIRTIO_NET_HDR_F_DATA_VALID bit to claim the validity of the checksum.

Fixes ffbd2dbd8e64 ("e1000e: Perform software segmentation for loopback")
---
  hw/net/net_tx_pkt.c | 3 +++
  1 file changed, 3 insertions(+)
hw/net/net_tx_pkt.c +0 -0
index 2e5f58b3c9cc..c225cf706513 100644
@@ -833,6 +833,9 @@ bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload,
 
Quoted 7 lines

hw/net/net_tx_pkt.c bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload, · line 838

Quoted 5 lines
hw/net/net_tx_pkt.c +3 -0
      if (offload || gso_type == VIRTIO_NET_HDR_GSO_NONE) {
          if (!offload && pkt->virt_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
+            pkt->virt_hdr.flags =
+                (pkt->virt_hdr.flags & ~VIRTIO_NET_HDR_F_NEEDS_CSUM) |
+                VIRTIO_NET_HDR_F_DATA_VALID;

Why VIRTIO_NET_HDR_F_DATA_VALID is used in TX path?

Quoted 3 lines

On igb, a packet sent from a PCI function may be routed to another function. The virtio header updated here will be directly provided to the RX path in such a case.

But I meant for example net_tx_pkt_send_custom() is used in e1000e_tx_pkt_send() which is the tx path on the host.

VIRTIO_NET_HDR_F_DATA_VALID is not necessary in the tx path.

Thanks

Quoted 21 lines

Regards,
Akihiko Odaki

Quoted 16 lines

Thanks

Quoted 12 lines
hw/net/net_tx_pkt.c +0 -1
              net_tx_pkt_do_sw_csum(pkt, &pkt->vec[NET_TX_PKT_L2HDR_FRAG],
                                    pkt->payload_frags + NET_TX_PKT_PL_START_FRAG - 1,
                                    pkt->payload_len);
 
---

base-commit: ba49d760eb04630e7b15f423ebecf6c871b8f77b
change-id: 20240324-tx-c57d3c22ad73

Best regards,
--
Akihiko Odaki <[email protected]>

#4 lore raw
Quoted 49 lines · Jason Wang
Quoted 48 lines · Akihiko Odaki
Quoted 45 lines · Jason Wang
Quoted 36 lines · Akihiko Odaki

It is incorrect to have the VIRTIO_NET_HDR_F_NEEDS_CSUM set when checksum offloading is disabled so clear the bit. Set the VIRTIO_NET_HDR_F_DATA_VALID bit instead to tell the checksum is valid.

TCP/UDP checksum is usually offloaded when the peer requires virtio headers because they can instruct the peer to compute checksum. However, igb disables TX checksum offloading when a VF is enabled whether the peer requires virtio headers because a transmitted packet can be routed to it and it expects the packet has a proper checksum. Therefore, it is necessary to have a correct virtio header even when checksum offloading is disabled.

A real TCP/UDP checksum will be computed and saved in the buffer when checksum offloading is disabled. The virtio specification requires to set the packet checksum stored in the buffer to the TCP/UDP pseudo header when the VIRTIO_NET_HDR_F_NEEDS_CSUM bit is set so the bit must be cleared in that case.

The VIRTIO_NET_HDR_F_NEEDS_CSUM bit also tells to skip checksum validation. Even if checksum offloading is disabled, it is desirable to skip checksum validation because the checksum is always correct. Use the VIRTIO_NET_HDR_F_DATA_VALID bit to claim the validity of the checksum.

Fixes ffbd2dbd8e64 ("e1000e: Perform software segmentation for loopback")
---
   hw/net/net_tx_pkt.c | 3 +++
   1 file changed, 3 insertions(+)
hw/net/net_tx_pkt.c +0 -0
index 2e5f58b3c9cc..c225cf706513 100644

hw/net/net_tx_pkt.c bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload, · line 838

Quoted 6 lines
hw/net/net_tx_pkt.c +3 -0
@@ -833,6 +833,9 @@ bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload,
 
       if (offload || gso_type == VIRTIO_NET_HDR_GSO_NONE) {
           if (!offload && pkt->virt_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
+            pkt->virt_hdr.flags =
+                (pkt->virt_hdr.flags & ~VIRTIO_NET_HDR_F_NEEDS_CSUM) |
+                VIRTIO_NET_HDR_F_DATA_VALID;

Why VIRTIO_NET_HDR_F_DATA_VALID is used in TX path?

Quoted 8 lines
Quoted 3 lines

On igb, a packet sent from a PCI function may be routed to another function. The virtio header updated here will be directly provided to the RX path in such a case.

But I meant for example net_tx_pkt_send_custom() is used in e1000e_tx_pkt_send() which is the tx path on the host.

VIRTIO_NET_HDR_F_DATA_VALID is not necessary in the tx path.

igb passes igb_tx_pkt_vmdq_callback to net_tx_pkt_send_custom(). igb_tx_pkt_vmdq_callback() passes the packet to its rx path for loopback.

Regards,
Akihiko Odaki

Quoted 25 lines

Thanks

Quoted 21 lines

Regards,
Akihiko Odaki

Quoted 16 lines

Thanks

Quoted 12 lines
hw/net/net_tx_pkt.c +0 -1
               net_tx_pkt_do_sw_csum(pkt, &pkt->vec[NET_TX_PKT_L2HDR_FRAG],
                                     pkt->payload_frags + NET_TX_PKT_PL_START_FRAG - 1,
                                     pkt->payload_len);
 
---

base-commit: ba49d760eb04630e7b15f423ebecf6c871b8f77b
change-id: 20240324-tx-c57d3c22ad73

Best regards,
--
Akihiko Odaki <[email protected]>

#5 lore raw
Quoted 55 lines · Akihiko Odaki
Quoted 53 lines · Jason Wang
Quoted 51 lines · Akihiko Odaki
Quoted 38 lines · Jason Wang
Quoted 37 lines · Akihiko Odaki

It is incorrect to have the VIRTIO_NET_HDR_F_NEEDS_CSUM set when checksum offloading is disabled so clear the bit. Set the VIRTIO_NET_HDR_F_DATA_VALID bit instead to tell the checksum is valid.

TCP/UDP checksum is usually offloaded when the peer requires virtio headers because they can instruct the peer to compute checksum. However, igb disables TX checksum offloading when a VF is enabled whether the peer requires virtio headers because a transmitted packet can be routed to it and it expects the packet has a proper checksum. Therefore, it is necessary to have a correct virtio header even when checksum offloading is disabled.

A real TCP/UDP checksum will be computed and saved in the buffer when checksum offloading is disabled. The virtio specification requires to set the packet checksum stored in the buffer to the TCP/UDP pseudo header when the VIRTIO_NET_HDR_F_NEEDS_CSUM bit is set so the bit must be cleared in that case.

The VIRTIO_NET_HDR_F_NEEDS_CSUM bit also tells to skip checksum validation. Even if checksum offloading is disabled, it is desirable to skip checksum validation because the checksum is always correct. Use the VIRTIO_NET_HDR_F_DATA_VALID bit to claim the validity of the checksum.

Fixes ffbd2dbd8e64 ("e1000e: Perform software segmentation for loopback")
---
   hw/net/net_tx_pkt.c | 3 +++
   1 file changed, 3 insertions(+)
hw/net/net_tx_pkt.c +0 -0
index 2e5f58b3c9cc..c225cf706513 100644
@@ -833,6 +833,9 @@ bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload,
 
Quoted 7 lines

hw/net/net_tx_pkt.c bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload, · line 838

Quoted 5 lines
hw/net/net_tx_pkt.c +3 -0
       if (offload || gso_type == VIRTIO_NET_HDR_GSO_NONE) {
           if (!offload && pkt->virt_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
+            pkt->virt_hdr.flags =
+                (pkt->virt_hdr.flags & ~VIRTIO_NET_HDR_F_NEEDS_CSUM) |
+                VIRTIO_NET_HDR_F_DATA_VALID;

Why VIRTIO_NET_HDR_F_DATA_VALID is used in TX path?

On igb, a packet sent from a PCI function may be routed to another function. The virtio header updated here will be directly provided to the RX path in such a case.

Quoted 8 lines
Quoted 4 lines

But I meant for example net_tx_pkt_send_custom() is used in e1000e_tx_pkt_send() which is the tx path on the host.

VIRTIO_NET_HDR_F_DATA_VALID is not necessary in the tx path.

igb passes igb_tx_pkt_vmdq_callback to net_tx_pkt_send_custom(). igb_tx_pkt_vmdq_callback() passes the packet to its rx path for loopback.

You are right, how about igb_tx_pkt_vmdq_callback()?

We probably need to tweak the name if it is only used in rx path.

Thanks

Quoted 29 lines

Regards,
Akihiko Odaki

Quoted 25 lines

Thanks

Quoted 21 lines

Regards,
Akihiko Odaki

Quoted 16 lines

Thanks

Quoted 12 lines
hw/net/net_tx_pkt.c +0 -1
               net_tx_pkt_do_sw_csum(pkt, &pkt->vec[NET_TX_PKT_L2HDR_FRAG],
                                     pkt->payload_frags + NET_TX_PKT_PL_START_FRAG - 1,
                                     pkt->payload_len);
 
---

base-commit: ba49d760eb04630e7b15f423ebecf6c871b8f77b
change-id: 20240324-tx-c57d3c22ad73

Best regards,
--
Akihiko Odaki <[email protected]>

#6 lore raw
Quoted 61 lines · Jason Wang
Quoted 60 lines · Akihiko Odaki
Quoted 57 lines · Jason Wang
Quoted 48 lines · Akihiko Odaki
Quoted 38 lines · Jason Wang
Quoted 37 lines · Akihiko Odaki

It is incorrect to have the VIRTIO_NET_HDR_F_NEEDS_CSUM set when checksum offloading is disabled so clear the bit. Set the VIRTIO_NET_HDR_F_DATA_VALID bit instead to tell the checksum is valid.

TCP/UDP checksum is usually offloaded when the peer requires virtio headers because they can instruct the peer to compute checksum. However, igb disables TX checksum offloading when a VF is enabled whether the peer requires virtio headers because a transmitted packet can be routed to it and it expects the packet has a proper checksum. Therefore, it is necessary to have a correct virtio header even when checksum offloading is disabled.

A real TCP/UDP checksum will be computed and saved in the buffer when checksum offloading is disabled. The virtio specification requires to set the packet checksum stored in the buffer to the TCP/UDP pseudo header when the VIRTIO_NET_HDR_F_NEEDS_CSUM bit is set so the bit must be cleared in that case.

The VIRTIO_NET_HDR_F_NEEDS_CSUM bit also tells to skip checksum validation. Even if checksum offloading is disabled, it is desirable to skip checksum validation because the checksum is always correct. Use the VIRTIO_NET_HDR_F_DATA_VALID bit to claim the validity of the checksum.

Fixes ffbd2dbd8e64 ("e1000e: Perform software segmentation for loopback")
---
    hw/net/net_tx_pkt.c | 3 +++
    1 file changed, 3 insertions(+)
hw/net/net_tx_pkt.c +0 -0
index 2e5f58b3c9cc..c225cf706513 100644
@@ -833,6 +833,9 @@ bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload,
 
Quoted 7 lines

hw/net/net_tx_pkt.c bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload, · line 838

Quoted 5 lines
hw/net/net_tx_pkt.c +3 -0
        if (offload || gso_type == VIRTIO_NET_HDR_GSO_NONE) {
            if (!offload && pkt->virt_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
+            pkt->virt_hdr.flags =
+                (pkt->virt_hdr.flags & ~VIRTIO_NET_HDR_F_NEEDS_CSUM) |
+                VIRTIO_NET_HDR_F_DATA_VALID;

Why VIRTIO_NET_HDR_F_DATA_VALID is used in TX path?

Quoted 3 lines

On igb, a packet sent from a PCI function may be routed to another function. The virtio header updated here will be directly provided to the RX path in such a case.

But I meant for example net_tx_pkt_send_custom() is used in e1000e_tx_pkt_send() which is the tx path on the host.

VIRTIO_NET_HDR_F_DATA_VALID is not necessary in the tx path.

Quoted 7 lines
Quoted 3 lines

igb passes igb_tx_pkt_vmdq_callback to net_tx_pkt_send_custom(). igb_tx_pkt_vmdq_callback() passes the packet to its rx path for loopback.

You are right, how about igb_tx_pkt_vmdq_callback()?

We probably need to tweak the name if it is only used in rx path.

igb_tx_pkt_vmdq_callback() itself is part of the tx path of a PCI function, and invokes the rx path of another PCI function in case of loopback, or triggers the transmission to the external peer.

Regards,
Akihiko Odaki

Quoted 33 lines

Thanks

Quoted 29 lines

Regards,
Akihiko Odaki

Quoted 25 lines

Thanks

Quoted 21 lines

Regards,
Akihiko Odaki

Quoted 16 lines

Thanks

Quoted 12 lines
hw/net/net_tx_pkt.c +0 -1
                net_tx_pkt_do_sw_csum(pkt, &pkt->vec[NET_TX_PKT_L2HDR_FRAG],
                                      pkt->payload_frags + NET_TX_PKT_PL_START_FRAG - 1,
                                      pkt->payload_len);
 
---

base-commit: ba49d760eb04630e7b15f423ebecf6c871b8f77b
change-id: 20240324-tx-c57d3c22ad73

Best regards,
--
Akihiko Odaki <[email protected]>

#7 lore raw
Quoted 67 lines · Akihiko Odaki
Quoted 65 lines · Jason Wang
Quoted 63 lines · Akihiko Odaki
Quoted 49 lines · Jason Wang
Quoted 48 lines · Akihiko Odaki
Quoted 45 lines · Jason Wang
Quoted 36 lines · Akihiko Odaki

It is incorrect to have the VIRTIO_NET_HDR_F_NEEDS_CSUM set when checksum offloading is disabled so clear the bit. Set the VIRTIO_NET_HDR_F_DATA_VALID bit instead to tell the checksum is valid.

TCP/UDP checksum is usually offloaded when the peer requires virtio headers because they can instruct the peer to compute checksum. However, igb disables TX checksum offloading when a VF is enabled whether the peer requires virtio headers because a transmitted packet can be routed to it and it expects the packet has a proper checksum. Therefore, it is necessary to have a correct virtio header even when checksum offloading is disabled.

A real TCP/UDP checksum will be computed and saved in the buffer when checksum offloading is disabled. The virtio specification requires to set the packet checksum stored in the buffer to the TCP/UDP pseudo header when the VIRTIO_NET_HDR_F_NEEDS_CSUM bit is set so the bit must be cleared in that case.

The VIRTIO_NET_HDR_F_NEEDS_CSUM bit also tells to skip checksum validation. Even if checksum offloading is disabled, it is desirable to skip checksum validation because the checksum is always correct. Use the VIRTIO_NET_HDR_F_DATA_VALID bit to claim the validity of the checksum.

Fixes ffbd2dbd8e64 ("e1000e: Perform software segmentation for loopback")
---
    hw/net/net_tx_pkt.c | 3 +++
    1 file changed, 3 insertions(+)
hw/net/net_tx_pkt.c +0 -0
index 2e5f58b3c9cc..c225cf706513 100644

hw/net/net_tx_pkt.c bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload, · line 838

Quoted 6 lines
hw/net/net_tx_pkt.c +3 -0
@@ -833,6 +833,9 @@ bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload,
 
        if (offload || gso_type == VIRTIO_NET_HDR_GSO_NONE) {
            if (!offload && pkt->virt_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
+            pkt->virt_hdr.flags =
+                (pkt->virt_hdr.flags & ~VIRTIO_NET_HDR_F_NEEDS_CSUM) |
+                VIRTIO_NET_HDR_F_DATA_VALID;

Why VIRTIO_NET_HDR_F_DATA_VALID is used in TX path?

Quoted 8 lines
Quoted 3 lines

On igb, a packet sent from a PCI function may be routed to another function. The virtio header updated here will be directly provided to the RX path in such a case.

But I meant for example net_tx_pkt_send_custom() is used in e1000e_tx_pkt_send() which is the tx path on the host.

VIRTIO_NET_HDR_F_DATA_VALID is not necessary in the tx path.

igb passes igb_tx_pkt_vmdq_callback to net_tx_pkt_send_custom(). igb_tx_pkt_vmdq_callback() passes the packet to its rx path for loopback.

Quoted 7 lines
Quoted 3 lines

You are right, how about igb_tx_pkt_vmdq_callback()?

We probably need to tweak the name if it is only used in rx path.

igb_tx_pkt_vmdq_callback() itself is part of the tx path of a PCI function, and invokes the rx path of another PCI function in case of loopback, or triggers the transmission to the external peer.

Right, so if it's an external TX, VIRTIO_NET_HDR_F_DATA_VALID may not work there.

Thanks

Quoted 38 lines

Regards,
Akihiko Odaki

Quoted 33 lines

Thanks

Quoted 29 lines

Regards,
Akihiko Odaki

Quoted 25 lines

Thanks

Quoted 21 lines

Regards,
Akihiko Odaki

Quoted 16 lines

Thanks

Quoted 12 lines
hw/net/net_tx_pkt.c +0 -1
                net_tx_pkt_do_sw_csum(pkt, &pkt->vec[NET_TX_PKT_L2HDR_FRAG],
                                      pkt->payload_frags + NET_TX_PKT_PL_START_FRAG - 1,
                                      pkt->payload_len);
 
---

base-commit: ba49d760eb04630e7b15f423ebecf6c871b8f77b
change-id: 20240324-tx-c57d3c22ad73

Best regards,
--
Akihiko Odaki <[email protected]>

#8 lore raw
Quoted 70 lines · Jason Wang
Quoted 69 lines · Akihiko Odaki
Quoted 67 lines · Jason Wang
Quoted 55 lines · Akihiko Odaki
Quoted 53 lines · Jason Wang
Quoted 51 lines · Akihiko Odaki
Quoted 38 lines · Jason Wang
Quoted 37 lines · Akihiko Odaki

It is incorrect to have the VIRTIO_NET_HDR_F_NEEDS_CSUM set when checksum offloading is disabled so clear the bit. Set the VIRTIO_NET_HDR_F_DATA_VALID bit instead to tell the checksum is valid.

TCP/UDP checksum is usually offloaded when the peer requires virtio headers because they can instruct the peer to compute checksum. However, igb disables TX checksum offloading when a VF is enabled whether the peer requires virtio headers because a transmitted packet can be routed to it and it expects the packet has a proper checksum. Therefore, it is necessary to have a correct virtio header even when checksum offloading is disabled.

A real TCP/UDP checksum will be computed and saved in the buffer when checksum offloading is disabled. The virtio specification requires to set the packet checksum stored in the buffer to the TCP/UDP pseudo header when the VIRTIO_NET_HDR_F_NEEDS_CSUM bit is set so the bit must be cleared in that case.

The VIRTIO_NET_HDR_F_NEEDS_CSUM bit also tells to skip checksum validation. Even if checksum offloading is disabled, it is desirable to skip checksum validation because the checksum is always correct. Use the VIRTIO_NET_HDR_F_DATA_VALID bit to claim the validity of the checksum.

Fixes ffbd2dbd8e64 ("e1000e: Perform software segmentation for loopback")
---
     hw/net/net_tx_pkt.c | 3 +++
     1 file changed, 3 insertions(+)
hw/net/net_tx_pkt.c +0 -0
index 2e5f58b3c9cc..c225cf706513 100644
@@ -833,6 +833,9 @@ bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload,
 
Quoted 7 lines

hw/net/net_tx_pkt.c bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload, · line 838

Quoted 5 lines
hw/net/net_tx_pkt.c +3 -0
         if (offload || gso_type == VIRTIO_NET_HDR_GSO_NONE) {
             if (!offload && pkt->virt_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
+            pkt->virt_hdr.flags =
+                (pkt->virt_hdr.flags & ~VIRTIO_NET_HDR_F_NEEDS_CSUM) |
+                VIRTIO_NET_HDR_F_DATA_VALID;

Why VIRTIO_NET_HDR_F_DATA_VALID is used in TX path?

On igb, a packet sent from a PCI function may be routed to another function. The virtio header updated here will be directly provided to the RX path in such a case.

Quoted 8 lines
Quoted 4 lines

But I meant for example net_tx_pkt_send_custom() is used in e1000e_tx_pkt_send() which is the tx path on the host.

VIRTIO_NET_HDR_F_DATA_VALID is not necessary in the tx path.

igb passes igb_tx_pkt_vmdq_callback to net_tx_pkt_send_custom(). igb_tx_pkt_vmdq_callback() passes the packet to its rx path for loopback.

You are right, how about igb_tx_pkt_vmdq_callback()?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

We probably need to tweak the name if it is only used in rx path.

igb_tx_pkt_vmdq_callback() itself is part of the tx path of a PCI function, and invokes the rx path of another PCI function in case of loopback, or triggers the transmission to the external peer.

Right, so if it's an external TX, VIRTIO_NET_HDR_F_DATA_VALID may not work there.

It should be fine since it's just a hint.

Regards,
Akihiko Odaki

Quoted 42 lines

Thanks

Quoted 38 lines

Regards,
Akihiko Odaki

Quoted 33 lines

Thanks

Quoted 29 lines

Regards,
Akihiko Odaki

Quoted 25 lines

Thanks

Quoted 21 lines

Regards,
Akihiko Odaki

Quoted 16 lines

Thanks

Quoted 12 lines
hw/net/net_tx_pkt.c +0 -1
                 net_tx_pkt_do_sw_csum(pkt, &pkt->vec[NET_TX_PKT_L2HDR_FRAG],
                                       pkt->payload_frags + NET_TX_PKT_PL_START_FRAG - 1,
                                       pkt->payload_len);
 
---

base-commit: ba49d760eb04630e7b15f423ebecf6c871b8f77b
change-id: 20240324-tx-c57d3c22ad73

Best regards,
--
Akihiko Odaki <[email protected]>

#9 lore raw
Quoted 74 lines · Akihiko Odaki
Quoted 72 lines · Jason Wang
Quoted 71 lines · Akihiko Odaki
Quoted 68 lines · Jason Wang
Quoted 55 lines · Akihiko Odaki
Quoted 53 lines · Jason Wang
Quoted 51 lines · Akihiko Odaki
Quoted 38 lines · Jason Wang
Quoted 37 lines · Akihiko Odaki

It is incorrect to have the VIRTIO_NET_HDR_F_NEEDS_CSUM set when checksum offloading is disabled so clear the bit. Set the VIRTIO_NET_HDR_F_DATA_VALID bit instead to tell the checksum is valid.

TCP/UDP checksum is usually offloaded when the peer requires virtio headers because they can instruct the peer to compute checksum. However, igb disables TX checksum offloading when a VF is enabled whether the peer requires virtio headers because a transmitted packet can be routed to it and it expects the packet has a proper checksum. Therefore, it is necessary to have a correct virtio header even when checksum offloading is disabled.

A real TCP/UDP checksum will be computed and saved in the buffer when checksum offloading is disabled. The virtio specification requires to set the packet checksum stored in the buffer to the TCP/UDP pseudo header when the VIRTIO_NET_HDR_F_NEEDS_CSUM bit is set so the bit must be cleared in that case.

The VIRTIO_NET_HDR_F_NEEDS_CSUM bit also tells to skip checksum validation. Even if checksum offloading is disabled, it is desirable to skip checksum validation because the checksum is always correct. Use the VIRTIO_NET_HDR_F_DATA_VALID bit to claim the validity of the checksum.

Fixes ffbd2dbd8e64 ("e1000e: Perform software segmentation for loopback")
---
     hw/net/net_tx_pkt.c | 3 +++
     1 file changed, 3 insertions(+)
hw/net/net_tx_pkt.c +0 -0
index 2e5f58b3c9cc..c225cf706513 100644
@@ -833,6 +833,9 @@ bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload,
 
Quoted 7 lines

hw/net/net_tx_pkt.c bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload, · line 838

Quoted 5 lines
hw/net/net_tx_pkt.c +3 -0
         if (offload || gso_type == VIRTIO_NET_HDR_GSO_NONE) {
             if (!offload && pkt->virt_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
+            pkt->virt_hdr.flags =
+                (pkt->virt_hdr.flags & ~VIRTIO_NET_HDR_F_NEEDS_CSUM) |
+                VIRTIO_NET_HDR_F_DATA_VALID;

Why VIRTIO_NET_HDR_F_DATA_VALID is used in TX path?

On igb, a packet sent from a PCI function may be routed to another function. The virtio header updated here will be directly provided to the RX path in such a case.

Quoted 8 lines
Quoted 4 lines

But I meant for example net_tx_pkt_send_custom() is used in e1000e_tx_pkt_send() which is the tx path on the host.

VIRTIO_NET_HDR_F_DATA_VALID is not necessary in the tx path.

igb passes igb_tx_pkt_vmdq_callback to net_tx_pkt_send_custom(). igb_tx_pkt_vmdq_callback() passes the packet to its rx path for loopback.

You are right, how about igb_tx_pkt_vmdq_callback()?

We probably need to tweak the name if it is only used in rx path.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

igb_tx_pkt_vmdq_callback() itself is part of the tx path of a PCI function, and invokes the rx path of another PCI function in case of loopback, or triggers the transmission to the external peer.

Right, so if it's an external TX, VIRTIO_NET_HDR_F_DATA_VALID may not work there.

It should be fine since it's just a hint.

It is not defined in the spec AFAIK. So we should try our best to avoid that.

For example vnet header might be hardened by failing a TX packet with that by kernel

I would bother now than bother it in the future for safety if it's not too hard.

Thanks

Thanks

Quoted 47 lines

Regards,
Akihiko Odaki

Quoted 42 lines

Thanks

Quoted 38 lines

Regards,
Akihiko Odaki

Quoted 33 lines

Thanks

Quoted 29 lines

Regards,
Akihiko Odaki

Quoted 25 lines

Thanks

Quoted 21 lines

Regards,
Akihiko Odaki

Quoted 16 lines

Thanks

Quoted 12 lines
hw/net/net_tx_pkt.c +0 -1
                 net_tx_pkt_do_sw_csum(pkt, &pkt->vec[NET_TX_PKT_L2HDR_FRAG],
                                       pkt->payload_frags + NET_TX_PKT_PL_START_FRAG - 1,
                                       pkt->payload_len);
 
---

base-commit: ba49d760eb04630e7b15f423ebecf6c871b8f77b
change-id: 20240324-tx-c57d3c22ad73

Best regards,
--
Akihiko Odaki <[email protected]>

#10 lore raw
Quoted 82 lines · Jason Wang
Quoted 81 lines · Akihiko Odaki
Quoted 78 lines · Jason Wang
Quoted 67 lines · Akihiko Odaki
Quoted 65 lines · Jason Wang
Quoted 63 lines · Akihiko Odaki
Quoted 49 lines · Jason Wang
Quoted 48 lines · Akihiko Odaki
Quoted 45 lines · Jason Wang
Quoted 36 lines · Akihiko Odaki

It is incorrect to have the VIRTIO_NET_HDR_F_NEEDS_CSUM set when checksum offloading is disabled so clear the bit. Set the VIRTIO_NET_HDR_F_DATA_VALID bit instead to tell the checksum is valid.

TCP/UDP checksum is usually offloaded when the peer requires virtio headers because they can instruct the peer to compute checksum. However, igb disables TX checksum offloading when a VF is enabled whether the peer requires virtio headers because a transmitted packet can be routed to it and it expects the packet has a proper checksum. Therefore, it is necessary to have a correct virtio header even when checksum offloading is disabled.

A real TCP/UDP checksum will be computed and saved in the buffer when checksum offloading is disabled. The virtio specification requires to set the packet checksum stored in the buffer to the TCP/UDP pseudo header when the VIRTIO_NET_HDR_F_NEEDS_CSUM bit is set so the bit must be cleared in that case.

The VIRTIO_NET_HDR_F_NEEDS_CSUM bit also tells to skip checksum validation. Even if checksum offloading is disabled, it is desirable to skip checksum validation because the checksum is always correct. Use the VIRTIO_NET_HDR_F_DATA_VALID bit to claim the validity of the checksum.

Fixes ffbd2dbd8e64 ("e1000e: Perform software segmentation for loopback")
---
      hw/net/net_tx_pkt.c | 3 +++
      1 file changed, 3 insertions(+)
hw/net/net_tx_pkt.c +0 -0
index 2e5f58b3c9cc..c225cf706513 100644

hw/net/net_tx_pkt.c bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload, · line 838

Quoted 6 lines
hw/net/net_tx_pkt.c +3 -0
@@ -833,6 +833,9 @@ bool net_tx_pkt_send_custom(struct NetTxPkt *pkt, bool offload,
 
          if (offload || gso_type == VIRTIO_NET_HDR_GSO_NONE) {
              if (!offload && pkt->virt_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
+            pkt->virt_hdr.flags =
+                (pkt->virt_hdr.flags & ~VIRTIO_NET_HDR_F_NEEDS_CSUM) |
+                VIRTIO_NET_HDR_F_DATA_VALID;

Why VIRTIO_NET_HDR_F_DATA_VALID is used in TX path?

Quoted 8 lines
Quoted 3 lines

On igb, a packet sent from a PCI function may be routed to another function. The virtio header updated here will be directly provided to the RX path in such a case.

But I meant for example net_tx_pkt_send_custom() is used in e1000e_tx_pkt_send() which is the tx path on the host.

VIRTIO_NET_HDR_F_DATA_VALID is not necessary in the tx path.

igb passes igb_tx_pkt_vmdq_callback to net_tx_pkt_send_custom(). igb_tx_pkt_vmdq_callback() passes the packet to its rx path for loopback.

Quoted 7 lines
Quoted 3 lines

You are right, how about igb_tx_pkt_vmdq_callback()?

We probably need to tweak the name if it is only used in rx path.

igb_tx_pkt_vmdq_callback() itself is part of the tx path of a PCI function, and invokes the rx path of another PCI function in case of loopback, or triggers the transmission to the external peer.

Right, so if it's an external TX, VIRTIO_NET_HDR_F_DATA_VALID may not work there.

Quoted 8 lines
Quoted 1 line

It should be fine since it's just a hint.

It is not defined in the spec AFAIK. So we should try our best to avoid that.

For example vnet header might be hardened by failing a TX packet with that by kernel

I would bother now than bother it in the future for safety if it's not too hard.

I checked the specification and found:
https://docs.oasis-open.org/virtio/virtio/v1.2/csd01/virtio-v1.2-csd01.html#x1-2310001

Quoted 4 lines

5.1.6.2.1 Driver Requirements: Packet Transmission

The driver MUST NOT set the VIRTIO_NET_HDR_F_DATA_VALID and VIRTIO_NET_HDR_F_RSC_INFO bits in flags.

So it's explicitly prohibited. I'll send v2, which removes VIRTIO_NET_HDR_F_DATA_VALID.

Regards,
Akihiko Odaki

Quoted 55 lines

Thanks

Thanks

Quoted 47 lines

Regards,
Akihiko Odaki

Quoted 42 lines

Thanks

Quoted 38 lines

Regards,
Akihiko Odaki

Quoted 33 lines

Thanks

Quoted 29 lines

Regards,
Akihiko Odaki

Quoted 25 lines

Thanks

Quoted 21 lines

Regards,
Akihiko Odaki

Quoted 16 lines

Thanks

Quoted 12 lines
hw/net/net_tx_pkt.c +0 -1
                  net_tx_pkt_do_sw_csum(pkt, &pkt->vec[NET_TX_PKT_L2HDR_FRAG],
                                        pkt->payload_frags + NET_TX_PKT_PL_START_FRAG - 1,
                                        pkt->payload_len);
 
---

base-commit: ba49d760eb04630e7b15f423ebecf6c871b8f77b
change-id: 20240324-tx-c57d3c22ad73

Best regards,
--
Akihiko Odaki <[email protected]>