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

Support TraceLoggingBinary for map find, update and delete. #3781

Merged
merged 49 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
45a9158
Initial commit
shpalani Aug 17, 2024
55b5c2a
Merge branch 'main' into shpalan/map-find
shpalani Aug 21, 2024
532aa5e
Initial commit
shpalani Aug 22, 2024
abeb90d
Added _DEBUG around tail call display
shpalani Aug 23, 2024
8084769
Merge branch 'main' into shpalan/map-find
shpalani Aug 23, 2024
96e6220
Renamed key to data
shpalani Aug 23, 2024
e3bcd07
Merge branch 'shpalan/map-find' of https://github.com/shpalani/ebpf-f…
shpalani Aug 23, 2024
4d77de6
Removed _DEBUG
shpalani Aug 24, 2024
e2be6c6
Added SAL annotation, as per the comments
shpalani Aug 24, 2024
d3fa44f
Added SAL annotation, as per the comments
shpalani Aug 24, 2024
9354006
Merge branch 'main' into shpalan/map-find
shpalani Aug 24, 2024
3cf1e04
Merge branch 'main' into shpalan/map-find
shpalani Aug 26, 2024
da02fd1
Fix crash
shpalani Aug 26, 2024
dd7da62
make data non-optional
shpalani Aug 26, 2024
ef71fc2
Added the check for .key_size != 0
shpalani Aug 27, 2024
3d557d7
Merge branch 'main' into shpalan/map-find
shpalani Aug 29, 2024
ca9c05a
Merge branch 'main' into shpalan/map-find
shpalani Sep 3, 2024
45e57f4
Merge branch 'main' into shpalan/map-find
shpalani Sep 5, 2024
36f7c2e
Removed additional tracing in EBPF_LOG_MESSAGE_BINARY macro
shpalani Sep 6, 2024
152fca5
Merge branch 'shpalan/map-find' of https://github.com/shpalani/ebpf-f…
shpalani Sep 6, 2024
13a7c50
Merge branch 'main' into shpalan/map-find
shpalani Sep 9, 2024
ec67f4e
Merged with main
shpalani Sep 9, 2024
6342c9b
Merge branch 'main' into shpalan/map-find
shpalani Sep 9, 2024
0e471eb
Trying 16KB of stack size
shpalani Sep 10, 2024
17f3495
Addressed PR comment
shpalani Sep 10, 2024
8c45f68
Added macro with combined traces
shpalani Sep 12, 2024
f2ef43d
Increased stack size to 32K for DEBUG image
shpalani Sep 17, 2024
1de366d
Merge branch 'main' into shpalan/map-find
shpalani Sep 17, 2024
af32fae
Fix the string concatenation in macro
shpalani Sep 18, 2024
5fc7ede
Merge branch 'main' into shpalan/map-find
shpalani Sep 18, 2024
b6d53cc
Merge branch 'shpalan/map-find' of https://github.com/shpalani/ebpf-f…
shpalani Sep 18, 2024
f809dac
Merge branch 'main' into shpalan/map-find
shpalani Sep 19, 2024
714ff58
Merge branch 'main' into shpalan/map-find
shpalani Sep 20, 2024
284ae4f
Merge branch 'main' into shpalan/map-find
shpalani Sep 23, 2024
7a53ce9
Merge branch 'main' into shpalan/map-find
shpalani Sep 24, 2024
7c45c39
Merge branch 'shpalan/map-find' of https://github.com/shpalani/ebpf-f…
shpalani Sep 24, 2024
7c03419
Increase the stack size to 64, and added some logs to check the crash…
shpalani Sep 24, 2024
ac25174
Added retry when the dump file cannot be compressed because it is use…
shpalani Sep 25, 2024
17294e2
Expanded stack size for all netebpf wfp callouts
shpalani Sep 27, 2024
fc505fd
Merge branch 'main' into shpalan/map-find
shpalani Sep 27, 2024
94e826c
Addressed PR comments
shpalani Sep 27, 2024
4646ac7
Added _DEBUG back
shpalani Sep 27, 2024
44a3cab
Increased stack size to 20K for DEBUG
shpalani Sep 28, 2024
6b4c2ed
Add optimatization
shpalani Sep 30, 2024
c0df804
With 4K stack expansion size
shpalani Oct 1, 2024
a1550c0
Merge branch 'main' into shpalan/map-find
shpalani Oct 1, 2024
396af87
Final commit
shpalani Oct 2, 2024
9c8312c
Merge branch 'main' into shpalan/map-find
shpalani Oct 2, 2024
5a34919
Merge branch 'shpalan/map-find' of https://github.com/shpalani/ebpf-f…
shpalani Oct 2, 2024
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
41 changes: 41 additions & 0 deletions libs/execution_context/ebpf_maps.c
Original file line number Diff line number Diff line change
Expand Up @@ -2450,6 +2450,20 @@ ebpf_map_find_entry(
{
// High volume call - Skip entry/exit logging.
uint8_t* return_value = NULL;

#ifdef _DEBUG
if ((flags & EBPF_MAP_FLAG_HELPER)) {
EBPF_LOG_MESSAGE_BINARY(
EBPF_TRACELOG_LEVEL_INFO,
EBPF_TRACELOG_KEYWORD_MAP,
"Map lookup",
_ebpf_map_display_names[map->ebpf_map_definition.type],
&map->name,
key,
map->ebpf_map_definition.key_size);
}
#endif // _DEBUG

if (!(flags & EBPF_MAP_FLAG_HELPER) && (key_size != map->ebpf_map_definition.key_size)) {
EBPF_LOG_MESSAGE_UINT64_UINT64(
EBPF_TRACELOG_LEVEL_ERROR,
Expand Down Expand Up @@ -2564,6 +2578,19 @@ ebpf_map_update_entry(
// High volume call - Skip entry/exit logging.
ebpf_result_t result;

#ifdef _DEBUG
if ((flags & EBPF_MAP_FLAG_HELPER)) {
EBPF_LOG_MESSAGE_BINARY(
EBPF_TRACELOG_LEVEL_INFO,
EBPF_TRACELOG_KEYWORD_MAP,
"Map update",
_ebpf_map_display_names[map->ebpf_map_definition.type],
&map->name,
key,
map->ebpf_map_definition.key_size);
}
#endif // _DEBUG

if (ebpf_map_metadata_tables[map->ebpf_map_definition.type].zero_length_key) {
if (key_size != 0) {
EBPF_LOG_MESSAGE_UINT64(
Expand Down Expand Up @@ -2649,6 +2676,20 @@ _Must_inspect_result_ ebpf_result_t
ebpf_map_delete_entry(_In_ ebpf_map_t* map, size_t key_size, _In_reads_(key_size) const uint8_t* key, int flags)
{
// High volume call - Skip entry/exit logging.

#ifdef _DEBUG
if ((flags & EBPF_MAP_FLAG_HELPER)) {
EBPF_LOG_MESSAGE_BINARY(
EBPF_TRACELOG_LEVEL_INFO,
EBPF_TRACELOG_KEYWORD_MAP,
"Map delete",
_ebpf_map_display_names[map->ebpf_map_definition.type],
&map->name,
key,
map->ebpf_map_definition.key_size);
}
#endif // _DEBUG

if (!(flags & EBPF_MAP_FLAG_HELPER) && (key_size != map->ebpf_map_definition.key_size)) {
EBPF_LOG_MESSAGE_UINT64_UINT64(
EBPF_TRACELOG_LEVEL_ERROR,
Expand Down
7 changes: 7 additions & 0 deletions libs/execution_context/ebpf_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,13 @@ ebpf_program_invoke(
ebpf_program_entry_point_t function_pointer;
function_pointer = (ebpf_program_entry_point_t)(current_program->code_or_vm.code.code_pointer);
*result = (function_pointer)(context);
#ifdef _DEBUG
shpalani marked this conversation as resolved.
Show resolved Hide resolved
EBPF_LOG_MESSAGE_UTF8_STRING(
EBPF_TRACELOG_LEVEL_INFO,
EBPF_TRACELOG_KEYWORD_PROGRAM,
"Tail call program",
&current_program->parameters.program_name);
#endif // _DEBUG
} else {
#if !defined(CONFIG_BPF_INTERPRETER_DISABLED)
uint64_t out_value;
Expand Down
14 changes: 14 additions & 0 deletions libs/shared/ebpf_tracelog.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,20 @@ extern "C"
ebpf_log_message_uint64_uint64(_##trace_level##, _##keyword##, message, value1, value2); \
}

void
ebpf_log_message_binary(
ebpf_tracelog_level_t trace_level,
ebpf_tracelog_keyword_t keyword,
_In_z_ const char* message,
_In_z_ const char* type,
_In_ const cxplat_utf8_string_t* name,
const void* data,
shpalani marked this conversation as resolved.
Show resolved Hide resolved
uint32_t data_size);
#define EBPF_LOG_MESSAGE_BINARY(trace_level, keyword, message, type, name, data, data_size) \
if (TraceLoggingProviderEnabled(ebpf_tracelog_provider, trace_level, keyword)) { \
ebpf_log_message_binary(_##trace_level##, _##keyword##, message, type, name, data, data_size); \
}

void
ebpf_log_message_error(
ebpf_tracelog_level_t trace_level,
Expand Down
83 changes: 83 additions & 0 deletions libs/shared/tracelog.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,89 @@ __declspec(noinline) void ebpf_log_message_uint64_uint64(
}
}

#define _EBPF_LOG_MESSAGE_BINARY(trace_level, keyword, message, type, name, data, data_size) \
TraceLoggingWrite( \
ebpf_tracelog_provider, \
EBPF_TRACELOG_EVENT_GENERIC_MESSAGE, \
TraceLoggingLevel((trace_level)), \
TraceLoggingKeyword((keyword)), \
TraceLoggingString((message), "Message"), \
TraceLoggingString((type), "Type"), \
TraceLoggingCountedUtf8String((const char*)(name)->value, (unsigned long)(name)->length, #name), \
TraceLoggingBinary((data), (data_size)));
#define EBPF_LOG_MESSAGE_BINARY_KEYWORD_SWITCH(trace_level, message, type, name, data, data_size) \
switch (keyword) { \
CASE_FUNCTION_ENTRY_EXIT: \
_EBPF_LOG_MESSAGE_BINARY(trace_level, KEYWORD_FUNCTION_ENTRY_EXIT, message, type, name, data, data_size); \
break; \
CASE_BASE: \
_EBPF_LOG_MESSAGE_BINARY(trace_level, KEYWORD_BASE, message, type, name, data, data_size); \
break; \
CASE_ERROR: \
_EBPF_LOG_MESSAGE_BINARY(trace_level, KEYWORD_ERROR, message, type, name, data, data_size); \
break; \
CASE_EPOCH: \
_EBPF_LOG_MESSAGE_BINARY(trace_level, KEYWORD_EPOCH, message, type, name, data, data_size); \
break; \
CASE_CORE: \
_EBPF_LOG_MESSAGE_BINARY(trace_level, KEYWORD_CORE, message, type, name, data, data_size); \
break; \
CASE_LINK: \
_EBPF_LOG_MESSAGE_BINARY(trace_level, KEYWORD_LINK, message, type, name, data, data_size); \
break; \
CASE_MAP: \
_EBPF_LOG_MESSAGE_BINARY(trace_level, KEYWORD_MAP, message, type, name, data, data_size); \
break; \
CASE_PROGRAM: \
_EBPF_LOG_MESSAGE_BINARY(trace_level, KEYWORD_PROGRAM, message, type, name, data, data_size); \
break; \
CASE_API: \
_EBPF_LOG_MESSAGE_BINARY(trace_level, KEYWORD_API, message, type, name, data, data_size); \
break; \
CASE_PRINTK: \
_EBPF_LOG_MESSAGE_BINARY(trace_level, KEYWORD_PRINTK, message, type, name, data, data_size); \
break; \
CASE_NATIVE: \
_EBPF_LOG_MESSAGE_BINARY(trace_level, KEYWORD_NATIVE, message, type, name, data, data_size); \
break; \
default: \
ebpf_assert(!"Invalid keyword"); \
break; \
}
__declspec(noinline) void ebpf_log_message_binary(
ebpf_tracelog_level_t trace_level,
ebpf_tracelog_keyword_t keyword,
_In_z_ const char* message,
_In_z_ const char* type,
_In_ const cxplat_utf8_string_t* name,
const void* data,
shpalani marked this conversation as resolved.
Show resolved Hide resolved
uint32_t data_size)
{
switch (trace_level) {
CASE_LOG_ALWAYS:
EBPF_LOG_MESSAGE_BINARY_KEYWORD_SWITCH(LEVEL_LOG_ALWAYS, message, type, name, data, data_size);
break;
CASE_CRITICAL:
EBPF_LOG_MESSAGE_BINARY_KEYWORD_SWITCH(LEVEL_CRITICAL, message, type, name, data, data_size);
break;
CASE_LEVEL_ERROR:
EBPF_LOG_MESSAGE_BINARY_KEYWORD_SWITCH(LEVEL_ERROR, message, type, name, data, data_size);
break;
CASE_WARNING:
EBPF_LOG_MESSAGE_BINARY_KEYWORD_SWITCH(LEVEL_WARNING, message, type, name, data, data_size);
break;
CASE_INFO:
EBPF_LOG_MESSAGE_BINARY_KEYWORD_SWITCH(LEVEL_INFO, message, type, name, data, data_size);
break;
CASE_VERBOSE:
EBPF_LOG_MESSAGE_BINARY_KEYWORD_SWITCH(LEVEL_VERBOSE, message, type, name, data, data_size);
break;
default:
ebpf_assert(!"Invalid trace level");
break;
}
}

#define _EBPF_LOG_MESSAGE_ERROR(trace_level, keyword, message, error) \
TraceLoggingWrite( \
ebpf_tracelog_provider, \
Expand Down
Loading