Skip to contentSkip to conversation

HiSilicon TRNG fix and simplification

PATCH In review Eric Biggers 3 participants 5 messages May 30 – Jun 11

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

cover HiSilicon TRNG fix and simplification

This series fixes and greatly simplifies the HiSilicon TRNG driver by removing the gratuitous crypto_rng interface, leaving just hwrng which is the one that actually matters.

Note that this mirrors similar changes in other drivers such as qcom-rng
(https://lore.kernel.org/r/[email protected])

Eric Biggers (2):
crypto: hisi-trng - Remove crypto_rng interface
hwrng: hisi-trng - Move hisi-trng into drivers/char/hw_random/

 MAINTAINERS                            |   2 +-
 arch/arm64/configs/defconfig           |   2 +-
 drivers/char/hw_random/Kconfig         |  10 +
 drivers/char/hw_random/Makefile        |   1 +
 drivers/char/hw_random/hisi-trng-v2.c  |  98 +++++++
 drivers/crypto/hisilicon/Kconfig       |   8 -
 drivers/crypto/hisilicon/Makefile      |   1 -
 drivers/crypto/hisilicon/trng/Makefile |   2 -
 drivers/crypto/hisilicon/trng/trng.c   | 390 -------------------------
 9 files changed, 111 insertions(+), 403 deletions(-)
 create mode 100644 drivers/char/hw_random/hisi-trng-v2.c
 delete mode 100644 drivers/crypto/hisilicon/trng/Makefile
 delete mode 100644 drivers/crypto/hisilicon/trng/trng.c

base-commit: 5624ea54f3ba5c83d2e5503411a31a8be0278c1e
prerequisite-patch-id: 07e982b663ac3f8312ca524f6b91b5b38661df5e
prerequisite-patch-id: 72064361a8f36e015ab0b7e1fa4d364b40d90506
prerequisite-patch-id: 8978b8e0db7f47935e5f6f0aff14a97f55d3073c
prerequisite-patch-id: 6aa0e3e93a008279d71e535a3d0cf48643f55e19

Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/2 crypto: hisi-trng - Remove crypto_rng interface

drivers/crypto/hisilicon/trng/trng.c exposes the same hardware through two completely separate interfaces, crypto_rng and hwrng. However, the implementation of this is buggy because it permits generation operations from these interfaces to run concurrently with each other, accessing the same registers. That is, hisi_trng_generate() synchronizes with itself but not with hisi_trng_read(). This results in potential repetition of output from the RNG, output of non-random values, etc.

Fortunately, there's actually no point in hardware RNG drivers implementing the crypto_rng interface. It's not actually used by anything besides the "rng" algorithm type of AF_ALG, which in turn is not actually used in practice. Other crypto_rng hardware drivers are likewise being phased out, leaving just the hwrng support.

Thus, remove it to simplify the code and avoid conflict (and confusion) with the hwrng interface which is the one that actually matters.

Fixes e4d9d10ef4be ("crypto: hisilicon/trng - add support for PRNG")
---
 drivers/crypto/hisilicon/Kconfig     |   1 -
 drivers/crypto/hisilicon/trng/trng.c | 296 +--------------------------
 2 files changed, 2 insertions(+), 295 deletions(-)
drivers/crypto/hisilicon/Kconfig +0 -1
index 1e6d772f4bb6..8aa23c939775 100644
@@ -78,8 +78,7 @@ config CRYPTO_DEV_HISI_HPRE
 
 config CRYPTO_DEV_HISI_TRNG
 	tristate "Support for HISI TRNG Driver"
 	depends on ARM64 && ACPI
 	select HW_RANDOM
-	select CRYPTO_RNG
 	help
 	  Support for HiSilicon TRNG Driver.
drivers/crypto/hisilicon/trng/trng.c +2 -294

364 lines not on this page · raw message

Signature · 1 line
2.54.0
#2 lore raw

PATCH 2/2 hwrng: hisi-trng - Move hisi-trng into drivers/char/hw_random/

In reply to Eric Biggers

Since this file just implements a hwrng driver, move it into drivers/char/hw_random/. Rename the kconfig option accordingly as well.

Note that this moves the file back to its original location.

---
 MAINTAINERS                                            |  2 +-
 arch/arm64/configs/defconfig                           |  2 +-
 drivers/char/hw_random/Kconfig                         | 10 ++++++++++
 drivers/char/hw_random/Makefile                        |  1 +
 .../trng/trng.c => char/hw_random/hisi-trng-v2.c}      |  0
 drivers/crypto/hisilicon/Kconfig                       |  7 -------
 drivers/crypto/hisilicon/Makefile                      |  1 -
 drivers/crypto/hisilicon/trng/Makefile                 |  2 --
 8 files changed, 13 insertions(+), 12 deletions(-)
 rename drivers/{crypto/hisilicon/trng/trng.c => char/hw_random/hisi-trng-v2.c} (100%)
 delete mode 100644 drivers/crypto/hisilicon/trng/Makefile
