Skip to content

DRAFT: Add support for virtio-pci transport #5240

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

Draft
wants to merge 24 commits into
base: feature/pcie
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9f50bcb
chore: update kvm and vmm-sys-util dependencies
bchalios May 30, 2025
55fcdba
pci: fixes in PCI crate
bchalios Jun 3, 2025
7461531
vm-device: return reference to EventFd from Interrupt trait
bchalios Jun 10, 2025
dd93d61
refactor: allow storing Arc<Vm> within Vmm
bchalios Jun 2, 2025
d993c9f
vm: track device interrupts within Vm object
bchalios Jun 2, 2025
2507104
interrupts: add support for MSI/MSI-X interrupts
bchalios Jun 3, 2025
4472a5b
vstate: support serializing interrupts to snapshots
bchalios Jun 10, 2025
d4269bb
pci: add virtio-pci transport implementation
bchalios Jun 2, 2025
75515e8
vmm: simplify device errors
bchalios Jun 3, 2025
9da1a71
fix(block): use correct index for interrupt
bchalios Jun 3, 2025
1f188db
virtio: initialize queue size with max_size
bchalios Jun 3, 2025
379dc82
acpi: PCI compatible flags in FADT
bchalios Jun 3, 2025
f1f7be6
pci: use VirtIO PCI transport when PCI is enabled
bchalios Jun 3, 2025
2b6ce5a
seccomp: allow new ioctls for vCPU threads
bchalios Jun 4, 2025
3d4023c
pci: add unit tests to PciSegment
bchalios Jun 4, 2025
9e44aaf
device_manager: save resource allocator in snapshot
bchalios Jun 5, 2025
2bbfd3e
refactor: VirtIO MMIO persistence logic
bchalios Jun 6, 2025
60dae37
pci: support snapshotting VirtIO PCI devices
bchalios Jun 5, 2025
7ab90b7
refactor(vm): move ResourceAllocator inside Vm
bchalios Jun 13, 2025
8e45f73
refactor: move Buses to Vm object
bchalios Jun 13, 2025
e691fdf
vm: implement DeviceRelocation for Vm
bchalios Jun 16, 2025
d35bc74
test: VirtIO PCI device create and restoration
bchalios Jun 17, 2025
4127ffe
arm: support MSI-X on ARM
bchalios Jun 18, 2025
bc83f51
test: enable PCI microVMs for performance testing
bchalios Jun 20, 2025
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
259 changes: 143 additions & 116 deletions Cargo.lock

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions resources/seccomp/aarch64-unknown-linux-musl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,49 @@
{
"syscall": "restart_syscall",
"comment": "automatically issued by the kernel when specific timing-related syscalls (e.g. nanosleep) get interrupted by SIGSTOP"
},
{
"syscall": "ioctl",
"args": [
{
"index": 1,
"type": "dword",
"op": "eq",
"val": 44547,
"comment": "KVM_CHECK_EXTENSION"
},
{
"index": 2,
"type": "dword",
"op": "eq",
"val": 131,
"comment": "KVM_CAP_MSI_DEVID"
}
]
},
{
"syscall": "ioctl",
"args": [
{
"index": 1,
"type": "dword",
"op": "eq",
"val": 1074310762,
"comment": "KVM_SET_GSI_ROUTING"
}
]
},
{
"syscall": "ioctl",
"args": [
{
"index": 1,
"type": "dword",
"op": "eq",
"val": 1075883638,
"comment": "KVM_IRQFD"
}
]
}
]
}
Expand Down
43 changes: 43 additions & 0 deletions resources/seccomp/x86_64-unknown-linux-musl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,49 @@
{
"syscall": "restart_syscall",
"comment": "automatically issued by the kernel when specific timing-related syscalls (e.g. nanosleep) get interrupted by SIGSTOP"
},
{
"syscall": "ioctl",
"args": [
{
"index": 1,
"type": "dword",
"op": "eq",
"val": 44547,
"comment": "KVM_CHECK_EXTENSION"
},
{
"index": 2,
"type": "dword",
"op": "eq",
"val": 131,
"comment": "KVM_CAP_MSI_DEVID"
}
]
},
{
"syscall": "ioctl",
"args": [
{
"index": 1,
"type": "dword",
"op": "eq",
"val": 1074310762,
"comment": "KVM_SET_GSI_ROUTING"
}
]
},
{
"syscall": "ioctl",
"args": [
{
"index": 1,
"type": "dword",
"op": "eq",
"val": 1075883638,
"comment": "KVM_IRQFD"
}
]
}
]
}
Expand Down
5 changes: 4 additions & 1 deletion src/firecracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ serde_json = "1.0.140"
[dev-dependencies]
cargo_toml = "0.22.1"
libc = "0.2.172"
regex = { version = "1.11.1", default-features = false, features = ["std", "unicode-perl"] }
regex = { version = "1.11.1", default-features = false, features = [
"std",
"unicode-perl",
] }

