RE: [PATCH V7 2/4] asm-generic/io.h: Add big-endian MMIO accessors
From: Guntupalli, Manikanta
Date: Wed Sep 24 2025 - 06:13:04 EST
[Public]
Hi,
> -----Original Message-----
> From: Arnd Bergmann <arnd@xxxxxxxx>
> Sent: Wednesday, September 24, 2025 3:16 PM
> To: Guntupalli, Manikanta <manikanta.guntupalli@xxxxxxx>; git (AMD-Xilinx)
> <git@xxxxxxx>; Simek, Michal <michal.simek@xxxxxxx>; Alexandre Belloni
> <alexandre.belloni@xxxxxxxxxxx>; Frank Li <Frank.Li@xxxxxxx>; Rob Herring
> <robh@xxxxxxxxxx>; krzk+dt@xxxxxxxxxx; Conor Dooley <conor+dt@xxxxxxxxxx>;
> Przemysław Gaj <pgaj@xxxxxxxxxxx>; Wolfram Sang <wsa+renesas@sang-
> engineering.com>; tommaso.merciai.xr@xxxxxxxxxxxxxx;
> quic_msavaliy@xxxxxxxxxxx; S-k, Shyam-sundar <Shyam-sundar.S-k@xxxxxxx>;
> Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx>; 'billy_tsai@xxxxxxxxxxxxxx'
> <billy_tsai@xxxxxxxxxxxxxx>; Kees Cook <kees@xxxxxxxxxx>; Gustavo A. R. Silva
> <gustavoars@xxxxxxxxxx>; Jarkko Nikula <jarkko.nikula@xxxxxxxxxxxxxxx>; Jorge
> Marques <jorge.marques@xxxxxxxxxx>; linux-i3c@xxxxxxxxxxxxxxxxxxx;
> devicetree@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx; Linux-Arch <linux-
> arch@xxxxxxxxxxxxxxx>; linux-hardening@xxxxxxxxxxxxxxx
> Cc: Pandey, Radhey Shyam <radhey.shyam.pandey@xxxxxxx>; Goud, Srinivas
> <srinivas.goud@xxxxxxx>; Datta, Shubhrajyoti <shubhrajyoti.datta@xxxxxxx>;
> manion05gk@xxxxxxxxx
> Subject: Re: [PATCH V7 2/4] asm-generic/io.h: Add big-endian MMIO accessors
>
> On Wed, Sep 24, 2025, at 10:59, Guntupalli, Manikanta wrote:
> >> From: Arnd Bergmann <arnd@xxxxxxxx>
> >> Sent: Wednesday, September 24, 2025 12:08 AM
> >> To: Guntupalli, Manikanta <manikanta.guntupalli@xxxxxxx>; git
> >> (AMD-Xilinx)
> >
> > From both description and implementation, {read,write}{b,w,l,q}()
> > access little-endian memory and return the result in native endianness:
> ...
> > This works on little-endian CPUs, but on big-endian CPUs the
> > {read,write}{b,w,l,q}() helpers already return data in big-endian
> > format.
>
> > The extra byte swap in io{read,write}*be() therefore corrupts the
> > data, producing little-endian values when big-endian is expected.
>
> > The newly introduced {read,write}{w,l,q}_be() helpers directly access
> > big-endian IO memory and return results in native endianness, avoiding
> > this mismatch.
>
> No, in both your {read,write}{w,l,q}_be() and the existing io{read,write}*be() helpers,
> big-endian platforms end up with an even number of swaps
> (0 or 2), while little-endian platforms have exactly one swap.
>
> The only exception is your {read,write}s{w,l,q}_be() string helpers that are wrong
> because they have an extra swap and are broken on FIFO registers in little-endian
> kernels.
We have performed our validation on little-endian kernels, and in our testing, the helpers worked correctly without any issues.
Thanks,
Manikanta.