Skip to contentSkip to conversation

net/virtio: add set_mtu in virtio

PATCH Superseded Dey 4 participants 15 messages Sep 21, 2016 – Sep 28, 2016 Network drivers

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Dey

author
#0 lore raw

PATCH v6 1/1 net/virtio: add set_mtu in virtio

From: souvikdey33 <[email protected]>

Virtio interfaces do not currently allow the user to specify a particular Maximum Transmission Unit (MTU).Consequently, the MTU of Virtio interfaces is typically set to the Ethernet default value of 1500.
This is problematic in the case of cloud deployments, in which a specific (and potentially non-standard) MTU needs to be set by a DHCP server, which needs to be honored by all interfaces across the traffic path.To acheive this Virtio interfaces should support setting of MTU.
In case when GRE/VXLAN tunneling is used for internal communication, there will be an overhead added by the infrastructure in the packet over and above the ETHER MTU of 1518. So to take care of this overhead in these cases the DHCP server corrects the L3 MTU to 1454. But since virtio interfaces was not having the MTU set functionality that MTU sent by the DHCP server was ignored and the instance will still send packets with 1500 MTU which after encapsulation will become more than 1518 and eventually gets dropped in the infrastructure.
By adding an additional 'set_mtu' function to the Virtio driver, we can honor the MTU sent by the DHCP server. The dhcp server/controller can then leverage this 'set_mtu' functionality to resolve the above mentioned issue of packets getting dropped due to incorrect size.

---
Changes in v6:
- Description of change corrected
- Corrected the identations
- Corrected the subject line too
- The From line was also not correct
Changes in v5:
- Fix log message for out-of-bounds MTU parameter in virtio_mtu_set
- Calculate frame size, based on 'mtu' parameter
- Corrected the upper bound and lower bound checks in virtio_mtu_set Changes in v4: Incorporated review comments.
Changes in v3: Corrected few style errors as reported by sys-stv. Changes in v2: Incorporated review comments.

 drivers/net/virtio/virtio_ethdev.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/virtio/virtio_ethdev.c +0 -0
index 423c597..1dbfea6 100644

+
+#define VLAN_TAG_SIZE 4 /* 802.3ac tag (not DMA'd) */
+
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) +{

+       struct rte_eth_dev_info dev_info;
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + ETHER_CRC_LEN + VLAN_TAG_SIZE;
+       uint32_t frame_size = mtu + ether_hdr_len;

+
+ virtio_dev_info_get(dev, &dev_info);
+
+ if (mtu < ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen) {
+ PMD_INIT_LOG(ERR, "MTU should be between %d and %d\n",
+ ETHER_MIN_MTU,
+ (dev_info.max_rx_pktlen - ether_hdr_len));
+ return -EINVAL;
+ }
+ return 0;
+}

/*
* dev_ops for virtio, bare necessities for basic operation */
@@ -677,7 +685,6 @@ static const struct eth_dev_ops virtio_eth_dev_ops = {

 	.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,
 	.xstats_get              = virtio_dev_xstats_get,
Signature · 1 line
2.9.3.windows.1
#1 lore raw
Quoted 10 lines · On Wed, 21 Sep 2016 19:11:47 -0400 Dey <[email protected]> wrote:
(quoted diff) +9 -0
+
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
+
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
+{
+       struct rte_eth_dev_info dev_info;
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + ETHER_CRC_LEN + VLAN_TAG_SIZE;
+       uint32_t frame_size = mtu + ether_hdr_len;
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+       virtio_dev_info_get(dev, &dev_info);
+
+       if (mtu < ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen) {
+               PMD_INIT_LOG(ERR, "MTU should be between %d and %d\n",
+                               ETHER_MIN_MTU,
+                               (dev_info.max_rx_pktlen - ether_hdr_len));
+               return -EINVAL;
+       }
+       return 0;
+}

I am fine with the general idea of this patch but:
1. Calling virtio_dev_info_get is needlessly wasteful when all you want is to access the max packet length. Since max_rx_pktlen is always VIRTIO_MAX_RX_PKTLEN, please just use that.

2. Defining VLAN_TAG_SIZE is irrelevant if doing vlan offload.

3. Virtio doesn't insert CRC, therefore CRC_LEN is irrelevant

#2 lore raw

Answers inline.

--
Regards,
Souvik

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, September 21, 2016 7:22 PM
To: Dey, Souvik <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 9 lines · On Wed, 21 Sep 2016 19:11:47 -0400 Dey <[email protected]> wrote:
(quoted diff) +8 -0
+
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
+
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) {
+       struct rte_eth_dev_info dev_info;
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + ETHER_CRC_LEN + VLAN_TAG_SIZE;
+       uint32_t frame_size = mtu + ether_hdr_len;
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+       virtio_dev_info_get(dev, &dev_info);
+
+       if (mtu < ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen) {
+               PMD_INIT_LOG(ERR, "MTU should be between %d and %d\n",
+                               ETHER_MIN_MTU,
+                               (dev_info.max_rx_pktlen - ether_hdr_len));
+               return -EINVAL;
+       }
+       return 0;
+}

I am fine with the general idea of this patch but:
1. Calling virtio_dev_info_get is needlessly wasteful when all you want
is to access the max packet length. Since max_rx_pktlen is always
VIRTIO_MAX_RX_PKTLEN, please just use that.
[Dey, Souvik] I am using the virtio_dev_info_get as in future can/may support the max_rx_pktlen as a variable to be set by the application. This will keep the changes future proof. As we need to support till 65535 instead of 9728 as the linux does.

2. Defining VLAN_TAG_SIZE is irrelevant if doing vlan offload.
[Dey, Souvik] vlan offload is not mandatory. Se again still have vlan being sent up to the application. In that case we need to consider the vlan length in the Ethernet size.

3. Virtio doesn't insert CRC, therefore CRC_LEN is irrelevant
[Dey, Souvik] I am not sure of this. Mark commented earlier to consider this length too. Mark what do you suggest ?

#3 lore raw
Quoted 33 lines · Souvik

Answers inline.

--
Regards,
Souvik

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, September 21, 2016 7:22 PM
To: Dey, Souvik <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 17 lines · On Wed, 21 Sep 2016 19:11:47 -0400 Dey <[email protected]> wrote:
(quoted diff) +16 -0
+
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
+
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) {
+       struct rte_eth_dev_info dev_info;
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + ETHER_CRC_LEN + VLAN_TAG_SIZE;
+       uint32_t frame_size = mtu + ether_hdr_len;
+
+       virtio_dev_info_get(dev, &dev_info);
+
+       if (mtu < ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen) {
+               PMD_INIT_LOG(ERR, "MTU should be between %d and %d\n",
+                               ETHER_MIN_MTU,
+                               (dev_info.max_rx_pktlen - ether_hdr_len));
+               return -EINVAL;
+       }
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+       return 0;
+}  

I am fine with the general idea of this patch but:
1. Calling virtio_dev_info_get is needlessly wasteful when all you want
is to access the max packet length. Since max_rx_pktlen is always
VIRTIO_MAX_RX_PKTLEN, please just use that.
[Dey, Souvik] I am using the virtio_dev_info_get as in future can/may support the max_rx_pktlen as a variable to be set by the application. This will keep the changes future proof. As we need to support till 65535 instead of 9728 as the linux does.

Fine, then just dereference hw->rx_max_pktlen. Driver code can/should reference its own data directly.

Quoted 3 lines

2. Defining VLAN_TAG_SIZE is irrelevant if doing vlan offload.
[Dey, Souvik] vlan offload is not mandatory. Se again still have vlan being sent up to the application. In that case we need to consider the vlan length in the Ethernet size.

