[dev][virtio-rng] Introduce virtio-rng driver to seed system prng#506
Merged
Conversation
travisg
reviewed
Apr 25, 2026
travisg
requested changes
Apr 25, 2026
Member
travisg
left a comment
There was a problem hiding this comment.
Looks great! just a few nits and this is lovely. Thanks!
| int virtio_pci_init() { | ||
| LTRACE_ENTRY; | ||
|
|
||
| constexpr virtio_pci_devices devices[] = { |
Member
There was a problem hiding this comment.
can you also add a virtio-mmio interface for this? Should be pretty easy, can test with the arm64 qemu since it can run with both mmio and PCI virtio interfaces (i think the -C flag switches to PCI from the default mmio)
travisg
reviewed
Apr 25, 2026
| bytes_read = virtio_rng_read(&seed, sizeof(seed)); | ||
|
|
||
| if (bytes_read == sizeof(seed)) { | ||
| srand(seed); |
Member
There was a problem hiding this comment.
reminds me we should implement a better system RNG
Contributor
Author
There was a problem hiding this comment.
I would be glad to help improve the system rng.
If there is anything specific you need help with or any direction you'd like me to explore, just let me know!
Introduces a new virtio-rng driver to fetch entropy from the host in virtualized environments. Additionally, an early boot hook (LK_INIT_LEVEL_TARGET + 1) is added to automatically seed the system's PRNG via srand() when the device is initialized. Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Add initialization dispatch for the virtio-rng device. This registers the transitional (0x1005) and non-transitional (0x1044) virtio-rng device IDs to the virtio PCI bus driver, allowing the bus to probe and initialize the device when discovered. Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Add initialization dispatch for the virtio-rng device on the MMIO. This registers the virtio-rng subsystem device ID (4) to the virtio MMIO driver, allowing platforms that default to MMIO to probe and initialize the hardware entropy source. Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Add dev/virtio/rng to the module dependencies for the qemu-virt-arm platform. This allows the system to automatically fetch hardware entropy and seed the PRNG during the early boot process. Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
0fd620e to
96b5782
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces a new virtio-rng driver to fetch hardware entropy from the host in virtualized environments.
Additionally, an early boot hook is implemented to automatically fetch entropy and seed the system's prng via srand() after the device is initialized.