Skip to contentSkip to conversation

hv_netvsc: Add XDP support and some error handling fixes

PATCH In review Haiyang Zhang 4 participants 13 messages Oct 28, 2019 – Nov 4, 2019

Subsystems (6)
lore
Share & tools
lore

Haiyang Zhang

author maintainer
#0 lore raw

cover hv_netvsc: Add XDP support and some error handling fixes

This patch set fixes some error handling issues in netvsc driver, and add XDP support.

Haiyang Zhang (4):
hv_netvsc: Fix error handling in netvsc_set_features()
hv_netvsc: Fix error handling in netvsc_attach()
hv_netvsc: Add XDP support
hv_netvsc: Update document for XDP support

 .../networking/device_drivers/microsoft/netvsc.txt |  14 ++
 drivers/net/hyperv/Makefile                        |   2 +-
 drivers/net/hyperv/hyperv_net.h                    |  15 ++
 drivers/net/hyperv/netvsc.c                        |   8 +-
 drivers/net/hyperv/netvsc_bpf.c                    | 211 +++++++++++++++++++++
 drivers/net/hyperv/netvsc_drv.c                    | 150 ++++++++++++---
 6 files changed, 374 insertions(+), 26 deletions(-)
 create mode 100644 drivers/net/hyperv/netvsc_bpf.c
Signature · 1 line
1.8.3.1
author maintainer
#1 lore raw

PATCH 1/4 hv_netvsc: Fix error handling in netvsc_set_features()

When an error is returned by rndis_filter_set_offload_params(), we should still assign the unaffected features to ndev->features. Otherwise, these features will be missing.

Fixes d6792a5a0747 ("hv_netvsc: Add handler for LRO setting change")
---
 drivers/net/hyperv/netvsc_drv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/hyperv/netvsc_drv.c +3 -1
index 39dddcd..734e411 100644
@@ -1807,8 +1807,10 @@ static int netvsc_set_features(struct net_device *ndev,
 
 	ret = rndis_filter_set_offload_params(ndev, nvdev, &offloads);
 
-	if (ret)
+	if (ret) {
 		features ^= NETIF_F_LRO;
+		ndev->features = features;
+	}
 
 syncvf:
 	if (!vf_netdev)
Signature · 1 line
1.8.3.1
author maintainer
#2 lore raw

PATCH 2/4 hv_netvsc: Fix error handling in netvsc_attach()

In reply to Haiyang Zhang

If rndis_filter_open() fails, we need to remove the rndis device created in earlier steps, before returning an error code. Otherwise, the retry of netvsc_attach() from its callers will fail and hang.

Fixes 7b2ee50c0cd5 ("hv_netvsc: common detach logic")
---
 drivers/net/hyperv/netvsc_drv.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/hyperv/netvsc_drv.c +8 -1
index 734e411..a14fc8e 100644
@@ -982,7 +982,7 @@ static int netvsc_attach(struct net_device *ndev,
 	if (netif_running(ndev)) {
 		ret = rndis_filter_open(nvdev);
 		if (ret)
-			return ret;
+			goto err;
 
 		rdev = nvdev->extension;
 		if (!rdev->link_state)
@@ -990,6 +990,13 @@ static int netvsc_attach(struct net_device *ndev,
 	}
 
 	return 0;
+
+err:
+	netif_device_detach(ndev);
+
+	rndis_filter_device_remove(hdev, nvdev);
+
+	return ret;
 }
 
 static int netvsc_set_channels(struct net_device *net,
Signature · 1 line
1.8.3.1
#3 lore raw

Re: [PATCH net-next, 2/4] hv_netvsc: Fix error handling in netvsc_attach()

Quoted 3 lines

If rndis_filter_open() fails, we need to remove the rndis device created in earlier steps, before returning an error code. Otherwise, the retry of netvsc_attach() from its callers will fail and hang.

How do you think about to choose a more “imperative mood” for your change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=0dbe6cb8f7e05bc9611602ef45980a6c57b245a3#n151

…

drivers/net/hyperv/netvsc_drv.c static int netvsc_attach(struct net_device *ndev, · line 988

Quoted 10 lines

+++ b/drivers/net/hyperv/netvsc_drv.c

drivers/net/hyperv/netvsc_drv.c +1 -1
@@ -982,7 +982,7 @@ static int netvsc_attach(struct net_device *ndev,
 	if (netif_running(ndev)) {
 		ret = rndis_filter_open(nvdev);
 		if (ret)
-			return ret;
+			goto err;
 
 		rdev = nvdev->extension;
 		if (!rdev->link_state)

…

I would prefer to specify the completed exception handling (addition of two function calls) by a compound statement in the shown if branch directly.

If you would insist to use a goto statement, I find an other label more appropriate according to the Linux coding style.

Regards,
Markus

author maintainer
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

PATCH 3/4 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.

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_TX, XDP_REDIRECT

---
 drivers/net/hyperv/Makefile     |   2 +-
 drivers/net/hyperv/hyperv_net.h |  15 +++
 drivers/net/hyperv/netvsc.c     |   8 +-
 drivers/net/hyperv/netvsc_bpf.c | 211 ++++++++++++++++++++++++++++++++++++++++
 drivers/net/hyperv/netvsc_drv.c | 141 ++++++++++++++++++++++-----
 5 files changed, 351 insertions(+), 26 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 +15 -0
index 670ef68..e5aa256 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];
 };
 
@@ -199,6 +201,15 @@ 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,
+		   void **p_pbuf);
+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 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);
@@ -865,6 +876,7 @@ struct netvsc_stats {
 	u64 bytes;
 	u64 broadcast;
 	u64 multicast;
+	u64 xdp_drop;
 	struct u64_stats_sync syncp;
 };
 
@@ -965,6 +977,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 +7 -1
index d22a36f..688487b 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);
 }
