Skip to content
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

Add networking UIO driver #137

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2214dda
add UIO net driver
dreamliner787-9 Oct 31, 2024
fadc3a7
place tx and rx fault addr into uio net header
dreamliner787-9 Nov 3, 2024
b7f5fd7
add simple workaround for mismatching sddf version with size vs capac…
dreamliner787-9 Nov 3, 2024
633cedf
allow accepting network interface name as argument instead of hardcode
dreamliner787-9 Nov 3, 2024
616e1c8
potential deadlock in TX signalling protocol
dreamliner787-9 Nov 3, 2024
78dc21c
use a custom SMP network queue library, would not work with stock sdd…
dreamliner787-9 Nov 3, 2024
1ebd9e5
add net uio echo server example
dreamliner787-9 Nov 3, 2024
5e7a3fc
fix compile errot
dreamliner787-9 Nov 4, 2024
7c53857
improve RX performance
dreamliner787-9 Nov 4, 2024
9079f3c
fix RX signalling protocol bug
dreamliner787-9 Nov 4, 2024
5e9d896
install ethtool in rootfs
dreamliner787-9 Nov 4, 2024
3cf969d
turn off HW offloading
dreamliner787-9 Nov 4, 2024
fe93501
improve queue signalling protocol implementation in net uio
dreamliner787-9 Nov 4, 2024
9def4de
add successful bootup log
dreamliner787-9 Nov 4, 2024
9fc6ac3
remove experimental queue library, this should come from sddf instead
dreamliner787-9 Nov 4, 2024
abff80a
revert accidental changes to odroidc4 kernel image readme of simple e…
dreamliner787-9 Nov 4, 2024
835139f
add licence specifier to net uio main.c
dreamliner787-9 Nov 5, 2024
06058d1
update read me
dreamliner787-9 Nov 5, 2024
4472e4a
remove trailing whitespaces
dreamliner787-9 Nov 6, 2024
727a477
fix style issues
dreamliner787-9 Nov 6, 2024
2c97266
move vmm c file to board dir
dreamliner787-9 Nov 6, 2024
08d8235
fix style
dreamliner787-9 Nov 6, 2024
b8fe17e
remove trailing whitespace
dreamliner787-9 Nov 6, 2024
93b9f2f
improve net uio driver logging
dreamliner787-9 Nov 17, 2024
ad65f3e
ci: build net uio example system
dreamliner787-9 Nov 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ci/examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ simulate_zig() {
./ci/buildroot_login.exp ${BUILD_DIR}/bin/loader.img
}

build_net() {
BOARD=$1
CONFIG=$2
echo "CI|INFO: building net example via Make with board: $BOARD and config: $CONFIG"
BUILD_DIR="${PWD}/build/examples/net/make/${BOARD}/${CONFIG}"
mkdir -p ${BUILD_DIR}
make -C examples/net -B \
BUILD_DIR=${BUILD_DIR} \
MICROKIT_CONFIG=${CONFIG} \
MICROKIT_BOARD=${BOARD} \
MICROKIT_SDK=${SDK_PATH}
}

build_simple_make "qemu_virt_aarch64" "debug"
simulate_simple_make "qemu_virt_aarch64" "debug"
build_simple_make "qemu_virt_aarch64" "release"
Expand Down Expand Up @@ -156,5 +169,8 @@ build_virtio "qemu_virt_aarch64" "release"
# build_virtio "odroidc4" "debug"
# build_virtio "odroidc4" "release"

build_net "odroidc4" "debug"
build_net "odroidc4" "release"

echo ""
echo "CI|INFO: Passed all VMM tests"
59 changes: 59 additions & 0 deletions examples/net/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#
# Copyright 2022, UNSW
#
# SPDX-License-Identifier: BSD-2-Clause
#

BUILD_DIR ?= build
export MICROKIT_CONFIG ?= debug

ifeq ($(strip $(MICROKIT_SDK)),)
$(error MICROKIT_SDK must be specified)
endif
export override MICROKIT_SDK:=$(abspath ${MICROKIT_SDK})


ifeq ($(strip $(TOOLCHAIN)),)
TOOLCHAIN := aarch64-none-elf
export TOOLCHAIN := aarch64-none-elf
export LIBC := $(dir $(realpath $(shell aarch64-none-elf-gcc --print-file-name libc.a)))
endif

