-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests/bpf: add test for softlock when modifying hashmap while ite…
…rating Add test that modifies the map while it's being iterated in such a way that hangs the kernel thread unless the _safe fix is applied to bpf_for_each_hash_elem. Signed-off-by: Brandon Kammerdiener <brandon.kammerdiener@intel.com> Link: https://lore.kernel.org/r/20250424153246.141677-3-brandon.kammerdiener@intel.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Hou Tao <houtao1@huawei.com>
- Loading branch information
Brandon Kammerdiener
authored and
Alexei Starovoitov
committed
Apr 25, 2025
1 parent
75673fd
commit 3d9c463
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2025 Intel Corporation */ | ||
#include "vmlinux.h" | ||
#include <bpf/bpf_helpers.h> | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_HASH); | ||
__uint(max_entries, 128); | ||
__type(key, __u64); | ||
__type(value, __u64); | ||
} hashmap SEC(".maps"); | ||
|
||
static int cb(struct bpf_map *map, __u64 *key, __u64 *val, void *arg) | ||
{ | ||
bpf_map_delete_elem(map, key); | ||
bpf_map_update_elem(map, key, val, 0); | ||
return 0; | ||
} | ||
|
||
SEC("tc") | ||
int test_pkt_access(struct __sk_buff *skb) | ||
{ | ||
(void)skb; | ||
|
||
bpf_for_each_map_elem(&hashmap, cb, NULL, 0); | ||
|
||
return 0; | ||
} |