Skip to contentSkip to conversation

short entropy delay causes RNG hardware error

DISCUSSION Stefano Manni 2 participants 4 messages Aug 5, 2024 – Aug 6, 2024

lore
Share & tools
lore
#0 lore raw

Hello,

on a custom board based on imx6ul once linux starts I see lot of errors like this:

caam_jr 2141000.jr: 2000005b: CCB: desc idx 0: RNG: Hardware error

approximately every 10 seconds. And if I try to read from device the same error occurs:

~# dd if=/dev/hwrng of=/dev/null bs=1 count=1
caam_jr 2141000.jr: 2000005b: CCB: desc idx 0: RNG: Hardware error
dd: /dev/hwrng: Invalid argument

No errors are fired in barebox where the RNG self-test is run succesfully:

rng_self_test: RNG software self-test passed caam [email protected]: Instantiated RNG4 SH0 caam [email protected]: Instantiated RNG4 SH1 caam [email protected]: registering rng-caam

Here [1] I found that enlarging the entroy delay may help so I tried to do the same in barebox by changing RTSDCTL_ENT_DLY_MIN from 3200 to 4800 and it succeded, I no longer see those errors in linux and trying to read from the device works perfectly.

The strange thing is that on another board based on imx6sx I never see those errors.

Is it something new to you?
May we change the delay? On linux-imx 6.6.3 3200 is still used.

Best,
Stefano

[1]
https://lore.kernel.org/all/CAOMZO5D0m1xCfgFifKz1H+oYQSfxsfuZp4U39rPMACmzv1fvjQ@mail.gmail.com/#t

#1 lore raw

Hi Stefano,

Quoted 8 lines · Stefano Manni

Hello,

on a custom board based on imx6ul once linux starts I see lot of errors like this:

caam_jr 2141000.jr: 2000005b: CCB: desc idx 0: RNG: Hardware error

approximately every 10 seconds.

Do you have rngd enabled? You don't need this anymore with a recent enough Linux (>= v6.1 or perhaps earlier).

This doesn't fix the underlying issue of course, but it will save you some CPU time.

Quoted 15 lines

And if I try to read from device the
same error occurs:

~# dd if=/dev/hwrng of=/dev/null bs=1 count=1
caam_jr 2141000.jr: 2000005b: CCB: desc idx 0: RNG: Hardware error
dd: /dev/hwrng: Invalid argument

No errors are fired in barebox where the RNG self-test is run succesfully:

rng_self_test: RNG software self-test passed caam [email protected]: Instantiated RNG4 SH0 caam [email protected]: Instantiated RNG4 SH1 caam [email protected]: registering rng-caam

Quoted 4 lines

Here [1] I found that enlarging the entroy delay may help so I tried to do the same in barebox by changing RTSDCTL_ENT_DLY_MIN from 3200 to 4800 and it succeded, I no longer see those errors in linux and trying to read from the device works perfectly.

That's the correct resolution, yes.

Quoted 2 lines

The strange thing is that on another board based on imx6sx I never see those errors.

There can be quite some variance in the time needed to collect enough entropy, even for SoCs cut from the same wafer, so this is not unusual.

Quoted 1 line

Is it something new to you?

This issue has been there for a long time. Optimally, NXP would store a suitable delay value into the OTP in the factory or at least public suitable initial delay values for their SoCs, but unfortunately they don't.

Quoted 1 line

May we change the delay? On linux-imx 6.6.3 3200 is still used.

The driver starts at 3200 and increases the delay in steps of 40 until it reaches a suitable value. There's a maximum (12800), but it's not used as that would slow down the RNG. Thus the search at probe time for the lowest possible delay value that still allows instantiating the RNG.

Unfortunately, a successful instantiated RNG doesn't necessarily mean that actual runtime usage of the CAAM won't trigger errors.

Increasing RTSDCTL_ENT_DLY_MIN to a value appropriate for your board is thus the way to go. I think it would be appropriate to add a device tree property, so the minimum delay value can be set on a per-board basis.

