-
Notifications
You must be signed in to change notification settings - Fork 29
arm64: Enable virtio-net and add network scripts #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
ebeb284
60835d6
1e84059
725a026
82ff20a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,8 @@ make check | |
|
||
## Usage | ||
|
||
### Start Emulator | ||
|
||
``` | ||
build/kvm-host -k bzImage [-i initrd] [-d disk-image] | ||
``` | ||
|
@@ -42,8 +44,63 @@ containing concatenated `bootsect.o + setup.o + misc.o + piggy.o`. `initrd` is t | |
initial RAM disk image, which is an optional argument. | ||
`disk-image` is the path to disk image which can be mounted as a block device via virtio. For the reference Linux guest, ext4 filesystem is used for disk image. | ||
|
||
### Stop Emulator | ||
|
||
To exit kvm-host, press "Ctrl-A", release both keys, and then press "x". | ||
|
||
### Enable Static Route to Test the Guest VirtIO-Net Interface | ||
|
||
1. Start the kvm-host emulator. Once initialized, the TUN/TAP interface (for example, `tap0`) is visible in the output of `ip a`. The following is sample output from the host: | ||
|
||
```shell | ||
❯ ip a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
1: lo: ... | ||
2: eth0: ... | ||
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 | ||
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff | ||
altname xxxxxxxxxxxxxxx | ||
inet 192.168.x.x/24 brd 192.168.x.255 scope global dynamic noprefixroute wlan0 | ||
valid_lft xxxxxxsec preferred_lft xxxxxxsec | ||
inet6 ... | ||
11: tap0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 | ||
link/ether 5a:1d:bd:2d:7c:1f brd ff:ff:ff:ff:ff:ff | ||
``` | ||
|
||
2. Execute the shell script `./scripts/set-host-bridge.sh`, which configures a bridge by assigning the default route to 10.0.0.1, integrating the TUN/TAP interface into the bridge, and activating the network interfaces. The following is sample output of `ip a` from the host: | ||
|
||
```shell | ||
❯ ip a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. Use |
||
... | ||
11: tap0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 | ||
link/ether 5a:1d:bd:2d:7c:1f brd ff:ff:ff:ff:ff:ff | ||
12: br0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 | ||
link/ether d6:92:97:85:e8:7c brd ff:ff:ff:ff:ff:ff | ||
inet 10.0.0.1/24 scope global br0 | ||
valid_lft forever preferred_lft forever | ||
``` | ||
|
||
3. Copy the commands from `scripts/set-guest-route.sh` into the guest environment and execute them. Below is a sample `ip a` output from the guest: | ||
|
||
```shell | ||
~ # ip a | ||
1: lo: <LOOPBACK> mtu 65536 qdisc noop qlen 1000 | ||
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 | ||
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 | ||
link/ether c2:5a:92:87:97:42 brd ff:ff:ff:ff:ff:ff | ||
inet 10.0.0.2/24 scope global eth0 | ||
valid_lft forever preferred_lft forever | ||
inet6 fe80::c05a:92ff:fe87:9742/64 scope link | ||
valid_lft forever preferred_lft forever | ||
3: sit0@NONE: <NOARP> mtu 1480 qdisc noop qlen 1000 | ||
link/sit 0.0.0.0 brd 0.0.0.0 | ||
``` | ||
|
||
4. Test guest network connectivity by pinging the configured default gateway. | ||
|
||
```bash | ||
ping 10.0.0.1 | ||
``` | ||
|
||
## License | ||
|
||
`kvm-host` is released under the BSD 2 clause license. Use of this source code is governed by | ||
|
@@ -52,7 +109,7 @@ a BSD-style license that can be found in the LICENSE file. | |
## References | ||
* [kvmtool](https://github.com/kvmtool/kvmtool) | ||
* [KVM (Kernel-based Virtual Machine) API](https://www.kernel.org/doc/Documentation/virtual/kvm/api.txt) | ||
* [The Linux/x86 Boot Protocol](https://www.kernel.org/doc/html/latest/x86/boot.html) | ||
* [The Linux/x86 Boot Protocol](https://www.kernel.org/doc/html/latest/arch/x86/boot.html) | ||
* [Using the KVM API](https://lwn.net/Articles/658511/) | ||
* [gokvm](https://github.com/bobuhiro11/gokvm) | ||
* [KVM Host in a few lines of code](https://zserge.com/posts/kvm/) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ CONFIG_CC_OPTIMIZE_FOR_SIZE=y | |
# CONFIG_MULTIUSER is not set | ||
# CONFIG_SYSFS_SYSCALL is not set | ||
# CONFIG_FHANDLE is not set | ||
# CONFIG_POSIX_TIMERS is not set | ||
CONFIG_POSIX_TIMERS=y | ||
# CONFIG_BUG is not set | ||
# CONFIG_BASE_FULL is not set | ||
# CONFIG_FUTEX is not set | ||
|
@@ -66,3 +66,15 @@ CONFIG_EXT4_FS=y | |
# CONFIG_DEBUG_MISC is not set | ||
# CONFIG_FTRACE is not set | ||
# CONFIG_STRICT_DEVMEM is not set | ||
CONFIG_NET=y | ||
CONFIG_INET=y | ||
CONFIG_IP_MULTICAST=y | ||
CONFIG_IP_PNP=y | ||
CONFIG_IP_PNP_DHCP=y | ||
CONFIG_NETDEVICES=y | ||
CONFIG_VIRTIO=y | ||
CONFIG_VIRTIO_NET=y | ||
CONFIG_VIRTIO_RING=y | ||
CONFIG_UNIX=y | ||
CONFIG_UNIX_SCM=y | ||
CONFIG_AF_UNIX_OOB=y | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirm if they are needed or not. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ip addr add 10.0.0.2/24 dev eth0 | ||
ip link set eth0 up | ||
ip route add default via 10.0.0.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
sudo ip link delete br0 || true | ||
sudo brctl addbr br0 | ||
sudo ip addr add 10.0.0.1/24 dev br0 | ||
sudo ip route add default via 10.0.0.1 dev br0 | ||
sudo ip link set br0 up | ||
sudo ip link set tap0 master br0 | ||
sudo ip link set tap0 up |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is meant to "stop" the emulation. Instead, the operation is dedicated to "exit" from the execution loop.