linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Ard Biesheuvel <ardb@kernel.org>,
	linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-crypto@vger.kernel.org, linux-ext4@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org,
	linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev,
	sparclinux@vger.kernel.org, x86@kernel.org
Subject: Re: [PATCH v2 04/18] crypto: crc32 - don't unnecessarily register arch algorithms
Date: Sat, 2 Nov 2024 09:36:05 -0700	[thread overview]
Message-ID: <20241102163605.GA28213@sol.localdomain> (raw)
In-Reply-To: <ZyYIO6RpjTFteaxH@gondor.apana.org.au>

On Sat, Nov 02, 2024 at 07:08:43PM +0800, Herbert Xu wrote:
> On Sat, Nov 02, 2024 at 12:05:01PM +0100, Ard Biesheuvel wrote:
> >
> > The only issue resulting from *not* taking this patch is that btrfs
> > may misidentify the CRC32 implementation as being 'slow' and take an
> > alternative code path, which does not necessarily result in worse
> > performance.
> 
> If we were removing crc32* (or at least crc32*-arch) from the Crypto
> API then these patches would be redundant.  But if we're keeping them
> because btrfs uses them then we should definitely make crc32*-arch
> do the right thing.  IOW they should not be registered if they're
> the same as crc32*-generic.
> 
> Thanks,

I would like to eventually remove crc32 and crc32c from the crypto API, but it
will take some time to get all the users converted.  If there are AF_ALG users
it could even be impossible, though the usual culprit, iwd, doesn't appear to
use any CRCs, so hopefully we are fine there.

I will plan to keep this patch, but change it to use a crc32_optimizations()
function instead which was Ard's first suggestion.

I don't think Ard's static_call suggestion would work as-is, since considering
the following:

    static inline u32 __pure crc32_le(u32 crc, const u8 *p, size_t len)
    {
            if (IS_ENABLED(CONFIG_CRC32_ARCH))
                    return static_call(crc32_le_arch)(crc, p, len);
            return crc32_le_base(crc, p, len);
    }

... the 'static_call(crc32_le_arch)(crc, p, len)' will be inlined into every
user, which could be a loadable module which gets loaded after crc32-${arch}.ko.
And AFAIK, static calls in that module won't be updated in that case.

That could be avoided by making crc32_le() a non-inline function in lib/crc32.c,
so the static call would only be in that one place.  That has the slight
disadvantage that it would introduce an extra jump into the common case where
the optimized function is enabled.  Considering that some users are passing
small amounts of data into the CRC functions (e.g., 4 bytes), I would like to
minimize the overhead as much as possible.

It could also be avoided by making CRC32 and CRC32_ARCH bool rather than
tristate.  I would prefer not to do that, since there can be situations where
only loadable modules need these functions so they should not have to be built
into the core kernel.

So I plan to go with the crc32_optimizations() solution in v3.

- Eric


  reply	other threads:[~2024-11-02 16:36 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25 19:14 [PATCH v2 00/18] Wire up CRC32 library functions to arch-optimized code Eric Biggers
2024-10-25 19:14 ` [PATCH v2 01/18] lib/crc32: drop leading underscores from __crc32c_le_base Eric Biggers
2024-10-25 19:14 ` [PATCH v2 02/18] lib/crc32: improve support for arch-specific overrides Eric Biggers
2024-10-25 19:14 ` [PATCH v2 03/18] lib/crc32: expose whether the lib is really optimized at runtime Eric Biggers
2024-10-25 20:32   ` Ard Biesheuvel
2024-10-25 21:32     ` Eric Biggers
2024-10-25 21:37       ` Ard Biesheuvel
2024-10-25 22:31         ` Eric Biggers
2024-10-25 19:14 ` [PATCH v2 04/18] crypto: crc32 - don't unnecessarily register arch algorithms Eric Biggers
2024-10-25 20:47   ` Ard Biesheuvel
2024-10-25 22:02     ` Eric Biggers
2024-10-26  4:09       ` Eric Biggers
2024-10-27  8:14         ` Ard Biesheuvel
2024-11-02  9:45         ` Herbert Xu
2024-11-02  9:58           ` Ard Biesheuvel
2024-11-02 10:19             ` Herbert Xu
2024-11-02 10:46               ` Ard Biesheuvel
2024-11-02 11:05                 ` Ard Biesheuvel
2024-11-02 11:08                   ` Herbert Xu
2024-11-02 16:36                     ` Eric Biggers [this message]
2024-11-02 16:46                       ` Ard Biesheuvel
2024-11-02 17:21                       ` Milan Broz
2024-10-25 19:14 ` [PATCH v2 05/18] arm/crc32: expose CRC32 functions through lib Eric Biggers
2024-10-25 19:14 ` [PATCH v2 06/18] loongarch/crc32: " Eric Biggers
2024-11-03 13:36   ` WangYuli
2024-11-03 13:57     ` Eric Biggers
2024-11-04  2:34       ` WangYuli
2024-10-25 19:14 ` [PATCH v2 07/18] mips/crc32: " Eric Biggers
2024-10-25 19:14 ` [PATCH v2 08/18] powerpc/crc32: " Eric Biggers
2024-10-25 19:14 ` [PATCH v2 09/18] s390/crc32: " Eric Biggers
2024-10-25 19:14 ` [PATCH v2 10/18] sparc/crc32: " Eric Biggers
2024-10-25 19:14 ` [PATCH v2 11/18] x86/crc32: update prototype for crc_pcl() Eric Biggers
2024-10-25 19:14 ` [PATCH v2 12/18] x86/crc32: update prototype for crc32_pclmul_le_16() Eric Biggers
2024-10-25 19:14 ` [PATCH v2 13/18] x86/crc32: expose CRC32 functions through lib Eric Biggers
2024-10-25 19:14 ` [PATCH v2 14/18] lib/crc32: make crc32c() go directly to lib Eric Biggers
2024-10-25 19:14 ` [PATCH v2 15/18] ext4: switch to using the crc32c library Eric Biggers
2024-11-02 22:26   ` Theodore Ts'o
2024-10-25 19:14 ` [PATCH v2 16/18] jbd2: " Eric Biggers
2024-10-25 19:14 ` [PATCH v2 17/18] f2fs: switch to using the crc32 library Eric Biggers
2024-10-25 19:14 ` [PATCH v2 18/18] scsi: target: iscsi: switch to using the crc32c library Eric Biggers
2024-10-25 22:14   ` Ard Biesheuvel

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=20241102163605.GA28213@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=ardb@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=loongarch@lists.linux.dev \
    --cc=sparclinux@vger.kernel.org \
    --cc=x86@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;
as well as URLs for NNTP newsgroup(s).