From: Ard Biesheuvel <ardb@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: herbert@gondor.apana.org.au, Ard Biesheuvel <ardb@kernel.org>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Eric Biggers <ebiggers@google.com>,
Peter Zijlstra <peterz@infradead.org>
Subject: [PATCH 2/7] crypto: lib/crc-t10dif - add static call support for optimized versions
Date: Mon, 11 Jan 2021 17:52:32 +0100 [thread overview]
Message-ID: <20210111165237.18178-3-ardb@kernel.org> (raw)
In-Reply-To: <20210111165237.18178-1-ardb@kernel.org>
Wire up the new static call facility to the CRC-T10DIF library code, so
that optimized implementations can be swapped in easily, without having
to rely on the complexity of the crypto API shash infrastructure.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
include/linux/crc-t10dif.h | 21 ++++++++++++--
lib/crc-t10dif.c | 30 +++++++++++++++-----
2 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/include/linux/crc-t10dif.h b/include/linux/crc-t10dif.h
index 6bb0c0bf357b..ad8b0a358680 100644
--- a/include/linux/crc-t10dif.h
+++ b/include/linux/crc-t10dif.h
@@ -3,6 +3,7 @@
#define _LINUX_CRC_T10DIF_H
#include <linux/types.h>
+#include <linux/static_call.h>
#define CRC_T10DIF_DIGEST_SIZE 2
#define CRC_T10DIF_BLOCK_SIZE 1
@@ -10,7 +11,23 @@
extern __u16 crc_t10dif_generic(__u16 crc, const unsigned char *buffer,
size_t len);
-extern __u16 crc_t10dif(unsigned char const *, size_t);
-extern __u16 crc_t10dif_update(__u16 crc, unsigned char const *, size_t);
+
+DECLARE_STATIC_CALL(crc_t10dif_arch, crc_t10dif_generic);
+
+static inline __u16 crc_t10dif_update(__u16 crc, unsigned char const *buffer,
+ size_t len)
+{
+ return static_call(crc_t10dif_arch)(crc, buffer, len);
+}
+
+static inline __u16 crc_t10dif(unsigned char const *buffer, size_t len)
+{
+ return crc_t10dif_update(0, buffer, len);
+}
+
+int crc_t10dif_register(__u16 (*)(__u16, const unsigned char *, size_t),
+ const char *name);
+
+int crc_t10dif_unregister(void);
#endif
diff --git a/lib/crc-t10dif.c b/lib/crc-t10dif.c
index cbb739f0a0d7..b657cdfb118a 100644
--- a/lib/crc-t10dif.c
+++ b/lib/crc-t10dif.c
@@ -18,6 +18,11 @@
#include <linux/static_key.h>
#include <linux/notifier.h>
+DEFINE_STATIC_CALL(crc_t10dif_arch, crc_t10dif_generic);
+EXPORT_STATIC_CALL(crc_t10dif_arch);
+
+static char const *crc_t10dif_arch_name;
+
/* Table generated using the following polynomium:
* x^16 + x^15 + x^11 + x^9 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
* gt: 0x8bb7
@@ -68,21 +73,32 @@ __u16 crc_t10dif_generic(__u16 crc, const unsigned char *buffer, size_t len)
}
EXPORT_SYMBOL(crc_t10dif_generic);
-__u16 crc_t10dif_update(__u16 crc, const unsigned char *buffer, size_t len)
+int crc_t10dif_register(__u16 (*func)(__u16, const unsigned char *, size_t),
+ const char *name)
{
- return crc_t10dif_generic(crc, buffer, len);
+ if (!name || cmpxchg(&crc_t10dif_arch_name, NULL, name) != NULL)
+ return -EBUSY;
+
+ static_call_update(crc_t10dif_arch, func);
+ return 0;
}
-EXPORT_SYMBOL(crc_t10dif_update);
+EXPORT_SYMBOL_NS(crc_t10dif_register, CRYPTO_INTERNAL);
-__u16 crc_t10dif(const unsigned char *buffer, size_t len)
+int crc_t10dif_unregister(void)
{
- return crc_t10dif_update(0, buffer, len);
+ // revert to generic implementation
+ static_call_update(crc_t10dif_arch, crc_t10dif_generic);
+ crc_t10dif_arch_name = NULL;
+
+ // wait for all potential callers of the unregistered routine to finish
+ synchronize_rcu_tasks();
+ return 0;
}
-EXPORT_SYMBOL(crc_t10dif);
+EXPORT_SYMBOL_NS(crc_t10dif_unregister, CRYPTO_INTERNAL);
static int crc_t10dif_transform_show(char *buffer, const struct kernel_param *kp)
{
- return sprintf(buffer, "fallback\n");
+ return sprintf(buffer, "%s\n", crc_t10dif_arch_name ?: "fallback");
}
module_param_call(transform, NULL, crc_t10dif_transform_show, NULL, 0444);
--
2.17.1
next prev parent reply other threads:[~2021-01-11 16:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-11 16:52 [PATCH 0/7] crypto: switch to static calls for CRC-T10DIF Ard Biesheuvel
2021-01-11 16:52 ` [PATCH 1/7] crypto: crc-t10dif - turn library wrapper for shash into generic library Ard Biesheuvel
2021-01-11 16:52 ` Ard Biesheuvel [this message]
2021-01-11 16:52 ` [PATCH 3/7] crypto: generic/crc-t10dif - expose both arch and generic shashes Ard Biesheuvel
2021-01-11 16:52 ` [PATCH 4/7] crypto: x86/crc-t10dif - convert to static call library API Ard Biesheuvel
2021-01-12 0:01 ` kernel test robot
2021-01-11 16:52 ` [PATCH 5/7] crypto: arm/crc-t10dif " Ard Biesheuvel
2021-01-11 16:52 ` [PATCH 6/7] crypto: arm64/crc-t10dif - convert to static call API Ard Biesheuvel
2021-01-11 16:52 ` [PATCH 7/7] crypto: powerpc/crc-t10dif " Ard Biesheuvel
2021-01-11 17:27 ` [PATCH 0/7] crypto: switch to static calls for CRC-T10DIF Ard Biesheuvel
2021-01-11 18:36 ` Ard Biesheuvel
2021-01-11 20:56 ` Peter Zijlstra
2021-01-11 21:01 ` Ard Biesheuvel
2021-01-11 21:05 ` Eric Biggers
2021-01-11 21:31 ` Ard Biesheuvel
2021-01-28 8:19 ` 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=20210111165237.18178-3-ardb@kernel.org \
--to=ardb@kernel.org \
--cc=ebiggers@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=peterz@infradead.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).