Migrate virtio-net from semu#748
Open
Charlie-Tsai1123 wants to merge 1 commit into
Open
Conversation
jserv
reviewed
Jul 1, 2026
Contributor
There was a problem hiding this comment.
Benchmarks
Details
| Benchmark suite | Current: 56a5c0b | Previous: b775142 | Ratio |
|---|---|---|---|
Dhrystone |
1576.667 DMIPS |
1585.333 DMIPS |
1.01 |
CoreMark |
1115.023 iterations/sec |
1120.589 iterations/sec |
1.00 |
This comment was automatically generated by workflow using github-action-benchmark.
7658d0a to
b775142
Compare
Contributor
|
I’m not the original author of the virtio-net device. Please check the commit history via |
Contributor
Author
|
Thanks for the clarification, and sorry for the incorrect attribution. |
This commit migrates virtio-net support from semu with the following modifications: 1. Implement virtio-net device model The virtio-net 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. The device currently supports a TAP-backend network interface and handles basic RX/TX virtqueue processing for guest network packets. 2. Add TAP backend helper Introduce netdev.c and netdev.h to provide host-side TAP device access. Future work may support other host-side backend. 3. Handle virtio-net header processing For guest TX, the device skips the virtio-net header before writing the Ethernet frame to the TAP backend. For guest RX, the device prepends a virtio-net header before copying the received Ethernet frame into the guest-provided RX buffer. 4. Implement MMIO_VIRTIONET Add MMIO routing for virtio-net and connect the device interrupt status to the PLIC, following the existing virtio-blk and virtio-rng interrupt update model. 5. Introduce new argument '-x vnet:<tap>' When virtio-net 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. Support coexistence with virtio-blk and virtio-rng Update the dynamic virtio-mmio device tree allocation path so virtio-net can coexist with existing virtio-blk and virtio-rng devices without reusing MMIO base addresses or IRQs. 7. Use virtio-net state Unlike semu's device integration model, rv32emu stores the virtio-net state in vm_attr_t so MMIO routing, interrupt routing, and device cleanup can access the same device instance. The emulator should be run with sudo when using the virtio-net TAP backend. This implementation is based on semu's virtio-net device, originally introduced by Jserv. Co-authored-by: Jim Huang <jserv@biilabs.io>
b775142 to
56a5c0b
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-net support from semu and follows the existing virtio-blk and virtio-rng integration in rv32emu.
The implementation adds a TAP-backed virtio-net device model for system emulation mode, including MMIO register handling, queue setup, feature negotiation, RX/TX virtqueue handling, virtio-net header processing, interrupt delivery through the PLIC, dynamic DTB node creation, and a runtime option for enabling the device.
Implementation notes
virtio,mmioDTB node for virtio-net.sudoor equivalent permissions when using the TAP backend.Test
Build:
After run rv32emu with
-x vnet:taprv32emu would build TAP, so host linux doesn't need to build TAP again.Host TAP setup:
Guest device verification:
readlink /sys/bus/virtio/devices/virtio0/driver ip link set eth0 up ip addr add 192.168.100.2/24 dev eth0 ip addr show eth0 ping -c 3 192.168.100.1Expected Result:
Summary by cubic
Adds a TAP-backed
virtio-netdevice for system emulation. It’s wired through VirtIO-MMIO and the PLIC, auto-added to the DTB, and enabled via-x vnet:tapfor guest networking.New Features
virtio,mmiowith unique MMIO base/IRQ; coexists withvirtio-blk/virtio-rng.Migration
-x vnet:tap; Linux hosts only. Use elevated privileges to create TAP. Bring the host TAP up and assign an IP if needed.Written for commit 56a5c0b. Summary will update on new commits.