Skip to contentSkip to conversation

hv_netvsc: Add XDP support

PATCH Superseded Haiyang Zhang 3 participants 9 messages Jan 22, 2020 – Jan 23, 2020

Subsystems (5)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Haiyang Zhang

author maintainer
#0 lore raw

v3 cover hv_netvsc: Add XDP support

Add XDP support and update related document.

Haiyang Zhang (2):
hv_netvsc: Add XDP support
hv_netvsc: Update document for XDP support

 .../networking/device_drivers/microsoft/netvsc.txt |  21 +++
 drivers/net/hyperv/Makefile                        |   2 +-
 drivers/net/hyperv/hyperv_net.h                    |  21 ++-
 drivers/net/hyperv/netvsc.c                        |  31 ++-
 drivers/net/hyperv/netvsc_bpf.c                    | 209 +++++++++++++++++++++
 drivers/net/hyperv/netvsc_drv.c                    | 175 ++++++++++++++---
 drivers/net/hyperv/rndis_filter.c                  |   2 +-
 7 files changed, 422 insertions(+), 39 deletions(-)
 create mode 100644 drivers/net/hyperv/netvsc_bpf.c
Signature · 1 line
1.8.3.1
author maintainer
#8 lore raw

PATCH v3 2/2 hv_netvsc: Update document for XDP support

Added the new section in the document regarding XDP support by hv_netvsc driver.

---
 .../networking/device_drivers/microsoft/netvsc.txt  | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
Documentation/networking/device_drivers/microsoft/netvsc.txt +21 -0
index 3bfa635..cd63556 100644
@@ -82,3 +82,24 @@ Features
   contain one or more packets. The send buffer is an optimization, the driver
   will use slower method to handle very large packets or if the send buffer
   area is exhausted.
+
+  XDP support
+  -----------
+  XDP (eXpress Data Path) is a feature that runs eBPF bytecode at the early
+  stage when packets arrive at a NIC card. The goal is to increase performance
+  for packet processing, reducing the overhead of SKB allocation and other
+  upper network layers.
+
+  hv_netvsc supports XDP in native mode, and transparently sets the XDP
+  program on the associated VF NIC as well.
+
+  Setting / unsetting XDP program on synthetic NIC (netvsc) propagates to
+  VF NIC automatically. Setting / unsetting XDP program on VF NIC directly
+  is not recommended, also not propagated to synthetic NIC, and may be
+  overwritten by setting of synthetic NIC.
+
+  XDP program cannot run with LRO (RSC) enabled, so you need to disable LRO
+  before running XDP:
+	ethtool -K eth0 lro off
+
+  XDP_REDIRECT action is not yet supported.
Signature · 1 line
1.8.3.1
author maintainer
#1 lore raw

PATCH v3 1/2 hv_netvsc: Add XDP support

In reply to Haiyang Zhang

This patch adds support of XDP in native mode for hv_netvsc driver, and transparently sets the XDP program on the associated VF NIC as well.

Setting / unsetting XDP program on synthetic NIC (netvsc) propagates to VF NIC automatically. Setting / unsetting XDP program on VF NIC directly is not recommended, also not propagated to synthetic NIC, and may be overwritten by setting of synthetic NIC.

The Azure/Hyper-V synthetic NIC receive buffer doesn't provide headroom for XDP. We thought about re-use the RNDIS header space, but it's too small. So we decided to copy the packets to a page buffer for XDP. And, most of our VMs on Azure have Accelerated Network (SRIOV) enabled, so most of the packets run on VF NIC. The synthetic NIC is considered as a fallback data-path. So the data copy on netvsc won't impact performance significantly.

XDP program cannot run with LRO (RSC) enabled, so you need to disable LRO before running XDP:
ethtool -K eth0 lro off

XDP actions not yet supported:
XDP_REDIRECT

---
Changes:
v3: Minor code and comment updates.
v2: Added XDP_TX support. Addressed review comments.

---
 drivers/net/hyperv/Makefile       |   2 +-
 drivers/net/hyperv/hyperv_net.h   |  21 +++-
 drivers/net/hyperv/netvsc.c       |  31 +++++-
 drivers/net/hyperv/netvsc_bpf.c   | 209 ++++++++++++++++++++++++++++++++++++++
 drivers/net/hyperv/netvsc_drv.c   | 175 +++++++++++++++++++++++++------
 drivers/net/hyperv/rndis_filter.c |   2 +-
 6 files changed, 401 insertions(+), 39 deletions(-)
 create mode 100644 drivers/net/hyperv/netvsc_bpf.c
