Skip to content

reduce BPF_ID_MAP_SIZE to fit only valid programs

Eduard Zingerman bpf 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 13 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4selftests/bpf: support for BPF_F_TEST_STATE_FREQ in test_loadertools/testing/selftests/bpf/progs/bpf_misc.h tools/testing/selftests/bpf/test_loader.c+11 -04 replies
2/4selftests/bpf: convenience macro for use with 'asm volatile' blockstools/testing/selftests/bpf/progs/bpf_misc.h+6 -03 replies
3/4bpf: reduce BPF_ID_MAP_SIZE to fit only valid programsinclude/linux/bpf_verifier.h kernel/bpf/verifier.c+6 -42 replies
4/4selftests/bpf: check if verifier.c:check_ids() handles 64+5 idstools/testing/selftests/bpf/prog_tests/verifier.c tools/testing/selftests/bpf/progs/check_ids_limits.c+89 -03 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchYonghong SongAndrii Nakryiko
1/4A-b
2/4A-b A-b
3/4A-b A-b
4/4A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH bpf-next 0/4] reduce BPF_ID_MAP_SIZE to fit only valid programs

This is a follow-up for threads [1] and [2]:
- The size of the bpf_verifier_state->idmap_scratch array is reduced but remains sufficient for any valid BPF program.
- selftests/bpf test_loader is updated to allow specifying that program requires BPF_F_TEST_STATE_FREQ flag.
- Test case for the verifier.c:check_ids() update uses test_loader and is meant as an example of using it for test_verifier-kind tests.

The combination of test_loader and naked functions (see [3]) with inline assembly allows to write verifier tests easier than it is done currently with BPF_RAW_INSN-series macros.

One can follow the steps below to add new tests of such kind:
- add a topic file under bpf/progs/ directory;
- define test programs using naked functions and inline assembly:

	#include <linux/bpf.h>
	#include "bpf_misc.h"
	
	SEC(...)
	__naked int foo_test(void)
	{
		asm volatile(
			"r0 = 0;"
			"exit;"
			::: __clobber_all);
	}

- add skeleton and runner functions in prog_tests/verifier.c:

	#include "topic.skel.h"
	TEST_SET(topic)

After these steps the test_progs binary would include the topic tests. Topic tests could be selectively executed using the following command:

$ ./test_progs -vvv -a topic

These changes are suggested by Andrii Nakryiko.

[1] https://lore.kernel.org/bpf/CAEf4BzYN1JmY9t03pnCHc4actob80wkBz2vk90ihJCBzi8CT9w@mail.gmail.com/
[2] https://lore.kernel.org/bpf/CAEf4BzYPsDWdRgx+ND1wiKAB62P=WwoLhr2uWkbVpQfbHqi1oA@mail.gmail.com/
[3] https://gcc.gnu.org/onlinedocs/gcc/Basic-Asm.html#Basic-Asm

Eduard Zingerman (4):
selftests/bpf: support for BPF_F_TEST_STATE_FREQ in test_loader selftests/bpf: convenience macro for use with 'asm volatile' blocks
bpf: reduce BPF_ID_MAP_SIZE to fit only valid programs selftests/bpf: check if verifier.c:check_ids() handles 64+5 ids

 include/linux/bpf_verifier.h                  |  4 +-
 kernel/bpf/verifier.c                         |  6 +-
 .../selftests/bpf/prog_tests/verifier.c       | 12 +++
 tools/testing/selftests/bpf/progs/bpf_misc.h  |  7 ++
 .../selftests/bpf/progs/check_ids_limits.c    | 77 +++++++++++++++++++
 tools/testing/selftests/bpf/test_loader.c     | 10 +++
 6 files changed, 112 insertions(+), 4 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/verifier.c
 create mode 100644 tools/testing/selftests/bpf/progs/check_ids_limits.c
Signature · 1 line
2.38.2