Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Shreesh Adiga <16567adigashreesh@gmail.com>
Cc: Ard Biesheuvel <ardb@kernel.org>,
	Demian Shulhan <demyansh@gmail.com>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] lib/crc: arm64: Add NEON PMULL+EOR3 crc64_nvme implementation
Date: Mon, 16 Nov 2026 23:11:38 -0800	[thread overview]
Message-ID: <20261117071138.GA269875@sol> (raw)
In-Reply-To: <CA+-x59b-gUddP2cfHbzDrv9jupmeM1LeHkQnNXhE8_y6B+JC1A@mail.gmail.com>

On Tue, Nov 17, 2026 at 12:20:08PM +0530, Shreesh Adiga wrote:
> Hi Eric,
> 
> On Tue, Nov 17, 2026 at 5:31 AM Eric Biggers <ebiggers@kernel.org> wrote:
> > Was crc_kunit run?  It already has a benchmark in it.
> No, I have access to only one aarch64 device that is Android Mediatek
> Dimensity 9400 SoC without root access.
> Therefore I can't run crc_kunit on that, instead I have done userspace
> comparisons for the same kernel with libbenchmark.
> This is based on my earlier work for FFmpeg:
> https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21651
> I also have Corporate MacOS M5 and did check inside Ubuntu VM but that
> is not accurate due to virtualization.

Well, this is a kernel patch.  Contributors are expected to test their
kernel patches.  It can at least be done with QEMU.

> > The commit message should also clarify that this benefits ARMv8.2 and
> > later processors with the sha3 extension, not just ARMv9.  (E.g., Apple
> > M1 is an example of an ARMv8.4 processor that benefits.)
> Sure I will take care of it, but for now I am thinking of first
> improving the existing PMULL to have 4x unrolling as per Demian's
> suggestion.

That would be fine too.

> > Note that this is missing several optimizations compared to the x86
> > version (lib/crc/x86/crc-pclmul-template.S), including using
> > fold_consts_2x for a tail of 'len & 32', efficiently handling lengths
> > that aren't a multiple of 16 bytes, and reducing to the final CRC in two
> > carryless multiplication instructions rather than three.
> I was looking at the crc-pclmul-template.S code and I have a few queries.
> In this aarch64 version we only dispatch to this SIMD routine only
> when len>=128.
> Since we have 128 bytes available, do we have to add the tail of `len
> & 32` handling?

It's still useful, since the length mod 64 might be >= 32.

> Handling len not a multiple of 16 bytes (partial block) I will add but
> I am assuming that the dispatch will maintain 128 minimum len.

There is overhead in entering a kernel-mode NEON section, so it makes
sense to continue to have a minimum length.

> I was trying to understand your "reducing to the final CRC in two
> carryless multiplications rather than three" statement.
> From going through the code in crc-pclmul-template.S:
> .Lreduce_128bits_to_crc tracing the logic below this label, I see
> three clmul operations:
> _pclmulqdq CONSTS_XMM, LO64_TERMS, %xmm0, HI64_TERMS, %xmm1
> 
> _cond_vex movdqa, OFFSETOF_BARRETT_REDUCTION_CONSTS(CONSTS_PTR), CONSTS_XMM
> _pclmulqdq CONSTS_XMM, HI64_TERMS, %xmm0, HI64_TERMS, %xmm1
> 
> .if LSB_CRC && \n == 64
> _cond_vex punpcklqdq, %xmm1, %xmm2, %xmm2
> _pclmulqdq CONSTS_XMM, LO64_TERMS, %xmm1, HI64_TERMS, %xmm1
> 
> I even checked the Intel Whitepaper and the reduction for 64-bit CRC
> section "Final Reduction of 128-bits" also mentions 3 clmul.
> One for using x^128 followed by xor, and then 2 more for final barrett
> reduction with mu and poly.
> Thus I am confused about accomplishing this with just 2 clmul. Could
> you provide details on this?

Sorry, I misremembered.  It's indeed 3 minimum.  There are just a lot of
implementations out there that unnecessarily do 4, including
lib/crc/arm64/crc-t10dif-core.S for example which still exists.

- Eric

  reply	other threads:[~2026-11-17  7:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 17:29 [PATCH v2] lib/crc: arm64: Add NEON PMULL+EOR3 crc64_nvme implementation Shreesh Adiga
2026-11-17  0:01 ` Eric Biggers
2026-11-17  6:50   ` Shreesh Adiga
2026-11-17  7:11     ` Eric Biggers [this message]
2026-11-17  0:45 ` Demian Shulhan
2026-11-17  7:06   ` Shreesh Adiga
2026-11-17  9:00 ` David Laight

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=20261117071138.GA269875@sol \
    --to=ebiggers@kernel.org \
    --cc=16567adigashreesh@gmail.com \
    --cc=ardb@kernel.org \
    --cc=demyansh@gmail.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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