Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
blk-mq: enforce op-specific segment limits in blk_insert_cloned_request
The block layer might merge together discard requests up until the
max_discard_segments limit is hit, but blk_insert_cloned_request checks
the segment count against max_segments regardless of the req op. This
can result in errors like the following when discards are issued through
a DM device and max_discard_segments exceeds max_segments for the queue
of the chosen underlying device.

blk_insert_cloned_request: over max segments limit. (256 > 129)

Fix this by looking at the req_op and enforcing the appropriate segment
limit - max_discard_segments for REQ_OP_DISCARDs and max_segments for
everything else.

Signed-off-by: Uday Shankar <ushankar@purestorage.com>
  • Loading branch information
Uday Shankar authored and intel-lab-lkp committed Feb 15, 2023
1 parent 6bea9ac commit 2cd958b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 1 addition & 3 deletions block/blk-merge.c
Expand Up @@ -588,9 +588,7 @@ EXPORT_SYMBOL(__blk_rq_map_sg);

static inline unsigned int blk_rq_get_max_segments(struct request *rq)
{
if (req_op(rq) == REQ_OP_DISCARD)
return queue_max_discard_segments(rq->q);
return queue_max_segments(rq->q);
return blk_queue_get_max_segments(rq->q, req_op(rq));
}

static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
Expand Down
5 changes: 3 additions & 2 deletions block/blk-mq.c
Expand Up @@ -3000,6 +3000,7 @@ blk_status_t blk_insert_cloned_request(struct request *rq)
{
struct request_queue *q = rq->q;
unsigned int max_sectors = blk_queue_get_max_sectors(q, req_op(rq));
unsigned int max_segments = blk_queue_get_max_segments(q, req_op(rq));
blk_status_t ret;

if (blk_rq_sectors(rq) > max_sectors) {
Expand All @@ -3026,9 +3027,9 @@ blk_status_t blk_insert_cloned_request(struct request *rq)
* original queue.
*/
rq->nr_phys_segments = blk_recalc_rq_segments(rq);
if (rq->nr_phys_segments > queue_max_segments(q)) {
if (rq->nr_phys_segments > max_segments) {
printk(KERN_ERR "%s: over max segments limit. (%hu > %hu)\n",
__func__, rq->nr_phys_segments, queue_max_segments(q));
__func__, rq->nr_phys_segments, max_segments);
return BLK_STS_IOERR;
}

Expand Down
8 changes: 8 additions & 0 deletions block/blk.h
Expand Up @@ -169,6 +169,14 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
return q->limits.max_sectors;
}

static inline unsigned int blk_queue_get_max_segments(struct request_queue *q,
enum req_op op)
{
if (op == REQ_OP_DISCARD)
return queue_max_discard_segments(q);
return queue_max_segments(q);
}

#ifdef CONFIG_BLK_DEV_INTEGRITY
void blk_flush_integrity(void);
bool __bio_integrity_endio(struct bio *);
Expand Down

0 comments on commit 2cd958b

Please sign in to comment.