@@ -321,16 +321,24 @@ pub fn build_microvm_for_boot(
321321 & mut boot_cmdline,
322322 vm_resources. block . devices . iter ( ) ,
323323 event_manager,
324+ secret_free,
324325 ) ?;
325326 attach_net_devices (
326327 & mut vmm,
327328 & mut boot_cmdline,
328329 vm_resources. net_builder . iter ( ) ,
329330 event_manager,
331+ secret_free,
330332 ) ?;
331333
332334 if let Some ( unix_vsock) = vm_resources. vsock . get ( ) {
333- attach_unixsock_vsock_device ( & mut vmm, & mut boot_cmdline, unix_vsock, event_manager) ?;
335+ attach_unixsock_vsock_device (
336+ & mut vmm,
337+ & mut boot_cmdline,
338+ unix_vsock,
339+ event_manager,
340+ secret_free,
341+ ) ?;
334342 }
335343
336344 if let Some ( entropy) = vm_resources. entropy . get ( ) {
@@ -707,14 +715,19 @@ fn attach_virtio_device<T: 'static + VirtioDevice + MutEventSubscriber + Debug>(
707715 device : Arc < Mutex < T > > ,
708716 cmdline : & mut LoaderKernelCmdline ,
709717 is_vhost_user : bool ,
718+ needs_bouncing : bool ,
710719) -> Result < ( ) , MmioError > {
711720 event_manager. add_subscriber ( device. clone ( ) ) ;
712721
713722 // We have to enable swiotlb as part of the boot process, because the device objects
714723 // themselves are created when the corresponding PUT API calls are made, and at that
715724 // point we don't know yet whether swiotlb should be enabled or not.
716- if vmm. vm . has_swiotlb ( ) {
717- device. lock ( ) . unwrap ( ) . force_swiotlb ( ) ;
725+ if needs_bouncing {
726+ if vmm. vm . has_swiotlb ( ) {
727+ device. lock ( ) . unwrap ( ) . force_swiotlb ( ) ;
728+ } else {
729+ device. lock ( ) . unwrap ( ) . force_userspace_bounce_buffers ( ) ;
730+ }
718731 }
719732
720733 // The device mutex mustn't be locked here otherwise it will deadlock.
@@ -772,6 +785,7 @@ fn attach_entropy_device(
772785 entropy_device. clone ( ) ,
773786 cmdline,
774787 false ,
788+ false ,
775789 )
776790}
777791
@@ -780,6 +794,7 @@ fn attach_block_devices<'a, I: Iterator<Item = &'a Arc<Mutex<Block>>> + Debug>(
780794 cmdline : & mut LoaderKernelCmdline ,
781795 blocks : I ,
782796 event_manager : & mut EventManager ,
797+ needs_bouncing : bool ,
783798) -> Result < ( ) , StartMicrovmError > {
784799 for block in blocks {
785800 let ( id, is_vhost_user) = {
@@ -804,6 +819,7 @@ fn attach_block_devices<'a, I: Iterator<Item = &'a Arc<Mutex<Block>>> + Debug>(
804819 block. clone ( ) ,
805820 cmdline,
806821 is_vhost_user,
822+ needs_bouncing,
807823 ) ?;
808824 }
809825 Ok ( ( ) )
@@ -814,11 +830,20 @@ fn attach_net_devices<'a, I: Iterator<Item = &'a Arc<Mutex<Net>>> + Debug>(
814830 cmdline : & mut LoaderKernelCmdline ,
815831 net_devices : I ,
816832 event_manager : & mut EventManager ,
833+ needs_bouncing : bool ,
817834) -> Result < ( ) , StartMicrovmError > {
818835 for net_device in net_devices {
819836 let id = net_device. lock ( ) . expect ( "Poisoned lock" ) . id ( ) . clone ( ) ;
820837 // The device mutex mustn't be locked here otherwise it will deadlock.
821- attach_virtio_device ( event_manager, vmm, id, net_device. clone ( ) , cmdline, false ) ?;
838+ attach_virtio_device (
839+ event_manager,
840+ vmm,
841+ id,
842+ net_device. clone ( ) ,
843+ cmdline,
844+ false ,
845+ needs_bouncing,
846+ ) ?;
822847 }
823848 Ok ( ( ) )
824849}
@@ -828,10 +853,19 @@ fn attach_unixsock_vsock_device(
828853 cmdline : & mut LoaderKernelCmdline ,
829854 unix_vsock : & Arc < Mutex < Vsock < VsockUnixBackend > > > ,
830855 event_manager : & mut EventManager ,
856+ needs_bouncing : bool ,
831857) -> Result < ( ) , MmioError > {
832858 let id = String :: from ( unix_vsock. lock ( ) . expect ( "Poisoned lock" ) . id ( ) ) ;
833859 // The device mutex mustn't be locked here otherwise it will deadlock.
834- attach_virtio_device ( event_manager, vmm, id, unix_vsock. clone ( ) , cmdline, false )
860+ attach_virtio_device (
861+ event_manager,
862+ vmm,
863+ id,
864+ unix_vsock. clone ( ) ,
865+ cmdline,
866+ false ,
867+ needs_bouncing,
868+ )
835869}
836870
837871fn attach_balloon_device (
@@ -842,7 +876,15 @@ fn attach_balloon_device(
842876) -> Result < ( ) , MmioError > {
843877 let id = String :: from ( balloon. lock ( ) . expect ( "Poisoned lock" ) . id ( ) ) ;
844878 // The device mutex mustn't be locked here otherwise it will deadlock.
845- attach_virtio_device ( event_manager, vmm, id, balloon. clone ( ) , cmdline, false )
879+ attach_virtio_device (
880+ event_manager,
881+ vmm,
882+ id,
883+ balloon. clone ( ) ,
884+ cmdline,
885+ false ,
886+ false ,
887+ )
846888}
847889
848890// Adds `O_NONBLOCK` to the stdout flags.
@@ -1018,6 +1060,7 @@ pub(crate) mod tests {
10181060 cmdline,
10191061 block_dev_configs. devices . iter ( ) ,
10201062 event_manager,
1063+ false ,
10211064 )
10221065 . unwrap ( ) ;
10231066 block_files
@@ -1032,7 +1075,7 @@ pub(crate) mod tests {
10321075 let mut net_builder = NetBuilder :: new ( ) ;
10331076 net_builder. build ( net_config) . unwrap ( ) ;
10341077
1035- let res = attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager) ;
1078+ let res = attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager, false ) ;
10361079 res. unwrap ( ) ;
10371080 }
10381081
@@ -1053,7 +1096,7 @@ pub(crate) mod tests {
10531096 Arc :: new ( Mutex :: new ( mmds) ) ,
10541097 ) ;
10551098
1056- attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager) . unwrap ( ) ;
1099+ attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager, false ) . unwrap ( ) ;
10571100 }
10581101
10591102 pub ( crate ) fn insert_vsock_device (
@@ -1066,7 +1109,7 @@ pub(crate) mod tests {
10661109 let vsock = VsockBuilder :: create_unixsock_vsock ( vsock_config) . unwrap ( ) ;
10671110 let vsock = Arc :: new ( Mutex :: new ( vsock) ) ;
10681111
1069- attach_unixsock_vsock_device ( vmm, cmdline, & vsock, event_manager) . unwrap ( ) ;
1112+ attach_unixsock_vsock_device ( vmm, cmdline, & vsock, event_manager, false ) . unwrap ( ) ;
10701113
10711114 assert ! (
10721115 vmm. mmio_device_manager
0 commit comments