From: Thomas Monjalon <thomas@monjalon.net>
To: Andre Muezerie <andremue@linux.microsoft.com>
Cc: "Morten Brørup" <mb@smartsharesystems.com>,
roretzla@linux.microsoft.com, techboard@dpdk.org,
Yuying.Zhang@intel.com, aman.deep.singh@intel.com,
anatoly.burakov@intel.com, bruce.richardson@intel.com,
byron.marohn@intel.com, conor.walsh@intel.com,
cristian.dumitrescu@intel.com, david.hunt@intel.com,
dev@dpdk.org, dsosnowski@nvidia.com, gakhil@marvell.com,
jerinj@marvell.com, jingjing.wu@intel.com,
kirill.rybalchenko@intel.com, konstantin.v.ananyev@yandex.ru,
matan@nvidia.com, orika@nvidia.com, radu.nicolau@intel.com,
ruifeng.wang@arm.com, sameh.gobriel@intel.com,
sivaprasad.tummala@amd.com, skori@marvell.com,
stephen@networkplumber.org, suanmingm@nvidia.com,
vattunuru@marvell.com, viacheslavo@nvidia.com,
vladimir.medvedkin@intel.com, yipeng1.wang@intel.com,
"Robin Jarry" <rjarry@redhat.com>
Subject: Re: [PATCH v5 01/16] eal: provide pack start macro for MSVC
Date: Thu, 21 Nov 2024 21:51:36 +0100 [thread overview]
Message-ID: <2590421.vzjCzTo3RI@thomas> (raw)
In-Reply-To: <20241121193914.GA26557@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net>
21/11/2024 20:39, Andre Muezerie:
> On Tue, Nov 19, 2024 at 09:32:07AM +0100, Morten Brørup wrote:
> > > From: Andre Muezerie [mailto:andremue@linux.microsoft.com]
> > > Sent: Tuesday, 19 November 2024 05.35
> > >
> > > From: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > >
> > > MSVC struct packing is not compatible with GCC. Provide a macro that
> > > can be used to push existing pack value and sets packing to 1-byte.
> > > The existing __rte_packed macro is then used to restore the pack value
> > > prior to the push.
> > >
> > > Instead of providing macros exclusively for MSVC and for GCC the
> > > existing macro is deliberately utilized to trigger a warning if no
> > > existing packing has been pushed allowing easy identification of
> > > locations where the __rte_msvc_pack is missing.
> > >
> > > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > > ---
> > > lib/eal/include/rte_common.h | 4 +++-
> > > 1 file changed, 3 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/lib/eal/include/rte_common.h
> > > b/lib/eal/include/rte_common.h
> > > index 4d299f2b36..409890863e 100644
> > > --- a/lib/eal/include/rte_common.h
> > > +++ b/lib/eal/include/rte_common.h
> > > @@ -103,8 +103,10 @@ typedef uint16_t unaligned_uint16_t;
> > > * Force a structure to be packed
> > > */
> > > #ifdef RTE_TOOLCHAIN_MSVC
> > > -#define __rte_packed
> > > +#define __rte_msvc_pack __pragma(pack(push, 1))
> > > +#define __rte_packed __pragma(pack(pop))
> > > #else
> > > +#define __rte_msvc_pack
> > > #define __rte_packed __attribute__((__packed__))
> > > #endif
> > >
> > > --
> > > 2.47.0.vfs.0.3
> >
> > Before proceeding with this, can we please discuss the alternative, proposed here:
> > https://inbox.dpdk.org/dev/CAJFAV8yStgiBbe+Nkt9mC30r0+ZP64_kGuRHOzqd90RD2HXZyw@mail.gmail.com/
> >
> > The definition of the packing macro in OVS, for reference:
> > https://github.com/openvswitch/ovs/blob/main/include/openvswitch/compiler.h#L209
> >
> > The current solution requires __rte_packed to be placed at the end of a structure, although __attribute__((packed)) is normally allowed at the beginning (between the "struct" tag and the name of the structure), which introduces a high risk of contributors placing it "incorrectly", thus causing errors.
> >
> > I have a strong preference for an __RTE_PACKED(decl) variant.
> >
> > Here's a third alternative:
> > #ifdef RTE_TOOLCHAIN_MSVC
> > #define __rte_msvc_pack_begin __pragma(pack(push, 1))
> > #define __rte_msvc_pack_end __pragma(pack(pop))
> > #else
> > #define __rte_msvc_pack_begin
> > #define __rte_msvc_pack_end
> > #endif
> >
> > The third alternative is also problematic, e.g. if a contributor forgets the _end after the structure declaration, or adds another structure declaration before the _end.
> >
> > -Morten
>
> I looked at the suggestions made and I liked the one having a __RTE_PACKED macro
> the most.
>
> Advantages:
> - Can be placed in front of the struct, or even in the middle. Good for readability.
> - Does not require a different macro to be placed at the end of the structure as was
> proposed in V5 series.
> - Works well in 99% of the cases.
>
> Problems can arise when compiler directives are present in the struct, as they
> become arguments for __RTE_PACKED macro. This is not portable.
> I've seen two situations in the DPDK code:
>
> 1) #defines mentioned in the struct. In this situation we can just move the
> #define out of the struct.
>
> 2) #if/#ifdef/#elif mentioned in the struct.
> This is a somewhat common pattern in structs where fields change based on
> endianness.
> Example:
>
> /**
> * IPv4 Header
> */
> struct __rte_aligned(2) rte_ipv4_hdr {
> __extension__
> union {
> uint8_t version_ihl; /**< version and header length */
> struct {
> #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
> uint8_t ihl:4; /**< header length */
> uint8_t version:4; /**< version */
> #elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
> uint8_t version:4; /**< version */
> uint8_t ihl:4; /**< header length */
> #endif
> };
> };
> uint8_t type_of_service; /**< type of service */
> rte_be16_t total_length; /**< length of packet */
> ...
> } __rte_packed;
>
> One way to solve this is to move the #if to the outside. But that involves
> defining the struct twice (once for each endianness). It's less than
> ideal because common parts would be duplicated. I'm not sure how popular
> this would be.
> It's not so common though (about 1% of the structs?). I think it's an
> acceptable trade-off to get portable code, but I would like to hear your
> thoughts.
This code would be portable if Microsoft would align with other compilers.
Also I'm not sure we really need __rte_packed for most network protocols.
next prev parent reply other threads:[~2024-11-21 20:51 UTC|newest]
Thread overview: 151+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-20 21:05 [PATCH 00/15] fix packing of structs when building with MSVC Tyler Retzlaff
2024-03-20 21:05 ` [PATCH 01/15] eal: provide pack start macro for MSVC Tyler Retzlaff
2024-03-20 21:05 ` [PATCH 02/15] eal: pack structures when building with MSVC Tyler Retzlaff
2024-03-21 16:02 ` Bruce Richardson
2024-03-20 21:05 ` [PATCH 03/15] net: " Tyler Retzlaff
2024-10-07 1:14 ` Stephen Hemminger
2024-03-20 21:06 ` [PATCH 04/15] common/iavf: " Tyler Retzlaff
2024-03-20 21:06 ` [PATCH 05/15] common/idpf: " Tyler Retzlaff
2024-03-20 21:06 ` [PATCH 06/15] common/mlx5: " Tyler Retzlaff
2024-03-20 21:06 ` [PATCH 07/15] dma/ioat: " Tyler Retzlaff
2024-03-21 16:13 ` Bruce Richardson
2024-03-27 22:51 ` Tyler Retzlaff
2024-03-20 21:06 ` [PATCH 08/15] net/i40e: " Tyler Retzlaff
2024-03-20 21:06 ` [PATCH 09/15] net/iavf: " Tyler Retzlaff
2024-03-21 16:26 ` Bruce Richardson
2024-03-20 21:06 ` [PATCH 10/15] net/ice: " Tyler Retzlaff
2024-03-20 21:06 ` [PATCH 11/15] net/mlx5: " Tyler Retzlaff
2024-03-20 21:06 ` [PATCH 12/15] net/octeon_ep: " Tyler Retzlaff
2024-03-20 21:06 ` [PATCH 13/15] app/testpmd: " Tyler Retzlaff
2024-03-21 16:28 ` Bruce Richardson
2024-03-20 21:06 ` [PATCH 14/15] app/test: " Tyler Retzlaff
2024-03-20 21:06 ` [PATCH 15/15] examples: " Tyler Retzlaff
2024-03-21 16:31 ` Bruce Richardson
2024-03-21 15:32 ` [PATCH 00/15] fix packing of structs " Stephen Hemminger
2024-03-21 15:46 ` Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 " Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 01/15] eal: provide pack start macro for MSVC Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 02/15] eal: pack structures when building with MSVC Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 03/15] net: " Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 04/15] common/iavf: " Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 05/15] common/idpf: " Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 06/15] common/mlx5: " Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 07/15] dma/ioat: " Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 08/15] net/i40e: " Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 09/15] net/iavf: " Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 10/15] net/ice: " Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 11/15] net/mlx5: " Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 12/15] net/octeon_ep: " Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 13/15] app/testpmd: " Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 14/15] app/test: " Tyler Retzlaff
2024-03-27 23:09 ` [PATCH v2 15/15] examples: " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 00/16] fix packing of structs " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 01/16] eal: provide pack start macro for MSVC Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 02/16] eal: pack structures when building with MSVC Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 03/16] net: " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 04/16] common/iavf: " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 05/16] common/idpf: " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 06/16] common/mlx5: " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 07/16] dma/ioat: " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 08/16] net/i40e: " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 09/16] net/iavf: " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 10/16] net/ice: " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 11/16] net/mlx5: " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 12/16] net/octeon_ep: " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 13/16] app/testpmd: " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 14/16] app/test: " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 15/16] examples: " Tyler Retzlaff
2024-04-15 23:51 ` [PATCH v3 16/16] crypto/mlx5: " Tyler Retzlaff
2024-04-16 0:04 ` [PATCH v4 00/16] fix packing of structs " Tyler Retzlaff
2024-04-16 0:04 ` [PATCH v4 01/16] eal: provide pack start macro for MSVC Tyler Retzlaff
2024-04-16 0:04 ` [PATCH v4 02/16] eal: pack structures when building with MSVC Tyler Retzlaff
2024-04-16 0:05 ` [PATCH v4 03/16] net: " Tyler Retzlaff
2024-04-16 0:05 ` [PATCH v4 04/16] common/iavf: " Tyler Retzlaff
2024-04-16 0:05 ` [PATCH v4 05/16] common/idpf: " Tyler Retzlaff
2024-04-16 0:05 ` [PATCH v4 06/16] common/mlx5: " Tyler Retzlaff
2024-04-16 0:05 ` [PATCH v4 07/16] dma/ioat: " Tyler Retzlaff
2024-04-16 0:05 ` [PATCH v4 08/16] net/i40e: " Tyler Retzlaff
2024-04-16 0:05 ` [PATCH v4 09/16] net/iavf: " Tyler Retzlaff
2024-04-16 0:05 ` [PATCH v4 10/16] net/ice: " Tyler Retzlaff
2024-04-16 0:05 ` [PATCH v4 11/16] net/mlx5: " Tyler Retzlaff
2024-04-16 0:05 ` [PATCH v4 12/16] net/octeon_ep: " Tyler Retzlaff
2024-04-16 0:05 ` [PATCH v4 13/16] app/testpmd: " Tyler Retzlaff
2024-04-16 0:05 ` [PATCH v4 14/16] app/test: " Tyler Retzlaff
2024-04-16 0:05 ` [PATCH v4 15/16] examples: " Tyler Retzlaff
2024-04-16 0:05 ` [PATCH v4 16/16] crypto/mlx5: " Tyler Retzlaff
2024-11-19 4:35 ` [PATCH v5 00/16] fix packing of structs " Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 01/16] eal: provide pack start macro for MSVC Andre Muezerie
2024-11-19 8:32 ` Morten Brørup
2024-11-19 11:00 ` Konstantin Ananyev
2024-11-19 16:23 ` Andre Muezerie
2024-11-21 19:39 ` Andre Muezerie
2024-11-21 20:51 ` Thomas Monjalon [this message]
2024-11-22 0:11 ` Andre Muezerie
2024-11-22 8:13 ` Morten Brørup
2024-11-25 22:15 ` Andre Muezerie
2024-12-05 0:20 ` Tyler Retzlaff
2024-11-19 4:35 ` [PATCH v5 02/16] eal: pack structures when building with MSVC Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 03/16] net: " Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 04/16] common/iavf: " Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 05/16] common/idpf: " Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 06/16] common/mlx5: " Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 07/16] dma/ioat: " Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 08/16] net/i40e: " Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 09/16] net/iavf: " Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 10/16] net/ice: " Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 11/16] net/mlx5: " Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 12/16] net/octeon_ep: " Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 13/16] app/testpmd: " Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 14/16] app/test: " Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 15/16] examples: " Andre Muezerie
2024-11-19 4:35 ` [PATCH v5 16/16] crypto/mlx5: " Andre Muezerie
2024-11-20 21:13 ` [PATCH v5 00/16] fix packing of structs " Patrick Robb
2024-11-27 0:52 ` [PATCH v6 00/30] " Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 01/30] devtools: check packed attributes Andre Muezerie
2024-12-05 0:16 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 02/30] eal/include: add new packing macros Andre Muezerie
2024-12-05 0:09 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 03/30] app/test-pmd: remove unnecessary packed attributes Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 04/30] app/test: replace " Andre Muezerie
2024-12-05 0:21 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 05/30] doc/guides: " Andre Muezerie
2024-12-05 0:12 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 06/30] drivers/baseband: " Andre Muezerie
2024-12-05 0:23 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 07/30] drivers/bus: " Andre Muezerie
2024-12-05 0:25 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 08/30] drivers/common: " Andre Muezerie
2024-12-05 0:26 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 09/30] drivers/compress: " Andre Muezerie
2024-12-05 0:26 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 10/30] drivers/crypto: " Andre Muezerie
2024-12-05 0:27 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 11/30] drivers/dma: " Andre Muezerie
2024-12-05 0:28 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 12/30] drivers/event: " Andre Muezerie
2024-12-05 0:28 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 13/30] drivers/mempool: " Andre Muezerie
2024-12-05 0:51 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 14/30] drivers/net: " Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 15/30] drivers/raw: " Andre Muezerie
2024-12-05 0:51 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 16/30] drivers/regex: " Andre Muezerie
2024-12-05 0:52 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 17/30] drivers/vdpa: " Andre Muezerie
2024-12-05 0:54 ` Tyler Retzlaff
2024-11-27 0:52 ` [PATCH v6 18/30] examples/common: " Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 19/30] examples/ip-pipeline: remove " Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 20/30] examples/ipsec_secgw: replace " Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 21/30] examples/l3fwd-power: " Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 22/30] examples/l3fwd: " Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 23/30] examples/ptpclient: " Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 24/30] examples/vhost_blk: " Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 25/30] lib/eal: " Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 26/30] lib/ipsec: " Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 27/30] lib/net: " Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 28/30] lib/pipeline: " Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 29/30] lib/vhost: " Andre Muezerie
2024-11-27 0:52 ` [PATCH v6 30/30] lib/eal: remove __rte_packed Andre Muezerie
2024-12-05 0:11 ` Tyler Retzlaff
2024-12-23 11:03 ` [PATCH v6 00/30] fix packing of structs when building with MSVC David Marchand
2024-12-23 11:46 ` David Marchand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2590421.vzjCzTo3RI@thomas \
--to=thomas@monjalon.net \
--cc=Yuying.Zhang@intel.com \
--cc=aman.deep.singh@intel.com \
--cc=anatoly.burakov@intel.com \
--cc=andremue@linux.microsoft.com \
--cc=bruce.richardson@intel.com \
--cc=byron.marohn@intel.com \
--cc=conor.walsh@intel.com \
--cc=cristian.dumitrescu@intel.com \
--cc=david.hunt@intel.com \
--cc=dev@dpdk.org \
--cc=dsosnowski@nvidia.com \
--cc=gakhil@marvell.com \
--cc=jerinj@marvell.com \
--cc=jingjing.wu@intel.com \
--cc=kirill.rybalchenko@intel.com \
--cc=konstantin.v.ananyev@yandex.ru \
--cc=matan@nvidia.com \
--cc=mb@smartsharesystems.com \
--cc=orika@nvidia.com \
--cc=radu.nicolau@intel.com \
--cc=rjarry@redhat.com \
--cc=roretzla@linux.microsoft.com \
--cc=ruifeng.wang@arm.com \
--cc=sameh.gobriel@intel.com \
--cc=sivaprasad.tummala@amd.com \
--cc=skori@marvell.com \
--cc=stephen@networkplumber.org \
--cc=suanmingm@nvidia.com \
--cc=techboard@dpdk.org \
--cc=vattunuru@marvell.com \
--cc=viacheslavo@nvidia.com \
--cc=vladimir.medvedkin@intel.com \
--cc=yipeng1.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).