@@ -146,7 +146,9 @@ impl Vcpu {
146146
147147 /// Registers a signal handler which makes use of TLS and kvm immediate exit to
148148 /// kick the vcpu running on the current thread, if there is one.
149- pub fn register_kick_signal_handler ( ) {
149+ pub fn register_kick_signal_handler ( & mut self ) {
150+ self . init_thread_local_data ( ) ;
151+
150152 extern "C" fn handle_signal ( _: c_int , _: * mut siginfo_t , _: * mut c_void ) {
151153 // SAFETY: This is safe because it's temporarily aliasing the `Vcpu` object, but we are
152154 // only reading `vcpu.fd` which does not change for the lifetime of the `Vcpu`.
@@ -222,7 +224,7 @@ impl Vcpu {
222224 . name ( format ! ( "fc_vcpu {}" , self . kvm_vcpu. index) )
223225 . spawn ( move || {
224226 let filter = & * seccomp_filter;
225- self . init_thread_local_data ( ) ;
227+ self . register_kick_signal_handler ( ) ;
226228 // Synchronization to make sure thread local data is initialized.
227229 barrier. wait ( ) ;
228230 self . run ( filter) ;
@@ -920,7 +922,6 @@ pub(crate) mod tests {
920922 }
921923
922924 fn vcpu_configured_for_boot ( ) -> ( Vm , VcpuHandle , EventFd ) {
923- Vcpu :: register_kick_signal_handler ( ) ;
924925 // Need enough mem to boot linux.
925926 let mem_size = mib_to_bytes ( 64 ) ;
926927 let ( kvm, vm, mut vcpu) = setup_vcpu ( mem_size) ;
@@ -1021,7 +1022,6 @@ pub(crate) mod tests {
10211022
10221023 #[ test]
10231024 fn test_vcpu_kick ( ) {
1024- Vcpu :: register_kick_signal_handler ( ) ;
10251025 let ( _, vm, mut vcpu) = setup_vcpu ( 0x1000 ) ;
10261026
10271027 let mut kvm_run =
@@ -1035,7 +1035,7 @@ pub(crate) mod tests {
10351035 let handle = std:: thread:: Builder :: new ( )
10361036 . name ( "test_vcpu_kick" . to_string ( ) )
10371037 . spawn ( move || {
1038- vcpu. init_thread_local_data ( ) ;
1038+ vcpu. register_kick_signal_handler ( ) ;
10391039 // Notify TLS was populated.
10401040 vcpu_barrier. wait ( ) ;
10411041 // Loop for max 1 second to check if the signal handler has run.
0 commit comments