@@ -44,6 +44,8 @@ use crate::device_manager::persist::{
44
44
ACPIDeviceManagerConstructorArgs , ACPIDeviceManagerRestoreError , MMIODevManagerConstructorArgs ,
45
45
} ;
46
46
use crate :: device_manager:: resources:: ResourceAllocator ;
47
+ #[ cfg( target_arch = "x86_64" ) ]
48
+ use crate :: devices:: acpi:: cpu_container:: { CpuContainer , CpuContainerError } ;
47
49
use crate :: devices:: acpi:: vmgenid:: { VmGenId , VmGenIdError } ;
48
50
use crate :: devices:: legacy:: serial:: SerialOut ;
49
51
#[ cfg( target_arch = "aarch64" ) ]
@@ -56,8 +58,6 @@ use crate::devices::virtio::mmio::MmioTransport;
56
58
use crate :: devices:: virtio:: net:: Net ;
57
59
use crate :: devices:: virtio:: rng:: Entropy ;
58
60
use crate :: devices:: virtio:: vsock:: { Vsock , VsockUnixBackend } ;
59
- #[ cfg( target_arch = "x86_64" ) ]
60
- use crate :: devices:: BusDevice ;
61
61
use crate :: logger:: { debug, error} ;
62
62
use crate :: persist:: { MicrovmState , MicrovmStateError } ;
63
63
use crate :: resources:: VmResources ;
@@ -77,6 +77,9 @@ pub enum StartMicrovmError {
77
77
AttachBlockDevice ( io:: Error ) ,
78
78
/// Unable to attach the VMGenID device: {0}
79
79
AttachVmgenidDevice ( kvm_ioctls:: Error ) ,
80
+ /// Unable to attach the CpuContainer device: {0}
81
+ #[ cfg( target_arch = "x86_64" ) ]
82
+ AttachCpuContainerDevice ( kvm_ioctls:: Error ) ,
80
83
/// System configuration error: {0}
81
84
ConfigureSystem ( crate :: arch:: ConfigurationError ) ,
82
85
/// Failed to create guest config: {0}
@@ -90,6 +93,9 @@ pub enum StartMicrovmError {
90
93
CreateLegacyDevice ( device_manager:: legacy:: LegacyDeviceError ) ,
91
94
/// Error creating VMGenID device: {0}
92
95
CreateVMGenID ( VmGenIdError ) ,
96
+ /// Error creating CpuContainer device: {0}
97
+ #[ cfg( target_arch = "x86_64" ) ]
98
+ CreateCpuContainer ( #[ from] CpuContainerError ) ,
93
99
/// Invalid Memory Configuration: {0}
94
100
GuestMemory ( crate :: vstate:: memory:: MemoryError ) ,
95
101
/// Cannot load initrd due to an invalid memory configuration.
@@ -318,6 +324,9 @@ pub fn build_microvm_for_boot(
318
324
attach_boot_timer_device ( & mut vmm, request_ts) ?;
319
325
}
320
326
327
+ #[ cfg( target_arch = "x86_64" ) ]
328
+ attach_cpu_container_device ( & mut vmm, vm_resources. vm_config . vcpu_count ) ?;
329
+
321
330
if let Some ( balloon) = vm_resources. balloon . get ( ) {
322
331
attach_balloon_device ( & mut vmm, & mut boot_cmdline, balloon, event_manager) ?;
323
332
}
@@ -1012,6 +1021,18 @@ fn attach_balloon_device(
1012
1021
attach_virtio_device ( event_manager, vmm, id, balloon. clone ( ) , cmdline, false )
1013
1022
}
1014
1023
1024
+ #[ cfg( target_arch = "x86_64" ) ]
1025
+ fn attach_cpu_container_device ( vmm : & mut Vmm , vcpu_count : u8 ) -> Result < ( ) , StartMicrovmError > {
1026
+ let cpu_container = Arc :: new ( Mutex :: new ( CpuContainer :: new (
1027
+ & mut vmm. resource_allocator ,
1028
+ vcpu_count,
1029
+ ) ?) ) ;
1030
+ vmm. acpi_device_manager
1031
+ . attach_cpu_container ( cpu_container, vmm. vm . fd ( ) )
1032
+ . map_err ( StartMicrovmError :: AttachCpuContainerDevice ) ?;
1033
+ Ok ( ( ) )
1034
+ }
1035
+
1015
1036
// Adds `O_NONBLOCK` to the stdout flags.
1016
1037
pub ( crate ) fn set_stdout_nonblocking ( ) {
1017
1038
// SAFETY: Call is safe since parameters are valid.
@@ -1036,6 +1057,8 @@ pub mod tests {
1036
1057
use super :: * ;
1037
1058
use crate :: arch:: DeviceType ;
1038
1059
use crate :: device_manager:: resources:: ResourceAllocator ;
1060
+ #[ cfg( target_arch = "x86_64" ) ]
1061
+ use crate :: devices:: acpi:: cpu_container:: CpuContainer ;
1039
1062
use crate :: devices:: virtio:: block:: CacheType ;
1040
1063
use crate :: devices:: virtio:: rng:: device:: ENTROPY_DEV_ID ;
1041
1064
use crate :: devices:: virtio:: vsock:: { TYPE_VSOCK , VSOCK_DEV_ID } ;
@@ -1114,8 +1137,19 @@ pub mod tests {
1114
1137
1115
1138
let mut vm = Vm :: new ( vec ! [ ] ) . unwrap ( ) ;
1116
1139
vm. memory_init ( & guest_memory, false ) . unwrap ( ) ;
1140
+
1141
+ #[ cfg( target_arch = "x86_64" ) ]
1142
+ let mut resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
1143
+ #[ cfg( target_arch = "aarch64" ) ]
1144
+ let resource_allocator = ResourceAllocator :: new ( ) . unwrap ( ) ;
1145
+
1117
1146
let mmio_device_manager = MMIODeviceManager :: new ( ) ;
1147
+
1148
+ #[ cfg( target_arch = "x86_64" ) ]
1149
+ let mut acpi_device_manager = ACPIDeviceManager :: new ( ) ;
1150
+ #[ cfg( target_arch = "aarch64" ) ]
1118
1151
let acpi_device_manager = ACPIDeviceManager :: new ( ) ;
1152
+
1119
1153
#[ cfg( target_arch = "x86_64" ) ]
1120
1154
let pio_device_manager = PortIODeviceManager :: new (
1121
1155
Arc :: new ( Mutex :: new ( SerialWrapper {
@@ -1135,6 +1169,16 @@ pub mod tests {
1135
1169
#[ cfg( target_arch = "x86_64" ) ]
1136
1170
setup_interrupt_controller ( & mut vm) . unwrap ( ) ;
1137
1171
1172
+ #[ cfg( target_arch = "x86_64" ) ]
1173
+ {
1174
+ let cpu_container = Arc :: new ( Mutex :: new (
1175
+ CpuContainer :: new ( & mut resource_allocator, 1 ) . unwrap ( ) ,
1176
+ ) ) ;
1177
+ acpi_device_manager
1178
+ . attach_cpu_container ( cpu_container, vm. fd ( ) )
1179
+ . unwrap ( ) ;
1180
+ }
1181
+
1138
1182
#[ cfg( target_arch = "aarch64" ) ]
1139
1183
{
1140
1184
let exit_evt = EventFd :: new ( libc:: EFD_NONBLOCK ) . unwrap ( ) ;
@@ -1153,7 +1197,7 @@ pub mod tests {
1153
1197
vcpus_exit_evt,
1154
1198
#[ cfg( target_arch = "x86_64" ) ]
1155
1199
seccomp_filters : crate :: seccomp_filters:: get_empty_filters ( ) ,
1156
- resource_allocator : ResourceAllocator :: new ( ) . unwrap ( ) ,
1200
+ resource_allocator,
1157
1201
mmio_device_manager,
1158
1202
#[ cfg( target_arch = "x86_64" ) ]
1159
1203
pio_device_manager,
@@ -1515,8 +1559,8 @@ pub mod tests {
1515
1559
#[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
1516
1560
assert ! ( cmdline_contains(
1517
1561
& cmdline,
1518
- "virtio_mmio.device=4K@0xd0000000:5 virtio_mmio.device=4K@0xd0001000:6 \
1519
- virtio_mmio.device=4K@0xd0002000:7 "
1562
+ "virtio_mmio.device=4K@0xd0001000:6 virtio_mmio.device=4K@0xd0002000:7 \
1563
+ virtio_mmio.device=4K@0xd0003000:8 "
1520
1564
) ) ;
1521
1565
}
1522
1566
@@ -1611,7 +1655,7 @@ pub mod tests {
1611
1655
#[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
1612
1656
assert ! ( cmdline_contains(
1613
1657
& cmdline,
1614
- "virtio_mmio.device=4K@0xd0000000:5 "
1658
+ "virtio_mmio.device=4K@0xd0001000:6 "
1615
1659
) ) ;
1616
1660
}
1617
1661
@@ -1628,7 +1672,7 @@ pub mod tests {
1628
1672
#[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
1629
1673
assert ! ( cmdline_contains(
1630
1674
& cmdline,
1631
- "virtio_mmio.device=4K@0xd0000000:5 "
1675
+ "virtio_mmio.device=4K@0xd0001000:6 "
1632
1676
) ) ;
1633
1677
}
1634
1678
@@ -1647,7 +1691,7 @@ pub mod tests {
1647
1691
#[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
1648
1692
assert ! ( cmdline_contains(
1649
1693
& cmdline,
1650
- "virtio_mmio.device=4K@0xd0000000:5 "
1694
+ "virtio_mmio.device=4K@0xd0001000:6 "
1651
1695
) ) ;
1652
1696
}
1653
1697
}
0 commit comments