The code needs to handle both vlan offload (or not), correctly. You are assuming the worst case here.

Quoted 3 lines

3. Virtio doesn't insert CRC, therefore CRC_LEN is irrelevant
[Dey, Souvik] I am not sure of this. Mark commented earlier to consider this length too. Mark what do you suggest ?

Actually, the thing that matters is the size of the merge rx buf header, not the CRC.

The patch is still buggy.

#4 lore raw

I still fail to understand how the dev_info.max_rx_pktlen is wrong here, and the hw->rx_max_pktlen is defined at all ? If you see the other driver code we have used the same way there too. Also for the vlan part isn't it better the take the worst case for the mtu lower boundary check, as that will be valid for both vlan offload on and off cases.

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, September 21, 2016 9:45 PM
To: Dey, Souvik <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 34 lines · Souvik

Answers inline.

--
Regards,
Souvik

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, September 21, 2016 7:22 PM
To: Dey, Souvik <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 17 lines · On Wed, 21 Sep 2016 19:11:47 -0400 Dey <[email protected]> wrote:
(quoted diff) +16 -0
+
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
+
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) {
+       struct rte_eth_dev_info dev_info;
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + ETHER_CRC_LEN + VLAN_TAG_SIZE;
+       uint32_t frame_size = mtu + ether_hdr_len;
+
+       virtio_dev_info_get(dev, &dev_info);
+
+       if (mtu < ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen) {
+               PMD_INIT_LOG(ERR, "MTU should be between %d and %d\n",
+                               ETHER_MIN_MTU,
+                               (dev_info.max_rx_pktlen - ether_hdr_len));
+               return -EINVAL;
+       }
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+       return 0;
+}

I am fine with the general idea of this patch but:
1. Calling virtio_dev_info_get is needlessly wasteful when all you want
is to access the max packet length. Since max_rx_pktlen is always
VIRTIO_MAX_RX_PKTLEN, please just use that.
[Dey, Souvik] I am using the virtio_dev_info_get as in future can/may support the max_rx_pktlen as a variable to be set by the application. This will keep the changes future proof. As we need to support till 65535 instead of 9728 as the linux does.

Fine, then just dereference hw->rx_max_pktlen. Driver code can/should reference its own data directly.

Quoted 3 lines

2. Defining VLAN_TAG_SIZE is irrelevant if doing vlan offload.
[Dey, Souvik] vlan offload is not mandatory. Se again still have vlan being sent up to the application. In that case we need to consider the vlan length in the Ethernet size.

The code needs to handle both vlan offload (or not), correctly. You are assuming the worst case here.

Quoted 3 lines

3. Virtio doesn't insert CRC, therefore CRC_LEN is irrelevant [Dey,
Souvik] I am not sure of this. Mark commented earlier to consider this length too. Mark what do you suggest ?

Actually, the thing that matters is the size of the merge rx buf header, not the CRC.

The patch is still buggy.

#5 lore raw
In reply to Stephen Hemminger
Quoted 45 lines · Stephen Hemminger
Quoted 33 lines · Souvik

Answers inline.

--
Regards,
Souvik

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, September 21, 2016 7:22 PM
To: Dey, Souvik <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 17 lines · On Wed, 21 Sep 2016 19:11:47 -0400 Dey <[email protected]> wrote:
(quoted diff) +16 -0
+
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
+
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) {
+       struct rte_eth_dev_info dev_info;
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + ETHER_CRC_LEN + VLAN_TAG_SIZE;
+       uint32_t frame_size = mtu + ether_hdr_len;
+
+       virtio_dev_info_get(dev, &dev_info);
+
+       if (mtu < ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen) {
+               PMD_INIT_LOG(ERR, "MTU should be between %d and %d\n",
+                               ETHER_MIN_MTU,
+                               (dev_info.max_rx_pktlen - ether_hdr_len));
+               return -EINVAL;
+       }
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+       return 0;
+}  

I am fine with the general idea of this patch but:
1. Calling virtio_dev_info_get is needlessly wasteful when all you want
is to access the max packet length. Since max_rx_pktlen is always
VIRTIO_MAX_RX_PKTLEN, please just use that.
[Dey, Souvik] I am using the virtio_dev_info_get as in future can/may support the max_rx_pktlen as a variable to be set by the application. This will keep the changes future proof. As we need to support till 65535 instead of 9728 as the linux does.

Quoted 2 lines

Fine, then just dereference hw->rx_max_pktlen. Driver code can/should reference its own data directly.

Dey, maybe you could just use VIRTIO_MAX_RX_PKTLEN here, like what you did in early versions.

Quoted 6 lines
Quoted 3 lines

2. Defining VLAN_TAG_SIZE is irrelevant if doing vlan offload.
[Dey, Souvik] vlan offload is not mandatory. Se again still have vlan being sent up to the application. In that case we need to consider the vlan length in the Ethernet size.

The code needs to handle both vlan offload (or not), correctly. You are assuming the worst case here.

I think we are fine here to assume worst case.

Quoted 5 lines
Quoted 3 lines

3. Virtio doesn't insert CRC, therefore CRC_LEN is irrelevant
[Dey, Souvik] I am not sure of this. Mark commented earlier to consider this length too. Mark what do you suggest ?

Actually, the thing that matters is the size of the merge rx buf header, not the CRC.

Right.

	--yliu
Quoted 3 lines

The patch is still buggy.

#6 lore raw
Quoted 67 lines

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 36 lines · Stephen Hemminger
Quoted 33 lines · Souvik

Answers inline.

--
Regards,
Souvik

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, September 21, 2016 7:22 PM
To: Dey, Souvik <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 17 lines · On Wed, 21 Sep 2016 19:11:47 -0400 Dey <[email protected]> wrote:
(quoted diff) +16 -0
+
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
+
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) {
+       struct rte_eth_dev_info dev_info;
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + ETHER_CRC_LEN + VLAN_TAG_SIZE;
+       uint32_t frame_size = mtu + ether_hdr_len;
+
+       virtio_dev_info_get(dev, &dev_info);
+
+       if (mtu < ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen) {
+               PMD_INIT_LOG(ERR, "MTU should be between %d and %d\n",
+                               ETHER_MIN_MTU,
+                               (dev_info.max_rx_pktlen - ether_hdr_len));
+               return -EINVAL;
+       }
Quoted 8 lines
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+       return 0;
+}

I am fine with the general idea of this patch but:
1. Calling virtio_dev_info_get is needlessly wasteful when all you want is to access the max packet length. Since max_rx_pktlen is always VIRTIO_MAX_RX_PKTLEN, please just use that.
[Dey, Souvik] I am using the virtio_dev_info_get as in future can/may support the

max_rx_pktlen as a variable to be set by the application. This will keep the changes future proof. As we need to support till 65535 instead of 9728 as the linux does.

Quoted 3 lines

Fine, then just dereference hw->rx_max_pktlen. Driver code can/should reference its own data directly.

Dey, maybe you could just use VIRTIO_MAX_RX_PKTLEN here, like what you did in early versions.

Quoted 3 lines
Quoted 3 lines

2. Defining VLAN_TAG_SIZE is irrelevant if doing vlan offload.
[Dey, Souvik] vlan offload is not mandatory. Se again still have vlan being sent up to

the application. In that case we need to consider the vlan length in the Ethernet size.

Quoted 3 lines

The code needs to handle both vlan offload (or not), correctly. You are assuming the worst case here.

I think we are fine here to assume worst case.

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

