netvsc: minor fixes and optimization
Subsystems (3)
PATCH v3 1/7 netvsc: fix return value for set_channels
In reply to Stephen HemmingerThe 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 v3 7/7 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
v3 cover netvsc: minor fixes and optimization
This is a subset of earlier submission with a few more fixes found during testing. The are two small optimizations, one is to better manage the receive completion ring, and the other is removing one unneeded level of indirection.
Will submit the improved VF support and buffer sizing in a later patch so they get more review.
Stephen Hemminger (7):
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: fix error unwind on device setup failure
netvsc: signal host if receive ring is emptied
drivers/net/hyperv/hyperv_net.h | 19 +-- drivers/net/hyperv/netvsc.c | 302 ++++++++++++++++---------------------- drivers/net/hyperv/netvsc_drv.c | 27 ++-- drivers/net/hyperv/rndis_filter.c | 108 +++++++------- 4 files changed, 208 insertions(+), 248 deletions(-)
Signature · 1 line
2.11.0
PATCH v3 2/7 netvsc: fix warnings reported by lockdep
This 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 v3 3/7 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 v3 4/7 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 v3 5/7 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 v3 6/7 netvsc: fix error unwind on device setup failure
In reply to Stephen HemmingerIf setting receive buffer fails, the error unwind would cause kernel panic because it was not correctly doing RCU and NAPI unwind. RCU'd pointer needs to be reset to NULL, and NAPI needs to be disabled not deleted.
--- drivers/net/hyperv/netvsc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/hyperv/netvsc.c +2 -1
@@ -1307,7 +1307,8 @@ struct netvsc_device *netvsc_device_add(struct hv_device *device,return net_device; close: -netif_napi_del (&net_device->chan_table[0 ].napi); +RCU_INIT_POINTER (net_device_ctx->nvdev,NULL ); +napi_disable (&net_device->chan_table[0 ].napi);/* Now, we can close the channel safely */ vmbus_close (device->channel);
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Stephen Hemminger <[email protected]>
Date: Fri, 28 Jul 2017 08:59:40 -0700
Quoted 7 lines
This is a subset of earlier submission with a few more fixes found during testing. The are two small optimizations, one is to better manage the receive completion ring, and the other is removing one unneeded level of indirection.
Will submit the improved VF support and buffer sizing in a later patch so they get more review.
Series applied, thanks Stephen.
Re: [PATCH net-next v3 2/7] netvsc: fix warnings reported by lockdep
In reply to Stephen HemmingerQuoted 8 lines · Stephen Hemminger
This 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.Signed-off-by Stephen Hemminger <[email protected]>
The subject and the commit message are inconsistent — is this fixing *warnings* (i.e. shut up a false positive), or is it fixing *issues*? It looks like it's actually fixing issues, not just warnings?
It's really useful to get that right.
FWIW the reason I'm looking in my netdev@ folder for lockdep warning fixes is because I was trying to confirm whether the commit message in
https://patchwork.kernel.org/patch/4372391/ is actually telling the truth or not — in that case I think it *is* just a false positive being shut up (and thus it's OK to say "fix warning"), not really fixing a true issue.
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
RE: [PATCH net-next v3 2/7] netvsc: fix warnings reported by lockdep
These are false positives; lockdep is complaining about things that are safe It is just that annotations were missing or incorrect.
-----Original Message-----
From: David Woodhouse [mailto:[email protected]]
Sent: Thursday, August 24, 2017 1:37 AM
To: Stephen Hemminger <[email protected]>; KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Stephen Hemminger <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH net-next v3 2/7] netvsc: fix warnings reported by lockdep
Quoted 8 lines · Stephen Hemminger
This 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.Signed-off-by Stephen Hemminger <[email protected]>
The subject and the commit message are inconsistent — is this fixing *warnings* (i.e. shut up a false positive), or is it fixing *issues*? It looks like it's actually fixing issues, not just warnings?
It's really useful to get that right.
FWIW the reason I'm looking in my netdev@ folder for lockdep warning fixes is because I was trying to confirm whether the commit message in
https://patchwork.kernel.org/patch/4372391/ is actually telling the truth or not — in that case I think it *is* just a false positive being shut up (and thus it's OK to say "fix warning"), not really fixing a true issue.