diff mbox

[ovs-dev,3/5] lib/dp-packet: Fix data_len issue with multi-segments

Message ID 1493705445-5774-4-git-send-email-qdy220091330@gmail.com
State Changes Requested
Headers show

Commit Message

Michael Qiu May 2, 2017, 6:10 a.m. UTC
From: Michael Qiu <qiudayu@chinac.com>

When a packet is from DPDK source, and it contains
multiple segments, data_len is not equal to the
packet size. This patch fix this issue.

Signed-off-by: Michael Qiu <qiudayu@chinac.com>
Signed-off-by: Marcin Ksiadz <marcinx.ksiadz@intel.com>
Signed-off-by: Mark Kavanagh <mark.b.kavanagh@intel.com>
Signed-off-by: Przemyslaw Lal <przemyslawx.lal@intel.com>
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/dp-packet.h | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

Comments

Mark Kavanagh May 3, 2017, 3:33 p.m. UTC | #1
>From: Michael Qiu <qiudayu@chinac.com>
>
>When a packet is from DPDK source, and it contains
>multiple segments, data_len is not equal to the
>packet size. This patch fix this issue.
>
>Signed-off-by: Michael Qiu <qiudayu@chinac.com>
>Signed-off-by: Marcin Ksiadz <marcinx.ksiadz@intel.com>
>Signed-off-by: Mark Kavanagh <mark.b.kavanagh@intel.com>
>Signed-off-by: Przemyslaw Lal <przemyslawx.lal@intel.com>
>Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
>---
> lib/dp-packet.h | 23 +++++++++++++----------
> 1 file changed, 13 insertions(+), 10 deletions(-)
>
>diff --git a/lib/dp-packet.h b/lib/dp-packet.h
>index c73ca19..337a600 100644
>--- a/lib/dp-packet.h
>+++ b/lib/dp-packet.h
>@@ -23,6 +23,7 @@
> #ifdef DPDK_NETDEV
> #include <rte_config.h>
> #include <rte_mbuf.h>
>+#include "rte_ether.h"
> #endif
>
> #include "netdev-dpdk.h"
>@@ -415,17 +416,19 @@ dp_packet_size(const struct dp_packet *b)
> static inline void
> dp_packet_set_size(struct dp_packet *b, uint32_t v)
> {
>-    /* netdev-dpdk does not currently support segmentation; consequently, for
>-     * all intents and purposes, 'data_len' (16 bit) and 'pkt_len' (32 bit) may
>-     * be used interchangably.
>-     *
>-     * On the datapath, it is expected that the size of packets
>-     * (and thus 'v') will always be <= UINT16_MAX; this means that there is no
>-     * loss of accuracy in assigning 'v' to 'data_len'.
>+    /*
>+     * Assign current segment length. If total length is greater than
>+     * max data length in a segment, additional calculation is needed
>      */
>-    b->mbuf.data_len = (uint16_t)v;  /* Current seg length. */
>-    b->mbuf.pkt_len = v;             /* Total length of all segments linked to
>-                                      * this segment. */
>+    if (v > (b->mbuf.buf_len - b->mbuf.data_off)) {

You could insert '(OVS_UNLIKELY' after the 'if'

>+        b->mbuf.data_len =
>+            (uint16_t) (b->mbuf.buf_len - b->mbuf.data_off);
>+    } else {
>+        b->mbuf.data_len = (uint16_t) v;
>+    }
>+
>+    /* Total length of all segments linked to this segment. */
>+    b->mbuf.pkt_len = v;
> }
>
> static inline uint16_t
>--
>1.8.3.1
Michael Qiu May 3, 2017, 4:04 p.m. UTC | #2
在 2017年5月3日,下午11:33,Kavanagh, Mark B <mark.b.kavanagh@intel.com> 写道:

