Skip to content

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

Merged
merged 27 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8fe3d11
chore: update kvm and vmm-sys-util dependencies
bchalios May 30, 2025
6084af8
pci: fixes in PCI crate
bchalios Jun 3, 2025
44fc536
vm-device: return reference to EventFd from Interrupt trait
bchalios Jun 10, 2025
a6cd1a9
cleanup: remove unused code from pci and vm-device crates
bchalios Jun 25, 2025
a172a8d
refactor: allow storing Arc<Vm> within Vmm
bchalios Jun 2, 2025
d7b8d8f
vm: track device interrupts within Vm object
bchalios Jun 2, 2025
0ed1d5b
interrupts: add support for MSI/MSI-X interrupts
bchalios Jun 3, 2025
3b91be4
vstate: support serializing interrupts to snapshots
bchalios Jun 10, 2025
7e9bbdc
fix(block): use correct index for interrupt
bchalios Jun 3, 2025
b8aa9e1
virtio: initialize queue size with max_size
bchalios Jun 3, 2025
1a5aafc
acpi: PCI compatible flags in FADT
bchalios Jun 3, 2025
cc9e9f6
vmm: simplify device errors
bchalios Jun 3, 2025
ba7691c
pci: add virtio-pci transport implementation
bchalios Jun 2, 2025
e40fab1
seccomp: allow new ioctls for vCPU threads
bchalios Jun 4, 2025
6e3495c
pci: add unit tests to PciSegment
bchalios Jun 4, 2025
b3feaa4
device_manager: save resource allocator in snapshot
bchalios Jun 5, 2025
9534b27
refactor: VirtIO MMIO persistence logic
bchalios Jun 6, 2025
c979c15
pci: support snapshotting VirtIO PCI devices
bchalios Jun 5, 2025
b424d27
refactor(vm): move ResourceAllocator inside Vm
bchalios Jun 13, 2025
be09412
refactor(vm): move `Bus` objects to Vm
bchalios Jun 13, 2025
d148cc5
arm: support MSI-X on ARM
bchalios Jun 18, 2025
7053fb3
test: VirtIO PCI device create and restoration
bchalios Jun 17, 2025
d2cf9ab
test: enable PCI microVMs for performance testing
bchalios Jun 20, 2025
fcdeb7a
test: remove pci=off default from various parts in tests
bchalios Jun 25, 2025
0c940cd
virtio: add kick() method in VirtioDevice trait
bchalios Jun 30, 2025
4f39170
refactor: simplify ResourceAllocator internals
bchalios Jun 30, 2025
b500902
fix(vsock): pass correct index when triggering interrupts
bchalios Jul 2, 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
263 changes: 145 additions & 118 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
3 changes: 2 additions & 1 deletion src/pci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ 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"] }
thiserror = "2.0.12"
vm-allocator = "0.1.2"
vm-allocator = "0.1.3"
vm-device = { path = "../vm-device" }
vm-memory = { version = "0.16.1", features = [
"backend-mmap",
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
13 changes: 7 additions & 6 deletions src/pci/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extern crate log;
mod bus;
mod configuration;
mod device;
mod msi;
mod msix;

use std::fmt::{self, Debug, Display};
Expand All @@ -24,15 +23,17 @@ 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
Loading
Loading