bpf: Fix incorrect handling of user flags by percpu map updates
Status from this message: This series was applied to bpf/bpf-next.git (master)
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v6 Latest3 patches 4 repliesApplied 3/3
- v53 patches 4 repliesSuperseded
- v43 patches 5 repliesSuperseded
Earlier versions · 3
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v3 | 3 patches | 1 reply | Superseded | |
| v2 | 2 patches | 6 replies | Superseded | |
| v1 | 2 patches | 1 reply | Superseded |
Changes in v6 from the cover letter
- Improve the style and structure of the selftest
Patches in v6 All 3 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | bpf: Fix incorrect handling of user flags in bpf_percpu_array_updateinclude/ kernel/ | +6 | 1 reply | Applied |
| 2/3 | bpf: Fix incorrect handling of user flags by percpu hash map updateskernel/ | +6 | 1 reply | Applied |
| 3/3 | selftests/bpf: add tests for percpu map flags combinationtools/ | +254 | 2 replies | Applied |
Reviews trailers per patch
All 3 patches have a Reviewed-by or Acked-by.
| Patch | Leon Hwang |
|---|---|
| 1/3 | A-b |
| 2/3 | A-b |
| 3/3 | A-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH bpf v6 0/3] bpf: Fix incorrect handling of user flags by percpu map updates
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 in some cases.
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.
V6 changes:
- Improve the style and structure of the selftest
V5 changes: https://lore.kernel.org/bpf/[email protected]/T/
- Simplify flag validations by introducing new macros in bpf.h
- Add helpers to verify the values after updates in the new tests
- Improve the style and structure of the new tests
V4 changes: https://lore.kernel.org/bpf/[email protected]/T/
- Edit selftest to use proper value_sz in the new cgroup map test
- Edit selftest to pin the current pid to the current cpu for LRU map
- Edit commit messages to include user-visible changes
V3 changes: https://lore.kernel.org/bpf/[email protected]/T/
- 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: https://lore.kernel.org/bpf/[email protected]/T/
- 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
V1: https://lore.kernel.org/bpf/[email protected]/T/
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
include/linux/bpf.h | 3 + kernel/bpf/arraymap.c | 6 +- kernel/bpf/hashtab.c | 10 +- .../selftests/bpf/prog_tests/percpu_alloc.c | 254 ++++++++++++++++++ 4 files changed, 266 insertions(+), 7 deletions(-)
Signature · 1 line
2.47.3