s390/cpufeature: rework to allow more than only hwcap bits
authorHeiko Carstens <hca@linux.ibm.com>
Wed, 13 Jul 2022 12:56:42 +0000 (14:56 +0200)
committerAlexander Gordeev <agordeev@linux.ibm.com>
Tue, 19 Jul 2022 14:18:49 +0000 (16:18 +0200)
Rework cpufeature implementation to allow for various cpu feature
indications, which is not only limited to hwcap bits. This is achieved
by adding a sequential list of cpu feature numbers, where each of them
is mapped to an entry which indicates what this number is about.

Each entry contains a type member, which indicates what feature
name space to look into (e.g. hwcap, or cpu facility). If wanted this
allows also to automatically load modules only in e.g. z/VM
configurations.

Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Link: https://lore.kernel.org/r/20220713125644.16121-2-seiden@linux.ibm.com
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
17 files changed:
arch/s390/crypto/aes_s390.c
arch/s390/crypto/chacha-glue.c
arch/s390/crypto/crc32-vx.c
arch/s390/crypto/des_s390.c
arch/s390/crypto/ghash_s390.c
arch/s390/crypto/prng.c
arch/s390/crypto/sha1_s390.c
arch/s390/crypto/sha256_s390.c
arch/s390/crypto/sha3_256_s390.c
arch/s390/crypto/sha3_512_s390.c
arch/s390/crypto/sha512_s390.c
arch/s390/include/asm/cpufeature.h
arch/s390/kernel/Makefile
arch/s390/kernel/cpufeature.c [new file with mode: 0644]
arch/s390/kernel/processor.c
drivers/char/hw_random/s390-trng.c
drivers/s390/crypto/pkey_api.c

index 1023e9d43d443e8ad778a4932a4794f18d8e4bb1..526c3f40f6a2624dedf3cd45335af2d34c27f713 100644 (file)
@@ -1049,7 +1049,7 @@ out_err:
        return ret;
 }
 
-module_cpu_feature_match(MSA, aes_s390_init);
+module_cpu_feature_match(S390_CPU_FEATURE_MSA, aes_s390_init);
 module_exit(aes_s390_fini);
 
 MODULE_ALIAS_CRYPTO("aes-all");
index 2ec51f339cec44462550d3629de7f79ac95cc260..7752bd314558e50ce6c0142c2472cb60297799f7 100644 (file)
@@ -121,7 +121,7 @@ static void __exit chacha_mod_fini(void)
                crypto_unregister_skciphers(chacha_algs, ARRAY_SIZE(chacha_algs));
 }
 
-module_cpu_feature_match(VXRS, chacha_mod_init);
+module_cpu_feature_match(S390_CPU_FEATURE_VXRS, chacha_mod_init);
 module_exit(chacha_mod_fini);
 
 MODULE_DESCRIPTION("ChaCha20 stream cipher");
index fafecad2075269735c45a070518e88881e297504..017143e9cef715887647746800f9bae2fc5434cb 100644 (file)
@@ -298,7 +298,7 @@ static void __exit crc_vx_mod_exit(void)
        crypto_unregister_shashes(crc32_vx_algs, ARRAY_SIZE(crc32_vx_algs));
 }
 
-module_cpu_feature_match(VXRS, crc_vx_mod_init);
+module_cpu_feature_match(S390_CPU_FEATURE_VXRS, crc_vx_mod_init);
 module_exit(crc_vx_mod_exit);
 
 MODULE_AUTHOR("Hendrik Brueckner <brueckner@linux.vnet.ibm.com>");
index e013088b511550a03f52644c3fa8ff4f0df1473a..8e75b83a5ddc745fa53481032102672bd53073a2 100644 (file)
@@ -492,7 +492,7 @@ out_err:
        return ret;
 }
 
-module_cpu_feature_match(MSA, des_s390_init);
+module_cpu_feature_match(S390_CPU_FEATURE_MSA, des_s390_init);
 module_exit(des_s390_exit);
 
 MODULE_ALIAS_CRYPTO("des");
index 6b07a2f1ce8ae7f10be604c9829e2c1df155860d..0800a2a5799f5d4523e9777ef9aba15f06594836 100644 (file)
@@ -145,7 +145,7 @@ static void __exit ghash_mod_exit(void)
        crypto_unregister_shash(&ghash_alg);
 }
 
-module_cpu_feature_match(MSA, ghash_mod_init);
+module_cpu_feature_match(S390_CPU_FEATURE_MSA, ghash_mod_init);
 module_exit(ghash_mod_exit);
 
 MODULE_ALIAS_CRYPTO("ghash");
