* [PATCH] net: improve vlan header type alignment
@ 2024-10-13 8:35 Morten Brørup
2024-10-13 8:51 ` Morten Brørup
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Morten Brørup @ 2024-10-13 8:35 UTC (permalink / raw)
To: dev; +Cc: Morten Brørup
Ethernet packets can be VLAN tagged, i.e. an Ethernet header can have a
VLAN tag (a.k.a. VLAN header) embedded.
Since the Ethernet header is 2 byte aligned, and the VLAN tag is directly
related to the Ethernet header, the VLAN tag is also 2 byte aligned, so
packing the VLAN tag structure is not necessary.
Furthermore, the Ethernet header type is implictly 2 byte aligned, so
removed the superfluous explicit 2 byte alignment.
Added static_asserts to verify the size and alignment of the various
Ethernet types.
Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
---
lib/net/rte_ether.h | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/lib/net/rte_ether.h b/lib/net/rte_ether.h
index 403e84f50b..c9a0b536c3 100644
--- a/lib/net/rte_ether.h
+++ b/lib/net/rte_ether.h
@@ -11,6 +11,8 @@
* Ethernet Helpers in RTE
*/
+#include <assert.h>
+#include <stdalign.h>
#include <stdint.h>
#include <stdio.h>
@@ -75,6 +77,11 @@ struct __rte_aligned(2) rte_ether_addr {
uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
};
+static_assert(sizeof(struct rte_ether_addr) == 6,
+ "sizeof(struct rte_ether_addr) == 6");
+static_assert(alignof(struct rte_ether_addr) == 2,
+ "alignof(struct rte_ether_addr) == 2");
+
#define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth. address. */
#define RTE_ETHER_GROUP_ADDR 0x01 /**< Multicast or broadcast Eth. address. */
@@ -290,12 +297,17 @@ rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
* Ethernet header: Contains the destination address, source address
* and frame type.
*/
-struct __rte_aligned(2) rte_ether_hdr {
+struct rte_ether_hdr {
struct rte_ether_addr dst_addr; /**< Destination address. */
struct rte_ether_addr src_addr; /**< Source address. */
rte_be16_t ether_type; /**< Frame type. */
};
+static_assert(sizeof(struct rte_ether_hdr) == 14,
+ "sizeof(struct rte_ether_hdr) == 14");
+static_assert(alignof(struct rte_ether_hdr) == 2,
+ "alignof(struct rte_ether_hdr) == 2");
+
/**
* Ethernet VLAN Header.
* Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
@@ -304,7 +316,12 @@ struct __rte_aligned(2) rte_ether_hdr {
struct rte_vlan_hdr {
rte_be16_t vlan_tci; /**< Priority (3) + CFI (1) + Identifier Code (12) */
rte_be16_t eth_proto; /**< Ethernet type of encapsulated frame. */
-} __rte_packed;
+};
+
+static_assert(sizeof(struct rte_vlan_hdr) == 4,
+ "sizeof(struct rte_vlan_hdr) == 4");
+static_assert(alignof(struct rte_vlan_hdr) == 2,
+ "alignof(struct rte_vlan_hdr) == 2");
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH] net: improve vlan header type alignment
2024-10-13 8:35 [PATCH] net: improve vlan header type alignment Morten Brørup
@ 2024-10-13 8:51 ` Morten Brørup
2024-10-14 5:42 ` fengchengwen
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Morten Brørup @ 2024-10-13 8:51 UTC (permalink / raw)
To: bruce.richardson, stephen; +Cc: dev
> From: Morten Brørup [mailto:mb@smartsharesystems.com]
> Sent: Sunday, 13 October 2024 10.36
>
> Ethernet packets can be VLAN tagged, i.e. an Ethernet header can have a
> VLAN tag (a.k.a. VLAN header) embedded.
> Since the Ethernet header is 2 byte aligned, and the VLAN tag is
> directly
> related to the Ethernet header, the VLAN tag is also 2 byte aligned, so
> packing the VLAN tag structure is not necessary.
Stephen, Bruce, you missed the VLAN header type in this patch:
https://git.dpdk.org/dpdk/commit/lib/librte_net/rte_ether.h?id=da5350ef29afd35c1adabe76f60832f3092269ad
This patch completes your work.
>
> Furthermore, the Ethernet header type is implictly 2 byte aligned, so
> removed the superfluous explicit 2 byte alignment.
>
> Added static_asserts to verify the size and alignment of the various
> Ethernet types.
>
> Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
> ---
> lib/net/rte_ether.h | 21 +++++++++++++++++++--
> 1 file changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/lib/net/rte_ether.h b/lib/net/rte_ether.h
> index 403e84f50b..c9a0b536c3 100644
> --- a/lib/net/rte_ether.h
> +++ b/lib/net/rte_ether.h
> @@ -11,6 +11,8 @@
> * Ethernet Helpers in RTE
> */
>
> +#include <assert.h>
> +#include <stdalign.h>
> #include <stdint.h>
> #include <stdio.h>
>
> @@ -75,6 +77,11 @@ struct __rte_aligned(2) rte_ether_addr {
> uint8_t addr_bytes[RTE_ETHER_ADDR_LEN]; /**< Addr bytes in tx
> order */
> };
>
> +static_assert(sizeof(struct rte_ether_addr) == 6,
> + "sizeof(struct rte_ether_addr) == 6");
> +static_assert(alignof(struct rte_ether_addr) == 2,
> + "alignof(struct rte_ether_addr) == 2");
> +
> #define RTE_ETHER_LOCAL_ADMIN_ADDR 0x02 /**< Locally assigned Eth.
> address. */
> #define RTE_ETHER_GROUP_ADDR 0x01 /**< Multicast or broadcast Eth.
> address. */
>
> @@ -290,12 +297,17 @@ rte_ether_unformat_addr(const char *str, struct
> rte_ether_addr *eth_addr);
> * Ethernet header: Contains the destination address, source address
> * and frame type.
> */
> -struct __rte_aligned(2) rte_ether_hdr {
> +struct rte_ether_hdr {
> struct rte_ether_addr dst_addr; /**< Destination address. */
> struct rte_ether_addr src_addr; /**< Source address. */
> rte_be16_t ether_type; /**< Frame type. */
> };
>
> +static_assert(sizeof(struct rte_ether_hdr) == 14,
> + "sizeof(struct rte_ether_hdr) == 14");
> +static_assert(alignof(struct rte_ether_hdr) == 2,
> + "alignof(struct rte_ether_hdr) == 2");
> +
> /**
> * Ethernet VLAN Header.
> * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet
> type
> @@ -304,7 +316,12 @@ struct __rte_aligned(2) rte_ether_hdr {
> struct rte_vlan_hdr {
> rte_be16_t vlan_tci; /**< Priority (3) + CFI (1) + Identifier
> Code (12) */
> rte_be16_t eth_proto; /**< Ethernet type of encapsulated frame.
> */
> -} __rte_packed;
> +};
> +
> +static_assert(sizeof(struct rte_vlan_hdr) == 4,
> + "sizeof(struct rte_vlan_hdr) == 4");
> +static_assert(alignof(struct rte_vlan_hdr) == 2,
> + "alignof(struct rte_vlan_hdr) == 2");
>
>
>
> --
> 2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] net: improve vlan header type alignment
2024-10-13 8:35 [PATCH] net: improve vlan header type alignment Morten Brørup
2024-10-13 8:51 ` Morten Brørup
@ 2024-10-14 5:42 ` fengchengwen
2024-10-14 8:04 ` Bruce Richardson
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: fengchengwen @ 2024-10-14 5:42 UTC (permalink / raw)
To: Morten Brørup, dev
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
On 2024/10/13 16:35, Morten Brørup wrote:
> Ethernet packets can be VLAN tagged, i.e. an Ethernet header can have a
> VLAN tag (a.k.a. VLAN header) embedded.
> Since the Ethernet header is 2 byte aligned, and the VLAN tag is directly
> related to the Ethernet header, the VLAN tag is also 2 byte aligned, so
> packing the VLAN tag structure is not necessary.
>
> Furthermore, the Ethernet header type is implictly 2 byte aligned, so
> removed the superfluous explicit 2 byte alignment.
>
> Added static_asserts to verify the size and alignment of the various
> Ethernet types.
>
> Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] net: improve vlan header type alignment
2024-10-13 8:35 [PATCH] net: improve vlan header type alignment Morten Brørup
2024-10-13 8:51 ` Morten Brørup
2024-10-14 5:42 ` fengchengwen
@ 2024-10-14 8:04 ` Bruce Richardson
2024-10-17 20:44 ` Thomas Monjalon
2024-10-18 9:11 ` Thomas Monjalon
4 siblings, 0 replies; 7+ messages in thread
From: Bruce Richardson @ 2024-10-14 8:04 UTC (permalink / raw)
To: Morten Brørup; +Cc: dev
On Sun, Oct 13, 2024 at 08:35:54AM +0000, Morten Brørup wrote:
> Ethernet packets can be VLAN tagged, i.e. an Ethernet header can have a
> VLAN tag (a.k.a. VLAN header) embedded.
> Since the Ethernet header is 2 byte aligned, and the VLAN tag is directly
> related to the Ethernet header, the VLAN tag is also 2 byte aligned, so
> packing the VLAN tag structure is not necessary.
>
> Furthermore, the Ethernet header type is implictly 2 byte aligned, so
> removed the superfluous explicit 2 byte alignment.
>
> Added static_asserts to verify the size and alignment of the various
> Ethernet types.
>
> Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
> ---
> lib/net/rte_ether.h | 21 +++++++++++++++++++--
> 1 file changed, 19 insertions(+), 2 deletions(-)
>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] net: improve vlan header type alignment
2024-10-13 8:35 [PATCH] net: improve vlan header type alignment Morten Brørup
` (2 preceding siblings ...)
2024-10-14 8:04 ` Bruce Richardson
@ 2024-10-17 20:44 ` Thomas Monjalon
2024-10-17 23:41 ` Morten Brørup
2024-10-18 9:11 ` Thomas Monjalon
4 siblings, 1 reply; 7+ messages in thread
From: Thomas Monjalon @ 2024-10-17 20:44 UTC (permalink / raw)
To: Morten Brørup; +Cc: dev, Bruce Richardson
13/10/2024 10:35, Morten Brørup:
> +static_assert(sizeof(struct rte_ether_addr) == 6,
> + "sizeof(struct rte_ether_addr) == 6");
> +static_assert(alignof(struct rte_ether_addr) == 2,
> + "alignof(struct rte_ether_addr) == 2");
Instead of repeating the condition twice,
it would be simpler to use RTE_BUILD_BUG_ON
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH] net: improve vlan header type alignment
2024-10-17 20:44 ` Thomas Monjalon
@ 2024-10-17 23:41 ` Morten Brørup
0 siblings, 0 replies; 7+ messages in thread
From: Morten Brørup @ 2024-10-17 23:41 UTC (permalink / raw)
To: Thomas Monjalon; +Cc: dev, Bruce Richardson
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Thursday, 17 October 2024 22.44
>
> 13/10/2024 10:35, Morten Brørup:
> > +static_assert(sizeof(struct rte_ether_addr) == 6,
> > + "sizeof(struct rte_ether_addr) == 6");
> > +static_assert(alignof(struct rte_ether_addr) == 2,
> > + "alignof(struct rte_ether_addr) == 2");
>
> Instead of repeating the condition twice,
> it would be simpler to use RTE_BUILD_BUG_ON
RTE_BUILD_BUG_ON can only be used in code blocks, so it would need to be wrapped in some dummy function.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] net: improve vlan header type alignment
2024-10-13 8:35 [PATCH] net: improve vlan header type alignment Morten Brørup
` (3 preceding siblings ...)
2024-10-17 20:44 ` Thomas Monjalon
@ 2024-10-18 9:11 ` Thomas Monjalon
4 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2024-10-18 9:11 UTC (permalink / raw)
To: Morten Brørup; +Cc: dev
13/10/2024 10:35, Morten Brørup:
> Ethernet packets can be VLAN tagged, i.e. an Ethernet header can have a
> VLAN tag (a.k.a. VLAN header) embedded.
> Since the Ethernet header is 2 byte aligned, and the VLAN tag is directly
> related to the Ethernet header, the VLAN tag is also 2 byte aligned, so
> packing the VLAN tag structure is not necessary.
>
> Furthermore, the Ethernet header type is implictly 2 byte aligned, so
> removed the superfluous explicit 2 byte alignment.
>
> Added static_asserts to verify the size and alignment of the various
> Ethernet types.
>
> Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-10-18 9:11 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-13 8:35 [PATCH] net: improve vlan header type alignment Morten Brørup
2024-10-13 8:51 ` Morten Brørup
2024-10-14 5:42 ` fengchengwen
2024-10-14 8:04 ` Bruce Richardson
2024-10-17 20:44 ` Thomas Monjalon
2024-10-17 23:41 ` Morten Brørup
2024-10-18 9:11 ` Thomas Monjalon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).