Skip to content

Commit d459d85

Browse files
dennisszhouaxboe
authored andcommitted
blkcg: reassociate bios when make_request() is called recursively
When submitting a bio, multiple recursive calls to make_request() may occur. This causes the initial associate done in blkcg_bio_issue_check() to be incorrect and reference the prior request_queue. This introduces a helper to do reassociation when make_request() is recursively called. Fixes: a7b39b4 ("blkcg: always associate a bio with a blkg") Reported-by: Valdis Kletnieks <valdis.kletnieks@vt.edu> Signed-off-by: Dennis Zhou <dennis@kernel.org> Tested-by: Valdis Kletnieks <valdis.kletnieks@vt.edu> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent b2c3fa5 commit d459d85

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

block/bio.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,6 +2083,26 @@ int bio_associate_create_blkg(struct request_queue *q, struct bio *bio)
20832083
return ret;
20842084
}
20852085

2086+
/**
2087+
* bio_reassociate_blkg - reassociate a bio with a blkg from q
2088+
* @q: request_queue where bio is going
2089+
* @bio: target bio
2090+
*
2091+
* When submitting a bio, multiple recursive calls to make_request() may occur.
2092+
* This causes the initial associate done in blkcg_bio_issue_check() to be
2093+
* incorrect and reference the prior request_queue. This performs reassociation
2094+
* when this situation happens.
2095+
*/
2096+
int bio_reassociate_blkg(struct request_queue *q, struct bio *bio)
2097+
{
2098+
if (bio->bi_blkg) {
2099+
blkg_put(bio->bi_blkg);
2100+
bio->bi_blkg = NULL;
2101+
}
2102+
2103+
return bio_associate_create_blkg(q, bio);
2104+
}
2105+
20862106
/**
20872107
* bio_disassociate_task - undo bio_associate_current()
20882108
* @bio: target bio

block/blk-core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,7 @@ blk_qc_t generic_make_request(struct bio *bio)
24332433
if (q)
24342434
blk_queue_exit(q);
24352435
q = bio->bi_disk->queue;
2436+
bio_reassociate_blkg(q, bio);
24362437
flags = 0;
24372438
if (bio->bi_opf & REQ_NOWAIT)
24382439
flags = BLK_MQ_REQ_NOWAIT;

include/linux/bio.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ int bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg);
514514
int bio_associate_blkg_from_css(struct bio *bio,
515515
struct cgroup_subsys_state *css);
516516
int bio_associate_create_blkg(struct request_queue *q, struct bio *bio);
517+
int bio_reassociate_blkg(struct request_queue *q, struct bio *bio);
517518
void bio_disassociate_task(struct bio *bio);
518519
void bio_clone_blkg_association(struct bio *dst, struct bio *src);
519520
#else /* CONFIG_BLK_CGROUP */
@@ -522,6 +523,8 @@ static inline int bio_associate_blkg_from_css(struct bio *bio,
522523
{ return 0; }
523524
static inline int bio_associate_create_blkg(struct request_queue *q,
524525
struct bio *bio) { return 0; }
526+
static inline int bio_reassociate_blkg(struct request_queue *q, struct bio *bio)
527+
{ return 0; }
525528
static inline void bio_disassociate_task(struct bio *bio) { }
526529
static inline void bio_clone_blkg_association(struct bio *dst,
527530
struct bio *src) { }

0 commit comments

Comments
 (0)