Skip to contentSkip to conversation

crypto: Add Qcom PRNG support

PATCH Superseded Vinod Koul 4 participants 19 messages Jul 3, 2018 – Jul 5, 2018

Subsystems (4)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Vinod Koul

author
#0 lore raw

v3 cover crypto: Add Qcom PRNG support

This series removes the hwrng qcom driver and replaces it with crypto qcom driver and then adds support for Execution Environment (EE) found in v2 version of the hardware and ACPI support for these

Timur Tabi (1):
crypto: qcom: Add ACPI support

Vinod Koul (5):
hwrng: remove msm hw_random driver
dt-bindings: crypto: Move prng binding to crypto
crypto: Add Qcom prng driver
dt-bindings: crypto: Add new compatible qcom,prng-ee
crypto: qcom: Add support for prng-ee

 .../bindings/{rng => crypto}/qcom,prng.txt         |   4 +-
 drivers/char/hw_random/Kconfig                     |  13 --
 drivers/char/hw_random/Makefile                    |   1 -
 drivers/char/hw_random/msm-rng.c                   | 183 ----------------
 drivers/crypto/Kconfig                             |  11 +
 drivers/crypto/Makefile                            |   1 +
 drivers/crypto/qcom-rng.c                          | 244 +++++++++++++++++++++
 7 files changed, 259 insertions(+), 198 deletions(-)
 rename Documentation/devicetree/bindings/{rng => crypto}/qcom,prng.txt (73%)
 delete mode 100644 drivers/char/hw_random/msm-rng.c
 create mode 100644 drivers/crypto/qcom-rng.c
Signature · 1 line
2.14.4
author
#1 lore raw

PATCH v3 1/6 hwrng: remove msm hw_random driver

This driver is for a psedo-rng so should not be added in hwrng. Remove it so that it's replacement can be added.

---
 drivers/char/hw_random/Kconfig   |  13 ---
 drivers/char/hw_random/Makefile  |   1 -
 drivers/char/hw_random/msm-rng.c | 183 ---------------------------------------
 3 files changed, 197 deletions(-)
 delete mode 100644 drivers/char/hw_random/msm-rng.c
drivers/char/hw_random/Kconfig +0 -13
index c34b257d852d..dac895dc01b9 100644
@@ -307,19 +307,6 @@ config HW_RANDOM_HISI
 
 	  If unsure, say Y.
 
-config HW_RANDOM_MSM
-	tristate "Qualcomm SoCs Random Number Generator support"
-	depends on HW_RANDOM && ARCH_QCOM
-	default HW_RANDOM
-	---help---
-	  This driver provides kernel-side support for the Random Number
-	  Generator hardware found on Qualcomm SoCs.
-
-	  To compile this driver as a module, choose M here. the
-	  module will be called msm-rng.
-
-	  If unsure, say Y.
-
 config HW_RANDOM_ST
 	tristate "ST Microelectronics HW Random Number Generator support"
 	depends on HW_RANDOM && ARCH_STI
drivers/char/hw_random/Makefile +0 -1
index 533e913c93d1..e35ec3ce3a20 100644
@@ -29,7 +29,6 @@ obj-$(CONFIG_HW_RANDOM_POWERNV) += powernv-rng.o
 obj-$(CONFIG_HW_RANDOM_HISI)	+= hisi-rng.o
 obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
 obj-$(CONFIG_HW_RANDOM_IPROC_RNG200) += iproc-rng200.o
-obj-$(CONFIG_HW_RANDOM_MSM) += msm-rng.o
 obj-$(CONFIG_HW_RANDOM_ST) += st-rng.o
 obj-$(CONFIG_HW_RANDOM_XGENE) += xgene-rng.o
 obj-$(CONFIG_HW_RANDOM_STM32) += stm32-rng.o
drivers/char/hw_random/msm-rng.c deleted +0 -183

183 lines not on this page · raw message

Signature · 1 line
2.14.4
author
#2 lore raw

PATCH v3 2/6 dt-bindings: crypto: Move prng binding to crypto

In reply to Vinod Koul

Now that we are adding new driver for prng in crypto, move the binding as well.

---
 Documentation/devicetree/bindings/{rng => crypto}/qcom,prng.txt | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename Documentation/devicetree/bindings/{rng => crypto}/qcom,prng.txt (100%)
