Skip to content

End-to-end network for Arm/virtio#47

Merged
jserv merged 5 commits into
masterfrom
arm-virtio-net
Apr 28, 2026
Merged

End-to-end network for Arm/virtio#47
jserv merged 5 commits into
masterfrom
arm-virtio-net

Conversation

@jserv

@jserv jserv commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Summary by cubic

Enable end-to-end virtio-net on arm64: proper FDT IRQ wiring, guest kernel config, and simple host/guest helpers so the guest can ping the host over a dedicated kvmbr0 link. Also updates docs and adds build prerequisites.

  • New Features

    • Wire virtio-net interrupts in the arm64 FDT and only describe devices that are actually registered.
    • Enable networking in configs/linux-arm64.config (CONFIG_NET, CONFIG_VIRTIO_NET, etc.) and CONFIG_POSIX_TIMERS so ping works.
    • Add scripts/set-host-bridge.sh and scripts/set-guest-route.sh to bring up a host-only bridge (kvmbr0) and guest IP for quick testing.
    • Expand README with flex, bison, libelf-dev prerequisites and a step-by-step virtio-net test, plus corrected Linux x86 boot protocol link.
  • Bug Fixes

    • Gate FDT interrupt-map entries on registered PCI devices to avoid phantom devices if -d or TAP setup is missing.
    • Call virtio_blk_init() on arm64 startup to ensure clean state for the registration gate.

Written for commit 430867a. Summary will update on new commits. Review in cubic

jserv and others added 5 commits April 29, 2026 03:06
The kernel documentation was reorganized and previous URL now returns
404. Point the reference to the current location under arch/x86/.
Building the in-tree Linux guest pulls in the kernel's build
dependencies (flex, bison, libelf headers), which are easy to miss on
a fresh setup. Mention them with a Debian/Ubuntu install line as an
example so users can map the package names onto their distribution.

Split the "Usage" section into "Start Emulator" and "Exit Emulator"
subsections. The exit instruction was previously buried below the
command line and is easier to find with its own heading; "Exit"
matches the actual semantics, since Ctrl-A x leaves the KVM_RUN loop
rather than pausing the guest.

Co-authored-by: Otis Chung <p76124605@gs.ncku.edu.tw>
VIRTIO_NET_IRQ was added to desc.h in 80b2677, which silenced the
arm64 link error but left the FDT generator describing a single PCI
device. With virtio-blk the only entry in interrupt-map, the guest
kernel cannot resolve INTA# for the virtio-net function and skips the
device when vm_enable_net brings it up.

Add a second interrupt-map entry pointing virtio-net at
VIRTIO_NET_IRQ. The IRQ value is a SPI offset programmed by the host;
the GIC adds the SPI base of 32, so this becomes global interrupt 34.
The number is arbitrary, only uniqueness against other emulated
devices matters.

Gate each entry on pci_dev_is_registered() so the FDT only describes
devices whose PCI bar/config space was actually set up. This preserves
the best-effort contract of vm_enable_net (failure logged, boot
continues): without the gate, a missing -d disk image or a TUN/TAP
open failure would leave the matching virtio_*_dev struct in its
default state and we would publish a zero pci_hi entry for a device
the guest cannot find. The check uses config_dev.len, which is set
inside pci_dev_register() to PCI_CFG_SPACE_SIZE.

For the gate to be reliable on arm64, also call virtio_blk_init() in
vm_arch_init_platform_device(); x86 already does. Without that memset
the struct is left as stack garbage on boots without -d, and
config_dev.len could match PCI_CFG_SPACE_SIZE by chance.

Co-authored-by: Otis Chung <p76124605@gs.ncku.edu.tw>
Turn on the bits the guest kernel needs to bring up the host-supplied
virtio-net device:
  CONFIG_NET, CONFIG_INET            core IPv4 stack
  CONFIG_IP_MULTICAST                NDP/IGMP frames seen during ifup
  CONFIG_IP_PNP, CONFIG_IP_PNP_DHCP  configure-on-boot if requested
  CONFIG_NETDEVICES                  netdev infrastructure
  CONFIG_VIRTIO                       virtio transport
  CONFIG_VIRTIO_NET                  the virtio-net driver itself

CONFIG_POSIX_TIMERS is enabled in the same patch because the only
networking smoke test we document is ping(8), which calls
timer_create()/timer_settime() to drive its retransmit interval.
Without POSIX timers ping aborts before sending the first echo
request, so connectivity verification has to live with this config
flip.

Co-authored-by: Otis Chung <p76124605@gs.ncku.edu.tw>
Provide two helpers under scripts/ plus a README walkthrough that
exercises the guest virtio-net interface end to end.

set-host-bridge.sh creates a dedicated `kvmbr0` (not `br0`) with
10.0.0.1/24, enslaves the kvm-host TAP, and brings both interfaces
up. Earlier drafts unconditionally `ip link delete br0` before
recreating it -- that would silently destroy a libvirt/Docker/etc.
bridge sharing the name. The script now refuses to touch a non-bridge
interface holding its target name, reuses an existing bridge instead
of recreating, and never installs a default route via 10.0.0.1
(doing so would replace the host's real default gateway and cut off
external connectivity). Both the TAP and bridge names are positional
arguments because kvm-host's TUNSETIFF "tap%d" picks the first free
tapN, which is not always tap0 if the host already runs other TAPs.

set-guest-route.sh now uses `ip addr replace` for idempotency and
deliberately does not install a default route. The host bridge does
not forward traffic, so a default via 10.0.0.1 would silently
black-hole everything outside 10.0.0.0/24; users who want internet
egress have to add NAT and forwarding on the host themselves.

The README "Test the Guest virtio-net Interface" section walks
through the new bridge name, explains the TAP-naming caveat, and
points out the NAT/forwarding requirement for off-bridge traffic.

Co-authored-by: Otis Chung <p76124605@gs.ncku.edu.tw>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

@jserv jserv merged commit 20bf18f into master Apr 28, 2026
11 checks passed
@jserv jserv deleted the arm-virtio-net branch April 28, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant