Skip to content
Snippets Groups Projects
Commit 87e42965 authored by David Jeffery's avatar David Jeffery Committed by Yang Yingliang
Browse files

block: recalculate segment count for multi-segment discards correctly

mainline inclusion
from mainline-5.12-rc5
commit	a958937ff166fc60d1c3a721036f6ff41bfa2821
category: bugfix
bugzilla: 51373
CVE: NA

-------------------------------------------------

When a stacked block device inserts a request into another block device
using blk_insert_cloned_request, the request's nr_phys_segments field gets
recalculated by a call to blk_recalc_rq_segments in
blk_cloned_rq_check_limits. But blk_recalc_rq_segments does not know how to
handle multi-segment discards. For disk types which can handle
multi-segment discards like nvme, this results in discard requests which
claim a single segment when it should report several, triggering a warning
in nvme and causing nvme to fail the discard from the invalid state.

 WARNING: CPU: 5 PID: 191 at drivers/nvme/host/core.c:700 nvme_setup_discard+0x170/0x1e0 [nvme_core]
 ...
 nvme_setup_cmd+0x217/0x270 [nvme_core]
 nvme_loop_queue_rq+0x51/0x1b0 [nvme_loop]
 __blk_mq_try_issue_di...
parent a329b8db
No related branches found
No related tags found
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment