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

ebpf: add Windows support #1710

Merged
merged 2 commits into from
Mar 5, 2025
Merged

ebpf: add Windows support #1710

merged 2 commits into from
Mar 5, 2025

Conversation

lmb
Copy link
Collaborator

@lmb lmb commented Mar 4, 2025

Basic support for the ebpf package. link doesn't work yet, so there is no way to attach a link at the moment.

all: add windows constants

Add constants for Windows map and program types as well as builtin
functions.

Signed-off-by: Lorenz Bauer <[email protected]>

ebpf: add basic Windows support

Add minimal support for Windows, which includes being able to create maps, 
load programs and interact with them via the usual APIs.

Unsupported APIs return ErrNotSupported or ErrNotSupportedOnOS.

Signed-off-by: Lorenz Bauer <[email protected]>

@lmb
Copy link
Collaborator Author

lmb commented Mar 4, 2025

Here is a summary of skipped tests, and their reason for skipping:

=== Skipped
=== SKIP: . TestMapReplacementsDataSections (0.01s)
    helpers_test.go:195: field ROData: map .rodata: map create: flags: not supported on windows

=== SKIP: . TestLoadCollectionSpec/loader-clang-11-el.elf (0.00s)
    elf_reader_test.go:261: map array_of_hash_map: inner map: map create: flags: not supported on windows

=== SKIP: . TestLoadCollectionSpec/loader-clang-14-el.elf (0.00s)
    elf_reader_test.go:261: map hash_map: map create: flags: not supported on windows

=== SKIP: . TestLoadCollectionSpec/loader-clang-17-el.elf (0.00s)
    elf_reader_test.go:261: map hash_map: map create: flags: not supported on windows

=== SKIP: . TestLoadCollectionSpec/loader-el.elf (0.00s)
    elf_reader_test.go:261: map perf_event_array: map type PerfEventArray (linux): not supported on windows

=== SKIP: . TestDataSections (0.00s)
    elf_reader_test.go:301: data_sections:
        	  ; __section("socket/3") int data_sections() {
        	 0: MovImm dst: r0 imm: 141
        	  ; if (uneg != (unsigned int)-1)
        	 1: LoadMapValue dst: r1, fd: 0 off: 8 <.rodata>
        	 3: LdXMemW dst: r1 src: r1 off: 0 imm: 0
        	 4: LdImmDW dst: r2 imm: 4294967295
        	  ; if (uneg != (unsigned int)-1)
        	 6: JNEReg dst: r1 off: 22 src: r2
        	 7: MovImm dst: r0 imm: 144
        	  ; if (neg != -2)
        	 8: LoadMapValue dst: r1, fd: 0 off: 12 <.rodata>
        	10: LdXMemW dst: r1 src: r1 off: 0 imm: 0
        	11: LdImmDW dst: r2 imm: 4294967294
        	  ; if (neg != -2)
        	13: JNEReg dst: r1 off: 15 src: r2
        	14: MovImm dst: r0 imm: 147
        	  ; if (static_uneg != (unsigned int)-3)
        	15: LoadMapValue dst: r1, fd: 0 off: 16 <.rodata>
        	17: LdXMemW dst: r1 src: r1 off: 0 imm: 0
        	18: LdImmDW dst: r2 imm: 4294967293
        	  ; if (static_uneg != (unsigned int)-3)
        	20: JNEReg dst: r1 off: 8 src: r2
        	  ; if (static_neg != -4)
        	21: LoadMapValue dst: r1, fd: 0 off: 20 <.rodata>
        	23: LdXMemW dst: r1 src: r1 off: 0 imm: 0
        	24: MovImm dst: r0 imm: 0
        	25: LdImmDW dst: r2 imm: 4294967292
        	27: JEqReg dst: r1 off: 1 src: r2
        	28: MovImm dst: r0 imm: 150
        	  ; }
        	29: Exit
        
    helpers_test.go:195: field Program: program data_sections: map .rodata: map create: flags: not supported on windows