# Dev-Dependencies for uffd examples
serde = { version = "1.0.219", features = ["derive"] }
Expand Down
1 change: 1 addition & 0 deletions src/pci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ default = []

[dependencies]
byteorder = "1.5.0"
displaydoc = "0.2.5"
libc = "0.2.172"
log = "0.4.27"
serde = { version = "1.0.219", features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions src/pci/src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
const NUM_DEVICE_IDS: usize = 32;

/// Errors for device manager.
#[derive(Debug)]
#[derive(Debug, thiserror::Error, displaydoc::Display)]

Check warning on line 27 in src/pci/src/bus.rs

View check run for this annotation

Codecov / codecov/patch

src/pci/src/bus.rs#L27

Added line #L27 was not covered by tests
pub enum PciRootError {
/// Could not allocate device address space for the device.
AllocateDeviceAddrs(PciDeviceError),
Expand Down Expand Up @@ -103,7 +103,7 @@
pub struct PciBus {
/// Devices attached to this bus.
/// Device 0 is host bridge.
devices: HashMap<u32, Arc<Mutex<dyn PciDevice>>>,
pub devices: HashMap<u32, Arc<Mutex<dyn PciDevice>>>,
device_reloc: Arc<dyn DeviceRelocation>,
device_ids: Vec<bool>,
}
Expand Down
6 changes: 3 additions & 3 deletions src/pci/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ struct PciBar {
r#type: Option<PciBarRegionType>,
}

#[derive(Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PciConfigurationState {
registers: Vec<u32>,
writable_bits: Vec<u32>,
Expand Down Expand Up @@ -466,7 +466,7 @@ impl From<PciBarRegionType> for PciBarType {
}
}

#[derive(Copy, Clone)]
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub enum PciBarPrefetchable {
NotPrefetchable = 0,
Prefetchable = 0x08,
Expand All @@ -481,7 +481,7 @@ impl From<PciBarPrefetchable> for bool {
}
}

#[derive(Copy, Clone)]
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub struct PciBarConfiguration {
addr: u64,
size: u64,
Expand Down
29 changes: 5 additions & 24 deletions src/pci/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

use std::any::Any;
use std::fmt::{self, Display};
use std::sync::{Arc, Barrier};
use std::{io, result};

Expand All @@ -16,39 +15,21 @@
use crate::configuration::{self, PciBarRegionType};
use crate::PciBarConfiguration;

#[derive(Debug)]
#[derive(Debug, thiserror::Error, displaydoc::Display)]

Check warning on line 18 in src/pci/src/device.rs

View check run for this annotation

Codecov / codecov/patch

src/pci/src/device.rs#L18

Added line #L18 was not covered by tests
pub enum Error {
/// Setup of the device capabilities failed.
/// Setup of the device capabilities failed: {0}.
CapabilitiesSetup(configuration::Error),
/// Allocating space for an IO BAR failed.
/// Allocating space for an IO BAR failed, size={0}.
IoAllocationFailed(u64),
/// Registering an IO BAR failed.
/// Registering an IO BAR at address {0} failed: {1}
IoRegistrationFailed(u64, configuration::Error),
/// Expected resource not found.
MissingResource,
/// Invalid resource.
/// Invalid resource
InvalidResource(Resource),
}
pub type Result<T> = std::result::Result<T, Error>;

impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Error::*;

match self {
CapabilitiesSetup(e) => write!(f, "failed to add capability {e}"),
IoAllocationFailed(size) => {
write!(f, "failed to allocate space for an IO BAR, size={size}")
}
IoRegistrationFailed(addr, e) => {
write!(f, "failed to register an IO BAR, addr={addr} err={e}")
}
MissingResource => write!(f, "failed to find expected resource"),
InvalidResource(r) => write!(f, "invalid resource {r:?}"),
}
}
}

