Skip to contentSkip to conversation

net/vhost: get csum offload capabilities of vhost backend

PATCH In review Wenwu Ma 3 participants 3 messages Feb 17, 2022 – May 5, 2022 Network drivers

lore
Share & tools
lore

Wenwu Ma

author
#0 lore raw

PATCH 1/1 net/vhost: get csum offload capabilities of vhost backend

The current vhost backend lacks csum offloads information, which will cause testpmd command such as "csum set tcp hw <port_id>" to fail. This patch adds the information according to the device features.

---
 drivers/net/vhost/rte_eth_vhost.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/net/vhost/rte_eth_vhost.c +18 -0
index 070f0e6dfd..7593d5a9ae 100644
@@ -1281,6 +1281,24 @@ eth_dev_info(struct rte_eth_dev *dev,
 				RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
 	dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
 
+	if (internal->vid != -1) {
+		uint64_t features = 0;
+		if (rte_vhost_get_negotiated_features(internal->vid, &features) != 0)
+			return 0;
+
+		if (features & (1ULL << VIRTIO_NET_F_CSUM)) {
+			dev_info->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
+						RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
+						RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
+		}
+
+		if (features & (1ULL << VIRTIO_NET_F_GUEST_CSUM)) {
+			dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
+						RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
+						RTE_ETH_RX_OFFLOAD_IPV4_CKSUM;
+		}
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.25.1
#1 lore raw

Hi Wenwu,

Quoted 9 lines

-----Original Message-----
From: Ma, WenwuX <[email protected]>
Sent: Thursday, February 17, 2022 11:16 PM
To: [email protected]; Xia, Chenbo <[email protected]>
Cc: [email protected]; Hu, Jiayu <[email protected]>; Wang, Yinan <[email protected]>; He, Xingguang <[email protected]>; Ma, WenwuX <[email protected]>
Subject: [PATCH] net/vhost: get csum offload capabilities of vhost backend

Quoted 3 lines

The current vhost backend lacks csum offloads information, which will cause testpmd command such as "csum set tcp hw <port_id>" to fail. This patch adds the information according to the device features.

Vhost-pmd cannot report correct checksum offloading capabilities, since feature negotiation may happen after vhost-pmd device creation. It's good to see there is a solution for it, IMO.

Quoted 23 lines
---
 drivers/net/vhost/rte_eth_vhost.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/net/vhost/rte_eth_vhost.c +7 -0
index 070f0e6dfd..7593d5a9ae 100644
@@ -1281,6 +1281,24 @@ eth_dev_info(struct rte_eth_dev *dev,
 				RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
 	dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
 
+	if (internal->vid != -1) {
+		uint64_t features = 0;
+		if (rte_vhost_get_negotiated_features(internal->vid,
 &features) != 0)
+			return 0;
+
+		if (features & (1ULL << VIRTIO_NET_F_CSUM)) {
+			dev_info->tx_offload_capa |=
Quoted 1 line

RTE_ETH_TX_OFFLOAD_TCP_CKSUM |

The spec says "VIRTIO_NET_F_CSUM: host handles pkts w/ partial csum". If this feature is negotiated, it means vhost pmd supports to receive packets with partial checksum, right? So VIRTIO_NET_F_CSUM should represent Rx offloading capabilities for vhost pmd.

drivers/net/vhost/rte_eth_vhost.c eth_dev_info(struct rte_eth_dev *dev,

Quoted 8 lines

+
RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
+

	RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
drivers/net/vhost/rte_eth_vhost.c +4 -0
+		}
+
+		if (features & (1ULL << VIRTIO_NET_F_GUEST_CSUM)) {
+			dev_info->rx_offload_capa |=

Same as above.

Thanks,
Jiayu

#2 lore raw
In reply to Wenwu Ma

Hi Wenwu,

Quoted 30 lines · Wenwu Ma

The current vhost backend lacks csum offloads information, which will cause testpmd command such as "csum set tcp hw <port_id>" to fail. This patch adds the information according to the device features.

---
  drivers/net/vhost/rte_eth_vhost.c | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)
drivers/net/vhost/rte_eth_vhost.c +11 -0
index 070f0e6dfd..7593d5a9ae 100644
@@ -1281,6 +1281,24 @@ eth_dev_info(struct rte_eth_dev *dev,
  				RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
  	dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
 
+	if (internal->vid != -1) {
+		uint64_t features = 0;
+		if (rte_vhost_get_negotiated_features(internal->vid, &features) != 0)
+			return 0;
+
+		if (features & (1ULL << VIRTIO_NET_F_CSUM)) {
+			dev_info->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
+						RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
+						RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
+		}
+

drivers/net/vhost/rte_eth_vhost.c eth_dev_info(struct rte_eth_dev *dev, · line 1304

Quoted 10 lines
drivers/net/vhost/rte_eth_vhost.c +7 -0
+		if (features & (1ULL << VIRTIO_NET_F_GUEST_CSUM)) {
+			dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
+						RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
+						RTE_ETH_RX_OFFLOAD_IPV4_CKSUM;
+		}
+	}
+
  	return 0;
  }
 

This patch has lots of gaps, since the negotiated Virtio features can change if the guest driver decides so, so the exposed ethdev offload capabilities may not represent what is really supported by the guest driver.

I have done a series that handles this issue by implementing SW fallbacks in case of misalignment between host application and guest application:

http://patches.dpdk.org/project/dpdk/cover/[email protected]/

Please help reviewing & testing the series if possible.

Thanks,
Maxime