Repository navigation
hwrng: nvt-rng: set a quality so the core feeds the entropy pool - #336
Conversation
The driver registers its hwrng with no quality. The hw_random core starts the hwrng fill thread only when the selected generator has a quality above zero or rng_core.default_quality is set, and that thread is the only path that credits generator output to the entropy pool. With a quality of zero the kernel never reads the generator on its own, and a system with no saved seed waits for interrupt entropy. On a quiet board the pool stays uninitialised, getrandom() blocks, and services that need random numbers at start, such as dropbear and majestic, never open their ports. Set the quality to 500, which credits about half of the bits read. The block is a ring oscillator followed by a CASR and a post-processing stage. The Novatek sources give no entropy rate for it, and the driver reads the data register back to back with no pacing. The block offers no per-word handshake to pace on. Measured on hardware, RNG_TDES_DONE is set in about one control register read in ten, clears by itself whether or not the data register is read, and is found clear after the block has been idle for milliseconds, while 800000 data words read back to back in four runs, most of them with the bit clear, contain no repeated neighbour. The other drivers in this tree that set a quality use 900 to 1000, so half credit is a conservative figure for a generator with no documented rate. The lower value costs nothing at boot, because the first reads go to crng_fast_load() whatever the credit and the pool is ready a few milliseconds after the driver registers. Tested on a Reolink E340 (NT98566) started by kexec with no rng_core parameter. The hwrng thread runs, "random: crng init done" is logged at 0.74 s, 10 ms after the driver registers, and both RTSP streams deliver. In QEMU with a model of the generator and a root filesystem with no saved seed, the pool is ready at 0.12 s and the streamer serves video. The same image with the unpatched kernel has not initialised the pool after 170 s. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR Summary by QodoCredit Novatek hardware RNG output to the entropy pool
AI Description
Merge Risk
|
Code Review by Qodo
1. Switching entropy sources can freeze the system
|
@qodo-free-for-open-source-projects the path you describe is in |
You're right that the deadlock needs a second, zero-quality hwrng to switch to, and this board has only one. The trigger is in On this hardware (one registered device, Options for
|
|
@qodo-free-for-open-source-projects Checked both paths in this tree's |
I can't mark finding 1 as deferred yet. The findings catalog for this PR is empty, so I have no stable ID to pass to the dismiss tool. Could you confirm the finding is the one titled "Switching entropy sources can freeze the system" in the published review ( Your analysis covers the single-generator case. The finding's trigger is a switch to a zero-quality generator. If a second generator with quality 0 is registered and selected through sysfs, or a fallback lands on one, the stop-under-mutex path could still be reached. You may want to note that scope in the deferral, or confirm that a zero-quality generator can't be registered alongside this one. |
openipc-ai
left a comment
There was a problem hiding this comment.
Approving. Three things in its favour beyond what the commit message says:
- Mainline already trusts this driver fully. Since 16bdbae39428 ("hwrng: core - treat default_quality as a maximum and default to 1024", v6.2), a hwrng that registers no quality gets 1024. On 4.19 the same driver gets 0, and the fill thread never starts. 500 is more cautious than what current kernels would do.
- We measured the generator independently on another NT98566 (an SC501AI board, 2026-11-27, during #330). We loaded
nvt-rngas a module and read a 4 MiB sample from/dev/hwrngat about 2.5 MB/s. It had 119 repeated 32-bit words where the birthday bound expects 128, and the chi² was unremarkable. That fits your "no repeated neighbour" result and rules out a short-period output. It does not measure entropy, but it is the right shape for half credit. - It reaches a shipped image.
nt98566.nand.config(firmware'snt98566_ultimate) setsCONFIG_HW_RANDOM_NVT=y, so this changes that image's boot, for the better: crng readiness stops depending on interrupt timing.
The "before" is shown in QEMU only. That proves the mechanism, but an unpatched boot log from the E340 (the crng init done time, or its absence) would make the hardware case complete if you have one. This doesn't block the merge.
The driver registers its hwrng with no quality, so the hw_random core never starts its fill thread and the generator is never used to initialise the entropy pool. A system with no saved seed then waits for interrupt entropy. On a quiet board
getrandom()blocks, and dropbear and majestic never open their ports.This sets the quality to 500. The Novatek sources give no entropy rate for the block, and it offers no per-word handshake to pace reads on: measured on hardware,
RNG_TDES_DONEis set in about one control-register read in ten, clears by itself whether or not the data register is read, and is found clear after the block has been idle for milliseconds. Half credit is a conservative figure next to the 900 to 1000 other drivers in this tree use.Tested on a Reolink E340 (NT98566) started by kexec: the hwrng thread runs,
crng init doneis logged at 0.74 s, and both RTSP streams deliver. In QEMU, on a root filesystem with no saved seed, the pool is ready at 0.12 s; the same image with the unpatched kernel has not initialised it after 170 s.Not changed here: the clock handling in cleanup and the probe error paths is incomplete.
🤖 Generated with Claude Code