hv_netvsc: Eliminate the additional head room
Subsystems (3)
cover hv_netvsc: Eliminate the additional head room
In an attempt to avoid having to allocate memory on the send path, the netvsc driver was requesting additional head room so that both rndis header and the netvsc packet (the state that had to persist) could be placed in the skb. Since the amount of head room requested was exceeding the default head room as set in LL_MAX_HEADER, we were forcing a reallocation of skb.
With this patch-set, I have reduced the size of the netvsc packet to 40 bytes and with this reduction we don't need to ask for any additional headroom. We place the rndis header in the skb head room and we place the netvsc packet in control buffer area in the skb.
K. Y. Srinivasan (8):
hv_netvsc: Resize some of the variables in hv_netvsc_packet
hv_netvsc: Rearrange the hv_negtvsc_packet to be space efficient
hv_netvsc: Eliminate the channel field in hv_netvsc_packet structure
hv_netvsc: Eliminate rndis_msg pointer from hv_netvsc_packet
structure
hv_netvsc: Eliminatte the data field from struct hv_netvsc_packet
hv_netvsc: Eliminate send_completion from struct hv_netvsc_packet
hv_netvsc: Eliminate send_completion_ctx from struct hv_netvsc_packet
hv_netvsc: Don't ask for additional head room in the skb
Vitaly Kuznetsov (2):
hv_netvsc: move subchannel existence check to netvsc_select_queue()
hv_netvsc: remove locking in netvsc_send()
drivers/net/hyperv/hyperv_net.h | 48 +++++++++++++++++------------------- drivers/net/hyperv/netvsc.c | 42 ++++++++++++-------------------- drivers/net/hyperv/netvsc_drv.c | 47 +++++++++++++++-------------------- drivers/net/hyperv/rndis_filter.c | 21 ++++++++++------ 4 files changed, 72 insertions(+), 86 deletions(-)
Signature · 1 line
1.7.4.1
PATCH 6/10 hv_netvsc: Eliminate send_completion from struct hv_netvsc_packet
In reply to K. Y. SrinivasanEliminate send_completion from struct hv_netvsc_packet.
--- drivers/net/hyperv/hyperv_net.h | 3 +-- drivers/net/hyperv/netvsc.c | 6 +++--- drivers/net/hyperv/netvsc_drv.c | 2 +- drivers/net/hyperv/rndis_filter.c | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-)
drivers/net/hyperv/hyperv_net.h +1 -2
@@ -135,7 +135,7 @@ struct hv_netvsc_packet {u8 rmsg_size;/* RNDIS header and PPI size */ u8 rmsg_pgcnt;/* page count of RNDIS header and PPI */ u8 page_buf_cnt; -u8 pad0; +u8 completion_func;u16 vlan_tci;u16 q_idx;
@@ -147,7 +147,6 @@ struct hv_netvsc_packet {u64 send_completion_tid;void *send_completion_ctx; -void (*send_completion)(void *context);struct hv_page_buffer *page_buf; };
drivers/net/hyperv/netvsc.c +3 -3
@@ -653,8 +653,8 @@ static void netvsc_send_completion(struct netvsc_device *net_device,netvsc_free_send_slot (net_device, send_index); q_idx = nvsc_packet->q_idx; channel = incoming_channel; - nvsc_packet->send_completion (nvsc_packet-> - send_completion_ctx); +netvsc_xmit_completion (nvsc_packet-> + send_completion_ctx); } num_outstanding_sends =
@@ -775,7 +775,7 @@ static inline int netvsc_send_pkt( nvmsg.msg.v1_msg.send_rndis_pkt.send_buf_section_size = packet->total_data_buflen; -if (packet->send_completion) +if (packet->completion_func) req_id = (ulong )packet;else req_id =0 ;
drivers/net/hyperv/netvsc_drv.c +1 -1
@@ -488,7 +488,7 @@ check_size:memset (rndis_msg,0 ,RNDIS_AND_PPI_SIZE );/* Set the completion routine */ - packet->send_completion = netvsc_xmit_completion; + packet->completion_func =1 ; packet->send_completion_ctx = packet; packet->send_completion_tid = (unsigned long )skb;
drivers/net/hyperv/rndis_filter.c +1 -1
@@ -237,7 +237,7 @@ static int rndis_filter_send_request(struct rndis_device *dev, packet->page_buf[0 ].len; } - packet->send_completion =NULL ; + packet->completion_func =0 ; packet->xmit_more = false; ret =netvsc_send (dev->net_dev->dev, packet,NULL );
Signature · 1 line
1.7.4.1
PATCH 10/10 hv_netvsc: remove locking in netvsc_send()
In reply to K. Y. SrinivasanFrom: Vitaly Kuznetsov <[email protected]>
Packet scheduler guarantees there won't be multiple senders for the same queue and as we use q_idx for multi_send_data the spinlock is redundant.
--- drivers/net/hyperv/hyperv_net.h | 1 - drivers/net/hyperv/netvsc.c | 8 -------- 2 files changed, 0 insertions(+), 9 deletions(-)
drivers/net/hyperv/hyperv_net.h +0 -1
@@ -633,7 +633,6 @@ struct nvsp_message {#define RNDIS_PKT_ALIGN_DEFAULT 8struct multi_send_data { -spinlock_t lock;/* protect struct multi_send_data */ struct hv_netvsc_packet *pkt;/* netvsc pkt pending */ u32 count;/* counter of batched packets */ };
drivers/net/hyperv/netvsc.c +0 -8
@@ -38,7 +38,6 @@ static struct netvsc_device *alloc_net_device(struct hv_device *device) {struct netvsc_device *net_device;struct net_device *ndev =hv_get_drvdata (device); -int i; net_device =kzalloc (sizeof (struct netvsc_device ),GFP_KERNEL );if (!net_device)
@@ -58,9 +57,6 @@ static struct netvsc_device *alloc_net_device(struct hv_device *device) net_device->max_pkt =RNDIS_MAX_PKT_DEFAULT ; net_device->pkt_align =RNDIS_PKT_ALIGN_DEFAULT ; -for (i =0 ; i <num_online_cpus (); i++) -spin_lock_init (&net_device->msd[i].lock); -hv_set_drvdata (device, net_device);return net_device; }
@@ -850,7 +846,6 @@ int netvsc_send(struct hv_device *device,u16 q_idx = packet->q_idx;u32 pktlen = packet->total_data_buflen, msd_len =0 ;unsigned int section_index =NETVSC_INVALID_INDEX ; -unsigned long flag;struct multi_send_data *msdp;struct hv_netvsc_packet *msd_send =NULL , *cur_send =NULL ;bool try_batch;
@@ -867,7 +862,6 @@ int netvsc_send(struct hv_device *device, msdp = &net_device->msd[q_idx];/* batch packets in send buffer if possible */ -spin_lock_irqsave (&msdp->lock, flag);if (msdp->pkt) msd_len = msdp->pkt->total_data_buflen;
@@ -927,8 +921,6 @@ int netvsc_send(struct hv_device *device, cur_send = packet; } -spin_unlock_irqrestore (&msdp->lock, flag); -if (msd_send) { m_ret =netvsc_send_pkt (msd_send, net_device);
Signature · 1 line
1.7.4.1
PATCH 7/10 hv_netvsc: Eliminate send_completion_ctx from struct hv_netvsc_packet
In reply to K. Y. SrinivasanEliminate send_completion_ctx from struct hv_netvsc_packet.
--- drivers/net/hyperv/hyperv_net.h | 1 - drivers/net/hyperv/netvsc.c | 3 +-- drivers/net/hyperv/netvsc_drv.c | 1 - 3 files changed, 1 insertions(+), 4 deletions(-)
drivers/net/hyperv/hyperv_net.h +0 -1
@@ -146,7 +146,6 @@ struct hv_netvsc_packet {u64 send_completion_tid; -void *send_completion_ctx;struct hv_page_buffer *page_buf; };
drivers/net/hyperv/netvsc.c +1 -2
@@ -653,8 +653,7 @@ static void netvsc_send_completion(struct netvsc_device *net_device,netvsc_free_send_slot (net_device, send_index); q_idx = nvsc_packet->q_idx; channel = incoming_channel; -netvsc_xmit_completion (nvsc_packet-> - send_completion_ctx); +netvsc_xmit_completion (nvsc_packet); } num_outstanding_sends =
drivers/net/hyperv/netvsc_drv.c +0 -1
@@ -489,7 +489,6 @@ check_size:/* Set the completion routine */ packet->completion_func =1 ; - packet->send_completion_ctx = packet; packet->send_completion_tid = (unsigned long )skb; isvlan = packet->vlan_tci &VLAN_TAG_PRESENT ;
Signature · 1 line
1.7.4.1
PATCH 1/10 hv_netvsc: Resize some of the variables in hv_netvsc_packet
In reply to K. Y. SrinivasanAs part of reducing the size of the hv_netvsc_packet, resize some of the variables based on their usage.
--- drivers/net/hyperv/hyperv_net.h | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/hyperv/hyperv_net.h +7 -7
@@ -127,11 +127,11 @@ struct ndis_tcp_ip_checksum_info;*/ struct hv_netvsc_packet {/* Bookkeeping stuff */ -u32 status; +u8 status; -bool is_data_pkt; -bool xmit_more;/* from skb */ -bool cp_partial;/* partial copy into send buffer */ +u8 is_data_pkt; +u8 xmit_more;/* from skb */ +u8 cp_partial;/* partial copy into send buffer */ u16 vlan_tci;
@@ -147,13 +147,13 @@ struct hv_netvsc_packet {/* This points to the memory after page_buf */ struct rndis_message *rndis_msg; -u32 rmsg_size;/* RNDIS header and PPI size */ -u32 rmsg_pgcnt;/* page count of RNDIS header and PPI */ +u8 rmsg_size;/* RNDIS header and PPI size */ +u8 rmsg_pgcnt;/* page count of RNDIS header and PPI */ u32 total_data_buflen;/* Points to the send/receive buffer where the ethernet frame is */ void *data; -u32 page_buf_cnt; +u8 page_buf_cnt;struct hv_page_buffer *page_buf; };
Signature · 1 line
1.7.4.1
PATCH 2/10 hv_netvsc: Rearrange the hv_negtvsc_packet to be space efficient
Rearrange the elements of struct hv_negtvsc_packet for optimal layout - eliminate unnecessary padding.
--- drivers/net/hyperv/hyperv_net.h | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)
drivers/net/hyperv/hyperv_net.h +10 -8
@@ -128,32 +128,34 @@ struct ndis_tcp_ip_checksum_info;struct hv_netvsc_packet {/* Bookkeeping stuff */ u8 status; -u8 is_data_pkt;u8 xmit_more;/* from skb */ u8 cp_partial;/* partial copy into send buffer */ -u16 vlan_tci; +u8 rmsg_size;/* RNDIS header and PPI size */ +u8 rmsg_pgcnt;/* page count of RNDIS header and PPI */ +u8 page_buf_cnt; +u8 pad0; +u16 vlan_tci;u16 q_idx; +u32 send_buf_index; + +u32 total_data_buflen; +u32 pad1; +struct vmbus_channel *channel;u64 send_completion_tid;void *send_completion_ctx;void (*send_completion)(void *context); -u32 send_buf_index;/* This points to the memory after page_buf */ struct rndis_message *rndis_msg; -u8 rmsg_size;/* RNDIS header and PPI size */ -u8 rmsg_pgcnt;/* page count of RNDIS header and PPI */ - -u32 total_data_buflen;/* Points to the send/receive buffer where the ethernet frame is */ void *data; -u8 page_buf_cnt;struct hv_page_buffer *page_buf; };
Signature · 1 line
1.7.4.1
PATCH 9/10 hv_netvsc: move subchannel existence check to netvsc_select_queue()
In reply to K. Y. SrinivasanFrom: Vitaly Kuznetsov <[email protected]>
--- drivers/net/hyperv/hyperv_net.h | 15 --------------- drivers/net/hyperv/netvsc.c | 5 ++--- drivers/net/hyperv/netvsc_drv.c | 3 +++ 3 files changed, 5 insertions(+), 18 deletions(-)
drivers/net/hyperv/hyperv_net.h +0 -15
@@ -1260,19 +1260,4 @@ struct rndis_message {#define TRANSPORT_INFO_IPV6_TCP ((INFO_IPV6 << 16) | INFO_TCP)#define TRANSPORT_INFO_IPV6_UDP ((INFO_IPV6 << 16) | INFO_UDP) -static inline struct vmbus_channel *get_channel (struct hv_netvsc_packet *packet, -struct netvsc_device *net_device) - -{ -struct vmbus_channel *out_channel; - - out_channel = net_device->chn_table[packet->q_idx]; -if (!out_channel) { - out_channel = net_device->dev->channel; - packet->q_idx =0 ; - } -return out_channel; -} - -#endif /* _HYPERV_NET_H */
drivers/net/hyperv/netvsc.c +2 -3
@@ -749,8 +749,8 @@ static inline int netvsc_send_pkt( struct netvsc_device *net_device) {struct nvsp_message nvmsg; -struct vmbus_channel *out_channel =get_channel (packet, net_device);u16 q_idx = packet->q_idx; +struct vmbus_channel *out_channel = net_device->chn_table[q_idx];struct net_device *ndev = net_device->ndev;u64 req_id;int ret;
@@ -859,8 +859,7 @@ int netvsc_send(struct hv_device *device,if (!net_device)return -ENODEV ; - out_channel =get_channel (packet, net_device); - q_idx = packet->q_idx; + out_channel = net_device->chn_table[q_idx]; packet->send_buf_index =NETVSC_INVALID_INDEX ; packet->cp_partial = false;
drivers/net/hyperv/netvsc_drv.c +3 -0
@@ -272,6 +272,9 @@ static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb,skb_set_hash (skb, hash,PKT_HASH_TYPE_L3 ); } +if (!nvsc_dev->chn_table[q_idx]) + q_idx =0 ; +return q_idx; }
Signature · 1 line
1.7.4.1
PATCH 5/10 hv_netvsc: Eliminatte the data field from struct hv_netvsc_packet
In reply to K. Y. SrinivasanEliminatte the data field from struct hv_netvsc_packet.
--- drivers/net/hyperv/hyperv_net.h | 5 ++--- drivers/net/hyperv/netvsc.c | 5 +++-- drivers/net/hyperv/netvsc_drv.c | 3 ++- drivers/net/hyperv/rndis_filter.c | 11 +++++++---- 4 files changed, 14 insertions(+), 10 deletions(-)
drivers/net/hyperv/hyperv_net.h +2 -3
@@ -148,9 +148,6 @@ struct hv_netvsc_packet {u64 send_completion_tid;void *send_completion_ctx;void (*send_completion)(void *context); - -/* Points to the send/receive buffer where the ethernet frame is */ -void *data;struct hv_page_buffer *page_buf; };
@@ -196,6 +193,7 @@ void netvsc_linkstatus_callback(struct hv_device *device_obj,void netvsc_xmit_completion (void *context);int netvsc_recv_callback (struct hv_device *device_obj,struct hv_netvsc_packet *packet, +void **data,struct ndis_tcp_ip_checksum_info *csum_info,struct vmbus_channel *channel);void netvsc_channel_cb (void *context);
@@ -206,6 +204,7 @@ int rndis_filter_device_add(struct hv_device *dev,void rndis_filter_device_remove (struct hv_device *dev);int rndis_filter_receive (struct hv_device *dev,struct hv_netvsc_packet *pkt, +void **data,struct vmbus_channel *channel);int rndis_filter_set_packet_filter (struct rndis_device *dev,u32 new_filter);
drivers/net/hyperv/netvsc.c +3 -2
@@ -1008,6 +1008,7 @@ static void netvsc_receive(struct netvsc_device *net_device,int i;int count =0 ;struct net_device *ndev; +void *data; ndev = net_device->ndev;
@@ -1047,13 +1048,13 @@ static void netvsc_receive(struct netvsc_device *net_device,for (i =0 ; i < count; i++) {/* Initialize the netvsc packet */ netvsc_packet->status =NVSP_STAT_SUCCESS ; - netvsc_packet->data = (void *)((unsigned long )net_device-> + data = (void *)((unsigned long )net_device-> recv_buf + vmxferpage_packet->ranges[i].byte_offset); netvsc_packet->total_data_buflen = vmxferpage_packet->ranges[i].byte_count;/* Pass it to the upper layer */ -rndis_filter_receive (device, netvsc_packet, channel); +rndis_filter_receive (device, netvsc_packet, &data, channel);if (netvsc_packet->status !=NVSP_STAT_SUCCESS ) status =NVSP_STAT_FAIL ;
drivers/net/hyperv/netvsc_drv.c +2 -1
@@ -685,6 +685,7 @@ void netvsc_linkstatus_callback(struct hv_device *device_obj,*/ int netvsc_recv_callback (struct hv_device *device_obj,struct hv_netvsc_packet *packet, +void **data,struct ndis_tcp_ip_checksum_info *csum_info,struct vmbus_channel *channel) {
@@ -713,7 +714,7 @@ int netvsc_recv_callback(struct hv_device *device_obj,* Copy to skb. This copy is needed here since the memory pointed by * hv_netvsc_packet cannot be deallocated */ -memcpy (skb_put (skb, packet->total_data_buflen), packet->data, +memcpy (skb_put (skb, packet->total_data_buflen), *data, packet->total_data_buflen); skb->protocol =eth_type_trans (skb, net);
drivers/net/hyperv/rndis_filter.c +7 -4
@@ -351,6 +351,7 @@ static inline void *rndis_get_ppi(struct rndis_packet *rpkt, u32 type)static void rndis_filter_receive_data (struct rndis_device *dev,struct rndis_message *msg,struct hv_netvsc_packet *pkt, +void **data,struct vmbus_channel *channel) {struct rndis_packet *rndis_pkt;
@@ -383,7 +384,7 @@ static void rndis_filter_receive_data(struct rndis_device *dev,* the data packet to the stack, without the rndis trailer padding */ pkt->total_data_buflen = rndis_pkt->data_len; - pkt->data = (void *)((unsigned long )pkt->data + data_offset); + *data = (void *)((unsigned long )(*data) + data_offset); vlan =rndis_get_ppi (rndis_pkt,IEEE_8021Q_INFO );if (vlan) {
@@ -394,11 +395,12 @@ static void rndis_filter_receive_data(struct rndis_device *dev, } csum_info =rndis_get_ppi (rndis_pkt,TCPIP_CHKSUM_PKTINFO ); -netvsc_recv_callback (dev->net_dev->dev, pkt, csum_info, channel); +netvsc_recv_callback (dev->net_dev->dev, pkt, data, csum_info, channel); }int rndis_filter_receive (struct hv_device *dev,struct hv_netvsc_packet *pkt, +void **data,struct vmbus_channel *channel) {struct netvsc_device *net_dev =hv_get_drvdata (dev);
@@ -430,7 +432,7 @@ int rndis_filter_receive(struct hv_device *dev, goto exit; } - rndis_msg = pkt->data; + rndis_msg = *data;if (netif_msg_rx_err (net_dev->nd_ctx))dump_rndis_message (dev, rndis_msg);
@@ -438,7 +440,8 @@ int rndis_filter_receive(struct hv_device *dev,switch (rndis_msg->ndis_msg_type) {case RNDIS_MSG_PACKET :/* data msg */ -rndis_filter_receive_data (rndis_dev, rndis_msg, pkt, channel); +rndis_filter_receive_data (rndis_dev, rndis_msg, pkt, + data, channel);break ;case RNDIS_MSG_INIT_C :
Signature · 1 line
1.7.4.1
PATCH 4/10 hv_netvsc: Eliminate rndis_msg pointer from hv_netvsc_packet structure
In reply to K. Y. SrinivasanEliminate rndis_msg pointer from hv_netvsc_packet structure.
--- drivers/net/hyperv/hyperv_net.h | 8 +++----- drivers/net/hyperv/netvsc.c | 10 ++++++---- drivers/net/hyperv/netvsc_drv.c | 7 +++---- drivers/net/hyperv/rndis_filter.c | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-)
drivers/net/hyperv/hyperv_net.h +3 -5
@@ -149,10 +149,6 @@ struct hv_netvsc_packet {void *send_completion_ctx;void (*send_completion)(void *context); - -/* This points to the memory after page_buf */ -struct rndis_message *rndis_msg; -/* Points to the send/receive buffer where the ethernet frame is */ void *data;struct hv_page_buffer *page_buf;
@@ -189,10 +185,12 @@ struct rndis_device {/* Interface */ +struct rndis_message ;int netvsc_device_add (struct hv_device *device,void *additional_info);int netvsc_device_remove (struct hv_device *device);int netvsc_send (struct hv_device *device, -struct hv_netvsc_packet *packet); +struct hv_netvsc_packet *packet, +struct rndis_message *rndis_msg);void netvsc_linkstatus_callback (struct hv_device *device_obj,struct rndis_message *resp);void netvsc_xmit_completion (void *context);
drivers/net/hyperv/netvsc.c +6 -4
@@ -706,7 +706,8 @@ static u32 netvsc_get_next_send_section(struct netvsc_device *net_device)static u32 netvsc_copy_to_send_buf (struct netvsc_device *net_device,unsigned int section_index,u32 pend_size, -struct hv_netvsc_packet *packet) +struct hv_netvsc_packet *packet, +struct rndis_message *rndis_msg) {char *start = net_device->send_buf;char *dest = start + (section_index * net_device->send_section_size)
@@ -722,7 +723,7 @@ static u32 netvsc_copy_to_send_buf(struct netvsc_device *net_device,if (packet->is_data_pkt && packet->xmit_more && remain && !packet->cp_partial) { padding = net_device->pkt_align - remain; - packet->rndis_msg->msg_len += padding; + rndis_msg->msg_len += padding; packet->total_data_buflen += padding; }
@@ -841,7 +842,8 @@ static inline int netvsc_send_pkt( }int netvsc_send (struct hv_device *device, -struct hv_netvsc_packet *packet) +struct hv_netvsc_packet *packet, +struct rndis_message *rndis_msg) {struct netvsc_device *net_device;int ret =0 , m_ret =0 ;
@@ -897,7 +899,7 @@ int netvsc_send(struct hv_device *device,if (section_index !=NETVSC_INVALID_INDEX ) {netvsc_copy_to_send_buf (net_device, section_index, msd_len, - packet); + packet, rndis_msg); packet->send_buf_index = section_index;
drivers/net/hyperv/netvsc_drv.c +3 -4
@@ -482,10 +482,10 @@ check_size: packet->is_data_pkt = true; packet->total_data_buflen = skb->len; - packet->rndis_msg = (struct rndis_message *)((unsigned long )packet + + rndis_msg = (struct rndis_message *)((unsigned long )packet +sizeof (struct hv_netvsc_packet )); -memset (packet->rndis_msg,0 ,RNDIS_AND_PPI_SIZE ); +memset (rndis_msg,0 ,RNDIS_AND_PPI_SIZE );/* Set the completion routine */ packet->send_completion = netvsc_xmit_completion;
@@ -495,7 +495,6 @@ check_size: isvlan = packet->vlan_tci &VLAN_TAG_PRESENT ;/* Add the rndis header */ - rndis_msg = packet->rndis_msg; rndis_msg->ndis_msg_type =RNDIS_MSG_PACKET ; rndis_msg->msg_len = packet->total_data_buflen; rndis_pkt = &rndis_msg->msg.pkt;
@@ -619,7 +618,7 @@ do_send: packet->page_buf_cnt =init_page_array (rndis_msg, rndis_msg_size, skb, packet); - ret =netvsc_send (net_device_ctx->device_ctx, packet); + ret =netvsc_send (net_device_ctx->device_ctx, packet, rndis_msg); drop:if (ret ==0 ) {
drivers/net/hyperv/rndis_filter.c +1 -1
@@ -240,7 +240,7 @@ static int rndis_filter_send_request(struct rndis_device *dev, packet->send_completion =NULL ; packet->xmit_more = false; - ret =netvsc_send (dev->net_dev->dev, packet); + ret =netvsc_send (dev->net_dev->dev, packet,NULL );return ret; }
Signature · 1 line
1.7.4.1
PATCH 8/10 hv_netvsc: Don't ask for additional head room in the skb
In reply to K. Y. SrinivasanThe rndis header is 116 bytes big and can be placed in the default head room that will be available in the skb. Since the netvsc packet is less than 48 bytes, we can use the skb control buffer for the netvsc packet. With these changes we don't need to ask for additional head room.
--- drivers/net/hyperv/hyperv_net.h | 3 +++ drivers/net/hyperv/netvsc_drv.c | 28 +++++++++------------------- 2 files changed, 12 insertions(+), 19 deletions(-)
drivers/net/hyperv/hyperv_net.h +3 -0
@@ -124,6 +124,9 @@ struct ndis_tcp_ip_checksum_info;/* * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame * within the RNDIS +* +* The size of this structure is less than 48 bytes and we can now +* place this structure in the skb->cb field. */ struct hv_netvsc_packet {/* Bookkeeping stuff */
drivers/net/hyperv/netvsc_drv.c +9 -19
@@ -432,7 +432,6 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)u32 net_trans_info;u32 hash;u32 skb_length; -u32 pkt_sz;struct hv_page_buffer page_buf[MAX_PAGE_BUFFER_COUNT ];struct netvsc_stats *tx_stats =this_cpu_ptr (net_device_ctx->tx_stats);
@@ -460,16 +459,19 @@ check_size: goto check_size; } - pkt_sz =sizeof (struct hv_netvsc_packet ) +RNDIS_AND_PPI_SIZE ; - - ret =skb_cow_head (skb, pkt_sz); +/* +* Place the rndis header in the skb head room and +* the skb->cb will be used for hv_netvsc_packet +* structure. +*/ + ret =skb_cow_head (skb,RNDIS_AND_PPI_SIZE );if (ret) {netdev_err (net,"unable to alloc hv_netvsc_packet\n" ); ret = -ENOMEM ; goto drop; } -/* Use the headroom for building up the packet */ - packet = (struct hv_netvsc_packet *)skb->head; +/* Use the skb control buffer for building up the packet */ + packet = (struct hv_netvsc_packet *)skb->cb; packet->status =0 ; packet->xmit_more = skb->xmit_more;
@@ -482,8 +484,7 @@ check_size: packet->is_data_pkt = true; packet->total_data_buflen = skb->len; - rndis_msg = (struct rndis_message *)((unsigned long )packet + -sizeof (struct hv_netvsc_packet )); + rndis_msg = (struct rndis_message *)skb->head;memset (rndis_msg,0 ,RNDIS_AND_PPI_SIZE );
@@ -1071,16 +1072,12 @@ static int netvsc_probe(struct hv_device *dev,struct netvsc_device_info device_info;struct netvsc_device *nvdev;int ret; -u32 max_needed_headroom; net =alloc_etherdev_mq (sizeof (struct net_device_context ),num_online_cpus ());if (!net)return -ENOMEM ; - max_needed_headroom =sizeof (struct hv_netvsc_packet ) + -RNDIS_AND_PPI_SIZE ; -netif_carrier_off (net); net_device_ctx =netdev_priv (net);
@@ -1116,13 +1113,6 @@ static int netvsc_probe(struct hv_device *dev, net->ethtool_ops = ðtool_ops;SET_NETDEV_DEV (net, &dev->device); -/* -* Request additional head room in the skb. -* We will use this space to build the rndis -* heaser and other state we need to maintain. -*/ - net->needed_headroom = max_needed_headroom; -/* Notify the netvsc driver of the new device */ memset (&device_info,0 ,sizeof (device_info)); device_info.ring_size = ring_size;
Signature · 1 line
1.7.4.1
PATCH 3/10 hv_netvsc: Eliminate the channel field in hv_netvsc_packet structure
In reply to K. Y. SrinivasanEliminate the channel field in hv_netvsc_packet structure.
--- drivers/net/hyperv/hyperv_net.h | 22 ++++++++++++++++++---- drivers/net/hyperv/netvsc.c | 19 ++++++++----------- drivers/net/hyperv/netvsc_drv.c | 5 +++-- drivers/net/hyperv/rndis_filter.c | 10 ++++++---- 4 files changed, 35 insertions(+), 21 deletions(-)
drivers/net/hyperv/hyperv_net.h +18 -4
@@ -144,7 +144,6 @@ struct hv_netvsc_packet {u32 total_data_buflen;u32 pad1; -struct vmbus_channel *channel;u64 send_completion_tid;void *send_completion_ctx;
@@ -199,7 +198,8 @@ void netvsc_linkstatus_callback(struct hv_device *device_obj,void netvsc_xmit_completion (void *context);int netvsc_recv_callback (struct hv_device *device_obj,struct hv_netvsc_packet *packet, -struct ndis_tcp_ip_checksum_info *csum_info); +struct ndis_tcp_ip_checksum_info *csum_info, +struct vmbus_channel *channel);void netvsc_channel_cb (void *context);int rndis_filter_open (struct hv_device *dev);int rndis_filter_close (struct hv_device *dev);
@@ -207,12 +207,12 @@ int rndis_filter_device_add(struct hv_device *dev, void *additional_info);void rndis_filter_device_remove (struct hv_device *dev);int rndis_filter_receive (struct hv_device *dev, -struct hv_netvsc_packet *pkt); +struct hv_netvsc_packet *pkt, +struct vmbus_channel *channel);int rndis_filter_set_packet_filter (struct rndis_device *dev,u32 new_filter);int rndis_filter_set_device_mac (struct hv_device *hdev,char *mac); -#define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF)#define NVSP_PROTOCOL_VERSION_1 2
@@ -1262,5 +1262,19 @@ struct rndis_message {#define TRANSPORT_INFO_IPV6_TCP ((INFO_IPV6 << 16) | INFO_TCP)#define TRANSPORT_INFO_IPV6_UDP ((INFO_IPV6 << 16) | INFO_UDP) +static inline struct vmbus_channel *get_channel (struct hv_netvsc_packet *packet, +struct netvsc_device *net_device) + +{ +struct vmbus_channel *out_channel; + + out_channel = net_device->chn_table[packet->q_idx]; +if (!out_channel) { + out_channel = net_device->dev->channel; + packet->q_idx =0 ; + } +return out_channel; +} +#endif /* _HYPERV_NET_H */
drivers/net/hyperv/netvsc.c +8 -11
@@ -610,6 +610,7 @@ static inline void netvsc_free_send_slot(struct netvsc_device *net_device, }static void netvsc_send_completion (struct netvsc_device *net_device, +struct vmbus_channel *incoming_channel,struct hv_device *device,struct vmpacket_descriptor *packet) {
@@ -651,7 +652,7 @@ static void netvsc_send_completion(struct netvsc_device *net_device,if (send_index !=NETVSC_INVALID_INDEX )netvsc_free_send_slot (net_device, send_index); q_idx = nvsc_packet->q_idx; - channel = nvsc_packet->channel; + channel = incoming_channel; nvsc_packet->send_completion (nvsc_packet-> send_completion_ctx); }
@@ -748,7 +749,7 @@ static inline int netvsc_send_pkt( struct netvsc_device *net_device) {struct nvsp_message nvmsg; -struct vmbus_channel *out_channel = packet->channel; +struct vmbus_channel *out_channel =get_channel (packet, net_device);u16 q_idx = packet->q_idx;struct net_device *ndev = net_device->ndev;u64 req_id;
@@ -857,13 +858,9 @@ int netvsc_send(struct hv_device *device,if (!net_device)return -ENODEV ; - out_channel = net_device->chn_table[q_idx]; -if (!out_channel) { - out_channel = device->channel; - q_idx =0 ; - packet->q_idx =0 ; - } - packet->channel = out_channel; + out_channel =get_channel (packet, net_device); + q_idx = packet->q_idx; + packet->send_buf_index =NETVSC_INVALID_INDEX ; packet->cp_partial = false;
@@ -1043,7 +1040,6 @@ static void netvsc_receive(struct netvsc_device *net_device, } count = vmxferpage_packet->range_cnt; - netvsc_packet->channel = channel;/* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */ for (i =0 ; i < count; i++) {
@@ -1055,7 +1051,7 @@ static void netvsc_receive(struct netvsc_device *net_device, vmxferpage_packet->ranges[i].byte_count;/* Pass it to the upper layer */ -rndis_filter_receive (device, netvsc_packet); +rndis_filter_receive (device, netvsc_packet, channel);if (netvsc_packet->status !=NVSP_STAT_SUCCESS ) status =NVSP_STAT_FAIL ;
@@ -1150,6 +1146,7 @@ void netvsc_channel_cb(void *context)switch (desc->type) {case VM_PKT_COMP :netvsc_send_completion (net_device, + channel, device, desc);break ;
drivers/net/hyperv/netvsc_drv.c +3 -2
@@ -686,7 +686,8 @@ void netvsc_linkstatus_callback(struct hv_device *device_obj,*/ int netvsc_recv_callback (struct hv_device *device_obj,struct hv_netvsc_packet *packet, -struct ndis_tcp_ip_checksum_info *csum_info) +struct ndis_tcp_ip_checksum_info *csum_info, +struct vmbus_channel *channel) {struct net_device *net;struct net_device_context *net_device_ctx;
@@ -732,7 +733,7 @@ int netvsc_recv_callback(struct hv_device *device_obj,__vlan_hwaccel_put_tag (skb,htons (ETH_P_8021Q ), packet->vlan_tci); -skb_record_rx_queue (skb, packet->channel-> +skb_record_rx_queue (skb, channel-> offermsg.offer.sub_channel_index);u64_stats_update_begin (&rx_stats->syncp);
drivers/net/hyperv/rndis_filter.c +6 -4
@@ -350,7 +350,8 @@ static inline void *rndis_get_ppi(struct rndis_packet *rpkt, u32 type)static void rndis_filter_receive_data (struct rndis_device *dev,struct rndis_message *msg, -struct hv_netvsc_packet *pkt) +struct hv_netvsc_packet *pkt, +struct vmbus_channel *channel) {struct rndis_packet *rndis_pkt;u32 data_offset;
@@ -393,11 +394,12 @@ static void rndis_filter_receive_data(struct rndis_device *dev, } csum_info =rndis_get_ppi (rndis_pkt,TCPIP_CHKSUM_PKTINFO ); -netvsc_recv_callback (dev->net_dev->dev, pkt, csum_info); +netvsc_recv_callback (dev->net_dev->dev, pkt, csum_info, channel); }int rndis_filter_receive (struct hv_device *dev, -struct hv_netvsc_packet *pkt) +struct hv_netvsc_packet *pkt, +struct vmbus_channel *channel) {struct netvsc_device *net_dev =hv_get_drvdata (dev);struct rndis_device *rndis_dev;
@@ -436,7 +438,7 @@ int rndis_filter_receive(struct hv_device *dev,switch (rndis_msg->ndis_msg_type) {case RNDIS_MSG_PACKET :/* data msg */ -rndis_filter_receive_data (rndis_dev, rndis_msg, pkt); +rndis_filter_receive_data (rndis_dev, rndis_msg, pkt, channel);break ;case RNDIS_MSG_INIT_C :
Signature · 1 line
1.7.4.1
Re: [PATCH net-next 01/10] hv_netvsc: Resize some of the variables in hv_netvsc_packet
In reply to K. Y. SrinivasanQuoted 16 lines · K. Y. Srinivasan
As part of reducing the size of the
hv_netvsc_packet, resize some of the variables based on their usage.Signed-off-by K. Y. Srinivasan <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>--- drivers/net/hyperv/hyperv_net.h | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)drivers/net/hyperv/hyperv_net.h +0
-0@@ -127,11 +127,11 @@ struct ndis_tcp_ip_checksum_info;*/ struct hv_netvsc_packet {
drivers/net/hyperv/hyperv_net.h struct ndis_tcp_ip_checksum_info; · line 134
Quoted 10 lines
drivers/net/hyperv/hyperv_net.h +4
-4/* Bookkeeping stuff */ -u32 status; +u8 status; -bool is_data_pkt; -bool xmit_more;/* from skb */ -bool cp_partial;/* partial copy into send buffer */ +u8 is_data_pkt; +u8 xmit_more;/* from skb */ +u8 cp_partial;/* partial copy into send buffer */
These are flags so we can make them bitfields and save even more space.
Quoted 19 lines
drivers/net/hyperv/hyperv_net.h +3
-3u16 vlan_tci;@@ -147,13 +147,13 @@ struct hv_netvsc_packet {/* This points to the memory after page_buf */ struct rndis_message *rndis_msg; -u32 rmsg_size;/* RNDIS header and PPI size */ -u32 rmsg_pgcnt;/* page count of RNDIS header and PPI */ +u8 rmsg_size;/* RNDIS header and PPI size */ +u8 rmsg_pgcnt;/* page count of RNDIS header and PPI */ u32 total_data_buflen;/* Points to the send/receive buffer where the ethernet frame is */ void *data; -u32 page_buf_cnt; +u8 page_buf_cnt;struct hv_page_buffer *page_buf; };
Signature · 1 line
Vitaly
Re: [PATCH net-next 08/10] hv_netvsc: Don't ask for additional head room in the skb
In reply to K. Y. SrinivasanQuoted 5 lines · K. Y. Srinivasan
The rndis header is 116 bytes big and can be placed in the default head room that will be available in the skb. Since the netvsc packet is less than 48 bytes, we can use the skb control buffer for the netvsc packet. With these changes we don't need to ask for additional head room.
Minor nit: could you add a BUILD_BUG_ON test for this? Something like
BUILD_BUG_ON(sizeof(struct hv_netvsc_packet) > FIELD_SIZEOF(struct sk_buff, cb));
Re: [PATCH net-next 08/10] hv_netvsc: Don't ask for additional head room in the skb
In reply to K. Y. SrinivasanQuoted 2 lines · K. Y. Srinivasan
The rndis header is 116 bytes big and can be placed in the default head room that will be available in the skb.
We have the following in include/linux/netdevice.h:
#if defined(CONFIG_WLAN) || IS_ENABLED(CONFIG_AX25)
# if defined(CONFIG_MAC80211_MESH) # define LL_MAX_HEADER 128 # else # define LL_MAX_HEADER 96 # endif #else # define LL_MAX_HEADER 32 #endif
In case someone disables MAC80211_MESH in his kernel config we're in troubles again. I suggest we add additional patch here making sure it is 128 bytes for Hyper-V:
#if defined(CONFIG_HYPERV_NET)
# define LL_MAX_HEADER 128 #elseif defined(CONFIG_WLAN) || IS_ENABLED(CONFIG_AX25) ...
Quoted 104 lines
Since the netvsc packet
is less than 48 bytes, we can use the skb control buffer for the netvsc packet. With these changes we don't need to ask for additional head room.Signed-off-by K. Y. Srinivasan <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>--- drivers/net/hyperv/hyperv_net.h | 3 +++ drivers/net/hyperv/netvsc_drv.c | 28 +++++++++------------------- 2 files changed, 12 insertions(+), 19 deletions(-)drivers/net/hyperv/hyperv_net.h +3
-0@@ -124,6 +124,9 @@ struct ndis_tcp_ip_checksum_info;/* * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame * within the RNDIS +* +* The size of this structure is less than 48 bytes and we can now +* place this structure in the skb->cb field. */ struct hv_netvsc_packet {/* Bookkeeping stuff */ drivers/net/hyperv/netvsc_drv.c +9
-19@@ -432,7 +432,6 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)u32 net_trans_info;u32 hash;u32 skb_length; -u32 pkt_sz;struct hv_page_buffer page_buf[MAX_PAGE_BUFFER_COUNT ];struct netvsc_stats *tx_stats =this_cpu_ptr (net_device_ctx->tx_stats);@@ -460,16 +459,19 @@ check_size: goto check_size; } - pkt_sz =sizeof (struct hv_netvsc_packet ) +RNDIS_AND_PPI_SIZE ; - - ret =skb_cow_head (skb, pkt_sz); +/* +* Place the rndis header in the skb head room and +* the skb->cb will be used for hv_netvsc_packet +* structure. +*/ + ret =skb_cow_head (skb,RNDIS_AND_PPI_SIZE );if (ret) {netdev_err (net,"unable to alloc hv_netvsc_packet\n" ); ret = -ENOMEM ; goto drop; } -/* Use the headroom for building up the packet */ - packet = (struct hv_netvsc_packet *)skb->head; +/* Use the skb control buffer for building up the packet */ + packet = (struct hv_netvsc_packet *)skb->cb; packet->status =0 ; packet->xmit_more = skb->xmit_more;@@ -482,8 +484,7 @@ check_size: packet->is_data_pkt = true; packet->total_data_buflen = skb->len; - rndis_msg = (struct rndis_message *)((unsigned long )packet + -sizeof (struct hv_netvsc_packet )); + rndis_msg = (struct rndis_message *)skb->head;memset (rndis_msg,0 ,RNDIS_AND_PPI_SIZE );@@ -1071,16 +1072,12 @@ static int netvsc_probe(struct hv_device *dev,struct netvsc_device_info device_info;struct netvsc_device *nvdev;int ret; -u32 max_needed_headroom; net =alloc_etherdev_mq (sizeof (struct net_device_context ),num_online_cpus ());if (!net)return -ENOMEM ; - max_needed_headroom =sizeof (struct hv_netvsc_packet ) + -RNDIS_AND_PPI_SIZE ; -netif_carrier_off (net); net_device_ctx =netdev_priv (net);@@ -1116,13 +1113,6 @@ static int netvsc_probe(struct hv_device *dev, net->ethtool_ops = ðtool_ops;SET_NETDEV_DEV (net, &dev->device); -/* -* Request additional head room in the skb. -* We will use this space to build the rndis -* heaser and other state we need to maintain. -*/ - net->needed_headroom = max_needed_headroom; -/* Notify the netvsc driver of the new device */ memset (&device_info,0 ,sizeof (device_info)); device_info.ring_size = ring_size;
Signature · 1 line
Vitaly
RE: [PATCH net-next 08/10] hv_netvsc: Don't ask for additional head room in the skb
Quoted 29 lines
-----Original Message-----
From: Vitaly Kuznetsov [mailto:[email protected]]
Sent: Tuesday, November 24, 2015 12:56 AM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next 08/10]hv_netvsc: Don't ask for additional head room in the skbQuoted 2 lines · K. Y. Srinivasan
The rndis header is 116 bytes big and can be placed in the default head room that will be available in the skb.
We have the following in
include/linux/netdevice.h:#if
defined(CONFIG_WLAN)||IS_ENABLED(CONFIG_AX25)# if defined(CONFIG_MAC80211_MESH) # define LL_MAX_HEADER 128 # else # define LL_MAX_HEADER 96 # endif #else # define LL_MAX_HEADER 32 #endif
Quoted 8 lines
In case someone disables
MAC80211_MESHin his kernel config we're in troubles again. I suggest we add additional patch here making sure it is 128 bytes for Hyper-V:#if
defined(CONFIG_HYPERV_NET)# define LL_MAX_HEADER 128 #elseif defined(CONFIG_WLAN) || IS_ENABLED(CONFIG_AX25) ...
Thanks Vitaly; will do.
K. Y
RE: [PATCH net-next 01/10] hv_netvsc: Resize some of the variables in hv_netvsc_packet
In reply to Vitaly KuznetsovQuoted 35 lines
-----Original Message-----
From: Vitaly Kuznetsov [mailto:[email protected]]
Sent: Tuesday, November 24, 2015 12:48 AM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next 01/10]hv_netvsc: Resize some of the variables inhv_netvsc_packetReview
Quoted 10 lines · K. Y. Srinivasan
As part of reducing the size of the
hv_netvsc_packet, resize some of the variables based on their usage.Signed-off-by K. Y. Srinivasan <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>--- drivers/net/hyperv/hyperv_net.h | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)(quoted diff) +0
-0
b/drivers/net/hyperv/hyperv_net.hQuoted 10 lines
index 5fa98f5..972e562 100644
drivers/net/hyperv/hyperv_net.h +1
-1@@ -127,11 +127,11 @@ struct ndis_tcp_ip_checksum_info;*/ struct hv_netvsc_packet {/* Bookkeeping stuff */ -u32 status; +u8 status;
Quoted 8 lines
drivers/net/hyperv/hyperv_net.h struct ndis_tcp_ip_checksum_info; · line 134
Quoted 6 lines
drivers/net/hyperv/hyperv_net.h +3
-3-bool is_data_pkt; -bool xmit_more;/* from skb */ -bool cp_partial;/* partial copy into send buffer */ +u8 is_data_pkt; +u8 xmit_more;/* from skb */ +u8 cp_partial;/* partial copy into send buffer */ These are flags so we can make them bitfields and save even more space.
I am not done with restructuring this structure yet. Once I get this to the bare minimum I will look at using bitfields.
K. Y
Quoted 23 lines
Quoted 10 lines
drivers/net/hyperv/hyperv_net.h +0
-2u16 vlan_tci;@@ -147,13 +147,13 @@ struct hv_netvsc_packet {/* This points to the memory after page_buf */ struct rndis_message *rndis_msg; -u32 rmsg_size;/* RNDIS header and PPI size */ -u32 rmsg_pgcnt;/* page count of RNDIS header and PPI */ drivers/net/hyperv/hyperv_net.h struct hv_netvsc_packet { · line 158
Quoted 10 lines
drivers/net/hyperv/hyperv_net.h +3
-1+u8 rmsg_size;/* RNDIS header and PPI size */ +u8 rmsg_pgcnt;/* page count of RNDIS header and PPI */ u32 total_data_buflen;/* Points to the send/receive buffer where the ethernet frame is */ void *data; -u32 page_buf_cnt; +u8 page_buf_cnt;struct hv_page_buffer *page_buf; };--
Vitaly
RE: [PATCH net-next 08/10] hv_netvsc: Don't ask for additional head room in the skb
In reply to Florian WestphalQuoted 19 lines
-----Original Message-----
From: Florian Westphal [mailto:[email protected]]
Sent: Tuesday, November 24, 2015 12:56 AM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next 08/10]hv_netvsc: Don't ask for additional head room in the skbQuoted 5 lines · K. Y. Srinivasan
The rndis header is 116 bytes big and can be placed in the default head room that will be available in the skb. Since the netvsc packet is less than 48 bytes, we can use the skb control buffer for the netvsc packet. With these changes we don't need to ask for additional head room.
Quoted 4 lines
Minor nit: could you add a
BUILD_BUG_ONtest for this? Something like
BUILD_BUG_ON(sizeof(struct hv_netvsc_packet) > FIELD_SIZEOF(struct sk_buff, cb));
Good point; will add this check.
Thanks,
K. Y