Commit 5fb750e
bpf: Replace bpf_map_kmalloc_node() with kmalloc_nolock() to allocate bpf_async_cb structures.
The following kmemleak splat:
[ 8.105530] kmemleak: Trying to color unknown object at 0xff11000100e918c0 as Black
[ 8.106521] Call Trace:
[ 8.106521] <TASK>
[ 8.106521] dump_stack_lvl+0x4b/0x70
[ 8.106521] kvfree_call_rcu+0xcb/0x3b0
[ 8.106521] ? hrtimer_cancel+0x21/0x40
[ 8.106521] bpf_obj_free_fields+0x193/0x200
[ 8.106521] htab_map_update_elem+0x29c/0x410
[ 8.106521] bpf_prog_cfc8cd0f42c04044_overwrite_cb+0x47/0x4b
[ 8.106521] bpf_prog_8c30cd7c4db2e963_overwrite_timer+0x65/0x86
[ 8.106521] bpf_prog_test_run_syscall+0xe1/0x2a0
happens due to the combination of features and fixes, but mainly due to
commit 6d78b44 ("bpf: Tell memcg to use allow_spinning=false path in bpf_timer_init()")
It's using __GFP_HIGH, which instructs slub/kmemleak internals to skip
kmemleak_alloc_recursive() on allocation, so subsequent kfree_rcu()->
kvfree_call_rcu()->kmemleak_ignore() complains with the above splat.
To fix this imbalance, replace bpf_map_kmalloc_node() with
kmalloc_nolock() and kfree_rcu() with call_rcu() + kfree_nolock() to
make sure that the objects allocated with kmalloc_nolock() are freed
with kfree_nolock() rather than the implicit kfree() that kfree_rcu()
uses internally.
Note, the kmalloc_nolock() happens under bpf_spin_lock_irqsave(), so
it will always fail in PREEMPT_RT. This is not an issue at the moment,
since bpf_timers are disabled in PREEMPT_RT. In the future
bpf_spin_lock will be replaced with state machine similar to
bpf_task_work.
Fixes: 6d78b44 ("bpf: Tell memcg to use allow_spinning=false path in bpf_timer_init()")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Harry Yoo <harry.yoo@oracle.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-mm@kvack.org
Link: https://lore.kernel.org/bpf/20251015000700.28988-1-alexei.starovoitov@gmail.com1 parent e603a34 commit 5fb750e
3 files changed
+33
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2499 | 2499 | | |
2500 | 2500 | | |
2501 | 2501 | | |
| 2502 | + | |
| 2503 | + | |
2502 | 2504 | | |
2503 | 2505 | | |
2504 | 2506 | | |
| |||
2511 | 2513 | | |
2512 | 2514 | | |
2513 | 2515 | | |
| 2516 | + | |
| 2517 | + | |
2514 | 2518 | | |
2515 | 2519 | | |
2516 | 2520 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1215 | 1215 | | |
1216 | 1216 | | |
1217 | 1217 | | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
1218 | 1225 | | |
1219 | 1226 | | |
1220 | 1227 | | |
1221 | 1228 | | |
1222 | 1229 | | |
1223 | 1230 | | |
1224 | | - | |
| 1231 | + | |
1225 | 1232 | | |
1226 | 1233 | | |
1227 | 1234 | | |
| |||
1230 | 1237 | | |
1231 | 1238 | | |
1232 | 1239 | | |
1233 | | - | |
| 1240 | + | |
1234 | 1241 | | |
1235 | 1242 | | |
1236 | 1243 | | |
1237 | 1244 | | |
1238 | 1245 | | |
1239 | | - | |
| 1246 | + | |
1240 | 1247 | | |
1241 | 1248 | | |
1242 | 1249 | | |
| |||
1270 | 1277 | | |
1271 | 1278 | | |
1272 | 1279 | | |
1273 | | - | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
1277 | | - | |
| 1280 | + | |
1278 | 1281 | | |
1279 | 1282 | | |
1280 | 1283 | | |
| |||
1315 | 1318 | | |
1316 | 1319 | | |
1317 | 1320 | | |
1318 | | - | |
| 1321 | + | |
1319 | 1322 | | |
1320 | 1323 | | |
1321 | 1324 | | |
| |||
1580 | 1583 | | |
1581 | 1584 | | |
1582 | 1585 | | |
1583 | | - | |
| 1586 | + | |
1584 | 1587 | | |
1585 | 1588 | | |
1586 | 1589 | | |
| |||
1607 | 1610 | | |
1608 | 1611 | | |
1609 | 1612 | | |
1610 | | - | |
| 1613 | + | |
1611 | 1614 | | |
1612 | 1615 | | |
1613 | 1616 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
520 | 520 | | |
521 | 521 | | |
522 | 522 | | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
523 | 538 | | |
524 | 539 | | |
525 | 540 | | |
| |||
0 commit comments