ARM: add module autoloading support for crypto modules
Subsystems (2)
cover ARM: add module autoloading support for crypto modules
This series wires up the crypto modules that use the ARM 32-bit versions of the ARMv8 Crypto Extensions to udev autoloading, by exposing the HWCAP2 feature bits via the CPU modalias. This is very similar to the arm64 implementation, with the notable exception that ARM has its CPU feature definitions split across HWCAP and HWCAP2.
Given that the crypto feature bits are all exposed via HWCAP2, and considering that there are currently no features exposed via HWCAP that are relevant to udev module autoloading, exposing HWCAP2 only should be sufficient, at least for now.
Note to Herbert: patches #2 - #5 all depend on #1, which requires an ack from Russell, so please don't pull anything until #1 has been acked and/or merged.
Ard Biesheuvel (5):
ARM: wire up HWCAP2 feature bits to the CPU modalias
crypto: arm/aes-ce - enable module autoloading based on CPU feature
bits
crypto: arm/ghash-ce - enable module autoloading based on CPU feature
bits
crypto: arm/sha1-ce - enable module autoloading based on CPU feature
bits
crypto: arm/sha2-ce - enable module autoloading based on CPU feature
bits
arch/arm/Kconfig | 1 + arch/arm/crypto/aes-ce-glue.c | 5 ++- arch/arm/crypto/ghash-ce-glue.c | 6 ++-- arch/arm/crypto/sha1-ce-glue.c | 5 ++- arch/arm/crypto/sha2-ce-glue.c | 5 ++- arch/arm/include/asm/cpufeature.h | 32 ++++++++++++++++++++ 6 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 arch/arm/include/asm/cpufeature.h
Signature · 1 line
2.7.4
PATCH 1/5 ARM: wire up HWCAP2 feature bits to the CPU modalias
Wire up the generic support for exposing CPU feature bits via the modalias in /sys/device/system/cpu. This allows udev to automatically load modules for things like crypto algorithms that are implemented using optional instructions.
--- arch/arm/Kconfig | 1 + arch/arm/include/asm/cpufeature.h | 32 ++++++++++++++++++++ 2 files changed, 33 insertions(+)
arch/arm/Kconfig +1 -0
@@ -21,6 +21,7 @@ config ARM select GENERIC_ALLOCATOR select GENERIC_ATOMIC64 if (CPU_V7M || CPU_V6 || !CPU_32v6K || !AEABI) select GENERIC_CLOCKEVENTS_BROADCAST if SMP + select GENERIC_CPU_AUTOPROBE select GENERIC_EARLY_IOREMAP select GENERIC_IDLE_POLL_SETUP select GENERIC_IRQ_PROBE
arch/arm/include/asm/cpufeature.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright (C) 2016 Linaro Ltd. <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __ASM_CPUFEATURE_H +#define __ASM_CPUFEATURE_H + +#include <asm/hwcap.h> + +/* +* Due to the fact that ELF_HWCAP is a 32-bit type on ARM, and given the number +* of optional CPU features it defines, ARM's CPU capability bits have been +* divided across separate elf_hwcap and elf_hwcap2 variables, each of which +* covers a subset of the available CPU features. +* +* Currently, only a few of those are suitable for automatic module loading +* (which is the primary use case of this facility) and those happen to be all +* covered by HWCAP2. So let's only expose those via the CPU modalias for now. +*/ +#define MAX_CPU_FEATURES (8 * sizeof(elf_hwcap2)) +#define cpu_feature (x) ilog2(HWCAP2_ ## x) + +static inline bool cpu_have_feature (unsigned int num) +{ +return elf_hwcap2 & (1UL << num); +} + +#endif
Signature · 1 line
2.7.4
PATCH 1/5 ARM: wire up HWCAP2 feature bits to the CPU modalias
Quoted 11 lines · Ard Biesheuvel
Wire up the generic support for exposing CPU feature bits via the modalias in
/sys/device/system/cpu. This allows udev to automatically load modules for things like crypto algorithms that are implemented using optional instructions.Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm/Kconfig | 1 + arch/arm/include/asm/cpufeature.h | 32 ++++++++++++++++++++ 2 files changed, 33 insertions(+)
Russell,
do you have any concerns regarding this patch? If not, I will drop it into the patch system.
Herbert,
I will resend the followup patches in this series to linux-crypto@ once this prerequisite is in place
Thanks,
Ard.
Quoted 53 lines
arch/arm/Kconfig +1
-0@@ -21,6 +21,7 @@ config ARM select GENERIC_ALLOCATOR select GENERIC_ATOMIC64 if (CPU_V7M || CPU_V6 || !CPU_32v6K || !AEABI) select GENERIC_CLOCKEVENTS_BROADCAST if SMP + select GENERIC_CPU_AUTOPROBE select GENERIC_EARLY_IOREMAP select GENERIC_IDLE_POLL_SETUP select GENERIC_IRQ_PROBEarch/arm/include/asm/cpufeature.h new file +32
-1@@ -0,0 +1,32 @@ +/* +* Copyright (C) 2016 Linaro Ltd. <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __ASM_CPUFEATURE_H +#define __ASM_CPUFEATURE_H + +#include <asm/hwcap.h> + +/* +* Due to the fact that ELF_HWCAP is a 32-bit type on ARM, and given the number +* of optional CPU features it defines, ARM's CPU capability bits have been +* divided across separate elf_hwcap and elf_hwcap2 variables, each of which +* covers a subset of the available CPU features. +* +* Currently, only a few of those are suitable for automatic module loading +* (which is the primary use case of this facility) and those happen to be all +* covered by HWCAP2. So let's only expose those via the CPU modalias for now. +*/ +#define MAX_CPU_FEATURES (8 * sizeof(elf_hwcap2)) +#define cpu_feature (x) ilog2(HWCAP2_ ## x) + +static inline bool cpu_have_feature (unsigned int num) +{ +return elf_hwcap2 & (1UL << num); +} + +#endif --2.7.4
Russell King - ARM Linux
maintainerPATCH 1/5 ARM: wire up HWCAP2 feature bits to the CPU modalias
Quoted 13 lines · Ard Biesheuvel
Quoted 11 lines · Ard Biesheuvel
Wire up the generic support for exposing CPU feature bits via the modalias in
/sys/device/system/cpu. This allows udev to automatically load modules for things like crypto algorithms that are implemented using optional instructions.Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm/Kconfig | 1 + arch/arm/include/asm/cpufeature.h | 32 ++++++++++++++++++++ 2 files changed, 33 insertions(+)
Quoted 4 lines
Russell,
do you have any concerns regarding this patch? If not, I will drop it into the patch system.
It's still something I need to look at... I've been offline last week, and sort-of offline the previous week, so I'm catching up.
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
PATCH 1/5 ARM: wire up HWCAP2 feature bits to the CPU modalias
Quoted 14 lines · Russell King - ARM Linux
Quoted 13 lines · Ard Biesheuvel
Quoted 11 lines · Ard Biesheuvel
Wire up the generic support for exposing CPU feature bits via the modalias in
/sys/device/system/cpu. This allows udev to automatically load modules for things like crypto algorithms that are implemented using optional instructions.Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm/Kconfig | 1 + arch/arm/include/asm/cpufeature.h | 32 ++++++++++++++++++++ 2 files changed, 33 insertions(+)
Quoted 8 lines
Quoted 4 lines
Russell,
do you have any concerns regarding this patch? If not, I will drop it into the patch system.
It's still something I need to look at... I've been offline last week, and sort-of offline the previous week, so I'm catching up.
Hi Russell,
Any thoughts yet?
Thanks,
Ard.
Russell King - ARM Linux
maintainerPATCH 1/5 ARM: wire up HWCAP2 feature bits to the CPU modalias
Quoted 21 lines · Ard Biesheuvel
Quoted 19 lines · Russell King - ARM Linux
Quoted 17 lines · Ard Biesheuvel
Quoted 11 lines · Ard Biesheuvel
Wire up the generic support for exposing CPU feature bits via the modalias in
/sys/device/system/cpu. This allows udev to automatically load modules for things like crypto algorithms that are implemented using optional instructions.Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm/Kconfig | 1 + arch/arm/include/asm/cpufeature.h | 32 ++++++++++++++++++++ 2 files changed, 33 insertions(+)Russell,
do you have any concerns regarding this patch? If not, I will drop it into the patch system.
Quoted 7 lines
Quoted 3 lines
It's still something I need to look at... I've been offline last week, and sort-of offline the previous week, so I'm catching up.
Hi Russell,
Any thoughts yet?
None, and the patch is well buried now that it'll take me a while to find... back in mid-October? Yea, I'll have to drop everything and go digging through my mailboxes to find it... and I'm just catching up (again) after a week and a bit's time offline - yep, it's wonderful timing. Sorry, no time to look at it right now, you're not the only one wanting my attention at the moment.
Please try again in about a week's time - don't leave it a few months, and please include the patch.
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
PATCH 1/5 ARM: wire up HWCAP2 feature bits to the CPU modalias
Quoted 28 lines · Russell King - ARM Linux
Quoted 27 lines · Ard Biesheuvel
Quoted 14 lines · Russell King - ARM Linux
Quoted 13 lines · Ard Biesheuvel
Quoted 11 lines · Ard Biesheuvel
Wire up the generic support for exposing CPU feature bits via the modalias in
/sys/device/system/cpu. This allows udev to automatically load modules for things like crypto algorithms that are implemented using optional instructions.Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm/Kconfig | 1 + arch/arm/include/asm/cpufeature.h | 32 ++++++++++++++++++++ 2 files changed, 33 insertions(+)Quoted 8 lines
Quoted 4 lines
Russell,
do you have any concerns regarding this patch? If not, I will drop it into the patch system.
It's still something I need to look at... I've been offline last week, and sort-of offline the previous week, so I'm catching up.
Hi Russell,
Quoted 9 lines
Quoted 1 line
Any thoughts yet?
None, and the patch is well buried now that it'll take me a while to find... back in mid-October? Yea, I'll have to drop everything and go digging through my mailboxes to find it... and I'm just catching up (again) after a week and a bit's time offline - yep, it's wonderful timing. Sorry, no time to look at it right now, you're not the only one wanting my attention at the moment.
No worries. It is not exactly urgent, but it is a useful enhancement nonetheless.
Quoted 3 lines
Please try again in about a week's time - don't leave it a few months, and please include the patch.
OK
PATCH 2/5 crypto: arm/aes-ce - enable module autoloading based on CPU feature bits
In reply to Ard BiesheuvelMake the module autoloadable by tying it to the CPU feature bit that describes whether the optional instructions it relies on are implemented by the current CPU.
--- arch/arm/crypto/aes-ce-glue.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm/crypto/aes-ce-glue.c +2 -3
@@ -14,6 +14,7 @@#include <crypto/aes.h> #include <crypto/ablk_helper.h> #include <crypto/algapi.h> +#include <linux/cpufeature.h> #include <linux/module.h> #include <crypto/xts.h>
@@ -515,8 +516,6 @@ static struct crypto_alg aes_algs[] = { {static int __init aes_init (void ) { -if (!(elf_hwcap2 &HWCAP2_AES )) -return -ENODEV ;return crypto_register_algs (aes_algs,ARRAY_SIZE (aes_algs)); }
@@ -525,5 +524,5 @@ static void __exit aes_exit(void)crypto_unregister_algs (aes_algs,ARRAY_SIZE (aes_algs)); } -module_init (aes_init); +module_cpu_feature_match (AES , aes_init);module_exit (aes_exit);
Signature · 1 line
2.7.4
PATCH 3/5 crypto: arm/ghash-ce - enable module autoloading based on CPU feature bits
In reply to Ard BiesheuvelMake the module autoloadable by tying it to the CPU feature bit that describes whether the optional instructions it relies on are implemented by the current CPU.
--- arch/arm/crypto/ghash-ce-glue.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
arch/arm/crypto/ghash-ce-glue.c +2 -4
@@ -15,6 +15,7 @@#include <crypto/cryptd.h> #include <crypto/internal/hash.h> #include <crypto/gf128mul.h> +#include <linux/cpufeature.h> #include <linux/crypto.h> #include <linux/module.h>
@@ -311,9 +312,6 @@ static int __init ghash_ce_mod_init(void) {int err; -if (!(elf_hwcap2 &HWCAP2_PMULL )) -return -ENODEV ; - err =crypto_register_shash (&ghash_alg);if (err)return err;
@@ -334,5 +332,5 @@ static void __exit ghash_ce_mod_exit(void)crypto_unregister_shash (&ghash_alg); } -module_init (ghash_ce_mod_init); +module_cpu_feature_match (PMULL , ghash_ce_mod_init);module_exit (ghash_ce_mod_exit);
Signature · 1 line
2.7.4
PATCH 4/5 crypto: arm/sha1-ce - enable module autoloading based on CPU feature bits
In reply to Ard BiesheuvelMake the module autoloadable by tying it to the CPU feature bit that describes whether the optional instructions it relies on are implemented by the current CPU.
--- arch/arm/crypto/sha1-ce-glue.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm/crypto/sha1-ce-glue.c +2 -3
@@ -11,6 +11,7 @@#include <crypto/internal/hash.h> #include <crypto/sha.h> #include <crypto/sha1_base.h> +#include <linux/cpufeature.h> #include <linux/crypto.h> #include <linux/module.h>
@@ -82,8 +83,6 @@ static struct shash_alg alg = {static int __init sha1_ce_mod_init (void ) { -if (!(elf_hwcap2 &HWCAP2_SHA1 )) -return -ENODEV ;return crypto_register_shash (&alg); }
@@ -92,5 +91,5 @@ static void __exit sha1_ce_mod_fini(void)crypto_unregister_shash (&alg); } -module_init (sha1_ce_mod_init); +module_cpu_feature_match (SHA1 , sha1_ce_mod_init);module_exit (sha1_ce_mod_fini);
Signature · 1 line
2.7.4
PATCH 5/5 crypto: arm/sha2-ce - enable module autoloading based on CPU feature bits
In reply to Ard BiesheuvelMake the module autoloadable by tying it to the CPU feature bit that describes whether the optional instructions it relies on are implemented by the current CPU.
--- arch/arm/crypto/sha2-ce-glue.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm/crypto/sha2-ce-glue.c +2 -3
@@ -11,6 +11,7 @@#include <crypto/internal/hash.h> #include <crypto/sha.h> #include <crypto/sha256_base.h> +#include <linux/cpufeature.h> #include <linux/crypto.h> #include <linux/module.h>
@@ -100,8 +101,6 @@ static struct shash_alg algs[] = { {static int __init sha2_ce_mod_init (void ) { -if (!(elf_hwcap2 &HWCAP2_SHA2 )) -return -ENODEV ;return crypto_register_shashes (algs,ARRAY_SIZE (algs)); }
@@ -110,5 +109,5 @@ static void __exit sha2_ce_mod_fini(void)crypto_unregister_shashes (algs,ARRAY_SIZE (algs)); } -module_init (sha2_ce_mod_init); +module_cpu_feature_match (SHA2 , sha2_ce_mod_init);module_exit (sha2_ce_mod_fini);
Signature · 1 line
2.7.4