netvsc fixes and new features
Subsystems (4)
v2 cover netvsc fixes and new features
This series has updates for Hyper-V network driver. The first four patches are just minor fixes.
The next group of patches aims to reduce the driver memory footprint by reducing the size of the per-device receive and send buffers, and the per-channel receive completion queue.
The biggest change is in the last three patches that implement transparent management of SR-IOV VF device. A little more explaination is required.
What does it do?
With the new netvsc VF logic, the Linux hyper-V network virtual driver will directly manage the link to SR-IOV VF device. When VF device is detected (hot plug) it is automatically made a slave device of the netvsc device. The VF device state reflects the state of the netvsc device; i.e. if netvsc is set down, then VF is set down. If netvsc is set up, then VF is brought up.
Packet flow is independent of VF status; all packets are sent and received as if they were associated with the netvsc device. If VF is removed or link is down then the synthetic VMBUS path is used.
What was wrong with using bonding script?
A lot of work went into getting the bonding script to work on all distributions, but it was a major struggle. Linux network devices can be configured many, many ways and there is no one solution from userspace to make it all work. What is really hard is when configuration is attached to synthetic device during boot (eth0) and then the same addresses and firewall rules needs to also work later if doing bonding. The new code gets around all of this.
How does VF work during initialization?
Since all packets are sent and received through the logical netvsc device, initialization is much easier. Just configure the regular netvsc Ethernet device; when/if SR-IOV is enabled it just works. Provisioning and cloud init only need to worry about setting up netvsc device (eth0). If SR-IOV is enabled (even as a later step), the address and rules stay the same.
What devices show up?
Both netvsc and PCI devices are visible in the system. The netvsc device is active and named in usual manner (eth0). The PCI device is visible to Linux and gets renamed by udev to a persistent name (enP2p3s0). The PCI device name is now irrelevant now.
The logica also sets the PCI VF device SLAVE flag on the network device so network tools can see the relationship if they are smart enough to understand how layered devices work.
This is a lot like how I see Windows working.
The VF device is visible in Device Manager, but is not configured.
Is there any performance impact?
There is no visible change in performance. The bonding and netvsc driver both have equivalent steps.
Is it compatible with old bonding script?
It turns out that if you use the old bonding script, then everything still works but in a sub-optimum manner. What happens is that bonding is unable to steal the VF from the netvsc device so it creates a one legged bond. Packet flow then is:
bond0 <--> eth0 <- -> VF (enP2p3s0).
In other words, if you get it wrong it still works, just awkward and slower.
What if I add address or firewall rule onto the VF?
Same problems occur with now as already occur with bonding, bridging, teaming on Linux if user incorrectly does configuration onto an underlying slave device. It will sort of work, packets will come in and out but the Linux kernel gets confused and things like ARP don’t work right. There is no way to block manipulation of the slave device, and I am sure someone will find some special use case where they want it.
Stephen Hemminger (10):
netvsc: fix return value for set_channels
netvsc: fix warnings reported by lockdep
netvsc: don't print pointer value in error message
netvsc: remove unnecessary indirection of page_buffer
netvsc: optimize receive completions
netvsc: signal host if receive ring is emptied
netvsc: allow smaller send/recv buffer size
netvsc: transparent VF management
netvsc: add documentation
netvsc: remove bonding setup script
Documentation/networking/netvsc.txt | 50 ++++ MAINTAINERS | 1 + drivers/net/hyperv/hyperv_net.h | 33 ++- drivers/net/hyperv/netvsc.c | 317 +++++++++++------------- drivers/net/hyperv/netvsc_drv.c | 476 ++++++++++++++++++++++++++++-------- drivers/net/hyperv/rndis_filter.c | 108 ++++---- tools/hv/bondvf.sh | 255 ------------------- 7 files changed, 642 insertions(+), 598 deletions(-) create mode 100644 Documentation/networking/netvsc.txt delete mode 100755 tools/hv/bondvf.sh
Signature · 1 line
2.11.0
PATCH v2 1/10 netvsc: fix return value for set_channels
The error and normal case got swapped.
--- drivers/net/hyperv/netvsc_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/hyperv/netvsc_drv.c +1 -1
@@ -758,8 +758,8 @@ static int netvsc_set_channels(struct net_device *net,if (!IS_ERR (nvdev)) {netif_set_real_num_tx_queues (net, nvdev->num_chn);netif_set_real_num_rx_queues (net, nvdev->num_chn); - ret =PTR_ERR (nvdev); }else { + ret =PTR_ERR (nvdev); device_info.num_chn = orig;rndis_filter_device_add (dev, &device_info); }
Signature · 1 line
2.11.0
PATCH v2 2/10 netvsc: fix warnings reported by lockdep
In reply to Stephen HemmingerThis includes a bunch of fixups for issues reported by lockdep.
* ethtool routines can assume RTNL
* send is done with RCU lock (and BH disable)
* avoid refetching internal device struct (netvsc) instead pass it as a parameter.
--- drivers/net/hyperv/hyperv_net.h | 3 +- drivers/net/hyperv/netvsc.c | 2 +- drivers/net/hyperv/netvsc_drv.c | 15 ++++--- drivers/net/hyperv/rndis_filter.c | 84 +++++++++++++++++++-------------------- 4 files changed, 54 insertions(+), 50 deletions(-)
drivers/net/hyperv/hyperv_net.h +2 -1
@@ -217,7 +217,8 @@ int rndis_filter_receive(struct net_device *ndev,struct vmbus_channel *channel, void *data, u32 buflen); -int rndis_filter_set_device_mac (struct net_device *ndev,char *mac); +int rndis_filter_set_device_mac (struct netvsc_device *ndev, +const char *mac);void netvsc_switch_datapath (struct net_device *nv_dev,bool vf);
drivers/net/hyperv/netvsc.c +1 -1
@@ -832,7 +832,7 @@ int netvsc_send(struct net_device_context *ndev_ctx, struct sk_buff *skb) {struct netvsc_device *net_device - =rcu_dereference_rtnl (ndev_ctx->nvdev); + =rcu_dereference_bh (ndev_ctx->nvdev);struct hv_device *device = ndev_ctx->device_ctx;int ret =0 ;struct netvsc_channel *nvchan;
drivers/net/hyperv/netvsc_drv.c +10 -5
@@ -923,6 +923,8 @@ static void netvsc_get_stats64(struct net_device *net,static int netvsc_set_mac_addr (struct net_device *ndev,void *p) { +struct net_device_context *ndc =netdev_priv (ndev); +struct netvsc_device *nvdev =rtnl_dereference (ndc->nvdev);struct sockaddr *addr = p;char save_adr[ETH_ALEN ];unsigned char save_aatype;
@@ -935,7 +937,10 @@ static int netvsc_set_mac_addr(struct net_device *ndev, void *p)if (err !=0 )return err; - err =rndis_filter_set_device_mac (ndev, addr->sa_data); +if (!nvdev) +return -ENODEV ; + + err =rndis_filter_set_device_mac (nvdev, addr->sa_data);if (err !=0 ) {/* roll back to saved MAC */ memcpy (ndev->dev_addr, save_adr,ETH_ALEN );
@@ -981,7 +986,7 @@ static void netvsc_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *stats, u64 *data) { struct net_device_context *ndc = netdev_priv(dev); -struct netvsc_device *nvdev =rcu_dereference (ndc->nvdev); +struct netvsc_device *nvdev =rtnl_dereference (ndc->nvdev);const void *nds = &ndc->eth_stats;const struct netvsc_stats *qstats;unsigned int start;
@@ -1019,7 +1024,7 @@ static void netvsc_get_ethtool_stats(struct net_device *dev,static void netvsc_get_strings (struct net_device *dev,u32 stringset,u8 *data) {struct net_device_context *ndc =netdev_priv (dev); -struct netvsc_device *nvdev =rcu_dereference (ndc->nvdev); +struct netvsc_device *nvdev =rtnl_dereference (ndc->nvdev);u8 *p = data;int i;
@@ -1077,7 +1082,7 @@ netvsc_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info, u32 *rules) {struct net_device_context *ndc =netdev_priv (dev); -struct netvsc_device *nvdev =rcu_dereference (ndc->nvdev); +struct netvsc_device *nvdev =rtnl_dereference (ndc->nvdev);if (!nvdev)return -ENODEV ;
@@ -1127,7 +1132,7 @@ static int netvsc_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc) {struct net_device_context *ndc =netdev_priv (dev); -struct netvsc_device *ndev =rcu_dereference (ndc->nvdev); +struct netvsc_device *ndev =rtnl_dereference (ndc->nvdev);struct rndis_device *rndis_dev;int i;
drivers/net/hyperv/rndis_filter.c +41 -43
221 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v2 3/10 netvsc: don't print pointer value in error message
In reply to Stephen HemmingerUsing %p to print pointer to packet meta-data doesn't give any good info, and exposes kernel memory offsets.
--- drivers/net/hyperv/netvsc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/hyperv/netvsc.c +4 -2
@@ -805,8 +805,10 @@ static inline int netvsc_send_pkt( ret = -ENOSPC ; } }else { -netdev_err (ndev,"Unable to send packet %p ret %d\n" , - packet, ret); +netdev_err (ndev, +"Unable to send packet pages %u len %u, ret %d\n" , + packet->page_buf_cnt, packet->total_data_buflen, + ret); }return ret;
Signature · 1 line
2.11.0
PATCH v2 4/10 netvsc: remove unnecessary indirection of page_buffer
In reply to Stephen HemmingerThe internal API was passing struct hv_page_buffer ** when only simple struct hv_page_buffer * was necessary for passing an array.
--- drivers/net/hyperv/hyperv_net.h | 2 +- drivers/net/hyperv/netvsc.c | 21 ++++++++++----------- drivers/net/hyperv/netvsc_drv.c | 10 ++++------ drivers/net/hyperv/rndis_filter.c | 4 ++-- 4 files changed, 17 insertions(+), 20 deletions(-)
drivers/net/hyperv/hyperv_net.h +1 -1
@@ -190,7 +190,7 @@ void netvsc_device_remove(struct hv_device *device);int netvsc_send (struct net_device_context *ndc,struct hv_netvsc_packet *packet,struct rndis_message *rndis_msg, -struct hv_page_buffer **page_buffer, +struct hv_page_buffer *page_buffer,struct sk_buff *skb);void netvsc_linkstatus_callback (struct hv_device *device_obj,struct rndis_message *resp);
drivers/net/hyperv/netvsc.c +10 -11
@@ -697,7 +697,7 @@ static u32 netvsc_copy_to_send_buf(struct netvsc_device *net_device,u32 pend_size, struct hv_netvsc_packet *packet, struct rndis_message *rndis_msg, - struct hv_page_buffer **pb, + struct hv_page_buffer *pb, struct sk_buff *skb) { char *start = net_device->send_buf;
@@ -718,9 +718,9 @@ static u32 netvsc_copy_to_send_buf(struct netvsc_device *net_device, }for (i =0 ; i < page_count; i++) { -char *src =phys_to_virt ((*pb)[i].pfn <<PAGE_SHIFT ); -u32 offset = (*pb)[i].offset; -u32 len = (*pb)[i].len; +char *src =phys_to_virt (pb[i].pfn <<PAGE_SHIFT ); +u32 offset = pb[i].offset; +u32 len = pb[i].len;memcpy (dest, (src + offset), len); msg_size += len;
@@ -739,7 +739,7 @@ static inline int netvsc_send_pkt(struct hv_device *device, struct hv_netvsc_packet *packet, struct netvsc_device *net_device, - struct hv_page_buffer **pb, + struct hv_page_buffer *pb, struct sk_buff *skb) { struct nvsp_message nvmsg;
@@ -750,7 +750,6 @@ static inline int netvsc_send_pkt(struct netdev_queue *txq =netdev_get_tx_queue (ndev, packet->q_idx);u64 req_id;int ret; -struct hv_page_buffer *pgbuf;u32 ring_avail =hv_ringbuf_avail_percent (&out_channel->outbound); nvmsg.hdr.msg_type =NVSP_MSG1_TYPE_SEND_RNDIS_PKT ;
@@ -776,11 +775,11 @@ static inline int netvsc_send_pkt(return -ENODEV ;if (packet->page_buf_cnt) { - pgbuf = packet->cp_partial ? (*pb) + - packet->rmsg_pgcnt : (*pb); +if (packet->cp_partial) + pb += packet->rmsg_pgcnt; + ret = vmbus_sendpacket_pagebuffer_ctl(out_channel, - pgbuf, - packet->page_buf_cnt, + pb, packet->page_buf_cnt, &nvmsg, sizeof(struct nvsp_message), req_id,
@@ -830,7 +829,7 @@ static inline void move_pkt_msd(struct hv_netvsc_packet **msd_send,int netvsc_send (struct net_device_context *ndev_ctx,struct hv_netvsc_packet *packet,struct rndis_message *rndis_msg, -struct hv_page_buffer **pb, +struct hv_page_buffer *pb,struct sk_buff *skb) {struct netvsc_device *net_device
drivers/net/hyperv/netvsc_drv.c +4 -6
@@ -282,9 +282,8 @@ static u32 fill_pg_buf(struct page *page, u32 offset, u32 len,static u32 init_page_array (void *hdr,u32 len,struct sk_buff *skb,struct hv_netvsc_packet *packet, -struct hv_page_buffer **page_buf) +struct hv_page_buffer *pb) { -struct hv_page_buffer *pb = *page_buf;u32 slots_used =0 ;char *data = skb->data;int frags =skb_shinfo (skb)->nr_frags;
@@ -359,8 +358,7 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)u32 rndis_msg_size;struct rndis_per_packet_info *ppi;u32 hash; -struct hv_page_buffer page_buf[MAX_PAGE_BUFFER_COUNT ]; -struct hv_page_buffer *pb = page_buf; +struct hv_page_buffer pb[MAX_PAGE_BUFFER_COUNT ];/* We can only transmit MAX_PAGE_BUFFER_COUNT number * of pages in a single packet. If skb is scattered around
@@ -503,12 +501,12 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) rndis_msg->msg_len += rndis_msg_size; packet->total_data_buflen = rndis_msg->msg_len; packet->page_buf_cnt =init_page_array (rndis_msg, rndis_msg_size, - skb, packet, &pb); + skb, packet, pb);/* timestamp packet in software */ skb_tx_timestamp (skb); - ret =netvsc_send (net_device_ctx, packet, rndis_msg, &pb, skb); + ret =netvsc_send (net_device_ctx, packet, rndis_msg, pb, skb);if (likely (ret ==0 ))return NETDEV_TX_OK ;
drivers/net/hyperv/rndis_filter.c +2 -2
@@ -214,11 +214,11 @@ static void dump_rndis_message(struct hv_device *hv_dev,static int rndis_filter_send_request (struct rndis_device *dev,struct rndis_request *req) { -int ret;struct hv_netvsc_packet *packet;struct hv_page_buffer page_buf[2 ];struct hv_page_buffer *pb = page_buf;struct net_device_context *net_device_ctx =netdev_priv (dev->ndev); +int ret;/* Setup the packet to send it */ packet = &req->pkt;
@@ -245,7 +245,7 @@ static int rndis_filter_send_request(struct rndis_device *dev, }rcu_read_lock_bh (); - ret =netvsc_send (net_device_ctx, packet,NULL , &pb,NULL ); + ret =netvsc_send (net_device_ctx, packet,NULL , pb,NULL );rcu_read_unlock_bh ();return ret;
Signature · 1 line
2.11.0
PATCH v2 5/10 netvsc: optimize receive completions
In reply to Stephen HemmingerOptimize how receive completion ring are managed.
* Allocate only as many slots as needed for all buffers from host
* Allocate before setting up sub channel for better error detection
* Don't need to keep copy of initial receive section message
* Precompute the watermark for when receive flushing is needed
* Replace division with conditional test
* Replace atomic per-device variable with per-channel check.
* Handle corner case where receive completion send
fails if ring buffer to host is full.
--- drivers/net/hyperv/hyperv_net.h | 14 +- drivers/net/hyperv/netvsc.c | 267 ++++++++++++++++---------------------- drivers/net/hyperv/rndis_filter.c | 20 +-- 3 files changed, 126 insertions(+), 175 deletions(-)
drivers/net/hyperv/hyperv_net.h +5 -9
@@ -186,6 +186,7 @@ struct net_device_context;struct netvsc_device *netvsc_device_add (struct hv_device *device,const struct netvsc_device_info *info); +int netvsc_alloc_recv_comp_ring (struct netvsc_device *net_device,u32 q_idx);void netvsc_device_remove (struct hv_device *device); int netvsc_send(struct net_device_context *ndc, struct hv_netvsc_packet *packet,
@@ -657,13 +658,10 @@ struct recv_comp_data {u32 status; }; -/* Netvsc Receive Slots Max */ -#define NETVSC_RECVSLOT_MAX (NETVSC_RECEIVE_BUFFER_SIZE / ETH_DATA_LEN + 1) -struct multi_recv_comp { -void *buf;/* queued receive completions */ -u32 first;/* first data entry */ -u32 next;/* next entry for writing */ +struct recv_comp_data *slots; +u32 first;/* first data entry */ +u32 next;/* next entry for writing */ };struct netvsc_stats {
@@ -750,7 +748,7 @@ struct netvsc_device {u32 recv_buf_size;u32 recv_buf_gpadl_handle;u32 recv_section_cnt; -struct nvsp_1_receive_buffer_section *recv_section; +u32 recv_completion_cnt;/* Send buffer allocated by us */ void *send_buf;
@@ -778,8 +776,6 @@ struct netvsc_device {u32 max_pkt;/* max number of pkt in one send, e.g. 8 */ u32 pkt_align;/* alignment bytes, e.g. 8 */ -atomic_t num_outstanding_recvs; -atomic_t open_cnt;struct netvsc_channel chan_table[VRSS_CHANNEL_MAX ];
drivers/net/hyperv/netvsc.c +109 -158
377 lines not on this page · raw message
drivers/net/hyperv/rndis_filter.c +12 -8
@@ -928,12 +928,12 @@ static bool netvsc_device_idle(const struct netvsc_device *nvdev) {int i; -if (atomic_read (&nvdev->num_outstanding_recvs) >0 ) -return false; -for (i =0 ; i < nvdev->num_chn; i++) {const struct netvsc_channel *nvchan = &nvdev->chan_table[i]; +if (nvchan->mrc.first != nvchan->mrc.next) +return false; +if (atomic_read (&nvchan->queue_sends) >0 )return false; }
@@ -1031,11 +1031,6 @@ static void netvsc_sc_open(struct vmbus_channel *new_sc)return ; nvchan = nvscdev->chan_table + chn_index; - nvchan->mrc.buf - =vzalloc (NETVSC_RECVSLOT_MAX *sizeof (struct recv_comp_data )); - -if (!nvchan->mrc.buf) -return ;/* Because the device uses NAPI, all the interrupt batching and * control is done via Net softirq, not the channel handling
@@ -1225,6 +1220,15 @@ struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,if (num_rss_qs ==0 )return net_device; +for (i =1 ; i < net_device->num_chn; i++) { + ret =netvsc_alloc_recv_comp_ring (net_device, i); +if (ret) { +while (--i !=0 ) +vfree (net_device->chan_table[i].mrc.slots); + goto out; + } + } +refcount_set (&net_device->sc_offered, num_rss_qs);vmbus_set_sc_create_callback (dev->channel, netvsc_sc_open);
Signature · 1 line
2.11.0
PATCH v2 6/10 netvsc: signal host if receive ring is emptied
In reply to Stephen HemmingerLatency improvement related to NAPI conversion. If all packets are processed from receive ring then need to signal host.
--- drivers/net/hyperv/netvsc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/net/hyperv/netvsc.c +8 -3
@@ -1195,10 +1195,15 @@ int netvsc_poll(struct napi_struct *napi, int budget) nvchan->desc =hv_pkt_iter_next (channel, nvchan->desc); } -/* If send of pending receive completions suceeded -* and did not exhaust NAPI budget +/* if ring is empty, signal host */ +if (!nvchan->desc) +hv_pkt_iter_close (channel); + +/* If send of pending receive completions suceeded +* and did not exhaust NAPI budget this time * and not doing busy poll -* then reschedule if more data has arrived from host +* then re-enable host interrupts +* and reschedule if ring is not empty. */ if (send_recv_completions(nvchan) == 0 && work_done < budget &&
Signature · 1 line
2.11.0
PATCH v2 7/10 netvsc: allow smaller send/recv buffer size
In reply to Stephen HemmingerThe default value of send and receive buffer area for host DMA is much larger than it needs to be. Experimentation shows that 4M receive and 1M send is sufficient.
Make the size a module parameter so that it can be adjusted as needed for testing or special needs.
--- drivers/net/hyperv/hyperv_net.h | 2 ++ drivers/net/hyperv/netvsc.c | 18 ++++++++++++------ drivers/net/hyperv/netvsc_drv.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 7 deletions(-)
drivers/net/hyperv/hyperv_net.h +2 -0
@@ -148,6 +148,8 @@ struct netvsc_device_info {unsigned char mac_adr[ETH_ALEN ];int ring_size;u32 num_chn; +u32 recv_buf_size; +u32 send_buf_size; };enum rndis_device_state {
drivers/net/hyperv/netvsc.c +12 -6
@@ -482,14 +482,16 @@ static int negotiate_nvsp_ver(struct hv_device *device, }static int netvsc_connect_vsp (struct hv_device *device, -struct netvsc_device *net_device) +struct netvsc_device *net_device, +const struct netvsc_device_info *device_info) {const u32 ver_list[] = {NVSP_PROTOCOL_VERSION_1 ,NVSP_PROTOCOL_VERSION_2 ,NVSP_PROTOCOL_VERSION_4 ,NVSP_PROTOCOL_VERSION_5 };struct nvsp_message *init_packet; -int ndis_version, i, ret; +u32 max_recv_buf_size, ndis_version; +int i, ret; init_packet = &net_device->channel_init_pkt;
@@ -534,10 +536,14 @@ static int netvsc_connect_vsp(struct hv_device *device,/* Post the big receive buffer to NetVSP */ if (net_device->nvsp_version <=NVSP_PROTOCOL_VERSION_2 ) - net_device->recv_buf_size =NETVSC_RECEIVE_BUFFER_SIZE_LEGACY ; + max_recv_buf_size =NETVSC_RECEIVE_BUFFER_SIZE_LEGACY ;else - net_device->recv_buf_size =NETVSC_RECEIVE_BUFFER_SIZE ; - net_device->send_buf_size =NETVSC_SEND_BUFFER_SIZE ; + max_recv_buf_size =NETVSC_RECEIVE_BUFFER_SIZE ; + + net_device->recv_buf_size =min (max_recv_buf_size, + device_info->recv_buf_size); + net_device->send_buf_size =min_t (u32,NETVSC_SEND_BUFFER_SIZE , + device_info->send_buf_size); ret =netvsc_init_buf (device, net_device);
@@ -1302,7 +1308,7 @@ struct netvsc_device *netvsc_device_add(struct hv_device *device,rcu_assign_pointer (net_device_ctx->nvdev, net_device);/* Connect with the NetVsp */ - ret =netvsc_connect_vsp (device, net_device); + ret =netvsc_connect_vsp (device, net_device, device_info);if (ret !=0 ) {netdev_err (ndev,"unable to connect to NetVSP - %d\n" , ret);
drivers/net/hyperv/netvsc_drv.c +30 -1
@@ -44,13 +44,23 @@#include "hyperv_net.h" -#define RING_SIZE_MIN 64 +#define RING_SIZE_MIN 64 +#define RECV_BUFFER_MIN 16 +#define SEND_BUFFER_MIN 4#define LINKCHANGE_INT (2 * HZ)static int ring_size =128 ;module_param (ring_size, int,S_IRUGO );MODULE_PARM_DESC (ring_size,"Ring buffer size (# of pages)" ); +static unsigned int recv_buffer_size = (4 *1024 *1024 ) /PAGE_SIZE ; +module_param (recv_buffer_size, uint,S_IRUGO ); +MODULE_PARM_DESC (recv_buffer_size,"Receive buffer size (# of pages)" ); + +static unsigned int send_buffer_size = (1024 *1024 ) /PAGE_SIZE ; +module_param (send_buffer_size, uint,S_IRUGO ); +MODULE_PARM_DESC (send_buffer_size,"Send buffer size (# of pages)" ); +static const u32 default_msg =NETIF_MSG_DRV |NETIF_MSG_PROBE |NETIF_MSG_LINK |NETIF_MSG_IFUP | NETIF_MSG_IFDOWN | NETIF_MSG_RX_ERR |
@@ -751,6 +761,8 @@ static int netvsc_set_channels(struct net_device *net,memset (&device_info,0 ,sizeof (device_info)); device_info.num_chn = count; device_info.ring_size = ring_size; + device_info.send_buf_size = nvdev->send_buf_size; + device_info.recv_buf_size = nvdev->recv_buf_size; nvdev =rndis_filter_device_add (dev, &device_info);if (!IS_ERR (nvdev)) {
@@ -848,6 +860,8 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)memset (&device_info,0 ,sizeof (device_info)); device_info.ring_size = ring_size; device_info.num_chn = nvdev->num_chn; + device_info.send_buf_size = nvdev->send_buf_size; + device_info.recv_buf_size = nvdev->recv_buf_size;rndis_filter_device_remove (hdev, nvdev);
@@ -1518,6 +1532,8 @@ static int netvsc_probe(struct hv_device *dev,memset (&device_info,0 ,sizeof (device_info)); device_info.ring_size = ring_size; device_info.num_chn =VRSS_CHANNEL_DEFAULT ; + device_info.send_buf_size = send_buffer_size *PAGE_SIZE ; + device_info.recv_buf_size = recv_buffer_size *PAGE_SIZE ; nvdev =rndis_filter_device_add (dev, &device_info);if (IS_ERR (nvdev)) {
@@ -1669,6 +1685,19 @@ static int __init netvsc_drv_init(void)pr_info ("Increased ring_size to %d (min allowed)\n" , ring_size); } + +if (recv_buffer_size <RECV_BUFFER_MIN ) { + recv_buffer_size =RECV_BUFFER_MIN ; +pr_notice ("Increased receive buffer size to %u (min allowed)\n" , + recv_buffer_size); + } + +if (send_buffer_size <SEND_BUFFER_MIN ) { + send_buffer_size =SEND_BUFFER_MIN ; +pr_notice ("Increased receive buffer size to %u (min allowed)\n" , + send_buffer_size); + } + ret =vmbus_driver_register (&netvsc_drv);if (ret)
Signature · 1 line
2.11.0
PATCH v2 8/10 netvsc: transparent VF management
In reply to Stephen HemmingerThis patch implements transparent fail over from synthetic NIC to SR-IOV virtual function NIC in Hyper-V environment. It is a better alternative to using bonding as is done now. Instead, the receive and transmit fail over is done internally inside the driver.
Using bonding driver has lots of issues because it depends on the script being run early enough in the boot process and with sufficient information to make the association. This patch moves all that functionality into the kernel.
--- drivers/net/hyperv/hyperv_net.h | 12 ++ drivers/net/hyperv/netvsc_drv.c | 418 +++++++++++++++++++++++++++++++--------- 2 files changed, 341 insertions(+), 89 deletions(-)
drivers/net/hyperv/hyperv_net.h +12 -0
@@ -682,6 +682,15 @@ struct netvsc_ethtool_stats {unsigned long tx_busy; }; +struct netvsc_vf_pcpu_stats { +u64 rx_packets; +u64 rx_bytes; +u64 tx_packets; +u64 tx_bytes; +struct u64_stats_sync syncp; +u32 tx_dropped; +}; +struct netvsc_reconfig {struct list_head list;u32 event;
@@ -715,6 +724,9 @@ struct net_device_context {/* State to manage the associated VF interface. */ struct net_device __rcu *vf_netdev; +struct netvsc_vf_pcpu_stats __percpu *vf_stats; +struct work_struct vf_takeover; +struct work_struct vf_notify;/* 1: allocated, serial number is valid. 0: not allocated */ u32 vf_alloc;
drivers/net/hyperv/netvsc_drv.c +329 -89
674 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v2 9/10 netvsc: add documentation
In reply to Stephen HemmingerAdd some background documentation on netvsc device options and limitations.
--- Documentation/networking/netvsc.txt | 50 +++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 51 insertions(+) create mode 100644 Documentation/networking/netvsc.txt
Documentation/networking/netvsc.txt new file +50 -0
@@ -0,0 +1,50 @@ +Hyper-V network driver +====================== + +Compatibility +============= + +This driver is compatible and tested on Windows Server 2012 R2, 2016 and +Windows 10. + +Features +======== + + Checksum offload + ---------------- + The netvsc driver supports checksum offload as long as the + Hyper-V host version does. Windows Server 2016 and Azure + support checksum offload for TCP and UDP for both IPv4 and + IPv6. Windows Server 2012 only supports checksum offload for TCP. + + Receive Side Scaling + -------------------- + Hyper-V supports receive side scaling. For TCP, packets are + distributed among available queues based on IP address and port + number. Current versions of Hyper-V host, only distribute UDP + packets based on the IP source and destination address. + The port number is not used as part of the hash value for UDP. + Fragmented IP packets are not distributed between queues; + all fragmented packets arrive on the first channel. + + Generic Receive Offload, aka GRO + -------------------------------- + The driver supports GRO and it is enabled by default. GRO coalesces + like packets and significantly reduces CPU usage under heavy Rx + load. + + SR-IOV support + -------------- + Hyper-V supports SR-IOV as a hardware acceleration option. If SR-IOV + is enabled in both the vSwitch and the guest configuration, then the + Virtual Function (VF) device is passed to the guest as a PCI + device. In this case, both a synthetic (netvsc) and VF device are + visible in the guest OS and both NIC's have the same MAC address. + + The VF is enslaved by netvsc device. The netvsc driver will transparently + switch the data path to the VF when it is available and up. + Network state (addresses, firewall, etc) should be applied only to the + netvsc device; the slave device should not be accessed directly in + most cases. The exceptions are if some special queue discipline or + flow direction is desired, these should be applied directly to the + VF slave device.
MAINTAINERS +1 -0
@@ -6294,6 +6294,7 @@ M: Haiyang Zhang <[email protected]> M: Stephen Hemminger <[email protected]> L: [email protected] S: Maintained +F: Documentation/networking/netvsc.txt F: arch/x86/include/asm/mshyperv.h F: arch/x86/include/uapi/asm/hyperv.h F: arch/x86/kernel/cpu/mshyperv.c
Signature · 1 line
2.11.0
PATCH v2 10/10 netvsc: remove bonding setup script
In reply to Stephen HemmingerNo longer needed, now all managed by transparent VF logic.
--- tools/hv/bondvf.sh | 255 ----------------------------------------------------- 1 file changed, 255 deletions(-) delete mode 100755 tools/hv/bondvf.sh
tools/hv/bondvf.sh deleted +0 -255
@@ -1,255 +0,0 @@ -#!/bin/bash - -# This example script creates bonding network devices based on synthetic NIC -# (the virtual network adapter usually provided by Hyper-V) and the matching -# VF NIC (SRIOV virtual function). So the synthetic NIC and VF NIC can -# function as one network device, and fail over to the synthetic NIC if VF is -# down. -# -# Usage: -# - After configured vSwitch and vNIC with SRIOV, start Linux virtual -# machine (VM) -# - Run this scripts on the VM. It will create configuration files in -# distro specific directory. -# - Reboot the VM, so that the bonding config are enabled. -# -# The config files are DHCP by default. You may edit them if you need to change -# to Static IP or change other settings. -# - -sysdir=/sys/class/net -netvsc_cls={f8615163-df3e-46c5-913f-f2d2f965ed0e} -bondcnt=0 - -# Detect Distro -if [ -f /etc/redhat-release ]; -then - cfgdir=/etc/sysconfig/network-scripts - distro=redhat -elif grep -q 'Ubuntu' /etc/issue -then - cfgdir=/etc/network - distro=ubuntu -elif grep -q 'SUSE' /etc/issue -then - cfgdir=/etc/sysconfig/network - distro=suse -else - echo "Unsupported Distro" - exit 1 -fi - -echo Detected Distro: $distro, or compatible - -# Get a list of ethernet names -list_eth=(`cd $sysdir && ls -d */ | cut -d/ -f1 | grep -v bond`) -eth_cnt=${#list_eth[@]} - -echo List of net devices: - -# Get the MAC addresses -for (( i=0; i < $eth_cnt; i++ )) -do - list_mac[$i]=`cat $sysdir/${list_eth[$i]}/address` - echo ${list_eth[$i]}, ${list_mac[$i]} -done - -# Find NIC with matching MAC -for (( i=0; i < $eth_cnt-1; i++ )) -do - for (( j=i+1; j < $eth_cnt; j++ )) - do - if [ "${list_mac[$i]}" = "${list_mac[$j]}" ] - then - list_match[$i]=${list_eth[$j]} - break - fi - done -done - -function create_eth_cfg_redhat { - local fn=$cfgdir/ifcfg-$1 - - rm -f $fn - echo DEVICE=$1 >>$fn - echo TYPE=Ethernet >>$fn - echo BOOTPROTO=none >>$fn - echo UUID=`uuidgen` >>$fn - echo ONBOOT=yes >>$fn - echo PEERDNS=yes >>$fn - echo IPV6INIT=yes >>$fn - echo MASTER=$2 >>$fn - echo SLAVE=yes >>$fn -} - -function create_eth_cfg_pri_redhat { - create_eth_cfg_redhat $1 $2 -} - -function create_bond_cfg_redhat { - local fn=$cfgdir/ifcfg-$1 - - rm -f $fn - echo DEVICE=$1 >>$fn - echo TYPE=Bond >>$fn - echo BOOTPROTO=dhcp >>$fn - echo UUID=`uuidgen` >>$fn - echo ONBOOT=yes >>$fn - echo PEERDNS=yes >>$fn - echo IPV6INIT=yes >>$fn - echo BONDING_MASTER=yes >>$fn - echo BONDING_OPTS=\"mode=active-backup miimon=100 primary=$2\" >>$fn -} - -function del_eth_cfg_ubuntu { - local mainfn=$cfgdir/interfaces - local fnlist=( $mainfn ) - - local dirlist=(`awk '/^[ \t]*source/{print $2}' $mainfn`) - - local i - for i in "${dirlist[@]}" - do - fnlist+=(`ls $i 2>/dev/null`) - done - - local tmpfl=$(mktemp) - - local nic_start='^[ \t]*(auto|iface|mapping|allow-.*)[ \t]+'$1 - local nic_end='^[ \t]*(auto|iface|mapping|allow-.*|source)' - - local fn - for fn in "${fnlist[@]}" - do - awk "/$nic_end/{x=0} x{next} /$nic_start/{x=1;next} 1" \ - $fn >$tmpfl - - cp $tmpfl $fn - done - - rm $tmpfl -} - -function create_eth_cfg_ubuntu { - local fn=$cfgdir/interfaces - - del_eth_cfg_ubuntu $1 - echo $'\n'auto $1 >>$fn - echo iface $1 inet manual >>$fn - echo bond-master $2 >>$fn -} - -function create_eth_cfg_pri_ubuntu { - local fn=$cfgdir/interfaces - - del_eth_cfg_ubuntu $1 - echo $'\n'allow-hotplug $1 >>$fn - echo iface $1 inet manual >>$fn - echo bond-master $2 >>$fn - echo bond-primary $1 >>$fn -} - -function create_bond_cfg_ubuntu { - local fn=$cfgdir/interfaces - - del_eth_cfg_ubuntu $1 - - echo $'\n'auto $1 >>$fn - echo iface $1 inet dhcp >>$fn - echo bond-mode active-backup >>$fn - echo bond-miimon 100 >>$fn - echo bond-slaves none >>$fn -} - -function create_eth_cfg_suse { - local fn=$cfgdir/ifcfg-$1 - - rm -f $fn - echo BOOTPROTO=none >>$fn - echo STARTMODE=auto >>$fn -} - -function create_eth_cfg_pri_suse { - local fn=$cfgdir/ifcfg-$1 - - rm -f $fn - echo BOOTPROTO=none >>$fn - echo STARTMODE=hotplug >>$fn -} - -function create_bond_cfg_suse { - local fn=$cfgdir/ifcfg-$1 - - rm -f $fn - echo BOOTPROTO=dhcp >>$fn - echo STARTMODE=auto >>$fn - echo BONDING_MASTER=yes >>$fn - echo BONDING_SLAVE_0=$2 >>$fn - echo BONDING_SLAVE_1=$3 >>$fn - echo BONDING_MODULE_OPTS=\'mode=active-backup miimon=100 primary=$2\' >>$fn -} - -function create_bond { - local bondname=bond$bondcnt - local primary - local secondary - - local class_id1=`cat $sysdir/$1/device/class_id 2>/dev/null` - local class_id2=`cat $sysdir/$2/device/class_id 2>/dev/null` - - if [ "$class_id1" = "$netvsc_cls" ] - then - primary=$2 - secondary=$1 - elif [ "$class_id2" = "$netvsc_cls" ] - then - primary=$1 - secondary=$2 - else - return 0 - fi - - echo $'\nBond name:' $bondname - - if [ $distro == ubuntu ] - then - local mainfn=$cfgdir/interfaces - local s="^[ \t]*(auto|iface|mapping|allow-.*)[ \t]+${bondname}" - - grep -E "$s" $mainfn - if [ $? -eq 0 ] - then - echo "WARNING: ${bondname} has been configured already" - return - fi - elif [ $distro == redhat ] || [ $distro == suse ] - then - local fn=$cfgdir/ifcfg-$bondname - if [ -f $fn ] - then - echo "WARNING: ${bondname} has been configured already" - return - fi - else - echo "Unsupported Distro: ${distro}" - return - fi - - echo configuring $primary - create_eth_cfg_pri_$distro $primary $bondname - - echo configuring $secondary - create_eth_cfg_$distro $secondary $bondname - - echo creating: $bondname with primary slave: $primary - create_bond_cfg_$distro $bondname $primary $secondary -} - -for (( i=0; i < $eth_cnt-1; i++ )) -do - if [ -n "${list_match[$i]}" ] - then - create_bond ${list_eth[$i]} ${list_match[$i]} - let bondcnt=bondcnt+1 - fi -done
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Stephen Hemminger <[email protected]>
Date: Wed, 26 Jul 2017 16:40:19 -0700
Quoted 3 lines
The next group of patches aims to reduce the driver memory footprint by reducing the size of the per-device receive and send buffers, and the per-channel receive completion queue.
Sorry Stephen, I have to draw the line with those module parameters.
Search out alternate mechanism which can work at run time, such as using devlink or similar.
Don't tell me it's "impossible" or "hard", simply do.
Thanks.