=== SKIP: . TestFreezeRodata (0.00s)
    elf_reader_test.go:346: Ignoring version constraint 5.9 for sk_lookup program type on windows
    helpers_test.go:195: field Program: program freeze_rodata: map .rodata: map create: flags: not supported on windows

=== SKIP: . TestLoadInitializedBTFMap/btf_map_init-eb.elf/NewCollection (0.00s)
    elf_reader_test.go:435: Skipping BigEndian collection

=== SKIP: . TestStringSection (0.00s)
    elf_reader_test.go:528: my_map
    elf_reader_test.go:528: .rodata.str1.1
    elf_reader_test.go:544: map .rodata.str1.1: map create: flags: not supported on windows

=== SKIP: . TestLoadRawTracepoint (0.00s)
    elf_reader_test.go:579: Ignoring version constraint 4.17 for BPF_RAW_TRACEPOINT API on windows
    elf_reader_test.go:592: program sched_process_exec: program type RawTracepoint (linux): not supported on windows

=== SKIP: . TestKconfig (0.00s)
    elf_reader_test.go:648: field Main: program kconfig: program type SocketFilter (linux): not supported on windows

=== SKIP: . TestKsym (0.00s)
    elf_reader_test.go:674: populating kallsyms caches: getting addresses from kallsyms: read /proc/kallsyms: not supported on windows

=== SKIP: . TestKsymWeakMissing (0.00s)
    elf_reader_test.go:710: populating kallsyms caches: getting addresses from kallsyms: read /proc/kallsyms: not supported on windows

=== SKIP: . TestKfunc (0.00s)
    elf_reader_test.go:721: Ignoring version constraint 5.18 for kfunc support on windows
    elf_reader_test.go:733: populating kallsyms caches: getting modules from kallsyms: read /proc/kallsyms: not supported on windows

=== SKIP: . TestWeakKfunc (0.00s)
    elf_reader_test.go:751: Ignoring version constraint 5.18 for kfunc support on windows
    elf_reader_test.go:764: populating kallsyms caches: getting modules from kallsyms: read /proc/kallsyms: not supported on windows

=== SKIP: . TestInvalidKfunc (0.00s)
    elf_reader_test.go:773: Ignoring version constraint 5.18 for kfunc support on windows
    elf_reader_test.go:774: Ignoring version constraint 5.11 for bpf_testmod on windows
    elf_reader_test.go:774: bpf_testmod not loaded

=== SKIP: . TestKfuncKmod (0.00s)
    elf_reader_test.go:790: Ignoring version constraint 5.18 for Kernel module function calls on windows
    elf_reader_test.go:791: Ignoring version constraint 5.11 for bpf_testmod on windows
    elf_reader_test.go:791: bpf_testmod not loaded

=== SKIP: . TestSubprogRelocation (0.00s)
    elf_reader_test.go:822: Ignoring version constraint 5.13 for bpf_for_each_map_elem on windows
    elf_reader_test.go:835: field Main: program fp_relocation: instruction 16: function FnForEachMapElem (linux): not supported on windows

=== SKIP: . TestIPRoute2Compat (0.00s)
    elf_reader_test.go:923: map hash_map: map type Hash (linux): not supported on windows

=== SKIP: . TestLibBPFCompat (0.00s)
    elf_reader_test.go:938: No path specified

=== SKIP: . TestWindowsELFCompat (0.00s)
    elf_reader_test.go:1331: No path specified

=== SKIP: . TestMapInfoFromProc (0.00s)
    info_test.go:46: creating map: map create: flags: not supported on windows

=== SKIP: . TestMapInfoFromProcOuterMap (0.00s)
    info_test.go:81: read fdinfo: not supported on windows

=== SKIP: . TestProgramInfoProc (0.00s)
    info_test.go:165: read fdinfo: not supported on windows

=== SKIP: . TestStats (0.00s)
    info_test.go:304: Ignoring version constraint 5.8 for BPF_ENABLE_STATS on windows
    info_test.go:338: failed to enable stats: not supported on windows