MAINTAINERS +1 -1
index 882214b0e7db..dcbbc56368be 100644
@@ -11703,11 +11703,11 @@ F:	Documentation/devicetree/bindings/mfd/hisilicon,hi6421-spmi-pmic.yaml
 F:	drivers/mfd/hi6421-spmi-pmic.c
 
 HISILICON TRUE RANDOM NUMBER GENERATOR V2 SUPPORT
 M:	Weili Qian <[email protected]>
 S:	Maintained
-F:	drivers/crypto/hisilicon/trng/trng.c
+F:	drivers/char/hw_random/hisi-trng-v2.c
 
 HISILICON V3XX SPI NOR FLASH Controller Driver
 M:	Yang Shen <[email protected]>
 S:	Maintained
 W:	http://www.hisilicon.com
arch/arm64/configs/defconfig +1 -1
index bb930cce7233..9aa62b675023 100644
@@ -548,10 +548,11 @@ CONFIG_VIRTIO_CONSOLE=y
 CONFIG_IPMI_HANDLER=m
 CONFIG_IPMI_DEVICE_INTERFACE=m
 CONFIG_IPMI_SI=m
 CONFIG_HW_RANDOM=y
 CONFIG_HW_RANDOM_VIRTIO=y
+CONFIG_HW_RANDOM_HISI_TRNG=m
 CONFIG_HW_RANDOM_QCOM=m
 CONFIG_TCG_TPM=y
 CONFIG_TCG_TIS=m
 CONFIG_TCG_TIS_SPI=m
 CONFIG_TCG_TIS_SPI_CR50=y
@@ -1960,11 +1961,10 @@ CONFIG_CRYPTO_DEV_ZYNQMP_AES=m
 CONFIG_CRYPTO_DEV_ZYNQMP_SHA3=m
 CONFIG_CRYPTO_DEV_CCREE=m
 CONFIG_CRYPTO_DEV_HISI_SEC2=m
 CONFIG_CRYPTO_DEV_HISI_ZIP=m
 CONFIG_CRYPTO_DEV_HISI_HPRE=m
-CONFIG_CRYPTO_DEV_HISI_TRNG=m
 CONFIG_CRYPTO_DEV_SA2UL=m
 CONFIG_DMA_RESTRICTED_POOL=y
 CONFIG_CMA_SIZE_MBYTES=32
 CONFIG_PRINTK_TIME=y
 CONFIG_DEBUG_KERNEL=y
drivers/char/hw_random/Kconfig +10 -0
index 7102e03dcf0a..6d8012d55ac0 100644
@@ -371,10 +371,20 @@ config HW_RANDOM_HISTB
 	  Generator hardware found on Hisilicon Hi37xx SoC.
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called histb-rng.
 
