@@ -291,16 +291,24 @@ pub fn build_microvm_for_boot(
291
291
& mut boot_cmdline,
292
292
vm_resources. block . devices . iter ( ) ,
293
293
event_manager,
294
+ vm_resources. machine_config . secret_free ,
294
295
) ?;
295
296
attach_net_devices (
296
297
& mut vmm,
297
298
& mut boot_cmdline,
298
299
vm_resources. net_builder . iter ( ) ,
299
300
event_manager,
301
+ vm_resources. machine_config . secret_free ,
300
302
) ?;
301
303
302
304
if let Some ( unix_vsock) = vm_resources. vsock . get ( ) {
303
- attach_unixsock_vsock_device ( & mut vmm, & mut boot_cmdline, unix_vsock, event_manager) ?;
305
+ attach_unixsock_vsock_device (
306
+ & mut vmm,
307
+ & mut boot_cmdline,
308
+ unix_vsock,
309
+ event_manager,
310
+ vm_resources. machine_config . secret_free ,
311
+ ) ?;
304
312
}
305
313
306
314
if let Some ( entropy) = vm_resources. entropy . get ( ) {
@@ -617,9 +625,14 @@ fn attach_virtio_device<T: 'static + VirtioDevice + MutEventSubscriber + Debug>(
617
625
device : Arc < Mutex < T > > ,
618
626
cmdline : & mut LoaderKernelCmdline ,
619
627
is_vhost_user : bool ,
628
+ secret_free : bool ,
620
629
) -> Result < ( ) , MmioError > {
621
630
event_manager. add_subscriber ( device. clone ( ) ) ;
622
631
632
+ if secret_free {
633
+ device. lock ( ) . unwrap ( ) . force_userspace_bounce_buffers ( ) ;
634
+ }
635
+
623
636
// The device mutex mustn't be locked here otherwise it will deadlock.
624
637
let device = MmioTransport :: new ( vmm. vm . guest_memory ( ) . clone ( ) , device, is_vhost_user) ;
625
638
vmm. mmio_device_manager
@@ -675,6 +688,7 @@ fn attach_entropy_device(
675
688
entropy_device. clone ( ) ,
676
689
cmdline,
677
690
false ,
691
+ false ,
678
692
)
679
693
}
680
694
@@ -683,6 +697,7 @@ fn attach_block_devices<'a, I: Iterator<Item = &'a Arc<Mutex<Block>>> + Debug>(
683
697
cmdline : & mut LoaderKernelCmdline ,
684
698
blocks : I ,
685
699
event_manager : & mut EventManager ,
700
+ secret_free : bool ,
686
701
) -> Result < ( ) , StartMicrovmError > {
687
702
for block in blocks {
688
703
let ( id, is_vhost_user) = {
@@ -707,6 +722,7 @@ fn attach_block_devices<'a, I: Iterator<Item = &'a Arc<Mutex<Block>>> + Debug>(
707
722
block. clone ( ) ,
708
723
cmdline,
709
724
is_vhost_user,
725
+ secret_free,
710
726
) ?;
711
727
}
712
728
Ok ( ( ) )
@@ -717,11 +733,20 @@ fn attach_net_devices<'a, I: Iterator<Item = &'a Arc<Mutex<Net>>> + Debug>(
717
733
cmdline : & mut LoaderKernelCmdline ,
718
734
net_devices : I ,
719
735
event_manager : & mut EventManager ,
736
+ secret_free : bool ,
720
737
) -> Result < ( ) , StartMicrovmError > {
721
738
for net_device in net_devices {
722
739
let id = net_device. lock ( ) . expect ( "Poisoned lock" ) . id ( ) . clone ( ) ;
723
740
// The device mutex mustn't be locked here otherwise it will deadlock.
724
- attach_virtio_device ( event_manager, vmm, id, net_device. clone ( ) , cmdline, false ) ?;
741
+ attach_virtio_device (
742
+ event_manager,
743
+ vmm,
744
+ id,
745
+ net_device. clone ( ) ,
746
+ cmdline,
747
+ false ,
748
+ secret_free,
749
+ ) ?;
725
750
}
726
751
Ok ( ( ) )
727
752
}
@@ -731,10 +756,19 @@ fn attach_unixsock_vsock_device(
731
756
cmdline : & mut LoaderKernelCmdline ,
732
757
unix_vsock : & Arc < Mutex < Vsock < VsockUnixBackend > > > ,
733
758
event_manager : & mut EventManager ,
759
+ secret_free : bool ,
734
760
) -> Result < ( ) , MmioError > {
735
761
let id = String :: from ( unix_vsock. lock ( ) . expect ( "Poisoned lock" ) . id ( ) ) ;
736
762
// The device mutex mustn't be locked here otherwise it will deadlock.
737
- attach_virtio_device ( event_manager, vmm, id, unix_vsock. clone ( ) , cmdline, false )
763
+ attach_virtio_device (
764
+ event_manager,
765
+ vmm,
766
+ id,
767
+ unix_vsock. clone ( ) ,
768
+ cmdline,
769
+ false ,
770
+ secret_free,
771
+ )
738
772
}
739
773
740
774
fn attach_balloon_device (
@@ -745,7 +779,15 @@ fn attach_balloon_device(
745
779
) -> Result < ( ) , MmioError > {
746
780
let id = String :: from ( balloon. lock ( ) . expect ( "Poisoned lock" ) . id ( ) ) ;
747
781
// The device mutex mustn't be locked here otherwise it will deadlock.
748
- attach_virtio_device ( event_manager, vmm, id, balloon. clone ( ) , cmdline, false )
782
+ attach_virtio_device (
783
+ event_manager,
784
+ vmm,
785
+ id,
786
+ balloon. clone ( ) ,
787
+ cmdline,
788
+ false ,
789
+ false ,
790
+ )
749
791
}
750
792
751
793
// Adds `O_NONBLOCK` to the stdout flags.
@@ -921,6 +963,7 @@ pub(crate) mod tests {
921
963
cmdline,
922
964
block_dev_configs. devices . iter ( ) ,
923
965
event_manager,
966
+ false ,
924
967
)
925
968
. unwrap ( ) ;
926
969
block_files
@@ -935,7 +978,7 @@ pub(crate) mod tests {
935
978
let mut net_builder = NetBuilder :: new ( ) ;
936
979
net_builder. build ( net_config) . unwrap ( ) ;
937
980
938
- let res = attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager) ;
981
+ let res = attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager, false ) ;
939
982
res. unwrap ( ) ;
940
983
}
941
984
@@ -956,7 +999,7 @@ pub(crate) mod tests {
956
999
Arc :: new ( Mutex :: new ( mmds) ) ,
957
1000
) ;
958
1001
959
- attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager) . unwrap ( ) ;
1002
+ attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager, false ) . unwrap ( ) ;
960
1003
}
961
1004
962
1005
pub ( crate ) fn insert_vsock_device (
@@ -969,7 +1012,7 @@ pub(crate) mod tests {
969
1012
let vsock = VsockBuilder :: create_unixsock_vsock ( vsock_config) . unwrap ( ) ;
970
1013
let vsock = Arc :: new ( Mutex :: new ( vsock) ) ;
971
1014
972
- attach_unixsock_vsock_device ( vmm, cmdline, & vsock, event_manager) . unwrap ( ) ;
1015
+ attach_unixsock_vsock_device ( vmm, cmdline, & vsock, event_manager, false ) . unwrap ( ) ;
973
1016
974
1017
assert ! (
975
1018
vmm. mmio_device_manager
0 commit comments