Documentation/devicetree/bindings/crypto/qcom,prng.txt renamed from Documentation/devicetree/bindings/rng/qcom,prng.txt +0 -0
similarity index 100%
rename from Documentation/devicetree/bindings/rng/qcom,prng.txt
rename to Documentation/devicetree/bindings/crypto/qcom,prng.txt
Signature · 1 line
2.14.4
author
#3 lore raw

PATCH v3 3/6 crypto: Add Qcom prng driver

In reply to Vinod Koul

This ports the Qcom prng from older hw_random driver.

No change of functionality and move from hw_random to crypto APIs is done.

---
 drivers/crypto/Kconfig    |  11 +++
 drivers/crypto/Makefile   |   1 +
 drivers/crypto/qcom-rng.c | 208 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 220 insertions(+)
 create mode 100644 drivers/crypto/qcom-rng.c
drivers/crypto/Kconfig +11 -0
index 43cccf6aff61..b8d9e71e550a 100644
@@ -585,6 +585,17 @@ config CRYPTO_DEV_QCE
 	  hardware. To compile this driver as a module, choose M here. The
 	  module will be called qcrypto.
 
+config CRYPTO_DEV_QCOM_RNG
+	tristate "Qualcomm Randon Number Generator Driver"
+	depends on ARCH_QCOM || COMPILE_TEST
+	select CRYPTO_RNG
+	help
+	  This driver provides support for the Random Number
+	  Generator hardware found on Qualcomm SoCs.
+
+	  To compile this driver as a module, choose M here. the
+          module will be called qcom-rng. If unsure, say N.
+
 config CRYPTO_DEV_VMX
 	bool "Support for VMX cryptographic acceleration instructions"
 	depends on PPC64 && VSX
drivers/crypto/Makefile +1 -0
index 7ae87b4f6c8d..3602875c4f80 100644
@@ -33,6 +33,7 @@ obj-$(CONFIG_CRYPTO_DEV_PICOXCELL) += picoxcell_crypto.o
 obj-$(CONFIG_CRYPTO_DEV_PPC4XX) += amcc/
 obj-$(CONFIG_CRYPTO_DEV_QAT) += qat/
 obj-$(CONFIG_CRYPTO_DEV_QCE) += qce/
+obj-$(CONFIG_CRYPTO_DEV_QCOM_RNG) += qcom-rng.o
 obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rockchip/
 obj-$(CONFIG_CRYPTO_DEV_S5P) += s5p-sss.o
 obj-$(CONFIG_CRYPTO_DEV_SAHARA) += sahara.o
drivers/crypto/qcom-rng.c new file +208 -0

208 lines not on this page · raw message

Signature · 1 line
2.14.4
author
#11 lore raw

PATCH v3 4/6 dt-bindings: crypto: Add new compatible qcom,prng-ee

In reply to Vinod Koul

Later qcom chips support v2 of the prng, which exposes an EE (Execution Enviornment) for OS to use so add new compatible qcom,prng-ee for this.

---
 Documentation/devicetree/bindings/crypto/qcom,prng.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/crypto/qcom,prng.txt +3 -1
index 8e5853c2879b..7ee0e9eac973 100644
@@ -2,7 +2,9 @@ Qualcomm MSM pseudo random number generator.
 
 Required properties:
 
-- compatible  : should be "qcom,prng"
+- compatible  : should be "qcom,prng" for 8916 etc
+              : should be "qcom,prng-ee" for 8996 and later using EE
+		(Execution Environment) slice of prng
 - reg         : specifies base physical address and size of the registers map
 - clocks      : phandle to clock-controller plus clock-specifier pair
 - clock-names : "core" clocks all registers, FIFO and circuits in PRNG IP block
Signature · 1 line
2.14.4
author
#12 lore raw

PATCH v3 5/6 crypto: qcom: Add support for prng-ee

In reply to Vinod Koul

Qcom 8996 and later chips features multiple Execution Environments (EE) and secure world is typically responsible for configuring the prng.

Add driver data for qcom,prng as 0 and qcom,prng-ee as 1 and use that to skip initialization routine.

---
 drivers/crypto/qcom-rng.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/crypto/qcom-rng.c +9 -2