=== SKIP: . TestProgInfoExtBTF (0.00s)
    info_test.go:446: Ignoring version constraint 5.0 for Program BTF (func/line_info) on windows
    info_test.go:457: field Main: program xdp_prog: map hash_map: map create: flags: not supported on windows

=== SKIP: . TestMapBatch/Array (0.00s)
    map_test.go:139: map batch api: not supported on windows

=== SKIP: . TestMapBatch/PerCPUArray (0.00s)
    map_test.go:133: Ignoring version constraint 5.13 for batched ops support for percpu array on windows
    map_test.go:139: map batch api: not supported on windows

=== SKIP: . TestMapBatch/Hash (0.00s)
    map_test.go:164: map batch api: not supported on windows

=== SKIP: . TestMapBatch/PerCPUHash (0.00s)
    map_test.go:164: map batch api: not supported on windows

=== SKIP: . TestMapBatchCursorReuse (0.00s)
    map_test.go:211: map batch lookup: map batch api: not supported on windows

=== SKIP: . TestBatchAPIMapDelete (0.00s)
    map_test.go:242: batch api not available: map batch api: not supported on windows

=== SKIP: . TestBatchMapWithLock (0.00s)
    map_test.go:298: Ignoring version constraint 5.13 for MAP BATCH BPF_F_LOCK on windows
    map_test.go:318: map batch api: not supported on windows

=== SKIP: . TestMapWithLock (0.00s)
    map_test.go:350: Ignoring version constraint 5.13 for MAP BPF_F_LOCK on windows
    map_test.go:371: Windows doesn't support UpdateLock

=== SKIP: . TestMapLoadReusePinned/DevMap (0.00s)
    map_test.go:584: Ignoring version constraint 4.14 for devmap on windows
    map_test.go:599: creating map: map type DevMap (linux): not supported on windows

=== SKIP: . TestMapLoadReusePinned/DevMapHash (0.00s)
    map_test.go:587: Ignoring version constraint 5.4 for devmap_hash on windows
    map_test.go:599: creating map: map type DevMapHash (linux): not supported on windows

=== SKIP: . TestMapLoadPinnedWithOptions/read-only (0.00s)
    map_test.go:647: Windows doesn't support file_flags in OBJ_GET

=== SKIP: . TestMapLoadPinnedWithOptions/write-only (0.00s)
    map_test.go:665: Windows doesn't support file_flags in OBJ_GET

=== SKIP: . TestPerfEventArray (0.00s)
    map_test.go:817: creating map: map type PerfEventArray (linux): not supported on windows

=== SKIP: . TestCPUMap (0.00s)
    map_test.go:822: Ignoring version constraint 4.15 for cpu map on windows
    map_test.go:824: creating map: map type CPUMap (linux): not supported on windows

=== SKIP: . TestIterateEmptyMap/SockHash (0.00s)
    map_test.go:854: creating map: map type SockHash (linux): not supported on windows

=== SKIP: . TestIterateEmptyMap/SockMap (0.00s)
    map_test.go:854: creating map: map type SockMap (linux): not supported on windows

=== SKIP: . TestMapBatchLookupAllocations (0.00s)
    map_test.go:967: map batch api: not supported on windows

=== SKIP: . TestMapGuessNonExistentKey (0.00s)
    map_test.go:1022: No need to test linux quirk on windows

=== SKIP: . TestCgroupPerCPUStorageMarshaling (0.00s)
    map_test.go:1253: Ignoring version constraint 5.9 for per-CPU CGoup storage with write from user space support on windows
    map_test.go:1255: creating map: map type PerCPUCGroupStorage (linux): not supported on windows

=== SKIP: . TestMapFreeze (0.00s)
    map_test.go:1448: can't freeze map: read- and write-only maps: not supported on windows

=== SKIP: . TestMapHandle (0.00s)
    map_test.go:1586: map WindowsHash#3: retrieve BTF ID: not supported

