@@ -71,7 +71,7 @@ use crate::vmm_config::machine_config::{MachineConfig, MachineConfigError};
71
71
use crate :: vstate:: kvm:: Kvm ;
72
72
use crate :: vstate:: memory:: { GuestAddress , GuestMemory , GuestMemoryMmap } ;
73
73
use crate :: vstate:: vcpu:: { Vcpu , VcpuConfig , VcpuError } ;
74
- use crate :: vstate:: vm:: { Vm , VmError } ;
74
+ use crate :: vstate:: vm:: Vm ;
75
75
use crate :: { device_manager, EventManager , Vmm , VmmError } ;
76
76
77
77
/// Errors associated with starting the instance.
@@ -175,10 +175,6 @@ fn create_vmm_and_vcpus(
175
175
. map_err ( VmmError :: Vm )
176
176
. map_err ( StartMicrovmError :: Internal ) ?;
177
177
178
- let vcpus_exit_evt = EventFd :: new ( libc:: EFD_NONBLOCK )
179
- . map_err ( VmmError :: EventFd )
180
- . map_err ( Internal ) ?;
181
-
182
178
let resource_allocator = ResourceAllocator :: new ( ) ?;
183
179
184
180
// Instantiate the MMIO device manager.
@@ -187,13 +183,13 @@ fn create_vmm_and_vcpus(
187
183
// Instantiate ACPI device manager.
188
184
let acpi_device_manager = ACPIDeviceManager :: new ( ) ;
189
185
190
- // For x86_64 we need to create the interrupt controller before calling `KVM_CREATE_VCPUS`
191
- // while on aarch64 we need to do it the other way around.
192
- #[ cfg( target_arch = "x86_64" ) ]
193
- let ( vcpus, pio_device_manager) = {
194
- setup_interrupt_controller ( & mut vm) ?;
195
- let vcpus = create_vcpus ( & vm, vcpu_count, & vcpus_exit_evt) . map_err ( Internal ) ?;
186
+ let ( vcpus, vcpus_exit_evt) = vm
187
+ . create_vcpus ( vcpu_count)
188
+ . map_err ( VmmError :: Vm )
189
+ . map_err ( Internal ) ?;
196
190
191
+ #[ cfg( target_arch = "x86_64" ) ]
192
+ let pio_device_manager = {
197
193
// Make stdout non blocking.
198
194
set_stdout_nonblocking ( ) ;
199
195
@@ -208,25 +204,10 @@ fn create_vmm_and_vcpus(
208
204
. map_err ( Internal ) ?;
209
205
210
206
// create pio dev manager with legacy devices
211
- let pio_device_manager = {
212
- // TODO Remove these unwraps.
213
- let mut pio_dev_mgr = PortIODeviceManager :: new ( serial_device, reset_evt) . unwrap ( ) ;
214
- pio_dev_mgr. register_devices ( vm. fd ( ) ) . unwrap ( ) ;
215
- pio_dev_mgr
216
- } ;
217
-
218
- ( vcpus, pio_device_manager)
219
- } ;
220
-
221
- // On aarch64, the vCPUs need to be created (i.e call KVM_CREATE_VCPU) before setting up the
222
- // IRQ chip because the `KVM_CREATE_VCPU` ioctl will return error if the IRQCHIP
223
- // was already initialized.
224
- // Search for `kvm_arch_vcpu_create` in arch/arm/kvm/arm.c.
225
- #[ cfg( target_arch = "aarch64" ) ]
226
- let vcpus = {
227
- let vcpus = create_vcpus ( & vm, vcpu_count, & vcpus_exit_evt) . map_err ( Internal ) ?;
228
- setup_interrupt_controller ( & mut vm, vcpu_count) ?;
229
- vcpus
207
+ // TODO Remove these unwraps.
208
+ let mut pio_dev_mgr = PortIODeviceManager :: new ( serial_device, reset_evt) . unwrap ( ) ;
209
+ pio_dev_mgr. register_devices ( vm. fd ( ) ) . unwrap ( ) ;
210
+ pio_dev_mgr
230
211
} ;
231
212
232
213
let vmm = Vmm {
@@ -671,24 +652,6 @@ where
671
652
} )
672
653
}
673
654
674
- /// Sets up the irqchip for a x86_64 microVM.
675
- #[ cfg( target_arch = "x86_64" ) ]
676
- pub fn setup_interrupt_controller ( vm : & mut Vm ) -> Result < ( ) , StartMicrovmError > {
677
- vm. setup_irqchip ( )
678
- . map_err ( VmError :: Arch )
679
- . map_err ( VmmError :: Vm )
680
- . map_err ( StartMicrovmError :: Internal )
681
- }
682
-
683
- /// Sets up the irqchip for a aarch64 microVM.
684
- #[ cfg( target_arch = "aarch64" ) ]
685
- pub fn setup_interrupt_controller ( vm : & mut Vm , vcpu_count : u8 ) -> Result < ( ) , StartMicrovmError > {
686
- vm. setup_irqchip ( vcpu_count)
687
- . map_err ( VmError :: Arch )
688
- . map_err ( VmmError :: Vm )
689
- . map_err ( StartMicrovmError :: Internal )
690
- }
691
-
692
655
/// Sets up the serial device.
693
656
pub fn setup_serial_device (
694
657
event_manager : & mut EventManager ,
@@ -746,16 +709,6 @@ fn attach_legacy_devices_aarch64(
746
709
. map_err ( VmmError :: RegisterMMIODevice )
747
710
}
748
711
749
- fn create_vcpus ( vm : & Vm , vcpu_count : u8 , exit_evt : & EventFd ) -> Result < Vec < Vcpu > , VmmError > {
750
- let mut vcpus = Vec :: with_capacity ( vcpu_count as usize ) ;
751
- for cpu_idx in 0 ..vcpu_count {
752
- let exit_evt = exit_evt. try_clone ( ) . map_err ( VmmError :: EventFd ) ?;
753
- let vcpu = Vcpu :: new ( cpu_idx, vm, exit_evt) . map_err ( VmmError :: VcpuCreate ) ?;
754
- vcpus. push ( vcpu) ;
755
- }
756
- Ok ( vcpus)
757
- }
758
-
759
712
/// Configures the system for booting Linux.
760
713
#[ cfg_attr( target_arch = "aarch64" , allow( unused) ) ]
761
714
pub fn configure_system_for_boot (
@@ -1127,11 +1080,6 @@ pub(crate) mod tests {
1127
1080
pub ( crate ) fn default_vmm ( ) -> Vmm {
1128
1081
let guest_memory = arch_mem ( 128 << 20 ) ;
1129
1082
1130
- let vcpus_exit_evt = EventFd :: new ( libc:: EFD_NONBLOCK )
1131
- . map_err ( VmmError :: EventFd )
1132
- . map_err ( StartMicrovmError :: Internal )
1133
- . unwrap ( ) ;
1134
-
1135
1083
let kvm = Kvm :: new ( vec ! [ ] ) . unwrap ( ) ;
1136
1084
let mut vm = Vm :: new ( & kvm) . unwrap ( ) ;
1137
1085
vm. memory_init ( & guest_memory) . unwrap ( ) ;
@@ -1153,15 +1101,7 @@ pub(crate) mod tests {
1153
1101
)
1154
1102
. unwrap ( ) ;
1155
1103
1156
- #[ cfg( target_arch = "x86_64" ) ]
1157
- setup_interrupt_controller ( & mut vm) . unwrap ( ) ;
1158
-
1159
- #[ cfg( target_arch = "aarch64" ) ]
1160
- {
1161
- let exit_evt = EventFd :: new ( libc:: EFD_NONBLOCK ) . unwrap ( ) ;
1162
- let _vcpu = Vcpu :: new ( 1 , & vm, exit_evt) . unwrap ( ) ;
1163
- setup_interrupt_controller ( & mut vm, 1 ) . unwrap ( ) ;
1164
- }
1104
+ let ( _, vcpus_exit_evt) = vm. create_vcpus ( 1 ) . unwrap ( ) ;
1165
1105
1166
1106
Vmm {
1167
1107
events_observer : Some ( std:: io:: stdin ( ) ) ,
@@ -1380,24 +1320,6 @@ pub(crate) mod tests {
1380
1320
) ;
1381
1321
}
1382
1322
1383
- #[ test]
1384
- fn test_create_vcpus ( ) {
1385
- let vcpu_count = 2 ;
1386
- let guest_memory = arch_mem ( 128 << 20 ) ;
1387
-
1388
- let kvm = Kvm :: new ( vec ! [ ] ) . expect ( "Cannot create Kvm" ) ;
1389
- #[ allow( unused_mut) ]
1390
- let mut vm = Vm :: new ( & kvm) . unwrap ( ) ;
1391
- vm. memory_init ( & guest_memory) . unwrap ( ) ;
1392
- let evfd = EventFd :: new ( libc:: EFD_NONBLOCK ) . unwrap ( ) ;
1393
-
1394
- #[ cfg( target_arch = "x86_64" ) ]
1395
- setup_interrupt_controller ( & mut vm) . unwrap ( ) ;
1396
-
1397
- let vcpu_vec = create_vcpus ( & vm, vcpu_count, & evfd) . unwrap ( ) ;
1398
- assert_eq ! ( vcpu_vec. len( ) , vcpu_count as usize ) ;
1399
- }
1400
-
1401
1323
#[ test]
1402
1324
fn test_attach_net_devices ( ) {
1403
1325
let mut event_manager = EventManager :: new ( ) . expect ( "Unable to create EventManager" ) ;
0 commit comments