BPF List
 help / color / mirror / Atom feed
* [PATCH bpf v3 0/3] bpf: Fix incorrect handling of user flags by percpu map updates
@ 2026-10-03 16:02 Masoud Aghasi
  2026-10-03 16:02 ` [PATCH bpf v3 1/3] bpf: Fix incorrect handling of user flags in bpf_percpu_array_update Masoud Aghasi
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Masoud Aghasi @ 2026-10-03 16:02 UTC (permalink / raw)
  To: bpf
  Cc: andrii, eddyz87, ast, daniel, memxor, martin.lau, song,
	yonghong.song, jolsa, emil, ihor.solodrai, leon.hwang,
	Masoud Aghasi

For BPF_MAP_TYPE_PERCPU_ARRAY map, bpf_percpu_array_update()
is not considering the possibility of a combination of
(BPF_NOEXIST, BPF_EXIST) flags with (BPF_F_CPU, BPF_F_ALL_CPUS) flags.
This causes the (BPF_NOEXIST, BPF_EXIST) flags to lose their effect
in some cases.

For BPF_MAP_TYPE_PERCPU_HASH and BPF_MAP_TYPE_LRU_PERCPU_HASH maps,
htab_map_check_update_flags() and check_flags() are not considering
the possibility of a combination of (BPF_NOEXIST, BPF_EXIST) flags
with (BPF_F_CPU, BPF_F_ALL_CPUS) flags.
This causes the (BPF_NOEXIST, BPF_EXIST) flags to lose their effect.

For example, when using (BPF_F_CPU | BPF_EXIST) flag combination
with bpf_map_update_elem() on a BPF_MAP_TYPE_PERCPU_HASH map, the
BPF_EXIST flag does not prevent new insertions as expected.

This series fixes the bug by adding proper flag validations and checks
and adds regression tests.

V3 changes:
- Split the fix into two separate patches for array map and hash maps
- Extend the selftest to cover all percpu map types
- Extend the selftest to cover all applicable flag combinations
- Extend the selftest to cover the unnecessary delete issue of LRU map

V2 changes:
- Fix a BPF_EXIST flag check in __htab_lru_percpu_map_update_elem()
- Add additional test for BPF_MAP_TYPE_LRU_PERCPU_HASH map
- Add check for BPF_EXIST, BPF_NOEXIST combination in percpu array map

Masoud Aghasi (3):
  bpf: Fix incorrect handling of user flags in bpf_percpu_array_update
  bpf: Fix incorrect handling of user flags by percpu hash map updates
  selftests/bpf: add tests for percpu map flags combination

 kernel/bpf/arraymap.c                         |   5 +-
 kernel/bpf/hashtab.c                          |  11 +-
 .../selftests/bpf/prog_tests/percpu_alloc.c   | 159 ++++++++++++++++++
 3 files changed, 169 insertions(+), 6 deletions(-)

-- 
2.47.3


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

end of thread, other threads:[~2026-10-04  9:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-03 16:02 [PATCH bpf v3 0/3] bpf: Fix incorrect handling of user flags by percpu map updates Masoud Aghasi
2026-10-03 16:02 ` [PATCH bpf v3 1/3] bpf: Fix incorrect handling of user flags in bpf_percpu_array_update Masoud Aghasi
2026-10-03 16:02 ` [PATCH bpf v3 2/3] bpf: Fix incorrect handling of user flags by percpu hash map updates Masoud Aghasi
2026-10-03 16:41   ` bot+bpf-ci
2026-10-03 16:02 ` [PATCH bpf v3 3/3] selftests/bpf: add tests for percpu map flags combination Masoud Aghasi
2026-10-03 16:41   ` bot+bpf-ci
2026-10-03 17:56   ` sashiko-bot
2026-10-04  9:39   ` Masoud Aghasi

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