Skip to contentSkip to conversation

netvsc: Use the new in-place consumption APIs in the rx path

PATCH In review K. Y. Srinivasan 2 participants 4 messages Jun 9, 2016 – Jul 1, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netvsc: Use the new in-place consumption APIs in the rx path

Use the new APIs for eliminating a copy on the receive path. These new APIs also help in minimizing the number of memory barriers we end up issuing (in the ringbuffer code) since we can better control when we want to expose the ring state to the host.

---
 drivers/net/hyperv/netvsc.c |   88 +++++++++++++++++++++++++++++--------------
 1 files changed, 59 insertions(+), 29 deletions(-)
drivers/net/hyperv/netvsc.c +59 -29
index 719cb35..8cd4c19 100644
@@ -1141,6 +1141,39 @@ static inline void netvsc_receive_inband(struct hv_device *hdev,
 	}
 }
 
+static void netvsc_process_raw_pkt(struct hv_device *device,
+				   struct vmbus_channel *channel,
+				   struct netvsc_device *net_device,
+				   struct net_device *ndev,
+				   u64 request_id,
+				   struct vmpacket_descriptor *desc)
+{
+	struct nvsp_message *nvmsg;
+
+	nvmsg = (struct nvsp_message *)((unsigned long)
+		desc + (desc->offset8 << 3));
+
+	switch (desc->type) {
+	case VM_PKT_COMP:
+		netvsc_send_completion(net_device, channel, device, desc);
+		break;
+
+	case VM_PKT_DATA_USING_XFER_PAGES:
+		netvsc_receive(net_device, channel, device, desc);
+		break;
+
+	case VM_PKT_DATA_INBAND:
+		netvsc_receive_inband(device, net_device, nvmsg);
+		break;
+
+	default:
+		netdev_err(ndev, "unhandled packet type %d, tid %llx\n",
+			   desc->type, request_id);
+		break;
+	}
+}
+
+
 void netvsc_channel_cb(void *context)
 {
 	int ret;
@@ -1153,7 +1186,7 @@ void netvsc_channel_cb(void *context)
 	unsigned char *buffer;
 	int bufferlen = NETVSC_PACKET_SIZE;
 	struct net_device *ndev;
-	struct nvsp_message *nvmsg;
+	bool need_to_commit = false;
 
 	if (channel->primary_channel != NULL)
 		device = channel->primary_channel->device_obj;
@@ -1167,39 +1200,36 @@ void netvsc_channel_cb(void *context)
 	buffer = get_per_channel_state(channel);
 
 	do {
+		desc = get_next_pkt_raw(channel);
+		if (desc != NULL) {
+			netvsc_process_raw_pkt(device,
+					       channel,
+					       net_device,
+					       ndev,
+					       desc->trans_id,
+					       desc);
+
+			put_pkt_raw(channel, desc);
+			need_to_commit = true;
+			continue;
+		}
+		if (need_to_commit) {
+			need_to_commit = false;
+			commit_rd_index(channel);
+		}
+
 		ret = vmbus_recvpacket_raw(channel, buffer, bufferlen,
 					   &bytes_recvd, &request_id);
 		if (ret == 0) {
 			if (bytes_recvd > 0) {
 				desc = (struct vmpacket_descriptor *)buffer;
-				nvmsg = (struct nvsp_message *)((unsigned long)
-					 desc + (desc->offset8 << 3));
-				switch (desc->type) {
-				case VM_PKT_COMP:
-					netvsc_send_completion(net_device,
-								channel,
-								device, desc);
-					break;
-
-				case VM_PKT_DATA_USING_XFER_PAGES:
-					netvsc_receive(net_device, channel,
-						       device, desc);
-					break;
-
-				case VM_PKT_DATA_INBAND:
-					netvsc_receive_inband(device,
-							      net_device,
-							      nvmsg);
-					break;
-
-				default:
-					netdev_err(ndev,
-						   "unhandled packet type %d, "
-						   "tid %llx len %d\n",
-						   desc->type, request_id,
-						   bytes_recvd);
-					break;
-				}
+				netvsc_process_raw_pkt(device,
+						       channel,
+						       net_device,
+						       ndev,
+						       request_id,
+						       desc);
+
 
 			} else {
 				/*
Signature · 1 line
1.7.4.1
#1 lore raw

Srinivasan,

these are all sent through linuxonhyperv.com, and fail DMARC because
they have a microsoft.com address but no valid DKIM.

Please fix your email setup. You need to go through the real microsoft smtp servers if you use a microsoft.com address. Or you need to get linuxonhyperv.com fixed as a smtp server with the proper MS email signing.

Linus

Quoted 134 lines · K. Y. Srinivasan

Use the new APIs for eliminating a copy on the receive path. These new APIs also help in minimizing the number of memory barriers we end up issuing (in the ringbuffer code) since we can better control when we want to expose the ring state to the host.

---
 drivers/net/hyperv/netvsc.c |   88 +++++++++++++++++++++++++++++--------------
 1 files changed, 59 insertions(+), 29 deletions(-)
drivers/net/hyperv/netvsc.c +59 -30
index 719cb35..8cd4c19 100644
@@ -1141,6 +1141,39 @@ static inline void netvsc_receive_inband(struct hv_device *hdev,
        }
 }
 
+static void netvsc_process_raw_pkt(struct hv_device *device,
+                                  struct vmbus_channel *channel,
+                                  struct netvsc_device *net_device,
+                                  struct net_device *ndev,
+                                  u64 request_id,
+                                  struct vmpacket_descriptor *desc)
+{
+       struct nvsp_message *nvmsg;
+
+       nvmsg = (struct nvsp_message *)((unsigned long)
+               desc + (desc->offset8 << 3));
+
+       switch (desc->type) {
+       case VM_PKT_COMP:
+               netvsc_send_completion(net_device, channel, device, desc);
+               break;
+
+       case VM_PKT_DATA_USING_XFER_PAGES:
+               netvsc_receive(net_device, channel, device, desc);
+               break;
+
+       case VM_PKT_DATA_INBAND:
+               netvsc_receive_inband(device, net_device, nvmsg);
+               break;
+
+       default:
+               netdev_err(ndev, "unhandled packet type %d, tid %llx\n",
+                          desc->type, request_id);
+               break;
+       }
+}
+
+
 void netvsc_channel_cb(void *context)
 {
        int ret;
@@ -1153,7 +1186,7 @@ void netvsc_channel_cb(void *context)
        unsigned char *buffer;
        int bufferlen = NETVSC_PACKET_SIZE;
        struct net_device *ndev;
-       struct nvsp_message *nvmsg;
+       bool need_to_commit = false;
 
        if (channel->primary_channel != NULL)
                device = channel->primary_channel->device_obj;
@@ -1167,39 +1200,36 @@ void netvsc_channel_cb(void *context)
        buffer = get_per_channel_state(channel);
 
        do {
+               desc = get_next_pkt_raw(channel);
+               if (desc != NULL) {
+                       netvsc_process_raw_pkt(device,
+                                              channel,
+                                              net_device,
+                                              ndev,
+                                              desc->trans_id,
+                                              desc);
+
+                       put_pkt_raw(channel, desc);
+                       need_to_commit = true;
+                       continue;
+               }
+               if (need_to_commit) {
+                       need_to_commit = false;
+                       commit_rd_index(channel);
+               }
+
                ret = vmbus_recvpacket_raw(channel, buffer, bufferlen,
                                           &bytes_recvd, &request_id);
                if (ret == 0) {
                        if (bytes_recvd > 0) {
                                desc = (struct vmpacket_descriptor *)buffer;
-                               nvmsg = (struct nvsp_message *)((unsigned long)
-                                        desc + (desc->offset8 << 3));
-                               switch (desc->type) {
-                               case VM_PKT_COMP:
-                                       netvsc_send_completion(net_device,
-                                                               channel,
-                                                               device, desc);
-                                       break;
-
-                               case VM_PKT_DATA_USING_XFER_PAGES:
-                                       netvsc_receive(net_device, channel,
-                                                      device, desc);
-                                       break;
-
-                               case VM_PKT_DATA_INBAND:
-                                       netvsc_receive_inband(device,
-                                                             net_device,
-                                                             nvmsg);
-                                       break;
-
-                               default:
-                                       netdev_err(ndev,
-                                                  "unhandled packet type %d, "
-                                                  "tid %llx len %d\n",
-                                                  desc->type, request_id,
-                                                  bytes_recvd);
-                                       break;
-                               }
+                               netvsc_process_raw_pkt(device,
+                                                      channel,
+                                                      net_device,
+                                                      ndev,
+                                                      request_id,
+                                                      desc);
+
 
                        } else {
                                /*
--

1.7.4.1

#2 lore raw
Quoted 18 lines

-----Original Message-----
From: Linus Torvalds [mailto:[email protected]]
Sent: Thursday, June 9, 2016 5:12 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; lkml <linux- [email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next] netvsc: Use the new in-place consumption APIs in the rx path

Srinivasan,

these are all sent through linuxonhyperv.com, and fail DMARC because
they have a microsoft.com address but no valid DKIM.

Quoted 6 lines

Please fix your email setup. You need to go through the real microsoft smtp servers if you use a microsoft.com address. Or you need to get linuxonhyperv.com fixed as a smtp server with the proper MS email signing.

Linus

Thanks Linus, we will fix our email setup.

Regards,

K. Y

Quoted 139 lines · K. Y. Srinivasan
Quoted 1 line

Use the new APIs for eliminating a copy on the receive path. These new APIs

also

Quoted 10 lines

help in minimizing the number of memory barriers we end up issuing (in the ringbuffer code) since we can better control when we want to expose the ring state to the host.

---
 drivers/net/hyperv/netvsc.c |   88 +++++++++++++++++++++++++++++---------

-----

drivers/net/hyperv/netvsc.c static inline void netvsc_receive_inband(struct

Quoted 7 lines
 1 files changed, 59 insertions(+), 29 deletions(-)
drivers/net/hyperv/netvsc.c +0 -0
index 719cb35..8cd4c19 100644
@@ -1141,6 +1141,39 @@ static inline void netvsc_receive_inband(struct

hv_device *hdev,

Quoted 116 lines
drivers/net/hyperv/netvsc.c +59 -30
        }
 }
 
+static void netvsc_process_raw_pkt(struct hv_device *device,
+                                  struct vmbus_channel *channel,
+                                  struct netvsc_device *net_device,
+                                  struct net_device *ndev,
+                                  u64 request_id,
+                                  struct vmpacket_descriptor *desc)
+{
+       struct nvsp_message *nvmsg;
+
+       nvmsg = (struct nvsp_message *)((unsigned long)
+               desc + (desc->offset8 << 3));
+
+       switch (desc->type) {
+       case VM_PKT_COMP:
+               netvsc_send_completion(net_device, channel, device, desc);
+               break;
+
+       case VM_PKT_DATA_USING_XFER_PAGES:
+               netvsc_receive(net_device, channel, device, desc);
+               break;
+
+       case VM_PKT_DATA_INBAND:
+               netvsc_receive_inband(device, net_device, nvmsg);
+               break;
+
+       default:
+               netdev_err(ndev, "unhandled packet type %d, tid %llx\n",
+                          desc->type, request_id);
+               break;
+       }
+}
+
+
 void netvsc_channel_cb(void *context)
 {
        int ret;
@@ -1153,7 +1186,7 @@ void netvsc_channel_cb(void *context)
        unsigned char *buffer;
        int bufferlen = NETVSC_PACKET_SIZE;
        struct net_device *ndev;
-       struct nvsp_message *nvmsg;
+       bool need_to_commit = false;
 
        if (channel->primary_channel != NULL)
                device = channel->primary_channel->device_obj;
@@ -1167,39 +1200,36 @@ void netvsc_channel_cb(void *context)
        buffer = get_per_channel_state(channel);
 
        do {
+               desc = get_next_pkt_raw(channel);
+               if (desc != NULL) {
+                       netvsc_process_raw_pkt(device,
+                                              channel,
+                                              net_device,
+                                              ndev,
+                                              desc->trans_id,
+                                              desc);
+
+                       put_pkt_raw(channel, desc);
+                       need_to_commit = true;
+                       continue;
+               }
+               if (need_to_commit) {
+                       need_to_commit = false;
+                       commit_rd_index(channel);
+               }
+
                ret = vmbus_recvpacket_raw(channel, buffer, bufferlen,
                                           &bytes_recvd, &request_id);
                if (ret == 0) {
                        if (bytes_recvd > 0) {
                                desc = (struct vmpacket_descriptor *)buffer;
-                               nvmsg = (struct nvsp_message *)((unsigned long)
-                                        desc + (desc->offset8 << 3));
-                               switch (desc->type) {
-                               case VM_PKT_COMP:
-                                       netvsc_send_completion(net_device,
-                                                               channel,
-                                                               device, desc);
-                                       break;
-
-                               case VM_PKT_DATA_USING_XFER_PAGES:
-                                       netvsc_receive(net_device, channel,
-                                                      device, desc);
-                                       break;
-
-                               case VM_PKT_DATA_INBAND:
-                                       netvsc_receive_inband(device,
-                                                             net_device,
-                                                             nvmsg);
-                                       break;
-
-                               default:
-                                       netdev_err(ndev,
-                                                  "unhandled packet type %d, "
-                                                  "tid %llx len %d\n",
-                                                  desc->type, request_id,
-                                                  bytes_recvd);
-                                       break;
-                               }
+                               netvsc_process_raw_pkt(device,
+                                                      channel,
+                                                      net_device,
+                                                      ndev,
+                                                      request_id,
+                                                      desc);
+
 
                        } else {
                                /*
--

1.7.4.1

#3 lore raw
Quoted 32 lines

-----Original Message-----
From: KY Srinivasan
Sent: Thursday, June 9, 2016 5:16 PM
To: 'Linus Torvalds' <[email protected]>
Cc: [email protected]; [email protected]; lkml <linux- [email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH net-next] netvsc: Use the new in-place consumption APIs in the rx path

Quoted 9 lines

-----Original Message-----
From: Linus Torvalds [mailto:[email protected]]
Sent: Thursday, June 9, 2016 5:12 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; lkml <linux- [email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next] netvsc: Use the new in-place consumption APIs

in

Quoted 7 lines

the rx path

Srinivasan,

these are all sent through linuxonhyperv.com, and fail DMARC because
they have a microsoft.com address but no valid DKIM.

Quoted 8 lines
Quoted 6 lines

Please fix your email setup. You need to go through the real microsoft smtp servers if you use a microsoft.com address. Or you need to get linuxonhyperv.com fixed as a smtp server with the proper MS email signing.

Linus

Thanks Linus, we will fix our email setup.

We have now addressed this issue (kind of). We will continue to send our patches from linuxonhyperv.com; however the "from" address will be [email protected]. We are working on the longer term solution that won't need this weird "from" address.

David, based on this comment from Linus, you have deferred this patch - as far as I know there were no other comments for me to address. Should I resend the patch.

Regards,

K. Y

Quoted 147 lines

Regards,

K. Y

Quoted 3 lines · K. Y. Srinivasan
Quoted 1 line

Use the new APIs for eliminating a copy on the receive path. These new

APIs

Quoted 2 lines

also

Quoted 1 line

help in minimizing the number of memory barriers we end up issuing (in

the

Quoted 1 line
Quoted 1 line

ringbuffer code) since we can better control when we want to expose the

ring

Quoted 8 lines
Quoted 8 lines

state to the host.

---
 drivers/net/hyperv/netvsc.c |   88 +++++++++++++++++++++++++++++-------

--

Quoted 125 lines

-----

drivers/net/hyperv/netvsc.c static inline void netvsc_receive_inband(struct

Quoted 7 lines
 1 files changed, 59 insertions(+), 29 deletions(-)
drivers/net/hyperv/netvsc.c +0 -0
index 719cb35..8cd4c19 100644
@@ -1141,6 +1141,39 @@ static inline void netvsc_receive_inband(struct

hv_device *hdev,

Quoted 116 lines
drivers/net/hyperv/netvsc.c +59 -30
        }
 }
 
+static void netvsc_process_raw_pkt(struct hv_device *device,
+                                  struct vmbus_channel *channel,
+                                  struct netvsc_device *net_device,
+                                  struct net_device *ndev,
+                                  u64 request_id,
+                                  struct vmpacket_descriptor *desc)
+{
+       struct nvsp_message *nvmsg;
+
+       nvmsg = (struct nvsp_message *)((unsigned long)
+               desc + (desc->offset8 << 3));
+
+       switch (desc->type) {
+       case VM_PKT_COMP:
+               netvsc_send_completion(net_device, channel, device, desc);
+               break;
+
+       case VM_PKT_DATA_USING_XFER_PAGES:
+               netvsc_receive(net_device, channel, device, desc);
+               break;
+
+       case VM_PKT_DATA_INBAND:
+               netvsc_receive_inband(device, net_device, nvmsg);
+               break;
+
+       default:
+               netdev_err(ndev, "unhandled packet type %d, tid %llx\n",
+                          desc->type, request_id);
+               break;
+       }
+}
+
+
 void netvsc_channel_cb(void *context)
 {
        int ret;
@@ -1153,7 +1186,7 @@ void netvsc_channel_cb(void *context)
        unsigned char *buffer;
        int bufferlen = NETVSC_PACKET_SIZE;
        struct net_device *ndev;
-       struct nvsp_message *nvmsg;
+       bool need_to_commit = false;
 
        if (channel->primary_channel != NULL)
                device = channel->primary_channel->device_obj;
@@ -1167,39 +1200,36 @@ void netvsc_channel_cb(void *context)
        buffer = get_per_channel_state(channel);
 
        do {
+               desc = get_next_pkt_raw(channel);
+               if (desc != NULL) {
+                       netvsc_process_raw_pkt(device,
+                                              channel,
+                                              net_device,
+                                              ndev,
+                                              desc->trans_id,
+                                              desc);
+
+                       put_pkt_raw(channel, desc);
+                       need_to_commit = true;
+                       continue;
+               }
+               if (need_to_commit) {
+                       need_to_commit = false;
+                       commit_rd_index(channel);
+               }
+
                ret = vmbus_recvpacket_raw(channel, buffer, bufferlen,
                                           &bytes_recvd, &request_id);
                if (ret == 0) {
                        if (bytes_recvd > 0) {
                                desc = (struct vmpacket_descriptor *)buffer;
-                               nvmsg = (struct nvsp_message *)((unsigned long)
-                                        desc + (desc->offset8 << 3));
-                               switch (desc->type) {
-                               case VM_PKT_COMP:
-                                       netvsc_send_completion(net_device,
-                                                               channel,
-                                                               device, desc);
-                                       break;
-
-                               case VM_PKT_DATA_USING_XFER_PAGES:
-                                       netvsc_receive(net_device, channel,
-                                                      device, desc);
-                                       break;
-
-                               case VM_PKT_DATA_INBAND:
-                                       netvsc_receive_inband(device,
-                                                             net_device,
-                                                             nvmsg);
-                                       break;
-
-                               default:
-                                       netdev_err(ndev,
-                                                  "unhandled packet type %d, "
-                                                  "tid %llx len %d\n",
-                                                  desc->type, request_id,
-                                                  bytes_recvd);
-                                       break;
-                               }
+                               netvsc_process_raw_pkt(device,
+                                                      channel,
+                                                      net_device,
+                                                      ndev,
+                                                      request_id,
+                                                      desc);
+
 
                        } else {
                                /*
--

1.7.4.1