Cheers,
Ahmad

Quoted 10 lines

Best,
Stefano

[1]
https://lore.kernel.org/all/CAOMZO5D0m1xCfgFifKz1H+oYQSfxsfuZp4U39rPMACmzv1fvjQ@mail.gmail.com/#t

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#2 lore raw

Hello Ahmad,

Quoted 6 lines · Ahmad Fatoum

Do you have rngd enabled? You don't need this anymore with a recent enough Linux (>= v6.1 or perhaps earlier).

This doesn't fix the underlying issue of course, but it will save you some CPU time.

Your speculation that rngd is running comes from the error pops every 10seconds? I cannot see any systemd service related to rng running on my machine. How can I disable it?

Quoted 56 lines
Quoted 17 lines

And if I try to read from device the
same error occurs:

~# dd if=/dev/hwrng of=/dev/null bs=1 count=1 caam_jr 2141000.jr: 2000005b: CCB: desc idx 0: RNG: Hardware
error
dd: /dev/hwrng: Invalid argument

No errors are fired in barebox where the RNG self-test is run succesfully:

rng_self_test: RNG software self-test passed caam [email protected]: Instantiated RNG4 SH0 caam [email protected]: Instantiated RNG4 SH1 caam [email protected]: registering rng-caam

Quoted 6 lines

Here [1] I found that enlarging the entroy delay may help so I tried to
do the same in barebox by changing RTSDCTL_ENT_DLY_MIN from 3200 to 4800 and it succeded, I no longer see those errors in linux and trying
to read from the device works perfectly.

That's the correct resolution, yes.

Quoted 3 lines

The strange thing is that on another board based on imx6sx I never see
those errors.

There can be quite some variance in the time needed to collect enough entropy, even for SoCs cut from the same wafer, so this is not unusual.

Quoted 1 line

Is it something new to you?

This issue has been there for a long time. Optimally, NXP would store a suitable delay value into the OTP in the factory or at least public suitable initial delay values for their SoCs, but unfortunately
they don't.

Quoted 1 line

May we change the delay? On linux-imx 6.6.3 3200 is still used.

The driver starts at 3200 and increases the delay in steps of 40 until
it reaches a suitable value. There's a maximum (12800), but it's not used as that would slow down the RNG. Thus the search at probe time for
the lowest possible delay value that still allows instantiating the RNG.

Unfortunately, a successful instantiated RNG doesn't necessarily mean that
actual runtime usage of the CAAM won't trigger errors.

Quoted 6 lines

Increasing RTSDCTL_ENT_DLY_MIN to a value appropriate for your board is
thus the way to go. I think it would be appropriate to add a device tree
property, so the minimum delay value can be set on a per-board basis.

Got it.

Thank you

#3 lore raw

Hello Stefano,

Quoted 7 lines · Stefano Manni

Hello Ahmad,

Quoted 4 lines · Ahmad Fatoum

Do you have rngd enabled? You don't need this anymore with a recent enough Linux (>= v6.1 or perhaps earlier).

Quoted 6 lines
Quoted 2 lines

This doesn't fix the underlying issue of course, but it will save you some CPU time.

Your speculation that rngd is running comes from the error pops every 10seconds? I cannot see any systemd service related to rng running on my machine. How can I disable it?

Maybe you have haveged running? You could use inotify to see who is opening the HWRNG's device file.

Quoted 8 lines
Quoted 6 lines

Increasing RTSDCTL_ENT_DLY_MIN to a value appropriate for your board is
thus the way to go. I think it would be appropriate to add a device tree
property, so the minimum delay value can be set on a per-board basis.

Got it.

The property would also be appropriate to have in the upstream device tree bindings, but it's ok to add it to barebox only for now. In that case use a barebox, prefix though.

Cheers,
Ahmad

Quoted 4 lines

Thank you

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |