Skip to contentSkip to conversation

crypto: x86/sha1 - autoload if SHA-NI detected

PATCH In review Eric Biggers 2 participants 2 messages Oct 29, 2023 – Oct 31, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: x86/sha1 - autoload if SHA-NI detected

From: Eric Biggers <[email protected]>

The x86 SHA-1 module contains four implementations: SSSE3, AVX, AVX2, and SHA-NI. Commit 1c43c0f1f84a ("crypto: x86/sha - load modules based on CPU features") made the module be autoloaded when SSSE3, AVX, or AVX2 is detected. The omission of SHA-NI appears to be an oversight, perhaps because of the outdated file-level comment. This patch fixes this, though in practice this makes no difference because SSSE3 is a subset of the other three features anyway. Indeed, sha1_ni_transform() executes SSSE3 instructions such as pshufb.

Cc Roxana Nicolescu <[email protected]>
---
 arch/x86/crypto/sha1_ssse3_glue.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/crypto/sha1_ssse3_glue.c +3 -2
index 959afa705e95..d88991f2cb3a 100644
@@ -1,16 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Cryptographic API.
  *
- * Glue code for the SHA1 Secure Hash Algorithm assembler implementation using
- * Supplemental SSE3 instructions.
+ * Glue code for the SHA1 Secure Hash Algorithm assembler implementations
+ * using SSSE3, AVX, AVX2, and SHA-NI instructions.
  *
  * This file is based on sha1_generic.c
  *
  * Copyright (c) Alan Smithee.
  * Copyright (c) Andrew McDonald <[email protected]>
  * Copyright (c) Jean-Francois Dive <[email protected]>
  * Copyright (c) Mathias Krause <[email protected]>
  * Copyright (c) Chandramouli Narayanan <[email protected]>
  */
 
@@ -21,20 +21,21 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/mm.h>
 #include <linux/types.h>
 #include <crypto/sha1.h>
 #include <crypto/sha1_base.h>
 #include <asm/cpu_device_id.h>
 #include <asm/simd.h>
 
 static const struct x86_cpu_id module_cpu_ids[] = {
+	X86_MATCH_FEATURE(X86_FEATURE_SHA_NI, NULL),
 	X86_MATCH_FEATURE(X86_FEATURE_AVX2, NULL),
 	X86_MATCH_FEATURE(X86_FEATURE_AVX, NULL),
 	X86_MATCH_FEATURE(X86_FEATURE_SSSE3, NULL),
 	{}
 };
 MODULE_DEVICE_TABLE(x86cpu, module_cpu_ids);
 
 static int sha1_update(struct shash_desc *desc, const u8 *data,
 			     unsigned int len, sha1_block_fn *sha1_xform)
 {

base-commit: f2b88bab69c86d4dab2bfd25a0e741d7df411f7a

Signature · 1 line
2.42.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Eric Biggers

From: Eric Biggers <[email protected]>

The x86 SHA-1 module contains four implementations: SSSE3, AVX, AVX2, and SHA-NI. Commit 1c43c0f1f84a ("crypto: x86/sha - load modules based on CPU features") made the module be autoloaded when SSSE3, AVX, or AVX2 is detected. The omission of SHA-NI appears to be an oversight, perhaps because of the outdated file-level comment. This patch fixes this, though in practice this makes no difference because SSSE3 is a subset of the other three features anyway. Indeed, sha1_ni_transform() executes SSSE3 instructions such as pshufb.

Quoted 2 lines
Cc Roxana Nicolescu <[email protected]>

Indeed, it was an oversight.

Quoted 51 lines
---
  arch/x86/crypto/sha1_ssse3_glue.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/crypto/sha1_ssse3_glue.c +3 -2
index 959afa705e95..d88991f2cb3a 100644
@@ -1,16 +1,16 @@
  // SPDX-License-Identifier: GPL-2.0-or-later
  /*
   * Cryptographic API.
   *
- * Glue code for the SHA1 Secure Hash Algorithm assembler implementation using
- * Supplemental SSE3 instructions.
+ * Glue code for the SHA1 Secure Hash Algorithm assembler implementations
+ * using SSSE3, AVX, AVX2, and SHA-NI instructions.
   *
   * This file is based on sha1_generic.c
   *
   * Copyright (c) Alan Smithee.
   * Copyright (c) Andrew McDonald <[email protected]>
   * Copyright (c) Jean-Francois Dive <[email protected]>
   * Copyright (c) Mathias Krause <[email protected]>
   * Copyright (c) Chandramouli Narayanan <[email protected]>
   */
 
@@ -21,20 +21,21 @@
  #include <linux/init.h>
  #include <linux/module.h>
  #include <linux/mm.h>
  #include <linux/types.h>
  #include <crypto/sha1.h>
  #include <crypto/sha1_base.h>
  #include <asm/cpu_device_id.h>
  #include <asm/simd.h>
 
  static const struct x86_cpu_id module_cpu_ids[] = {
+	X86_MATCH_FEATURE(X86_FEATURE_SHA_NI, NULL),
  	X86_MATCH_FEATURE(X86_FEATURE_AVX2, NULL),
  	X86_MATCH_FEATURE(X86_FEATURE_AVX, NULL),
  	X86_MATCH_FEATURE(X86_FEATURE_SSSE3, NULL),
  	{}
  };
  MODULE_DEVICE_TABLE(x86cpu, module_cpu_ids);
 
  static int sha1_update(struct shash_desc *desc, const u8 *data,
  			     unsigned int len, sha1_block_fn *sha1_xform)
  {

base-commit: f2b88bab69c86d4dab2bfd25a0e741d7df411f7a