@@ -296,16 +296,24 @@ pub fn build_microvm_for_boot(
296
296
& mut boot_cmdline,
297
297
vm_resources. block . devices . iter ( ) ,
298
298
event_manager,
299
+ vm_resources. machine_config . secret_free ,
299
300
) ?;
300
301
attach_net_devices (
301
302
& mut vmm,
302
303
& mut boot_cmdline,
303
304
vm_resources. net_builder . iter ( ) ,
304
305
event_manager,
306
+ vm_resources. machine_config . secret_free ,
305
307
) ?;
306
308
307
309
if let Some ( unix_vsock) = vm_resources. vsock . get ( ) {
308
- attach_unixsock_vsock_device ( & mut vmm, & mut boot_cmdline, unix_vsock, event_manager) ?;
310
+ attach_unixsock_vsock_device (
311
+ & mut vmm,
312
+ & mut boot_cmdline,
313
+ unix_vsock,
314
+ event_manager,
315
+ vm_resources. machine_config . secret_free ,
316
+ ) ?;
309
317
}
310
318
311
319
if let Some ( entropy) = vm_resources. entropy . get ( ) {
@@ -677,9 +685,14 @@ fn attach_virtio_device<T: 'static + VirtioDevice + MutEventSubscriber + Debug>(
677
685
device : Arc < Mutex < T > > ,
678
686
cmdline : & mut LoaderKernelCmdline ,
679
687
is_vhost_user : bool ,
688
+ secret_free : bool ,
680
689
) -> Result < ( ) , MmioError > {
681
690
event_manager. add_subscriber ( device. clone ( ) ) ;
682
691
692
+ if secret_free {
693
+ device. lock ( ) . unwrap ( ) . force_userspace_bounce_buffers ( ) ;
694
+ }
695
+
683
696
// The device mutex mustn't be locked here otherwise it will deadlock.
684
697
let device = MmioTransport :: new ( vmm. vm . guest_memory ( ) . clone ( ) , device, is_vhost_user) ;
685
698
vmm. mmio_device_manager
@@ -735,6 +748,7 @@ fn attach_entropy_device(
735
748
entropy_device. clone ( ) ,
736
749
cmdline,
737
750
false ,
751
+ false ,
738
752
)
739
753
}
740
754
@@ -743,6 +757,7 @@ fn attach_block_devices<'a, I: Iterator<Item = &'a Arc<Mutex<Block>>> + Debug>(
743
757
cmdline : & mut LoaderKernelCmdline ,
744
758
blocks : I ,
745
759
event_manager : & mut EventManager ,
760
+ secret_free : bool ,
746
761
) -> Result < ( ) , StartMicrovmError > {
747
762
for block in blocks {
748
763
let ( id, is_vhost_user) = {
@@ -767,6 +782,7 @@ fn attach_block_devices<'a, I: Iterator<Item = &'a Arc<Mutex<Block>>> + Debug>(
767
782
block. clone ( ) ,
768
783
cmdline,
769
784
is_vhost_user,
785
+ secret_free,
770
786
) ?;
771
787
}
772
788
Ok ( ( ) )
@@ -777,11 +793,20 @@ fn attach_net_devices<'a, I: Iterator<Item = &'a Arc<Mutex<Net>>> + Debug>(
777
793
cmdline : & mut LoaderKernelCmdline ,
778
794
net_devices : I ,
779
795
event_manager : & mut EventManager ,
796
+ secret_free : bool ,
780
797
) -> Result < ( ) , StartMicrovmError > {
781
798
for net_device in net_devices {
782
799
let id = net_device. lock ( ) . expect ( "Poisoned lock" ) . id ( ) . clone ( ) ;
783
800
// The device mutex mustn't be locked here otherwise it will deadlock.
784
- attach_virtio_device ( event_manager, vmm, id, net_device. clone ( ) , cmdline, false ) ?;
801
+ attach_virtio_device (
802
+ event_manager,
803
+ vmm,
804
+ id,
805
+ net_device. clone ( ) ,
806
+ cmdline,
807
+ false ,
808
+ secret_free,
809
+ ) ?;
785
810
}
786
811
Ok ( ( ) )
787
812
}
@@ -791,10 +816,19 @@ fn attach_unixsock_vsock_device(
791
816
cmdline : & mut LoaderKernelCmdline ,
792
817
unix_vsock : & Arc < Mutex < Vsock < VsockUnixBackend > > > ,
793
818
event_manager : & mut EventManager ,
819
+ secret_free : bool ,
794
820
) -> Result < ( ) , MmioError > {
795
821
let id = String :: from ( unix_vsock. lock ( ) . expect ( "Poisoned lock" ) . id ( ) ) ;
796
822
// The device mutex mustn't be locked here otherwise it will deadlock.
797
- attach_virtio_device ( event_manager, vmm, id, unix_vsock. clone ( ) , cmdline, false )
823
+ attach_virtio_device (
824
+ event_manager,
825
+ vmm,
826
+ id,
827
+ unix_vsock. clone ( ) ,
828
+ cmdline,
829
+ false ,
830
+ secret_free,
831
+ )
798
832
}
799
833
800
834
fn attach_balloon_device (
@@ -805,7 +839,15 @@ fn attach_balloon_device(
805
839
) -> Result < ( ) , MmioError > {
806
840
let id = String :: from ( balloon. lock ( ) . expect ( "Poisoned lock" ) . id ( ) ) ;
807
841
// The device mutex mustn't be locked here otherwise it will deadlock.
808
- attach_virtio_device ( event_manager, vmm, id, balloon. clone ( ) , cmdline, false )
842
+ attach_virtio_device (
843
+ event_manager,
844
+ vmm,
845
+ id,
846
+ balloon. clone ( ) ,
847
+ cmdline,
848
+ false ,
849
+ false ,
850
+ )
809
851
}
810
852
811
853
// Adds `O_NONBLOCK` to the stdout flags.
@@ -981,6 +1023,7 @@ pub(crate) mod tests {
981
1023
cmdline,
982
1024
block_dev_configs. devices . iter ( ) ,
983
1025
event_manager,
1026
+ false ,
984
1027
)
985
1028
. unwrap ( ) ;
986
1029
block_files
@@ -995,7 +1038,7 @@ pub(crate) mod tests {
995
1038
let mut net_builder = NetBuilder :: new ( ) ;
996
1039
net_builder. build ( net_config) . unwrap ( ) ;
997
1040
998
- let res = attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager) ;
1041
+ let res = attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager, false ) ;
999
1042
res. unwrap ( ) ;
1000
1043
}
1001
1044
@@ -1016,7 +1059,7 @@ pub(crate) mod tests {
1016
1059
Arc :: new ( Mutex :: new ( mmds) ) ,
1017
1060
) ;
1018
1061
1019
- attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager) . unwrap ( ) ;
1062
+ attach_net_devices ( vmm, cmdline, net_builder. iter ( ) , event_manager, false ) . unwrap ( ) ;
1020
1063
}
1021
1064
1022
1065
pub ( crate ) fn insert_vsock_device (
@@ -1029,7 +1072,7 @@ pub(crate) mod tests {
1029
1072
let vsock = VsockBuilder :: create_unixsock_vsock ( vsock_config) . unwrap ( ) ;
1030
1073
let vsock = Arc :: new ( Mutex :: new ( vsock) ) ;
1031
1074
1032
- attach_unixsock_vsock_device ( vmm, cmdline, & vsock, event_manager) . unwrap ( ) ;
1075
+ attach_unixsock_vsock_device ( vmm, cmdline, & vsock, event_manager, false ) . unwrap ( ) ;
1033
1076
1034
1077
assert ! (
1035
1078
vmm. mmio_device_manager
0 commit comments