bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] bpf: Add a generic bits iterator
@ 2024-02-18 11:48 Yafang Shao
  2024-02-18 11:48 ` [PATCH bpf-next 1/2] bpf: Add " Yafang Shao
  2024-02-18 11:48 ` [PATCH bpf-next 2/2] selftests/bpf: Add selftest for bits iter Yafang Shao
  0 siblings, 2 replies; 11+ messages in thread
From: Yafang Shao @ 2024-02-18 11:48 UTC (permalink / raw)
  To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
	yonghong.song, kpsingh, sdf, haoluo, jolsa
  Cc: bpf, Yafang Shao

Introducing three new kfuncs, namely bpf_iter_bits_{new,next,destroy}, to
support the newly added bits iter functionality. These functions enable
seamless iteration of bits from a specified memory area.

- bpf_iter_bits_new
  Initializes a new bits iterator for a given memory area. Notably, due to
  limitations within bpf memalloc, the maximum number of bits that can be
  iterated over is constrained to (4096 * 8).
- bpf_iter_bits_next
  Get the next bit in a bpf_iter_bits
- bpf_iter_bits_destroy
  Destroy a bpf_iter_bits

The bits iterator can be used in any context and on any address.

In our specific use case, we leverage the cgroup iterator to traverse
percpu data, subsequently exposing it to userspace through a seq file.
For detailed usage examples, please refer to the example in patch #2.

Changes:
- bpf: Add bpf_iter_cpumask
  https://lwn.net/Articles/961104/
- bpf: Add new bpf helper bpf_for_each_cpu
  https://lwn.net/Articles/939939/

Yafang Shao (2):
  bpf: Add bits iterator
  selftests/bpf: Add selftest for bits iter

 kernel/bpf/helpers.c                          | 100 ++++++++++
 tools/testing/selftests/bpf/config            |   1 +
 .../selftests/bpf/prog_tests/bits_iter.c      | 180 ++++++++++++++++++
 .../bpf/progs/test_bits_iter_failure.c        |  53 ++++++
 .../bpf/progs/test_bits_iter_success.c        | 146 ++++++++++++++
 5 files changed, 480 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/bits_iter.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_bits_iter_failure.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_bits_iter_success.c

-- 
2.39.1


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

end of thread, other threads:[~2024-02-27  0:34 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-18 11:48 [PATCH bpf-next 0/2] bpf: Add a generic bits iterator Yafang Shao
2024-02-18 11:48 ` [PATCH bpf-next 1/2] bpf: Add " Yafang Shao
2024-02-26 23:21   ` John Fastabend
2024-02-27  0:20     ` Alexei Starovoitov
2024-02-27  0:34       ` John Fastabend
2024-02-18 11:48 ` [PATCH bpf-next 2/2] selftests/bpf: Add selftest for bits iter Yafang Shao
2024-02-22 17:36   ` Alexei Starovoitov
2024-02-23  2:29     ` Yafang Shao
2024-02-23 11:52       ` Eduard Zingerman
2024-02-25  2:29         ` Yafang Shao
2024-02-25 19:38   ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).