@@ -322,16 +322,24 @@ pub fn build_microvm_for_boot(
322322 & mut boot_cmdline,
323323 vm_resources. block . devices . iter ( ) ,
324324 event_manager,
325+ secret_free,
325326 ) ?;
326327 attach_net_devices (
327328 & mut vmm,
328329 & mut boot_cmdline,
329330 vm_resources. net_builder . iter ( ) ,
330331 event_manager,
332+ secret_free,
331333 ) ?;
332334
333335 if let Some ( unix_vsock) = vm_resources. vsock . get ( ) {
334- attach_unixsock_vsock_device ( & mut vmm, & mut boot_cmdline, unix_vsock, event_manager) ?;
336+ attach_unixsock_vsock_device (
337+ & mut vmm,
338+ & mut boot_cmdline,
339+ unix_vsock,
340+ event_manager,
341+ secret_free,
342+ ) ?;
335343 }
336344
337345 if let Some ( entropy) = vm_resources. entropy . get ( ) {
@@ -708,14 +716,19 @@ fn attach_virtio_device<T: 'static + VirtioDevice + MutEventSubscriber + Debug>(
708716 device : Arc < Mutex < T > > ,
709717 cmdline : & mut LoaderKernelCmdline ,
710718 is_vhost_user : bool ,
719+ needs_bouncing : bool ,
711720) -> Result < ( ) , MmioError > {
712721 event_manager. add_subscriber ( device. clone ( ) ) ;
713722
714723 // We have to enable swiotlb as part of the boot process, because the device objects
715724 // themselves are created when the corresponding PUT API calls are made, and at that
716725 // point we don't know yet whether swiotlb should be enabled or not.
717- if vmm. vm . has_swiotlb ( ) {
718- device. lock ( ) . unwrap ( ) . force_swiotlb ( ) ;
726+ if needs_bouncing {
727+ if vmm. vm . has_swiotlb ( ) {
728+ device. lock ( ) . unwrap ( ) . force_swiotlb ( ) ;
729+ } else {
730+ device. lock ( ) . unwrap ( ) . force_userspace_bounce_buffers ( ) ;
731+ }
719732 }
720733
721734 // The device mutex mustn't be locked here otherwise it will deadlock.
@@ -773,6 +786,7 @@ fn attach_entropy_device(
773786 entropy_device. clone ( ) ,
774787 cmdline,
775788 false ,
789+ false ,
776790 )
777791}
778792
@@ -781,6 +795,7 @@ fn attach_block_devices<'a, I: Iterator<Item = &'a Arc<Mutex<Block>>> + Debug>(
781795 cmdline : & mut LoaderKernelCmdline ,
782796 blocks : I ,
783797 event_manager : & mut EventManager ,
798+ needs_bouncing : bool ,
784799) -> Result < ( ) , StartMicrovmError > {
785800 for block in blocks {
786801 let ( id, is_vhost_user) = {
@@ -805,6 +820,7 @@ fn attach_block_devices<'a, I: Iterator<Item = &'a Arc<Mutex<Block>>> + Debug>(
805820 block. clone ( ) ,
806821 cmdline,
807822 is_vhost_user,
823+ needs_bouncing,
808824 ) ?;
809825 }
810826 Ok ( ( ) )
@@ -815,11 +831,20 @@ fn attach_net_devices<'a, I: Iterator<Item = &'a Arc<Mutex<Net>>> + Debug>(
815831 cmdline : & mut LoaderKernelCmdline ,
816832 net_devices : I ,
817833 event_manager : & mut EventManager ,
834+ needs_bouncing : bool ,
818835) -> Result < ( ) , StartMicrovmError > {
819836 for net_device in net_devices {
820837 let id = net_device. lock ( ) . expect ( "Poisoned lock" ) . id ( ) . clone ( ) ;
821838 // The device mutex mustn't be locked here otherwise it will deadlock.
822- attach_virtio_device ( event_manager, vmm, id, net_device. clone ( ) , cmdline, false ) ?;
839+ attach_virtio_device (
840+ event_manager,
841+ vmm,
842+ id,
843+ net_device. clone ( ) ,
844+ cmdline,
845+ false ,
846+ needs_bouncing,
847+ ) ?;
823848 }
824849 Ok ( ( ) )
825850}
@@ -829,10 +854,19 @@ fn attach_unixsock_vsock_device(
829854 cmdline : & mut LoaderKernelCmdline ,
830855 unix_vsock : & Arc < Mutex < Vsock < VsockUnixBackend > > > ,
831856 event_manager : & mut EventManager ,
857+ needs_bouncing : bool ,
832858) -> Result < ( ) , MmioError > {
833859 let id = String :: from ( unix_vsock. lock ( ) . expect ( "Poisoned lock" ) . id ( ) ) ;
834860 // The device mutex mustn't be locked here otherwise it will deadlock.
835- attach_virtio_device ( event_manager, vmm, id, unix_vsock. clone ( ) , cmdline, false )
861+ attach_virtio_device (
862+ event_manager,
863+ vmm,
864+ id,
865+ unix_vsock. clone ( ) ,
866+ cmdline,
867+ false ,
868+ needs_bouncing,
869+ )
836870}
837871
838872fn attach_balloon_device (
@@ -843,7 +877,15 @@ fn attach_balloon_device(
843877) -> Result < ( ) , MmioError > {
844878 let id = String :: from ( balloon. lock ( ) . expect ( "Poisoned lock" ) . id ( ) ) ;
845879 // The device mutex mustn't be locked here otherwise it will deadlock.
846- attach_virtio_device ( event_manager, vmm, id, balloon. clone ( ) , cmdline, false )
880+ attach_virtio_device (
881+ event_manager,
882+ vmm,
883+ id,
884+ balloon. clone ( ) ,
885+ cmdline,
886+ false ,
887+ false ,
888+ )
847889}
848890
849891// Adds `O_NONBLOCK` to the stdout flags.
@@ -1019,6 +1061,7 @@ pub(crate) mod tests {
10191061 cmdline,
10201062 block_dev_configs. devices . iter ( ) ,
10211063 event_manager,
1064+ false ,
10221065 )
10231066 . unwrap ( ) ;
10241067 block_files
@@ -1033,7 +1076,7 @@ pub(crate) mod tests {
10331076 let mut net_builder = NetBuilder :: new ( ) ;
10341077 net_builder. build ( net_config) . unwrap ( ) ;
10351078
1036- let res = attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager) ;
1079+ let res = attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager, false ) ;
10371080 res. unwrap ( ) ;
10381081 }
10391082
@@ -1054,7 +1097,7 @@ pub(crate) mod tests {
10541097 Arc :: new ( Mutex :: new ( mmds) ) ,
10551098 ) ;
10561099
1057- attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager) . unwrap ( ) ;
1100+ attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager, false ) . unwrap ( ) ;
10581101 }
10591102
10601103 pub ( crate ) fn insert_vsock_device (
@@ -1067,7 +1110,7 @@ pub(crate) mod tests {
10671110 let vsock = VsockBuilder :: create_unixsock_vsock ( vsock_config) . unwrap ( ) ;
10681111 let vsock = Arc :: new ( Mutex :: new ( vsock) ) ;
10691112
1070- attach_unixsock_vsock_device ( vmm, cmdline, & vsock, event_manager) . unwrap ( ) ;
1113+ attach_unixsock_vsock_device ( vmm, cmdline, & vsock, event_manager, false ) . unwrap ( ) ;
10711114
10721115 assert ! (
10731116 vmm. mmio_device_manager
0 commit comments