drivers/net/hyperv/Makefile +1 -1
index 3a2aa07..0db7cca 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_HYPERV_NET) += hv_netvsc.o
 
-hv_netvsc-y := netvsc_drv.o netvsc.o rndis_filter.o netvsc_trace.o
+hv_netvsc-y := netvsc_drv.o netvsc.o rndis_filter.o netvsc_trace.o netvsc_bpf.o
drivers/net/hyperv/hyperv_net.h +20 -1
index dc44819..abda736 100644
@@ -142,6 +142,8 @@ struct netvsc_device_info {
 	u32  send_section_size;
 	u32  recv_section_size;
 
+	struct bpf_prog *bprog;
+
 	u8 rss_key[NETVSC_HASH_KEYLEN];
 };
 
@@ -189,7 +191,8 @@ int netvsc_send(struct net_device *net,
 		struct hv_netvsc_packet *packet,
 		struct rndis_message *rndis_msg,
 		struct hv_page_buffer *page_buffer,
-		struct sk_buff *skb);
+		struct sk_buff *skb,
+		bool xdp_tx);
 void netvsc_linkstatus_callback(struct net_device *net,
 				struct rndis_message *resp);
 int netvsc_recv_callback(struct net_device *net,
@@ -198,6 +201,16 @@ int netvsc_recv_callback(struct net_device *net,
 void netvsc_channel_cb(void *context);
 int netvsc_poll(struct napi_struct *napi, int budget);
 
+u32 netvsc_run_xdp(struct net_device *ndev, struct netvsc_channel *nvchan,
+		   struct xdp_buff *xdp);
+unsigned int netvsc_xdp_fraglen(unsigned int len);
+struct bpf_prog *netvsc_xdp_get(struct netvsc_device *nvdev);
+int netvsc_xdp_set(struct net_device *dev, struct bpf_prog *prog,
+		   struct netlink_ext_ack *extack,
+		   struct netvsc_device *nvdev);
+int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog *prog);
+int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf);
+
 int rndis_set_subchannel(struct net_device *ndev,
 			 struct netvsc_device *nvdev,
 			 struct netvsc_device_info *dev_info);
