Skip to content

Commit 1802979

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.dk/linux-block
Pull block updates and fixes from Jens Axboe: - NVMe updates and fixes that missed the first pull request. This includes bug fixes, and support for autonomous power management. - Fix from Christoph for missing clear of the request payload, causing a problem with (at least) the storvsc driver. - Further fixes for the queue/bdi life time issues from Jan. - The Kconfig mq scheduler update from me. - Fixing a use-after-free in dm-rq, spotted by Bart, introduced in this merge window. - Three fixes for nbd from Josef. - Bug fix from Omar, fixing a bug in sas transport code that oopses when bsg ioctls were used. From Omar. - Improvements to the queue restart and tag wait from from Omar. - Set of fixes for the sed/opal code from Scott. - Three trivial patches to cciss from Tobin * 'for-linus' of git://git.kernel.dk/linux-block: (41 commits) dm-rq: don't dereference request payload after ending request blk-mq-sched: separate mark hctx and queue restart operations blk-mq: use sbq wait queues instead of restart for driver tags block/sed-opal: Propagate original error message to userland. nvme/pci: re-check security protocol support after reset block/sed-opal: Introduce free_opal_dev to free the structure and clean up state nvme: detect NVMe controller in recent MacBooks nvme-rdma: add support for host_traddr nvmet-rdma: Fix error handling nvmet-rdma: use nvme cm status helper nvme-rdma: move nvme cm status helper to .h file nvme-fc: don't bother to validate ioccsz and iorcsz nvme/pci: No special case for queue busy on IO nvme/core: Fix race kicking freed request_queue nvme/pci: Disable on removal when disconnected nvme: Enable autonomous power state transitions nvme: Add a quirk mechanism that uses identify_ctrl nvme: make nvmf_register_transport require a create_ctrl callback nvme: Use CNS as 8-bit field and avoid endianness conversion nvme: add semicolon in nvme_command setting ...
2 parents f1ef09f + 61febef commit 1802979

32 files changed

+986
-761
lines changed

block/Kconfig.iosched

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -69,50 +69,6 @@ config MQ_IOSCHED_DEADLINE
6969
---help---
7070
MQ version of the deadline IO scheduler.
7171

72-
config MQ_IOSCHED_NONE
73-
bool
74-
default y
75-
76-
choice
77-
prompt "Default single-queue blk-mq I/O scheduler"
78-
default DEFAULT_SQ_NONE
79-
help
80-
Select the I/O scheduler which will be used by default for blk-mq
81-
managed block devices with a single queue.
82-
83-
config DEFAULT_SQ_DEADLINE
84-
bool "MQ Deadline" if MQ_IOSCHED_DEADLINE=y
85-
86-
config DEFAULT_SQ_NONE
87-
bool "None"
88-
89-
endchoice
90-
91-
config DEFAULT_SQ_IOSCHED
92-
string
93-
default "mq-deadline" if DEFAULT_SQ_DEADLINE
94-
default "none" if DEFAULT_SQ_NONE
95-
96-
choice
97-
prompt "Default multi-queue blk-mq I/O scheduler"
98-
default DEFAULT_MQ_NONE
99-
help
100-
Select the I/O scheduler which will be used by default for blk-mq
101-
managed block devices with multiple queues.
102-
103-
config DEFAULT_MQ_DEADLINE
104-
bool "MQ Deadline" if MQ_IOSCHED_DEADLINE=y
105-
106-
config DEFAULT_MQ_NONE
107-
bool "None"
108-
109-
endchoice
110-
111-
config DEFAULT_MQ_IOSCHED
112-
string
113-
default "mq-deadline" if DEFAULT_MQ_DEADLINE
114-
default "none" if DEFAULT_MQ_NONE
115-
11672
endmenu
11773

11874
endif