#[derive(Clone, Copy)]
pub struct BarReprogrammingParams {
pub old_base: u64,
Expand Down
11 changes: 7 additions & 4 deletions src/pci/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ use serde::de::Visitor;
pub use self::bus::{PciBus, PciConfigIo, PciConfigMmio, PciRoot, PciRootError};
pub use self::configuration::{
PciBarConfiguration, PciBarPrefetchable, PciBarRegionType, PciCapability, PciCapabilityId,
PciClassCode, PciConfiguration, PciExpressCapabilityId, PciHeaderType, PciMassStorageSubclass,
PciNetworkControllerSubclass, PciProgrammingInterface, PciSerialBusSubClass, PciSubclass,
PCI_CONFIGURATION_ID,
PciClassCode, PciConfiguration, PciConfigurationState, PciExpressCapabilityId, PciHeaderType,
PciMassStorageSubclass, PciNetworkControllerSubclass, PciProgrammingInterface,
PciSerialBusSubClass, PciSubclass, PCI_CONFIGURATION_ID,
};
pub use self::device::{
BarReprogrammingParams, DeviceRelocation, Error as PciDeviceError, PciDevice,
};
pub use self::msi::{msi_num_enabled_vectors, MsiCap, MsiConfig};
pub use self::msix::{MsixCap, MsixConfig, MsixTableEntry, MSIX_CONFIG_ID, MSIX_TABLE_ENTRY_SIZE};
pub use self::msix::{
Error as MsixError, MsixCap, MsixConfig, MsixConfigState, MsixTableEntry, MSIX_CONFIG_ID,
MSIX_TABLE_ENTRY_SIZE,
};

/// PCI has four interrupt pins A->D.
#[derive(Copy, Clone)]
Expand Down
18 changes: 15 additions & 3 deletions src/pci/src/msix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
pub const MSIX_TABLE_ENTRY_SIZE: usize = 16;
pub const MSIX_CONFIG_ID: &str = "msix_config";

#[derive(Debug)]
#[derive(Debug, thiserror::Error, displaydoc::Display)]

Check warning on line 29 in src/pci/src/msix.rs

View check run for this annotation

Codecov / codecov/patch

src/pci/src/msix.rs#L29

Added line #L29 was not covered by tests
pub enum Error {
/// Failed enabling the interrupt route.
EnableInterruptRoute(io::Error),
Expand Down Expand Up @@ -59,7 +59,7 @@
}
}

#[derive(Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MsixConfigState {
table_entries: Vec<MsixTableEntry>,
pba_entries: Vec<u64>,
Expand All @@ -71,11 +71,23 @@
pub table_entries: Vec<MsixTableEntry>,
pub pba_entries: Vec<u64>,
pub devid: u32,
interrupt_source_group: Arc<dyn InterruptSourceGroup>,
pub interrupt_source_group: Arc<dyn InterruptSourceGroup>,
masked: bool,
enabled: bool,
}

impl std::fmt::Debug for MsixConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("MsixConfig")
.field("table_entries", &self.table_entries)
.field("pba_entries", &self.pba_entries)
.field("devid", &self.devid)
.field("masked", &self.masked)
.field("enabled", &self.enabled)
.finish()
}

Check warning on line 88 in src/pci/src/msix.rs

View check run for this annotation

Codecov / codecov/patch

src/pci/src/msix.rs#L80-L88

Added lines #L80 - L88 were not covered by tests
}

impl MsixConfig {
pub fn new(
msix_vectors: u16,
Expand Down
2 changes: 1 addition & 1 deletion src/vm-device/src/interrupt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub trait InterruptSourceGroup: Send + Sync {
/// to inject interrupts into a guest, by writing to the file returned
/// by this method.
#[allow(unused_variables)]
fn notifier(&self, index: InterruptIndex) -> Option<EventFd>;
fn notifier(&self, index: InterruptIndex) -> Option<&EventFd>;

/// Update the interrupt source group configuration.
///
Expand Down
4 changes: 3 additions & 1 deletion src/vmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ gdb = ["arrayvec", "gdbstub", "gdbstub_arch"]

acpi_tables = { path = "../acpi-tables" }
aes-gcm = { version = "0.10.1", default-features = false, features = ["aes"] }
anyhow = "1.0.98"
arrayvec = { version = "0.7.6", optional = true }
aws-lc-rs = { version = "1.13.1", features = ["bindgen"] }
base64 = "0.22.1"
bincode = { version = "2.0.1", features = ["serde"] }
bitflags = "2.9.1"
byteorder = "1.5.0"
crc64 = "2.0.0"
derive_more = { version = "2.0.1", default-features = false, features = [
"from",
Expand Down Expand Up @@ -50,7 +52,7 @@ userfaultfd = "0.8.1"
utils = { path = "../utils" }
uuid = "1.16.0"
vhost = { version = "0.14.0", features = ["vhost-user-frontend"] }
vm-allocator = "0.1.2"
vm-allocator = { version = "0.1.2", features = ["serde"] }
vm-device = { path = "../vm-device" }
vm-memory = { version = "0.16.2", features = [
"backend-mmap",
Expand Down
Loading
Loading