index ae382bafc77252d6676a39be80c5fc66cab2ba6f..a077087bc6ccfb1864fb31d612ea47715eec157b 100644 (file)
@@ -907,5 +907,5 @@ static void __exit prng_exit(void)
        }
 }
 
-module_cpu_feature_match(MSA, prng_init);
+module_cpu_feature_match(S390_CPU_FEATURE_MSA, prng_init);
 module_exit(prng_exit);
index a3fabf310a38fa62883635e20d95c72fa0f0ba3a..bc3a22704e09304bd2e227b4b0e0129d6be4a71c 100644 (file)
@@ -95,7 +95,7 @@ static void __exit sha1_s390_fini(void)
        crypto_unregister_shash(&alg);
 }
 
-module_cpu_feature_match(MSA, sha1_s390_init);
+module_cpu_feature_match(S390_CPU_FEATURE_MSA, sha1_s390_init);
 module_exit(sha1_s390_fini);
 
 MODULE_ALIAS_CRYPTO("sha1");
index 24983f17567695d97d9393243d9c5f20cba80dca..6f1ccdf93d3e5ee09c9f5210122e995bad05d6e3 100644 (file)
@@ -134,7 +134,7 @@ static void __exit sha256_s390_fini(void)
        crypto_unregister_shash(&sha256_alg);
 }
 
-module_cpu_feature_match(MSA, sha256_s390_init);
+module_cpu_feature_match(S390_CPU_FEATURE_MSA, sha256_s390_init);
 module_exit(sha256_s390_fini);
 
 MODULE_ALIAS_CRYPTO("sha256");
index 30ac49b635bf273f85160aded199b68962a529ba..e1350e033a32580a40fb85cc241b44b787252e76 100644 (file)
@@ -137,7 +137,7 @@ static void __exit sha3_256_s390_fini(void)
        crypto_unregister_shash(&sha3_256_alg);
 }
 
-module_cpu_feature_match(MSA, sha3_256_s390_init);
+module_cpu_feature_match(S390_CPU_FEATURE_MSA, sha3_256_s390_init);
 module_exit(sha3_256_s390_fini);
 
 MODULE_ALIAS_CRYPTO("sha3-256");
index e70d50f7620f7f197c3ac7a422ff6c32ff6d736e..06c142ed9bb1d32bcb256c418b6c53b7d398af59 100644 (file)
@@ -147,7 +147,7 @@ static void __exit fini(void)
        crypto_unregister_shash(&sha3_384_alg);
 }
 
-module_cpu_feature_match(MSA, init);
+module_cpu_feature_match(S390_CPU_FEATURE_MSA, init);
 module_exit(fini);
 
 MODULE_LICENSE("GPL");
index 43ce4956df73fa5fa44b3759ddf741e8d166125c..04f11c40776345722482d6c295d2ce623fde6c18 100644 (file)
@@ -142,7 +142,7 @@ static void __exit fini(void)
        crypto_unregister_shash(&sha384_alg);
 }
 
-module_cpu_feature_match(MSA, init);
+module_cpu_feature_match(S390_CPU_FEATURE_MSA, init);
 module_exit(fini);
 
 MODULE_LICENSE("GPL");
index 14cfd48d598e1ed73f68b2a8fbf1409f20f6bad1..771caf5281e576563e47ad2e1cc0b34cb52bf568 100644 (file)
@@ -2,28 +2,20 @@
 /*
  * Module interface for CPU features
  *
- * Copyright IBM Corp. 2015
+ * Copyright IBM Corp. 2015, 2022
  * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
  */
 
 #ifndef __ASM_S390_CPUFEATURE_H
 #define __ASM_S390_CPUFEATURE_H
 
-#include <asm/elf.h>
+enum {
+       S390_CPU_FEATURE_MSA,
+       S390_CPU_FEATURE_VXRS,
+       MAX_CPU_FEATURES
+};
 
-/* Hardware features on Linux on z Systems are indicated by facility bits that
- * are mapped to the so-called machine flags.  Particular machine flags are
- * then used to define ELF hardware capabilities; most notably hardware flags
- * that are essential for user space / glibc.
- *
- * Restrict the set of exposed CPU features to ELF hardware capabilities for
- * now.  Additional machine flags can be indicated by values larger than
- * MAX_ELF_HWCAP_FEATURES.
- */
-#define MAX_ELF_HWCAP_FEATURES (8 * sizeof(elf_hwcap))
-#define MAX_CPU_FEATURES       MAX_ELF_HWCAP_FEATURES
-
-#define cpu_feature(feat)      ilog2(HWCAP_ ## feat)
+#define cpu_feature(feature)   (feature)
 
 int cpu_have_feature(unsigned int nr);
 