@@ -1370,6 +1372,10 @@ 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);
+
+		xdp_rxq_info_reg(&nvchan->xdp_rxq, ndev, i);
+		xdp_rxq_info_reg_mem_model(&nvchan->xdp_rxq,
+					   MEM_TYPE_PAGE_SHARED, NULL);
 	}
 
 	/* Enable NAPI handler before init callbacks */
drivers/net/hyperv/netvsc_bpf.c new file +211 -0

211 lines not on this page · raw message

drivers/net/hyperv/netvsc_drv.c +117 -24

330 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#6 lore raw

Re: [PATCH net-next, 3/4] hv_netvsc: Add XDP support

Quoted 9 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.

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_TX, XDP_REDIRECT

I don't think we want to merge support without at least XDP_TX these days..

And without the ability to prepend headers this may be the least complete initial XDP implementation we've seen :(

Quoted 19 lines
drivers/net/hyperv/netvsc.c +3 -1
index d22a36f..688487b 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);
 }

drivers/net/hyperv/netvsc.c struct netvsc_device *netvsc_device_add(struct hv_device *device, · line 1378

Quoted 7 lines
drivers/net/hyperv/netvsc.c +4 -0
@@ -1370,6 +1372,10 @@ 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);
+
+		xdp_rxq_info_reg(&nvchan->xdp_rxq, ndev, i);
+		xdp_rxq_info_reg_mem_model(&nvchan->xdp_rxq,
+					   MEM_TYPE_PAGE_SHARED, NULL);

These can fail.

Quoted 38 lines
drivers/net/hyperv/netvsc.c +0 -0
 	}
 
 	/* Enable NAPI handler before init callbacks */
drivers/net/hyperv/netvsc_bpf.c new file +29 -0
new file mode 100644
index 0000000..4d235ac
@@ -0,0 +1,211 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (c) 2019, Microsoft Corporation.
+ *
+ * Author:
+ *   Haiyang Zhang <[email protected]>
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
+#include <linux/bpf.h>
+#include <linux/bpf_trace.h>
+#include <linux/kernel.h>
+#include <net/xdp.h>
+
+#include <linux/mutex.h>
+#include <linux/rtnetlink.h>
+
+#include "hyperv_net.h"
+
+u32 netvsc_run_xdp(struct net_device *ndev, struct netvsc_channel *nvchan,
+		   void **p_pbuf)
+{
+	struct page *page = NULL;
+	void *data = nvchan->rsc.data[0];
+	u32 len = nvchan->rsc.len[0];
+	void *pbuf = data;

drivers/net/hyperv/netvsc_bpf.c line 39

Quoted 10 lines
drivers/net/hyperv/netvsc_bpf.c new file +10 -0
+	struct bpf_prog *prog;
+	struct xdp_buff xdp;
+	u32 act = XDP_PASS;
+
+	*p_pbuf = NULL;
+
+	rcu_read_lock();
+	prog = rcu_dereference(nvchan->bpf_prog);
+
+	if (!prog || nvchan->rsc.cnt > 1)

Can rsc.cnt == 1 not be ensured at setup time? This looks quite limiting if random frames could be forced to bypass the filter.

drivers/net/hyperv/netvsc_bpf.c line 46

Quoted 7 lines
drivers/net/hyperv/netvsc_bpf.c new file +7 -0
+		goto out;
+
+	/* copy to a new page buffer if data are not within a page */
+	if (virt_to_page(data) != virt_to_page(data + len - 1)) {
+		page = alloc_page(GFP_ATOMIC);
+		if (!page)
+			goto out;

Returning XDP_PASS on allocation failure seems highly questionable.

drivers/net/hyperv/netvsc_bpf.c line 55

Quoted 8 lines
drivers/net/hyperv/netvsc_bpf.c new file +8 -0
+		pbuf = page_address(page);
+		memcpy(pbuf, nvchan->rsc.data[0], len);
+
+		*p_pbuf = pbuf;
+	}
+
+	xdp.data_hard_start = pbuf;
+	xdp.data = xdp.data_hard_start;

This patch also doesn't add any headroom for XDP to prepend data :(

Quoted 45 lines
drivers/net/hyperv/netvsc_bpf.c new file +45 -0
+	xdp_set_data_meta_invalid(&xdp);
+	xdp.data_end = xdp.data + len;
+	xdp.rxq = &nvchan->xdp_rxq;
+	xdp.handle = 0;
+
+	act = bpf_prog_run_xdp(prog, &xdp);
+
+	switch (act) {
+	case XDP_PASS:
+		/* Pass to upper layers */
+		break;
+
+	case XDP_ABORTED:
+		trace_xdp_exception(ndev, prog, act);
+		break;
+
+	case XDP_DROP:
+		break;
+
+	default:
+		bpf_warn_invalid_xdp_action(act);
+	}
+
+out:
+	rcu_read_unlock();
+
+	if (page && act != XDP_PASS) {
+		*p_pbuf = NULL;
+		__free_page(page);
+	}
+
+	return act;
+}
+
+unsigned int netvsc_xdp_fraglen(unsigned int len)
+{
+	return SKB_DATA_ALIGN(len) +
+	       SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+}
+
+struct bpf_prog *netvsc_xdp_get(struct netvsc_device *nvdev)
+{
+	return rtnl_dereference(nvdev->chan_table[0].bpf_prog);
+}
+