3. Virtio doesn't insert CRC, therefore CRC_LEN is irrelevant
[Dey, Souvik] I am not sure of this. Mark commented earlier to consider this length too.

Mark what do you suggest ?

Quoted 2 lines

Actually, the thing that matters is the size of the merge rx buf header, not the CRC.

Right.

My comments were based on my experience with DPDK ethdev PMDs - Stephen and Yuanhan have much more experience with virtio, so I'd go with their suggestion.

Quoted 5 lines
	--yliu
Quoted 3 lines

The patch is still buggy.

#7 lore raw

Hi Liu/Mark/Stephen,

I have tried to modify the code with all of your latest comments. Do let me know if this looks fine or you have more comments.

Changes done :

-- max frame ize is compare to VIRTIO_MAX_RX_PKTLEN instead of dev_info.max_rx_pktlen

-- removed the CRC_LEN from the ether_len calculation and added the merge rx buf hdr len. ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_SIZE + hw->vtnet_hdr_size

-- Still retained the VLAN Size as the worst case scenario.

--

drivers/net/virtio/virtio_ethdev.c | 16 ++++++++++++++++

1 file changed, 16 insertions(+)
drivers/net/virtio/virtio_ethdev.c +0 -0

index 423c597..1dbfea6 100644

--- a/drivers/net/virtio/virtio_ethdev.c

+++ b/drivers/net/virtio/virtio_ethdev.c

@@ -653,12 +653,20 @@ virtio_dev_allmulticast_disable(struct rte_eth_dev *dev)

                PMD_INIT_LOG(ERR, "Failed to disable allmulticast");

}

+#define VLAN_TAG_SIZE 4 /* 802.3ac tag (not DMA'd) */

+

+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)

+{

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

+ uint32_t ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_SIZE + hw->vtnet_hdr_size;

+ uint32_t frame_size = mtu + ether_hdr_len;

+

+ if (mtu < ETHER_MIN_MTU || frame_size > VIRTIO_MAX_RX_PKTLEN ) {

+ PMD_INIT_LOG(ERR, "MTU should be between %d and %d\n",

+ ETHER_MIN_MTU, VIRTIO_MAX_RX_PKTLEN);

+ return -EINVAL;

+ }

+ return 0;

+}

/*

* dev_ops for virtio, bare necessities for basic operation

*/

@@ -677,7 +685,6 @@ static const struct eth_dev_ops virtio_eth_dev_ops = {

.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,

.xstats_get = virtio_dev_xstats_get,

--

Please do let me know if this looks good to you all. Thanks

--

Regards,

Souvik

-----Original Message-----
From: Kavanagh, Mark B [mailto:[email protected]]
Sent: Friday, September 23, 2016 5:08 AM
To: Yuanhan Liu <[email protected]>; Stephen Hemminger <[email protected]>
Cc: Dey, Souvik <[email protected]>; [email protected]
Subject: RE: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 148 lines

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 91 lines · Stephen Hemminger

On Thu, 22 Sep 2016 00:08:38 +0000

Quoted 85 lines · "Dey, Souvik" <[email protected]<mailto:[email protected]>> wrote:

Answers inline.

--

Regards,

Souvik

-----Original Message-----

From: Stephen Hemminger [mailto:[email protected]]

Sent: Wednesday, September 21, 2016 7:22 PM

To: Dey, Souvik <[email protected]<mailto:[email protected]>>

[email protected]<mailto:[email protected]>

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

On Wed, 21 Sep 2016 19:11:47 -0400

Quoted 27 lines · Dey <[email protected]<mailto:[email protected]>> wrote:
(quoted diff) +13 -0
+
 
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
 
+
 
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) {
 
+       struct rte_eth_dev_info dev_info;
 
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + ETHER_CRC_LEN + VLAN_TAG_SIZE;
 
+       uint32_t frame_size = mtu + ether_hdr_len;
 
+
 
+       virtio_dev_info_get(dev, &dev_info);
 
+
 
+       if (mtu < ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen) {
 
+               PMD_INIT_LOG(ERR, "MTU should be between %d and %d\n",
 
+                               ETHER_MIN_MTU,

Review

Quoted 10 lines
(quoted diff) +5 -0
 
+                               (dev_info.max_rx_pktlen - ether_hdr_len));
 
+               return -EINVAL;
 
+       }
 
+       return 0;
 
+}

I am fine with the general idea of this patch but:

1. Calling virtio_dev_info_get is needlessly wasteful when all you want

is to access the max packet length. Since max_rx_pktlen is always

VIRTIO_MAX_RX_PKTLEN, please just use that.

[Dey, Souvik] I am using the virtio_dev_info_get as in future

can/may support the

max_rx_pktlen as a variable to be set by the application. This will

keep the changes future proof. As we need to support till 65535 instead of 9728 as the linux does.

Quoted 5 lines

Fine, then just dereference hw->rx_max_pktlen. Driver code can/should

reference its own data directly.

Dey, maybe you could just use VIRTIO_MAX_RX_PKTLEN here, like what you

did in early versions.

Quoted 7 lines
Quoted 7 lines

2. Defining VLAN_TAG_SIZE is irrelevant if doing vlan offload.

[Dey, Souvik] vlan offload is not mandatory. Se again still have

vlan being sent up to

the application. In that case we need to consider the vlan length in the Ethernet size.

Quoted 5 lines

The code needs to handle both vlan offload (or not), correctly. You

are assuming the worst case here.

I think we are fine here to assume worst case.

Quoted 5 lines
Quoted 5 lines

3. Virtio doesn't insert CRC, therefore CRC_LEN is irrelevant

[Dey, Souvik] I am not sure of this. Mark commented earlier to consider this length too.

Mark what do you suggest ?

Quoted 1 line
Quoted 5 lines
Quoted 1 line

Actually, the thing that matters is the size of the merge rx buf header, not the CRC.

Right.

My comments were based on my experience with DPDK ethdev PMDs - Stephen and Yuanhan have much more experience with virtio, so I'd go with their suggestion.

Quoted 9 lines

           --yliu
Quoted 5 lines

The patch is still buggy.

#8 lore raw

Hi Stephen,

Are you okay with this change?

	--yliu
Quoted 302 lines · Souvik

Hi Liu/Mark/Stephen,

I have tried to modify the code with all of your latest comments.
Do let me know if this looks fine or you have more comments.

Changes done :

-- max frame ize is compare to VIRTIO_MAX_RX_PKTLEN instead of dev_info.max_rx_pktlen

-- removed the CRC_LEN from the ether_len calculation and added the merge rx buf hdr len. ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_SIZE + hw->vtnet_hdr_size

-- Still retained the VLAN Size as the worst case scenario.

--

drivers/net/virtio/virtio_ethdev.c | 16 ++++++++++++++++

1 file changed, 16 insertions(+)
drivers/net/virtio/ renamed from drivers/net/virtio/virtio_ethdev.c +0 -0

virtio_ethdev.c

index 423c597..1dbfea6 100644

--- a/drivers/net/virtio/virtio_ethdev.c

+++ b/drivers/net/virtio/virtio_ethdev.c

drivers/net/virtio/ renamed from drivers/net/virtio/virtio_ethdev.c +6 -0
@@ -653,12 +653,20 @@ virtio_dev_allmulticast_disable(struct rte_eth_dev *dev)
 
                PMD_INIT_LOG(ERR, "Failed to disable allmulticast");
 
 }
 
 
 
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
 
