Re: [PATCH] LoongArch: Add unaligned access support

From: Xi Ruoyao
Date: Mon Oct 17 2022 - 04:14:30 EST


On Mon, 2022-10-17 at 09:38 +0200, Arnd Bergmann wrote:

> > Some unaligned accesses are observed from the kernel network stack, it
> > seems related to whether the packet aligns to IP header or MAC header.
>
> This is usually a bug in the device driver. It's a fairly common bug
> since the network driver has to ensure the alignment is correct, but
> it's usually fixable, and fixing it results in better performance on
> machines that support unaligned access as well.

Or, maybe a GCC bug is causing -mstrict-align not implemented correctly.

> > And, gcc has a -mstrict-align parameter, if without this, there are
> > unaligned instructions.
>
> Does this default to strict or non-strict mode? Usually gcc does not
> allow to turn this off on architectures that have no hardware support
> for unaligned access.

On LoongArch the unaligned access support is optional. An
implementation is allowed to implement it or not. The software can
determine if it's supported by a CPUCFG instruction.

I think -march=la264 will turn off strict align, but it's not added into
GCC yet.

The GCC default is -mno-strict-align. I expressed my concern about this
decision when I reviewed the GCC port, but at last they just kept the
decision. But the kernel already sets -mstrict-align in CFLAGS anyway.

--
Xi Ruoyao <xry111@xxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University