drivers/net/hyperv/netvsc_bpf.c line 110

Quoted 10 lines
drivers/net/hyperv/netvsc_bpf.c new file +10 -0
+int netvsc_xdp_set(struct net_device *dev, struct bpf_prog *prog,
+		   struct netvsc_device *nvdev)
+{
+	struct bpf_prog *old_prog;
+	int frag_max, i;
+
+	old_prog = netvsc_xdp_get(nvdev);
+
+	if (!old_prog && !prog)
+		return 0;

I think this case is now handled by the core.

drivers/net/hyperv/netvsc_bpf.c line 120

Quoted 9 lines
drivers/net/hyperv/netvsc_bpf.c new file +9 -0
+	frag_max = netvsc_xdp_fraglen(dev->mtu + ETH_HLEN);
+	if (prog && frag_max > PAGE_SIZE) {
+		netdev_err(dev, "XDP: mtu:%u too large, frag:%u\n",
+			   dev->mtu, frag_max);
+		return -EOPNOTSUPP;
+	}
+
+	if (prog && (dev->features & NETIF_F_LRO)) {
+		netdev_err(dev, "XDP: not support LRO\n");

Please report this via extack, that way users will see it in the console in which they're installing the program.

Quoted 29 lines
drivers/net/hyperv/netvsc_bpf.c new file +29 -0
+		return -EOPNOTSUPP;
+	}
+
+	if (prog) {
+		prog = bpf_prog_add(prog, nvdev->num_chn);
+		if (IS_ERR(prog))
+			return PTR_ERR(prog);
+	}
+
+	for (i = 0; i < nvdev->num_chn; i++)
+		rcu_assign_pointer(nvdev->chan_table[i].bpf_prog, prog);
+
+	if (old_prog)
+		for (i = 0; i < nvdev->num_chn; i++)
+			bpf_prog_put(old_prog);
+
+	return 0;
+}
+
+int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog *prog)
+{
+	struct netdev_bpf xdp;
+	bpf_op_t ndo_bpf;
+
+	ASSERT_RTNL();
+
+	if (!vf_netdev)
+		return 0;
+

drivers/net/hyperv/netvsc_bpf.c line 159

Quoted 10 lines
drivers/net/hyperv/netvsc_bpf.c new file +10 -0
+	ndo_bpf = vf_netdev->netdev_ops->ndo_bpf;
+	if (!ndo_bpf)
+		return 0;
+
+	memset(&xdp, 0, sizeof(xdp));
+
+	xdp.command = XDP_SETUP_PROG;
+	xdp.prog = prog;
+
+	return ndo_bpf(vf_netdev, &xdp);

IMHO the automatic propagation is not a good idea. Especially if the propagation doesn't make the entire installation fail if VF doesn't have ndo_bpf.

Quoted 1 line
drivers/net/hyperv/netvsc_bpf.c new file +1 -0
+}
author maintainer
#7 lore raw

RE: [PATCH net-next, 3/4] hv_netvsc: Add XDP support

Quoted 17 lines

-----Original Message-----
From: Jakub Kicinski <[email protected]>
Sent: Monday, October 28, 2019 5:33 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]; linux- [email protected]
Subject: Re: [PATCH net-next, 3/4] hv_netvsc: Add XDP support

Quoted 4 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.