+config HW_RANDOM_HISI_TRNG
+	tristate "HiSilicon True Random Number Generator support"
+	depends on ARM64 && ACPI
+	help
+	  This driver provides kernel-side support for the True Random Number
+	  Generator hardware found on some HiSilicon SoCs.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called hisi-trng-v2.
+
 config HW_RANDOM_ST
 	tristate "ST Microelectronics HW Random Number Generator support"
 	depends on ARCH_STI || COMPILE_TEST
 	help
 	  This driver provides kernel-side support for the Random Number
drivers/char/hw_random/Makefile +1 -0
index 605ba8df5a8f..f2888524b6ef 100644
@@ -29,10 +29,11 @@ obj-$(CONFIG_HW_RANDOM_OCTEON) += octeon-rng.o
 obj-$(CONFIG_HW_RANDOM_NOMADIK) += nomadik-rng.o
 obj-$(CONFIG_HW_RANDOM_PSERIES) += pseries-rng.o
 obj-$(CONFIG_HW_RANDOM_POWERNV) += powernv-rng.o
 obj-$(CONFIG_HW_RANDOM_HISI)	+= hisi-rng.o
 obj-$(CONFIG_HW_RANDOM_HISTB) += histb-rng.o
+obj-$(CONFIG_HW_RANDOM_HISI_TRNG) += hisi-trng-v2.o
 obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
 obj-$(CONFIG_HW_RANDOM_BCM74110) += bcm74110-rng.o
 obj-$(CONFIG_HW_RANDOM_IPROC_RNG200) += iproc-rng200.o
 obj-$(CONFIG_HW_RANDOM_ST) += st-rng.o
 obj-$(CONFIG_HW_RANDOM_XGENE) += xgene-rng.o
drivers/char/hw_random/hisi-trng-v2.c renamed from drivers/crypto/hisilicon/trng/trng.c +0 -0
similarity index 100%
rename from drivers/crypto/hisilicon/trng/trng.c
rename to drivers/char/hw_random/hisi-trng-v2.c
drivers/crypto/hisilicon/Kconfig +0 -7
index 8aa23c939775..aeff08ccbadd 100644
@@ -73,12 +73,5 @@ config CRYPTO_DEV_HISI_HPRE
 	select CRYPTO_RSA
 	select CRYPTO_ECDH
 	help
 	  Support for HiSilicon HPRE(High Performance RSA Engine)
 	  accelerator, which can accelerate RSA and DH algorithms.
-
-config CRYPTO_DEV_HISI_TRNG
-	tristate "Support for HISI TRNG Driver"
-	depends on ARM64 && ACPI
-	select HW_RANDOM
-	help
-	  Support for HiSilicon TRNG Driver.
drivers/crypto/hisilicon/Makefile +0 -1
index 8595a5a5d228..e1068ee9f973 100644
@@ -3,6 +3,5 @@ obj-$(CONFIG_CRYPTO_DEV_HISI_HPRE) += hpre/
 obj-$(CONFIG_CRYPTO_DEV_HISI_SEC) += sec/
 obj-$(CONFIG_CRYPTO_DEV_HISI_SEC2) += sec2/
 obj-$(CONFIG_CRYPTO_DEV_HISI_QM) += hisi_qm.o
 hisi_qm-objs = qm.o sgl.o debugfs.o
 obj-$(CONFIG_CRYPTO_DEV_HISI_ZIP) += zip/
-obj-$(CONFIG_CRYPTO_DEV_HISI_TRNG) += trng/
drivers/crypto/hisilicon/trng/Makefile deleted +0 -2
deleted file mode 100644
index d909079f351c..000000000000
@@ -1,2 +0,0 @@
-obj-$(CONFIG_CRYPTO_DEV_HISI_TRNG) += hisi-trng-v2.o
-hisi-trng-v2-objs = trng.o
Signature · 1 line
2.54.0
Acked-by on the v1 series
#3 lore raw
In reply to Eric Biggers
Quoted 26 lines · Eric Biggers

