Skip to contentSkip to conversation

add mtu set in virtio

PATCH Superseded souvikdey33 2 participants 5 messages Aug 27, 2016 – Aug 29, 2016 Network drivers

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add mtu set in virtio

This functionality is required mostly in the cloud infrastructure. For example, if we use gre or vxlan network between compute and controller, then we should not use 1500 mtu in the guest as with encapsulation the sixe of the packet will be more and will get dropped in the infrastructure. So, in that case we should honor the mtu size sent by the dhcp server and configure the same on the virtual interfaces in the guest. This will also keep a consistent mtu through out the infrastructure.

souvikdey33 (1):

 drivers/net/virtio/virtio_ethdev.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Quoted 1 line

From 2e4b391fe90ba5e617611e341a7d260dd3dd9144 Mon Sep 17 00:00:00 2001

From: souvikdey33 <[email protected]>
Date: Fri, 26 Aug 2016 20:46:21 -0400
Subject: [PATCH v1] Signed-off-by: Souvik Dey <[email protected]>

Fixes 1fb8e8896ca8 ("Signed-off-by: Souvik Dey <[email protected]>")

Virtio interfaces should also support setting of mtu, as in case of cloud it is expected to have the consistent mtu across the infrastructure that the dhcp server sends and not hardcoded to 1500(default).

---
 drivers/net/virtio/virtio_ethdev.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/net/virtio/virtio_ethdev.c +12 -0
index 07d6449..da16ad4 100644
@@ -92,6 +92,7 @@ static void virtio_mac_addr_add(struct rte_eth_dev *dev,
 static void virtio_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
 static void virtio_mac_addr_set(struct rte_eth_dev *dev,
 				struct ether_addr *mac_addr);
+static int  virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
 
 static int virtio_dev_queue_stats_mapping_set(
 	__rte_unused struct rte_eth_dev *eth_dev,
@@ -652,6 +653,16 @@ virtio_dev_allmulticast_disable(struct rte_eth_dev *dev)
 		PMD_INIT_LOG(ERR, "Failed to disable allmulticast");
 }
 
+static int 
+virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) 
+{
+   struct virtio_hw *hw = dev->data->dev_private;
+   if (unlikely(mtu < (uint32_t)hw->vtnet_hdr_size + ETHER_HDR_LEN)) {
+       return -1;
+   }
+   return 0;
+}
+
 /*
  * dev_ops for virtio, bare necessities for basic operation
  */
@@ -664,6 +675,7 @@ static const struct eth_dev_ops virtio_eth_dev_ops = {
 	.promiscuous_disable     = virtio_dev_promiscuous_disable,
 	.allmulticast_enable     = virtio_dev_allmulticast_enable,
 	.allmulticast_disable    = virtio_dev_allmulticast_disable,
+	.mtu_set                 = virtio_mtu_set,
 
 	.dev_infos_get           = virtio_dev_info_get,
 	.stats_get               = virtio_dev_stats_get,
Signature · 1 line
2.9.3.windows.1
#1 lore raw
Quoted 9 lines · On Fri, 26 Aug 2016 20:54:28 -0400 souvikdey33 <[email protected]> wrote:

This functionality is required mostly in the cloud infrastructure. For example, if we use gre or vxlan network between compute and controller, then we should not use 1500 mtu in the guest as with encapsulation the sixe of the packet will be more and will get dropped in the infrastructure. So, in that case we should honor the mtu size sent by the dhcp server and configure the same on the virtual interfaces in the guest. This will also keep a consistent mtu through out the infrastructure.

Quoted 6 lines

souvikdey33 (1):

 drivers/net/virtio/virtio_ethdev.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Thanks for the patch, it is a good step forward but it looks like more code is needed to do this safely. At a minimum, need to check that MTU is not greater than VIRTIO_MAX_RX_PKTLEN. And error return should be negative errno not -1.

Something like:
if (mtu < VIRTIO_MIN_MTU || mtu > VIRTIO_MAX_RX_PKTLEN)

	return -EINVAL;

Looking at Linux driver, it allows MTU of up to 64K, yet DPDK only allows 9728. That should probably be fixed.

#2 lore raw

Hi ,
Currently as you have mentioned, I have changed the code to:
static int
virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)

 {
    struct virtio_hw *hw = dev->data->dev_private;

- if (unlikely(mtu < (uint32_t)hw->vtnet_hdr_size + ETHER_HDR_LEN)) {
- return -1;
+ if (unlikely(mtu < VIRTIO_MIN_RX_BUFSIZE || mtu > VIRTIO_MAX_RX_PKTLEN)) {
+ PMD_INIT_LOG(ERR,"Mtu should be between 64 and 9728."

+       return -EINVAL;
    }
    return 0;

}

Yes, we should support till 64K as the kernel does , but I need to go through the changes and test it properly before submitting it for review. Moreover I was thinking with the changes in the mtu, we should also support multi-segment buffers in kni. What do you suggest ?

--
Regards,
Souvik

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, August 27, 2016 8:16 PM
To: Dey, Souvik <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v1] add mtu set in virtio

Quoted 9 lines · On Fri, 26 Aug 2016 20:54:28 -0400 souvikdey33 <[email protected]> wrote:

This functionality is required mostly in the cloud infrastructure. For example, if we use gre or vxlan network between compute and controller, then we should not use 1500 mtu in the guest as with encapsulation the sixe of the packet will be more and will get dropped in the infrastructure. So, in that case we should honor the mtu size sent by the dhcp server and configure the same on the virtual interfaces in the guest. This will also keep a consistent mtu through out the infrastructure.

Quoted 6 lines

souvikdey33 (1):

 drivers/net/virtio/virtio_ethdev.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Thanks for the patch, it is a good step forward but it looks like more code is needed to do this safely. At a minimum, need to check that MTU is not greater than VIRTIO_MAX_RX_PKTLEN. And error return should be negative errno not -1.

Something like:
if (mtu < VIRTIO_MIN_MTU || mtu > VIRTIO_MAX_RX_PKTLEN)

	return -EINVAL;

Looking at Linux driver, it allows MTU of up to 64K, yet DPDK only allows 9728. That should probably be fixed.

#3 lore raw
Quoted 15 lines · Souvik

Hi ,
Currently as you have mentioned, I have changed the code to:
static int
virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)

 {
    struct virtio_hw *hw = dev->data->dev_private;
(quoted diff) +3 -2
-   if (unlikely(mtu < (uint32_t)hw->vtnet_hdr_size + ETHER_HDR_LEN)) {
-       return -1;
+   if (unlikely(mtu < VIRTIO_MIN_RX_BUFSIZE || mtu > VIRTIO_MAX_RX_PKTLEN)) {
+	   PMD_INIT_LOG(ERR,"Mtu should be between 64 and 9728."
+       return -EINVAL;
    }
    return 0;
 }
Quoted 1 line

Yes, we should support till 64K as the kernel does , but I need to go through the changes and test it properly before submitting it for review. Moreover I was thinking with the changes in the mtu, we should also support multi-segment buffers in kni. What do you suggest ?

This looks good, but you really don't need likely/unlikely in this code. It is not at all performance critical.

author Reviewed-by Stephen Hemminger
#4 lore raw

Thanks , I will remove the unlikely from the conditionally statement. Below is the complete patch :

Quoted 1 line

From 2e4b391fe90ba5e617611e341a7d260dd3dd9144 Mon Sep 17 00:00:00 2001

From: souvikdey33 <[email protected]>
Date: Fri, 26 Aug 2016 20:46:21 -0400
Subject: [PATCH v2 2/3] Signed-off-by: Souvik Dey <[email protected]>

Fixes 1fb8e8896ca8 ("Signed-off-by: Souvik Dey <[email protected]>")

Virtio interfaces should also support setting of mtu, as in case of cloud it is expected to have the consistent mtu across the infrastructure that the dhcp server sends and not hardcoded to 1500(default).

---
 drivers/net/virtio/virtio_ethdev.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/net/virtio/virtio_ethdev.c +12 -0
index 07d6449..da16ad4 100644
@@ -92,6 +92,7 @@ static void virtio_mac_addr_add(struct rte_eth_dev *dev,
 static void virtio_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
 static void virtio_mac_addr_set(struct rte_eth_dev *dev,
 				struct ether_addr *mac_addr);
+static int  virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
 
 static int virtio_dev_queue_stats_mapping_set(
 	__rte_unused struct rte_eth_dev *eth_dev,
@@ -652,6 +653,16 @@ virtio_dev_allmulticast_disable(struct rte_eth_dev *dev)
 		PMD_INIT_LOG(ERR, "Failed to disable allmulticast");
 }
 
+static int 
+virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) 
+{
+   struct virtio_hw *hw = dev->data->dev_private;
+   if (mtu < VIRTIO_MIN_RX_BUFSIZE || mtu > VIRTIO_MAX_RX_PKTLEN) {
+	   PMD_INIT_LOG(ERR,"Mtu should be between 64 and 9728."
+          return -EINVAL;
+   }
+   return 0;
+}
+
 /*
  * dev_ops for virtio, bare necessities for basic operation

*/
@@ -664,6 +675,7 @@ static const struct eth_dev_ops virtio_eth_dev_ops = {

 	.promiscuous_disable     = virtio_dev_promiscuous_disable,
 	.allmulticast_enable     = virtio_dev_allmulticast_enable,
 	.allmulticast_disable    = virtio_dev_allmulticast_disable,
+	.mtu_set                 = virtio_mtu_set,

.dev_infos_get = virtio_dev_info_get,
.stats_get = virtio_dev_stats_get,

Signature · 7 lines
2.9.3.windows.1

As I am submitting to DPDK for the first time can you please guide with the next steps.

--
Regards,
Souvik

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, August 29, 2016 3:33 PM
To: Dey, Souvik <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v1] add mtu set in virtio

Quoted 14 lines · Souvik

Hi ,
Currently as you have mentioned, I have changed the code to:
static int

 virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)  {
    struct virtio_hw *hw = dev->data->dev_private;
(quoted diff) +3 -2
-   if (unlikely(mtu < (uint32_t)hw->vtnet_hdr_size + ETHER_HDR_LEN)) {
-       return -1;
+   if (unlikely(mtu < VIRTIO_MIN_RX_BUFSIZE || mtu > VIRTIO_MAX_RX_PKTLEN)) {
+	   PMD_INIT_LOG(ERR,"Mtu should be between 64 and 9728."
+       return -EINVAL;
    }
    return 0;
 }
Quoted 1 line

Yes, we should support till 64K as the kernel does , but I need to go through the changes and test it properly before submitting it for review. Moreover I was thinking with the changes in the mtu, we should also support multi-segment buffers in kni. What do you suggest ?

This looks good, but you really don't need likely/unlikely in this code. It is not at all performance critical.