Thread (41 messages) 41 messages, 6 authors, 2024-11-05

Re: [PATCH v2 03/18] lib/crc32: expose whether the lib is really optimized at runtime

From: Eric Biggers <ebiggers@kernel.org>
Date: 2024-10-25 21:32:44
Also in: linux-arch, linux-arm-kernel, linux-crypto, linux-ext4, linux-f2fs-devel, linux-mips, linux-riscv, linux-s390, linux-scsi, lkml, loongarch, sparclinux

On Fri, Oct 25, 2024 at 10:32:14PM +0200, Ard Biesheuvel wrote:
On Fri, 25 Oct 2024 at 21:15, Eric Biggers [off-list ref] wrote:
quoted
From: Eric Biggers <redacted>

Make the CRC32 library export some flags that indicate which CRC32
functions are actually executing optimized code at runtime.  Set these
correctly from the architectures that implement the CRC32 functions.

This will be used to determine whether the crc32[c]-$arch shash
algorithms should be registered in the crypto API.  btrfs could also
start using these flags instead of the hack that it currently uses where
it parses the crypto_shash_driver_name.

Signed-off-by: Eric Biggers <redacted>
---
 arch/arm64/lib/crc32-glue.c  | 15 +++++++++++++++
 arch/riscv/lib/crc32-riscv.c | 15 +++++++++++++++
 include/linux/crc32.h        | 15 +++++++++++++++
 lib/crc32.c                  |  5 +++++
 4 files changed, 50 insertions(+)
...
quoted
diff --git a/include/linux/crc32.h b/include/linux/crc32.h
index 58c632533b08..bf26d454b60d 100644
--- a/include/linux/crc32.h
+++ b/include/linux/crc32.h
@@ -35,10 +35,25 @@ static inline u32 __pure __crc32c_le(u32 crc, const u8 *p, size_t len)
        if (IS_ENABLED(CONFIG_CRC32_ARCH))
                return crc32c_le_arch(crc, p, len);
        return crc32c_le_base(crc, p, len);
 }

+/*
+ * crc32_optimizations contains flags that indicate which CRC32 library
+ * functions are using architecture-specific optimizations.  Unlike
+ * IS_ENABLED(CONFIG_CRC32_ARCH) it takes into account the different CRC32
+ * variants and also whether any needed CPU features are available at runtime.
+ */
+#define CRC32_LE_OPTIMIZATION  BIT(0) /* crc32_le() is optimized */
+#define CRC32_BE_OPTIMIZATION  BIT(1) /* crc32_be() is optimized */
+#define CRC32C_OPTIMIZATION    BIT(2) /* __crc32c_le() is optimized */
+#if IS_ENABLED(CONFIG_CRC32_ARCH)
+extern u32 crc32_optimizations;
+#else
+#define crc32_optimizations 0
+#endif
+
Wouldn't it be cleaner to add a new library function for this, instead
of using a global variable?
The architecture crc32 modules need to be able to write to this.  There could be
a setter function and a getter function, but just using a variable is simpler.

- Eric
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help