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

Isolate eBPF store APIs into atomic km & um libraries. #2690

Merged
merged 63 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
c11fb36
draft
gtrevi Jun 21, 2023
6e7d7c1
wip
gtrevi Jun 22, 2023
ea9203e
wip
gtrevi Jun 22, 2023
b2a218c
wip
gtrevi Jun 23, 2023
93af0c4
wip
gtrevi Jun 24, 2023
4662099
wip - km & um compile
gtrevi Jul 17, 2023
9f7b461
fix
gtrevi Jul 17, 2023
c331eff
fix include order
gtrevi Jul 17, 2023
b8ef664
wip
gtrevi Jul 17, 2023
b2a4e2d
wip
gtrevi Jul 18, 2023
2313155
wip
gtrevi Jul 18, 2023
7a08efb
wip - api_common
gtrevi Jul 18, 2023
36c878a
wip - updated projects
gtrevi Jul 18, 2023
a8027c3
wip
gtrevi Jul 18, 2023
76bf472
wip
gtrevi Jul 18, 2023
18c4c03
Merge branch 'main' into gtrevi/reg-api
gtrevi Jul 18, 2023
5cc7ef1
fix merge issues
gtrevi Jul 18, 2023
289ea99
wip
gtrevi Jul 18, 2023
c9c41f3
fix C28196/C6387
gtrevi Jul 18, 2023
88974ea
wip
gtrevi Jul 19, 2023
77cbb89
wip
gtrevi Jul 19, 2023
18c9321
fix SAL
gtrevi Jul 19, 2023
4d0cb8a
cleanup
gtrevi Jul 19, 2023
d1a2fc9
fix SAL bugs
gtrevi Jul 19, 2023
7a19ea3
wip - cmake
gtrevi Jul 19, 2023
1a5c391
add cmake files
gtrevi Jul 19, 2023
a46673b
wip
gtrevi Jul 19, 2023
0d3f566
wip
gtrevi Jul 19, 2023
36001fe
update msi artifacts
gtrevi Jul 19, 2023
a6d241f
wip
gtrevi Jul 19, 2023
d7a6d5d
cleanup
gtrevi Jul 19, 2023
9698a12
collapse null-checks
gtrevi Jul 25, 2023
5456f63
clean-up headers
gtrevi Jul 25, 2023
04a4382
refactor return types to ebpf_result_t
gtrevi Jul 26, 2023
836e0a7
replace ebpf_registry_result_t with ebpf_result_t
gtrevi Jul 26, 2023
6759086
update header
gtrevi Jul 26, 2023
6de7183
remove cpp wrapper, misc cleanup.
gtrevi Jul 27, 2023
42cb008
rename um/km registry helpers
gtrevi Jul 27, 2023
60d07c4
cleanup
gtrevi Jul 27, 2023
8583203
cleanup
gtrevi Jul 27, 2023
c270f55
update
gtrevi Jul 27, 2023
6eb6212
nit
gtrevi Jul 27, 2023
74b6bf8
fix
gtrevi Jul 27, 2023
ed033f1
Added KERNEL_MODE var, so to default to USER_MODE.
gtrevi Jul 27, 2023
b16652f
fix cmake
gtrevi Jul 27, 2023
d8d2203
align result var names with ebpf_result_t
gtrevi Jul 27, 2023
7cd581a
pr feedback
gtrevi Jul 27, 2023
390e92c
Merge branch 'main' into gtrevi/reg-api
gtrevi Jul 28, 2023
e549384
add project refs
gtrevi Jul 28, 2023
b3bbcca
Add NativeOnly* cfgs to ebpf_store_helper_km
gtrevi Jul 28, 2023
4a29ed1
Update docs, API reordering in source.
gtrevi Jul 31, 2023
07fa08d
pr feedback
gtrevi Jul 31, 2023
92cd59b
Rename types to abstract use of registry
gtrevi Jul 31, 2023
a391fa2
Normalize all registry API names.
gtrevi Jul 31, 2023
6d4ec80
Merge branch 'main' into gtrevi/reg-api
gtrevi Jul 31, 2023
1c82d62
rename
gtrevi Jul 31, 2023
99f6ba0
merge sln
gtrevi Jul 31, 2023
d434ac6
fix var typo
gtrevi Aug 3, 2023
4a8bfb7
refactor store root keys
gtrevi Aug 4, 2023
a0883cf
feedback
gtrevi Aug 5, 2023
bfa8321
doc/comments
gtrevi Aug 5, 2023
b493d3e
remove KERNEL_MODE
gtrevi Aug 7, 2023
0514697
Force ignore format on all preprocessor code paths.
gtrevi Aug 7, 2023
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
44 changes: 39 additions & 5 deletions docs/eBpfExtensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,48 @@ The helper function ID for a general helper function must be in the range 0 - 65
The parameter and return types for these helper functions must adhere to the `ebpf_argument_type_t` and
`ebpf_return_type_t` enums.

### 2.7 Registering Program Types and Attach Types
### 2.7 Registering Program Types and Attach Types - eBPF Store
The eBPF Execution Context loads an eBPF program from an ELF file that has program section(s) with section names. The
prefix to these names determines the program type. For example, the section name `"xdp"` implies that the corresponding
program type is `EBPF_PROGRAM_TYPE_XDP`. The Execution Context discovers the program type associated with a section
prefix by reading the data from Windows registry. When an eBPF extension is installed, it must update the registry with
the program types it implements along with the associated section prefixes.
program type is `EBPF_PROGRAM_TYPE_XDP`.

