Commit c691e4b
bio: fix kmemleak false positives from percpu bio alloc cache
When a bio is allocated from the mempool with REQ_ALLOC_CACHE set and
later completed, bio_put() places it into the per-cpu bio_alloc_cache
via bio_put_percpu_cache() instead of freeing it back to the
mempool/slab. The slab allocation remains tracked by kmemleak, but the
only reference to the bio is through the percpu cache's free_list,
which kmemleak fails to trace through percpu memory. This causes
kmemleak to report the cached bios as unreferenced objects.
Use symmetric kmemleak_free()/kmemleak_alloc() calls to properly track
bios across percpu cache transitions:
- bio_put_percpu_cache: call kmemleak_free() when a bio enters the
cache, unregistering it from kmemleak tracking.
- bio_alloc_percpu_cache: call kmemleak_alloc() when a bio is taken
from the cache for reuse, re-registering it so that genuine leaks
of reused bios remain detectable.
- __bio_alloc_cache_prune: call kmemleak_alloc() before bio_free() so
that kmem_cache_free()'s internal kmemleak_free() has a matching
allocation to pair with.
Tested-by: Yi Zhang <yi.zhang@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://patch.msgid.link/20260326144058.2392319-1-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>1 parent f91ffe8 commit c691e4b
1 file changed
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
119 | 125 | | |
120 | 126 | | |
121 | 127 | | |
| |||
486 | 492 | | |
487 | 493 | | |
488 | 494 | | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
489 | 498 | | |
490 | 499 | | |
491 | 500 | | |
| |||
728 | 737 | | |
729 | 738 | | |
730 | 739 | | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
731 | 743 | | |
732 | 744 | | |
733 | 745 | | |
| |||
791 | 803 | | |
792 | 804 | | |
793 | 805 | | |
| 806 | + | |
794 | 807 | | |
795 | 808 | | |
796 | 809 | | |
797 | 810 | | |
798 | 811 | | |
799 | 812 | | |
800 | 813 | | |
| 814 | + | |
801 | 815 | | |
802 | 816 | | |
803 | 817 | | |
| |||
0 commit comments