Commit c4d6d78
mm/slab: allow freeing kmalloc_nolock()'d objects using kfree[_rcu]()
Slab objects that are allocated with kmalloc_nolock() must be freed
using kfree_nolock() because only a subset of alloc hooks are called,
since kmalloc_nolock() can't spin on a lock during allocation.
This imposes a limitation: such objects cannot be freed with kfree_rcu(),
forcing users to work around this limitation by calling call_rcu()
with a callback that frees the object using kfree_nolock().
Remove this limitation by teaching kmemleak to gracefully ignore cases
when kmemleak_free() or kmemleak_ignore() is called without a prior
kmemleak_alloc().
Unlike kmemleak, kfence already handles this case, because,
due to its design, only a subset of allocations are served from kfence.
With this change, kfree() and kfree_rcu() can be used to free objects
that are allocated using kmalloc_nolock().
Suggested-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
Link: https://patch.msgid.link/20260210044642.139482-2-harry.yoo@oracle.com
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>1 parent a1e244a commit c4d6d78
3 files changed
Lines changed: 32 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1076 | 1076 | | |
1077 | 1077 | | |
1078 | 1078 | | |
1079 | | - | |
1080 | | - | |
| 1079 | + | |
| 1080 | + | |
1081 | 1081 | | |
1082 | 1082 | | |
1083 | 1083 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
837 | 837 | | |
838 | 838 | | |
839 | 839 | | |
840 | | - | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | | - | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
845 | 845 | | |
846 | | - | |
847 | 846 | | |
848 | 847 | | |
849 | 848 | | |
| |||
926 | 925 | | |
927 | 926 | | |
928 | 927 | | |
929 | | - | |
930 | | - | |
931 | | - | |
932 | | - | |
933 | | - | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
934 | 933 | | |
935 | | - | |
936 | 934 | | |
937 | 935 | | |
938 | 936 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2585 | 2585 | | |
2586 | 2586 | | |
2587 | 2587 | | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
2588 | 2606 | | |
2589 | 2607 | | |
2590 | 2608 | | |
| |||
6394 | 6412 | | |
6395 | 6413 | | |
6396 | 6414 | | |
6397 | | - | |
| 6415 | + | |
6398 | 6416 | | |
6399 | 6417 | | |
6400 | 6418 | | |
| |||
6413 | 6431 | | |
6414 | 6432 | | |
6415 | 6433 | | |
| 6434 | + | |
6416 | 6435 | | |
6417 | 6436 | | |
6418 | 6437 | | |
| |||
0 commit comments