_Note: The registry location and data format are TBD. This is currently tracked by issue #223._
The *Execution Context* discovers the program type associated with a section prefix by reading the data from the ***"eBPF store"***, which is currently kept in the Windows registry.
When an eBPF extension is installed, it must update the eBPF store with the program types it implements along with the associated section prefixes.

To operate on the eBPF store, the extension must link the `\lib\ebpf_store_helper_km.lib` kernel-mode library and include the related `\include\ebpf_store_helper.h` header file, both distributed within the [eBPF for Windows NuGet package](https://www.nuget.org/packages/eBPF-for-Windows/). With these, the extension can use the following APIs to register program types, attach types and helper functions:

- `ebpf_store_update_helper_prototype`: updates the provider prototype information in the eBPF store, given a pointer to the store key to be initialized and a pointer to the helper function prototype (i.e., `_ebpf_helper_function_prototype`):
gtrevi marked this conversation as resolved.
Show resolved Hide resolved

```c
ebpf_result_t
ebpf_store_update_helper_prototype(
ebpf_store_key_t helper_info_key, _In_ const ebpf_helper_function_prototype_t* helper_info);
```c
```

- `ebpf_store_update_global_helper_information`: updates the global helper information in the eBPF store, given a pointer to an array of helper function prototypes:

```c
ebpf_result_t
ebpf_store_update_global_helper_information(
_In_reads_(helper_info_count) ebpf_helper_function_prototype_t* helper_info, uint32_t helper_info_count);
```

- `ebpf_store_update_section_information`: updates the section information in eBPF store, given a pointer to an array of section information (i.e., `_ebpf_program_section_info`):
gtrevi marked this conversation as resolved.
Show resolved Hide resolved

```c
ebpf_result_t
ebpf_store_update_section_information(
_In_reads_(section_info_count) const ebpf_program_section_info_t* section_info, uint32_t section_info_count);
```

- `ebpf_store_update_program_information`: updates the global helper information in eBPF store, given a pointer to an array of program information (i.e., `_ebpf_program_info`):
gtrevi marked this conversation as resolved.
Show resolved Hide resolved

```c
ebpf_result_t
ebpf_store_update_program_information(
_In_reads_(program_info_count) const ebpf_program_info_t* program_info, uint32_t program_info_count);
```

### 2.8 eBPF Sample Driver
The eBPF for Windows project provides a
Expand Down
174 changes: 174 additions & 0 deletions ebpf-for-windows.sln

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions ebpfapi/ebpfapi.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@
<ProjectReference Include="..\external\ebpf-verifier\build\ebpfverifier.vcxproj">
<Project>{7d5b4e68-c0fa-3f86-9405-f6400219b440}</Project>
</ProjectReference>
<ProjectReference Include="..\external\ebpf-verifier\build\external\libbtf\libbtf\libbtf.vcxproj">
<Project>{bc45d39c-f956-3951-bd46-44eae20ec7c9}</Project>
</ProjectReference>
<ProjectReference Include="..\external\usersim\src\usersim.vcxproj">
<Project>{030a7ac6-14dc-45cf-af34-891057ab1402}</Project>
</ProjectReference>
<ProjectReference Include="..\external\ebpf-verifier\external\libbtf\build\libbtf\libbtf.vcxproj">
<Project>{c034859f-e0d6-3ae6-b4fe-71b012fdc618}</Project>
</ProjectReference>
<ProjectReference Include="..\libs\api\api.vcxproj">
<Project>{c8bf60c3-40a9-43ad-891a-8aa34f1c3a68}</Project>
</ProjectReference>
Expand Down Expand Up @@ -276,4 +276,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
5 changes: 4 additions & 1 deletion ebpfcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ wdk_add_driver("EbpfCore" WINVER "${EBPFFORWINDOWS_WDK_WINVER}" KMDF "${EBPFFORW

target_include_directories("EbpfCore" PRIVATE
"${CMAKE_SOURCE_DIR}/include"
"${CMAKE_SOURCE_DIR}/libs/execution_context"
"${CMAKE_SOURCE_DIR}/libs/platform"
"${CMAKE_SOURCE_DIR}/libs/platform/kernel"
"${CMAKE_SOURCE_DIR}/libs/execution_context"
"${CMAKE_SOURCE_DIR}/libs/store_helper/kernel"
"${CMAKE_SOURCE_DIR}/resource"
"${CMAKE_CURRENT_SOURCE_DIR}"
)
Expand All @@ -28,6 +29,7 @@ target_link_directories("EbpfCore" PRIVATE

target_link_libraries("EbpfCore"
"ebpf_for_windows_common_settings"
"ebpf_store_helper_km"
gtrevi marked this conversation as resolved.
Show resolved Hide resolved
"execution_context_kernel"
"platform_kernel"
"external::ebpfverifier_headers"
Expand All @@ -38,6 +40,7 @@ target_link_libraries("EbpfCore"
)

target_compile_definitions("EbpfCore" PRIVATE
KERNEL_MODE
BINARY_COMPATIBLE=0
NT
NDIS60
Expand Down
Loading