Skip to content

Commit

Permalink
Add workaround for NmrRegisterClient calling detach (#3594)
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Jowett <[email protected]>
Co-authored-by: Alan Jowett <[email protected]>
  • Loading branch information
Alan-Jowett and Alan Jowett authored May 31, 2024
1 parent effcfdb commit 22742b4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions libs/execution_context/ebpf_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,18 @@ _ebpf_program_type_specific_program_information_detach_provider(void* client_bin
// to the program information.
ebpf_lock_unlock(&program->lock, state);

// Wait for any threads executing in the current epoch to complete.
ebpf_epoch_synchronize();
// Note: NmrRegisterClient can synchronously call the attach and then the detach callback. This can result in the
// detach callback being called inside an epoch, which will result in a deadlock. To prevent this, detect when
// the detach is being called prior to the object being fully initialized, where it is safe to assume that no other
// threads are using the object.

// Check if the program is visible to any other threads.
// Until an object id is assigned, this program can not be used by any other thread and therefore can not have
// any links or be invoked.
if (program->object.id != 0) {
// Wait for any threads executing in the current epoch to complete.
ebpf_epoch_synchronize();
}
return STATUS_SUCCESS;
}

Expand Down

0 comments on commit 22742b4

Please sign in to comment.