Skip to contentSkip to conversation

libbpf: error reporting changes for v1.0

PATCH Superseded Andrii Nakryiko 5 participants 11 messages May 21, 2021 – May 25, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Andrii Nakryiko

author maintainer
#0 lore raw

cover libbpf: error reporting changes for v1.0

Implement error reporting changes discussed in "Libbpf: the road to v1.0" ([0]) document.

Libbpf gets a new API, libbpf_set_strict_mode() which accepts a set of flags that turn on a set of libbpf 1.0 changes, that might be potentially breaking. It's possible to opt-in into all current and future 1.0 features by specifying LIBBPF_STRICT_ALL flag.

When some of the 1.0 "features" are requested, libbpf APIs might behave differently. In this patch set a first set of changes are implemented, all related to the way libbpf returns errors. See individual patches for details.

Patch #1 adds a no-op libbpf_set_strict_mode() functionality to enable updating selftests.

Patch #2 gets rid of all the bad code patterns that will break in libbpf 1.0 (exact -1 comparison for low-level APIs, direct IS_ERR() macro usage to check pointer-returning APIs for error, etc). These changes make selftest work in both legacy and 1.0 libbpf modes. Selftests also opt-in into 100% libbpf 1.0 mode to automatically gain all the subsequent changes, which will come in follow up patches.

Patch #3 streamlines error reporting for low-level APIs wrapping bpf() syscall.

Patch #4 streamlines errors for all the rest APIs.

Patch #5 ensures that BPF skeletons propagate errors properly as well, as currently on error some APIs will return NULL with no way of checking exact error code.

[0] https://docs.google.com/document/d/1UyjTZuPFWiPFyKk1tV5an11_iaRuec6U-ZESZ54nNTY

Andrii Nakryiko (5):
libbpf: add libbpf_set_strict_mode() API to turn on libbpf 1.0
behaviors
selftests/bpf: turn on libbpf 1.0 mode and fix all IS_ERR checks
libbpf: streamline error reporting for low-level APIs
libbpf: streamline error reporting for high-level APIs
bpftool: set errno on skeleton failures and propagate errors

 tools/bpf/bpftool/gen.c                       |  27 +-
 tools/lib/bpf/Makefile                        |   1 +
 tools/lib/bpf/bpf.c                           | 168 ++++--
 tools/lib/bpf/bpf_prog_linfo.c                |  18 +-
 tools/lib/bpf/btf.c                           | 302 +++++-----
 tools/lib/bpf/btf_dump.c                      |  14 +-
 tools/lib/bpf/libbpf.c                        | 519 ++++++++++--------
 tools/lib/bpf/libbpf.h                        |   1 +
 tools/lib/bpf/libbpf.map                      |   5 +
 tools/lib/bpf/libbpf_errno.c                  |   7 +-
 tools/lib/bpf/libbpf_internal.h               |  53 ++
 tools/lib/bpf/libbpf_legacy.h                 |  59 ++
 tools/lib/bpf/linker.c                        |  22 +-
 tools/lib/bpf/netlink.c                       |  81 +--
 tools/lib/bpf/ringbuf.c                       |  26 +-
 tools/testing/selftests/bpf/bench.c           |   1 +
 .../selftests/bpf/benchs/bench_rename.c       |   2 +-
 .../selftests/bpf/benchs/bench_ringbufs.c     |   6 +-
 .../selftests/bpf/benchs/bench_trigger.c      |   2 +-
 .../selftests/bpf/prog_tests/attach_probe.c   |  12 +-
 .../selftests/bpf/prog_tests/bpf_iter.c       |  31 +-
 .../selftests/bpf/prog_tests/bpf_tcp_ca.c     |   8 +-
 tools/testing/selftests/bpf/prog_tests/btf.c  |  93 ++--
 .../selftests/bpf/prog_tests/btf_dump.c       |   8 +-
 .../selftests/bpf/prog_tests/btf_write.c      |   4 +-
 .../bpf/prog_tests/cg_storage_multi.c         |  84 +--
 .../bpf/prog_tests/cgroup_attach_multi.c      |   2 +-
 .../selftests/bpf/prog_tests/cgroup_link.c    |  14 +-
 .../bpf/prog_tests/cgroup_skb_sk_lookup.c     |   2 +-
 .../selftests/bpf/prog_tests/check_mtu.c      |   2 +-
 .../selftests/bpf/prog_tests/core_reloc.c     |  15 +-
 .../selftests/bpf/prog_tests/fexit_bpf2bpf.c  |  25 +-
 .../selftests/bpf/prog_tests/flow_dissector.c |   2 +-
 .../bpf/prog_tests/flow_dissector_reattach.c  |  10 +-
 .../bpf/prog_tests/get_stack_raw_tp.c         |  10 +-
 .../prog_tests/get_stackid_cannot_attach.c    |   9 +-
 .../selftests/bpf/prog_tests/hashmap.c        |   9 +-
 .../selftests/bpf/prog_tests/kfree_skb.c      |  19 +-
 .../selftests/bpf/prog_tests/ksyms_btf.c      |   3 +-
 .../selftests/bpf/prog_tests/link_pinning.c   |   7 +-
 .../selftests/bpf/prog_tests/obj_name.c       |   8 +-
 .../selftests/bpf/prog_tests/perf_branches.c  |   4 +-
 .../selftests/bpf/prog_tests/perf_buffer.c    |   2 +-
 .../bpf/prog_tests/perf_event_stackmap.c      |   3 +-
 .../selftests/bpf/prog_tests/probe_user.c     |   7 +-
 .../selftests/bpf/prog_tests/prog_run_xattr.c |   4 +-
 .../bpf/prog_tests/raw_tp_test_run.c          |   4 +-
 .../selftests/bpf/prog_tests/rdonly_maps.c    |   7 +-
 .../bpf/prog_tests/reference_tracking.c       |   2 +-
 .../selftests/bpf/prog_tests/resolve_btfids.c |   2 +-
 .../selftests/bpf/prog_tests/ringbuf_multi.c  |   2 +-
 .../bpf/prog_tests/select_reuseport.c         |  53 +-
 .../selftests/bpf/prog_tests/send_signal.c    |   3 +-
 .../selftests/bpf/prog_tests/sk_lookup.c      |   2 +-
 .../selftests/bpf/prog_tests/sock_fields.c    |  14 +-
 .../selftests/bpf/prog_tests/sockmap_basic.c  |   8 +-
 .../selftests/bpf/prog_tests/sockmap_ktls.c   |   2 +-
 .../selftests/bpf/prog_tests/sockmap_listen.c |  10 +-
 .../bpf/prog_tests/stacktrace_build_id_nmi.c  |   3 +-
 .../selftests/bpf/prog_tests/stacktrace_map.c |   2 +-
 .../bpf/prog_tests/stacktrace_map_raw_tp.c    |   5 +-
 .../bpf/prog_tests/tcp_hdr_options.c          |  15 +-
 .../selftests/bpf/prog_tests/test_overhead.c  |  12 +-
 .../bpf/prog_tests/trampoline_count.c         |  14 +-
 .../selftests/bpf/prog_tests/udp_limit.c      |   7 +-
 .../selftests/bpf/prog_tests/xdp_bpf2bpf.c    |   2 +-
 .../selftests/bpf/prog_tests/xdp_link.c       |   8 +-
 tools/testing/selftests/bpf/test_maps.c       | 168 +++---
 tools/testing/selftests/bpf/test_progs.c      |   3 +
 tools/testing/selftests/bpf/test_progs.h      |   9 +-
 .../selftests/bpf/test_tcpnotify_user.c       |   7 +-
 71 files changed, 1123 insertions(+), 952 deletions(-)
 create mode 100644 tools/lib/bpf/libbpf_legacy.h
Signature · 1 line
2.30.2
Acked-by on the v1 series
#1 lore raw
Quoted 32 lines · Andrii Nakryiko

Implement error reporting changes discussed in "Libbpf: the road to v1.0" ([0]) document.

Libbpf gets a new API, libbpf_set_strict_mode() which accepts a set of flags that turn on a set of libbpf 1.0 changes, that might be potentially breaking. It's possible to opt-in into all current and future 1.0 features by specifying LIBBPF_STRICT_ALL flag.

When some of the 1.0 "features" are requested, libbpf APIs might behave differently. In this patch set a first set of changes are implemented, all related to the way libbpf returns errors. See individual patches for details.

Patch #1 adds a no-op libbpf_set_strict_mode() functionality to enable updating selftests.

Patch #2 gets rid of all the bad code patterns that will break in libbpf 1.0 (exact -1 comparison for low-level APIs, direct IS_ERR() macro usage to check pointer-returning APIs for error, etc). These changes make selftest work in both legacy and 1.0 libbpf modes. Selftests also opt-in into 100% libbpf 1.0 mode to automatically gain all the subsequent changes, which will come in follow up patches.

Patch #3 streamlines error reporting for low-level APIs wrapping bpf() syscall.

Patch #4 streamlines errors for all the rest APIs.

