public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
From: Edward Cree <ecree.xilinx@gmail.com>
To: kernel test robot <lkp@intel.com>
Cc: llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
	linux-kernel@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
	Andy Moreton <andy.moreton@amd.com>,
	Simon Horman <simon.horman@corigine.com>
Subject: Re: drivers/net/ethernet/sfc/selftest.c:48:16: warning: field ip within 'struct efx_loopback_payload::(anonymous at drivers/net/ethernet/sfc/selftest.c:46:2)' is less aligned than 'struct iphdr' and is usually due to 'struct efx_loopback_payload::(anonymous a...
Date: Wed, 22 Nov 2023 16:15:49 +0000	[thread overview]
Message-ID: <3f42dee6-a6e2-1b35-674f-309aae042ae7@gmail.com> (raw)
In-Reply-To: <202311220537.geMTr31W-lkp@intel.com>

On 21/11/2023 21:25, kernel test robot wrote:
> Hi Edward,
> 
> FYI, the error/warning still remains.

As I've argued previously, this is a false positive / compiler bug,
 and there is no way to resolve it without making the code strictly
 worse.

This:
>>> drivers/net/ethernet/sfc/selftest.c:48:16: warning: field ip within 'struct efx_loopback_payload::(anonymous at drivers/net/ethernet/sfc/selftest.c:46:2)' is less aligned than 'struct iphdr' and is usually due to 'struct efx_loopback_payload::(anonymous at drivers/net/ethernet/sfc/selftest.c:46:2)' being packed, which can lead to unaligned accesses [-Wunaligned-access]
 is complaining about alignment within an anonymous struct, which
 only ever appears embedded within a larger struct in a way which
 maintains the correct alignment.

#ifdef RANT

Indeed, the only way we even *could* create an unaligned access
 out of this code would be via a declaration like
    typeof(*(((struct efx_loopback_payload *)0)->packet)) bad;
 because *the struct is anonymous*.  And if that happened, the
 bad declaration would be the place to warn, both because it's
 incredibly ugly and because it's the place that's actually
 wrong.  The struct definition itself is entirely *fine*.
The compiler should be able to detect that, and if it's not smart
 enough to do so then it shouldn't be trying to warn in the first
 place.  Quoth Linus[1]:

 "And if the compiler isn't good enough to do it, then the compiler
  shouldn't be warning about something that it hasn't got a clue about."

The anonymous struct has to be there so that we can placate the
 memcpy hardening, and it has to contain a struct iphdr at a
 4n+2 offset because that's what shape the on-the-wire packet
 *is*.  To avoid the warning we would need to lose __packed and
 memcpy all of the members in and out of the buffer individually
 to explicitly-calculated offsets, which is worse code.

#endif

Either fix the compiler to not warn, or fix your automation to
 ignore this instance of the warning.

-ed

[1]: https://yarchive.net/comp/linux/gcc.html#13

  reply	other threads:[~2023-11-22 16:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21 21:25 drivers/net/ethernet/sfc/selftest.c:48:16: warning: field ip within 'struct efx_loopback_payload::(anonymous at drivers/net/ethernet/sfc/selftest.c:46:2)' is less aligned than 'struct iphdr' and is usually due to 'struct efx_loopback_payload::(anonymous a kernel test robot
2023-11-22 16:15 ` Edward Cree [this message]
2023-11-23  3:05   ` Yujie Liu
  -- strict thread matches above, loose matches on Subject: below --
2023-08-27 20:25 kernel test robot

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=3f42dee6-a6e2-1b35-674f-309aae042ae7@gmail.com \
    --to=ecree.xilinx@gmail.com \
    --cc=andy.moreton@amd.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=llvm@lists.linux.dev \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=simon.horman@corigine.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