netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: "Samudrala, Sridhar" <sridhar.samudrala@intel.com>
Cc: anthony.l.nguyen@intel.com,
	Norbert Ciosek <norbertx.ciosek@intel.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, netdev <netdev@vger.kernel.org>,
	sassmann@redhat.com,
	Konrad Jankowski <konrad0.jankowski@intel.com>,
	Mateusz Palczewski <mateusz.palczewski@intel.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net 1/4] virtchnl: Fix layout of RSS structures
Date: Sat, 27 Mar 2021 10:53:23 +0100	[thread overview]
Message-ID: <CAMuHMdW3BSkJXjSL5R4xuYv6Yb765U5zwBCLcsSW+zr_K7898g@mail.gmail.com> (raw)
In-Reply-To: <ce03118c-d368-def0-8a1f-8c3a770901d6@intel.com>

Hi Samudrala,

On Fri, Mar 26, 2021 at 11:45 PM Samudrala, Sridhar
<sridhar.samudrala@intel.com> wrote:
> On 3/26/2021 1:06 AM, Geert Uytterhoeven wrote:
> > On Thu, Mar 25, 2021 at 11:29 PM Tony Nguyen <anthony.l.nguyen@intel.com> wrote:
> > From: Norbert Ciosek <norbertx.ciosek@intel.com>
> >
> > Remove padding from RSS structures. Previous layout
> > could lead to unwanted compiler optimizations
> > in loops when iterating over key and lut arrays.
> >
> > From an earlier private conversation with Mateusz, I understand the real
> > explanation is that key[] and lut[] must be at the end of the
> > structures, because they are used as flexible array members?
> >
> > Fixes: 65ece6de0114 ("virtchnl: Add missing explicit padding to structures")
> > Signed-off-by: Norbert Ciosek <norbertx.ciosek@intel.com>
> > Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>
> > Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
> >
> > --- a/include/linux/avf/virtchnl.h
> > +++ b/include/linux/avf/virtchnl.h
> > @@ -476,7 +476,6 @@ struct virtchnl_rss_key {
> >         u16 vsi_id;
> >         u16 key_len;
> >         u8 key[1];         /* RSS hash key, packed bytes */
> > -       u8 pad[1];
> >  };
> >
> >  VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key);
> > @@ -485,7 +484,6 @@ struct virtchnl_rss_lut {
> >         u16 vsi_id;
> >         u16 lut_entries;
> >         u8 lut[1];        /* RSS lookup table */
> > -       u8 pad[1];
> >  };
> >
> > If you use a flexible array member, it should be declared without a size,
> > i.e.
> >
> >     u8 key[];
> >
> > Everything else is (trying to) fool the compiler, and leading to undefined
> > behavior, and people (re)adding explicit padding.
>
> This header file is shared across other OSes that use C++ that doesn't support
> flexible arrays. So the structures in this file use an array of size 1 as a last
> element to enable variable sized arrays.

I don't think it is accepted practice to have non-Linux-isms in
include/*linux*/avf/virtchnl.h header files.  Moreover, using a size
of 1 is counter-intuitive for people used to Linux kernel development,
and may lead to off-by-one errors in calculation of sizes.

If you insist on ignoring the above, this definitely deserves a
comment next to the member's declaration.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

  parent reply	other threads:[~2021-03-27  9:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-25 22:31 [PATCH net 0/4][pull request] Intel Wired LAN Driver Updates 2021-03-25 Tony Nguyen
2021-03-25 22:31 ` [PATCH net 1/4] virtchnl: Fix layout of RSS structures Tony Nguyen
2021-03-26  8:06   ` Geert Uytterhoeven
     [not found]     ` <ce03118c-d368-def0-8a1f-8c3a770901d6@intel.com>
2021-03-27  9:53       ` Geert Uytterhoeven [this message]
2021-03-29  3:19         ` Samudrala, Sridhar
2021-03-25 22:31 ` [PATCH net 2/4] i40e: Added Asym_Pause to supported link modes Tony Nguyen
2021-03-25 22:31 ` [PATCH net 3/4] i40e: Fix kernel oops when i40e driver removes VF's Tony Nguyen
2021-03-25 22:31 ` [PATCH net 4/4] i40e: Fix oops at i40e_rebuild() Tony Nguyen
2021-03-26  1:00 ` [PATCH net 0/4][pull request] Intel Wired LAN Driver Updates 2021-03-25 patchwork-bot+netdevbpf

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=CAMuHMdW3BSkJXjSL5R4xuYv6Yb765U5zwBCLcsSW+zr_K7898g@mail.gmail.com \
    --to=geert@linux-m68k.org \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=konrad0.jankowski@intel.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mateusz.palczewski@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=norbertx.ciosek@intel.com \
    --cc=sassmann@redhat.com \
    --cc=sridhar.samudrala@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).