Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap calls from ebpf_drv.c in epoch calls #2189

Merged
merged 4 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions ebpfcore/ebpf_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

#include "ebpf_core.h"
#include "ebpf_object.h"

#include <wdf.h>

Expand Down Expand Up @@ -203,10 +202,7 @@ static void
_ebpf_driver_file_close(WDFFILEOBJECT wdf_file_object)
{
FILE_OBJECT* file_object = WdfFileObjectWdmGetFileObject(wdf_file_object);
ebpf_base_object_t* base_object = file_object->FsContext2;
if (base_object != NULL) {
base_object->release_reference(base_object);
}
ebpf_core_close_context(file_object->FsContext2);
}

static void
Expand Down
26 changes: 21 additions & 5 deletions libs/execution_context/ebpf_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2310,10 +2310,8 @@ ebpf_core_invoke_protocol_handler(
goto Done;
}

retval = ebpf_epoch_enter();
if (retval != EBPF_SUCCESS) {
goto Done;
}
ebpf_epoch_enter();
retval = EBPF_SUCCESS;
epoch_entered = true;

switch (handler->call_type) {
Expand Down Expand Up @@ -2384,5 +2382,23 @@ ebpf_core_invoke_protocol_handler(
bool
ebpf_core_cancel_protocol_handler(_Inout_ void* async_context)
{
return ebpf_async_cancel(async_context);
ebpf_epoch_enter();
bool return_value = ebpf_async_cancel(async_context);
ebpf_epoch_exit();
return return_value;
}

void
ebpf_core_close_context(_In_opt_ void* context)
{
if (!context) {
return;
}

ebpf_epoch_enter();
Alan-Jowett marked this conversation as resolved.
Show resolved Hide resolved

ebpf_core_object_t* object = (ebpf_core_object_t*)context;
object->base.release_reference(object);

ebpf_epoch_exit();
}
8 changes: 8 additions & 0 deletions libs/execution_context/ebpf_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ extern "C"
_In_reads_(count_of_helpers) const uint32_t* helper_function_ids,
_Out_writes_(count_of_helpers) uint64_t* helper_function_addresses);

/**
* @brief Close the FsContext2 from a file object.
*
* @param[in] context The FsContext2 from a fileobject to close.
*/
void
ebpf_core_close_context(_In_opt_ void* context);

#ifdef __cplusplus
}
#endif
5 changes: 1 addition & 4 deletions libs/execution_context/ebpf_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,7 @@ _ebpf_link_instance_invoke_batch_begin(
goto Done;
}

return_value = ebpf_epoch_enter();
if (return_value != EBPF_SUCCESS) {
goto Done;
}
ebpf_epoch_enter();
epoch_entered = true;

return_value = ebpf_program_reference_providers(link->program);
Expand Down
10 changes: 2 additions & 8 deletions libs/execution_context/ebpf_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -1710,10 +1710,7 @@ _ebpf_program_test_run_work_item(_Inout_opt_ void* work_item_context)
old_irql = ebpf_raise_irql(context->required_irql);
irql_raised = true;

result = ebpf_epoch_enter();
if (result != EBPF_SUCCESS) {
goto Done;
}
ebpf_epoch_enter();
epoch_entered = true;

ebpf_get_execution_context_state(&execution_context_state);
Expand All @@ -1727,10 +1724,7 @@ _ebpf_program_test_run_work_item(_Inout_opt_ void* work_item_context)
// Start a new epoch every batch_size iterations.
if ((i % batch_size == (batch_size - 1))) {
ebpf_epoch_exit();
result = ebpf_epoch_enter();
if (result != EBPF_SUCCESS) {
break;
}
ebpf_epoch_enter();
}
ebpf_program_invoke(context->program, context->context, &return_value, &execution_context_state);
if (ebpf_should_yield_processor()) {
Expand Down
Loading