mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: "Wentao Guan" <guanwentao@uniontech.com>
Cc: "Eric Biggers" <ebiggers@kernel.org>,
	"chenhuacai" <chenhuacai@kernel.org>,
	"Huacai Chen" <chenhuacai@loongson.cn>,
	"Ard Biesheuvel" <ardb@kernel.org>,
	"linux-crypto" <linux-crypto@vger.kernel.org>,
	"WANG Xuerui" <kernel@xen0n.name>,
	"loongarch" <loongarch@lists.linux.dev>,
	"linux-kernel" <linux-kernel@vger.kernel.org>,
	"Tianyang Zhang" <zhangtianyang@loongson.cn>
Subject: Re: [PATCH 1/2] lib/crc: loongarch: Use hardware unaligned load in CRC32(C) loops
Date: Mon, 12 Oct 2026 14:08:02 +0100	[thread overview]
Message-ID: <20261012140802.267c293a@pumpkin> (raw)
In-Reply-To: <tencent_339CC94656CDACB222608A27@qq.com>

On Mon, 12 Oct 2026 19:11:02 +0800
"Wentao Guan" <guanwentao@uniontech.com> wrote:

> Hi Eric,
> 
> > On Mon, Oct 12, 2026 at 02:43:47PM +0800, Huacai Chen wrote:  
> > > Yes, we considered modifying {get,put}_unaligned_* globally. But it is
> > > not arch-specific code and we have no way to override it.
> > >
> > > On the other hand, the byte-to-byte {get,put}_unaligned_* is always
> > > correct, we are free to only optimise the hot path (like crc32 code).  
> > 
> > The unaligned access macros are used in lots of other
> > performance-critical code.  Hacks in random places don't scale.  
> Agree, from their side, they thought may like: the change is minimal?
> My thought like what other arch did, use alternative to patch the {get,put}_unaligned_*?
> 
> > > > > Since loongarch made the incorrect decision to not specify unaligned
> > > > > access unconditionally, similar to RISC-V it can be worked around only
> > > > > by overriding that in the kconfig.  For loongarch that appears that
> > > > > already be implemented; just unset CONFIG_ARCH_STRICT_ALIGN when you
> > > > > know the kernel will run only on CPUs that have fixed this bug.  
> > > > I think that we have the use cases to provide the general kernel instead of the two kernel with
> > > > different config, so the image increase will be tolerated.  
> > > Yes, the default configuration is to keep CONFIG_ARCH_STRICT_ALIGN set
> > > for single kernel binary.  
> > 
> > So don't do that.  It does not work for divergent unaligned access
> > support, as the other architectures have learned long ago.  
>
> From RISC-V workaround learn, their model is different,
> they want to default unaligned access, and trap and emulate the access.

Which is entirely broken from a performance point of view.
Especially since some system hide the emulation from the kernel.

> 
> This LoongArch model is point to default safely aligned access,
> after detected the unaligned access support, next to use the unaligned to speed up.
> Or did anything I missing?

There are three cases:
1) Unaligned accesses fault and must be avoided.
2) Unaligned accesses are executed by the cpu but take a small number
   of extra cycles.
3) Unaligned accesses are executed by the cpu and are (almost always)
   free.
For (2) it is still worth aligning buffers.
x86 is pretty much in camp (3) - I suspect it uses byte-enables on a 64 byte
wide interface to the cache.

If you align buffers you don't have to worry about things like
'word at a time strlen()' running off the end of a page.

David

> 
> BRs
> Wentao Guan

  reply	other threads:[~2026-10-12 13:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-11 14:29 Huacai Chen
2026-10-11 14:29 ` [PATCH 2/2] lib/crc: loongarch: Add 3-way parallel CRC32(C) for large buffers Huacai Chen
2026-10-11 15:12   ` Eric Biggers
2026-10-12  6:45     ` Huacai Chen
2026-10-12  7:24       ` Eric Biggers
2026-10-12 10:02         ` Huacai Chen
2026-10-11 14:48 ` Re:[PATCH 1/2] lib/crc: loongarch: Use hardware unaligned load in CRC32(C) loops Wentao Guan
2026-10-11 15:00 ` [PATCH " Eric Biggers
2026-10-11 15:14   ` Wentao Guan
2026-10-12  6:43     ` Huacai Chen
2026-10-12  7:22       ` Eric Biggers
2026-10-12 11:11         ` Wentao Guan
2026-10-12 13:08           ` David Laight [this message]
2026-10-12 14:50             ` Wentao Guan

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=20261012140802.267c293a@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=ardb@kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=chenhuacai@loongson.cn \
    --cc=ebiggers@kernel.org \
    --cc=guanwentao@uniontech.com \
    --cc=kernel@xen0n.name \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=zhangtianyang@loongson.cn \
    /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

all inboxes | Powered by JetHome®