index 27d6b3c7aa06ef843d2b2718263f66bf36decca9..3cbfa9fddd9a924ffcfe875e3ae14ec0a31484eb 100644 (file)
@@ -35,7 +35,7 @@ CFLAGS_unwind_bc.o    += -fno-optimize-sibling-calls
 
 obj-y  := traps.o time.o process.o earlypgm.o early.o setup.o idle.o vtime.o
 obj-y  += processor.o syscall.o ptrace.o signal.o cpcmd.o ebcdic.o nmi.o
-obj-y  += debug.o irq.o ipl.o dis.o diag.o vdso.o
+obj-y  += debug.o irq.o ipl.o dis.o diag.o vdso.o cpufeature.o
 obj-y  += sysinfo.o lgr.o os_info.o machine_kexec.o
 obj-y  += runtime_instr.o cache.o fpu.o dumpstack.o guarded_storage.o sthyi.o
 obj-y  += entry.o reipl.o relocate_kernel.o kdebugfs.o alternative.o
diff --git a/arch/s390/kernel/cpufeature.c b/arch/s390/kernel/cpufeature.c
new file mode 100644 (file)
index 0000000..89c4183
--- /dev/null
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright IBM Corp. 2022
+ */
+
+#include <linux/cpufeature.h>
+#include <linux/bug.h>
+#include <asm/elf.h>
+
+enum {
+       TYPE_HWCAP,
+};
+
+struct s390_cpu_feature {
+       unsigned int type       : 4;
+       unsigned int num        : 28;
+};
+
+static struct s390_cpu_feature s390_cpu_features[MAX_CPU_FEATURES] = {
+       [S390_CPU_FEATURE_MSA]  = {.type = TYPE_HWCAP, .num = HWCAP_NR_MSA},
+       [S390_CPU_FEATURE_VXRS] = {.type = TYPE_HWCAP, .num = HWCAP_NR_VXRS},
+};
+
+/*
+ * cpu_have_feature - Test CPU features on module initialization
+ */
+int cpu_have_feature(unsigned int num)
+{
+       struct s390_cpu_feature *feature;
+
+       if (WARN_ON_ONCE(num >= MAX_CPU_FEATURES))
+               return 0;
+       feature = &s390_cpu_features[num];
+       switch (feature->type) {
+       case TYPE_HWCAP:
+               return !!(elf_hwcap & BIT(feature->num));
+       default:
+               WARN_ON_ONCE(1);
+               return 0;
+       }
+}
+EXPORT_SYMBOL(cpu_have_feature);
index aa0e0e7fc773e31901eef61e4f7dfc1f763b1f29..a194611ba88c7ba470d4c965b2b623aef2e6bed5 100644 (file)
@@ -8,7 +8,6 @@
 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 
 #include <linux/stop_machine.h>
-#include <linux/cpufeature.h>
 #include <linux/bitops.h>
 #include <linux/kernel.h>
 #include <linux/random.h>
@@ -96,15 +95,6 @@ void cpu_init(void)
        enter_lazy_tlb(&init_mm, current);
 }
 
-/*
- * cpu_have_feature - Test CPU features on module initialization
- */
-int cpu_have_feature(unsigned int num)
-{
-       return elf_hwcap & (1UL << num);
-}
-EXPORT_SYMBOL(cpu_have_feature);
-
 static void show_facilities(struct seq_file *m)
 {
        unsigned int bit;
index 2beaa35c0d742ba57e771bb7ab8f8a86498c2973..12fbac0ed8cad476844e959279d9d2ba6645e484 100644 (file)
@@ -261,5 +261,5 @@ static void __exit trng_exit(void)
        trng_debug_exit();
 }
 
-module_cpu_feature_match(MSA, trng_init);
+module_cpu_feature_match(S390_CPU_FEATURE_MSA, trng_init);
 module_exit(trng_exit);
index 7329caa7d46791c2c301468dc55a48fc72164c60..5a05d1cdfec20adf5bc43a6fad6fa2f219fc9805 100644 (file)
@@ -2115,5 +2115,5 @@ static void __exit pkey_exit(void)
        pkey_debug_exit();
 }
 
-module_cpu_feature_match(MSA, pkey_init);
+module_cpu_feature_match(S390_CPU_FEATURE_MSA, pkey_init);
 module_exit(pkey_exit);