Skip to content

Commit b6655b4

Browse files
committed
refactor: move kick signal registration to Vcpu
Let vcpus register the signal handler instead of doing this manually. This way the thread local is guarantied to be set before new signal handler is able to run. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent 5408cc9 commit b6655b4

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/vmm/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,6 @@ impl Vmm {
375375
})?;
376376
}
377377

378-
Vcpu::register_kick_signal_handler();
379-
380378
self.vcpus_handles.reserve(vcpu_count);
381379

382380
for mut vcpu in vcpus.drain(..) {

src/vmm/src/vstate/vcpu.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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(&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);

0 commit comments

Comments
 (0)