ifeq ($(strip $(MICROKIT_BOARD)), odroidc4)
export DRIV_DIR := meson
export UART_DRIV_DIR := meson
export TIMER_DRV_DIR := meson
export CPU := cortex-a55
else
$(error Unsupported MICROKIT_BOARD given)
endif

export BUILD_DIR:=$(abspath ${BUILD_DIR})
export MICROKIT_SDK:=$(abspath ${MICROKIT_SDK})

export CC := $(TOOLCHAIN)-gcc
export CC_USERLEVEL := zig cc
export LD := $(TOOLCHAIN)-ld
export AS := $(TOOLCHAIN)-as
export AR := $(TOOLCHAIN)-ar
export DTC := dtc
export RANLIB := $(TOOLCHAIN)-ranlib
export MICROKIT_TOOL ?= $(MICROKIT_SDK)/bin/microkit
export SDDF=$(abspath ../../dep/sddf)
export LIBVMM=$(abspath ../../)

export ECHO_INCLUDE:=$(SDDF)/examples/echo_server/include

IMAGE_FILE := $(BUILD_DIR)/loader.img
REPORT_FILE := $(BUILD_DIR)/report.txt

all: ${IMAGE_FILE}

qemu ${IMAGE_FILE} ${REPORT_FILE} clean clobber: ${BUILD_DIR}/Makefile FORCE
${MAKE} -C ${BUILD_DIR} MICROKIT_SDK=${MICROKIT_SDK} $(notdir $@)

${BUILD_DIR}/Makefile: echo.mk
mkdir -p ${BUILD_DIR}
cp echo.mk $@

FORCE:
86 changes: 86 additions & 0 deletions examples/net/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!--
Copyright 2024, UNSW
SPDX-License-Identifier: CC-BY-SA-4.0
-->

# UIO Networking example

This example show case an Ethernet driver VM running with sDDF's echo server on the Odroid C4. It is a shallow copy that only contains files that needs to be modified to accomodate the Ethernet driver VM. This is a summary of modified files, relative to `/dep/sddf/examples/echo_server/`:
- `board/odroidc4/echo_server.system`: swapped out native Ethernet driver for VM.
- `include/serial_config/serial_config.h`: Hooked VM to serial TX virt.
- `Makefile`: specified `zig cc` for Linux userspace drivers compilation and added libvmm related paths.
- `echo.mk`: swapped out native Ethernet driver build step for VM build steps.

The basic idea is we have a userspace program in Linux that converts sDDF's network TX/RX into corresponding syscalls in a Linux socket.
- The sDDF network control, data regions and notification from virtualisers are mapped into Linux userspace via UIO.
- A promiscuous socket is opened to sniff all incoming frames. When a frame comes through from the socket, we enqueue the data into the appropriate sDDF queues and fault on a pre-determined address so the VMM can notify the RX virtualiser.
- When a client wants to transmit data, we will get TX virt notifications via UIO, then we simply write the data out into the socket.

Even though we already have a native Ethernet driver for Odroid C4, this example is still useful as it could be used to provide Ethernet driver VM on new boards or further developed into a WiFi/Cellular/Bluetooth driver VM.

The example currently works on the following platforms:
* HardKernel Odroid-C4

Things to note when using the network UIO driver:
- You need to map in the control queues as uncached in the guest and native virtualisers. This is because Linux treats UIO regions as device memory thus map them uncached to userspace.

## Compilation
To compile this example, run:
```
make MICROKIT_SDK=<absolute path to 1.4.1 SDK> MICROKIT_BOARD=odroidc4 MICROKIT_CONFIG=release
```