XDP program cannot run with LRO (RSC) enabled, so you need to disable

LRO

Quoted 8 lines
Quoted 5 lines

before running XDP:
ethtool -K eth0 lro off

XDP actions not yet supported:
XDP_TX, XDP_REDIRECT

I don't think we want to merge support without at least XDP_TX these days..

Thanks for your detailed comments --
I'm working on the XDP_TX...

Quoted 3 lines

And without the ability to prepend headers this may be the least complete initial XDP implementation we've seen :(

The RNDIS packet buffer received by netvsc doesn't have a head room, but I'm considering copy the packets to the page buffer, with a head room space reserved for XDP.

Quoted 22 lines

drivers/net/hyperv/netvsc.c static void free_netvsc_device(struct rcu_head

Quoted 8 lines
drivers/net/hyperv/netvsc.c +0 -0
index d22a36f..688487b 100644
@@ -122,8 +122,10 @@ static void free_netvsc_device(struct rcu_head

*head)

drivers/net/hyperv/netvsc.c struct netvsc_device *netvsc_device_add(struct

Quoted 12 lines
drivers/net/hyperv/netvsc.c +3 -1
 	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);
 }
@@ -1370,6 +1372,10 @@ struct netvsc_device *netvsc_device_add(struct

hv_device *device,

Quoted 9 lines

drivers/net/hyperv/netvsc.c struct netvsc_device *netvsc_device_add(struct hv_device *device, · line 1378

Quoted 7 lines
drivers/net/hyperv/netvsc.c +4 -0
 		nvchan->net_device = net_device;
 		u64_stats_init(&nvchan->tx_stats.syncp);
 		u64_stats_init(&nvchan->rx_stats.syncp);
+
+		xdp_rxq_info_reg(&nvchan->xdp_rxq, ndev, i);
+		xdp_rxq_info_reg_mem_model(&nvchan->xdp_rxq,
+					   MEM_TYPE_PAGE_SHARED, NULL);

These can fail.

I will add error handling.

Quoted 46 lines

Review

Quoted 5 lines
drivers/net/hyperv/netvsc.c +0 -0
 	}
 
 	/* Enable NAPI handler before init callbacks */
(quoted diff) +0 -0

b/drivers/net/hyperv/netvsc_bpf.c

Quoted 18 lines

new file mode 100644
index 0000000..4d235ac

drivers/net/hyperv/netvsc_bpf.c new file +13 -0
@@ -0,0 +1,211 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (c) 2019, Microsoft Corporation.
+ *
+ * Author:
+ *   Haiyang Zhang <[email protected]>
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
+#include <linux/bpf.h>

drivers/net/hyperv/netvsc_bpf.c line 23

Quoted 10 lines
drivers/net/hyperv/netvsc_bpf.c new file +10 -0
+#include <linux/bpf_trace.h>
+#include <linux/kernel.h>
+#include <net/xdp.h>
+
+#include <linux/mutex.h>
+#include <linux/rtnetlink.h>
+
+#include "hyperv_net.h"
+
+u32 netvsc_run_xdp(struct net_device *ndev, struct netvsc_channel

*nvchan,

Quoted 11 lines
drivers/net/hyperv/netvsc_bpf.c new file +11 -0
+		   void **p_pbuf)
+{
+	struct page *page = NULL;
+	void *data = nvchan->rsc.data[0];
+	u32 len = nvchan->rsc.len[0];
+	void *pbuf = data;
+	struct bpf_prog *prog;
+	struct xdp_buff xdp;
+	u32 act = XDP_PASS;
+
+	*p_pbuf = NULL;
Quoted 8 lines

drivers/net/hyperv/netvsc_bpf.c line 39

Quoted 5 lines
drivers/net/hyperv/netvsc_bpf.c new file +5 -0
+
+	rcu_read_lock();
+	prog = rcu_dereference(nvchan->bpf_prog);
+
+	if (!prog || nvchan->rsc.cnt > 1)

Can rsc.cnt == 1 not be ensured at setup time? This looks quite limiting if random frames could be forced to bypass the filter.

Yes, the setup code already check/ensure LRO is disabled. So rsc.cnt > 1 is NOT expected here. Just an error check. I will change the return value to XDP_ABORTED for this.

Quoted 10 lines

drivers/net/hyperv/netvsc_bpf.c line 46

Quoted 8 lines
drivers/net/hyperv/netvsc_bpf.c new file +7 -0
+		goto out;
+
+	/* copy to a new page buffer if data are not within a page */
+	if (virt_to_page(data) != virt_to_page(data + len - 1)) {
+		page = alloc_page(GFP_ATOMIC);
+		if (!page)
+			goto out;

Returning XDP_PASS on allocation failure seems highly questionable.

I will change the return value to XDP_ABORTED for this too.

Quoted 11 lines

drivers/net/hyperv/netvsc_bpf.c line 55

Quoted 9 lines
drivers/net/hyperv/netvsc_bpf.c new file +8 -0
+		pbuf = page_address(page);
+		memcpy(pbuf, nvchan->rsc.data[0], len);
+
+		*p_pbuf = pbuf;
+	}
+
+	xdp.data_hard_start = pbuf;
+	xdp.data = xdp.data_hard_start;

This patch also doesn't add any headroom for XDP to prepend data :(

I'm considering to add the headroom to the start of the page.

Quoted 50 lines
Quoted 50 lines
drivers/net/hyperv/netvsc_bpf.c new file +49 -0
+	xdp_set_data_meta_invalid(&xdp);
+	xdp.data_end = xdp.data + len;
+	xdp.rxq = &nvchan->xdp_rxq;
+	xdp.handle = 0;
+
+	act = bpf_prog_run_xdp(prog, &xdp);
+
+	switch (act) {
+	case XDP_PASS:
+		/* Pass to upper layers */
+		break;
+
+	case XDP_ABORTED:
+		trace_xdp_exception(ndev, prog, act);
+		break;
+
+	case XDP_DROP:
+		break;
+
+	default:
+		bpf_warn_invalid_xdp_action(act);
+	}
+
+out:
+	rcu_read_unlock();
+
+	if (page && act != XDP_PASS) {
+		*p_pbuf = NULL;
+		__free_page(page);
+	}
+
+	return act;
+}
+
+unsigned int netvsc_xdp_fraglen(unsigned int len)
+{
+	return SKB_DATA_ALIGN(len) +
+	       SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+}
+
+struct bpf_prog *netvsc_xdp_get(struct netvsc_device *nvdev)
+{
+	return rtnl_dereference(nvdev->chan_table[0].bpf_prog);
+}
+
+int netvsc_xdp_set(struct net_device *dev, struct bpf_prog *prog,
+		   struct netvsc_device *nvdev)
+{
+	struct bpf_prog *old_prog;
Quoted 8 lines

drivers/net/hyperv/netvsc_bpf.c line 110

Quoted 6 lines
drivers/net/hyperv/netvsc_bpf.c new file +6 -0
+	int frag_max, i;
+
+	old_prog = netvsc_xdp_get(nvdev);
+
+	if (!old_prog && !prog)
+		return 0;

I think this case is now handled by the core.

Thanks for the reminder. I saw the code in dev_change_xdp_fd(), so the upper layer doesn't call XDP_SETUP_PROG with old/new prog both NULL.
But this function is also called by other functions in our driver, like netvsc_detach(), netvsc_remove(), etc. Instead of checking for NULL in each place, I still keep the check inside netvsc_xdp_set().

Quoted 13 lines

drivers/net/hyperv/netvsc_bpf.c line 120

Quoted 10 lines
drivers/net/hyperv/netvsc_bpf.c new file +9 -0
+	frag_max = netvsc_xdp_fraglen(dev->mtu + ETH_HLEN);
+	if (prog && frag_max > PAGE_SIZE) {
+		netdev_err(dev, "XDP: mtu:%u too large, frag:%u\n",
+			   dev->mtu, frag_max);
+		return -EOPNOTSUPP;
+	}
+
+	if (prog && (dev->features & NETIF_F_LRO)) {
+		netdev_err(dev, "XDP: not support LRO\n");

Please report this via extack, that way users will see it in the console in which they're installing the program.

I will.

Quoted 37 lines
Quoted 11 lines
drivers/net/hyperv/netvsc_bpf.c new file +10 -0
+		return -EOPNOTSUPP;
+	}
+
+	if (prog) {
+		prog = bpf_prog_add(prog, nvdev->num_chn);
+		if (IS_ERR(prog))
+			return PTR_ERR(prog);
+	}
+
+	for (i = 0; i < nvdev->num_chn; i++)

drivers/net/hyperv/netvsc_bpf.c

Quoted 10 lines
drivers/net/hyperv/netvsc_bpf.c new file +10 -0
+		rcu_assign_pointer(nvdev->chan_table[i].bpf_prog, prog);
+
+	if (old_prog)
+		for (i = 0; i < nvdev->num_chn; i++)
+			bpf_prog_put(old_prog);
+
+	return 0;
+}
+
+int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog

*prog)

