Random Number Generator fixes
v4 cover Random Number Generator fixes
This series aim to fix smccc bind issue and add a list command for RNG devices.
Changelog:
v3 --> v4
- update doc/usage/cmd/rng.rst
v2 --> v3
- remove fallback smc call
- add Fixes tag
v1 --> v2
- check SMCCC_ARCH_FEATURES
- update commit message and rng help info
Weizhao Ouyang (3):
firmware: psci: Fix bind_smccc_features psci check
driver: rng: Fix SMCCC TRNG crash
cmd: rng: Add rng list command
cmd/rng.c | 23 ++++++++++++++++++----- doc/usage/cmd/rng.rst | 14 ++++++++++---- drivers/firmware/psci.c | 5 ++++- drivers/rng/smccc_trng.c | 2 +- include/linux/arm-smccc.h | 6 ++++++ 5 files changed, 39 insertions(+), 11 deletions(-)
Signature · 1 line
2.40.1
PATCH v4 1/3 firmware: psci: Fix bind_smccc_features psci check
According to PSCI specification DEN0022F, PSCI_FEATURES is used to check whether the SMCCC is implemented by discovering SMCCC_VERSION.
---
v3: remove fallback smc call
v2: check SMCCC_ARCH_FEATURES
--- drivers/firmware/psci.c | 5 ++++- include/linux/arm-smccc.h | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-)
drivers/firmware/psci.c +4 -1
@@ -135,10 +135,13 @@ static int bind_smccc_features(struct udevice *dev, int psci_method) PSCI_VERSION_MAJOR(psci_0_2_get_version()) == 0)return 0 ; -if (request_psci_features (ARM_SMCCC_ARCH_FEATURES ) == +if (request_psci_features (ARM_SMCCC_VERSION ) ==PSCI_RET_NOT_SUPPORTED )return 0 ; +if (invoke_psci_fn (ARM_SMCCC_VERSION ,0 ,0 ,0 ) <ARM_SMCCC_VERSION_1_1 ) +return 0 ; +if (psci_method ==PSCI_METHOD_HVC ) pdata->invoke_fn = smccc_invoke_hvc;else
include/linux/arm-smccc.h +6 -0
@@ -55,8 +55,14 @@#define ARM_SMCCC_QUIRK_NONE 0#define ARM_SMCCC_QUIRK_QCOM_A6 1/* Save/restore register a6 */ +#define ARM_SMCCC_VERSION 0x80000000#define ARM_SMCCC_ARCH_FEATURES 0x80000001 +#define ARM_SMCCC_VERSION_1_0 0x10000 +#define ARM_SMCCC_VERSION_1_1 0x10001 +#define ARM_SMCCC_VERSION_1_2 0x10002 +#define ARM_SMCCC_VERSION_1_3 0x10003 +#define ARM_SMCCC_RET_NOT_SUPPORTED ((unsigned long)-1)#ifndef __ASSEMBLY__
Signature · 1 line
2.40.1
Re: [PATCH v4 1/3] firmware: psci: Fix bind_smccc_features psci check
Quoted 4 lines · Weizhao Ouyang
According to PSCI specification DEN0022F,
PSCI_FEATURESis used to check whether the SMCCC is implemented by discoveringSMCCC_VERSION.Signed-off-by Weizhao Ouyang <[email protected]>
Applied to u-boot/next, thanks!
Signature · 1 line
Tom
PATCH v4 2/3 driver: rng: Fix SMCCC TRNG crash
In reply to Weizhao OuyangFix a SMCCC TRNG null pointer crash due to a failed smccc feature binding.
---
v3: add Fixes tag
--- drivers/rng/smccc_trng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rng/smccc_trng.c +1 -1
@@ -166,7 +166,7 @@ static int smccc_trng_probe(struct udevice *dev)struct smccc_trng_priv *priv =dev_get_priv (dev);struct arm_smccc_res res; -if (!(smccc_trng_is_supported (smccc->invoke_fn))) +if (!smccc || !(smccc_trng_is_supported (smccc->invoke_fn)))return -ENODEV ;/* At least one of 64bit and 32bit interfaces is available */
Signature · 1 line
2.40.1
Re: [PATCH v4 2/3] driver: rng: Fix SMCCC TRNG crash
Quoted 6 lines · Weizhao Ouyang
Fix a SMCCC TRNG null pointer crash due to a failed smccc feature binding.
Fixes 53355bb86c25 ("drivers: rng: add smccc trng driver")Reviewed-by Heinrich Schuchardt <[email protected]>Signed-off-by Weizhao Ouyang <[email protected]>
Applied to u-boot/next, thanks!
Signature · 1 line
Tom
PATCH v4 3/3 cmd: rng: Add rng list command
In reply to Weizhao OuyangThe 'rng list' command probes all RNG devices and list those devices that are successfully probed. Also update the help info.
---
v4: update doc/usage/cmd/rng.rst
--- cmd/rng.c | 23 ++++++++++++++++++----- doc/usage/cmd/rng.rst | 14 ++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-)
cmd/rng.c +18 -5
@@ -19,6 +19,22 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])struct udevice *dev;int ret =CMD_RET_SUCCESS ; +if (argc ==2 && !strcmp (argv[1 ],"list" )) { +int idx =0 ; + + uclass_foreach_dev_probe(UCLASS_RNG, dev) { + idx++; +printf ("RNG #%d - %s\n" , dev->seq_, dev->name); + } + +if (!idx) { +log_err ("No RNG device\n" ); +return CMD_RET_FAILURE ; + } + +return CMD_RET_SUCCESS ; + } +switch (argc) {case 1 : devnum =0 ;
@@ -56,12 +72,9 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])return ret; } -U_BOOT_LONGHELP (rng, -"[dev [n]]\n" -" - print n random bytes(max 64) read from dev\n" ); -U_BOOT_CMD ( rng,3 ,0 , do_rng,"print bytes from the hardware random number generator" , - rng_help_text +"list - list all the probed rng devices\n" +"rng [dev] [n] - print n random bytes(max 64) read from dev\n" );
doc/usage/cmd/rng.rst +10 -4
@@ -11,16 +11,22 @@ Synopsis :: - rng [devnum [n]] + rng list + rng [dev] [n] -Description ------------ +rng list +-------- + +List all the probed rng devices. + +rng [dev] [n] +------------- The *rng* command reads the random number generator(RNG) device and prints the random bytes read on the console. A maximum of 64 bytes can be read in one invocation of the command. -devnum +dev The RNG device from which the random bytes are to be read. Defaults to 0.
Signature · 1 line
2.40.1
Re: [PATCH v4 3/3] cmd: rng: Add rng list command
Quoted 5 lines · Weizhao Ouyang
The 'rng list' command probes all RNG devices and list those devices that are successfully probed. Also update the help info.
Reviewed-by Heinrich Schuchardt <[email protected]>Signed-off-by Weizhao Ouyang <[email protected]>
Applied to u-boot/next, thanks!
Signature · 1 line
Tom