### Boot
On a successful boot, your console will look like this:
```
Starting syslogd: OK
Starting klogd: OK
Running sysctl: OK
Saving random seed: [ 4.917610] random: crng init done
OK
Starting network: OK
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
link/ether 00:1e:06:4a:35:e4 brd ff:ff:ff:ff:ff:ff
[ 5.149624] meson8b-dwmac ff3f0000.ethernet eth0: PHY [mdio_mux-0.0:00] driver [RTL8211F Gigabit Ethernet] (irq=POLL)
[ 5.150295] meson8b-dwmac ff3f0000.ethernet eth0: Register MEM_TYPE_PAGE_POOL RxQ-0
[ 5.157634] meson8b-dwmac ff3f0000.ethernet eth0: No Safety Features support found
[ 5.157800] meson8b-dwmac ff3f0000.ethernet eth0: PTP not supported by HW
[ 5.158231] meson8b-dwmac ff3f0000.ethernet eth0: configuring for phy/rgmii link mode
[ 10.312812] meson8b-dwmac ff3f0000.ethernet eth0: Link is Up - 1Gbps/Full - flow control off
ethtool -K eth0 gso off
ethtool -K eth0 gro off
ethtool -K eth0 tx off rx off
UIO(NET): *** Starting up
UIO(NET): *** Network interface: eth0
UIO(NET): *** Setting up raw promiscuous socket
[ 13.203873] device eth0 entered promiscuous mode
UIO(NET): *** Creating epoll
UIO(NET): *** Binding socket to epoll
UIO(NET): *** Mapping in sDDF control and data queues
UIO(NET): *** Total control + data size is 0xe00000
UIO(NET): *** Setting up sDDF control and data queues
UIO(NET): *** rx_free_drv = 0xffff8d905000
UIO(NET): *** rx_active_drv = 0xffff8db05000
UIO(NET): *** tx_free_drv = 0xffff8dd05000
UIO(NET): *** tx_active_drv = 0xffff8df05000
UIO(NET): *** rx_data_drv = 0xffff8e105000
UIO(NET): *** tx_data_drv cli0 = 0xffff8e305000
UIO(NET): *** tx_data_drv cli1 = 0xffff8e505000
UIO(NET): *** Setting up UIO TX and RX interrupts from VMM "incoming"
UIO(NET): *** Binding UIO TX and RX incoming interrupts to epoll
UIO(NET): *** Setting up UIO data passing between VMM and us
UIO(NET): *** RX paddr: 0x8000000
UIO(NET): *** TX cli0 paddr: 0x8200000
UIO(NET): *** TX cli1 paddr: 0x8600000
UIO(NET): *** Setting up UIO TX and RX interrupts to VMM "outgoing"
UIO(NET): *** Waiting for RX virt to boot up
UIO(NET): *** All initialisation successful, now sending all pending TX active before we block on events
UIO(NET): *** All pending TX active have been sent thru the raw sock, entering event loop now.
UIO(NET): *** You won't see any output from UIO Net anymore. Unless there is a warning or error.
LWIP|NOTICE: DHCP request for client0 returned IP address: 172.16.1.218
LWIP|NOTICE: DHCP request for client1 returned IP address: 172.16.1.219
```

Though the MAC, IP and memory addreses would be different of course. There will be delay in the tens of seconds between the Linux userspace network driver initialisation and LWIP DHCP completion. This is due to all the components being able to initialise first before the guest can get to userspace. So LWIP will send many DHCP requests without success, with increasing timeout for each request.
34 changes: 34 additions & 0 deletions examples/net/board/odroidc4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--
Copyright 2024, UNSW
SPDX-License-Identifier: CC-BY-SA-4.0
-->

# Odroid-C4 images

## Linux kernel

### Details
* Image name: `linux`
* Config name: `linux_config`
* Git remote: https://github.com/torvalds/linux.git
* Tag: v6.1 (commit hash: `830b3c68c1fb1e9176028d02ef86f3cf76aa2476`)
* Toolchain: `aarch64-none-elf`
* Version: GNU Toolchain for the A-profile Architecture 10.2-2020.11 (arm-10.16)) 10.2.1 20201103

You can also get the Linux config used after booting by running the following
command in userspace: `zcat /proc/config.gz`.

### Instructions for reproducing

```
git clone --depth 1 --branch v6.1 https://github.com/torvalds/linux.git
cp linux_config linux/.config
make -C linux ARCH=arm64 CROSS_COMPILE=aarch64-none-elf- linux_config all -j$(nproc)
```

The path to the image will be: `linux/arm64/boot/Image`.

## Buildroot RootFS image

Note that buildoot currently does not list a configuration for OdroidC4 so we just
use the OdroidC2 configuration.
Loading
Loading