Patch #5 ensures that BPF skeletons propagate errors properly as well, as currently on error some APIs will return NULL with no way of checking exact error code.

[0] https://docs.google.com/document/d/1UyjTZuPFWiPFyKk1tV5an11_iaRuec6U-ZESZ54nNTY

Quoted 8 lines

Andrii Nakryiko (5):
libbpf: add libbpf_set_strict_mode() API to turn on libbpf 1.0
behaviors
selftests/bpf: turn on libbpf 1.0 mode and fix all IS_ERR checks
libbpf: streamline error reporting for low-level APIs
libbpf: streamline error reporting for high-level APIs
bpftool: set errno on skeleton failures and propagate errors

LGTM for the series,

#2 lore raw
Quoted 43 lines · John Fastabend
Quoted 32 lines · Andrii Nakryiko

Implement error reporting changes discussed in "Libbpf: the road to v1.0" ([0]) document.

Libbpf gets a new API, libbpf_set_strict_mode() which accepts a set of flags that turn on a set of libbpf 1.0 changes, that might be potentially breaking. It's possible to opt-in into all current and future 1.0 features by specifying LIBBPF_STRICT_ALL flag.

When some of the 1.0 "features" are requested, libbpf APIs might behave differently. In this patch set a first set of changes are implemented, all related to the way libbpf returns errors. See individual patches for details.

Patch #1 adds a no-op libbpf_set_strict_mode() functionality to enable updating selftests.

Patch #2 gets rid of all the bad code patterns that will break in libbpf 1.0 (exact -1 comparison for low-level APIs, direct IS_ERR() macro usage to check pointer-returning APIs for error, etc). These changes make selftest work in both legacy and 1.0 libbpf modes. Selftests also opt-in into 100% libbpf 1.0 mode to automatically gain all the subsequent changes, which will come in follow up patches.

Patch #3 streamlines error reporting for low-level APIs wrapping bpf() syscall.

Patch #4 streamlines errors for all the rest APIs.

Patch #5 ensures that BPF skeletons propagate errors properly as well, as currently on error some APIs will return NULL with no way of checking exact error code.

[0] https://docs.google.com/document/d/1UyjTZuPFWiPFyKk1tV5an11_iaRuec6U-ZESZ54nNTY

Quoted 8 lines

Andrii Nakryiko (5):
libbpf: add libbpf_set_strict_mode() API to turn on libbpf 1.0
behaviors
selftests/bpf: turn on libbpf 1.0 mode and fix all IS_ERR checks
libbpf: streamline error reporting for low-level APIs
libbpf: streamline error reporting for high-level APIs
bpftool: set errno on skeleton failures and propagate errors

Quoted 3 lines

LGTM for the series,

Thanks, John!

Toke, Stanislav, you cared about these aspects of libbpf 1.0 (by commenting on the doc itself), do you mind also taking a brief look and letting me know if this works for your use cases? Thanks!

#3 lore raw
Quoted 48 lines · Andrii Nakryiko
Quoted 45 lines · John Fastabend
Quoted 32 lines · Andrii Nakryiko

Implement error reporting changes discussed in "Libbpf: the road to v1.0" ([0]) document.

Libbpf gets a new API, libbpf_set_strict_mode() which accepts a set of flags that turn on a set of libbpf 1.0 changes, that might be potentially breaking. It's possible to opt-in into all current and future 1.0 features by specifying LIBBPF_STRICT_ALL flag.

When some of the 1.0 "features" are requested, libbpf APIs might behave differently. In this patch set a first set of changes are implemented, all related to the way libbpf returns errors. See individual patches for details.

Patch #1 adds a no-op libbpf_set_strict_mode() functionality to enable updating selftests.

Patch #2 gets rid of all the bad code patterns that will break in libbpf 1.0 (exact -1 comparison for low-level APIs, direct IS_ERR() macro usage to check pointer-returning APIs for error, etc). These changes make selftest work in both legacy and 1.0 libbpf modes. Selftests also opt-in into 100% libbpf 1.0 mode to automatically gain all the subsequent changes, which will come in follow up patches.

Patch #3 streamlines error reporting for low-level APIs wrapping bpf() syscall.

Patch #4 streamlines errors for all the rest APIs.

Patch #5 ensures that BPF skeletons propagate errors properly as well, as currently on error some APIs will return NULL with no way of checking exact error code.

[0] https://docs.google.com/document/d/1UyjTZuPFWiPFyKk1tV5an11_iaRuec6U-ZESZ54nNTY

Quoted 8 lines

