Skip to content

Commit e58af04

Browse files
committed
Merge branch 'for-6.11/block' into for-next
* for-6.11/block: block: check bio alignment in blk_mq_submit_bio
2 parents a694b08 + 0676c43 commit e58af04

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

block/blk-mq.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,6 +2909,17 @@ static void blk_mq_use_cached_rq(struct request *rq, struct blk_plug *plug,
29092909
INIT_LIST_HEAD(&rq->queuelist);
29102910
}
29112911

2912+
static bool bio_unaligned(const struct bio *bio, struct request_queue *q)
2913+
{
2914+
unsigned int bs_mask = queue_logical_block_size(q) - 1;
2915+
2916+
/* .bi_sector of any zero sized bio need to be initialized */
2917+
if ((bio->bi_iter.bi_size & bs_mask) ||
2918+
((bio->bi_iter.bi_sector << SECTOR_SHIFT) & bs_mask))
2919+
return true;
2920+
return false;
2921+
}
2922+
29122923
/**
29132924
* blk_mq_submit_bio - Create and send a request to block device.
29142925
* @bio: Bio pointer.
@@ -2961,6 +2972,15 @@ void blk_mq_submit_bio(struct bio *bio)
29612972
return;
29622973
}
29632974

2975+
/*
2976+
* Device reconfiguration may change logical block size, so alignment
2977+
* check has to be done with queue usage counter held
2978+
*/
2979+
if (unlikely(bio_unaligned(bio, q))) {
2980+
bio_io_error(bio);
2981+
goto queue_exit;
2982+
}
2983+
29642984
if (unlikely(bio_may_exceed_limits(bio, &q->limits))) {
29652985
bio = __bio_split_to_limits(bio, &q->limits, &nr_segs);
29662986
if (!bio)

0 commit comments

Comments
 (0)