Re: [net PATCH 1/2] net: dsa: qca8k: fix inband mgmt for big-endian systems

From: Vladimir Oltean
Date: Wed Oct 12 2022 - 09:32:00 EST


On Wed, Oct 12, 2022 at 02:59:17PM +0200, Christian Marangi wrote:
> > > Humm...
> > >
> > > This might have the same alignment issue as the second patch. In fact,
> > > because the Ethernet header is 14 bytes in size, it is often
> > > deliberately out of alignment by 2 bytes, so that the IP header is
> > > aligned. You should probably be using get_unaligned_le32() when
> > > accessing members of mgmt_ethhdr.
> > >
> > > Andrew
> >
> > Should I replace everything to get_unaligned_le32? Or this is only
> > needed for the mgmt_ethhdr as it's 12 bytes?
> >
> > The skb data is all 32 bit contiguous stuff so it should be safe? Or
> > should we treat that also as unalligned just to make sure?
> >
> > Same question for patch 2. the rest of the mib in skb data are all 32 or
> > 64 values contiguous so wonder if we just take extra care of the
> > mgmt_ethhdr.
> >
>
> Also also... Should I use put_unalligned to fill the mgmt_ethhdr?

Documentation/core-api/unaligned-memory-access.rst section "Alignment vs. Networking"
says that the IP header is aligned to a 4 byte boundary.

Relative to the IP header, skb_mac_header(skb) is a pointer that's 14
bytes behind, right?

14 bytes behind something aligned to a 4 byte boundary is something
that's not aligned to a 4 byte boundary. That's why Andrew is suggesting
to use the unaligned helper for accesses (both put and get).

On-stack data structures don't need this, the compiler should take care
of aligning them and their fields appropriately. The trouble is with
pointers generated using manual arithmetics.