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

[WIP] Virtio backend #56

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
DEBUG ?= false
LARGE_MEM ?= true
IXGBE ?= true
VIRTIO_NET ?= false
VIRTIO_NET ?= true
VIRTIO_BLOCK ?= false

ifndef NO_DEFAULT_FLAGS
Expand Down Expand Up @@ -72,6 +72,8 @@ domain_list := $(addprefix domains/build/, \
ixgbe \
virtio_net \
virtio_block \
virtio_backend \
virtio_net_mmio \
nvme \
tpm \
bdev_shadow \
Expand Down Expand Up @@ -204,7 +206,7 @@ idl_generation: tools/redIDL
then echo "redIDL not found. Maybe you want to do 'git submodule init && git submodule update' then try again?"; \
exit -1; \
fi
make -C interface
# make -C interface

.PHONY: domains
domains: idl_generation $(xv6fs_img) memops
Expand Down
77 changes: 77 additions & 0 deletions domains/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions domains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ members = [
"sys/driver/tpm",
"sys/driver/virtio_net",
"sys/driver/virtio_block",
"sys/driver/virtio_backend",
"sys/driver/virtio_net_mmio",
"sys/init",
"usr/proxy",
"usr/shadow/bdev",
Expand Down
30 changes: 30 additions & 0 deletions domains/sys/driver/virtio_backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "virtio_backend"
version = "0.1.0"
authors = ["RedLeaf Team"]
edition = "2018"

[dependencies]
libsyscalls = { path = "../../../../lib/core/libsyscalls" }
libtime = { path = "../../../../lib/core/libtime" }
console = { path = "../../../../lib/core/console" }
malloc = { path = "../../../../lib/core/malloc" }
spin = { path = "../../../../lib/core/spin-rs" }

# Interfaces
syscalls = { path = "../../../../lib/core/interfaces/syscalls" }
pci_driver = { path = "../../../../lib/core/interfaces/dev/pci/pci_driver" }
protocol = { path = "../../../../lib/core/interfaces/protocol" }
platform = { path = "../../../../lib/core/interfaces/platform" }
interface = { path = "../../../../interface/generated" }

virtio_net_mmio_device = { path = "../../../../lib/devices/virtio_net_mmio" }
virtio_net_mmio = { path = "../virtio_net_mmio" }
virtio_backend_trusted = { path = "../../../../lib/devices/virtio_backend" }

virtio_device = { path = "../../../../lib/devices/virtio" }

hashbrown = "0.7.2"

[features]
default = []
101 changes: 101 additions & 0 deletions domains/sys/driver/virtio_backend/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#![no_std]
#![no_main]
// #![forbid(unsafe_code)]
#![feature(
box_syntax,
const_fn,
const_raw_ptr_to_usize_cast,
const_in_array_repeat_expressions,
untagged_unions,
maybe_uninit_extra,
core_intrinsics
)]

extern crate alloc;
extern crate malloc;

mod virtio_backend;

use alloc::{boxed::Box, sync::Arc, vec, vec::Vec};
use console::{print, println};
use core::{
borrow::BorrowMut,
intrinsics::size_of,
panic::PanicInfo,
ptr::{read_volatile, write_volatile},
};
use interface::{
net::Net,
rref::{RRef, RRefDeque},
};
use libsyscalls::syscalls::{sys_backtrace, sys_create_thread, sys_yield};
use libtime::sys_ns_sleep;
use spin::{Mutex, MutexGuard, Once};
use syscalls::{Heap, Syscall};
use virtio_backend::VirtioBackend;
use virtio_backend_trusted::{
defs::{
Buffer, DeviceNotificationType, BATCH_SIZE, DEVICE_NOTIFY, MAX_SUPPORTED_QUEUES,
MMIO_ADDRESS,
},
get_device_notifications, get_thread_arguments, VirtioBackendThreadArguments, THREAD_ARGUMENTS,
};
use virtio_backend_trusted::{initialize_device_config_space, virtual_queue::VirtualQueue};
use virtio_device::{defs::VirtQueue, VirtioPciCommonConfig};
use virtio_net_mmio_device::VirtioNetworkDeviceConfig;

pub extern "C" fn virtio_backend() {
// Retrieve Thread Arguments
let args = get_thread_arguments();

initialize_device_config_space();
process_notifications(args.net);
}

fn process_notifications(net: Box<dyn Net>) -> ! {
let mut backend = VirtioBackend::new(net);

loop {
// Check device for processed buffers and move to queues
backend.update_queues();

let notification = get_device_notifications();

match notification {
DeviceNotificationType::DeviceConfigurationUpdated => {
backend.handle_device_config_update();
}
DeviceNotificationType::QueueUpdated => {
backend.handle_queue_notify();
}
DeviceNotificationType::None => {}
}

sys_yield();
}
}

#[no_mangle]
pub fn trusted_entry(
s: Box<dyn Syscall + Send + Sync>,
heap: Box<dyn Heap + Send + Sync>,
net: Box<dyn Net>,
) {
libsyscalls::syscalls::init(s);
interface::rref::init(heap, libsyscalls::syscalls::sys_get_current_domain_id());

// Prepare thread arguments
unsafe {
THREAD_ARGUMENTS = Some(VirtioBackendThreadArguments { net });
}

sys_create_thread("virtio_backend", virtio_backend);
}

// This function is called on panic.
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
println!("{:?}", info);
sys_backtrace();
loop {}
}
Loading