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

Open
wants to merge 26 commits into
base: feature/pcie
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
23a5f13
chore: update kvm and vmm-sys-util dependencies
bchalios May 30, 2025
2486030
pci: fixes in PCI crate
bchalios Jun 3, 2025
ef2c7ed
vm-device: return reference to EventFd from Interrupt trait
bchalios Jun 10, 2025
df5d3a8
cleanup: remove unused code from pci and vm-device crates
bchalios Jun 25, 2025
1ca4b38
refactor: allow storing Arc<Vm> within Vmm
bchalios Jun 2, 2025
742a5e2
vm: track device interrupts within Vm object
bchalios Jun 2, 2025
ad00226
interrupts: add support for MSI/MSI-X interrupts
bchalios Jun 3, 2025
b983e19
vstate: support serializing interrupts to snapshots
bchalios Jun 10, 2025
af4abd0
pci: add virtio-pci transport implementation
bchalios Jun 2, 2025
3f250db
vmm: simplify device errors
bchalios Jun 3, 2025
6a747ea
fix(block): use correct index for interrupt
bchalios Jun 3, 2025
e860e00
virtio: initialize queue size with max_size
bchalios Jun 3, 2025
6228619
acpi: PCI compatible flags in FADT
bchalios Jun 3, 2025
b2fb3e0
pci: use VirtIO PCI transport when PCI is enabled
bchalios Jun 3, 2025
dcb422e
seccomp: allow new ioctls for vCPU threads
bchalios Jun 4, 2025
65cb508
pci: add unit tests to PciSegment
bchalios Jun 4, 2025
ca81563
device_manager: save resource allocator in snapshot
bchalios Jun 5, 2025
469d892
refactor: VirtIO MMIO persistence logic
bchalios Jun 6, 2025
8ea5b08
pci: support snapshotting VirtIO PCI devices
bchalios Jun 5, 2025
5b5fbcb
refactor(vm): move ResourceAllocator inside Vm
bchalios Jun 13, 2025
b162e55
refactor(vm): move `Bus` objects to Vm
bchalios Jun 13, 2025
9e04d88
vm: implement DeviceRelocation for Vm
bchalios Jun 16, 2025
ff49795
test: VirtIO PCI device create and restoration
bchalios Jun 17, 2025
d8a56aa
arm: support MSI-X on ARM
bchalios Jun 18, 2025
5e60785
test: enable PCI microVMs for performance testing
bchalios Jun 20, 2025
75825ea
test: remove pci=off default from various parts in tests
bchalios Jun 25, 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
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