block/blk-mq-sched.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)
205205
* needing a restart in that case.
206206
*/
207207
if (!list_empty(&rq_list)) {
208-
blk_mq_sched_mark_restart(hctx);
208+
blk_mq_sched_mark_restart_hctx(hctx);
209209
did_work = blk_mq_dispatch_rq_list(hctx, &rq_list);
210210
} else if (!has_sched_dispatch) {
211211
blk_mq_flush_busy_ctxs(hctx, &rq_list);
@@ -331,20 +331,16 @@ static void blk_mq_sched_restart_hctx(struct blk_mq_hw_ctx *hctx)
331331

332332
void blk_mq_sched_restart_queues(struct blk_mq_hw_ctx *hctx)
333333
{
334+
struct request_queue *q = hctx->queue;
334335
unsigned int i;
335336

336-
if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
337+
if (test_bit(QUEUE_FLAG_RESTART, &q->queue_flags)) {
338+
if (test_and_clear_bit(QUEUE_FLAG_RESTART, &q->queue_flags)) {
339+
queue_for_each_hw_ctx(q, hctx, i)
340+
blk_mq_sched_restart_hctx(hctx);
341+
}
342+
} else {
337343
blk_mq_sched_restart_hctx(hctx);
338-
else {
339-
struct request_queue *q = hctx->queue;
340-
341-
if (!test_bit(QUEUE_FLAG_RESTART, &q->queue_flags))
342-
return;
343-
344-
clear_bit(QUEUE_FLAG_RESTART, &q->queue_flags);
345-
346-
queue_for_each_hw_ctx(q, hctx, i)
347-
blk_mq_sched_restart_hctx(hctx);
348344
}
349345
}
350346

@@ -498,15 +494,6 @@ int blk_mq_sched_init(struct request_queue *q)
498494
{
499495
int ret;
500496

501-
#if defined(CONFIG_DEFAULT_SQ_NONE)
502-
if (q->nr_hw_queues == 1)
503-
return 0;
504-
#endif
505-
#if defined(CONFIG_DEFAULT_MQ_NONE)
506-
if (q->nr_hw_queues > 1)
507-
return 0;
508-
#endif
509-
510497
mutex_lock(&q->sysfs_lock);
511498
ret = elevator_init(q, NULL);
512499
mutex_unlock(&q->sysfs_lock);

block/blk-mq-sched.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,27 @@ static inline bool blk_mq_sched_has_work(struct blk_mq_hw_ctx *hctx)
122122
return false;
123123
}
124124

125-
static inline void blk_mq_sched_mark_restart(struct blk_mq_hw_ctx *hctx)
125+
/*
126+
* Mark a hardware queue as needing a restart.
127+
*/
128+
static inline void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx)
126129
{
127-
if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state)) {
130+
if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
128131
set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
129-
if (hctx->flags & BLK_MQ_F_TAG_SHARED) {
130-
struct request_queue *q = hctx->queue;
132+
}
133+
134+
/*
135+
* Mark a hardware queue and the request queue it belongs to as needing a
136+
* restart.
137+
*/
138+
static inline void blk_mq_sched_mark_restart_queue(struct blk_mq_hw_ctx *hctx)
139+
{
140+
struct request_queue *q = hctx->queue;
131141

132-
if (!test_bit(QUEUE_FLAG_RESTART, &q->queue_flags))
133-
set_bit(QUEUE_FLAG_RESTART, &q->queue_flags);
134-
}
135-
}
142+
if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
143+
set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
144+
if (!test_bit(QUEUE_FLAG_RESTART, &q->queue_flags))
145+
set_bit(QUEUE_FLAG_RESTART, &q->queue_flags);
136146
}
137147

138148
static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx)

block/blk-mq.c

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,44 @@ static bool reorder_tags_to_front(struct list_head *list)
904904
return first != NULL;
905905
}
906906

907+
static int blk_mq_dispatch_wake(wait_queue_t *wait, unsigned mode, int flags,
908+
void *key)
909+
{
910+
struct blk_mq_hw_ctx *hctx;
911+
912+
hctx = container_of(wait, struct blk_mq_hw_ctx, dispatch_wait);
913+
914+
list_del(&wait->task_list);
915+
clear_bit_unlock(BLK_MQ_S_TAG_WAITING, &hctx->state);
916+
blk_mq_run_hw_queue(hctx, true);
917+
return 1;
918+
}
919+
920+
static bool blk_mq_dispatch_wait_add(struct blk_mq_hw_ctx *hctx)
921+
{
922+
struct sbq_wait_state *ws;
923+
924+
/*
925+
* The TAG_WAITING bit serves as a lock protecting hctx->dispatch_wait.
926+
* The thread which wins the race to grab this bit adds the hardware
927+
* queue to the wait queue.
928+
*/
929+
if (test_bit(BLK_MQ_S_TAG_WAITING, &hctx->state) ||
930+
test_and_set_bit_lock(BLK_MQ_S_TAG_WAITING, &hctx->state))
931+
return false;
932+
933+
init_waitqueue_func_entry(&hctx->dispatch_wait, blk_mq_dispatch_wake);
934+
ws = bt_wait_ptr(&hctx->tags->bitmap_tags, hctx);
935+
936+
/*
937+
* As soon as this returns, it's no longer safe to fiddle with
938+
* hctx->dispatch_wait, since a completion can wake up the wait queue
939+
* and unlock the bit.
940+
*/
941+
add_wait_queue(&ws->wait, &hctx->dispatch_wait);
942+
return true;
943+
}
944+
907945
bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list)
908946
{
909947
struct request_queue *q = hctx->queue;
@@ -931,15 +969,22 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list)
931969
continue;
932970