Quoted 15 lines
drivers/net/hyperv/netvsc_bpf.c new file +15 -0
+{
+	struct netdev_bpf xdp;
+	bpf_op_t ndo_bpf;
+
+	ASSERT_RTNL();
+
+	if (!vf_netdev)
+		return 0;
+
+	ndo_bpf = vf_netdev->netdev_ops->ndo_bpf;
+	if (!ndo_bpf)
+		return 0;
+
+	memset(&xdp, 0, sizeof(xdp));
+
Quoted 8 lines

drivers/net/hyperv/netvsc_bpf.c line 159

Quoted 4 lines
drivers/net/hyperv/netvsc_bpf.c new file +4 -0
+	xdp.command = XDP_SETUP_PROG;
+	xdp.prog = prog;
+
+	return ndo_bpf(vf_netdev, &xdp);

IMHO the automatic propagation is not a good idea. Especially if the propagation doesn't make the entire installation fail if VF doesn't have ndo_bpf.

On Hyperv and Azure hosts, VF is always acting as a slave below netvsc. And they are both active -- most data packets go to VF, but broadcast, multicast, and TCP SYN packets go to netvsc synthetic data path. The synthetic NIC (netvsc) is also a failover NIC when VF is not available.
We ask customers to only use the synthetic NIC directly. So propagation of XDP setting to VF NIC is desired.
But, I will change the return code to error, so the entire installation fails if VF is present but unable to set XDP prog.

Thanks,
- Haiyang

#8 lore raw

Re: [PATCH net-next, 3/4] hv_netvsc: Add XDP support

Quoted 12 lines · Haiyang Zhang
Quoted 4 lines
Quoted 4 lines
drivers/net/hyperv/netvsc_bpf.c new file +4 -0
+int netvsc_xdp_set(struct net_device *dev, struct bpf_prog *prog,
+		   struct netvsc_device *nvdev)
+{
+	struct bpf_prog *old_prog;
Quoted 8 lines

drivers/net/hyperv/netvsc_bpf.c line 110

Quoted 6 lines
drivers/net/hyperv/netvsc_bpf.c new file +6 -0
+	int frag_max, i;
+
+	old_prog = netvsc_xdp_get(nvdev);
+
+	if (!old_prog && !prog)
+		return 0;  

I think this case is now handled by the core.

Quoted 5 lines

Thanks for the reminder. I saw the code in dev_change_xdp_fd(), so the upper layer doesn't call XDP_SETUP_PROG with old/new prog both NULL.
But this function is also called by other functions in our driver, like netvsc_detach(), netvsc_remove(), etc. Instead of checking for NULL in each place, I still keep the check inside netvsc_xdp_set().

I see. Makes sense on a closer look.

BTW would you do me a favour and reformat this line:

static struct netvsc_device_info *netvsc_devinfo_get
(struct netvsc_device *nvdev)

to look like this:

static
struct netvsc_device_info *netvsc_devinfo_get(struct netvsc_device *nvdev)

or

static struct netvsc_device_info *
netvsc_devinfo_get(struct netvsc_device *nvdev)

Otherwise git diff gets confused about which function given chunk belongs to. (Incorrectly thinking your patch is touching netvsc_get_channels()). I spent few minutes trying to figure out what's going on there :)

Quoted 45 lines
Quoted 36 lines
Quoted 36 lines
drivers/net/hyperv/netvsc_bpf.c new file +35 -0
+		return -EOPNOTSUPP;
+	}
+
+	if (prog) {
+		prog = bpf_prog_add(prog, nvdev->num_chn);
+		if (IS_ERR(prog))
+			return PTR_ERR(prog);
+	}
+
+	for (i = 0; i < nvdev->num_chn; i++)
+		rcu_assign_pointer(nvdev->chan_table[i].bpf_prog, prog);
+
+	if (old_prog)
+		for (i = 0; i < nvdev->num_chn; i++)
+			bpf_prog_put(old_prog);
+
+	return 0;
+}
+
+int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog *prog)  
+{
+	struct netdev_bpf xdp;
+	bpf_op_t ndo_bpf;
+
+	ASSERT_RTNL();
+
+	if (!vf_netdev)
+		return 0;
+
+	ndo_bpf = vf_netdev->netdev_ops->ndo_bpf;
+	if (!ndo_bpf)
+		return 0;
+
+	memset(&xdp, 0, sizeof(xdp));
+
Quoted 8 lines

drivers/net/hyperv/netvsc_bpf.c line 159

Quoted 4 lines
drivers/net/hyperv/netvsc_bpf.c new file +4 -0
+	xdp.command = XDP_SETUP_PROG;
+	xdp.prog = prog;
+
+	return ndo_bpf(vf_netdev, &xdp);  

IMHO the automatic propagation is not a good idea. Especially if the propagation doesn't make the entire installation fail if VF doesn't have ndo_bpf.

Quoted 8 lines

On Hyperv and Azure hosts, VF is always acting as a slave below netvsc. And they are both active -- most data packets go to VF, but broadcast, multicast, and TCP SYN packets go to netvsc synthetic data path. The synthetic NIC (netvsc) is also a failover NIC when VF is not available.
We ask customers to only use the synthetic NIC directly. So propagation of XDP setting to VF NIC is desired.
But, I will change the return code to error, so the entire installation fails if VF is present but unable to set XDP prog.

Okay, if I read the rest of the code correctly you also fail attach if xdp propagation failed? If that's the case and we return an error here on missing NDO, then the propagation could be okay.

So the semantics are these:

(a) install on virt - potentially overwrites the existing VF prog;
(b) install on VF is not noticed by virt;
(c) uninstall on virt - clears both virt and VF, regardless what

    program was installed on virt;

(d) uninstall on VF does not propagate;

Since you're adding documentation it would perhaps be worth stating there that touching the program on the VF is not supported/may lead to breakage, and users should only touch/configure the program on the virt.

author maintainer
#9 lore raw

RE: [PATCH net-next, 3/4] hv_netvsc: Add XDP support

Quoted 50 lines

-----Original Message-----
From: Jakub Kicinski <[email protected]>
Sent: Tuesday, October 29, 2019 3:53 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]; linux- [email protected]
Subject: Re: [PATCH net-next, 3/4] hv_netvsc: Add XDP support

