BPF List
 help / color / mirror / Atom feed
* [PATCH v2 bpf-next 0/5] Tag fmod_ret functions that return ERR_PTR()
@ 2026-11-30 18:04 Anton Protopopov
  2026-11-30 18:04 ` [PATCH v2 bpf-next 1/5] resolve_btfids: Do not count errors translated to NULL Anton Protopopov
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Anton Protopopov @ 2026-11-30 18:04 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Alan Maguire,
	John Fastabend, bpf
  Cc: Anton Protopopov

With CONFIG_BPF_FMODRET_SCAN=y the build tags the functions that
return errors, so that an fmod_ret program can attach to them.
But it looks only at the functions that return an integer.
This set tags the functions that return ERR_PTR() too.

The verifier part of v1 (patches 1, 2, 3 and 5) is in bpf-next now.
This is the resolve_btfids part.

Patch 1 fixes a problem which is shared with the integer functions.
A function may test a value with IS_ERR() and return it only if it
is not an error:

	return IS_ERR(prev) ? NULL : prev;

Such a function got a tag though it never returns an error pointer,
and its callers check only for NULL. Now an error does not count
once its register is compared with -MAX_ERRNO on the way to the
return. This is a simple check and it loses a few real errors too:
"if (IS_ERR(p)) return p;" when a constant error and another value
meet in p before the test. In an arm64 vmlinux it untags 17 of the
new functions and 16 integer functions. In an x86-64 vmlinux it
untags 24 functions. Evaluating the branch on the compare would keep
them, this can be done in a follow-up, but adds ~300-400 lines of
code, so I've dropped it.

Patch 2 tags the functions that return a pointer. Patches 3 and 4
skip functions which have the right tag, but whose callers break
when a program skips them. Patch 3 skips the seq_file operations:
seq_file calls ->stop() after ->start() failed, so ->stop() unlocks
what a skipped ->start() did not lock. Patch 4 skips eight functions
by name.

Patch 5 tests the series.

In an arm64 vmlinux built with clang this series tags 1263 functions
which return a pointer: 14864 functions are tagged instead of 13617.

v1 -> v2:
- Drop the test of a declared function that returns a pointer (Alexei)
- Do not count errors tested with IS_ERR() (Alexei)
- Count any -EINPROGRESS which a function loads, so that a lost one
  does not make its -EBUSY a failure. 3 functions affected.
- Do not tag the seq_file operations (Alexei)
- Filter out a few functions by name (Alexei)

v1: https://lore.kernel.org/bpf/20261125102810.699464-1-a.s.protopopov@gmail.com/

Anton Protopopov (5):
  resolve_btfids: Do not count errors translated to NULL
  resolve_btfids: Tag the functions that return ERR_PTR()
  resolve_btfids: Do not tag seq_file operations
  resolve_btfids: Do not tag functions whose callers break on a skip
  selftests/bpf: Test fmod_ret on functions that return a pointer

 tools/bpf/resolve_btfids/fmodret.c            | 62 +++++++++++++++----
 tools/bpf/resolve_btfids/fmodret_scan.c       |  5 +-
 tools/bpf/resolve_btfids/fmodret_scan.h       |  5 +-
 tools/bpf/resolve_btfids/text_flow.c          | 12 +++-
 tools/bpf/resolve_btfids/text_flow.h          |  3 +
 tools/bpf/resolve_btfids/text_insn.h          |  1 +
 tools/bpf/resolve_btfids/text_mc.cpp          |  9 ++-
 tools/bpf/resolve_btfids/text_mc.h            |  4 ++
 tools/bpf/resolve_btfids/text_mc_arm64.c      |  6 ++
 tools/bpf/resolve_btfids/text_mc_x86.c        |  6 ++
 .../selftests/bpf/prog_tests/fmodret_retval.c |  2 +-
 .../bpf/prog_tests/fmodret_untagged.c         |  2 +
 tools/testing/selftests/bpf/progs/err.h       |  5 ++
 .../selftests/bpf/progs/fmodret_retval.c      | 10 +++
 .../bpf/test_kmods/bpf_testmod_retval.c       |  2 +-
 15 files changed, 113 insertions(+), 21 deletions(-)

-- 
2.43.0


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

end of thread, other threads:[~2026-11-30 18:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 18:04 [PATCH v2 bpf-next 0/5] Tag fmod_ret functions that return ERR_PTR() Anton Protopopov
2026-11-30 18:04 ` [PATCH v2 bpf-next 1/5] resolve_btfids: Do not count errors translated to NULL Anton Protopopov
2026-11-30 18:06   ` sashiko-bot
2026-11-30 18:04 ` [PATCH v2 bpf-next 2/5] resolve_btfids: Tag the functions that return ERR_PTR() Anton Protopopov
2026-11-30 18:04 ` [PATCH v2 bpf-next 3/5] resolve_btfids: Do not tag seq_file operations Anton Protopopov
2026-11-30 18:04 ` [PATCH v2 bpf-next 4/5] resolve_btfids: Do not tag functions whose callers break on a skip Anton Protopopov
2026-11-30 18:02   ` sashiko-bot
2026-11-30 18:04 ` [PATCH v2 bpf-next 5/5] selftests/bpf: Test fmod_ret on functions that return a pointer Anton Protopopov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox