Migrate virtio-rng from semu#747
Open
Charlie-Tsai1123 wants to merge 1 commit into
Open
Conversation
cb52b1c to
fe0e805
Compare
Contributor
|
Could you add me as a co-author in the commit? AFAIK, Thanks. |
fe0e805 to
60f74c0
Compare
Author
|
Thanks for the reminder. |
jserv
reviewed
May 26, 2026
Contributor
There was a problem hiding this comment.
Benchmarks
Details
| Benchmark suite | Current: efcf2f8 | Previous: 60f74c0 | Ratio |
|---|---|---|---|
Dhrystone |
1454.667 DMIPS |
1769 DMIPS |
1.22 |
CoreMark |
1060.317 iterations/sec |
1153.875 iterations/sec |
1.09 |
This comment was automatically generated by workflow using github-action-benchmark.
This commit migrates virtio-rng support from semu and follows the existing virtio-blk implementation, with the following modifications: 1. Implement virtio-rng device model The virtio-rng implementation follows the VirtIO-MMIO flow used by virtio-blk, including feature negotiation, queue setup, QueueNotify handling, used ring update, interrupt status, and device status reset. 2. Rename virtio_rng_reg_read/write to virtio_rng_read/write In semu, virtio_rng_read/write first checks the memory access width and then calls virtio_rng_reg_read/write for register handling. In rv32emu, MMIO accesses are already routed to each device by system.h, following the existing virtio-blk model. Therefore, the migrated virtio-rng device exposes virtio_rng_read/write as the register handlers directly. 3. Implement MMIO_VIRTIORNG Add MMIO routing for virtio-rng and connect the device interrupt status to the PLIC, following the existing virtio-blk interrupt update model. 4. Implement vrng_new() and vrng_delete() These functions align virtio-rng with the allocation and cleanup. 5. Introduce new argument '-x vrng' for virtio-rng The new option enables virtio-rng in system emulation mode. When it is enabled, rv32emu dynamically creates a virtio-mmio node in the generated device tree and assigns an MMIO base address and IRQ for the device. 6. Use virtio-rng state Unlike semu's global rng_fd, rv32emu stores the virtio-rng state in vm_attr_t so MMIO routing, interrupt routing, and device cleanup can access the same device instance. 7. Enable virtio-rng in the guest Linux configuration Enable the Linux hardware random framework and virtio-rng driver so the guest can bind the device and expose /dev/hwrng. Co-authored-by: Shengwen Cheng <shengwen1997.tw@gmail.com>
60f74c0 to
efcf2f8
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.
Summary
This PR migrates virtio-rng support from semu while following the existing virtio-blk integration in rv32emu.
The implementation adds a virtio-rng device model, MMIO routing, PLIC interrupt integration, dynamic DTB node creation, and a new
-x vrngoption for system emulation mode. The guest Linux configuration is also updated to enable the virtio-rng driver so/dev/hwrngcan be exposed inside the guest.Implementation notes
virtio-rngMMIO register handling, feature negotiation, queue setup,QueueNotifyhandling, used ring update, interrupt status handling, and device reset handling.MMIO_VIRTIORNGrouting and update virtio-rng interrupts through the PLIC.vrng_new()/vrng_delete()following the existing device lifecycle style.-x vrngto enable virtio-rng at runtime.virtio,mmioDTB node for virtio-rng when enabled.Test
Build and basic check
Guest Verification
Also tested virtio-rng together with virtio-blk:
Guest Verification:
Summary by cubic
Adds virtio-rng to system emulation, exposing a guest
/dev/hwrng. Implements MMIO routing, PLIC interrupts, a DTBvirtio,mmionode with assigned MMIO base and IRQ, and a new-x vrngflag; coexists withvirtio-blk.New Features
MMIO_VIRTIORNGwith PLIC updates (emu_update_vrng_interrupts).virtio-blknodes (assigns MMIO base and IRQ).-x vrngCLI flag; guest config enablesCONFIG_HW_RANDOMandCONFIG_HW_RANDOM_VIRTIO.Bug Fixes
vblk_mmio_max_hi = base + cnt - 1) to ensure proper address matching when virtio-rng is enabled.Written for commit efcf2f8. Summary will update on new commits. Review in cubic