Skip to content

Commit f1a3944

Browse files
committed
Merge tag 'bpf-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf
Pull bpf fixes from Alexei Starovoitov: - Add namespace to BPF internal symbols (Alexei Starovoitov) - Fix possible endless loop in BPF map iteration (Brandon Kammerdiener) - Fix compilation failure for samples/bpf on LoongArch (Haoran Jiang) - Disable a part of sockmap_ktls test (Ihor Solodrai) - Correct typo in __clang_major__ macro (Peilin Ye) * tag 'bpf-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf: selftests/bpf: Correct typo in __clang_major__ macro samples/bpf: Fix compilation failure for samples/bpf on LoongArch Fedora bpf: Add namespace to BPF internal symbols selftests/bpf: add test for softlock when modifying hashmap while iterating bpf: fix possible endless loop in BPF map iteration selftests/bpf: Mitigate sockmap_ktls disconnect_after_delete failure
2 parents 1eb09e6 + f000791 commit f1a3944

File tree

9 files changed

+82
-7
lines changed

9 files changed

+82
-7
lines changed

Documentation/bpf/bpf_devel_QA.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,14 @@ In case of new BPF instructions, once the changes have been accepted
382382
into the Linux kernel, please implement support into LLVM's BPF back
383383
end. See LLVM_ section below for further information.
384384

385+
Q: What "BPF_INTERNAL" symbol namespace is for?
386+
-----------------------------------------------
387+
A: Symbols exported as BPF_INTERNAL can only be used by BPF infrastructure
388+
like preload kernel modules with light skeleton. Most symbols outside
389+
of BPF_INTERNAL are not expected to be used by code outside of BPF either.
390+
Symbols may lack the designation because they predate the namespaces,
391+
or due to an oversight.
392+
385393
Stable submission
386394
=================
387395

kernel/bpf/hashtab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,7 @@ static long bpf_for_each_hash_elem(struct bpf_map *map, bpf_callback_t callback_
21892189
b = &htab->buckets[i];
21902190
rcu_read_lock();
21912191
head = &b->head;
2192-
hlist_nulls_for_each_entry_rcu(elem, n, head, hash_node) {
2192+
hlist_nulls_for_each_entry_safe(elem, n, head, hash_node) {
21932193
key = elem->key;
21942194
if (is_percpu) {
21952195
/* current cpu value for percpu map */

kernel/bpf/preload/bpf_preload_kern.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,6 @@ static void __exit fini(void)
8989
}
9090
late_initcall(load);
9191
module_exit(fini);
92+
MODULE_IMPORT_NS("BPF_INTERNAL");
9293
MODULE_LICENSE("GPL");
9394
MODULE_DESCRIPTION("Embedded BPF programs for introspection in bpffs");

kernel/bpf/syscall.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,7 @@ struct bpf_map *bpf_map_get(u32 ufd)
15831583

15841584
return map;
15851585
}
1586-
EXPORT_SYMBOL(bpf_map_get);
1586+
EXPORT_SYMBOL_NS(bpf_map_get, "BPF_INTERNAL");
15871587

15881588
struct bpf_map *bpf_map_get_with_uref(u32 ufd)
15891589
{
@@ -3364,7 +3364,7 @@ struct bpf_link *bpf_link_get_from_fd(u32 ufd)
33643364
bpf_link_inc(link);
33653365
return link;
33663366
}
3367-
EXPORT_SYMBOL(bpf_link_get_from_fd);
3367+
EXPORT_SYMBOL_NS(bpf_link_get_from_fd, "BPF_INTERNAL");
33683368

33693369
static void bpf_tracing_link_release(struct bpf_link *link)
33703370
{
@@ -6020,7 +6020,7 @@ int kern_sys_bpf(int cmd, union bpf_attr *attr, unsigned int size)
60206020
return ____bpf_sys_bpf(cmd, attr, size);
60216021
}
60226022
}
6023-
EXPORT_SYMBOL(kern_sys_bpf);
6023+
EXPORT_SYMBOL_NS(kern_sys_bpf, "BPF_INTERNAL");
60246024

60256025
static const struct bpf_func_proto bpf_sys_bpf_proto = {
60266026
.func = bpf_sys_bpf,

samples/bpf/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ $(obj)/%.o: $(src)/%.c
376376
@echo " CLANG-bpf " $@
377377
$(Q)$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(BPF_EXTRA_CFLAGS) \
378378
-I$(obj) -I$(srctree)/tools/testing/selftests/bpf/ \
379-
-I$(LIBBPF_INCLUDE) \
379+
-I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES) \
380380
-D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \
381381
-D__TARGET_ARCH_$(SRCARCH) -Wno-compare-distinct-pointer-types \
382382
-Wno-gnu-variable-sized-type-not-at-end \

tools/testing/selftests/bpf/prog_tests/for_each.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "for_each_array_map_elem.skel.h"
77
#include "for_each_map_elem_write_key.skel.h"
88
#include "for_each_multi_maps.skel.h"
9+
#include "for_each_hash_modify.skel.h"
910

1011
static unsigned int duration;
1112

@@ -203,6 +204,40 @@ static void test_multi_maps(void)
203204
for_each_multi_maps__destroy(skel);
204205
}
205206