=== SKIP: . TestPerfEventArrayCompatible (0.00s)
    map_test.go:1604: creating map: map type PerfEventArray (linux): not supported on windows

=== SKIP: . TestMemory (0.00s)
    memory_test.go:33: creating map: map create: flags: not supported on windows

=== SKIP: . TestMemoryBounds (0.00s)
    memory_test.go:57: creating map: map create: flags: not supported on windows

=== SKIP: . TestMemoryReadOnly (0.00s)
    memory_test.go:73: creating map: map create: flags: not supported on windows

=== SKIP: . TestMemoryUnmap (0.00s)
    memory_test.go:88: creating map: map create: flags: not supported on windows

=== SKIP: . TestProgramRunRawTracepoint (0.00s)
    prog_test.go:135: Ignoring version constraint 5.10 for RawTracepoint test run on windows
    prog_test.go:137: program type RawTracepoint (linux): not supported on windows

=== SKIP: . TestProgramKernelVersion (0.00s)
    prog_test.go:298: Ignoring version constraint 4.20 for KernelVersion on windows
    prog_test.go:300: program type Kprobe (linux): not supported on windows

=== SKIP: . TestProgramVerifierLog (0.00s)
    prog_test.go:355: log level: not supported on windows

=== SKIP: . TestProgramAttachToKernel/LSMMac:task_getpgid (0.00s)
    prog_test.go:681: program type LSM (linux): not supported on windows

=== SKIP: . TestProgramAttachToKernel/TraceFEntry:inet_dgram_connect (0.00s)
    prog_test.go:681: program type Tracing (linux): not supported on windows

=== SKIP: . TestProgramAttachToKernel/TraceFExit:inet_dgram_connect (0.00s)
    prog_test.go:681: program type Tracing (linux): not supported on windows

=== SKIP: . TestProgramAttachToKernel/ModifyReturn:bpf_modify_return_test (0.00s)
    prog_test.go:681: program type Tracing (linux): not supported on windows

=== SKIP: . TestProgramAttachToKernel/TraceRawTp:kfree_skb (0.00s)
    prog_test.go:681: program type Tracing (linux): not supported on windows

=== SKIP: . TestProgramAttachToKernel/TraceFEntry:bpf_testmod_test_read (0.00s)
    prog_test.go:678: Ignoring version constraint 5.11 for bpf_testmod on windows
    prog_test.go:678: bpf_testmod not loaded

=== SKIP: . TestProgramAttachToKernel/TraceFExit:bpf_testmod_test_read (0.00s)
    prog_test.go:678: Ignoring version constraint 5.11 for bpf_testmod on windows
    prog_test.go:678: bpf_testmod not loaded

=== SKIP: . TestProgramAttachToKernel/ModifyReturn:bpf_testmod_test_read (0.00s)
    prog_test.go:678: Ignoring version constraint 5.11 for bpf_testmod on windows
    prog_test.go:678: bpf_testmod not loaded

=== SKIP: . TestProgramAttachToKernel/TraceRawTp:bpf_testmod_test_read (0.00s)
    prog_test.go:678: Ignoring version constraint 5.11 for bpf_testmod on windows
    prog_test.go:678: bpf_testmod not loaded

=== SKIP: . TestProgramKernelTypes (0.00s)
    prog_test.go:698: /sys/kernel/btf/vmlinux not present

=== SKIP: . TestProgramInstructions (0.01s)
    prog_test.go:757: read instructions: not supported on windows

=== SKIP: . TestProgramLoadErrors/poisoned_single (0.00s)
    prog_test.go:801: poisoned_single:
        	  ; __section("socket") int poisoned_single() {
        	 0: MovImm dst: r0 imm: 18
        	 1: LdImmDW dst: r1 imm: 2
        	  ; FORCE_BTF;
        	 3: JEqImm dst: r1 off: 3 imm: 0
        	 4: MovReg dst: r1 src: rfp
        	  ; return core_access(ne.non_exist);
        	 5: AddImm dst: r1 imm: -4
        	 6: LdXMemW dst: r0 src: r1 off: 0 imm: 0
        	  ; }
        	 7: Exit
        
    prog_test.go:802: apply CO-RE relocations: fixup for CORERelocation(local_type_id, Int:"int"[0], local_id=2): CO-RE fixup: not supported on windows