+
 
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 
+{
 
+            struct virtio_hw *hw = dev->data->dev_private;
 
+            uint32_t ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_SIZE + hw->

vtnet_hdr_size;

drivers/net/virtio/ renamed from drivers/net/virtio/virtio_ethdev.c +4 -0
+            uint32_t frame_size = mtu + ether_hdr_len;
 
+
 
+            if (mtu < ETHER_MIN_MTU || frame_size > VIRTIO_MAX_RX_PKTLEN ) {
 
+                           PMD_INIT_LOG(ERR, "MTU should be between %d and %d\

n",

drivers/net/virtio/ renamed from drivers/net/virtio/virtio_ethdev.c +5 -0
+                                         ETHER_MIN_MTU, VIRTIO_MAX_RX_PKTLEN);
 
+                           return -EINVAL;
 
+            }
 
+            return 0;
 
+}

/*

* dev_ops for virtio, bare necessities for basic operation

*/

drivers/net/virtio/ renamed from drivers/net/virtio/virtio_ethdev.c +1 -1
@@ -677,7 +685,6 @@ static const struct eth_dev_ops virtio_eth_dev_ops = {
 
             .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,
 
             .xstats_get              = virtio_dev_xstats_get,
 
--

Please do let me know if this looks good to you all. Thanks

--

Regards,

Souvik

-----Original Message-----
From: Kavanagh, Mark B [mailto:[email protected]]
Sent: Friday, September 23, 2016 5:08 AM
To: Yuanhan Liu <[email protected]>; Stephen Hemminger <[email protected]>
Cc: Dey, Souvik <[email protected]>; [email protected]
Subject: RE: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 4 lines

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 55 lines
Quoted 53 lines · Stephen Hemminger

On Thu, 22 Sep 2016 00:08:38 +0000

Quoted 47 lines · Souvik

Answers inline.

--

Regards,

Souvik

-----Original Message-----

From: Stephen Hemminger [mailto:[email protected]]

Sent: Wednesday, September 21, 2016 7:22 PM

To: Dey, Souvik <[email protected]>

[email protected]

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

On Wed, 21 Sep 2016 19:11:47 -0400

Quoted 13 lines · Dey
(quoted diff) +6 -0
+
 
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
 
+
 
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) {
 
+       struct rte_eth_dev_info dev_info;
 
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + ETHER_CRC_LEN +

VLAN_TAG_SIZE;

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 9 lines
(quoted diff) +5 -0
+       uint32_t frame_size = mtu + ether_hdr_len;
 
+
 
+       virtio_dev_info_get(dev, &dev_info);
 
+
 
+       if (mtu < ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen)

{

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 5 lines
(quoted diff) +3 -0
+               PMD_INIT_LOG(ERR, "MTU should be between %d and %d\n",
 
+                               ETHER_MIN_MTU,
 
+                               (dev_info.max_rx_pktlen -

ether_hdr_len));

Quoted 18 lines
Quoted 17 lines
Quoted 17 lines

Review

Quoted 7 lines
(quoted diff) +4 -0
+               return -EINVAL;
 
+       }
 
+       return 0;
 
+}

I am fine with the general idea of this patch but:

1. Calling virtio_dev_info_get is needlessly wasteful when all you want

is to access the max packet length. Since max_rx_pktlen is always

VIRTIO_MAX_RX_PKTLEN, please just use that.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

[Dey, Souvik] I am using the virtio_dev_info_get as in future

can/may support the

max_rx_pktlen as a variable to be set by the application. This will

keep the changes future proof. As we need to support till 65535 instead of

9728 as the linux does.

Quoted 16 lines
Quoted 5 lines

Fine, then just dereference hw->rx_max_pktlen. Driver code can/should

reference its own data directly.

Dey, maybe you could just use VIRTIO_MAX_RX_PKTLEN here, like what you

did in early versions.

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

2. Defining VLAN_TAG_SIZE is irrelevant if doing vlan offload.

[Dey, Souvik] vlan offload is not mandatory. Se again still have

vlan being sent up to

the application. In that case we need to consider the vlan length in the

Ethernet size.

Quoted 17 lines
Quoted 5 lines

The code needs to handle both vlan offload (or not), correctly. You

are assuming the worst case here.

I think we are fine here to assume worst case.

Quoted 5 lines
Quoted 5 lines

3. Virtio doesn't insert CRC, therefore CRC_LEN is irrelevant

[Dey, Souvik] I am not sure of this. Mark commented earlier to consider

this length too.

Quoted 5 lines

Mark what do you suggest ?

Quoted 3 lines

Actually, the thing that matters is the size of the merge rx buf header, not

the CRC.

Quoted 3 lines

Right.

My comments were based on my experience with DPDK ethdev PMDs - Stephen and Yuanhan have much more experience with virtio, so I'd go with their suggestion.

Quoted 9 lines

           --yliu
Quoted 5 lines

The patch is still buggy.

#9 lore raw

Hi All,
Any further updates/comments on this ?

--
Regards,
Souvik

-----Original Message-----
From: Yuanhan Liu [mailto:[email protected]]
Sent: Sunday, September 25, 2016 11:21 PM
To: Stephen Hemminger <[email protected]>
Cc: Dey, Souvik <[email protected]>; Kavanagh, Mark B <[email protected]>; [email protected]
Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Hi Stephen,

Are you okay with this change?

	--yliu
Quoted 321 lines · Souvik

Hi Liu/Mark/Stephen,

I have tried to modify the code with all of your latest comments.
Do let me know if this looks fine or you have more comments.

Changes done :

-- max frame ize is compare to VIRTIO_MAX_RX_PKTLEN instead of dev_info.max_rx_pktlen

-- removed the CRC_LEN from the ether_len calculation and added the merge rx buf hdr len. ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_SIZE + hw->vtnet_hdr_size

-- Still retained the VLAN Size as the worst case scenario.

--

drivers/net/virtio/virtio_ethdev.c | 16 ++++++++++++++++

1 file changed, 16 insertions(+)
drivers/net/virtio/ renamed from drivers/net/virtio/virtio_ethdev.c +0 -0

virtio_ethdev.c

index 423c597..1dbfea6 100644

--- a/drivers/net/virtio/virtio_ethdev.c

+++ b/drivers/net/virtio/virtio_ethdev.c

drivers/net/virtio/ renamed from drivers/net/virtio/virtio_ethdev.c +7 -0
@@ -653,12 +653,20 @@ virtio_dev_allmulticast_disable(struct 
 rte_eth_dev *dev)
 
                PMD_INIT_LOG(ERR, "Failed to disable allmulticast");
 
 }
 
 
 
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
 
+
 
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 
+{
 
+            struct virtio_hw *hw = dev->data->dev_private;
 
+            uint32_t ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_SIZE + 
+ hw->

vtnet_hdr_size;

drivers/net/virtio/ renamed from drivers/net/virtio/virtio_ethdev.c +6 -0
+            uint32_t frame_size = mtu + ether_hdr_len;
 
+
 
+            if (mtu < ETHER_MIN_MTU || frame_size > 
+ VIRTIO_MAX_RX_PKTLEN ) {
 
+                           PMD_INIT_LOG(ERR, "MTU should be between 
+ %d and %d\

n",

drivers/net/virtio/ renamed from drivers/net/virtio/virtio_ethdev.c +6 -0
+                                         ETHER_MIN_MTU, 
+ VIRTIO_MAX_RX_PKTLEN);
 
+                           return -EINVAL;
 
+            }
 
+            return 0;
 
+}

/*

* dev_ops for virtio, bare necessities for basic operation

*/

