@@ -14,13 +14,6 @@ use std::sync::{Arc, Mutex};
14
14
use event_manager:: { MutEventSubscriber , SubscriberOps } ;
15
15
use libc:: EFD_NONBLOCK ;
16
16
use linux_loader:: cmdline:: Cmdline as LoaderKernelCmdline ;
17
- use linux_loader:: loader:: KernelLoader ;
18
- #[ cfg( target_arch = "x86_64" ) ]
19
- use linux_loader:: loader:: elf:: Elf as Loader ;
20
- #[ cfg( target_arch = "x86_64" ) ]
21
- use linux_loader:: loader:: elf:: PvhBootCapability ;
22
- #[ cfg( target_arch = "aarch64" ) ]
23
- use linux_loader:: loader:: pe:: PE as Loader ;
24
17
use userfaultfd:: Uffd ;
25
18
use utils:: time:: TimestampUs ;
26
19
#[ cfg( target_arch = "aarch64" ) ]
@@ -30,7 +23,7 @@ use vmm_sys_util::eventfd::EventFd;
30
23
31
24
#[ cfg( target_arch = "x86_64" ) ]
32
25
use crate :: acpi;
33
- use crate :: arch:: { BootProtocol , EntryPoint } ;
26
+ use crate :: arch:: { ConfigurationError , EntryPoint , load_kernel } ;
34
27
#[ cfg( target_arch = "aarch64" ) ]
35
28
use crate :: construct_kvm_mpidrs;
36
29
use crate :: cpu_config:: templates:: {
@@ -66,11 +59,10 @@ use crate::persist::{MicrovmState, MicrovmStateError};
66
59
use crate :: resources:: VmResources ;
67
60
use crate :: seccomp:: BpfThreadMap ;
68
61
use crate :: snapshot:: Persist ;
69
- use crate :: vmm_config:: boot_source:: BootConfig ;
70
62
use crate :: vmm_config:: instance_info:: InstanceInfo ;
71
63
use crate :: vmm_config:: machine_config:: { MachineConfig , MachineConfigError } ;
72
64
use crate :: vstate:: kvm:: Kvm ;
73
- use crate :: vstate:: memory:: { GuestAddress , GuestMemoryMmap } ;
65
+ use crate :: vstate:: memory:: GuestMemoryMmap ;
74
66
use crate :: vstate:: vcpu:: { Vcpu , VcpuConfig , VcpuError } ;
75
67
use crate :: vstate:: vm:: Vm ;
76
68
use crate :: { EventManager , Vmm , VmmError , device_manager} ;
@@ -83,7 +75,7 @@ pub enum StartMicrovmError {
83
75
/// Unable to attach the VMGenID device: {0}
84
76
AttachVmgenidDevice ( kvm_ioctls:: Error ) ,
85
77
/// System configuration error: {0}
86
- ConfigureSystem ( crate :: arch :: ConfigurationError ) ,
78
+ ConfigureSystem ( # [ from ] ConfigurationError ) ,
87
79
/// Failed to create guest config: {0}
88
80
CreateGuestConfig ( #[ from] GuestConfigError ) ,
89
81
/// Cannot create network device: {0}
@@ -105,8 +97,6 @@ pub enum StartMicrovmError {
105
97
GetCpuTemplate ( #[ from] GetCpuTemplateError ) ,
106
98
/// Invalid kernel command line: {0}
107
99
KernelCmdline ( String ) ,
108
- /// Cannot load kernel due to invalid memory configuration or invalid kernel image: {0}
109
- KernelLoader ( linux_loader:: loader:: Error ) ,
110
100
/// Cannot load command line string: {0}
111
101
LoadCommandline ( linux_loader:: loader:: Error ) ,
112
102
/// Cannot start microvm without kernel configuration.
@@ -236,7 +226,7 @@ pub fn build_microvm_for_boot(
236
226
. allocate_guest_memory ( )
237
227
. map_err ( StartMicrovmError :: GuestMemory ) ?;
238
228
239
- let entry_point = load_kernel ( boot_config, & guest_memory) ?;
229
+ let entry_point = load_kernel ( & boot_config. kernel_file , & guest_memory) ?;
240
230
let initrd = InitrdConfig :: from_config ( boot_config, & guest_memory) ?;
241
231
// Clone the command-line so that a failed boot doesn't pollute the original.
242
232
#[ allow( unused_mut) ]
@@ -541,64 +531,6 @@ pub fn build_microvm_from_snapshot(
541
531
Ok ( vmm)
542
532
}
543
533
544
- #[ cfg( target_arch = "x86_64" ) ]
545
- fn load_kernel (
546
- boot_config : & BootConfig ,
547
- guest_memory : & GuestMemoryMmap ,
548
- ) -> Result < EntryPoint , StartMicrovmError > {
549
- let mut kernel_file = boot_config
550
- . kernel_file
551
- . try_clone ( )
552
- . map_err ( VmmError :: KernelFile ) ?;
553
-
554
- let entry_addr = Loader :: load :: < std:: fs:: File , GuestMemoryMmap > (
555
- guest_memory,
556
- None ,
557
- & mut kernel_file,
558
- Some ( GuestAddress ( crate :: arch:: get_kernel_start ( ) ) ) ,
559
- )
560
- . map_err ( StartMicrovmError :: KernelLoader ) ?;
561
-
562
- let mut entry_point_addr: GuestAddress = entry_addr. kernel_load ;
563
- let mut boot_prot: BootProtocol = BootProtocol :: LinuxBoot ;
564
- if let PvhBootCapability :: PvhEntryPresent ( pvh_entry_addr) = entry_addr. pvh_boot_cap {
565
- // Use the PVH kernel entry point to boot the guest
566
- entry_point_addr = pvh_entry_addr;
567
- boot_prot = BootProtocol :: PvhBoot ;
568
- }
569
-
570
- debug ! ( "Kernel loaded using {boot_prot}" ) ;
571
-
572
- Ok ( EntryPoint {
573
- entry_addr : entry_point_addr,
574
- protocol : boot_prot,
575
- } )
576
- }
577
-
578
- #[ cfg( target_arch = "aarch64" ) ]
579
- fn load_kernel (
580
- boot_config : & BootConfig ,
581
- guest_memory : & GuestMemoryMmap ,
582
- ) -> Result < EntryPoint , StartMicrovmError > {
583
- let mut kernel_file = boot_config
584
- . kernel_file
585
- . try_clone ( )
586
- . map_err ( VmmError :: KernelFile ) ?;
587
-
588
- let entry_addr = Loader :: load :: < std:: fs:: File , GuestMemoryMmap > (
589
- guest_memory,
590
- Some ( GuestAddress ( crate :: arch:: get_kernel_start ( ) ) ) ,
591
- & mut kernel_file,
592
- None ,
593
- )
594
- . map_err ( StartMicrovmError :: KernelLoader ) ?;
595
-
596
- Ok ( EntryPoint {
597
- entry_addr : entry_addr. kernel_load ,
598
- protocol : BootProtocol :: LinuxBoot ,
599
- } )
600
- }
601
-
602
534
/// Sets up the serial device.
603
535
pub fn setup_serial_device (
604
536
event_manager : & mut EventManager ,
@@ -725,7 +657,7 @@ pub fn configure_system_for_boot(
725
657
726
658
linux_loader:: loader:: load_cmdline :: < crate :: vstate:: memory:: GuestMemoryMmap > (
727
659
vmm. guest_memory ( ) ,
728
- GuestAddress ( crate :: arch:: x86_64:: layout:: CMDLINE_START ) ,
660
+ crate :: vstate :: memory :: GuestAddress ( crate :: arch:: x86_64:: layout:: CMDLINE_START ) ,
729
661
& boot_cmdline,
730
662
)
731
663
. map_err ( LoadCommandline ) ?;
@@ -737,8 +669,7 @@ pub fn configure_system_for_boot(
737
669
initrd,
738
670
vcpu_config. vcpu_count ,
739
671
entry_point. protocol ,
740
- )
741
- . map_err ( ConfigureSystem ) ?;
672
+ ) ?;
742
673
743
674
// Create ACPI tables and write them in guest memory
744
675
// For the time being we only support ACPI in x86_64
@@ -777,8 +708,7 @@ pub fn configure_system_for_boot(
777
708
vmm. vm . get_irqchip ( ) ,
778
709
& vmm. acpi_device_manager . vmgenid ,
779
710
initrd,
780
- )
781
- . map_err ( ConfigureSystem ) ?;
711
+ ) ?;
782
712
}
783
713
Ok ( ( ) )
784
714
}
0 commit comments