Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
86 changes: 85 additions & 1 deletion Cargo.lock

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

6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ struct VMMOpts {
/// Stdout console file path
#[clap(long)]
console: Option<String>,

/// Interface name
#[clap(long)]
net: Option<String>,
}

#[derive(Debug)]
Expand All @@ -47,7 +51,7 @@ fn main() -> Result<(), Error> {
// * Memory size (in MB)
// * Path to a Linux kernel
// * Optional path to console file
vmm.configure(opts.cpus, opts.memory, &opts.kernel, opts.console)
vmm.configure(opts.cpus, opts.memory, &opts.kernel, opts.console, opts.net)
.map_err(Error::VmmConfigure)?;

// Run the VMM
Expand Down
121 changes: 120 additions & 1 deletion src/vmm/Cargo.lock

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

6 changes: 5 additions & 1 deletion src/vmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ libc = "0.2.91"
linux-loader = { version = "0.8.1", features = ["bzimage", "elf"] }
vm-memory = { version = "0.10.0", features = ["backend-mmap"] }
vmm-sys-util = "0.11.1"
virtio-bindings = "0.2.0"

# vm-device is not yet published on crates.io.
# To make sure that breaking changes to vm-device are not breaking the
# vm-vcpu build, we're using a fixed revision.
vm-device = { git = "https://github.com/rust-vmm/vm-device", rev = "5847f12" }
vm-device = { git = "https://github.com/lucido-simon/vm-device", rev = "63bf6ecea4ee851d500e283dc3809baf6f89555d" }
vm-allocator = { git = "https://github.com/lucido-simon/vm-allocator", rev = "dfb880a86763a0064fdd700fbe731f26fcbf6681"}
virtio-device = { git = "https://github.com/rust-vmm/vm-virtio" }
virtio-queue = { git = "https://github.com/rust-vmm/vm-virtio" }

vm-superio = "0.7.0"
36 changes: 35 additions & 1 deletion src/vmm/src/cpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{result, u64};

use kvm_bindings::{kvm_fpu, kvm_regs, CpuId};
use kvm_ioctls::{VcpuExit, VcpuFd, VmFd};
use vm_device::device_manager::{IoManager, MmioManager};
use vm_memory::{Address, Bytes, GuestAddress, GuestMemoryError, GuestMemoryMmap};
use vmm_sys_util::terminal::Terminal;

Expand Down Expand Up @@ -66,15 +67,22 @@ pub(crate) struct Vcpu {
pub vcpu_fd: VcpuFd,

serial: Arc<Mutex<LumperSerial>>,
virtio_manager: Arc<Mutex<IoManager>>,
}

impl Vcpu {
/// Create a new vCPU.
pub fn new(vm_fd: &VmFd, index: u64, serial: Arc<Mutex<LumperSerial>>) -> Result<Self> {
pub fn new(
vm_fd: &VmFd,
index: u64,
serial: Arc<Mutex<LumperSerial>>,
virtio_manager: Arc<Mutex<IoManager>>,
) -> Result<Self> {
Ok(Vcpu {
index,
vcpu_fd: vm_fd.create_vcpu(index).map_err(Error::KvmIoctl)?,
serial,
virtio_manager,
})
}

Expand Down Expand Up @@ -266,10 +274,36 @@ impl Vcpu {
println!("Unsupported device read at {:x?}", addr);
}
},

// This is a MMIO write, i.e. the guest is trying to write
// something to a memory-mapped I/O region.
VcpuExit::MmioWrite(addr, data) => {
self.virtio_manager
.lock()
.unwrap()
.mmio_write(GuestAddress(addr), data)
.unwrap_or_else(|e| {
eprintln!("Failed to write to MMIO at addrress {:#x}: {}", addr, e);
});
}

// This is a MMIO read, i.e. the guest is trying to read
// from a memory-mapped I/O region.
VcpuExit::MmioRead(addr, data) => {
self.virtio_manager
.lock()
.unwrap()
.mmio_read(GuestAddress(addr), data)
.unwrap_or_else(|e| {
eprintln!("Failed to read to MMIO at addrress {:#x}: {}", addr, e);
});
}

_ => {
eprintln!("Unhandled VM-Exit: {:?}", exit_reason);
}
},

Err(e) => eprintln!("Emulation error: {}", e),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/vmm/src/devices/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0

pub(crate) mod net;
pub(crate) mod serial;
Loading