Re: [PATCH RFC v2 0/6] lib/crc: x86: convert the CRC assembly to C intrinsics

From: Qu Wenruo

Date: Thu Nov 19 2026 - 23:24:21 EST




在 2026/11/20 14:12, Eric Biggers 写道:
[ +Cc x86@xxxxxxxxxx ]

Hi Qu,

On Fri, Nov 20, 2026 at 11:48:58AM +1030, Qu Wenruo wrote:
[...]

Thanks for exploring this.

I think we should be honest: this would be a negative for
maintainability at least in the short term. We'd be replacing existing
well-optimized and well-documented code with an experimental use of x86
C intrinsics in the kernel, with many of the original comments stripped
out or made inconsistent,

That's indeed a huge problem, thanks for pointing this out.

Sorry that I didn't manually compare the comment part before and after the change, that's all my bad.

That's in fact the most important part for readability, and my focus on the generated code blinded me on this important part.

and signing up to fight with compiler issues
(including inconsistent support between compilers, having to use
error-prone hacks to use the x86 intrinsics in the kernel at all,

To be honest, to make kernel use intrinsics with current latest gcc/clang is easier than my initial expectation.

And even for ancient ones, only GCC 8.1/8.2 are really problematic, again better than my expectation, but still requires extra adhoc fixes for certain compilers.

and
inefficient code generation which in some cases might not be solvable
without contributing fixes to gcc/clang).

I've used the x86 C intrinsics extensively in userspace projects. So
sure, some of these compiler issues (minus the ones specific to trying
to use the intrinsics in the kernel) are things I'm used to already.
It's just been nice to not have to deal with them in the kernel.

Note that gcc can't even generate simple loops using vector intrinsics
without emitting unnecessary move instructions. I reported it years ago
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107892) and it's still
unfixed. So realistically, we either need to simply tolerate bad
codegen like that, or actually step up and actively contribute fixes to
the compilers (as merely opening a bug report does not result in a fix).

Personally speaking I'd also prefer the compiler to do a lot of things better, include not pulling in the memory allocation headers just for x86 intrinsics.


And as you mentioned in your cover letter, a lot of the code grew in
size and became slower, especially for short inputs which are important
for some in-kernel use cases. So clearly there is some bad codegen
going on compared to what was there before.

I kind of feel this could only be a benefit in the long term if we
actually go all in and commit to switching the crypto code over to this
style of implementation as well. But that area has a lot more code.
And that code also has another thorny issue: when operating on secrets,
it has to make sure to only use x86 instructions that are in the DOITM
(Data Operand Independent Timing Mode) subset. Yet there's no compiler
support for restricting the used instructions to that subset, and no
announced plans from anyone (Intel, AMD, or otherwise) to implement it.

I'll also note that the hardest part to understand about this code (IMO)
is actually the polynomial math, especially the Barrett reduction. And
yet this series deletes or greatly shortens many of the comments
explaining it, leaving unexplained operations, factually wrong comments
(especially for the Barrett reduction), and dangling references. That's
most of the negative diff, too.

So if we're going to proceed, I'd at least like to see a version that
compares a bit more favorably to the original. But also I think before
diving into this approach I'd like wider agreement in the Linux
community (x86 maintainers, crypto, etc.) that the x86 intrinsics are
the way to go, and for there to be a path forward for DOITM as well, and
hopefully some interest in improving the compilers too.

Sure, that's a very reasonable argument, and I'm definitely stepping beyond my ability and initial objective (just to use the same intrinsics code in both kernel and progs).

I can definitely wait for more feedback on this topic before continue any future work.

And to my initial objective, I'd check other user space CRC32C implementation as a reference for now.

Thanks,
Qu


- Eric