microsoft / ebpf-for-windows

eBPF implementation that runs on top of Windows
MIT License
2.82k stars 216 forks source link

bpf_map_lookup_batch map api: Fails to fetch all entries, when the next key is deleted in the hash map. #3561

Open shpalani opened 3 months ago

shpalani commented 3 months ago

Describe the bug

Concurrent test case:

Problem: The bpf_map_lookup_batch API fails to retrieve all the hash map entries during iteration when one of the next key is deleted. And also, returns ENOENT in the next iteration, when there are more entries.

OS information

Windows 11 or above.

Steps taken to reproduce bug

To retrieve entries in batches,

  1. Set the batch size to be small.
  2. Iterate until ENOENT.
  3. Delete the next_key entry, before the next iteration, and continue.

Expected behavior

All the entries in the hash map should be retrieved.

Actual outcome

Please add below test case to https://github.com/microsoft/ebpf-for-windows/pull/3563. TEST_CASE("libbpf hash map del batch", "[libbpf]") { _test_maps_batch(BPF_MAP_TYPE_HASH, true); }

C:\Users\xxx\ebpf-for-windows-2024\ebpf-for-windows\x64\Debug>unit_tests.exe "libbpf hash map del batch" -d yes
Filters: "libbpf hash map del batch"
Randomness seeded to: 1258998329
No more entries. End of map reached.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
unit_tests.exe is a Catch2 v3.6.0 host application.
Run with -? for options

-------------------------------------------------------------------------------
libbpf hash map del batch
-------------------------------------------------------------------------------
C:\Users\xxx\ebpf-for-windows-2024\ebpf-for-windows\tests\unit\libbpf_test.cpp(3443)
...............................................................................

C:\Users\xxx\ebpf-for-windows-2024\ebpf-for-windows\tests\unit\libbpf_test.cpp(3276): FAILED:
  REQUIRE( returned_keys.size() == batch_size )
with expansion:
  1998 (0x7ce) == 19999 (0x4e1f)

0.000 s: libbpf hash map del batch
===============================================================================
test cases:  1 |  0 passed | 1 failed
assertions: 15 | 14 passed | 1 failed

Additional details

No response

shpalani commented 3 months ago

As a follow-up, please find the Linux behavior for the return code when the next key in the next iteration is deleted in map batch operation.