All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v6 0/2] bpf: Track borrowed iterator result lifetimes
@ 2026-09-27 12:04 Xu Yunxiang
  2026-09-27 12:04 ` [PATCH bpf-next v6 1/2] bpf: Track borrowed iterator results by default Xu Yunxiang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Xu Yunxiang @ 2026-09-27 12:04 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, eddyz87, memxor, ameryhung, yonghong.song,
	puranjay

Make non-RCU, non-acquired struct iterator results borrow the current
element lifetime by default. KF_ITER_RET_INDEPENDENT marks the explicit
exception for results whose lifetime is independent of the iterator.
This follows Amery's and Alexei's opt-out feedback on v5.

Keep the v5 propagation through trusted fields and dynptr constructors,
and reuse the reference traversal when invalidating iterator dependents.
Next preserves the iterator itself and invalidates old dependents before
both return outcomes; destroy propagates outstanding-child errors.
The second patch covers these rules and the independent/RCU controls.

Scope and overlap: the trusted-field propagation was already in v5 and
overlaps the work Amery pointed out to Kumar. This revision adds no general
kfunc borrowed-return annotation and does not fix the separate
bpf_real_data_inode() return-lifetime gap Kumar said he would handle.
The iterator policy itself has no dependency on such an annotation.
We will need to reconcile the shared field-propagation code when that
work is available; this series does not claim complete coverage through
ordinary kfunc returns.

Changes in v6 (relative to the posted v5):
  - Replace KF_ITER_LIFETIME opt-in with KF_ITER_RET_INDEPENDENT opt-out.
    Native borrowed struct iterators no longer need individual flags;
    mark the independent testmod iterator explicitly.
  - Reuse the reference graph traversal for next while retaining the root
    iterator reference, instead of the PTR_TO_BTF_ID-only scan.
  - Retain the fifteen v5 lifetime tests and use scalar opaque storage
    for the one-word testmod iterator.
  - Correct the iterator Fixes tag to its introduction and rebase onto
    bpf-next ea9358e1270ab. Keep implementation and tests in two commits.

v5:
https://lore.kernel.org/r/20260920210432.345758-1-xyx2021@mail.ustc.edu.cn
Amery's opt-out clarification:
https://lore.kernel.org/r/CAMB2axMt8K6tnLZ_wNzx_c=tCqpUeLOETitN98_v1y7Z7J2EwQ@mail.gmail.com
Alexei's opt-out review:
https://lore.kernel.org/r/DLM8JHZUINUJ.3V54PKAS0QV9B@gmail.com
Kumar's related work:
https://lore.kernel.org/r/DLGYPZAL708V.3GFLANAPH2L8O@gmail.com

Validation on the rebased candidate with a matching bpf_testmod:
  - W=1 verifier, full kernel and modules builds passed.
  - Changed BPF objects and required fixtures compiled strictly.
  - iters: 1/121 passed; 0 skipped.
  - dynptr: 2/133 passed; 0 skipped.
  - file_reader: 1/8 passed; 0 skipped.
  - verifier_vfs_accept: 1/6 passed; 0 skipped.
  - verifier_vfs_reject: 1/12 passed; 0 skipped.
  - kmem_cache_iter: 1/3 passed; 0 skipped.
  - dmabuf_iter: 1/4 passed; 0 skipped.

No selected test failed. The VM used panic_on_warn and panic_on_oops;
no WARN_ON report, Oops or panic was found. Unprivileged BPF was
enabled only in the isolated guest; the kernel printed the expected
Spectre-v2 notice when enabling that sysctl.

The broad test_progs build used BPF_STRICT_BUILD=0 for unselected
objects requiring unavailable kernel features. The changed objects
and required fixtures were also compiled in strict mode. Annotated
lifetime tests check loading and diagnostics. The unfiltered full
suite, sanitizer and architecture matrices, and new unmodified-base
differential probes were not run in this rebase validation.

Please queue the verifier fix for stable after it reaches the BPF tree.

Rebase adaptation: use bit 19 for KF_ITER_RET_INDEPENDENT because
upstream KF_PERFMON uses bit 18, and use the new stack-slot accessor.

Xu Yunxiang (2):
  bpf: Track borrowed iterator results by default
  selftests/bpf: Test borrowed iterator result lifetimes

 Documentation/bpf/bpf_iterators.rst           |  10 +
 include/linux/btf.h                           |   1 +
 kernel/bpf/btf.c                              |  13 +-
 kernel/bpf/verifier.c                         | 103 ++++-
 .../selftests/bpf/progs/iters_testmod.c       | 370 ++++++++++++++++++
 .../selftests/bpf/test_kmods/bpf_testmod.c    |  25 ++
 .../selftests/bpf/test_kmods/bpf_testmod.h    |   4 +
 .../bpf/test_kmods/bpf_testmod_kfunc.h        |   5 +
 8 files changed, 512 insertions(+), 19 deletions(-)


base-commit: ea9358e1270ab2c3ba6f36bd9bdda68617665516
-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-10-21  0:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-27 12:04 [PATCH bpf-next v6 0/2] bpf: Track borrowed iterator result lifetimes Xu Yunxiang
2026-09-27 12:04 ` [PATCH bpf-next v6 1/2] bpf: Track borrowed iterator results by default Xu Yunxiang
2026-10-21  0:05   ` Alexei Starovoitov
2026-09-27 12:04 ` [PATCH bpf-next v6 2/2] selftests/bpf: Test borrowed iterator result lifetimes Xu Yunxiang
2026-09-27 20:28   ` bot+bpf-ci
2026-10-14  3:07 ` [PATCH bpf-next v6 0/2] bpf: Track " Xu Yunxiang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.