hv_netvsc: Add support for XDP_REDIRECT
Haiyang Zhang
maintainerPATCH 1/1 hv_netvsc: Add support for XDP_REDIRECT
Handle XDP_REDIRECT action in netvsc driver.
Also, transparently pass ndo_xdp_xmit to VF when available.
Signed-off-by Haiyang Zhang <[email protected]>
--- drivers/net/hyperv/hyperv_net.h | 69 ++++++++++++++- drivers/net/hyperv/netvsc.c | 8 +- drivers/net/hyperv/netvsc_bpf.c | 95 +++++++++++++++++++- drivers/net/hyperv/netvsc_drv.c | 150 +++++++++++++------------------- 4 files changed, 228 insertions(+), 94 deletions(-)
drivers/net/hyperv/hyperv_net.h +66 -3
@@ -15,6 +15,7 @@#include <linux/list.h> #include <linux/hyperv.h> #include <linux/rndis.h> +#include <linux/jhash.h> /* RSS related */ #define OID_GEN_RECEIVE_SCALE_CAPABILITIES 0x00010203/* query only */
@@ -237,6 +238,7 @@ int netvsc_recv_callback(struct net_device *net,void netvsc_channel_cb (void *context);int netvsc_poll (struct napi_struct *napi,int budget); +void netvsc_xdp_xmit (struct sk_buff *skb,struct net_device *ndev);u32 netvsc_run_xdp (struct net_device *ndev,struct netvsc_channel *nvchan,struct xdp_buff *xdp);unsigned int netvsc_xdp_fraglen (unsigned int len);
@@ -246,6 +248,8 @@ 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 netvsc_ndoxdp_xmit (struct net_device *ndev,int n, +struct xdp_frame **frames,u32 flags); int rndis_set_subchannel(struct net_device *ndev, struct netvsc_device *nvdev,
@@ -942,12 +946,21 @@ struct nvsc_rsc {#define NVSC_RSC_CSUM_INFO BIT(1)/* valid/present bit for 'csum_info' */ #define NVSC_RSC_HASH_INFO BIT(2)/* valid/present bit for 'hash_info' */ -struct netvsc_stats { +struct netvsc_stats_tx { +u64 packets; +u64 bytes; +u64 xdp_xmit; +struct u64_stats_sync syncp; +}; + +struct netvsc_stats_rx {u64 packets;u64 bytes;u64 broadcast;u64 multicast;u64 xdp_drop; +u64 xdp_redirect; +u64 xdp_tx;struct u64_stats_sync syncp; };
@@ -1046,6 +1059,55 @@ struct net_device_context {struct netvsc_device_info *saved_netvsc_dev_info; }; +/* Azure hosts don't support non-TCP port numbers in hashing for fragmented +* packets. We can use ethtool to change UDP hash level when necessary. +*/ +static inline u32 netvsc_get_hash (struct sk_buff *skb, +const struct net_device_context *ndc) +{ +struct flow_keys flow; +u32 hash, pkt_proto =0 ; +static u32 hashrnd__read_mostly ; + +net_get_random_once (&hashrnd,sizeof (hashrnd)); + +if (!skb_flow_dissect_flow_keys (skb, &flow,0 )) +return 0 ; + +switch (flow.basic.ip_proto) { +case IPPROTO_TCP : +if (flow.basic.n_proto ==htons (ETH_P_IP )) + pkt_proto =HV_TCP4_L4HASH ; +else if (flow.basic.n_proto ==htons (ETH_P_IPV6 )) + pkt_proto =HV_TCP6_L4HASH ; + +break ; + +case IPPROTO_UDP : +if (flow.basic.n_proto ==htons (ETH_P_IP )) + pkt_proto =HV_UDP4_L4HASH ; +else if (flow.basic.n_proto ==htons (ETH_P_IPV6 )) + pkt_proto =HV_UDP6_L4HASH ; + +break ; + } + +if (pkt_proto & ndc->l4_hash) { +return skb_get_hash (skb); + }else { +if (flow.basic.n_proto ==htons (ETH_P_IP )) + hash =jhash2 ((u32 *)&flow.addrs.v4addrs,2 , hashrnd); +else if (flow.basic.n_proto ==htons (ETH_P_IPV6 )) + hash =jhash2 ((u32 *)&flow.addrs.v6addrs,8 , hashrnd); +else +return 0 ; + +__skb_set_sw_hash (skb, hash, false); + } + +return hash; +} +/* Per channel data */ struct netvsc_channel {struct vmbus_channel *channel;
@@ -1060,9 +1122,10 @@ struct netvsc_channel {struct bpf_prog __rcu *bpf_prog;struct xdp_rxq_info xdp_rxq; +bool xdp_flush; -struct netvsc_stats tx_stats; -struct netvsc_stats rx_stats; +struct netvsc_stats_tx tx_stats; +struct netvsc_stats_rx rx_stats; };/* Per netvsc device */
drivers/net/hyperv/netvsc.c +7 -1
@@ -20,6 +20,7 @@#include <linux/vmalloc.h> #include <linux/rtnetlink.h> #include <linux/prefetch.h> +#include <linux/filter.h> #include <asm/sync_bitops.h> #include <asm/mshyperv.h>
@@ -805,7 +806,7 @@ static void netvsc_send_tx_complete(struct net_device *ndev,struct hv_netvsc_packet *packet = (struct hv_netvsc_packet *)skb->cb;u32 send_index = packet->send_buf_index; -struct netvsc_stats *tx_stats; +struct netvsc_stats_tx *tx_stats;if (send_index !=NETVSC_INVALID_INDEX )netvsc_free_send_slot (net_device, send_index);
@@ -1670,12 +1671,17 @@ int netvsc_poll(struct napi_struct *napi, int budget)if (!nvchan->desc) nvchan->desc =hv_pkt_iter_first (channel); + nvchan->xdp_flush = false; +while (nvchan->desc && work_done < budget) { work_done +=netvsc_process_raw_pkt (device, nvchan, net_device, ndev, nvchan->desc, budget); nvchan->desc =hv_pkt_iter_next (channel, nvchan->desc); } +if (nvchan->xdp_flush) +xdp_do_flush (); +/* Send any pending receive completions */ ret =send_recv_completions (ndev, net_device, nvchan);
drivers/net/hyperv/netvsc_bpf.c +94 -1
130 lines not on this page · raw message
drivers/net/hyperv/netvsc_drv.c +61 -89
259 lines not on this page · raw message
Signature · 1 line
2.25.1
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Thu, 7 Apr 2022 13:21:34 -0700 you wrote:
Handle
XDP_REDIRECTaction in netvsc driver.
Also, transparently passndo_xdp_xmitto VF when available.Signed-off-by Haiyang Zhang <[email protected]>--- drivers/net/hyperv/hyperv_net.h | 69 ++++++++++++++- drivers/net/hyperv/netvsc.c | 8 +- drivers/net/hyperv/netvsc_bpf.c | 95 +++++++++++++++++++- drivers/net/hyperv/netvsc_drv.c | 150 +++++++++++++------------------- 4 files changed, 228 insertions(+), 94 deletions(-)
Here is the summary with links:
- [net-next] hv_netvsc: Add support for XDP_REDIRECT
https://git.kernel.org/netdev/net-next/c/1cb9d3b6185b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html