Skip to content

Commit

Permalink
block: don't call bio_uninit from bio_endio
Browse files Browse the repository at this point in the history
BugLink: https://bugs.launchpad.net/bugs/2085849

[ Upstream commit bf4c89f ]

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]>
Signed-off-by: Sasha Levin <[email protected]>
Signed-off-by: Manuel Diewald <[email protected]>
Signed-off-by: Roxana Nicolescu <[email protected]>
  • Loading branch information
Christoph Hellwig authored and mehmetb0 committed Nov 9, 2024
1 parent 7ee0da7 commit 595731e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions block/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1603,8 +1603,18 @@ void bio_endio(struct bio *bio)
}

blk_throtl_bio_endio(bio);
/* release cgroup info */
bio_uninit(bio);
#ifdef CONFIG_BLK_CGROUP
/*
* Release cgroup info. We shouldn't have to do this here, but quite
* a few callers of bio_init fail to call bio_uninit, so we cover up
* for that here at least for now.
*/
if (bio->bi_blkg) {
blkg_put(bio->bi_blkg);
bio->bi_blkg = NULL;
}
#endif

if (bio->bi_end_io)
bio->bi_end_io(bio);
}
Expand Down

0 comments on commit 595731e

Please sign in to comment.