Andrii Nakryiko (5):
libbpf: add libbpf_set_strict_mode() API to turn on libbpf 1.0
behaviors
selftests/bpf: turn on libbpf 1.0 mode and fix all IS_ERR checks
libbpf: streamline error reporting for low-level APIs
libbpf: streamline error reporting for high-level APIs
bpftool: set errno on skeleton failures and propagate errors

LGTM for the series,

Quoted 7 lines
Quoted 1 line

Thanks, John!

Toke, Stanislav, you cared about these aspects of libbpf 1.0 (by commenting on the doc itself), do you mind also taking a brief look and letting me know if this works for your use cases? Thanks!

I took a quick look earlier today and everything looks good, thanks! I'll try to enable strict mode in our codebase in the coming weeks to see how it goes.

#4 lore raw
Quoted 53 lines · Stanislav Fomichev
Quoted 50 lines · Andrii Nakryiko
Quoted 46 lines · John Fastabend
Quoted 32 lines · Andrii Nakryiko

Implement error reporting changes discussed in "Libbpf: the road to v1.0" ([0]) document.

Libbpf gets a new API, libbpf_set_strict_mode() which accepts a set of flags that turn on a set of libbpf 1.0 changes, that might be potentially breaking. It's possible to opt-in into all current and future 1.0 features by specifying LIBBPF_STRICT_ALL flag.

When some of the 1.0 "features" are requested, libbpf APIs might behave differently. In this patch set a first set of changes are implemented, all related to the way libbpf returns errors. See individual patches for details.

Patch #1 adds a no-op libbpf_set_strict_mode() functionality to enable updating selftests.

Patch #2 gets rid of all the bad code patterns that will break in libbpf 1.0 (exact -1 comparison for low-level APIs, direct IS_ERR() macro usage to check pointer-returning APIs for error, etc). These changes make selftest work in both legacy and 1.0 libbpf modes. Selftests also opt-in into 100% libbpf 1.0 mode to automatically gain all the subsequent changes, which will come in follow up patches.

Patch #3 streamlines error reporting for low-level APIs wrapping bpf() syscall.

Patch #4 streamlines errors for all the rest APIs.

Patch #5 ensures that BPF skeletons propagate errors properly as well, as currently on error some APIs will return NULL with no way of checking exact error code.

[0] https://docs.google.com/document/d/1UyjTZuPFWiPFyKk1tV5an11_iaRuec6U-ZESZ54nNTY

Quoted 8 lines

Andrii Nakryiko (5):
libbpf: add libbpf_set_strict_mode() API to turn on libbpf 1.0
behaviors
selftests/bpf: turn on libbpf 1.0 mode and fix all IS_ERR checks
libbpf: streamline error reporting for low-level APIs
libbpf: streamline error reporting for high-level APIs
bpftool: set errno on skeleton failures and propagate errors

LGTM for the series,

Quoted 7 lines
Quoted 5 lines

Thanks, John!

Toke, Stanislav, you cared about these aspects of libbpf 1.0 (by commenting on the doc itself), do you mind also taking a brief look and letting me know if this works for your use cases? Thanks!

I took a quick look earlier today and everything looks good, thanks!

Great, thanks for looking.

Quoted 2 lines

I'll try to enable strict mode in our codebase in the coming weeks to see how it goes.

Keep in mind, if you do libbpf_set_strict_mode(LIBBPF_STRICT_ALL) you are automatically opting in for all the future "features", so for production you might want to go conservative and start with specifying explicitly LIBBPF_STRICT_DIRECT_ERRS | LIBBPF_STRICT_CLEAN_PTRS, and then add more as you check that your code will handle new changes.

#5 lore raw
In reply to Andrii Nakryiko
Quoted 47 lines · Andrii Nakryiko
Quoted 45 lines · John Fastabend
Quoted 32 lines · Andrii Nakryiko

Implement error reporting changes discussed in "Libbpf: the road to v1.0" ([0]) document.

Libbpf gets a new API, libbpf_set_strict_mode() which accepts a set of flags that turn on a set of libbpf 1.0 changes, that might be potentially breaking. It's possible to opt-in into all current and future 1.0 features by specifying LIBBPF_STRICT_ALL flag.

When some of the 1.0 "features" are requested, libbpf APIs might behave differently. In this patch set a first set of changes are implemented, all related to the way libbpf returns errors. See individual patches for details.

Patch #1 adds a no-op libbpf_set_strict_mode() functionality to enable updating selftests.

