netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Fertser <fercerpav@gmail.com>
To: David Laight <david.laight.linux@gmail.com>
Cc: kalavakunta.hari.prasad@gmail.com, sam@mendozajonas.com,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, npeacock@meta.com,
	akozlov@meta.com, hkalavakunta@meta.com
Subject: Re: [PATCH net-next v2] net: ncsi: Fix GCPS 64-bit member variables
Date: Mon, 14 Apr 2025 01:52:13 +0300	[thread overview]
Message-ID: <Z/xAHeYXfFAUpxbR@home.paul.comp> (raw)
In-Reply-To: <20250412102304.3f74738c@pumpkin>

Hello David,

Many thanks for chiming in and correcting my mistake. Hari, sorry for
misleading you on the last iteration.

On Sat, Apr 12, 2025 at 10:23:04AM +0100, David Laight wrote:
> On Thu, 10 Apr 2025 13:50:58 +0300
> Paul Fertser <fercerpav@gmail.com> wrote:
> 
> > Hello Hari,
> > 
> > Thank you for the patch, it looks really clean. However I have one
> > more question now.
> > 
> > On Wed, Apr 09, 2025 at 06:23:08PM -0700, kalavakunta.hari.prasad@gmail.com wrote:
> > > @@ -290,11 +289,11 @@ struct ncsi_rsp_gcps_pkt {
> > >  	__be32                  tx_1023_frames; /* Tx 512-1023 bytes frames   */
> > >  	__be32                  tx_1522_frames; /* Tx 1024-1522 bytes frames  */
> > >  	__be32                  tx_9022_frames; /* Tx 1523-9022 bytes frames  */
> > > -	__be32                  rx_valid_bytes; /* Rx valid bytes             */
> > > +	__be64                  rx_valid_bytes; /* Rx valid bytes             */
> > >  	__be32                  rx_runt_pkts;   /* Rx error runt packets      */
> > >  	__be32                  rx_jabber_pkts; /* Rx error jabber packets    */
> > >  	__be32                  checksum;       /* Checksum                   */
> > > -};
> > > +}  __packed __aligned(4);  
> > 
> > This made me check the Specification and indeed somehow it happened
> > that they have forgotten to ensure natural alignment for 64-bit fields
> > (at least they cared enough to do it for 32-bit values). [0] is the
> > relevant read.
> > 
> > > +	ncs->hnc_cnt            = be64_to_cpu(rsp->cnt);  
> 
> Doesn't look related to the structure above.

This is related to the earlier change of the same struct, I just
omitted that hunk while quoting.

> > This means that while it works fine on common BMCs now (since they run
> > in 32-bit mode) the access will be trappped as unaligned on 64-bit
> > Arms which one day will be common (Aspeed AST2700, Nuvoton NPCM8XX).
> > 
> > So I guess you should be doing `be64_to_cpup(&rsp->cnt)` there.
> 
> That is is the one that fails - the compiler is likely to warn about
> taking the address of a member of a packed structure.

Indeed I was confused. I was reading just
include/linux/byteorder/generic.h and expecting some kind of tricky
behaviour from the compiler (for the sake of optimisation as usual)
and wasn't aware of [0]. Taking address of such a field would indeed
produce a warning with -Waddress-of-packed-member.

> IIRC it is enough to mark the member rx_valid_bytes __packed.
> That removes the padding before it and the compiler will then assume
> it is 4-byte aligned.

The problem is that this struct is full of members that happen to be
unaligned (as the NC-SI standard specified that), it's used to unpack
a response packet returned by networking interface, so ratehr than
having every __be64 value there __packed it's cleaner to have the
attribute specified for the whole struct I guess.

Thanks again!


[0] https://www.kernel.org/doc/html/latest/core-api/unaligned-memory-access.html#code-that-does-not-cause-unaligned-access

  reply	other threads:[~2025-04-13 22:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-10  1:23 [PATCH net-next v2] net: ncsi: Fix GCPS 64-bit member variables kalavakunta.hari.prasad
2025-04-10 10:50 ` Paul Fertser
2025-04-12  9:23   ` David Laight
2025-04-13 22:52     ` Paul Fertser [this message]
2025-04-14 16:51       ` Hari Kalavakunta
2025-04-15 11:41 ` Paul Fertser
2025-04-15 13:30 ` 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=Z/xAHeYXfFAUpxbR@home.paul.comp \
    --to=fercerpav@gmail.com \
    --cc=akozlov@meta.com \
    --cc=davem@davemloft.net \
    --cc=david.laight.linux@gmail.com \
    --cc=edumazet@google.com \
    --cc=hkalavakunta@meta.com \
    --cc=horms@kernel.org \
    --cc=kalavakunta.hari.prasad@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=npeacock@meta.com \
    --cc=pabeni@redhat.com \
    --cc=sam@mendozajonas.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).