>> From: Michael Qiu <qiudayu@chinac.com>
>> 
>> When a packet is from DPDK source, and it contains
>> multiple segments, data_len is not equal to the
>> packet size. This patch fix this issue.
>> 
>> Signed-off-by: Michael Qiu <qiudayu@chinac.com>
>> Signed-off-by: Marcin Ksiadz <marcinx.ksiadz@intel.com>
>> Signed-off-by: Mark Kavanagh <mark.b.kavanagh@intel.com>
>> Signed-off-by: Przemyslaw Lal <przemyslawx.lal@intel.com>
>> Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
>> ---
>> lib/dp-packet.h | 23 +++++++++++++----------
>> 1 file changed, 13 insertions(+), 10 deletions(-)
>> 
>> diff --git a/lib/dp-packet.h b/lib/dp-packet.h
>> index c73ca19..337a600 100644
>> --- a/lib/dp-packet.h
>> +++ b/lib/dp-packet.h
>> @@ -23,6 +23,7 @@
>> #ifdef DPDK_NETDEV
>> #include <rte_config.h>
>> #include <rte_mbuf.h>
>> +#include "rte_ether.h"
>> #endif
>> 
>> #include "netdev-dpdk.h"
>> @@ -415,17 +416,19 @@ dp_packet_size(const struct dp_packet *b)
>> static inline void
>> dp_packet_set_size(struct dp_packet *b, uint32_t v)
>> {
>> -    /* netdev-dpdk does not currently support segmentation; consequently, for
>> -     * all intents and purposes, 'data_len' (16 bit) and 'pkt_len' (32 bit) may
>> -     * be used interchangably.
>> -     *
>> -     * On the datapath, it is expected that the size of packets
>> -     * (and thus 'v') will always be <= UINT16_MAX; this means that there is no
>> -     * loss of accuracy in assigning 'v' to 'data_len'.
>> +    /*
>> +     * Assign current segment length. If total length is greater than
>> +     * max data length in a segment, additional calculation is needed
>>     */
>> -    b->mbuf.data_len = (uint16_t)v;  /* Current seg length. */
>> -    b->mbuf.pkt_len = v;             /* Total length of all segments linked to
>> -                                      * this segment. */
>> +    if (v > (b->mbuf.buf_len - b->mbuf.data_off)) {
> 
> You could insert '(OVS_UNLIKELY' after the 'if'

What I consider is that after enable hw offloading, multiple segments should be unlikely?

But anyway, before enable it, unlikely could be right thing.

> 
>> +        b->mbuf.data_len =
>> +            (uint16_t) (b->mbuf.buf_len - b->mbuf.data_off);
>> +    } else {
>> +        b->mbuf.data_len = (uint16_t) v;
>> +    }
>> +
>> +    /* Total length of all segments linked to this segment. */
>> +    b->mbuf.pkt_len = v;
>> }
>> 
>> static inline uint16_t
>> --
>> 1.8.3.1
> 
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Ben Pfaff May 4, 2017, 9:24 p.m. UTC | #3
On Tue, May 02, 2017 at 02:10:43PM +0800, Michael Qiu wrote:
> From: Michael Qiu <qiudayu@chinac.com>
> 
> When a packet is from DPDK source, and it contains
> multiple segments, data_len is not equal to the
> packet size. This patch fix this issue.
> 
> Signed-off-by: Michael Qiu <qiudayu@chinac.com>
> Signed-off-by: Marcin Ksiadz <marcinx.ksiadz@intel.com>
> Signed-off-by: Mark Kavanagh <mark.b.kavanagh@intel.com>
> Signed-off-by: Przemyslaw Lal <przemyslawx.lal@intel.com>
> Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>

Thank you for working to improve OVS support for DPDK.

This is a very simple patch.  Can you explain the chain of authorship?