Patch #2 gets rid of all the bad code patterns that will break in libbpf 1.0 (exact -1 comparison for low-level APIs, direct IS_ERR() macro usage to check pointer-returning APIs for error, etc). These changes make selftest work in both legacy and 1.0 libbpf modes. Selftests also opt-in into 100% libbpf 1.0 mode to automatically gain all the subsequent changes, which will come in follow up patches.

Patch #3 streamlines error reporting for low-level APIs wrapping bpf() syscall.

Patch #4 streamlines errors for all the rest APIs.

Patch #5 ensures that BPF skeletons propagate errors properly as well, as currently on error some APIs will return NULL with no way of checking exact error code.

[0] https://docs.google.com/document/d/1UyjTZuPFWiPFyKk1tV5an11_iaRuec6U-ZESZ54nNTY

Quoted 8 lines

Andrii Nakryiko (5):
libbpf: add libbpf_set_strict_mode() API to turn on libbpf 1.0
behaviors
selftests/bpf: turn on libbpf 1.0 mode and fix all IS_ERR checks
libbpf: streamline error reporting for low-level APIs
libbpf: streamline error reporting for high-level APIs
bpftool: set errno on skeleton failures and propagate errors

LGTM for the series,

Quoted 7 lines
Quoted 1 line

Thanks, John!

Toke, Stanislav, you cared about these aspects of libbpf 1.0 (by commenting on the doc itself), do you mind also taking a brief look and letting me know if this works for your use cases? Thanks!

Changes LGTM:

As a side note, the series seems to have been chopped up into individual emails with no threading; was a bit weird that I had to go hunting for the individual patches in my mailbox...

#6 lore raw
Quoted 58 lines · Toke Høiland-Jørgensen
Quoted 47 lines · Andrii Nakryiko
Quoted 45 lines · John Fastabend
Quoted 32 lines · Andrii Nakryiko

Implement error reporting changes discussed in "Libbpf: the road to v1.0" ([0]) document.

Libbpf gets a new API, libbpf_set_strict_mode() which accepts a set of flags that turn on a set of libbpf 1.0 changes, that might be potentially breaking. It's possible to opt-in into all current and future 1.0 features by specifying LIBBPF_STRICT_ALL flag.

When some of the 1.0 "features" are requested, libbpf APIs might behave differently. In this patch set a first set of changes are implemented, all related to the way libbpf returns errors. See individual patches for details.

Patch #1 adds a no-op libbpf_set_strict_mode() functionality to enable updating selftests.

Patch #2 gets rid of all the bad code patterns that will break in libbpf 1.0 (exact -1 comparison for low-level APIs, direct IS_ERR() macro usage to check pointer-returning APIs for error, etc). These changes make selftest work in both legacy and 1.0 libbpf modes. Selftests also opt-in into 100% libbpf 1.0 mode to automatically gain all the subsequent changes, which will come in follow up patches.

Patch #3 streamlines error reporting for low-level APIs wrapping bpf() syscall.

Patch #4 streamlines errors for all the rest APIs.

Patch #5 ensures that BPF skeletons propagate errors properly as well, as currently on error some APIs will return NULL with no way of checking exact error code.

[0] https://docs.google.com/document/d/1UyjTZuPFWiPFyKk1tV5an11_iaRuec6U-ZESZ54nNTY

Quoted 8 lines

Andrii Nakryiko (5):
libbpf: add libbpf_set_strict_mode() API to turn on libbpf 1.0
behaviors
selftests/bpf: turn on libbpf 1.0 mode and fix all IS_ERR checks
libbpf: streamline error reporting for low-level APIs
libbpf: streamline error reporting for high-level APIs
bpftool: set errno on skeleton failures and propagate errors

LGTM for the series,

Quoted 7 lines
Quoted 1 line

Thanks, John!

Toke, Stanislav, you cared about these aspects of libbpf 1.0 (by commenting on the doc itself), do you mind also taking a brief look and letting me know if this works for your use cases? Thanks!

Quoted 8 lines

Changes LGTM:

As a side note, the series seems to have been chopped up into individual emails with no threading; was a bit weird that I had to go hunting for the individual patches in my mailbox...

That's my bad, I messed up and sent them individually and probably that's why they weren't threaded properly.

#7 lore raw
Quoted 63 lines · Andrii Nakryiko
Quoted 62 lines · Toke Høiland-Jørgensen
Quoted 47 lines · Andrii Nakryiko
Quoted 45 lines · John Fastabend
Quoted 32 lines · Andrii Nakryiko

Implement error reporting changes discussed in "Libbpf: the road to v1.0" ([0]) document.