drivers/net/virtio/ renamed from drivers/net/virtio/virtio_ethdev.c +1 -1
@@ -677,7 +685,6 @@ static const struct eth_dev_ops virtio_eth_dev_ops 
 = {
 
             .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,
 
             .xstats_get              = virtio_dev_xstats_get,
 
--

Please do let me know if this looks good to you all. Thanks

--

Regards,

Souvik

-----Original Message-----
From: Kavanagh, Mark B [mailto:[email protected]]
Sent: Friday, September 23, 2016 5:08 AM
To: Yuanhan Liu <[email protected]>; Stephen Hemminger <[email protected]>
Cc: Dey, Souvik <[email protected]>; [email protected]
Subject: RE: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 4 lines

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 57 lines
Quoted 55 lines · Stephen Hemminger

On Thu, 22 Sep 2016 00:08:38 +0000

Quoted 49 lines · Souvik

Answers inline.

--

Regards,

Souvik

-----Original Message-----

From: Stephen Hemminger [mailto:[email protected]]

Sent: Wednesday, September 21, 2016 7:22 PM

To: Dey, Souvik <[email protected]>

[email protected]

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

On Wed, 21 Sep 2016 19:11:47 -0400

Quoted 15 lines · Dey
(quoted diff) +8 -0
+
 
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
 
+
 
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t 
+mtu) {
 
+       struct rte_eth_dev_info dev_info;
 
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + ETHER_CRC_LEN 
+ +

VLAN_TAG_SIZE;

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Review

Quoted 10 lines
(quoted diff) +6 -0
+       uint32_t frame_size = mtu + ether_hdr_len;
 
+
 
+       virtio_dev_info_get(dev, &dev_info);
 
+
 
+       if (mtu < ETHER_MIN_MTU || frame_size > 
+ dev_info.max_rx_pktlen)

{

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 6 lines
(quoted diff) +4 -0
+               PMD_INIT_LOG(ERR, "MTU should be between %d and 
+ %d\n",
 
+                               ETHER_MIN_MTU,
 
+                               (dev_info.max_rx_pktlen -

ether_hdr_len));

Quoted 20 lines
Quoted 19 lines
Quoted 19 lines

Review

Quoted 7 lines
(quoted diff) +4 -0
+               return -EINVAL;
 
+       }
 
+       return 0;
 
+}

I am fine with the general idea of this patch but:

1. Calling virtio_dev_info_get is needlessly wasteful when all
you want

is to access the max packet length. Since max_rx_pktlen is
always

VIRTIO_MAX_RX_PKTLEN, please just use that.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

[Dey, Souvik] I am using the virtio_dev_info_get as in future

can/may support the

max_rx_pktlen as a variable to be set by the application. This will

keep the changes future proof. As we need to support till 65535 instead of

9728 as the linux does.

Quoted 18 lines
Quoted 6 lines

Fine, then just dereference hw->rx_max_pktlen. Driver code can/should

reference its own data directly.

Dey, maybe you could just use VIRTIO_MAX_RX_PKTLEN here, like what you

did in early versions.

Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

2. Defining VLAN_TAG_SIZE is irrelevant if doing vlan offload.

[Dey, Souvik] vlan offload is not mandatory. Se again still have

vlan being sent up to

the application. In that case we need to consider the vlan length in the

Ethernet size.

Quoted 18 lines
Quoted 5 lines

The code needs to handle both vlan offload (or not), correctly. You

are assuming the worst case here.

I think we are fine here to assume worst case.

Quoted 6 lines
Quoted 6 lines

3. Virtio doesn't insert CRC, therefore CRC_LEN is irrelevant

[Dey, Souvik] I am not sure of this. Mark commented earlier to consider

this length too.

Quoted 6 lines

Mark what do you suggest ?

Quoted 4 lines

Actually, the thing that matters is the size of the merge rx buf header, not

the CRC.

Quoted 3 lines

Right.

My comments were based on my experience with DPDK ethdev PMDs -
Stephen and Yuanhan have much more experience with virtio, so I'd go with their suggestion.

Quoted 9 lines

           --yliu
Quoted 5 lines

The patch is still buggy.

#10 lore raw
In reply to Dey, Souvik
Quoted 108 lines · Souvik

Hi Liu/Mark/Stephen,

I have tried to modify the code with all of your latest comments. Do let me know if this looks fine or you have more comments.

Changes done :

-- max frame ize is compare to VIRTIO_MAX_RX_PKTLEN instead of dev_info.max_rx_pktlen

-- removed the CRC_LEN from the ether_len calculation and added the merge rx buf hdr len. ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_SIZE + hw->vtnet_hdr_size

-- Still retained the VLAN Size as the worst case scenario.

--

drivers/net/virtio/virtio_ethdev.c | 16 ++++++++++++++++

1 file changed, 16 insertions(+)
drivers/net/virtio/virtio_ethdev.c +0 -0

index 423c597..1dbfea6 100644

--- a/drivers/net/virtio/virtio_ethdev.c

+++ b/drivers/net/virtio/virtio_ethdev.c

drivers/net/virtio/virtio_ethdev.c +15 -0
@@ -653,12 +653,20 @@ virtio_dev_allmulticast_disable(struct rte_eth_dev *dev)
 
                PMD_INIT_LOG(ERR, "Failed to disable allmulticast");
 
 }
 
 
 
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
 
+
 
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 
+{
 
+            struct virtio_hw *hw = dev->data->dev_private;
 
+            uint32_t ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_SIZE + hw->vtnet_hdr_size;
 
+            uint32_t frame_size = mtu + ether_hdr_len;
 
+
 
+            if (mtu < ETHER_MIN_MTU || frame_size > VIRTIO_MAX_RX_PKTLEN ) {
 
+                           PMD_INIT_LOG(ERR, "MTU should be between %d and %d\n",
 
+                                         ETHER_MIN_MTU, VIRTIO_MAX_RX_PKTLEN);
 
+                           return -EINVAL;
 
+            }
 
+            return 0;
 
+}

/*

* dev_ops for virtio, bare necessities for basic operation

*/

drivers/net/virtio/virtio_ethdev.c +1 -1
@@ -677,7 +685,6 @@ static const struct eth_dev_ops virtio_eth_dev_ops = {
 
             .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,
 
             .xstats_get              = virtio_dev_xstats_get,
 
--

Please do let me know if this looks good to you all. Thanks

--

Regards,

Souvik

Quoted 159 lines

-----Original Message-----
From: Kavanagh, Mark B [mailto:[email protected]]
Sent: Friday, September 23, 2016 5:08 AM
To: Yuanhan Liu <[email protected]>; Stephen Hemminger <[email protected]>
Cc: Dey, Souvik <[email protected]>; [email protected]
Subject: RE: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 149 lines

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 91 lines · Stephen Hemminger

On Thu, 22 Sep 2016 00:08:38 +0000

Quoted 85 lines · "Dey, Souvik" <[email protected]<mailto:[email protected]>> wrote:

Answers inline.

--

Regards,

Souvik

-----Original Message-----

From: Stephen Hemminger [mailto:[email protected]]

Sent: Wednesday, September 21, 2016 7:22 PM

To: Dey, Souvik <[email protected]<mailto:[email protected]>>

[email protected]<mailto:[email protected]>

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

On Wed, 21 Sep 2016 19:11:47 -0400

Quoted 27 lines · Dey <[email protected]<mailto:[email protected]>> wrote:
(quoted diff) +13 -0
+
 
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
 
+
 
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) {
 
+       struct rte_eth_dev_info dev_info;
 
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + ETHER_CRC_LEN + VLAN_TAG_SIZE;
 
+       uint32_t frame_size = mtu + ether_hdr_len;
 
+
 
+       virtio_dev_info_get(dev, &dev_info);
 
+
 
+       if (mtu < ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen) {
 
+               PMD_INIT_LOG(ERR, "MTU should be between %d and %d\n",
 
+                               ETHER_MIN_MTU,

Review

Quoted 10 lines
(quoted diff) +5 -0
 
+                               (dev_info.max_rx_pktlen - ether_hdr_len));
 
+               return -EINVAL;
 
+       }
 
+       return 0;
 
+}