933971
/*
934-
* We failed getting a driver tag. Mark the queue(s)
935-
* as needing a restart. Retry getting a tag again,
936-
* in case the needed IO completed right before we
937-
* marked the queue as needing a restart.
972+
* The initial allocation attempt failed, so we need to
973+
* rerun the hardware queue when a tag is freed.
938974
*/
939-
blk_mq_sched_mark_restart(hctx);
940-
if (!blk_mq_get_driver_tag(rq, &hctx, false))
975+
if (blk_mq_dispatch_wait_add(hctx)) {
976+
/*
977+
* It's possible that a tag was freed in the
978+
* window between the allocation failure and
979+
* adding the hardware queue to the wait queue.
980+
*/
981+
if (!blk_mq_get_driver_tag(rq, &hctx, false))
982+
break;
983+
} else {
941984
break;
985+
}
942986
}
987+
943988
list_del_init(&rq->queuelist);
944989

945990
bd.rq = rq;
@@ -995,10 +1040,11 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list)
9951040
*
9961041
* blk_mq_run_hw_queue() already checks the STOPPED bit
9971042
*
998-
* If RESTART is set, then let completion restart the queue
999-
* instead of potentially looping here.
1043+
* If RESTART or TAG_WAITING is set, then let completion restart
1044+
* the queue instead of potentially looping here.
10001045
*/
1001-
if (!blk_mq_sched_needs_restart(hctx))
1046+
if (!blk_mq_sched_needs_restart(hctx) &&
1047+
!test_bit(BLK_MQ_S_TAG_WAITING, &hctx->state))
10021048
blk_mq_run_hw_queue(hctx, true);
10031049
}
10041050

block/elevator.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,24 @@ int elevator_init(struct request_queue *q, char *name)
220220
}
221221

222222
if (!e) {
223-
if (q->mq_ops && q->nr_hw_queues == 1)
224-
e = elevator_get(CONFIG_DEFAULT_SQ_IOSCHED, false);
225-
else if (q->mq_ops)
226-
e = elevator_get(CONFIG_DEFAULT_MQ_IOSCHED, false);
227-
else
223+
/*
224+
* For blk-mq devices, we default to using mq-deadline,
225+
* if available, for single queue devices. If deadline
226+
* isn't available OR we have multiple queues, default
227+
* to "none".
228+
*/
229+
if (q->mq_ops) {
230+
if (q->nr_hw_queues == 1)
231+
e = elevator_get("mq-deadline", false);
232+
if (!e)
233+
return 0;
234+
} else
228235
e = elevator_get(CONFIG_DEFAULT_IOSCHED, false);
229236

230237
if (!e) {
231238
printk(KERN_ERR
232239
"Default I/O scheduler not found. " \
233-
"Using noop/none.\n");
240+
"Using noop.\n");
234241
e = elevator_get("noop", false);
235242
}
236243
}

block/genhd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,14 +669,14 @@ void del_gendisk(struct gendisk *disk)
669669
disk_part_iter_init(&piter, disk,
670670
DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE);
671671
while ((part = disk_part_iter_next(&piter))) {
672-
bdev_unhash_inode(MKDEV(disk->major,
673-
disk->first_minor + part->partno));
674672
invalidate_partition(disk, part->partno);
673+
bdev_unhash_inode(part_devt(part));
675674
delete_partition(disk, part->partno);
676675
}
677676
disk_part_iter_exit(&piter);
678677

679678
invalidate_partition(disk, 0);
679+
bdev_unhash_inode(disk_devt(disk));
680680
set_capacity(disk, 0);
681681
disk->flags &= ~GENHD_FL_UP;
682682

0 commit comments

Comments
 (0)