Libbpf gets a new API, libbpf_set_strict_mode() which accepts a set of flags that turn on a set of libbpf 1.0 changes, that might be potentially breaking. It's possible to opt-in into all current and future 1.0 features by specifying LIBBPF_STRICT_ALL flag.

When some of the 1.0 "features" are requested, libbpf APIs might behave differently. In this patch set a first set of changes are implemented, all related to the way libbpf returns errors. See individual patches for details.

Patch #1 adds a no-op libbpf_set_strict_mode() functionality to enable updating selftests.

Patch #2 gets rid of all the bad code patterns that will break in libbpf 1.0 (exact -1 comparison for low-level APIs, direct IS_ERR() macro usage to check pointer-returning APIs for error, etc). These changes make selftest work in both legacy and 1.0 libbpf modes. Selftests also opt-in into 100% libbpf 1.0 mode to automatically gain all the subsequent changes, which will come in follow up patches.

Patch #3 streamlines error reporting for low-level APIs wrapping bpf() syscall.

Patch #4 streamlines errors for all the rest APIs.

Patch #5 ensures that BPF skeletons propagate errors properly as well, as currently on error some APIs will return NULL with no way of checking exact error code.

[0] https://docs.google.com/document/d/1UyjTZuPFWiPFyKk1tV5an11_iaRuec6U-ZESZ54nNTY

Quoted 8 lines

Andrii Nakryiko (5):
libbpf: add libbpf_set_strict_mode() API to turn on libbpf 1.0
behaviors
selftests/bpf: turn on libbpf 1.0 mode and fix all IS_ERR checks
libbpf: streamline error reporting for low-level APIs
libbpf: streamline error reporting for high-level APIs
bpftool: set errno on skeleton failures and propagate errors

LGTM for the series,

Quoted 7 lines
Quoted 1 line

Thanks, John!

Toke, Stanislav, you cared about these aspects of libbpf 1.0 (by commenting on the doc itself), do you mind also taking a brief look and letting me know if this works for your use cases? Thanks!

Changes LGTM:

Quoted 7 lines
Quoted 4 lines

As a side note, the series seems to have been chopped up into individual emails with no threading; was a bit weird that I had to go hunting for the individual patches in my mailbox...

That's my bad, I messed up and sent them individually and probably that's why they weren't threaded properly.

Right, OK, I'll stop looking for bugs on my end, then :)

BTW, one more thing that just came to mind: since that gdoc is not likely to be around forever, would it be useful to make the reference in the commit message(s) point to something more stable? IDK what that shoul be, really. Maybe just pasting (an abbreviated outline of?) the text in the document into the cover letter / merge commit could work?

-Toke

#8 lore raw
Quoted 74 lines · Toke Høiland-Jørgensen
Quoted 63 lines · Andrii Nakryiko
Quoted 62 lines · Toke Høiland-Jørgensen
Quoted 47 lines · Andrii Nakryiko
Quoted 45 lines · John Fastabend
Quoted 32 lines · Andrii Nakryiko

Implement error reporting changes discussed in "Libbpf: the road to v1.0" ([0]) document.

Libbpf gets a new API, libbpf_set_strict_mode() which accepts a set of flags that turn on a set of libbpf 1.0 changes, that might be potentially breaking. It's possible to opt-in into all current and future 1.0 features by specifying LIBBPF_STRICT_ALL flag.

When some of the 1.0 "features" are requested, libbpf APIs might behave differently. In this patch set a first set of changes are implemented, all related to the way libbpf returns errors. See individual patches for details.

Patch #1 adds a no-op libbpf_set_strict_mode() functionality to enable updating selftests.

Patch #2 gets rid of all the bad code patterns that will break in libbpf 1.0 (exact -1 comparison for low-level APIs, direct IS_ERR() macro usage to check pointer-returning APIs for error, etc). These changes make selftest work in both legacy and 1.0 libbpf modes. Selftests also opt-in into 100% libbpf 1.0 mode to automatically gain all the subsequent changes, which will come in follow up patches.

Patch #3 streamlines error reporting for low-level APIs wrapping bpf() syscall.

Patch #4 streamlines errors for all the rest APIs.

Patch #5 ensures that BPF skeletons propagate errors properly as well, as currently on error some APIs will return NULL with no way of checking exact error code.

[0] https://docs.google.com/document/d/1UyjTZuPFWiPFyKk1tV5an11_iaRuec6U-ZESZ54nNTY

Quoted 8 lines

