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

Remove JIT and interpreter code from NativeOnly builds #2475

Merged
merged 8 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
PR feedback from Anurag
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
  • Loading branch information
dthaler committed Jun 6, 2023
commit f9815805284d4890c35546578ce607aaa51c2e04
2 changes: 1 addition & 1 deletion libs/api/api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ ebpf_api_elf_enumerate_sections(
_Outptr_result_maybenull_ ebpf_section_info_t** infos,
_Outptr_result_maybenull_z_ const char** error_message) noexcept;

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
/**
* @brief Load an eBPF programs from raw instructions.
*
Expand Down
12 changes: 6 additions & 6 deletions libs/api/ebpf_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "map_descriptors.hpp"
#define _PEPARSE_WINDOWS_CONFLICTS
#include "pe-parse/parse.h"
#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#include "rpc_client.h"
extern "C"
{
Expand Down Expand Up @@ -204,7 +204,7 @@ ebpf_api_initiate() noexcept
// it will be re-attempted before an IOCTL call is made.
(void)initialize_device_handle();

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
RPC_STATUS status = initialize_rpc_binding();

if (status != RPC_S_OK) {
Expand All @@ -227,7 +227,7 @@ ebpf_api_terminate() noexcept
clear_ebpf_provider_data();
_clean_up_ebpf_objects();
clean_up_device_handle();
#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
clean_up_rpc_binding();
#endif
ebpf_trace_terminate();
Expand Down Expand Up @@ -761,7 +761,7 @@ ebpf_map_get_next_key(fd_t map_fd, _In_opt_ const void* previous_key, _Out_ void
EBPF_RETURN_RESULT(result);
}

#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
_create_program(
ebpf_program_type_t program_type,
Expand Down Expand Up @@ -2539,7 +2539,7 @@ _Requires_lock_not_held_(_ebpf_state_mutex) static ebpf_result_t
EBPF_RETURN_RESULT(result);
}

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
_Must_inspect_result_ ebpf_result_t
ebpf_program_load_bytes(
_In_ const ebpf_program_type_t* program_type,
Expand Down Expand Up @@ -2752,7 +2752,7 @@ ebpf_object_load(_Inout_ struct bpf_object* object) noexcept
goto Done;
}

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
result = _ebpf_object_load_programs(object);
#else
result = EBPF_OPERATION_NOT_SUPPORTED;
Expand Down
6 changes: 3 additions & 3 deletions libs/api/libbpf_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bpf_load_program_xattr(const struct bpf_load_program_attr* load_attr, char* log_
return libbpf_err(-EINVAL);
}

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
fd_t program_fd;
ebpf_result_t result = ebpf_program_load_bytes(
program_type,
Expand Down Expand Up @@ -85,7 +85,7 @@ bpf_prog_load(
return libbpf_err(-EINVAL);
}

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
char* log_buffer = (opts) ? opts->log_buf : nullptr;
size_t log_buffer_size = (opts) ? opts->log_size : 0;

Expand Down Expand Up @@ -709,4 +709,4 @@ bpf_prog_test_run_opts(int prog_fd, struct bpf_test_run_opts* opts)
opts->duration = (uint32_t)options.duration;

return 0;
}
}
10 changes: 5 additions & 5 deletions libs/execution_context/ebpf_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ ebpf_core_load_code(
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_load_code(_In_ const ebpf_operation_load_code_request_t* request)
{
Expand Down Expand Up @@ -569,7 +569,7 @@ _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)
Expand Down Expand Up @@ -2183,7 +2183,7 @@ typedef struct _ebpf_protocol_handler
#if !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#define PROTOCOL_INTERPRET_MODE 4
#endif
#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#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)
#elif !defined(CONFIG_BPF_JIT_DISABLED)
Expand Down Expand Up @@ -2264,11 +2264,11 @@ static ebpf_protocol_handler_t _ebpf_protocol_handlers[] = {
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)
#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)
#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),
Expand Down
10 changes: 5 additions & 5 deletions libs/execution_context/ebpf_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ typedef enum _ebpf_operation_id
EBPF_OPERATION_RESOLVE_HELPER,
EBPF_OPERATION_RESOLVE_MAP,
#endif
#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#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)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
EBPF_OPERATION_LOAD_CODE,
#endif
EBPF_OPERATION_MAP_FIND_ELEMENT,
Expand Down Expand Up @@ -99,7 +99,7 @@ typedef struct _ebpf_operation_resolve_map_reply
} ebpf_operation_resolve_map_reply_t;
#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;
Expand All @@ -116,7 +116,7 @@ typedef struct _ebpf_operation_create_program_reply
} ebpf_operation_create_program_reply_t;
#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;
Expand Down Expand Up @@ -466,4 +466,4 @@ typedef struct _ebpf_operation_program_test_run_reply
uint64_t return_value;
uint64_t context_offset;
uint8_t data[1];
} ebpf_operation_program_test_run_reply_t;
} ebpf_operation_program_test_run_reply_t;
4 changes: 2 additions & 2 deletions libs/execution_context/unit/execution_context_unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ TEST_CASE("EBPF_OPERATION_RESOLVE_MAP", "[execution_context][negative]")
}
#endif

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
TEST_CASE("EBPF_OPERATION_CREATE_PROGRAM", "[execution_context][negative]")
{
NEGATIVE_TEST_PROLOG();
Expand Down Expand Up @@ -1349,7 +1349,7 @@ TEST_CASE("EBPF_OPERATION_CREATE_MAP", "[execution_context][negative]")
REQUIRE(invoke_protocol(EBPF_OPERATION_CREATE_MAP, request, reply) == EBPF_INVALID_ARGUMENT);
}

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
TEST_CASE("EBPF_OPERATION_LOAD_CODE", "[execution_context][negative]")
{

Expand Down
6 changes: 3 additions & 3 deletions libs/thunk/mock/mock.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MIT

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#include "api_service.h"
#endif
#include "ebpf_api.h"
#include "mock.h"
#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#include "rpc_interface_h.h"
#endif

Expand Down Expand Up @@ -186,7 +186,7 @@ _stop_service(SC_HANDLE service_handle)

} // namespace Platform

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
// RPC related mock functions.

RPC_STATUS
Expand Down
2 changes: 1 addition & 1 deletion tests/bpf2c_tests/raw_bpf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ parse_test_file(const std::string& data_file)
return {prefix, mem, result, instructions};
}

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
ubpf_vm*
prepare_ubpf_vm(const std::vector<ebpf_inst> instructions)
{
Expand Down
6 changes: 3 additions & 3 deletions tests/performance/ExecutionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ typedef class _ebpf_program_test_state
ebpf_core_terminate();
}

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
void
prepare_jit_program()
{
Expand Down Expand Up @@ -272,7 +272,7 @@ static ebpf_program_test_state_t* _ebpf_program_test_state_instance = nullptr;
static ebpf_map_test_state_t* _ebpf_map_test_state_instance = nullptr;
static ebpf_map_lpm_trie_test_state_t* _ebpf_map_lpm_trie_test_state_instance = nullptr;

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
static void
_ebpf_program_invoke()
{
Expand Down Expand Up @@ -422,7 +422,7 @@ test_bpf_map_lookup_lru_elem(bool preemptible)
measure.run_test();
}

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
void
test_program_invoke_jit(bool preemptible)
{
Expand Down