index e235a35359d3..fdbbcac7bcb8 100644
@@ -30,6 +30,7 @@ struct qcom_rng {
 	struct mutex lock;
 	void __iomem *base;
 	struct clk *clk;
+	unsigned int skip_init;
 };
 
 struct qcom_rng_ctx {
@@ -128,7 +129,10 @@ static int qcom_rng_init(struct crypto_tfm *tfm)
 
 	ctx->rng = qcom_rng_dev;
 
-	return qcom_rng_enable(ctx->rng);
+	if (!ctx->rng->skip_init)
+		return qcom_rng_enable(ctx->rng);
+
+	return 0;
 }
 
 static struct rng_alg qcom_rng_alg = {
@@ -168,6 +172,8 @@ static int qcom_rng_probe(struct platform_device *pdev)
 	if (IS_ERR(rng->clk))
 		return PTR_ERR(rng->clk);
 
+	rng->skip_init = (unsigned long)of_device_get_match_data(&pdev->dev);
+
 	qcom_rng_dev = rng;
 	ret = crypto_register_rng(&qcom_rng_alg);
 	if (ret) {
@@ -188,7 +194,8 @@ static int qcom_rng_remove(struct platform_device *pdev)
 }
 
 static const struct of_device_id qcom_rng_of_match[] = {
-	{ .compatible = "qcom,prng" },
+	{ .compatible = "qcom,prng", .data = (void *)0},
+	{ .compatible = "qcom,prng-ee", .data = (void *)1},
 	{}
 };
 MODULE_DEVICE_TABLE(of, qcom_rng_of_match);
Signature · 1 line
2.14.4
author
#13 lore raw

PATCH v3 6/6 crypto: qcom: Add ACPI support

In reply to Vinod Koul

From: Timur Tabi <[email protected]>

Add support for probing on ACPI systems, with ACPI HID QCOM8160.

On ACPI systems, clocks are always enabled, the PRNG should already be enabled, and the register region is read-only. The driver only verifies that the hardware is already enabled never tries to disable or configure it.

[port to crypto API]
---
 drivers/crypto/qcom-rng.c | 37 +++++++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)
drivers/crypto/qcom-rng.c +33 -4
index fdbbcac7bcb8..bc0131d130d6 100644
@@ -4,6 +4,7 @@
 // Based on msm-rng.c and downstream driver
 
 #include <crypto/internal/rng.h>
+#include <linux/acpi.h>
 #include <linux/clk.h>
 #include <linux/crypto.h>
 #include <linux/module.h>
@@ -154,6 +155,7 @@ static int qcom_rng_probe(struct platform_device *pdev)
 {
 	struct resource *res;
 	struct qcom_rng *rng;
+	u32 val;
 	int ret;
 
 	rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL);
@@ -168,11 +170,27 @@ static int qcom_rng_probe(struct platform_device *pdev)
 	if (IS_ERR(rng->base))
 		return PTR_ERR(rng->base);
 
-	rng->clk = devm_clk_get(&pdev->dev, "core");
-	if (IS_ERR(rng->clk))
-		return PTR_ERR(rng->clk);
 
-	rng->skip_init = (unsigned long)of_device_get_match_data(&pdev->dev);
+	/*
+	 * ACPI systems have v2 hardware. The clocks are always enabled,
+	 * the PRNG register space is read-only and the PRNG should
+	 * already be enabled.
+	 */
+	if (has_acpi_companion(&pdev->dev)) {
+		val = readl(rng->base + PRNG_CONFIG);
+		if (!(val & PRNG_CONFIG_HW_ENABLE)) {
+			dev_err(&pdev->dev, "device is not enabled\n");
+			return -ENODEV;
+		}
+		rng->skip_init = 1;
+	} else {
+		rng->clk = devm_clk_get(&pdev->dev, "core");
+		if (IS_ERR(rng->clk))
+			return PTR_ERR(rng->clk);
+
+		rng->skip_init =
+			(unsigned long)of_device_get_match_data(&pdev->dev);
+	}
 
 	qcom_rng_dev = rng;
 	ret = crypto_register_rng(&qcom_rng_alg);
