Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hv_netvsc: Add XDP support

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

Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Haiyang Zhang and committed by
David S. Miller
351e1581 6ec8b6cd

+409 -39
+1 -1
drivers/net/hyperv/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 obj-$(CONFIG_HYPERV_NET) += hv_netvsc.o 3 3 4 - hv_netvsc-y := netvsc_drv.o netvsc.o rndis_filter.o netvsc_trace.o 4 + hv_netvsc-y := netvsc_drv.o netvsc.o rndis_filter.o netvsc_trace.o netvsc_bpf.o
+20 -1
drivers/net/hyperv/hyperv_net.h
··· 142 142 u32 send_section_size; 143 143 u32 recv_section_size; 144 144 145 + struct bpf_prog *bprog; 146 + 145 147 u8 rss_key[NETVSC_HASH_KEYLEN]; 146 148 }; 147 149 ··· 191 189 struct hv_netvsc_packet *packet, 192 190 struct rndis_message *rndis_msg, 193 191 struct hv_page_buffer *page_buffer, 194 - struct sk_buff *skb); 192 + struct sk_buff *skb, 193 + bool xdp_tx); 195 194 void netvsc_linkstatus_callback(struct net_device *net, 196 195 struct rndis_message *resp); 197 196 int netvsc_recv_callback(struct net_device *net, ··· 200 197 struct netvsc_channel *nvchan); 201 198 void netvsc_channel_cb(void *context); 202 199 int netvsc_poll(struct napi_struct *napi, int budget); 200 + 201 + u32 netvsc_run_xdp(struct net_device *ndev, struct netvsc_channel *nvchan, 202 + struct xdp_buff *xdp); 203 + unsigned int netvsc_xdp_fraglen(unsigned int len); 204 + struct bpf_prog *netvsc_xdp_get(struct netvsc_device *nvdev); 205 + int netvsc_xdp_set(struct net_device *dev, struct bpf_prog *prog, 206 + struct netlink_ext_ack *extack, 207 + struct netvsc_device *nvdev); 208 + int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog *prog); 209 + int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf); 203 210 204 211 int rndis_set_subchannel(struct net_device *ndev, 205 212 struct netvsc_device *nvdev, ··· 845 832 #define RNDIS_MAX_PKT_DEFAULT 8 846 833 #define RNDIS_PKT_ALIGN_DEFAULT 8 847 834 835 + #define NETVSC_XDP_HDRM 256 836 + 848 837 struct multi_send_data { 849 838 struct sk_buff *skb; /* skb containing the pkt */ 850 839 struct hv_netvsc_packet *pkt; /* netvsc pkt pending */ ··· 882 867 u64 bytes; 883 868 u64 broadcast; 884 869 u64 multicast; 870 + u64 xdp_drop; 885 871 struct u64_stats_sync syncp; 886 872 }; 887 873 ··· 987 971 struct multi_recv_comp mrc; 988 972 atomic_t queue_sends; 989 973 struct nvsc_rsc rsc; 974 + 975 + struct bpf_prog __rcu *bpf_prog; 976 + struct xdp_rxq_info xdp_rxq; 990 977 991 978 struct netvsc_stats tx_stats; 992 979 struct netvsc_stats rx_stats;
+26 -5
drivers/net/hyperv/netvsc.c
··· 122 122 vfree(nvdev->send_buf); 123 123 kfree(nvdev->send_section_map); 124 124 125 - for (i = 0; i < VRSS_CHANNEL_MAX; i++) 125 + for (i = 0; i < VRSS_CHANNEL_MAX; i++) { 126 + xdp_rxq_info_unreg(&nvdev->chan_table[i].xdp_rxq); 126 127 vfree(nvdev->chan_table[i].mrc.slots); 128 + } 127 129 128 130 kfree(nvdev); 129 131 } ··· 902 900 struct hv_netvsc_packet *packet, 903 901 struct rndis_message *rndis_msg, 904 902 struct hv_page_buffer *pb, 905 - struct sk_buff *skb) 903 + struct sk_buff *skb, 904 + bool xdp_tx) 906 905 { 907 906 struct net_device_context *ndev_ctx = netdev_priv(ndev); 908 907 struct netvsc_device *net_device ··· 926 923 packet->send_buf_index = NETVSC_INVALID_INDEX; 927 924 packet->cp_partial = false; 928 925 929 - /* Send control message directly without accessing msd (Multi-Send 930 - * Data) field which may be changed during data packet processing. 926 + /* Send a control message or XDP packet directly without accessing 927 + * msd (Multi-Send Data) field which may be changed during data packet 928 + * processing. 931 929 */ 932 - if (!skb) 930 + if (!skb || xdp_tx) 933 931 return netvsc_send_pkt(device, packet, net_device, pb, skb); 934 932 935 933 /* batch packets in send buffer if possible */ ··· 1396 1392 nvchan->net_device = net_device; 1397 1393 u64_stats_init(&nvchan->tx_stats.syncp); 1398 1394 u64_stats_init(&nvchan->rx_stats.syncp); 1395 + 1396 + ret = xdp_rxq_info_reg(&nvchan->xdp_rxq, ndev, i); 1397 + 1398 + if (ret) { 1399 + netdev_err(ndev, "xdp_rxq_info_reg fail: %d\n", ret); 1400 + goto cleanup2; 1401 + } 1402 + 1403 + ret = xdp_rxq_info_reg_mem_model(&nvchan->xdp_rxq, 1404 + MEM_TYPE_PAGE_SHARED, NULL); 1405 + 1406 + if (ret) { 1407 + netdev_err(ndev, "xdp reg_mem_model fail: %d\n", ret); 1408 + goto cleanup2; 1409 + } 1399 1410 } 1400 1411 1401 1412 /* Enable NAPI handler before init callbacks */ ··· 1456 1437 1457 1438 cleanup: 1458 1439 netif_napi_del(&net_device->chan_table[0].napi); 1440 + 1441 + cleanup2: 1459 1442 free_netvsc_device(&net_device->rcu); 1460 1443 1461 1444 return ERR_PTR(ret);
+209
drivers/net/hyperv/netvsc_bpf.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* Copyright (c) 2019, Microsoft Corporation. 3 + * 4 + * Author: 5 + * Haiyang Zhang <haiyangz@microsoft.com> 6 + */ 7 + 8 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 9 + 10 + #include <linux/netdevice.h> 11 + #include <linux/etherdevice.h> 12 + #include <linux/ethtool.h> 13 + #include <linux/bpf.h> 14 + #include <linux/bpf_trace.h> 15 + #include <linux/kernel.h> 16 + #include <net/xdp.h> 17 + 18 + #include <linux/mutex.h> 19 + #include <linux/rtnetlink.h> 20 + 21 + #include "hyperv_net.h" 22 + 23 + u32 netvsc_run_xdp(struct net_device *ndev, struct netvsc_channel *nvchan, 24 + struct xdp_buff *xdp) 25 + { 26 + void *data = nvchan->rsc.data[0]; 27 + u32 len = nvchan->rsc.len[0]; 28 + struct page *page = NULL; 29 + struct bpf_prog *prog; 30 + u32 act = XDP_PASS; 31 + 32 + xdp->data_hard_start = NULL; 33 + 34 + rcu_read_lock(); 35 + prog = rcu_dereference(nvchan->bpf_prog); 36 + 37 + if (!prog) 38 + goto out; 39 + 40 + /* allocate page buffer for data */ 41 + page = alloc_page(GFP_ATOMIC); 42 + if (!page) { 43 + act = XDP_DROP; 44 + goto out; 45 + } 46 + 47 + xdp->data_hard_start = page_address(page); 48 + xdp->data = xdp->data_hard_start + NETVSC_XDP_HDRM; 49 + xdp_set_data_meta_invalid(xdp); 50 + xdp->data_end = xdp->data + len; 51 + xdp->rxq = &nvchan->xdp_rxq; 52 + xdp->handle = 0; 53 + 54 + memcpy(xdp->data, data, len); 55 + 56 + act = bpf_prog_run_xdp(prog, xdp); 57 + 58 + switch (act) { 59 + case XDP_PASS: 60 + case XDP_TX: 61 + case XDP_DROP: 62 + break; 63 + 64 + case XDP_ABORTED: 65 + trace_xdp_exception(ndev, prog, act); 66 + break; 67 + 68 + default: 69 + bpf_warn_invalid_xdp_action(act); 70 + } 71 + 72 + out: 73 + rcu_read_unlock(); 74 + 75 + if (page && act != XDP_PASS && act != XDP_TX) { 76 + __free_page(page); 77 + xdp->data_hard_start = NULL; 78 + } 79 + 80 + return act; 81 + } 82 + 83 + unsigned int netvsc_xdp_fraglen(unsigned int len) 84 + { 85 + return SKB_DATA_ALIGN(len) + 86 + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); 87 + } 88 + 89 + struct bpf_prog *netvsc_xdp_get(struct netvsc_device *nvdev) 90 + { 91 + return rtnl_dereference(nvdev->chan_table[0].bpf_prog); 92 + } 93 + 94 + int netvsc_xdp_set(struct net_device *dev, struct bpf_prog *prog, 95 + struct netlink_ext_ack *extack, 96 + struct netvsc_device *nvdev) 97 + { 98 + struct bpf_prog *old_prog; 99 + int buf_max, i; 100 + 101 + old_prog = netvsc_xdp_get(nvdev); 102 + 103 + if (!old_prog && !prog) 104 + return 0; 105 + 106 + buf_max = NETVSC_XDP_HDRM + netvsc_xdp_fraglen(dev->mtu + ETH_HLEN); 107 + if (prog && buf_max > PAGE_SIZE) { 108 + netdev_err(dev, "XDP: mtu:%u too large, buf_max:%u\n", 109 + dev->mtu, buf_max); 110 + NL_SET_ERR_MSG_MOD(extack, "XDP: mtu too large"); 111 + 112 + return -EOPNOTSUPP; 113 + } 114 + 115 + if (prog && (dev->features & NETIF_F_LRO)) { 116 + netdev_err(dev, "XDP: not support LRO\n"); 117 + NL_SET_ERR_MSG_MOD(extack, "XDP: not support LRO"); 118 + 119 + return -EOPNOTSUPP; 120 + } 121 + 122 + if (prog) 123 + bpf_prog_add(prog, nvdev->num_chn); 124 + 125 + for (i = 0; i < nvdev->num_chn; i++) 126 + rcu_assign_pointer(nvdev->chan_table[i].bpf_prog, prog); 127 + 128 + if (old_prog) 129 + for (i = 0; i < nvdev->num_chn; i++) 130 + bpf_prog_put(old_prog); 131 + 132 + return 0; 133 + } 134 + 135 + int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog *prog) 136 + { 137 + struct netdev_bpf xdp; 138 + bpf_op_t ndo_bpf; 139 + 140 + ASSERT_RTNL(); 141 + 142 + if (!vf_netdev) 143 + return 0; 144 + 145 + ndo_bpf = vf_netdev->netdev_ops->ndo_bpf; 146 + if (!ndo_bpf) 147 + return 0; 148 + 149 + memset(&xdp, 0, sizeof(xdp)); 150 + 151 + xdp.command = XDP_SETUP_PROG; 152 + xdp.prog = prog; 153 + 154 + return ndo_bpf(vf_netdev, &xdp); 155 + } 156 + 157 + static u32 netvsc_xdp_query(struct netvsc_device *nvdev) 158 + { 159 + struct bpf_prog *prog = netvsc_xdp_get(nvdev); 160 + 161 + if (prog) 162 + return prog->aux->id; 163 + 164 + return 0; 165 + } 166 + 167 + int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf) 168 + { 169 + struct net_device_context *ndevctx = netdev_priv(dev); 170 + struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev); 171 + struct net_device *vf_netdev = rtnl_dereference(ndevctx->vf_netdev); 172 + struct netlink_ext_ack *extack = bpf->extack; 173 + int ret; 174 + 175 + if (!nvdev || nvdev->destroy) { 176 + if (bpf->command == XDP_QUERY_PROG) { 177 + bpf->prog_id = 0; 178 + return 0; /* Query must always succeed */ 179 + } else { 180 + return -ENODEV; 181 + } 182 + } 183 + 184 + switch (bpf->command) { 185 + case XDP_SETUP_PROG: 186 + ret = netvsc_xdp_set(dev, bpf->prog, extack, nvdev); 187 + 188 + if (ret) 189 + return ret; 190 + 191 + ret = netvsc_vf_setxdp(vf_netdev, bpf->prog); 192 + 193 + if (ret) { 194 + netdev_err(dev, "vf_setxdp failed:%d\n", ret); 195 + NL_SET_ERR_MSG_MOD(extack, "vf_setxdp failed"); 196 + 197 + netvsc_xdp_set(dev, NULL, extack, nvdev); 198 + } 199 + 200 + return ret; 201 + 202 + case XDP_QUERY_PROG: 203 + bpf->prog_id = netvsc_xdp_query(nvdev); 204 + return 0; 205 + 206 + default: 207 + return -EINVAL; 208 + } 209 + }
+152 -31
drivers/net/hyperv/netvsc_drv.c
··· 25 25 #include <linux/slab.h> 26 26 #include <linux/rtnetlink.h> 27 27 #include <linux/netpoll.h> 28 + #include <linux/bpf.h> 28 29 29 30 #include <net/arp.h> 30 31 #include <net/route.h> ··· 520 519 return rc; 521 520 } 522 521 523 - static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) 522 + static int netvsc_xmit(struct sk_buff *skb, struct net_device *net, bool xdp_tx) 524 523 { 525 524 struct net_device_context *net_device_ctx = netdev_priv(net); 526 525 struct hv_netvsc_packet *packet = NULL; ··· 687 686 /* timestamp packet in software */ 688 687 skb_tx_timestamp(skb); 689 688 690 - ret = netvsc_send(net, packet, rndis_msg, pb, skb); 689 + ret = netvsc_send(net, packet, rndis_msg, pb, skb, xdp_tx); 691 690 if (likely(ret == 0)) 692 691 return NETDEV_TX_OK; 693 692 ··· 708 707 no_memory: 709 708 ++net_device_ctx->eth_stats.tx_no_memory; 710 709 goto drop; 710 + } 711 + 712 + static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *ndev) 713 + { 714 + return netvsc_xmit(skb, ndev, false); 711 715 } 712 716 713 717 /* ··· 757 751 schedule_delayed_work(&ndev_ctx->dwork, 0); 758 752 } 759 753 754 + static void netvsc_xdp_xmit(struct sk_buff *skb, struct net_device *ndev) 755 + { 756 + int rc; 757 + 758 + skb->queue_mapping = skb_get_rx_queue(skb); 759 + __skb_push(skb, ETH_HLEN); 760 + 761 + rc = netvsc_xmit(skb, ndev, true); 762 + 763 + if (dev_xmit_complete(rc)) 764 + return; 765 + 766 + dev_kfree_skb_any(skb); 767 + ndev->stats.tx_dropped++; 768 + } 769 + 760 770 static void netvsc_comp_ipcsum(struct sk_buff *skb) 761 771 { 762 772 struct iphdr *iph = (struct iphdr *)skb->data; ··· 782 760 } 783 761 784 762 static struct sk_buff *netvsc_alloc_recv_skb(struct net_device *net, 785 - struct netvsc_channel *nvchan) 763 + struct netvsc_channel *nvchan, 764 + struct xdp_buff *xdp) 786 765 { 787 766 struct napi_struct *napi = &nvchan->napi; 788 767 const struct ndis_pkt_8021q_info *vlan = nvchan->rsc.vlan; ··· 791 768 nvchan->rsc.csum_info; 792 769 const u32 *hash_info = nvchan->rsc.hash_info; 793 770 struct sk_buff *skb; 771 + void *xbuf = xdp->data_hard_start; 794 772 int i; 795 773 796 - skb = napi_alloc_skb(napi, nvchan->rsc.pktlen); 797 - if (!skb) 798 - return skb; 774 + if (xbuf) { 775 + unsigned int hdroom = xdp->data - xdp->data_hard_start; 776 + unsigned int xlen = xdp->data_end - xdp->data; 777 + unsigned int frag_size = netvsc_xdp_fraglen(hdroom + xlen); 799 778 800 - /* 801 - * Copy to skb. This copy is needed here since the memory pointed by 802 - * hv_netvsc_packet cannot be deallocated 803 - */ 804 - for (i = 0; i < nvchan->rsc.cnt; i++) 805 - skb_put_data(skb, nvchan->rsc.data[i], nvchan->rsc.len[i]); 779 + skb = build_skb(xbuf, frag_size); 780 + 781 + if (!skb) { 782 + __free_page(virt_to_page(xbuf)); 783 + return NULL; 784 + } 785 + 786 + skb_reserve(skb, hdroom); 787 + skb_put(skb, xlen); 788 + skb->dev = napi->dev; 789 + } else { 790 + skb = napi_alloc_skb(napi, nvchan->rsc.pktlen); 791 + 792 + if (!skb) 793 + return NULL; 794 + 795 + /* Copy to skb. This copy is needed here since the memory 796 + * pointed by hv_netvsc_packet cannot be deallocated. 797 + */ 798 + for (i = 0; i < nvchan->rsc.cnt; i++) 799 + skb_put_data(skb, nvchan->rsc.data[i], 800 + nvchan->rsc.len[i]); 801 + } 806 802 807 803 skb->protocol = eth_type_trans(skb, net); 808 804 ··· 871 829 struct vmbus_channel *channel = nvchan->channel; 872 830 u16 q_idx = channel->offermsg.offer.sub_channel_index; 873 831 struct sk_buff *skb; 874 - struct netvsc_stats *rx_stats; 832 + struct netvsc_stats *rx_stats = &nvchan->rx_stats; 833 + struct xdp_buff xdp; 834 + u32 act; 875 835 876 836 if (net->reg_state != NETREG_REGISTERED) 877 837 return NVSP_STAT_FAIL; 878 838 839 + act = netvsc_run_xdp(net, nvchan, &xdp); 840 + 841 + if (act != XDP_PASS && act != XDP_TX) { 842 + u64_stats_update_begin(&rx_stats->syncp); 843 + rx_stats->xdp_drop++; 844 + u64_stats_update_end(&rx_stats->syncp); 845 + 846 + return NVSP_STAT_SUCCESS; /* consumed by XDP */ 847 + } 848 + 879 849 /* Allocate a skb - TODO direct I/O to pages? */ 880 - skb = netvsc_alloc_recv_skb(net, nvchan); 850 + skb = netvsc_alloc_recv_skb(net, nvchan, &xdp); 881 851 882 852 if (unlikely(!skb)) { 883 853 ++net_device_ctx->eth_stats.rx_no_memory; ··· 903 849 * on the synthetic device because modifying the VF device 904 850 * statistics will not work correctly. 905 851 */ 906 - rx_stats = &nvchan->rx_stats; 907 852 u64_stats_update_begin(&rx_stats->syncp); 908 853 rx_stats->packets++; 909 854 rx_stats->bytes += nvchan->rsc.pktlen; ··· 912 859 else if (skb->pkt_type == PACKET_MULTICAST) 913 860 ++rx_stats->multicast; 914 861 u64_stats_update_end(&rx_stats->syncp); 862 + 863 + if (act == XDP_TX) { 864 + netvsc_xdp_xmit(skb, net); 865 + return NVSP_STAT_SUCCESS; 866 + } 915 867 916 868 napi_gro_receive(&nvchan->napi, skb); 917 869 return NVSP_STAT_SUCCESS; ··· 944 886 /* Alloc struct netvsc_device_info, and initialize it from either existing 945 887 * struct netvsc_device, or from default values. 946 888 */ 947 - static struct netvsc_device_info *netvsc_devinfo_get 948 - (struct netvsc_device *nvdev) 889 + static 890 + struct netvsc_device_info *netvsc_devinfo_get(struct netvsc_device *nvdev) 949 891 { 950 892 struct netvsc_device_info *dev_info; 893 + struct bpf_prog *prog; 951 894 952 895 dev_info = kzalloc(sizeof(*dev_info), GFP_ATOMIC); 953 896 ··· 956 897 return NULL; 957 898 958 899 if (nvdev) { 900 + ASSERT_RTNL(); 901 + 959 902 dev_info->num_chn = nvdev->num_chn; 960 903 dev_info->send_sections = nvdev->send_section_cnt; 961 904 dev_info->send_section_size = nvdev->send_section_size; ··· 966 905 967 906 memcpy(dev_info->rss_key, nvdev->extension->rss_key, 968 907 NETVSC_HASH_KEYLEN); 908 + 909 + prog = netvsc_xdp_get(nvdev); 910 + if (prog) { 911 + bpf_prog_inc(prog); 912 + dev_info->bprog = prog; 913 + } 969 914 } else { 970 915 dev_info->num_chn = VRSS_CHANNEL_DEFAULT; 971 916 dev_info->send_sections = NETVSC_DEFAULT_TX; ··· 981 914 } 982 915 983 916 return dev_info; 917 + } 918 + 919 + /* Free struct netvsc_device_info */ 920 + static void netvsc_devinfo_put(struct netvsc_device_info *dev_info) 921 + { 922 + if (dev_info->bprog) { 923 + ASSERT_RTNL(); 924 + bpf_prog_put(dev_info->bprog); 925 + } 926 + 927 + kfree(dev_info); 984 928 } 985 929 986 930 static int netvsc_detach(struct net_device *ndev, ··· 1004 926 /* Don't try continuing to try and setup sub channels */ 1005 927 if (cancel_work_sync(&nvdev->subchan_work)) 1006 928 nvdev->num_chn = 1; 929 + 930 + netvsc_xdp_set(ndev, NULL, NULL, nvdev); 1007 931 1008 932 /* If device was up (receiving) then shutdown */ 1009 933 if (netif_running(ndev)) { ··· 1040 960 struct hv_device *hdev = ndev_ctx->device_ctx; 1041 961 struct netvsc_device *nvdev; 1042 962 struct rndis_device *rdev; 1043 - int ret; 963 + struct bpf_prog *prog; 964 + int ret = 0; 1044 965 1045 966 nvdev = rndis_filter_device_add(hdev, dev_info); 1046 967 if (IS_ERR(nvdev)) ··· 1057 976 } 1058 977 } 1059 978 979 + prog = dev_info->bprog; 980 + if (prog) { 981 + ret = netvsc_xdp_set(ndev, prog, NULL, nvdev); 982 + if (ret) 983 + goto err1; 984 + } 985 + 1060 986 /* In any case device is now ready */ 1061 987 netif_device_attach(ndev); 1062 988 ··· 1073 985 if (netif_running(ndev)) { 1074 986 ret = rndis_filter_open(nvdev); 1075 987 if (ret) 1076 - goto err; 988 + goto err2; 1077 989 1078 990 rdev = nvdev->extension; 1079 991 if (!rdev->link_state) ··· 1082 994 1083 995 return 0; 1084 996 1085 - err: 997 + err2: 1086 998 netif_device_detach(ndev); 1087 999 1000 + err1: 1088 1001 rndis_filter_device_remove(hdev, nvdev); 1089 1002 1090 1003 return ret; ··· 1135 1046 } 1136 1047 1137 1048 out: 1138 - kfree(device_info); 1049 + netvsc_devinfo_put(device_info); 1139 1050 return ret; 1140 1051 } 1141 1052 ··· 1242 1153 dev_set_mtu(vf_netdev, orig_mtu); 1243 1154 1244 1155 out: 1245 - kfree(device_info); 1156 + netvsc_devinfo_put(device_info); 1246 1157 return ret; 1247 1158 } 1248 1159 ··· 1467 1378 /* statistics per queue (rx/tx packets/bytes) */ 1468 1379 #define NETVSC_PCPU_STATS_LEN (num_present_cpus() * ARRAY_SIZE(pcpu_stats)) 1469 1380 1470 - /* 4 statistics per queue (rx/tx packets/bytes) */ 1471 - #define NETVSC_QUEUE_STATS_LEN(dev) ((dev)->num_chn * 4) 1381 + /* 5 statistics per queue (rx/tx packets/bytes, rx xdp_drop) */ 1382 + #define NETVSC_QUEUE_STATS_LEN(dev) ((dev)->num_chn * 5) 1472 1383 1473 1384 static int netvsc_get_sset_count(struct net_device *dev, int string_set) 1474 1385 { ··· 1500 1411 struct netvsc_ethtool_pcpu_stats *pcpu_sum; 1501 1412 unsigned int start; 1502 1413 u64 packets, bytes; 1414 + u64 xdp_drop; 1503 1415 int i, j, cpu; 1504 1416 1505 1417 if (!nvdev) ··· 1529 1439 start = u64_stats_fetch_begin_irq(&qstats->syncp); 1530 1440 packets = qstats->packets; 1531 1441 bytes = qstats->bytes; 1442 + xdp_drop = qstats->xdp_drop; 1532 1443 } while (u64_stats_fetch_retry_irq(&qstats->syncp, start)); 1533 1444 data[i++] = packets; 1534 1445 data[i++] = bytes; 1446 + data[i++] = xdp_drop; 1535 1447 } 1536 1448 1537 1449 pcpu_sum = kvmalloc_array(num_possible_cpus(), ··· 1580 1488 sprintf(p, "rx_queue_%u_packets", i); 1581 1489 p += ETH_GSTRING_LEN; 1582 1490 sprintf(p, "rx_queue_%u_bytes", i); 1491 + p += ETH_GSTRING_LEN; 1492 + sprintf(p, "rx_queue_%u_xdp_drop", i); 1583 1493 p += ETH_GSTRING_LEN; 1584 1494 } 1585 1495 ··· 1879 1785 } 1880 1786 1881 1787 out: 1882 - kfree(device_info); 1788 + netvsc_devinfo_put(device_info); 1883 1789 return ret; 1790 + } 1791 + 1792 + static netdev_features_t netvsc_fix_features(struct net_device *ndev, 1793 + netdev_features_t features) 1794 + { 1795 + struct net_device_context *ndevctx = netdev_priv(ndev); 1796 + struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev); 1797 + 1798 + if (!nvdev || nvdev->destroy) 1799 + return features; 1800 + 1801 + if ((features & NETIF_F_LRO) && netvsc_xdp_get(nvdev)) { 1802 + features ^= NETIF_F_LRO; 1803 + netdev_info(ndev, "Skip LRO - unsupported with XDP\n"); 1804 + } 1805 + 1806 + return features; 1884 1807 } 1885 1808 1886 1809 static int netvsc_set_features(struct net_device *ndev, ··· 1986 1875 .ndo_start_xmit = netvsc_start_xmit, 1987 1876 .ndo_change_rx_flags = netvsc_change_rx_flags, 1988 1877 .ndo_set_rx_mode = netvsc_set_rx_mode, 1878 + .ndo_fix_features = netvsc_fix_features, 1989 1879 .ndo_set_features = netvsc_set_features, 1990 1880 .ndo_change_mtu = netvsc_change_mtu, 1991 1881 .ndo_validate_addr = eth_validate_addr, 1992 1882 .ndo_set_mac_address = netvsc_set_mac_addr, 1993 1883 .ndo_select_queue = netvsc_select_queue, 1994 1884 .ndo_get_stats64 = netvsc_get_stats64, 1885 + .ndo_bpf = netvsc_bpf, 1995 1886 }; 1996 1887 1997 1888 /* ··· 2280 2167 { 2281 2168 struct net_device_context *net_device_ctx; 2282 2169 struct netvsc_device *netvsc_dev; 2170 + struct bpf_prog *prog; 2283 2171 struct net_device *ndev; 2284 2172 int ret; 2285 2173 ··· 2325 2211 vf_netdev->wanted_features = ndev->features; 2326 2212 netdev_update_features(vf_netdev); 2327 2213 2214 + prog = netvsc_xdp_get(netvsc_dev); 2215 + netvsc_vf_setxdp(vf_netdev, prog); 2216 + 2328 2217 return NOTIFY_OK; 2329 2218 } 2330 2219 ··· 2368 2251 cancel_delayed_work_sync(&net_device_ctx->vf_takeover); 2369 2252 2370 2253 netdev_info(ndev, "VF unregistering: %s\n", vf_netdev->name); 2254 + 2255 + netvsc_vf_setxdp(vf_netdev, NULL); 2371 2256 2372 2257 netdev_rx_handler_unregister(vf_netdev); 2373 2258 netdev_upper_dev_unlink(vf_netdev, ndev); ··· 2482 2363 list_add(&net_device_ctx->list, &netvsc_dev_list); 2483 2364 rtnl_unlock(); 2484 2365 2485 - kfree(device_info); 2366 + netvsc_devinfo_put(device_info); 2486 2367 return 0; 2487 2368 2488 2369 register_failed: 2489 2370 rtnl_unlock(); 2490 2371 rndis_filter_device_remove(dev, nvdev); 2491 2372 rndis_failed: 2492 - kfree(device_info); 2373 + netvsc_devinfo_put(device_info); 2493 2374 devinfo_failed: 2494 2375 free_percpu(net_device_ctx->vf_stats); 2495 2376 no_stats: ··· 2517 2398 2518 2399 rtnl_lock(); 2519 2400 nvdev = rtnl_dereference(ndev_ctx->nvdev); 2520 - if (nvdev) 2401 + if (nvdev) { 2521 2402 cancel_work_sync(&nvdev->subchan_work); 2403 + netvsc_xdp_set(net, NULL, NULL, nvdev); 2404 + } 2522 2405 2523 2406 /* 2524 2407 * Call to the vsc driver to let it know that the device is being ··· 2593 2472 2594 2473 ret = netvsc_attach(net, device_info); 2595 2474 2596 - rtnl_unlock(); 2597 - 2598 - kfree(device_info); 2475 + netvsc_devinfo_put(device_info); 2599 2476 net_device_ctx->saved_netvsc_dev_info = NULL; 2477 + 2478 + rtnl_unlock(); 2600 2479 2601 2480 return ret; 2602 2481 }
+1 -1
drivers/net/hyperv/rndis_filter.c
··· 235 235 trace_rndis_send(dev->ndev, 0, &req->request_msg); 236 236 237 237 rcu_read_lock_bh(); 238 - ret = netvsc_send(dev->ndev, packet, NULL, pb, NULL); 238 + ret = netvsc_send(dev->ndev, packet, NULL, pb, NULL, false); 239 239 rcu_read_unlock_bh(); 240 240 241 241 return ret;