Skip to content

Commit

Permalink
add net support
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandru Agache <[email protected]>
  • Loading branch information
alexandruag committed Mar 3, 2021
1 parent 6fddf45 commit ee66a26
Show file tree
Hide file tree
Showing 12 changed files with 1,312 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion coverage_config_x86_64.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coverage_score": 80.8,
"exclude_path": "msr_index.rs,mpspec.rs,tests/",
"exclude_path": "msr_index.rs,mpspec.rs,tests/,src/devices/src/virtio/net/bindings.rs",
"crate_features": ""
}
10 changes: 5 additions & 5 deletions src/devices/src/virtio/block/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ where
let config_space = build_config_space(&args.file_path)?;
let virtio_cfg = VirtioConfig::new(device_features, queues, config_space);

let common_cfg = CommonConfig::new(virtio_cfg, env).map_err(Error::Generic)?;
let common_cfg = CommonConfig::new(virtio_cfg, env).map_err(Error::Virtio)?;

Ok(Block {
cfg: common_cfg,
Expand All @@ -70,10 +70,10 @@ where

// Register the device on the MMIO bus.
env.register_mmio_device(block.clone())
.map_err(Error::Generic)?;
.map_err(Error::Virtio)?;

env.insert_cmdline_str(args.cmdline_config_substring())
.map_err(Error::Generic)?;
.map_err(Error::Virtio)?;

Ok(block)
}
Expand Down Expand Up @@ -128,14 +128,14 @@ impl<M: GuestAddressSpace + Clone + Send + 'static> VirtioDeviceActions for Bloc
disk,
};

let mut ioevents = self.cfg.prepare_activate().map_err(Error::Generic)?;
let mut ioevents = self.cfg.prepare_activate().map_err(Error::Virtio)?;

let handler = Arc::new(Mutex::new(QueueHandler {
inner,
ioeventfd: ioevents.remove(0),
}));

self.cfg.finalize_activate(handler).map_err(Error::Generic)
self.cfg.finalize_activate(handler).map_err(Error::Virtio)
}

fn reset(&mut self) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/devices/src/virtio/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const SECTOR_SHIFT: u8 = 9;
#[derive(Debug)]
pub enum Error {
Backend(stdio_executor::Error),
Generic(crate::virtio::Error),
Virtio(crate::virtio::Error),
OpenFile(io::Error),
Seek(io::Error),
}
Expand Down
27 changes: 26 additions & 1 deletion src/devices/src/virtio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// We're only providing virtio over MMIO devices for now, but we aim to add PCI support as well.

pub mod block;
pub mod net;

use std::convert::TryFrom;
use std::io;
Expand All @@ -17,7 +18,7 @@ use event_manager::{
};
use kvm_ioctls::{IoEventAddress, VmFd};
use linux_loader::cmdline::Cmdline;
use vm_device::bus::{self, MmioRange};
use vm_device::bus::{self, MmioAddress, MmioRange};
use vm_device::device_manager::MmioManager;
use vm_device::DeviceMmio;
use vm_memory::{GuestAddress, GuestAddressSpace};
Expand Down Expand Up @@ -58,6 +59,7 @@ pub enum Error {
Cmdline(linux_loader::cmdline::Error),
Endpoint(EvmgrError),
EventFd(io::Error),
Overflow,
QueuesNotValid,
RegisterIoevent(errno::Error),
RegisterIrqfd(errno::Error),
Expand All @@ -73,6 +75,24 @@ pub struct MmioConfig {
pub gsi: u32,
}

impl MmioConfig {
pub fn new(base: u64, size: u64, gsi: u32) -> Result<Self> {
MmioRange::new(MmioAddress(base), size)
.map(|range| MmioConfig { range, gsi })
.map_err(Error::Bus)
}

pub fn next(&self) -> Result<Self> {
let range = self.range;
let next_start = range
.base()
.0
.checked_add(range.size())
.ok_or(Error::Overflow)?;
Self::new(next_start, range.size(), self.gsi + 1)
}
}

// Represents the environment the devices in this crate current expect in order to be created
// and registered with the appropriate buses/handlers/etc. We're always passing a mmio_cfg object
// for now, and we'll re-evaluate the mechanism for exposing environment (i.e. maybe we'll do it
Expand Down Expand Up @@ -313,6 +333,9 @@ pub(crate) mod tests {
}
}

// Skipping until adding Arm support and figuring out how make the irqchip creation in the
// `Mock` object work there as well.
#[cfg_attr(target_arch = "aarch64", ignore)]
#[test]
fn test_env() {
// Just a dummy device we're going to register on the bus.
Expand Down Expand Up @@ -348,6 +371,8 @@ pub(crate) mod tests {
assert!(mock.kernel_cmdline.as_str().ends_with("ending_string"));
}

// Ignoring until aarch64 support is here.
#[cfg_attr(target_arch = "aarch64", ignore)]
#[test]
fn test_common_config() {
let mut mock = EnvMock::new();
Expand Down
Loading

0 comments on commit ee66a26

Please sign in to comment.