Quoted 12 lines · Haiyang Zhang
Quoted 4 lines
Quoted 4 lines
drivers/net/hyperv/netvsc_bpf.c new file +4 -0
+int netvsc_xdp_set(struct net_device *dev, struct bpf_prog *prog,
+		   struct netvsc_device *nvdev)
+{
+	struct bpf_prog *old_prog;
Quoted 8 lines

drivers/net/hyperv/netvsc_bpf.c line 110

Quoted 6 lines
drivers/net/hyperv/netvsc_bpf.c new file +6 -0
+	int frag_max, i;
+
+	old_prog = netvsc_xdp_get(nvdev);
+
+	if (!old_prog && !prog)
+		return 0;

I think this case is now handled by the core.

Quoted 1 line

Thanks for the reminder. I saw the code in dev_change_xdp_fd(), so the

upper layer

Quoted 2 lines

doesn't call XDP_SETUP_PROG with old/new prog both NULL.
But this function is also called by other functions in our driver, like

netvsc_detach(),

Quoted 1 line

netvsc_remove(), etc. Instead of checking for NULL in each place, I still

keep the check inside

Quoted 1 line

netvsc_xdp_set().

I see. Makes sense on a closer look.

BTW would you do me a favour and reformat this line:

static struct netvsc_device_info *netvsc_devinfo_get
(struct netvsc_device *nvdev)

to look like this:

static
struct netvsc_device_info *netvsc_devinfo_get(struct netvsc_device *nvdev)

or

Quoted 7 lines

static struct netvsc_device_info *
netvsc_devinfo_get(struct netvsc_device *nvdev)

Otherwise git diff gets confused about which function given chunk belongs to. (Incorrectly thinking your patch is touching netvsc_get_channels()). I spent few minutes trying to figure out what's going on there :)

I will.

Quoted 67 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/net/hyperv/netvsc_bpf.c new file +12 -0
+		return -EOPNOTSUPP;
+	}
+
+	if (prog) {
+		prog = bpf_prog_add(prog, nvdev->num_chn);
+		if (IS_ERR(prog))
+			return PTR_ERR(prog);
+	}
+
+	for (i = 0; i < nvdev->num_chn; i++)
+		rcu_assign_pointer(nvdev->chan_table[i].bpf_prog, prog);
+
Quoted 8 lines
Quoted 8 lines

