[PATCH bpf-next 0/2] bpf: Add a generic bits iterator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux