Commit ff88079
Alexei Starovoitov
Merge branch 'bpf-introduce-file-dynptr'
Mykyta Yatsenko says:
====================
bpf: Introduce file dynptr
From: Mykyta Yatsenko <[email protected]>
This series adds a new dynptr kind, file dynptr, which enables BPF
programs to perform safe reads from files in a structured way.
Initial motivations include:
* Parsing the executable’s ELF to locate thread-local variable symbols
* Capturing stack traces when frame pointers are disabled
By leveraging the existing dynptr abstraction, we reuse the verifier’s
lifetime/size checks and keep the API consistent with existing dynptr
read helpers.
Technical details:
1. Reuses the existing freader library to read files a folio at a time.
2. bpf_dynptr_slice() and bpf_dynptr_read() always copy data from folios
into a program-provided buffer; zero-copy access is intentionally not
supported to keep it simple.
3. Reads may sleep if the requested folios are not in the page cache.
4. Few verifier changes required:
* Support dynptr destruction in kfuncs
* Add kfunc address substitution based on whether the program runs in
a sleepable or non-sleepable context.
Testing:
The final patch adds a selftest that validates BPF program reads the
same data as userspace, page faults are enabled in sleepable context and
disabled in non-sleepable.
Changelog:
---
v4 -> v5
v4: https://lore.kernel.org/all/[email protected]/
* Inlined and removed kfunc_call_imm(), run overflow check for call_imm
only if !bpf_jit_supports_far_kfunc_call().
v3 -> v4
v3: https://lore.kernel.org/bpf/[email protected]/
* Remove ringbuf usage from selftests
* bpf_dynptr_set_null(ptr) when discarding file dynptr
* call kfunc_call_imm() in specialize_kfunc() only, removed
call from add_kfunc_call()
v2 -> v3
v2: https://lore.kernel.org/bpf/[email protected]/
* Add negative tests
* Rewrote tests to use LSM for bpf_get_task_exe_file()
* Move call_imm overflow check into kfunc_call_imm()
v1 -> v2
v1: https://lore.kernel.org/bpf/[email protected]/
* Remove ELF parsing selftest
* Expanded u32 -> u64 refactoring, changes in include/uapi/linux/bpf.h
* Removed freader.{c,h}, instead move freader definitions into
buildid.h.
* Small refactoring of the multiple folios reading algorithm
* Directly return error after unmark_stack_slots_dynptr().
* Make kfuncs receive trusted arguments.
* Remove enum bpf_is_sleepable, use bool instead
* Remove unnecessary sorting from specialize_kfunc()
* Remove bool kfunc_in_sleepable_ctx; field from the struct
bpf_insn_aux_data, rely on non_sleepable field introduced by Kumar
* Refactor selftests, do madvise(...MADV_PAGEOUT) for all pages read by
the test
* Introduce the test for non-sleepable case, verify it fails with -EFAULT
====================
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>File tree
17 files changed
+649
-195
lines changed- include
- linux
- uapi/linux
- kernel
- bpf
- trace
- lib
- tools
- include/uapi/linux
- testing/selftests/bpf
- prog_tests
- progs
17 files changed
+649
-195
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4648 | 4648 | | |
4649 | 4649 | | |
4650 | 4650 | | |
| 4651 | + | |
4651 | 4652 | | |
4652 | 4653 | | |
4653 | 4654 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
670 | 670 | | |
671 | 671 | | |
672 | 672 | | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
673 | 676 | | |
674 | 677 | | |
675 | 678 | | |
| |||
792 | 795 | | |
793 | 796 | | |
794 | 797 | | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
795 | 801 | | |
796 | 802 | | |
797 | 803 | | |
798 | 804 | | |
799 | 805 | | |
800 | | - | |
| 806 | + | |
801 | 807 | | |
802 | 808 | | |
803 | 809 | | |
| |||
1385 | 1391 | | |
1386 | 1392 | | |
1387 | 1393 | | |
| 1394 | + | |
| 1395 | + | |
1388 | 1396 | | |
1389 | 1397 | | |
1390 | | - | |
1391 | | - | |
1392 | | - | |
1393 | | - | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
1394 | 1402 | | |
1395 | | - | |
1396 | | - | |
1397 | | - | |
1398 | | - | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
1399 | 1407 | | |
1400 | | - | |
| 1408 | + | |
1401 | 1409 | | |
1402 | | - | |
| 1410 | + | |
1403 | 1411 | | |
1404 | 1412 | | |
1405 | 1413 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
21 | 46 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5618 | 5618 | | |
5619 | 5619 | | |
5620 | 5620 | | |
5621 | | - | |
| 5621 | + | |
5622 | 5622 | | |
5623 | 5623 | | |
5624 | 5624 | | |
| |||
5661 | 5661 | | |
5662 | 5662 | | |
5663 | 5663 | | |
5664 | | - | |
| 5664 | + | |
5665 | 5665 | | |
5666 | 5666 | | |
5667 | 5667 | | |
| |||
5671 | 5671 | | |
5672 | 5672 | | |
5673 | 5673 | | |
5674 | | - | |
| 5674 | + | |
5675 | 5675 | | |
5676 | 5676 | | |
5677 | 5677 | | |
| |||
5692 | 5692 | | |
5693 | 5693 | | |
5694 | 5694 | | |
5695 | | - | |
| 5695 | + | |
5696 | 5696 | | |
5697 | 5697 | | |
5698 | 5698 | | |
| |||
0 commit comments