@@ -832,6 +845,8 @@ struct nvsp_message {
 #define RNDIS_MAX_PKT_DEFAULT 8
 #define RNDIS_PKT_ALIGN_DEFAULT 8
 
+#define NETVSC_XDP_HDRM 256
+
 struct multi_send_data {
 	struct sk_buff *skb; /* skb containing the pkt */
 	struct hv_netvsc_packet *pkt; /* netvsc pkt pending */
@@ -867,6 +882,7 @@ struct netvsc_stats {
 	u64 bytes;
 	u64 broadcast;
 	u64 multicast;
+	u64 xdp_drop;
 	struct u64_stats_sync syncp;
 };
 
@@ -972,6 +988,9 @@ struct netvsc_channel {
 	atomic_t queue_sends;
 	struct nvsc_rsc rsc;
 
+	struct bpf_prog __rcu *bpf_prog;
+	struct xdp_rxq_info xdp_rxq;
+
 	struct netvsc_stats tx_stats;
 	struct netvsc_stats rx_stats;
 };
drivers/net/hyperv/netvsc.c +26 -5
index eab83e7..ae3f308 100644
@@ -122,8 +122,10 @@ static void free_netvsc_device(struct rcu_head *head)
 	vfree(nvdev->send_buf);
 	kfree(nvdev->send_section_map);
 
-	for (i = 0; i < VRSS_CHANNEL_MAX; i++)
+	for (i = 0; i < VRSS_CHANNEL_MAX; i++) {
+		xdp_rxq_info_unreg(&nvdev->chan_table[i].xdp_rxq);
 		vfree(nvdev->chan_table[i].mrc.slots);
+	}
 
 	kfree(nvdev);
 }
@@ -900,7 +902,8 @@ int netvsc_send(struct net_device *ndev,
 		struct hv_netvsc_packet *packet,
 		struct rndis_message *rndis_msg,
 		struct hv_page_buffer *pb,
-		struct sk_buff *skb)
+		struct sk_buff *skb,
+		bool xdp_tx)
 {
 	struct net_device_context *ndev_ctx = netdev_priv(ndev);
 	struct netvsc_device *net_device
@@ -923,10 +926,11 @@ int netvsc_send(struct net_device *ndev,
 	packet->send_buf_index = NETVSC_INVALID_INDEX;
 	packet->cp_partial = false;
 
-	/* Send control message directly without accessing msd (Multi-Send
-	 * Data) field which may be changed during data packet processing.
+	/* Send a control message or XDP packet directly without accessing
+	 * msd (Multi-Send Data) field which may be changed during data packet
+	 * processing.
 	 */
-	if (!skb)
+	if (!skb || xdp_tx)
 		return netvsc_send_pkt(device, packet, net_device, pb, skb);
 
 	/* batch packets in send buffer if possible */
@@ -1392,6 +1396,21 @@ struct netvsc_device *netvsc_device_add(struct hv_device *device,
 		nvchan->net_device = net_device;
 		u64_stats_init(&nvchan->tx_stats.syncp);
 		u64_stats_init(&nvchan->rx_stats.syncp);
+
+		ret = xdp_rxq_info_reg(&nvchan->xdp_rxq, ndev, i);
+
+		if (ret) {
+			netdev_err(ndev, "xdp_rxq_info_reg fail: %d\n", ret);
+			goto cleanup2;
+		}
+
+		ret = xdp_rxq_info_reg_mem_model(&nvchan->xdp_rxq,
+						 MEM_TYPE_PAGE_SHARED, NULL);
+
+		if (ret) {
+			netdev_err(ndev, "xdp reg_mem_model fail: %d\n", ret);
+			goto cleanup2;
+		}
 	}
 
 	/* Enable NAPI handler before init callbacks */
@@ -1437,6 +1456,8 @@ struct netvsc_device *netvsc_device_add(struct hv_device *device,
 
 cleanup:
 	netif_napi_del(&net_device->chan_table[0].napi);
+
+cleanup2:
 	free_netvsc_device(&net_device->rcu);
 
 	return ERR_PTR(ret);
drivers/net/hyperv/netvsc_bpf.c new file +209 -0

209 lines not on this page · raw message

drivers/net/hyperv/netvsc_drv.c +144 -31

406 lines not on this page · raw message

drivers/net/hyperv/rndis_filter.c +1 -1
index e66d77d..b81ceba 100644
@@ -235,7 +235,7 @@ static int rndis_filter_send_request(struct rndis_device *dev,
 	trace_rndis_send(dev->ndev, 0, &req->request_msg);
 
 	rcu_read_lock_bh();
-	ret = netvsc_send(dev->ndev, packet, NULL, pb, NULL);
+	ret = netvsc_send(dev->ndev, packet, NULL, pb, NULL, false);
 	rcu_read_unlock_bh();
 
 	return ret;
Signature · 1 line
1.8.3.1
#2 lore raw
Quoted 9 lines · On Wed, 22 Jan 2020 09:23:33 -0800 Haiyang Zhang <[email protected]> wrote:
drivers/net/hyperv/netvsc_bpf.c new file +9 -0
+u32 netvsc_run_xdp(struct net_device *ndev, struct netvsc_channel *nvchan,
+		   struct xdp_buff *xdp)
+{
+	void *data = nvchan->rsc.data[0];
+	u32 len = nvchan->rsc.len[0];
+	struct page *page = NULL;
+	struct bpf_prog *prog;
+	u32 act = XDP_PASS;
+

drivers/net/hyperv/netvsc_bpf.c line 41

Quoted 10 lines
drivers/net/hyperv/netvsc_bpf.c new file +10 -0
+	xdp->data_hard_start = NULL;
+
+	rcu_read_lock();
+	prog = rcu_dereference(nvchan->bpf_prog);
+
+	if (!prog)
+		goto out;
+
+	/* allocate page buffer for data */
+	page = alloc_page(GFP_ATOMIC);

The alloc_page() + __free_page() alone[1] cost 231 cycles(tsc) 64.395 ns. Thus, the XDP_DROP case will already be limited to just around 10Gbit/s 14.88 Mpps (67.2ns).

XDP is suppose to be done for performance reasons. This looks like a slowdown.

Measurement tool:
[1] https://github.com/netoptimizer/prototype-kernel/blob/master/kernel/mm/bench/page_bench01.c

drivers/net/hyperv/netvsc_bpf.c line 54

Quoted 13 lines
drivers/net/hyperv/netvsc_bpf.c new file +13 -0
+	if (!page) {
+		act = XDP_DROP;
+		goto out;
+	}
+
+	xdp->data_hard_start = page_address(page);
+	xdp->data = xdp->data_hard_start + NETVSC_XDP_HDRM;
+	xdp_set_data_meta_invalid(xdp);
+	xdp->data_end = xdp->data + len;
+	xdp->rxq = &nvchan->xdp_rxq;
+	xdp->handle = 0;
+
+	memcpy(xdp->data, data, len);

And a memcpy.

Quoted 12 lines
drivers/net/hyperv/netvsc_bpf.c new file +12 -0
+
+	act = bpf_prog_run_xdp(prog, xdp);
+
+	switch (act) {
+	case XDP_PASS:
+	case XDP_TX:
+	case XDP_DROP:
+		break;
+
+	case XDP_ABORTED:
+		trace_xdp_exception(ndev, prog, act);
+		break;

drivers/net/hyperv/netvsc_bpf.c line 76

Quoted 10 lines
drivers/net/hyperv/netvsc_bpf.c new file +10 -0
+
+	default:
+		bpf_warn_invalid_xdp_action(act);
+	}
+
+out:
+	rcu_read_unlock();
+
+	if (page && act != XDP_PASS && act != XDP_TX) {
+		__free_page(page);

Given this runs under NAPI you could optimize this easily for XDP_DROP (and XDP_ABORTED) by recycling the page in a driver local cache. (The page_pool also have a driver local cache build in, but it might be overkill to use page_pool in this simple case).

You could do this in a followup patch.

Quoted 5 lines
drivers/net/hyperv/netvsc_bpf.c new file +5 -0
+		xdp->data_hard_start = NULL;
+	}
+
+	return act;
+}
Signature · 4 lines
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer
author maintainer
#3 lore raw
Quoted 42 lines

-----Original Message-----
From: Jesper Dangaard Brouer <[email protected]>
Sent: Wednesday, January 22, 2020 2:52 PM
To: Haiyang Zhang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; KY Srinivasan <[email protected]>; Stephen Hemminger <[email protected]>; [email protected]; vkuznets <[email protected]>; [email protected]; [email protected]; Ilias Apalodimas <[email protected]>
Subject: Re: [PATCH V3,net-next, 1/2] hv_netvsc: Add XDP support

Quoted 9 lines · On Wed, 22 Jan 2020 09:23:33 -0800 Haiyang Zhang <[email protected]> wrote:
drivers/net/hyperv/netvsc_bpf.c new file +9 -0
+u32 netvsc_run_xdp(struct net_device *ndev, struct netvsc_channel *nvchan,
+		   struct xdp_buff *xdp)
+{
+	void *data = nvchan->rsc.data[0];
+	u32 len = nvchan->rsc.len[0];
+	struct page *page = NULL;
+	struct bpf_prog *prog;
+	u32 act = XDP_PASS;
+

drivers/net/hyperv/netvsc_bpf.c line 41

Quoted 10 lines
drivers/net/hyperv/netvsc_bpf.c new file +10 -0
+	xdp->data_hard_start = NULL;
+
+	rcu_read_lock();
+	prog = rcu_dereference(nvchan->bpf_prog);
+
+	if (!prog)
+		goto out;
+
+	/* allocate page buffer for data */
+	page = alloc_page(GFP_ATOMIC);

The alloc_page() + __free_page() alone[1] cost 231 cycles(tsc) 64.395 ns. Thus, the XDP_DROP case will already be limited to just around 10Gbit/s 14.88 Mpps (67.2ns).

XDP is suppose to be done for performance reasons. This looks like a slowdown.

Quoted 9 lines

Measurement tool:
[1]
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.co
m%2Fnetoptimizer%2Fprototype- kernel%2Fblob%2Fmaster%2Fkernel%2Fmm%2Fbench%2Fpage_bench01.c&am p;data=02%7C01%7Chaiyangz%40microsoft.com%7C681b5b13e50448d098d408 d79f748522%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C63715319 5109318994&amp;sdata=pncqYIWm1yS5rDf%2BAIbWgskycmuofzl09yA1QmsRb M0%3D&amp;reserved=0

On synthetic data path (netvsc), the per channel throughput is much slower than 10Gbps, because of the host side software based vSwitch. Also in most VMs on Azure, Accelerated Network (SRIOV) is enabled. So the alloc_page() overhead on synthetic data path won't impact performance significantly.

Quoted 16 lines
Quoted 4 lines
drivers/net/hyperv/netvsc_bpf.c new file +3 -0
+	if (!page) {
+		act = XDP_DROP;
+		goto out;

drivers/net/hyperv/netvsc_bpf.c line 54

Quoted 10 lines
drivers/net/hyperv/netvsc_bpf.c new file +10 -0
+	}
+
+	xdp->data_hard_start = page_address(page);
+	xdp->data = xdp->data_hard_start + NETVSC_XDP_HDRM;
+	xdp_set_data_meta_invalid(xdp);
+	xdp->data_end = xdp->data + len;
+	xdp->rxq = &nvchan->xdp_rxq;
+	xdp->handle = 0;
+
+	memcpy(xdp->data, data, len);

And a memcpy.

As in the commit log:
The Azure/Hyper-V synthetic NIC receive buffer doesn't provide headroom for XDP. We thought about re-use the RNDIS header space, but it's too small. So we decided to copy the packets to a page buffer for XDP. And, most of our VMs on Azure have Accelerated Network (SRIOV) enabled, so most of the packets run on VF NIC. The synthetic NIC is considered as a fallback data-path. So the data copy on netvsc won't impact performance significantly.

Quoted 29 lines
Quoted 13 lines
drivers/net/hyperv/netvsc_bpf.c new file +12 -0
+
+	act = bpf_prog_run_xdp(prog, xdp);
+
+	switch (act) {
+	case XDP_PASS:
+	case XDP_TX:
+	case XDP_DROP:
+		break;
+
+	case XDP_ABORTED:
+		trace_xdp_exception(ndev, prog, act);
+		break;

drivers/net/hyperv/netvsc_bpf.c line 76

Quoted 10 lines
drivers/net/hyperv/netvsc_bpf.c new file +10 -0
+
+	default:
+		bpf_warn_invalid_xdp_action(act);
+	}
+
+out:
+	rcu_read_unlock();
+
+	if (page && act != XDP_PASS && act != XDP_TX) {
+		__free_page(page);

Given this runs under NAPI you could optimize this easily for XDP_DROP (and XDP_ABORTED) by recycling the page in a driver local cache. (The page_pool also have a driver local cache build in, but it might be overkill to use page_pool in this simple case).

Quoted 1 line

You could do this in a followup patch.

I will do the optimization in a follow-up patch.

Thanks,
- Haiyang

maintainer
#4 lore raw
In reply to Haiyang Zhang
Quoted 23 lines · Haiyang Zhang

This patch adds support of XDP in native mode for hv_netvsc driver, and transparently sets the XDP program on the associated VF NIC as well.

Setting / unsetting XDP program on synthetic NIC (netvsc) propagates to VF NIC automatically. Setting / unsetting XDP program on VF NIC directly is not recommended, also not propagated to synthetic NIC, and may be overwritten by setting of synthetic NIC.

The Azure/Hyper-V synthetic NIC receive buffer doesn't provide headroom for XDP. We thought about re-use the RNDIS header space, but it's too small. So we decided to copy the packets to a page buffer for XDP. And, most of our VMs on Azure have Accelerated Network (SRIOV) enabled, so most of the packets run on VF NIC. The synthetic NIC is considered as a fallback data-path. So the data copy on netvsc won't impact performance significantly.

XDP program cannot run with LRO (RSC) enabled, so you need to disable LRO before running XDP:
ethtool -K eth0 lro off

XDP actions not yet supported:
XDP_REDIRECT

Quoted 6 lines

---
Changes:
v3: Minor code and comment updates.
v2: Added XDP_TX support. Addressed review comments.

How does the locking of the TX path work? You seem to be just calling the normal xmit method, but you don't hold the xmit queue lock, so the stack can start xmit concurrently, no?

author maintainer
#5 lore raw
Quoted 38 lines

-----Original Message-----
From: Jakub Kicinski <[email protected]>
Sent: Thursday, January 23, 2020 11:59 AM
To: Haiyang Zhang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; KY Srinivasan <[email protected]>; Stephen Hemminger <[email protected]>; [email protected]; vkuznets <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V3,net-next, 1/2] hv_netvsc: Add XDP support

Quoted 25 lines · Haiyang Zhang

This patch adds support of XDP in native mode for hv_netvsc driver, and transparently sets the XDP program on the associated VF NIC as well.

Setting / unsetting XDP program on synthetic NIC (netvsc) propagates to VF NIC automatically. Setting / unsetting XDP program on VF NIC directly is not recommended, also not propagated to synthetic NIC, and may be overwritten by setting of synthetic NIC.

The Azure/Hyper-V synthetic NIC receive buffer doesn't provide headroom for XDP. We thought about re-use the RNDIS header space, but it's too small. So we decided to copy the packets to a page buffer for XDP. And, most of our VMs on Azure have Accelerated Network (SRIOV) enabled, so most of the packets run on VF NIC. The synthetic NIC is considered as a fallback data-path. So the data copy on netvsc won't impact performance significantly.

XDP program cannot run with LRO (RSC) enabled, so you need to disable LRO before running XDP:
ethtool -K eth0 lro off

XDP actions not yet supported:
XDP_REDIRECT

Quoted 8 lines
Quoted 4 lines

---
Changes:
v3: Minor code and comment updates.
v2: Added XDP_TX support. Addressed review comments.

How does the locking of the TX path work? You seem to be just calling the normal xmit method, but you don't hold the xmit queue lock, so the stack can start xmit concurrently, no?

The netvsc and vmbus can handle concurrent transmits, except the msd (Multi-Send Data) field which can only be used by one queue.

I already added a new flag to netvsc_send(), so packets from XDP_TX won't use the msd.

Thanks,
- Haiyang

maintainer
#6 lore raw
Quoted 8 lines · Haiyang Zhang
Quoted 7 lines
Quoted 3 lines

Changes:
v3: Minor code and comment updates.
v2: Added XDP_TX support. Addressed review comments.

How does the locking of the TX path work? You seem to be just calling the normal xmit method, but you don't hold the xmit queue lock, so the stack can start xmit concurrently, no?

Quoted 5 lines

The netvsc and vmbus can handle concurrent transmits, except the msd (Multi-Send Data) field which can only be used by one queue.

I already added a new flag to netvsc_send(), so packets from XDP_TX won't use the msd.

I see, there's a few non-atomic counters there, but maybe that's not a big deal.

What frees the skb if the ring is full, and netvsc_send_pkt() returns -EAGAIN? Nothing checks the return value from netvsc_xdp_xmit().

author maintainer
#7 lore raw
Quoted 21 lines

-----Original Message-----
From: Jakub Kicinski <[email protected]>
Sent: Thursday, January 23, 2020 12:30 PM
To: Haiyang Zhang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; KY Srinivasan <[email protected]>; Stephen Hemminger <[email protected]>; [email protected]; vkuznets <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V3,net-next, 1/2] hv_netvsc: Add XDP support

Quoted 8 lines · Haiyang Zhang
Quoted 7 lines
Quoted 3 lines

Changes:
v3: Minor code and comment updates.
v2: Added XDP_TX support. Addressed review comments.

How does the locking of the TX path work? You seem to be just calling the normal xmit method, but you don't hold the xmit queue lock, so the stack can start xmit concurrently, no?

Quoted 7 lines
Quoted 5 lines

The netvsc and vmbus can handle concurrent transmits, except the msd (Multi-Send Data) field which can only be used by one queue.

I already added a new flag to netvsc_send(), so packets from XDP_TX won't use the msd.

I see, there's a few non-atomic counters there, but maybe that's not a big deal.

Yes, those error counters are used less frequently, and not necessary to be precise.

Quoted 2 lines

What frees the skb if the ring is full, and netvsc_send_pkt() returns -EAGAIN? Nothing checks the return value from netvsc_xdp_xmit().

Good catch! I will add skb free when -EAGAIN is returned for XDP_TX. I will update the patch.

Thanks,
- Haiyang