I am fine with the general idea of this patch but:

1. Calling virtio_dev_info_get is needlessly wasteful when all you want

is to access the max packet length. Since max_rx_pktlen is always

VIRTIO_MAX_RX_PKTLEN, please just use that.

[Dey, Souvik] I am using the virtio_dev_info_get as in future

can/may support the

max_rx_pktlen as a variable to be set by the application. This will

keep the changes future proof. As we need to support till 65535 instead of 9728 as the linux does.

Quoted 5 lines

Fine, then just dereference hw->rx_max_pktlen. Driver code can/should

reference its own data directly.

Dey, maybe you could just use VIRTIO_MAX_RX_PKTLEN here, like what you

did in early versions.

Quoted 7 lines
Quoted 7 lines

2. Defining VLAN_TAG_SIZE is irrelevant if doing vlan offload.

[Dey, Souvik] vlan offload is not mandatory. Se again still have

vlan being sent up to

the application. In that case we need to consider the vlan length in the Ethernet size.

Quoted 5 lines

The code needs to handle both vlan offload (or not), correctly. You

are assuming the worst case here.

I think we are fine here to assume worst case.

Quoted 5 lines
Quoted 5 lines

3. Virtio doesn't insert CRC, therefore CRC_LEN is irrelevant

[Dey, Souvik] I am not sure of this. Mark commented earlier to consider this length too.

Mark what do you suggest ?

Quoted 3 lines

Actually, the thing that matters is the size of the merge rx buf header, not the CRC.

This patch is good enough for now, but not fully correct.
The actual max value depends on the host negotiation protocol, ie merge rx buf is only sometimes used.

There was some discussion on netdev mailing list to pass MTU from host to guest in virtio, not sure where that landed.

#11 lore raw

Hi Stephen,
So what should be my next steps , should I submit a v7 for this patch or you suggest otherwise.

--
Regards,
Souvik

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, September 27, 2016 2:57 PM
To: Dey, Souvik <[email protected]>
Cc: Kavanagh, Mark B <[email protected]>; Yuanhan Liu <[email protected]>; [email protected]
Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 118 lines · Souvik

Hi Liu/Mark/Stephen,

I have tried to modify the code with all of your latest comments. Do let me know if this looks fine or you have more comments.

Changes done :

-- max frame ize is compare to VIRTIO_MAX_RX_PKTLEN instead of dev_info.max_rx_pktlen

-- removed the CRC_LEN from the ether_len calculation and added the merge rx buf hdr len. ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_SIZE + hw->vtnet_hdr_size

-- Still retained the VLAN Size as the worst case scenario.

--

drivers/net/virtio/virtio_ethdev.c | 16 ++++++++++++++++

1 file changed, 16 insertions(+)
drivers/net/virtio/virtio_ethdev.c +0 -0

index 423c597..1dbfea6 100644

--- a/drivers/net/virtio/virtio_ethdev.c

+++ b/drivers/net/virtio/virtio_ethdev.c

drivers/net/virtio/virtio_ethdev.c +19 -0
@@ -653,12 +653,20 @@ virtio_dev_allmulticast_disable(struct 
 rte_eth_dev *dev)
 
                PMD_INIT_LOG(ERR, "Failed to disable allmulticast");
 
 }
 
 
 
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
 
+
 
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 
+{
 
+            struct virtio_hw *hw = dev->data->dev_private;
 
+            uint32_t ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_SIZE + 
+ hw->vtnet_hdr_size;
 
+            uint32_t frame_size = mtu + ether_hdr_len;
 
+
 
+            if (mtu < ETHER_MIN_MTU || frame_size > 
+ VIRTIO_MAX_RX_PKTLEN ) {
 
+                           PMD_INIT_LOG(ERR, "MTU should be between 
+ %d and %d\n",
 
+                                         ETHER_MIN_MTU, 
+ VIRTIO_MAX_RX_PKTLEN);
 
+                           return -EINVAL;
 
+            }
 
+            return 0;
 
+}

/*

* dev_ops for virtio, bare necessities for basic operation

*/

drivers/net/virtio/virtio_ethdev.c +1 -1
@@ -677,7 +685,6 @@ static const struct eth_dev_ops virtio_eth_dev_ops 
 = {
 
             .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,
 
             .xstats_get              = virtio_dev_xstats_get,
 
--

Please do let me know if this looks good to you all. Thanks

--

Regards,

Souvik

Quoted 170 lines

-----Original Message-----
From: Kavanagh, Mark B [mailto:[email protected]]
Sent: Friday, September 23, 2016 5:08 AM
To: Yuanhan Liu <[email protected]>; Stephen Hemminger <[email protected]>
Cc: Dey, Souvik <[email protected]>; [email protected]
Subject: RE: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 159 lines

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 99 lines · Stephen Hemminger

On Thu, 22 Sep 2016 00:08:38 +0000

Quoted 93 lines · "Dey, Souvik" <[email protected]<mailto:[email protected]>> wrote:

Answers inline.

--

Regards,

Souvik

-----Original Message-----

From: Stephen Hemminger [mailto:[email protected]]

Sent: Wednesday, September 21, 2016 7:22 PM

To: Dey, Souvik <[email protected]<mailto:[email protected]>>

Cc: [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>;

[email protected]<mailto:[email protected]>

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

On Wed, 21 Sep 2016 19:11:47 -0400

Quoted 32 lines · Dey <[email protected]<mailto:[email protected]>> wrote:
(quoted diff) +17 -0
+
 
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
 
+
 
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t 
+mtu) {
 
+       struct rte_eth_dev_info dev_info;
 
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + ETHER_CRC_LEN 
+ + VLAN_TAG_SIZE;
 
+       uint32_t frame_size = mtu + ether_hdr_len;
 
+
 
+       virtio_dev_info_get(dev, &dev_info);
 
+
 
+       if (mtu < ETHER_MIN_MTU || frame_size > 
+ dev_info.max_rx_pktlen) {
 
+               PMD_INIT_LOG(ERR, "MTU should be between %d and 
+ %d\n",
 
+                               ETHER_MIN_MTU,
 

Review

Quoted 10 lines
(quoted diff) +6 -0
+                               (dev_info.max_rx_pktlen - 
+ ether_hdr_len));
 
+               return -EINVAL;
 
+       }
 
+       return 0;
 
+}

I am fine with the general idea of this patch but:

1. Calling virtio_dev_info_get is needlessly wasteful when all
you want

is to access the max packet length. Since max_rx_pktlen is
always

VIRTIO_MAX_RX_PKTLEN, please just use that.

[Dey, Souvik] I am using the virtio_dev_info_get as in future

can/may support the

max_rx_pktlen as a variable to be set by the application. This will

keep the changes future proof. As we need to support till 65535 instead of 9728 as the linux does.

Quoted 6 lines

Fine, then just dereference hw->rx_max_pktlen. Driver code can/should

reference its own data directly.

Dey, maybe you could just use VIRTIO_MAX_RX_PKTLEN here, like what you

did in early versions.

Quoted 7 lines
Quoted 7 lines

2. Defining VLAN_TAG_SIZE is irrelevant if doing vlan offload.

[Dey, Souvik] vlan offload is not mandatory. Se again still have

vlan being sent up to

the application. In that case we need to consider the vlan length in the Ethernet size.

Quoted 5 lines

The code needs to handle both vlan offload (or not), correctly. You

are assuming the worst case here.

I think we are fine here to assume worst case.

Quoted 5 lines
Quoted 5 lines

3. Virtio doesn't insert CRC, therefore CRC_LEN is irrelevant

[Dey, Souvik] I am not sure of this. Mark commented earlier to consider this length too.

Mark what do you suggest ?

Quoted 3 lines

Actually, the thing that matters is the size of the merge rx buf header, not the CRC.

This patch is good enough for now, but not fully correct.
The actual max value depends on the host negotiation protocol, ie merge rx buf is only sometimes used.

There was some discussion on netdev mailing list to pass MTU from host to guest in virtio, not sure where that landed.

#12 lore raw
Quoted 2 lines · Souvik

Hi Stephen,
So what should be my next steps , should I submit a v7 for this patch or you suggest otherwise.

Yes, please. Another note is please don't use white space for indentation, use TAB instead.

-yliu

Quoted 308 lines

--
Regards,
Souvik

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, September 27, 2016 2:57 PM
To: Dey, Souvik <[email protected]>
Cc: Kavanagh, Mark B <[email protected]>; Yuanhan Liu <[email protected]>; [email protected]
Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 118 lines · Souvik

Hi Liu/Mark/Stephen,

I have tried to modify the code with all of your latest comments. Do let me know if this looks fine or you have more comments.

Changes done :

-- max frame ize is compare to VIRTIO_MAX_RX_PKTLEN instead of dev_info.max_rx_pktlen

-- removed the CRC_LEN from the ether_len calculation and added the merge rx buf hdr len. ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_SIZE + hw->vtnet_hdr_size

-- Still retained the VLAN Size as the worst case scenario.

--

drivers/net/virtio/virtio_ethdev.c | 16 ++++++++++++++++

1 file changed, 16 insertions(+)
drivers/net/virtio/virtio_ethdev.c +0 -0

index 423c597..1dbfea6 100644

--- a/drivers/net/virtio/virtio_ethdev.c

+++ b/drivers/net/virtio/virtio_ethdev.c

drivers/net/virtio/virtio_ethdev.c +19 -0
@@ -653,12 +653,20 @@ virtio_dev_allmulticast_disable(struct 
 rte_eth_dev *dev)
 
                PMD_INIT_LOG(ERR, "Failed to disable allmulticast");
 
 }
 
 
 
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
 
