@@ -146,7 +146,9 @@ impl Vcpu {
146
146
147
147
/// Registers a signal handler which makes use of TLS and kvm immediate exit to
148
148
/// 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
+
150
152
extern "C" fn handle_signal ( _: c_int , _: * mut siginfo_t , _: * mut c_void ) {
151
153
// SAFETY: This is safe because it's temporarily aliasing the `Vcpu` object, but we are
152
154
// only reading `vcpu.fd` which does not change for the lifetime of the `Vcpu`.
@@ -222,7 +224,7 @@ impl Vcpu {
222
224
. name ( format ! ( "fc_vcpu {}" , self . kvm_vcpu. index) )
223
225
. spawn ( move || {
224
226
let filter = & * seccomp_filter;
225
- self . init_thread_local_data ( ) ;
227
+ self . register_kick_signal_handler ( ) ;
226
228
// Synchronization to make sure thread local data is initialized.
227
229
barrier. wait ( ) ;
228
230
self . run ( filter) ;
@@ -920,7 +922,6 @@ pub(crate) mod tests {
920
922
}
921
923
922
924
fn vcpu_configured_for_boot ( ) -> ( Vm , VcpuHandle , EventFd ) {
923
- Vcpu :: register_kick_signal_handler ( ) ;
924
925
// Need enough mem to boot linux.
925
926
let mem_size = mib_to_bytes ( 64 ) ;
926
927
let ( kvm, vm, mut vcpu) = setup_vcpu ( mem_size) ;
@@ -1021,7 +1022,6 @@ pub(crate) mod tests {
1021
1022
1022
1023
#[ test]
1023
1024
fn test_vcpu_kick ( ) {
1024
- Vcpu :: register_kick_signal_handler ( ) ;
1025
1025
let ( _, vm, mut vcpu) = setup_vcpu ( 0x1000 ) ;
1026
1026
1027
1027
let mut kvm_run =
@@ -1035,7 +1035,7 @@ pub(crate) mod tests {
1035
1035
let handle = std:: thread:: Builder :: new ( )
1036
1036
. name ( "test_vcpu_kick" . to_string ( ) )
1037
1037
. spawn ( move || {
1038
- vcpu. init_thread_local_data ( ) ;
1038
+ vcpu. register_kick_signal_handler ( ) ;
1039
1039
// Notify TLS was populated.
1040
1040
vcpu_barrier. wait ( ) ;
1041
1041
// Loop for max 1 second to check if the signal handler has run.
0 commit comments