@@ -193,6 +211,16 @@ static int qcom_rng_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#if IS_ENABLED(CONFIG_ACPI)
+static const struct acpi_device_id qcom_rng_acpi_match[] = {
+	{
+		.id = "QCOM8160",
+	},
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, msm_rng_acpi_match);
+#endif
+
 static const struct of_device_id qcom_rng_of_match[] = {
 	{ .compatible = "qcom,prng", .data = (void *)0},
 	{ .compatible = "qcom,prng-ee", .data = (void *)1},
@@ -206,6 +234,7 @@ static struct platform_driver qcom_rng_driver = {
 	.driver = {
 		.name = KBUILD_MODNAME,
 		.of_match_table = of_match_ptr(qcom_rng_of_match),
+		.acpi_match_table = ACPI_PTR(qcom_rng_acpi_match),
 	}
 };
 module_platform_driver(qcom_rng_driver);
Signature · 1 line
2.14.4
#4 lore raw

Re: [PATCH v3 3/6] crypto: Add Qcom prng driver

In reply to Vinod Koul

Am Dienstag, 3. Juli 2018, 08:04:31 CEST schrieb Vinod Koul:

Hi Vinod,

drivers/crypto/qcom-rng.c line 44

Quoted 4 lines
drivers/crypto/qcom-rng.c new file +4 -0
+static int qcom_rng_read(struct qcom_rng *rng, void *data, size_t max)
+{
+	size_t currsize = 0;
+	u32 *retdata = data;

How can you be sure that this cast is appropriate? I.e. how is it guaranteed that data is 4-byte aligned?

Also, the data variable in qcom_rng_generate is a u8 -- shouldn't this type be used instead of a void?

Ciao
Stephan

#14 lore raw

Re: [PATCH v3 6/6] crypto: qcom: Add ACPI support

In reply to Vinod Koul
Quoted 10 lines · Vinod Koul

Add support for probing on ACPI systems, with ACPI HID QCOM8160.

On ACPI systems, clocks are always enabled, the PRNG should already be enabled, and the register region is read-only. The driver only verifies that the hardware is already enabled never tries to disable or configure it.

[port to crypto API]

I've asked a colleague who still works at Qualcomm to test this code on silicon. It looks okay, but I just want to be sure.

drivers/crypto/qcom-rng.c static int qcom_rng_probe(struct platform_device *pdev) · line 184

Quoted 11 lines
drivers/crypto/qcom-rng.c +11 -0
+	/*
+	 * ACPI systems have v2 hardware. The clocks are always enabled,
+	 * the PRNG register space is read-only and the PRNG should
+	 * already be enabled.
+	 */
+	if (has_acpi_companion(&pdev->dev)) {
+		val = readl(rng->base + PRNG_CONFIG);
+		if (!(val & PRNG_CONFIG_HW_ENABLE)) {
+			dev_err(&pdev->dev, "device is not enabled\n");
+			return -ENODEV;
+		}

I'm having second thoughts about this PRNG_CONFIG_HW_ENABLE check. The PRNG on the QDF2400 is the same as the one on the 8996, so it should have the same register interface. Currently, the ACPI table points to a full PRNG register block, but I'm beginning to believe that it should instead point to a "reduced" block that doesn't have a PRNG_CONFIG register.

#16 lore raw

Re: [PATCH v3 6/6] crypto: qcom: Add ACPI support

In reply to Vinod Koul
Quoted 70 lines · Vinod Koul

From: Timur Tabi <[email protected]>

Add support for probing on ACPI systems, with ACPI HID QCOM8160.

On ACPI systems, clocks are always enabled, the PRNG should already be enabled, and the register region is read-only. The driver only verifies that the hardware is already enabled never tries to disable or configure it.

[port to crypto API]
---
  drivers/crypto/qcom-rng.c | 37 +++++++++++++++++++++++++++++++++----
  1 file changed, 33 insertions(+), 4 deletions(-)
drivers/crypto/qcom-rng.c +22 -4
index fdbbcac7bcb8..bc0131d130d6 100644
@@ -4,6 +4,7 @@
  // Based on msm-rng.c and downstream driver
 
  #include <crypto/internal/rng.h>
+#include <linux/acpi.h>
  #include <linux/clk.h>
  #include <linux/crypto.h>
  #include <linux/module.h>
@@ -154,6 +155,7 @@ static int qcom_rng_probe(struct platform_device *pdev)
  {
  	struct resource *res;
  	struct qcom_rng *rng;
+	u32 val;
  	int ret;
 
  	rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL);
@@ -168,11 +170,27 @@ static int qcom_rng_probe(struct platform_device *pdev)
  	if (IS_ERR(rng->base))
  		return PTR_ERR(rng->base);
 
-	rng->clk = devm_clk_get(&pdev->dev, "core");
-	if (IS_ERR(rng->clk))
-		return PTR_ERR(rng->clk);
 
-	rng->skip_init = (unsigned long)of_device_get_match_data(&pdev->dev);
+	/*
+	 * ACPI systems have v2 hardware. The clocks are always enabled,
+	 * the PRNG register space is read-only and the PRNG should
+	 * already be enabled.
+	 */
+	if (has_acpi_companion(&pdev->dev)) {
+		val = readl(rng->base + PRNG_CONFIG);
+		if (!(val & PRNG_CONFIG_HW_ENABLE)) {
+			dev_err(&pdev->dev, "device is not enabled\n");
+			return -ENODEV;
+		}
+		rng->skip_init = 1;
+	} else {
+		rng->clk = devm_clk_get(&pdev->dev, "core");
+		if (IS_ERR(rng->clk))
+			return PTR_ERR(rng->clk);
+
+		rng->skip_init =
+			(unsigned long)of_device_get_match_data(&pdev->dev);
+	}
 
  	qcom_rng_dev = rng;
  	ret = crypto_register_rng(&qcom_rng_alg);
@@ -193,6 +211,16 @@ static int qcom_rng_remove(struct platform_device *pdev)
  	return 0;

drivers/crypto/qcom-rng.c static int qcom_rng_remove(struct platform_device *pdev) · line 221

Quoted 10 lines
drivers/crypto/qcom-rng.c +8 -0
  }
 
+#if IS_ENABLED(CONFIG_ACPI)
+static const struct acpi_device_id qcom_rng_acpi_match[] = {
+	{
+		.id = "QCOM8160",
+	},
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, msm_rng_acpi_match);

qcom_rng_acpi_match?
Looks like a copy/paste issue. This causes a build failure for me. I'm trying to see if it works otherwise...

Quoted 14 lines
drivers/crypto/qcom-rng.c +3 -0
+#endif
+
  static const struct of_device_id qcom_rng_of_match[] = {
  	{ .compatible = "qcom,prng", .data = (void *)0},
  	{ .compatible = "qcom,prng-ee", .data = (void *)1},
@@ -206,6 +234,7 @@ static struct platform_driver qcom_rng_driver = {
  	.driver = {
  		.name = KBUILD_MODNAME,
  		.of_match_table = of_match_ptr(qcom_rng_of_match),
+		.acpi_match_table = ACPI_PTR(qcom_rng_acpi_match),
  	}
  };
  module_platform_driver(qcom_rng_driver);
Signature · 4 lines
Jeffrey Hugo
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.
author
#5 lore raw

Re: [PATCH v3 3/6] crypto: Add Qcom prng driver

In reply to Stephan Mueller

Hi Stephan,

Quoted 8 lines · Stephan Mueller

Am Dienstag, 3. Juli 2018, 08:04:31 CEST schrieb Vinod Koul:

drivers/crypto/qcom-rng.c line 44

Quoted 4 lines
drivers/crypto/qcom-rng.c new file +4 -0
+static int qcom_rng_read(struct qcom_rng *rng, void *data, size_t max)
+{
+	size_t currsize = 0;
+	u32 *retdata = data;

How can you be sure that this cast is appropriate? I.e. how is it guaranteed that data is 4-byte aligned?

While reading we check the alignment:

               /* make sure we stay on 32bit boundary */
               if ((max - currsize) < WORD_SZ)
                       break;
Quoted 2 lines

Also, the data variable in qcom_rng_generate is a u8 -- shouldn't this type be used instead of a void?

That does make sense to me. IIRC the read is for a byte. I will check this and update it

Thanks for the quick review

Signature · 1 line
~Vinod
author
#15 lore raw

Re: [PATCH v3 6/6] crypto: qcom: Add ACPI support

In reply to Timur Tabi
Quoted 24 lines · Timur Tabi
Quoted 10 lines · Vinod Koul

Add support for probing on ACPI systems, with ACPI HID QCOM8160.

On ACPI systems, clocks are always enabled, the PRNG should already be enabled, and the register region is read-only. The driver only verifies that the hardware is already enabled never tries to disable or configure it.

[port to crypto API]

I've asked a colleague who still works at Qualcomm to test this code on silicon. It looks okay, but I just want to be sure.

Quoted 9 lines
drivers/crypto/qcom-rng.c +9 -0
+	/*
+	 * ACPI systems have v2 hardware. The clocks are always enabled,
+	 * the PRNG register space is read-only and the PRNG should
+	 * already be enabled.
+	 */
+	if (has_acpi_companion(&pdev->dev)) {
+		val = readl(rng->base + PRNG_CONFIG);
+		if (!(val & PRNG_CONFIG_HW_ENABLE)) {
+			dev_err(&pdev->dev, "device is not enabled\n");
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+			return -ENODEV;
+		}

I'm having second thoughts about this PRNG_CONFIG_HW_ENABLE check. The PRNG on the QDF2400 is the same as the one on the 8996, so it should have the same register interface. Currently, the ACPI table points to a full PRNG register block, but I'm beginning to believe that it should instead point to a "reduced" block that doesn't have a PRNG_CONFIG register.

That was my doubt too. I will go ahead and make it skip this then...

Signature · 1 line
~Vinod
author
#17 lore raw

Re: [PATCH v3 6/6] crypto: qcom: Add ACPI support

In reply to Jeffrey Hugo
Quoted 14 lines · Jeffrey Hugo

drivers/crypto/qcom-rng.c static int qcom_rng_remove(struct platform_device *pdev) · line 221

Quoted 8 lines · Vinod Koul
drivers/crypto/qcom-rng.c +8 -0
+#if IS_ENABLED(CONFIG_ACPI)
+static const struct acpi_device_id qcom_rng_acpi_match[] = {
+	{
+		.id = "QCOM8160",
+	},
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, msm_rng_acpi_match);

qcom_rng_acpi_match?
Looks like a copy/paste issue. This causes a build failure for me. I'm trying to see if it works otherwise...

Ah sorry about that, I though I had fixed it, looks like I missed to fold the fix.

Did it work for you?

Signature · 1 line
~Vinod
author
#6 lore raw

Re: [PATCH v3 3/6] crypto: Add Qcom prng driver

In reply to Vinod
Quoted 18 lines · Vinod

Hi Stephan,

Quoted 8 lines · Stephan Mueller

Am Dienstag, 3. Juli 2018, 08:04:31 CEST schrieb Vinod Koul:

drivers/crypto/qcom-rng.c line 44

Quoted 4 lines
drivers/crypto/qcom-rng.c new file +4 -0
+static int qcom_rng_read(struct qcom_rng *rng, void *data, size_t max)
+{
+	size_t currsize = 0;
+	u32 *retdata = data;

How can you be sure that this cast is appropriate? I.e. how is it guaranteed that data is 4-byte aligned?

While reading we check the alignment:

               /* make sure we stay on 32bit boundary */
               if ((max - currsize) < WORD_SZ)
                       break;
Quoted 5 lines
Quoted 2 lines

Also, the data variable in qcom_rng_generate is a u8 -- shouldn't this type be used instead of a void?

That does make sense to me. IIRC the read is for a byte. I will check this and update it

Okay so I rechecked this, the hardware gives 32 bits of random data. I am thinking of splitting the word and updating by each byte. That way trailing zero can also be avoided which is the case now

Signature · 1 line
~Vinod
#7 lore raw

Re: [PATCH v3 3/6] crypto: Add Qcom prng driver

Am Mittwoch, 4. Juli 2018, 08:10:35 CEST schrieb Vinod:

Hi Vinod,

Quoted 14 lines · Vinod
Quoted 13 lines

Hi Stephan,

Quoted 9 lines · Stephan Mueller

Am Dienstag, 3. Juli 2018, 08:04:31 CEST schrieb Vinod Koul:

drivers/crypto/qcom-rng.c line 44

Quoted 5 lines

+static int qcom_rng_read(struct qcom_rng *rng, void *data, size_t max)

drivers/crypto/qcom-rng.c new file +3 -0
+{
+	size_t currsize = 0;
+	u32 *retdata = data;

How can you be sure that this cast is appropriate? I.e. how is it guaranteed that data is 4-byte aligned?

Quoted 5 lines
Quoted 5 lines

While reading we check the alignment:

               /* make sure we stay on 32bit boundary */
               if ((max - currsize) < WORD_SZ)
               
                       break;

I am not sure I follow your argument.

You cast a void (or u8 pointer into u32:

+ u32 *retdata = data;

You use it:

+ *retdata++ = val;

Followed by your check.

What I mean is that the initial cast and then the subsequent write operation is only guaranteed to work if the initial pointer is alighed on a 4 byte boundary. However, since it is an u8 pointer, it is not guaranteed to be aligned.

So, I guess you want to use memcpy (at least if it is not aligned).

Ciao
Stephan

#8 lore raw

Re: [PATCH v3 3/6] crypto: Add Qcom prng driver

In reply to Vinod
Quoted 3 lines · Vinod

Okay so I rechecked this, the hardware gives 32 bits of random data. I am thinking of splitting the word and updating by each byte. That way trailing zero can also be avoided which is the case now

The current driver only returns data in multiples of 4 bytes. Why can't you keep that?

#9 lore raw

Re: [PATCH v3 3/6] crypto: Add Qcom prng driver

In reply to Vinod Koul

Am Dienstag, 3. Juli 2018, 08:04:31 CEST schrieb Vinod Koul:

Hi Vinod,

drivers/crypto/qcom-rng.c line 94

Quoted 5 lines
drivers/crypto/qcom-rng.c new file +5 -0
+static int qcom_rng_seed(struct crypto_rng *tfm, const u8 *seed,
+			 unsigned int slen)
+{
+	return 0;
+}

One more question: is it not possible to mix in data into the DRNG? I thought it would be possible with the Qualcomm DRBG.

Note, I am asking because of my /dev/random drop-in-replacement implementation, any RNG from the kernel crypto API can be configured to be used as an output DRNG. Though, this will only work if the DRNG also accepts seed from the software noise sources.

Ciao
Stephan

author
#10 lore raw

Re: [PATCH v3 3/6] crypto: Add Qcom prng driver

Hi Stephan,

Quoted 10 lines · Stephan Mueller

Am Dienstag, 3. Juli 2018, 08:04:31 CEST schrieb Vinod Koul:

drivers/crypto/qcom-rng.c line 94

Quoted 5 lines
drivers/crypto/qcom-rng.c new file +5 -0
+static int qcom_rng_seed(struct crypto_rng *tfm, const u8 *seed,
+			 unsigned int slen)
+{
+	return 0;
+}

One more question: is it not possible to mix in data into the DRNG? I thought it would be possible with the Qualcomm DRBG.

Quoted 4 lines

Note, I am asking because of my /dev/random drop-in-replacement implementation, any RNG from the kernel crypto API can be configured to be used as an output DRNG. Though, this will only work if the DRNG also accepts seed from the software noise sources.

The v1 hardware supports seeding but the register is Read Only for SW and only trusted zone (firmware) can write.

v2 hardware slice does not have seeding. v2 seeding is not accessible to SW.

So in short, it is not available for us to use :(

Signature · 1 line
~Vinod
#18 lore raw

Re: [PATCH v3 6/6] crypto: qcom: Add ACPI support

In reply to Vinod
Quoted 16 lines · Vinod
Quoted 14 lines · Jeffrey Hugo

drivers/crypto/qcom-rng.c static int qcom_rng_remove(struct platform_device *pdev) · line 221

Quoted 8 lines · Vinod Koul
drivers/crypto/qcom-rng.c +8 -0
+#if IS_ENABLED(CONFIG_ACPI)
+static const struct acpi_device_id qcom_rng_acpi_match[] = {
+	{
+		.id = "QCOM8160",
+	},
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, msm_rng_acpi_match);

qcom_rng_acpi_match?
Looks like a copy/paste issue. This causes a build failure for me. I'm trying to see if it works otherwise...

Quoted 5 lines

Ah sorry about that, I though I had fixed it, looks like I missed to fold the fix.

Did it work for you?

It seems to work. Driver compiles, and loads. Still working on the verification.

Signature · 4 lines
Jeffrey Hugo
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.