+
 
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 
+{
 
+            struct virtio_hw *hw = dev->data->dev_private;
 
+            uint32_t ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_SIZE + 
+ hw->vtnet_hdr_size;
 
+            uint32_t frame_size = mtu + ether_hdr_len;
 
+
 
+            if (mtu < ETHER_MIN_MTU || frame_size > 
+ VIRTIO_MAX_RX_PKTLEN ) {
 
+                           PMD_INIT_LOG(ERR, "MTU should be between 
+ %d and %d\n",
 
+                                         ETHER_MIN_MTU, 
+ VIRTIO_MAX_RX_PKTLEN);
 
+                           return -EINVAL;
 
+            }
 
+            return 0;
 
+}

/*

* dev_ops for virtio, bare necessities for basic operation

*/

drivers/net/virtio/virtio_ethdev.c +1 -1
@@ -677,7 +685,6 @@ static const struct eth_dev_ops virtio_eth_dev_ops 
 = {
 
             .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,
 
             .xstats_get              = virtio_dev_xstats_get,
 
--

Please do let me know if this looks good to you all. Thanks

--

Regards,

Souvik

Quoted 170 lines

-----Original Message-----
From: Kavanagh, Mark B [mailto:[email protected]]
Sent: Friday, September 23, 2016 5:08 AM
To: Yuanhan Liu <[email protected]>; Stephen Hemminger <[email protected]>
Cc: Dey, Souvik <[email protected]>; [email protected]
Subject: RE: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 159 lines

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 99 lines · Stephen Hemminger

On Thu, 22 Sep 2016 00:08:38 +0000

Quoted 93 lines · "Dey, Souvik" <[email protected]<mailto:[email protected]>> wrote:

Answers inline.

--

Regards,

Souvik

-----Original Message-----

From: Stephen Hemminger [mailto:[email protected]]

Sent: Wednesday, September 21, 2016 7:22 PM

To: Dey, Souvik <[email protected]<mailto:[email protected]>>

Cc: [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>;

[email protected]<mailto:[email protected]>

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

On Wed, 21 Sep 2016 19:11:47 -0400

Quoted 32 lines · Dey <[email protected]<mailto:[email protected]>> wrote:
(quoted diff) +17 -0
+
 
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
 
+
 
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t 
+mtu) {
 
+       struct rte_eth_dev_info dev_info;
 
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + ETHER_CRC_LEN 
+ + VLAN_TAG_SIZE;
 
+       uint32_t frame_size = mtu + ether_hdr_len;
 
+
 
+       virtio_dev_info_get(dev, &dev_info);
 
+
 
+       if (mtu < ETHER_MIN_MTU || frame_size > 
+ dev_info.max_rx_pktlen) {
 
+               PMD_INIT_LOG(ERR, "MTU should be between %d and 
+ %d\n",
 
+                               ETHER_MIN_MTU,
 

Review

Quoted 10 lines
(quoted diff) +6 -0
+                               (dev_info.max_rx_pktlen - 
+ ether_hdr_len));
 
+               return -EINVAL;
 
+       }
 
+       return 0;
 
+}

I am fine with the general idea of this patch but:

1. Calling virtio_dev_info_get is needlessly wasteful when all
you want

is to access the max packet length. Since max_rx_pktlen is
always

VIRTIO_MAX_RX_PKTLEN, please just use that.

[Dey, Souvik] I am using the virtio_dev_info_get as in future

can/may support the

max_rx_pktlen as a variable to be set by the application. This will

keep the changes future proof. As we need to support till 65535 instead of 9728 as the linux does.

Quoted 6 lines

Fine, then just dereference hw->rx_max_pktlen. Driver code can/should

reference its own data directly.

Dey, maybe you could just use VIRTIO_MAX_RX_PKTLEN here, like what you

did in early versions.

Quoted 7 lines
Quoted 7 lines

2. Defining VLAN_TAG_SIZE is irrelevant if doing vlan offload.

[Dey, Souvik] vlan offload is not mandatory. Se again still have

vlan being sent up to

the application. In that case we need to consider the vlan length in the Ethernet size.

Quoted 5 lines

The code needs to handle both vlan offload (or not), correctly. You

are assuming the worst case here.

I think we are fine here to assume worst case.

Quoted 5 lines
Quoted 5 lines

3. Virtio doesn't insert CRC, therefore CRC_LEN is irrelevant

[Dey, Souvik] I am not sure of this. Mark commented earlier to consider this length too.

Mark what do you suggest ?

Quoted 3 lines

Actually, the thing that matters is the size of the merge rx buf header, not the CRC.

This patch is good enough for now, but not fully correct.
The actual max value depends on the host negotiation protocol, ie merge rx buf is only sometimes used.

There was some discussion on netdev mailing list to pass MTU from host to guest in virtio, not sure where that landed.

#13 lore raw

OK sure will do that.

-----Original Message-----
From: Yuanhan Liu [mailto:[email protected]]
Sent: Tuesday, September 27, 2016 7:12 PM
To: Dey, Souvik <[email protected]>
Cc: Stephen Hemminger <[email protected]>; Kavanagh, Mark B <[email protected]>; [email protected]
Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 2 lines · Souvik

Hi Stephen,
So what should be my next steps , should I submit a v7 for this patch or you suggest otherwise.

Yes, please. Another note is please don't use white space for indentation, use TAB instead.

-yliu

Quoted 317 lines

--
Regards,
Souvik

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, September 27, 2016 2:57 PM
To: Dey, Souvik <[email protected]>
Cc: Kavanagh, Mark B <[email protected]>; Yuanhan Liu <[email protected]>; [email protected]
Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 120 lines · Souvik

Hi Liu/Mark/Stephen,

I have tried to modify the code with all of your latest comments. Do let me know if this looks fine or you have more comments.

Changes done :

-- max frame ize is compare to VIRTIO_MAX_RX_PKTLEN instead of dev_info.max_rx_pktlen

-- removed the CRC_LEN from the ether_len calculation and added the merge rx buf hdr len. ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_SIZE +
hw->vtnet_hdr_size

-- Still retained the VLAN Size as the worst case scenario.

--

drivers/net/virtio/virtio_ethdev.c | 16 ++++++++++++++++

1 file changed, 16 insertions(+)
drivers/net/virtio/virtio_ethdev.c +0 -0

index 423c597..1dbfea6 100644

--- a/drivers/net/virtio/virtio_ethdev.c

+++ b/drivers/net/virtio/virtio_ethdev.c

drivers/net/virtio/virtio_ethdev.c +20 -0
@@ -653,12 +653,20 @@ virtio_dev_allmulticast_disable(struct
 rte_eth_dev *dev)
 
                PMD_INIT_LOG(ERR, "Failed to disable allmulticast");
 
 }
 
 
 
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
 
