Skip to content

Commit bf4c89f

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: don't call bio_uninit from bio_endio
Commit b222dd2 ("block: call bio_uninit in bio_endio") added a call to bio_uninit in bio_endio to work around callers that use bio_init but fail to call bio_uninit after they are done to release the resources. While this is an abuse of the bio_init API we still have quite a few of those left. But this early uninit causes a problem for integrity data, as at least some users need the bio_integrity_payload. Right now the only one is the NVMe passthrough which archives this by adding a special case to skip the freeing if the BIP_INTEGRITY_USER flag is set. Sort this out by only putting bi_blkg in bio_endio as that is the cause of the actual leaks - the few users of the crypto context and integrity data all properly call bio_uninit, usually through bio_put for dynamically allocated bios. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 21671a1 commit bf4c89f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

block/bio.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,8 +1630,18 @@ void bio_endio(struct bio *bio)
16301630
goto again;
16311631
}
16321632

1633-
/* release cgroup info */
1634-
bio_uninit(bio);
1633+
#ifdef CONFIG_BLK_CGROUP
1634+
/*
1635+
* Release cgroup info. We shouldn't have to do this here, but quite
1636+
* a few callers of bio_init fail to call bio_uninit, so we cover up
1637+
* for that here at least for now.
1638+
*/
1639+
if (bio->bi_blkg) {
1640+
blkg_put(bio->bi_blkg);
1641+
bio->bi_blkg = NULL;
1642+
}
1643+
#endif
1644+
16351645
if (bio->bi_end_io)
16361646
bio->bi_end_io(bio);
16371647
}

0 commit comments

Comments
 (0)