207+
static void test_hash_modify(void)
208+
{
209+
struct for_each_hash_modify *skel;
210+
int max_entries, i, err;
211+
__u64 key, val;
212+
213+
LIBBPF_OPTS(bpf_test_run_opts, topts,
214+
.data_in = &pkt_v4,
215+
.data_size_in = sizeof(pkt_v4),
216+
.repeat = 1
217+
);
218+
219+
skel = for_each_hash_modify__open_and_load();
220+
if (!ASSERT_OK_PTR(skel, "for_each_hash_modify__open_and_load"))
221+
return;
222+
223+
max_entries = bpf_map__max_entries(skel->maps.hashmap);
224+
for (i = 0; i < max_entries; i++) {
225+
key = i;
226+
val = i;
227+
err = bpf_map__update_elem(skel->maps.hashmap, &key, sizeof(key),
228+
&val, sizeof(val), BPF_ANY);
229+
if (!ASSERT_OK(err, "map_update"))
230+
goto out;
231+
}
232+
233+
err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.test_pkt_access), &topts);
234+
ASSERT_OK(err, "bpf_prog_test_run_opts");
235+
ASSERT_OK(topts.retval, "retval");
236+
237+
out:
238+
for_each_hash_modify__destroy(skel);
239+
}
240+
206241
void test_for_each(void)
207242
{
208243
if (test__start_subtest("hash_map"))
@@ -213,4 +248,6 @@ void test_for_each(void)
213248
test_write_map_key();
214249
if (test__start_subtest("multi_maps"))
215250
test_multi_maps();
251+
if (test__start_subtest("hash_modify"))
252+
test_hash_modify();
216253
}

tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ static void test_sockmap_ktls_disconnect_after_delete(int family, int map)
6868
goto close_cli;
6969

7070
err = disconnect(cli);
71-
ASSERT_OK(err, "disconnect");
7271

7372
close_cli:
7473
close(cli);

tools/testing/selftests/bpf/progs/bpf_misc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
#define CAN_USE_GOTOL
222222
#endif
223223

224-
#if _clang_major__ >= 18
224+
#if __clang_major__ >= 18
225225
#define CAN_USE_BPF_ST
226226
#endif
227227

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (c) 2025 Intel Corporation */
3+
#include "vmlinux.h"
4+
#include <bpf/bpf_helpers.h>
5+
6+
char _license[] SEC("license") = "GPL";
7+
8+
struct {
9+
__uint(type, BPF_MAP_TYPE_HASH);
10+
__uint(max_entries, 128);
11+
__type(key, __u64);
12+
__type(value, __u64);
13+
} hashmap SEC(".maps");
14+
15+
static int cb(struct bpf_map *map, __u64 *key, __u64 *val, void *arg)
16+
{
17+
bpf_map_delete_elem(map, key);
18+
bpf_map_update_elem(map, key, val, 0);
19+
return 0;
20+
}
21+
22+
SEC("tc")
23+
int test_pkt_access(struct __sk_buff *skb)
24+
{
25+
(void)skb;
26+
27+
bpf_for_each_map_elem(&hashmap, cb, NULL, 0);
28+
29+
return 0;
30+
}

0 commit comments

Comments
 (0)