+
 
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 
+{
 
+            struct virtio_hw *hw = dev->data->dev_private;
 
+            uint32_t ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_SIZE 
+ +
+ hw->vtnet_hdr_size;
 
+            uint32_t frame_size = mtu + ether_hdr_len;
 
+
 
+            if (mtu < ETHER_MIN_MTU || frame_size > 
+ VIRTIO_MAX_RX_PKTLEN ) {
 
+                           PMD_INIT_LOG(ERR, "MTU should be between 
+ %d and %d\n",
 
+                                         ETHER_MIN_MTU, 
+ VIRTIO_MAX_RX_PKTLEN);
 
+                           return -EINVAL;
 
+            }
 
+            return 0;
 
+}

/*

* dev_ops for virtio, bare necessities for basic operation

*/

drivers/net/virtio/virtio_ethdev.c +1 -1
@@ -677,7 +685,6 @@ static const struct eth_dev_ops 
 virtio_eth_dev_ops = {
 
             .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,
 
             .xstats_get              = virtio_dev_xstats_get,
 
--

Please do let me know if this looks good to you all. Thanks

--

Regards,

Souvik

Quoted 176 lines

-----Original Message-----
From: Kavanagh, Mark B [mailto:[email protected]]
Sent: Friday, September 23, 2016 5:08 AM
To: Yuanhan Liu <[email protected]>; Stephen Hemminger <[email protected]>
Cc: Dey, Souvik <[email protected]>; [email protected]
Subject: RE: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 165 lines

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

Quoted 102 lines · Stephen Hemminger

On Thu, 22 Sep 2016 00:08:38 +0000

Quoted 96 lines · "Dey, Souvik" <[email protected]<mailto:[email protected]>> wrote:

Answers inline.

--

Regards,

Souvik

-----Original Message-----

From: Stephen Hemminger [mailto:[email protected]]

Sent: Wednesday, September 21, 2016 7:22 PM

To: Dey, Souvik <[email protected]<mailto:[email protected]>>

Cc:
[email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]> ;

[email protected]<mailto:[email protected]>

Subject: Re: [PATCH v6] net/virtio: add set_mtu in virtio

On Wed, 21 Sep 2016 19:11:47 -0400

Quoted 33 lines · Dey <[email protected]<mailto:[email protected]>> wrote:
(quoted diff) +18 -0
+
 
+#define VLAN_TAG_SIZE           4    /* 802.3ac tag (not DMA'd) */
 
+
 
+static int virtio_mtu_set(struct rte_eth_dev *dev, uint16_t
+mtu) {
 
+       struct rte_eth_dev_info dev_info;
 
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + 
+ ETHER_CRC_LEN
+ + VLAN_TAG_SIZE;
 
+       uint32_t frame_size = mtu + ether_hdr_len;
 
+
 
+       virtio_dev_info_get(dev, &dev_info);
 
+
 
+       if (mtu < ETHER_MIN_MTU || frame_size >
+ dev_info.max_rx_pktlen) {
 
+               PMD_INIT_LOG(ERR, "MTU should be between %d 
+ and %d\n",
 
+                               ETHER_MIN_MTU,
 

Review

Quoted 10 lines
(quoted diff) +6 -0
+                               (dev_info.max_rx_pktlen - 
+ ether_hdr_len));
 
+               return -EINVAL;
 
+       }
 
+       return 0;
 
+}

I am fine with the general idea of this patch but:

1. Calling virtio_dev_info_get is needlessly wasteful when
all you want

is to access the max packet length. Since max_rx_pktlen is
always

VIRTIO_MAX_RX_PKTLEN, please just use that.

[Dey, Souvik] I am using the virtio_dev_info_get as in future

can/may support the

max_rx_pktlen as a variable to be set by the application. This will

keep the changes future proof. As we need to support till 65535 instead of 9728 as the linux does.

Quoted 6 lines

Fine, then just dereference hw->rx_max_pktlen. Driver code can/should

reference its own data directly.

Dey, maybe you could just use VIRTIO_MAX_RX_PKTLEN here, like what you

did in early versions.

Quoted 8 lines
Quoted 8 lines

2. Defining VLAN_TAG_SIZE is irrelevant if doing vlan offload.

[Dey, Souvik] vlan offload is not mandatory. Se again still have

vlan being sent up to

the application. In that case we need to consider the vlan length in the Ethernet size.

Quoted 6 lines

The code needs to handle both vlan offload (or not), correctly. You

are assuming the worst case here.

I think we are fine here to assume worst case.

Quoted 5 lines
Quoted 5 lines

3. Virtio doesn't insert CRC, therefore CRC_LEN is irrelevant

[Dey, Souvik] I am not sure of this. Mark commented earlier to consider this length too.

Mark what do you suggest ?

Quoted 3 lines

Actually, the thing that matters is the size of the merge rx buf header, not the CRC.

This patch is good enough for now, but not fully correct.
The actual max value depends on the host negotiation protocol, ie merge rx buf is only sometimes used.

There was some discussion on netdev mailing list to pass MTU from host to guest in virtio, not sure where that landed.

#14 lore raw
In reply to Dey, Souvik
Quoted 5 lines · Souvik

I am fine with the general idea of this patch but:
1. Calling virtio_dev_info_get is needlessly wasteful when all you want
is to access the max packet length. Since max_rx_pktlen is always
VIRTIO_MAX_RX_PKTLEN, please just use that.
[Dey, Souvik] I am using the virtio_dev_info_get as in future can/may support the max_rx_pktlen as a variable to be set by the application. This will keep the changes future proof. As we need to support till 65535 instead of 9728 as the linux does.

Future proof is a myth. Don't add code based on planned future functionality

http://www.extremeprogramming.org/rules/early.html