drivers/net/hyperv/netvsc_bpf.c

Quoted 8 lines
drivers/net/hyperv/netvsc_bpf.c new file +8 -0
+	if (old_prog)
+		for (i = 0; i < nvdev->num_chn; i++)
+			bpf_prog_put(old_prog);
+
+	return 0;
+}
+
+int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog

*prog)

Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
drivers/net/hyperv/netvsc_bpf.c new file +15 -0
+{
+	struct netdev_bpf xdp;
+	bpf_op_t ndo_bpf;
+
+	ASSERT_RTNL();
+
+	if (!vf_netdev)
+		return 0;
+
+	ndo_bpf = vf_netdev->netdev_ops->ndo_bpf;
+	if (!ndo_bpf)
+		return 0;
+
+	memset(&xdp, 0, sizeof(xdp));
+
Quoted 8 lines

drivers/net/hyperv/netvsc_bpf.c line 159

Quoted 4 lines
drivers/net/hyperv/netvsc_bpf.c new file +4 -0
+	xdp.command = XDP_SETUP_PROG;
+	xdp.prog = prog;
+
+	return ndo_bpf(vf_netdev, &xdp);

IMHO the automatic propagation is not a good idea. Especially if the propagation doesn't make the entire installation fail if VF doesn't have ndo_bpf.

Quoted 3 lines

On Hyperv and Azure hosts, VF is always acting as a slave below netvsc. And they are both active -- most data packets go to VF, but broadcast, multicast, and TCP SYN packets go to netvsc synthetic data path. The

synthetic

Quoted 4 lines

NIC (netvsc) is also a failover NIC when VF is not available.
We ask customers to only use the synthetic NIC directly. So propagation of XDP setting to VF NIC is desired.
But, I will change the return code to error, so the entire installation fails if

VF is

Quoted 1 line

present but unable to set XDP prog.

Okay, if I read the rest of the code correctly you also fail attach if xdp propagation failed? If that's the case and we return an error here on missing NDO, then the propagation could be okay.

So the semantics are these:

(a) install on virt - potentially overwrites the existing VF prog;
(b) install on VF is not noticed by virt;
(c) uninstall on virt - clears both virt and VF, regardless what

Quoted 7 lines
    program was installed on virt;

(d) uninstall on VF does not propagate;

Since you're adding documentation it would perhaps be worth stating there that touching the program on the VF is not supported/may lead to breakage, and users should only touch/configure the program on the virt.

Sure I will document the recommended way of install xdp prog.

Thanks,
- Haiyang

#10 lore raw

Re: [PATCH net-next, 3/4] hv_netvsc: Add XDP support

In reply to Haiyang Zhang
Quoted 29 lines · On Tue, 29 Oct 2019 19:17:25 +0000 Haiyang Zhang <[email protected]> wrote:
Quoted 17 lines

-----Original Message-----
From: Jakub Kicinski <[email protected]>
Sent: Monday, October 28, 2019 5:33 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]; linux- [email protected]
Subject: Re: [PATCH net-next, 3/4] hv_netvsc: Add XDP support