> @@ -415,17 +416,19 @@ dp_packet_size(const struct dp_packet *b)
>  static inline void
>  dp_packet_set_size(struct dp_packet *b, uint32_t v)
>  {
> -    /* netdev-dpdk does not currently support segmentation; consequently, for
> -     * all intents and purposes, 'data_len' (16 bit) and 'pkt_len' (32 bit) may
> -     * be used interchangably.
> -     *
> -     * On the datapath, it is expected that the size of packets
> -     * (and thus 'v') will always be <= UINT16_MAX; this means that there is no
> -     * loss of accuracy in assigning 'v' to 'data_len'.
> +    /*
> +     * Assign current segment length. If total length is greater than
> +     * max data length in a segment, additional calculation is needed
>       */
> -    b->mbuf.data_len = (uint16_t)v;  /* Current seg length. */
> -    b->mbuf.pkt_len = v;             /* Total length of all segments linked to
> -                                      * this segment. */
> +    if (v > (b->mbuf.buf_len - b->mbuf.data_off)) {
> +        b->mbuf.data_len =
> +            (uint16_t) (b->mbuf.buf_len - b->mbuf.data_off);
> +    } else {
> +        b->mbuf.data_len = (uint16_t) v;
> +    }

I don't see any value in the two casts to uint16_t above.  They convert
their operands to uint16_t, but this will also happen just as well
without the casts since the destination has type uint16_t.  Open vSwitch
style omits needless casts.

Also, I think that the above can be written more simply as:
        b->mbuf.data_len = MIN(v, b->mbuf.buf_len - b->mbuf.data_off);
Mark Kavanagh May 5, 2017, 8:57 a.m. UTC | #4
>
>On Tue, May 02, 2017 at 02:10:43PM +0800, Michael Qiu wrote:
>> From: Michael Qiu <qiudayu@chinac.com>
>>
>> When a packet is from DPDK source, and it contains
>> multiple segments, data_len is not equal to the
>> packet size. This patch fix this issue.
>>
>> Signed-off-by: Michael Qiu <qiudayu@chinac.com>
>> Signed-off-by: Marcin Ksiadz <marcinx.ksiadz@intel.com>
>> Signed-off-by: Mark Kavanagh <mark.b.kavanagh@intel.com>
>> Signed-off-by: Przemyslaw Lal <przemyslawx.lal@intel.com>
>> Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
>
>Thank you for working to improve OVS support for DPDK.
>
>This is a very simple patch.  Can you explain the chain of authorship?

Hi Ben,

This code originates from an RFC patch, which was authored by the individuals listed: https://mail.openvswitch.org/pipermail/ovs-dev/2016-June/316414.html

Hope this clears things up.

Thanks,
Mark
>
>> @@ -415,17 +416,19 @@ dp_packet_size(const struct dp_packet *b)
>>  static inline void
>>  dp_packet_set_size(struct dp_packet *b, uint32_t v)
>>  {
>> -    /* netdev-dpdk does not currently support segmentation; consequently, for
>> -     * all intents and purposes, 'data_len' (16 bit) and 'pkt_len' (32 bit) may
>> -     * be used interchangably.
>> -     *
>> -     * On the datapath, it is expected that the size of packets
>> -     * (and thus 'v') will always be <= UINT16_MAX; this means that there is no
>> -     * loss of accuracy in assigning 'v' to 'data_len'.
>> +    /*
>> +     * Assign current segment length. If total length is greater than
>> +     * max data length in a segment, additional calculation is needed
>>       */
>> -    b->mbuf.data_len = (uint16_t)v;  /* Current seg length. */
>> -    b->mbuf.pkt_len = v;             /* Total length of all segments linked to
>> -                                      * this segment. */
>> +    if (v > (b->mbuf.buf_len - b->mbuf.data_off)) {
>> +        b->mbuf.data_len =
>> +            (uint16_t) (b->mbuf.buf_len - b->mbuf.data_off);
>> +    } else {
>> +        b->mbuf.data_len = (uint16_t) v;
>> +    }
>
>I don't see any value in the two casts to uint16_t above.  They convert
>their operands to uint16_t, but this will also happen just as well
>without the casts since the destination has type uint16_t.  Open vSwitch
>style omits needless casts.
>
>Also, I think that the above can be written more simply as:
>        b->mbuf.data_len = MIN(v, b->mbuf.buf_len - b->mbuf.data_off);
>
>
>_______________________________________________
>dev mailing list
>dev@openvswitch.org
>https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Ben Pfaff May 5, 2017, 3:44 p.m. UTC | #5
On Fri, May 05, 2017 at 08:57:27AM +0000, Kavanagh, Mark B wrote:
> >
> >On Tue, May 02, 2017 at 02:10:43PM +0800, Michael Qiu wrote:
> >> From: Michael Qiu <qiudayu@chinac.com>
> >>
> >> When a packet is from DPDK source, and it contains
> >> multiple segments, data_len is not equal to the
> >> packet size. This patch fix this issue.
> >>
> >> Signed-off-by: Michael Qiu <qiudayu@chinac.com>
> >> Signed-off-by: Marcin Ksiadz <marcinx.ksiadz@intel.com>
> >> Signed-off-by: Mark Kavanagh <mark.b.kavanagh@intel.com>
> >> Signed-off-by: Przemyslaw Lal <przemyslawx.lal@intel.com>
> >> Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
> >
> >Thank you for working to improve OVS support for DPDK.
> >
> >This is a very simple patch.  Can you explain the chain of authorship?
> 
> Hi Ben,
> 
> This code originates from an RFC patch, which was authored by the individuals listed: https://mail.openvswitch.org/pipermail/ovs-dev/2016-June/316414.html
> 
> Hope this clears things up.

OK, if the listed signoffs are co-authors, then Co-authored-by: tags are
needed.  The RFC had them but Michael's version drops them.  Michael,
please add back the Co-authored-by: tags.

Thanks,

Ben.
Michael Qiu May 31, 2017, 8:57 a.m. UTC | #6
在 2017/5/5 23:44, Ben Pfaff 写道:
> On Fri, May 05, 2017 at 08:57:27AM +0000, Kavanagh, Mark B wrote:
>>> On Tue, May 02, 2017 at 02:10:43PM +0800, Michael Qiu wrote:
>>>> From: Michael Qiu <qiudayu@chinac.com>
>>>>
>>>> When a packet is from DPDK source, and it contains
>>>> multiple segments, data_len is not equal to the
>>>> packet size. This patch fix this issue.
>>>>
>>>> Signed-off-by: Michael Qiu <qiudayu@chinac.com>
>>>> Signed-off-by: Marcin Ksiadz <marcinx.ksiadz@intel.com>
>>>> Signed-off-by: Mark Kavanagh <mark.b.kavanagh@intel.com>
>>>> Signed-off-by: Przemyslaw Lal <przemyslawx.lal@intel.com>
>>>> Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
>>> Thank you for working to improve OVS support for DPDK.
>>>
>>> This is a very simple patch.  Can you explain the chain of authorship?
>> Hi Ben,
>>
>> This code originates from an RFC patch, which was authored by the individuals listed: https://mail.openvswitch.org/pipermail/ovs-dev/2016-June/316414.html
>>
>> Hope this clears things up.
> OK, if the listed signoffs are co-authors, then Co-authored-by: tags are
> needed.  The RFC had them but Michael's version drops them.  Michael,
> please add back the Co-authored-by: tags.

OK, I will re-add them and send another version.

> Thanks,
>
> Ben.
Mark Kavanagh May 31, 2017, 10:59 a.m. UTC | #7
>From: Michael Qiu [mailto:qdy220091330@gmail.com]

>Sent: Wednesday, May 31, 2017 9:58 AM

>To: Ben Pfaff <blp@ovn.org>; Kavanagh, Mark B <mark.b.kavanagh@intel.com>

>Cc: dev@openvswitch.org; Lal, PrzemyslawX <przemyslawx.lal@intel.com>; Michael Qiu

><qiudayu@chinac.com>; Ksiadz, MarcinX <marcinx.ksiadz@intel.com>

>Subject: Re: [ovs-dev] [PATCH 3/5] lib/dp-packet: Fix data_len issue with multi-segments

>

>

>

>在 2017/5/5 23:44, Ben Pfaff 写道:

>> On Fri, May 05, 2017 at 08:57:27AM +0000, Kavanagh, Mark B wrote:

>>>> On Tue, May 02, 2017 at 02:10:43PM +0800, Michael Qiu wrote:

>>>>> From: Michael Qiu <qiudayu@chinac.com>

>>>>>

>>>>> When a packet is from DPDK source, and it contains

>>>>> multiple segments, data_len is not equal to the

>>>>> packet size. This patch fix this issue.

>>>>>

>>>>> Signed-off-by: Michael Qiu <qiudayu@chinac.com>

>>>>> Signed-off-by: Marcin Ksiadz <marcinx.ksiadz@intel.com>

>>>>> Signed-off-by: Mark Kavanagh <mark.b.kavanagh@intel.com>

>>>>> Signed-off-by: Przemyslaw Lal <przemyslawx.lal@intel.com>

>>>>> Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>

>>>> Thank you for working to improve OVS support for DPDK.

>>>>

>>>> This is a very simple patch.  Can you explain the chain of authorship?

>>> Hi Ben,

>>>

>>> This code originates from an RFC patch, which was authored by the individuals listed:

>https://mail.openvswitch.org/pipermail/ovs-dev/2016-June/316414.html

>>>

>>> Hope this clears things up.

>> OK, if the listed signoffs are co-authors, then Co-authored-by: tags are

>> needed.  The RFC had them but Michael's version drops them.  Michael,

>> please add back the Co-authored-by: tags.

>

>OK, I will re-add them and send another version.


Hi Michael,

A number of people have mentioned to me that your patchset doesn't apply to HEAD of master; if you could also rebase in the next version that'd be great.

Thanks,
Mark


>

>> Thanks,

>>

>> Ben.
Michael Qiu June 1, 2017, 3:41 a.m. UTC | #8
在 2017/5/31 18:59, Kavanagh, Mark B 写道:
>> From: Michael Qiu [mailto:qdy220091330@gmail.com]
>> Sent: Wednesday, May 31, 2017 9:58 AM
>> To: Ben Pfaff <blp@ovn.org>; Kavanagh, Mark B <mark.b.kavanagh@intel.com>
>> Cc: dev@openvswitch.org; Lal, PrzemyslawX <przemyslawx.lal@intel.com>; Michael Qiu
>> <qiudayu@chinac.com>; Ksiadz, MarcinX <marcinx.ksiadz@intel.com>
>> Subject: Re: [ovs-dev] [PATCH 3/5] lib/dp-packet: Fix data_len issue with multi-segments
>>
>>
>>
>> 在 2017/5/5 23:44, Ben Pfaff 写道:
>>> On Fri, May 05, 2017 at 08:57:27AM +0000, Kavanagh, Mark B wrote:
>>>>> On Tue, May 02, 2017 at 02:10:43PM +0800, Michael Qiu wrote:
>>>>>> From: Michael Qiu <qiudayu@chinac.com>
>>>>>>
>>>>>> When a packet is from DPDK source, and it contains
>>>>>> multiple segments, data_len is not equal to the
>>>>>> packet size. This patch fix this issue.
>>>>>>
>>>>>> Signed-off-by: Michael Qiu <qiudayu@chinac.com>
>>>>>> Signed-off-by: Marcin Ksiadz <marcinx.ksiadz@intel.com>
>>>>>> Signed-off-by: Mark Kavanagh <mark.b.kavanagh@intel.com>
>>>>>> Signed-off-by: Przemyslaw Lal <przemyslawx.lal@intel.com>
>>>>>> Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
>>>>> Thank you for working to improve OVS support for DPDK.
>>>>>
>>>>> This is a very simple patch.  Can you explain the chain of authorship?
>>>> Hi Ben,
>>>>
>>>> This code originates from an RFC patch, which was authored by the individuals listed:
>> https://mail.openvswitch.org/pipermail/ovs-dev/2016-June/316414.html
>>>> Hope this clears things up.
>>> OK, if the listed signoffs are co-authors, then Co-authored-by: tags are
>>> needed.  The RFC had them but Michael's version drops them.  Michael,
>>> please add back the Co-authored-by: tags.
>> OK, I will re-add them and send another version.
> Hi Michael,
>
> A number of people have mentioned to me that your patchset doesn't apply to HEAD of master; if you could also rebase in the next version that'd be great.

Sure, I will rebase it.

Thanks,
Michael
> Thanks,
> Mark
>
>
>>> Thanks,
>>>
>>> Ben.
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
diff mbox

Patch

diff --git a/lib/dp-packet.h b/lib/dp-packet.h
index c73ca19..337a600 100644
--- a/lib/dp-packet.h
+++ b/lib/dp-packet.h
@@ -23,6 +23,7 @@ 
 #ifdef DPDK_NETDEV
 #include <rte_config.h>
 #include <rte_mbuf.h>
+#include "rte_ether.h"
 #endif
 
 #include "netdev-dpdk.h"
@@ -415,17 +416,19 @@  dp_packet_size(const struct dp_packet *b)
 static inline void
 dp_packet_set_size(struct dp_packet *b, uint32_t v)
 {
-    /* netdev-dpdk does not currently support segmentation; consequently, for
-     * all intents and purposes, 'data_len' (16 bit) and 'pkt_len' (32 bit) may
-     * be used interchangably.
-     *
-     * On the datapath, it is expected that the size of packets
-     * (and thus 'v') will always be <= UINT16_MAX; this means that there is no
-     * loss of accuracy in assigning 'v' to 'data_len'.
+    /*
+     * Assign current segment length. If total length is greater than
+     * max data length in a segment, additional calculation is needed
      */
-    b->mbuf.data_len = (uint16_t)v;  /* Current seg length. */
-    b->mbuf.pkt_len = v;             /* Total length of all segments linked to
-                                      * this segment. */
+    if (v > (b->mbuf.buf_len - b->mbuf.data_off)) {
+        b->mbuf.data_len =
+            (uint16_t) (b->mbuf.buf_len - b->mbuf.data_off);
+    } else {
+        b->mbuf.data_len = (uint16_t) v;
+    }
+
+    /* Total length of all segments linked to this segment. */
+    b->mbuf.pkt_len = v;
 }
 
 static inline uint16_t