Andrii Nakryiko (5):
libbpf: add libbpf_set_strict_mode() API to turn on libbpf 1.0
behaviors
selftests/bpf: turn on libbpf 1.0 mode and fix all IS_ERR checks
libbpf: streamline error reporting for low-level APIs
libbpf: streamline error reporting for high-level APIs
bpftool: set errno on skeleton failures and propagate errors

LGTM for the series,

Quoted 7 lines
Quoted 1 line

Thanks, John!

Toke, Stanislav, you cared about these aspects of libbpf 1.0 (by commenting on the doc itself), do you mind also taking a brief look and letting me know if this works for your use cases? Thanks!

Changes LGTM:

Quoted 7 lines
Quoted 4 lines

As a side note, the series seems to have been chopped up into individual emails with no threading; was a bit weird that I had to go hunting for the individual patches in my mailbox...

That's my bad, I messed up and sent them individually and probably that's why they weren't threaded properly.

Quoted 7 lines

Right, OK, I'll stop looking for bugs on my end, then :)

BTW, one more thing that just came to mind: since that gdoc is not likely to be around forever, would it be useful to make the reference in the commit message(s) point to something more stable? IDK what that shoul be, really. Maybe just pasting (an abbreviated outline of?) the text in the document into the cover letter / merge commit could work?

I was hoping Google won't deprecate Google Docs any time soon and I had no intention to remove that document. But I was also thinking to start wiki page at github.com/libbpf/libbpf with migration instructions, so once that is up and running I can link that from libbpf_set_strict_mode() doc comment. But I'd like to avoid blocking on that.

Quoted 3 lines

-Toke

#9 lore raw
Quoted 83 lines · Andrii Nakryiko
Quoted 74 lines · Toke Høiland-Jørgensen
Quoted 63 lines · Andrii Nakryiko
Quoted 62 lines · Toke Høiland-Jørgensen
Quoted 47 lines · Andrii Nakryiko
Quoted 45 lines · John Fastabend
Quoted 32 lines · Andrii Nakryiko

Implement error reporting changes discussed in "Libbpf: the road to v1.0" ([0]) document.

Libbpf gets a new API, libbpf_set_strict_mode() which accepts a set of flags that turn on a set of libbpf 1.0 changes, that might be potentially breaking. It's possible to opt-in into all current and future 1.0 features by specifying LIBBPF_STRICT_ALL flag.

When some of the 1.0 "features" are requested, libbpf APIs might behave differently. In this patch set a first set of changes are implemented, all related to the way libbpf returns errors. See individual patches for details.

Patch #1 adds a no-op libbpf_set_strict_mode() functionality to enable updating selftests.

Patch #2 gets rid of all the bad code patterns that will break in libbpf 1.0 (exact -1 comparison for low-level APIs, direct IS_ERR() macro usage to check pointer-returning APIs for error, etc). These changes make selftest work in both legacy and 1.0 libbpf modes. Selftests also opt-in into 100% libbpf 1.0 mode to automatically gain all the subsequent changes, which will come in follow up patches.

Patch #3 streamlines error reporting for low-level APIs wrapping bpf() syscall.

Patch #4 streamlines errors for all the rest APIs.

Patch #5 ensures that BPF skeletons propagate errors properly as well, as currently on error some APIs will return NULL with no way of checking exact error code.

[0] https://docs.google.com/document/d/1UyjTZuPFWiPFyKk1tV5an11_iaRuec6U-ZESZ54nNTY

Quoted 8 lines

Andrii Nakryiko (5):
libbpf: add libbpf_set_strict_mode() API to turn on libbpf 1.0
behaviors
selftests/bpf: turn on libbpf 1.0 mode and fix all IS_ERR checks
libbpf: streamline error reporting for low-level APIs
libbpf: streamline error reporting for high-level APIs
bpftool: set errno on skeleton failures and propagate errors

LGTM for the series,

Quoted 7 lines
Quoted 1 line

Thanks, John!

Toke, Stanislav, you cared about these aspects of libbpf 1.0 (by commenting on the doc itself), do you mind also taking a brief look and letting me know if this works for your use cases? Thanks!

Changes LGTM:

Quoted 7 lines
Quoted 4 lines

As a side note, the series seems to have been chopped up into individual emails with no threading; was a bit weird that I had to go hunting for the individual patches in my mailbox...

That's my bad, I messed up and sent them individually and probably that's why they weren't threaded properly.

Quoted 7 lines

Right, OK, I'll stop looking for bugs on my end, then :)

BTW, one more thing that just came to mind: since that gdoc is not likely to be around forever, would it be useful to make the reference in the commit message(s) point to something more stable? IDK what that shoul be, really. Maybe just pasting (an abbreviated outline of?) the text in the document into the cover letter / merge commit could work?