Quoted 4 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.

XDP program cannot run with LRO (RSC) enabled, so you need to disable

LRO

Quoted 8 lines
Quoted 5 lines

before running XDP:
ethtool -K eth0 lro off

XDP actions not yet supported:
XDP_TX, XDP_REDIRECT

I don't think we want to merge support without at least XDP_TX these days..

Thanks for your detailed comments --
I'm working on the XDP_TX...

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

And without the ability to prepend headers this may be the least complete initial XDP implementation we've seen :(

The RNDIS packet buffer received by netvsc doesn't have a head room, but I'm considering copy the packets to the page buffer, with a head room space reserved for XDP.

There is a small amount of headroom available by reusing the RNDIS header and packet space. Looks like 40 bytes or so.

author maintainer
#11 lore raw

RE: [PATCH net-next, 3/4] hv_netvsc: Add XDP support

Quoted 49 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, October 29, 2019 5:59 PM
To: Haiyang Zhang <[email protected]>
Cc: Jakub Kicinski <[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]
Subject: Re: [PATCH net-next, 3/4] hv_netvsc: Add XDP support

Quoted 11 lines · On Tue, 29 Oct 2019 19:17:25 +0000 Haiyang Zhang <[email protected]> wrote:
Quoted 11 lines

-----Original Message-----
From: Jakub Kicinski <[email protected]>
Sent: Monday, October 28, 2019 5:33 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]; linux- [email protected]
Subject: Re: [PATCH net-next, 3/4] hv_netvsc: Add XDP support

Quoted 2 lines
Quoted 2 lines · Haiyang Zhang
Quoted 1 line

This patch adds support of XDP in native mode for hv_netvsc driver,

and

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

transparently sets the XDP program on the associated VF NIC as well.

XDP program cannot run with LRO (RSC) enabled, so you need to

disable

Quoted 15 lines
Quoted 9 lines

LRO

Quoted 5 lines

before running XDP:
ethtool -K eth0 lro off

XDP actions not yet supported:
XDP_TX, XDP_REDIRECT

I don't think we want to merge support without at least XDP_TX these days..

Thanks for your detailed comments --
I'm working on the XDP_TX...

Quoted 3 lines

And without the ability to prepend headers this may be the least complete initial XDP implementation we've seen :(

Quoted 8 lines
Quoted 1 line

The RNDIS packet buffer received by netvsc doesn't have a head room, but

I'm

Quoted 2 lines

considering copy the packets to the page buffer, with a head room space reserved for XDP.

There is a small amount of headroom available by reusing the RNDIS header and packet space. Looks like 40 bytes or so.

Yes, I thought about the RNDIS header. But is this space sufficient? I saw some drivers, like virtio_net gives bigger headroom: 256 bytes.

Thanks,
- Haiyang

author maintainer
#12 lore raw

PATCH 4/4 hv_netvsc: Update document for XDP support

In reply to Haiyang Zhang

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

---
 .../networking/device_drivers/microsoft/netvsc.txt         | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/networking/device_drivers/microsoft/netvsc.txt +14 -0
index 3bfa635..69ccfca 100644
@@ -82,3 +82,17 @@ 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.
+
+  XDP program cannot run with LRO (RSC) enabled, so you need to disable LRO
+  before running XDP:
+	ethtool -K eth0 lro off
Signature · 1 line
1.8.3.1