From ad2eddbd6942296708bf91d3df1fd8c17f6795b5 Mon Sep 17 00:00:00 2001 From: Anurag Saxena Date: Wed, 21 Feb 2024 11:58:35 -0800 Subject: [PATCH] backup --- libs/execution_context/ebpf_core.c | 68 +++++++++++++++++--------- libs/execution_context/ebpf_protocol.h | 24 +++------ 2 files changed, 54 insertions(+), 38 deletions(-) diff --git a/libs/execution_context/ebpf_core.c b/libs/execution_context/ebpf_core.c index 5ee5de801d..5aabd396a2 100644 --- a/libs/execution_context/ebpf_core.c +++ b/libs/execution_context/ebpf_core.c @@ -292,6 +292,7 @@ ebpf_core_terminate() ebpf_platform_terminate(); } +#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED) _Must_inspect_result_ ebpf_result_t ebpf_core_load_code( ebpf_handle_t program_handle, @@ -317,12 +318,17 @@ ebpf_core_load_code( EBPF_OBJECT_RELEASE_REFERENCE((ebpf_core_object_t*)program); EBPF_RETURN_RESULT(retval); } +#endif -#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED) static ebpf_result_t _ebpf_core_protocol_load_code(_In_ const ebpf_operation_load_code_request_t* request) { EBPF_LOG_ENTRY(); + +#if defined(CONFIG_BPF_JIT_DISABLED) && defined(CONFIG_BPF_INTERPRETER_DISABLED) + UNREFERENCED_PARAMETER(request); + EBPF_RETURN_RESULT(EBPF_OPERATION_NOT_SUPPORTED); +#else ebpf_result_t retval; uint8_t* code = NULL; size_t code_length = 0; @@ -359,8 +365,8 @@ _ebpf_core_protocol_load_code(_In_ const ebpf_operation_load_code_request_t* req Done: EBPF_RETURN_RESULT(retval); +#endif // CONFIG_BPF_JIT_DISABLED && CONFIG_BPF_INTERPRETER_DISABLED } -#endif _Must_inspect_result_ ebpf_result_t ebpf_core_resolve_helper( @@ -400,7 +406,6 @@ ebpf_core_resolve_helper( EBPF_RETURN_RESULT(return_value); } -#if !defined(CONFIG_BPF_JIT_DISABLED) static ebpf_result_t _ebpf_core_protocol_resolve_helper( _In_ const ebpf_operation_resolve_helper_request_t* request, @@ -408,6 +413,12 @@ _ebpf_core_protocol_resolve_helper( uint16_t reply_length) { EBPF_LOG_ENTRY(); + +#if defined(CONFIG_BPF_JIT_DISABLED) + UNREFERENCED_PARAMETER(request); + UNREFERENCED_PARAMETER(reply); + EBPF_RETURN_RESULT(EBPF_OPERATION_NOT_SUPPORTED); +#else uint32_t* request_helper_ids = NULL; size_t required_reply_length = 0; size_t helper_id_length; @@ -447,8 +458,8 @@ _ebpf_core_protocol_resolve_helper( ebpf_free(request_helper_ids); EBPF_RETURN_RESULT(return_value); +#endif // CONFIG_BPF_JIT_DISABLED } -#endif _Must_inspect_result_ ebpf_result_t ebpf_core_resolve_maps( @@ -491,7 +502,7 @@ ebpf_core_resolve_maps( EBPF_RETURN_RESULT(return_value); } -#if !defined(CONFIG_BPF_JIT_DISABLED) +// #if !defined(CONFIG_BPF_JIT_DISABLED) static ebpf_result_t _ebpf_core_protocol_resolve_map( _In_ const struct _ebpf_operation_resolve_map_request* request, @@ -499,6 +510,12 @@ _ebpf_core_protocol_resolve_map( uint16_t reply_length) { EBPF_LOG_ENTRY(); + +#if defined(CONFIG_BPF_JIT_DISABLED) + UNREFERENCED_PARAMETER(request); + UNREFERENCED_PARAMETER(reply); + EBPF_RETURN_RESULT(EBPF_OPERATION_NOT_SUPPORTED); +#else size_t map_handle_length; ebpf_result_t return_value = ebpf_safe_size_t_subtract( request->header.length, EBPF_OFFSET_OF(ebpf_operation_resolve_map_request_t, map_handle), &map_handle_length); @@ -526,8 +543,9 @@ _ebpf_core_protocol_resolve_map( Done: EBPF_RETURN_RESULT(return_value); +#endif // CONFIG_BPF_JIT_DISABLED } -#endif +// #endif _Must_inspect_result_ ebpf_result_t ebpf_core_create_map( @@ -578,12 +596,18 @@ _ebpf_core_protocol_create_map( EBPF_RETURN_RESULT(retval); } -#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED) +// #if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED) static ebpf_result_t _ebpf_core_protocol_create_program( _In_ const ebpf_operation_create_program_request_t* request, _Inout_ ebpf_operation_create_program_reply_t* reply) { EBPF_LOG_ENTRY(); + +#if defined(CONFIG_BPF_JIT_DISABLED) && defined(CONFIG_BPF_INTERPRETER_DISABLED) + UNREFERENCED_PARAMETER(request); + UNREFERENCED_PARAMETER(reply); + EBPF_RETURN_RESULT(EBPF_OPERATION_NOT_SUPPORTED); +#else ebpf_result_t retval; ebpf_program_parameters_t parameters = {0}; uint8_t* file_name = NULL; @@ -620,8 +644,9 @@ _ebpf_core_protocol_create_program( Done: EBPF_RETURN_RESULT(retval); +#endif // CONFIG_BPF_JIT_DISABLED && CONFIG_BPF_INTERPRETER_DISABLED } -#endif +// #endif static ebpf_result_t _ebpf_core_protocol_load_native_module( @@ -1597,20 +1622,27 @@ _ebpf_core_protocol_close_handle(_In_ const ebpf_operation_close_handle_request_ EBPF_RETURN_RESULT(ebpf_handle_close(request->handle)); } -#if !defined(CONFIG_BPF_JIT_DISABLED) +// #if !defined(CONFIG_BPF_JIT_DISABLED) static uint64_t _ebpf_core_protocol_get_ec_function( _In_ const ebpf_operation_get_ec_function_request_t* request, _Inout_ ebpf_operation_get_ec_function_reply_t* reply) { EBPF_LOG_ENTRY(); + +#if defined(CONFIG_BPF_JIT_DISABLED) + UNREFERENCED_PARAMETER(request); + UNREFERENCED_PARAMETER(reply); + EBPF_RETURN_RESULT(EBPF_OPERATION_NOT_SUPPORTED); +#else if (request->function != EBPF_EC_FUNCTION_LOG) { return EBPF_INVALID_ARGUMENT; } reply->address = (uint64_t)ebpf_log_function; EBPF_RETURN_RESULT(EBPF_SUCCESS); +#endif // CONFIG_BPF_JIT_DISABLED } -#endif +// #endif // Get helper info for a program or program type. This is used by the jitter/verifier, // not by libbpf which instead uses ebpf_program_get_info @@ -2392,12 +2424,12 @@ typedef struct _ebpf_protocol_handler } const ebpf_protocol_handler_t; #define PROTOCOL_NATIVE_MODE 1 -#if !defined(CONFIG_BPF_JIT_DISABLED) +// #if !defined(CONFIG_BPF_JIT_DISABLED) #define PROTOCOL_JIT_MODE 2 -#endif -#if !defined(CONFIG_BPF_INTERPRETER_DISABLED) +// #endif +// #if !defined(CONFIG_BPF_INTERPRETER_DISABLED) #define PROTOCOL_INTERPRET_MODE 4 -#endif +// #endif #if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED) #define PROTOCOL_JIT_OR_INTERPRET_MODE (PROTOCOL_JIT_MODE | PROTOCOL_INTERPRET_MODE) #define PROTOCOL_ALL_MODES (PROTOCOL_NATIVE_MODE | PROTOCOL_JIT_MODE | PROTOCOL_INTERPRET_MODE) @@ -2475,17 +2507,11 @@ ALIAS_TYPES(get_handle_by_id, get_map_handle_by_id) ALIAS_TYPES(get_handle_by_id, get_program_handle_by_id) static ebpf_protocol_handler_t _ebpf_protocol_handlers[] = { -#if !defined(CONFIG_BPF_JIT_DISABLED) DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_VARIABLE_REPLY(resolve_helper, helper_id, address, PROTOCOL_JIT_MODE), DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_VARIABLE_REPLY(resolve_map, map_handle, address, PROTOCOL_JIT_MODE), -#endif -#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED) DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_FIXED_REPLY(create_program, data, PROTOCOL_JIT_OR_INTERPRET_MODE), -#endif DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_FIXED_REPLY(create_map, data, PROTOCOL_ALL_MODES), -#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED) DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_NO_REPLY(load_code, code, PROTOCOL_JIT_OR_INTERPRET_MODE), -#endif DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_VARIABLE_REPLY(map_find_element, key, value, PROTOCOL_ALL_MODES), DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_NO_REPLY(map_update_element, data, PROTOCOL_ALL_MODES), DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_NO_REPLY(map_update_element_with_handle, key, PROTOCOL_ALL_MODES), @@ -2498,9 +2524,7 @@ static ebpf_protocol_handler_t _ebpf_protocol_handlers[] = { DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_FIXED_REPLY(link_program, data, PROTOCOL_ALL_MODES), DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_NO_REPLY(unlink_program, data, PROTOCOL_ALL_MODES), DECLARE_PROTOCOL_HANDLER_FIXED_REQUEST_NO_REPLY(close_handle, PROTOCOL_ALL_MODES), -#if !defined(CONFIG_BPF_JIT_DISABLED) DECLARE_PROTOCOL_HANDLER_FIXED_REQUEST_FIXED_REPLY(get_ec_function, PROTOCOL_JIT_MODE), -#endif DECLARE_PROTOCOL_HANDLER_FIXED_REQUEST_VARIABLE_REPLY(get_program_info, data, PROTOCOL_ALL_MODES), DECLARE_PROTOCOL_HANDLER_FIXED_REQUEST_VARIABLE_REPLY(get_pinned_map_info, data, PROTOCOL_ALL_MODES), DECLARE_PROTOCOL_HANDLER_FIXED_REQUEST_FIXED_REPLY(get_link_handle_by_id, PROTOCOL_ALL_MODES), diff --git a/libs/execution_context/ebpf_protocol.h b/libs/execution_context/ebpf_protocol.h index 9cac5c347c..215f57bb3a 100644 --- a/libs/execution_context/ebpf_protocol.h +++ b/libs/execution_context/ebpf_protocol.h @@ -9,17 +9,11 @@ typedef enum _ebpf_operation_id { -#if !defined(CONFIG_BPF_JIT_DISABLED) EBPF_OPERATION_RESOLVE_HELPER, EBPF_OPERATION_RESOLVE_MAP, -#endif -#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED) EBPF_OPERATION_CREATE_PROGRAM, -#endif EBPF_OPERATION_CREATE_MAP, -#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED) EBPF_OPERATION_LOAD_CODE, -#endif EBPF_OPERATION_MAP_FIND_ELEMENT, EBPF_OPERATION_MAP_UPDATE_ELEMENT, EBPF_OPERATION_MAP_UPDATE_ELEMENT_WITH_HANDLE, @@ -31,9 +25,7 @@ typedef enum _ebpf_operation_id EBPF_OPERATION_LINK_PROGRAM, EBPF_OPERATION_UNLINK_PROGRAM, EBPF_OPERATION_CLOSE_HANDLE, -#if !defined(CONFIG_BPF_JIT_DISABLED) EBPF_OPERATION_GET_EC_FUNCTION, -#endif EBPF_OPERATION_GET_PROGRAM_INFO, EBPF_OPERATION_GET_PINNED_MAP_INFO, EBPF_OPERATION_GET_LINK_HANDLE_BY_ID, @@ -74,7 +66,7 @@ typedef enum _ebpf_ec_function EBPF_EC_FUNCTION_LOG } ebpf_ec_function_t; -#if !defined(CONFIG_BPF_JIT_DISABLED) +// #if !defined(CONFIG_BPF_JIT_DISABLED) typedef struct _ebpf_operation_resolve_helper_request { struct _ebpf_operation_header header; @@ -100,9 +92,9 @@ typedef struct _ebpf_operation_resolve_map_reply struct _ebpf_operation_header header; uintptr_t address[1]; } ebpf_operation_resolve_map_reply_t; -#endif +// #endif -#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED) +// #if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED) typedef struct _ebpf_operation_create_program_request { struct _ebpf_operation_header header; @@ -117,9 +109,9 @@ typedef struct _ebpf_operation_create_program_reply struct _ebpf_operation_header header; ebpf_handle_t program_handle; } ebpf_operation_create_program_reply_t; -#endif +// #endif -#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED) +// #if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED) typedef struct _ebpf_operation_load_code_request { struct _ebpf_operation_header header; @@ -127,7 +119,7 @@ typedef struct _ebpf_operation_load_code_request ebpf_code_type_t code_type; uint8_t code[1]; } ebpf_operation_load_code_request_t; -#endif +// #endif typedef struct _ebpf_operation_create_map_request { @@ -283,7 +275,7 @@ typedef struct _ebpf_operation_close_handle_request ebpf_handle_t handle; } ebpf_operation_close_handle_request_t; -#if !defined(CONFIG_BPF_JIT_DISABLED) +// #if !defined(CONFIG_BPF_JIT_DISABLED) typedef struct _ebpf_operation_get_ec_function_request { struct _ebpf_operation_header header; @@ -295,7 +287,7 @@ typedef struct _ebpf_operation_get_ec_function_reply struct _ebpf_operation_header header; uintptr_t address; } ebpf_operation_get_ec_function_reply_t; -#endif +// #endif typedef struct _ebpf_operation_get_program_info_request {