Quoted 5 lines

I was hoping Google won't deprecate Google Docs any time soon and I had no intention to remove that document. But I was also thinking to start wiki page at github.com/libbpf/libbpf with migration instructions, so once that is up and running I can link that from libbpf_set_strict_mode() doc comment.

Right, that sounds reasonable :)

Quoted 1 line

But I'd like to avoid blocking on that.

Understandable; but just pasting an outline into the commit message (and keeping the link) could work in the meantime?

-Toke

#10 lore raw
Quoted 92 lines · Toke Høiland-Jørgensen
Quoted 83 lines · Andrii Nakryiko
Quoted 74 lines · Toke Høiland-Jørgensen
Quoted 63 lines · Andrii Nakryiko
Quoted 62 lines · Toke Høiland-Jørgensen
Quoted 47 lines · Andrii Nakryiko
Quoted 45 lines · John Fastabend
Quoted 32 lines · Andrii Nakryiko

Implement error reporting changes discussed in "Libbpf: the road to v1.0" ([0]) document.

Libbpf gets a new API, libbpf_set_strict_mode() which accepts a set of flags that turn on a set of libbpf 1.0 changes, that might be potentially breaking. It's possible to opt-in into all current and future 1.0 features by specifying LIBBPF_STRICT_ALL flag.

When some of the 1.0 "features" are requested, libbpf APIs might behave differently. In this patch set a first set of changes are implemented, all related to the way libbpf returns errors. See individual patches for details.

Patch #1 adds a no-op libbpf_set_strict_mode() functionality to enable updating selftests.

Patch #2 gets rid of all the bad code patterns that will break in libbpf 1.0 (exact -1 comparison for low-level APIs, direct IS_ERR() macro usage to check pointer-returning APIs for error, etc). These changes make selftest work in both legacy and 1.0 libbpf modes. Selftests also opt-in into 100% libbpf 1.0 mode to automatically gain all the subsequent changes, which will come in follow up patches.

Patch #3 streamlines error reporting for low-level APIs wrapping bpf() syscall.

Patch #4 streamlines errors for all the rest APIs.

Patch #5 ensures that BPF skeletons propagate errors properly as well, as currently on error some APIs will return NULL with no way of checking exact error code.

[0] https://docs.google.com/document/d/1UyjTZuPFWiPFyKk1tV5an11_iaRuec6U-ZESZ54nNTY

Quoted 8 lines

Andrii Nakryiko (5):
libbpf: add libbpf_set_strict_mode() API to turn on libbpf 1.0
behaviors
selftests/bpf: turn on libbpf 1.0 mode and fix all IS_ERR checks
libbpf: streamline error reporting for low-level APIs
libbpf: streamline error reporting for high-level APIs
bpftool: set errno on skeleton failures and propagate errors

LGTM for the series,

Quoted 7 lines
Quoted 1 line

Thanks, John!

Toke, Stanislav, you cared about these aspects of libbpf 1.0 (by commenting on the doc itself), do you mind also taking a brief look and letting me know if this works for your use cases? Thanks!

Changes LGTM:

Quoted 7 lines
Quoted 4 lines

As a side note, the series seems to have been chopped up into individual emails with no threading; was a bit weird that I had to go hunting for the individual patches in my mailbox...

That's my bad, I messed up and sent them individually and probably that's why they weren't threaded properly.

Quoted 7 lines

Right, OK, I'll stop looking for bugs on my end, then :)

BTW, one more thing that just came to mind: since that gdoc is not likely to be around forever, would it be useful to make the reference in the commit message(s) point to something more stable? IDK what that shoul be, really. Maybe just pasting (an abbreviated outline of?) the text in the document into the cover letter / merge commit could work?

Quoted 5 lines

I was hoping Google won't deprecate Google Docs any time soon and I had no intention to remove that document. But I was also thinking to start wiki page at github.com/libbpf/libbpf with migration instructions, so once that is up and running I can link that from libbpf_set_strict_mode() doc comment.

Quoted 6 lines

Right, that sounds reasonable :)

Quoted 1 line

But I'd like to avoid blocking on that.

Understandable; but just pasting an outline into the commit message (and keeping the link) could work in the meantime?

I'm not sure what are we trying to achieve by copy/pasting parts of that doc here. Each patch succinctly explains how each feature behaves, so it's completely self-describing. I put the link to the document for anyone that wants to read the entire discussion or leave some more comments, but it's not mandatory to understand this patch set.

Quoted 3 lines

-Toke