This series fixes and greatly simplifies the HiSilicon TRNG driver by removing the gratuitous crypto_rng interface, leaving just hwrng which is the one that actually matters.

Note that this mirrors similar changes in other drivers such as qcom-rng
(https://lore.kernel.org/r/[email protected])

Eric Biggers (2):
crypto: hisi-trng - Remove crypto_rng interface
hwrng: hisi-trng - Move hisi-trng into drivers/char/hw_random/

 MAINTAINERS                            |   2 +-
 arch/arm64/configs/defconfig           |   2 +-
 drivers/char/hw_random/Kconfig         |  10 +
 drivers/char/hw_random/Makefile        |   1 +
 drivers/char/hw_random/hisi-trng-v2.c  |  98 +++++++
 drivers/crypto/hisilicon/Kconfig       |   8 -
 drivers/crypto/hisilicon/Makefile      |   1 -
 drivers/crypto/hisilicon/trng/Makefile |   2 -
 drivers/crypto/hisilicon/trng/trng.c   | 390 -------------------------
 9 files changed, 111 insertions(+), 403 deletions(-)
 create mode 100644 drivers/char/hw_random/hisi-trng-v2.c
 delete mode 100644 drivers/crypto/hisilicon/trng/Makefile
 delete mode 100644 drivers/crypto/hisilicon/trng/trng.c
Quoted 6 lines

base-commit: 5624ea54f3ba5c83d2e5503411a31a8be0278c1e
prerequisite-patch-id: 07e982b663ac3f8312ca524f6b91b5b38661df5e
prerequisite-patch-id: 72064361a8f36e015ab0b7e1fa4d364b40d90506
prerequisite-patch-id: 8978b8e0db7f47935e5f6f0aff14a97f55d3073c
prerequisite-patch-id: 6aa0e3e93a008279d71e535a3d0cf48643f55e19

Thanks.

maintainer
#4 lore raw
In reply to Eric Biggers
Quoted 26 lines · Eric Biggers

This series fixes and greatly simplifies the HiSilicon TRNG driver by removing the gratuitous crypto_rng interface, leaving just hwrng which is the one that actually matters.

Note that this mirrors similar changes in other drivers such as qcom-rng
(https://lore.kernel.org/r/[email protected])

Eric Biggers (2):
crypto: hisi-trng - Remove crypto_rng interface
hwrng: hisi-trng - Move hisi-trng into drivers/char/hw_random/

 MAINTAINERS                            |   2 +-
 arch/arm64/configs/defconfig           |   2 +-
 drivers/char/hw_random/Kconfig         |  10 +
 drivers/char/hw_random/Makefile        |   1 +
 drivers/char/hw_random/hisi-trng-v2.c  |  98 +++++++
 drivers/crypto/hisilicon/Kconfig       |   8 -
 drivers/crypto/hisilicon/Makefile      |   1 -
 drivers/crypto/hisilicon/trng/Makefile |   2 -
 drivers/crypto/hisilicon/trng/trng.c   | 390 -------------------------
 9 files changed, 111 insertions(+), 403 deletions(-)
 create mode 100644 drivers/char/hw_random/hisi-trng-v2.c
 delete mode 100644 drivers/crypto/hisilicon/trng/Makefile
 delete mode 100644 drivers/crypto/hisilicon/trng/trng.c
Quoted 7 lines

base-commit: 5624ea54f3ba5c83d2e5503411a31a8be0278c1e
prerequisite-patch-id: 07e982b663ac3f8312ca524f6b91b5b38661df5e
prerequisite-patch-id: 72064361a8f36e015ab0b7e1fa4d364b40d90506
prerequisite-patch-id: 8978b8e0db7f47935e5f6f0aff14a97f55d3073c
prerequisite-patch-id: 6aa0e3e93a008279d71e535a3d0cf48643f55e19

Signature · 1 line
2.54.0

All applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt