Skip to content

Commit

Permalink
hcl: fix multiple calls to flush_deferred_actions (#739) (#822)
Browse files Browse the repository at this point in the history
Don't remove the deferred action list from TLS until the
`ProcessorRunner` is actually dropped.

This fixes crashes after a failed servicing operation.

Backport-of: #739
  • Loading branch information
jstarks authored Feb 8, 2025
1 parent 64131d1 commit b63600a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions openhcl/hcl/src/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,8 @@ mod private {
impl<T> Drop for ProcessorRunner<'_, T> {
fn drop(&mut self) {
self.flush_deferred_actions();
let actions = DEFERRED_ACTIONS.with(|actions| actions.take());
assert!(actions.is_none_or(|a| a.is_empty()));
let old_state = std::mem::replace(&mut *self.vp.state.lock(), VpState::NotRunning);
assert!(matches!(old_state, VpState::Running(thread) if thread == Pthread::current()));
}
Expand All @@ -1710,8 +1712,10 @@ impl<T> ProcessorRunner<'_, T> {
/// actions will be lost.
pub fn flush_deferred_actions(&mut self) {
if self.sidecar.is_none() {
let mut deferred_actions = DEFERRED_ACTIONS.with(|state| state.take().unwrap());
deferred_actions.run_actions(self.hcl);
DEFERRED_ACTIONS.with(|actions| {
let mut actions = actions.borrow_mut();
actions.as_mut().unwrap().run_actions(self.hcl);
})
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions openhcl/hcl/src/ioctl/deferred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ impl DeferredActions {
}
}

pub fn is_empty(&self) -> bool {
self.actions.is_empty()
}

/// Copies the queued actions to the slots in the run page. Issues any
/// immediately that won't fit in the run page.
pub fn copy_to_slots(&mut self, slots: &mut DeferredActionSlots, hcl: &Hcl) {
Expand Down

0 comments on commit b63600a

Please sign in to comment.