=== SKIP: . TestProgramLoadErrors/poisoned_double (0.00s)
    prog_test.go:801: poisoned_double:
        	 ; __section("socket") int poisoned_double() {
        	0: MovImm dst: r0 imm: 24
        	1: LdImmDW dst: r1 imm: 2
        	 ; FORCE_BTF;
        	3: JEqImm dst: r1 off: 2 imm: 0
        	4: LdImmDW dst: r0 imm: 1
        	 ; }
        	6: Exit
        
    prog_test.go:802: apply CO-RE relocations: fixup for CORERelocation(local_type_id, Int:"int"[0], local_id=2): CO-RE fixup: not supported on windows

=== SKIP: . TestProgramLoadErrors/poisoned_kfunc (0.00s)
    prog_test.go:801: poisoned_kfunc:
        	 ; return invalid_kfunc();
        	0: Call Kfunc(-1) <invalid_kfunc>
        	 ; return invalid_kfunc();
        	1: Exit
        
    prog_test.go:802: fixing up kfuncs: not supported on windows

=== SKIP: . TestProgramAttachToKernelModule (0.00s)
    prog_test.go:825: Ignoring version constraint 5.11 for bpf_testmod on windows
    prog_test.go:825: bpf_testmod not loaded

=== SKIP: . TestHaveBatchAPI (0.00s)
    syscalls_test.go:27: map batch api: not supported on windows

=== SKIP: . TestHaveMapMutabilityModifiers (0.00s)
    syscalls_test.go:43: read- and write-only maps: not supported on windows

=== SKIP: . TestHaveMmapableMaps (0.00s)
    syscalls_test.go:47: mmapable maps: not supported on windows

=== SKIP: . TestHaveInnerMaps (0.00s)
    syscalls_test.go:51: inner maps: not supported on windows

=== SKIP: . TestHaveProbeReadKernel (0.00s)
    syscalls_test.go:55: bpf_probe_read_kernel: not supported on windows

=== SKIP: . TestHaveBPFToBPFCalls (0.00s)
    syscalls_test.go:59: bpf2bpf calls: not supported on windows

=== SKIP: . TestHaveSyscallWrapper (0.00s)
    syscalls_test.go:63: syscall wrapper: not supported on windows

=== SKIP: . TestHaveProgramExtInfos (0.00s)
    syscalls_test.go:67: program ext_infos: not supported on windows

=== SKIP: . TestVariable (0.00s)
    variable_test.go:84: mmapable maps: not supported on windows

=== SKIP: . TestVariableConst (0.00s)
    variable_test.go:136: mmapable maps: not supported on windows

DONE 327 tests, 80 skipped in 2.426s

@lmb lmb requested a review from rgo3 March 4, 2025 15:27
@lmb lmb marked this pull request as ready for review March 5, 2025 10:04
@lmb lmb requested a review from a team as a code owner March 5, 2025 10:04
Copy link
Contributor

@rgo3 rgo3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides double checking the comments you made during our code walk this morning, this LGTM.

lmb added 2 commits March 5, 2025 17:00
Add constants for Windows map and program types as well as
builtin functions.

Signed-off-by: Lorenz Bauer <[email protected]>
Add minimal support for Windows, which includes being able to create maps,
load programs and interact with them via the usual APIs.

Unsupported APIs return ErrNotSupported or ErrNotSupportedOnOS.

Signed-off-by: Lorenz Bauer <[email protected]>
@lmb lmb merged commit 995422c into cilium:main Mar 5, 2025
17 checks passed
@lmb lmb deleted the windows-ebpf branch March 5, 2025 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants