Merge branch 'for-linus' of git://git.kernel.dk/linux-block into next
Pull block follow-up bits from Jens Axboe:
"A few minor (but important) fixes for blk-mq for the -rc1 window.
- Hot removal potential oops fix for single queue devices. From me.
- Two merged patches in late May meant that we accidentally lost a
fix for freeing an active queue. Fix that up. From me.
- A change of the blk_mq_tag_to_rq() API, passing in blk_mq_tags, to
make life considerably easier for scsi-mq. From me.
- A schedule-while-atomic fix from Ming Lei, which would hit if the
tag space was exhausted.
- Missing __percpu annotation in one place in blk-mq. Found by the
magic Wu compile bot due to code being moved around by the previous
patch, but it's actually an older issue. From Ming Lei.
- Clearing of tag of a flush request at end_io time. From Ming Lei"
* 'for-linus' of git://git.kernel.dk/linux-block:
block: mq flush: clear flush_rq's tag in flush_end_io()
blk-mq: let blk_mq_tag_to_rq() take blk_mq_tags as the main parameter
blk-mq: fix regression from commit 624dbe4754
blk-mq: handle NULL req return from blk_map_request in single queue mode
blk-mq: fix sparse warning on missed __percpu annotation
blk-mq: fix schedule from atomic context
blk-mq: move blk_mq_get_ctx/blk_mq_put_ctx to mq private header
This commit is contained in:
Коммит
f1a7cd0ffe
|
@ -225,7 +225,7 @@ static void flush_end_io(struct request *flush_rq, int error)
|
|||
|
||||
if (q->mq_ops) {
|
||||
spin_lock_irqsave(&q->mq_flush_lock, flags);
|
||||
q->flush_rq->cmd_flags = 0;
|
||||
q->flush_rq->tag = -1;
|
||||
}
|
||||
|
||||
running = &q->flush_queue[q->flush_running_idx];
|
||||
|
|
|
@ -221,8 +221,10 @@ static struct bt_wait_state *bt_wait_ptr(struct blk_mq_bitmap_tags *bt,
|
|||
return bs;
|
||||
}
|
||||
|
||||
static int bt_get(struct blk_mq_bitmap_tags *bt, struct blk_mq_hw_ctx *hctx,
|
||||
unsigned int *last_tag, gfp_t gfp)
|
||||
static int bt_get(struct blk_mq_alloc_data *data,
|
||||
struct blk_mq_bitmap_tags *bt,
|
||||
struct blk_mq_hw_ctx *hctx,
|
||||
unsigned int *last_tag)
|
||||
{
|
||||
struct bt_wait_state *bs;
|
||||
DEFINE_WAIT(wait);
|
||||
|
@ -232,7 +234,7 @@ static int bt_get(struct blk_mq_bitmap_tags *bt, struct blk_mq_hw_ctx *hctx,
|
|||
if (tag != -1)
|
||||
return tag;
|
||||
|
||||
if (!(gfp & __GFP_WAIT))
|
||||
if (!(data->gfp & __GFP_WAIT))
|
||||
return -1;
|
||||
|
||||
bs = bt_wait_ptr(bt, hctx);
|
||||
|
@ -249,50 +251,62 @@ static int bt_get(struct blk_mq_bitmap_tags *bt, struct blk_mq_hw_ctx *hctx,
|
|||
if (was_empty)
|
||||
atomic_set(&bs->wait_cnt, bt->wake_cnt);
|
||||
|
||||
blk_mq_put_ctx(data->ctx);
|
||||
|
||||
io_schedule();
|
||||
|
||||
data->ctx = blk_mq_get_ctx(data->q);
|
||||
data->hctx = data->q->mq_ops->map_queue(data->q,
|
||||
data->ctx->cpu);
|
||||
if (data->reserved) {
|
||||
bt = &data->hctx->tags->breserved_tags;
|
||||
} else {
|
||||
last_tag = &data->ctx->last_tag;
|
||||
hctx = data->hctx;
|
||||
bt = &hctx->tags->bitmap_tags;
|
||||
}
|
||||
finish_wait(&bs->wait, &wait);
|
||||
bs = bt_wait_ptr(bt, hctx);
|
||||
} while (1);
|
||||
|
||||
finish_wait(&bs->wait, &wait);
|
||||
return tag;
|
||||
}
|
||||
|
||||
static unsigned int __blk_mq_get_tag(struct blk_mq_tags *tags,
|
||||
struct blk_mq_hw_ctx *hctx,
|
||||
unsigned int *last_tag, gfp_t gfp)
|
||||
static unsigned int __blk_mq_get_tag(struct blk_mq_alloc_data *data)
|
||||
{
|
||||
int tag;
|
||||
|
||||
tag = bt_get(&tags->bitmap_tags, hctx, last_tag, gfp);
|
||||
tag = bt_get(data, &data->hctx->tags->bitmap_tags, data->hctx,
|
||||
&data->ctx->last_tag);
|
||||
if (tag >= 0)
|
||||
return tag + tags->nr_reserved_tags;
|
||||
return tag + data->hctx->tags->nr_reserved_tags;
|
||||
|
||||
return BLK_MQ_TAG_FAIL;
|
||||
}
|
||||
|
||||
static unsigned int __blk_mq_get_reserved_tag(struct blk_mq_tags *tags,
|
||||
gfp_t gfp)
|
||||
static unsigned int __blk_mq_get_reserved_tag(struct blk_mq_alloc_data *data)
|
||||
{
|
||||
int tag, zero = 0;
|
||||
|
||||
if (unlikely(!tags->nr_reserved_tags)) {
|
||||
if (unlikely(!data->hctx->tags->nr_reserved_tags)) {
|
||||
WARN_ON_ONCE(1);
|
||||
return BLK_MQ_TAG_FAIL;
|
||||
}
|
||||
|
||||
tag = bt_get(&tags->breserved_tags, NULL, &zero, gfp);
|
||||
tag = bt_get(data, &data->hctx->tags->breserved_tags, NULL, &zero);
|
||||
if (tag < 0)
|
||||
return BLK_MQ_TAG_FAIL;
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
unsigned int blk_mq_get_tag(struct blk_mq_hw_ctx *hctx, unsigned int *last_tag,
|
||||
gfp_t gfp, bool reserved)
|
||||
unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data)
|
||||
{
|
||||
if (!reserved)
|
||||
return __blk_mq_get_tag(hctx->tags, hctx, last_tag, gfp);
|
||||
if (!data->reserved)
|
||||
return __blk_mq_get_tag(data);
|
||||
|
||||
return __blk_mq_get_reserved_tag(hctx->tags, gfp);
|
||||
return __blk_mq_get_reserved_tag(data);
|
||||
}
|
||||
|
||||
static struct bt_wait_state *bt_wake_ptr(struct blk_mq_bitmap_tags *bt)
|
||||
|
|
|
@ -48,7 +48,7 @@ struct blk_mq_tags {
|
|||
extern struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags, unsigned int reserved_tags, int node);
|
||||
extern void blk_mq_free_tags(struct blk_mq_tags *tags);
|
||||
|
||||
extern unsigned int blk_mq_get_tag(struct blk_mq_hw_ctx *hctx, unsigned int *last_tag, gfp_t gfp, bool reserved);
|
||||
extern unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data);
|
||||
extern void blk_mq_put_tag(struct blk_mq_hw_ctx *hctx, unsigned int tag, unsigned int *last_tag);
|
||||
extern bool blk_mq_has_free_tags(struct blk_mq_tags *tags);
|
||||
extern ssize_t blk_mq_tag_sysfs_show(struct blk_mq_tags *tags, char *page);
|
||||
|
|
|
@ -33,28 +33,6 @@ static LIST_HEAD(all_q_list);
|
|||
|
||||
static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx);
|
||||
|
||||
static struct blk_mq_ctx *__blk_mq_get_ctx(struct request_queue *q,
|
||||
unsigned int cpu)
|
||||
{
|
||||
return per_cpu_ptr(q->queue_ctx, cpu);
|
||||
}
|
||||
|
||||
/*
|
||||
* This assumes per-cpu software queueing queues. They could be per-node
|
||||
* as well, for instance. For now this is hardcoded as-is. Note that we don't
|
||||
* care about preemption, since we know the ctx's are persistent. This does
|
||||
* mean that we can't rely on ctx always matching the currently running CPU.
|
||||
*/
|
||||
static struct blk_mq_ctx *blk_mq_get_ctx(struct request_queue *q)
|
||||
{
|
||||
return __blk_mq_get_ctx(q, get_cpu());
|
||||
}
|
||||
|
||||
static void blk_mq_put_ctx(struct blk_mq_ctx *ctx)
|
||||
{
|
||||
put_cpu();
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if any of the ctx's have pending work in this hardware queue
|
||||
*/
|
||||
|
@ -232,24 +210,23 @@ static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,
|
|||
}
|
||||
|
||||
static struct request *
|
||||
__blk_mq_alloc_request(struct request_queue *q, struct blk_mq_hw_ctx *hctx,
|
||||
struct blk_mq_ctx *ctx, int rw, gfp_t gfp, bool reserved)
|
||||
__blk_mq_alloc_request(struct blk_mq_alloc_data *data, int rw)
|
||||
{
|
||||
struct request *rq;
|
||||
unsigned int tag;
|
||||
|
||||
tag = blk_mq_get_tag(hctx, &ctx->last_tag, gfp, reserved);
|
||||
tag = blk_mq_get_tag(data);
|
||||
if (tag != BLK_MQ_TAG_FAIL) {
|
||||
rq = hctx->tags->rqs[tag];
|
||||
rq = data->hctx->tags->rqs[tag];
|
||||
|
||||
rq->cmd_flags = 0;
|
||||
if (blk_mq_tag_busy(hctx)) {
|
||||
if (blk_mq_tag_busy(data->hctx)) {
|
||||
rq->cmd_flags = REQ_MQ_INFLIGHT;
|
||||
atomic_inc(&hctx->nr_active);
|
||||
atomic_inc(&data->hctx->nr_active);
|
||||
}
|
||||
|
||||
rq->tag = tag;
|
||||
blk_mq_rq_ctx_init(q, ctx, rq, rw);
|
||||
blk_mq_rq_ctx_init(data->q, data->ctx, rq, rw);
|
||||
return rq;
|
||||
}
|
||||
|
||||
|
@ -262,22 +239,27 @@ struct request *blk_mq_alloc_request(struct request_queue *q, int rw, gfp_t gfp,
|
|||
struct blk_mq_ctx *ctx;
|
||||
struct blk_mq_hw_ctx *hctx;
|
||||
struct request *rq;
|
||||
struct blk_mq_alloc_data alloc_data;
|
||||
|
||||
if (blk_mq_queue_enter(q))
|
||||
return NULL;
|
||||
|
||||
ctx = blk_mq_get_ctx(q);
|
||||
hctx = q->mq_ops->map_queue(q, ctx->cpu);
|
||||
blk_mq_set_alloc_data(&alloc_data, q, gfp & ~__GFP_WAIT,
|
||||
reserved, ctx, hctx);
|
||||
|
||||
rq = __blk_mq_alloc_request(q, hctx, ctx, rw, gfp & ~__GFP_WAIT,
|
||||
reserved);
|
||||
rq = __blk_mq_alloc_request(&alloc_data, rw);
|
||||
if (!rq && (gfp & __GFP_WAIT)) {
|
||||
__blk_mq_run_hw_queue(hctx);
|
||||
blk_mq_put_ctx(ctx);
|
||||
|
||||
ctx = blk_mq_get_ctx(q);
|
||||
hctx = q->mq_ops->map_queue(q, ctx->cpu);
|
||||
rq = __blk_mq_alloc_request(q, hctx, ctx, rw, gfp, reserved);
|
||||
blk_mq_set_alloc_data(&alloc_data, q, gfp, reserved, ctx,
|
||||
hctx);
|
||||
rq = __blk_mq_alloc_request(&alloc_data, rw);
|
||||
ctx = alloc_data.ctx;
|
||||
}
|
||||
blk_mq_put_ctx(ctx);
|
||||
return rq;
|
||||
|
@ -547,15 +529,20 @@ void blk_mq_kick_requeue_list(struct request_queue *q)
|
|||
}
|
||||
EXPORT_SYMBOL(blk_mq_kick_requeue_list);
|
||||
|
||||
struct request *blk_mq_tag_to_rq(struct blk_mq_hw_ctx *hctx, unsigned int tag)
|
||||
static inline bool is_flush_request(struct request *rq, unsigned int tag)
|
||||
{
|
||||
struct request_queue *q = hctx->queue;
|
||||
return ((rq->cmd_flags & REQ_FLUSH_SEQ) &&
|
||||
rq->q->flush_rq->tag == tag);
|
||||
}
|
||||
|
||||
if ((q->flush_rq->cmd_flags & REQ_FLUSH_SEQ) &&
|
||||
q->flush_rq->tag == tag)
|
||||
return q->flush_rq;
|
||||
struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag)
|
||||
{
|
||||
struct request *rq = tags->rqs[tag];
|
||||
|
||||
return hctx->tags->rqs[tag];
|
||||
if (!is_flush_request(rq, tag))
|
||||
return rq;
|
||||
|
||||
return rq->q->flush_rq;
|
||||
}
|
||||
EXPORT_SYMBOL(blk_mq_tag_to_rq);
|
||||
|
||||
|
@ -584,7 +571,7 @@ static void blk_mq_timeout_check(void *__data, unsigned long *free_tags)
|
|||
if (tag >= hctx->tags->nr_tags)
|
||||
break;
|
||||
|
||||
rq = blk_mq_tag_to_rq(hctx, tag++);
|
||||
rq = blk_mq_tag_to_rq(hctx->tags, tag++);
|
||||
if (rq->q != hctx->queue)
|
||||
continue;
|
||||
if (!test_bit(REQ_ATOM_STARTED, &rq->atomic_flags))
|
||||
|
@ -1158,6 +1145,7 @@ static struct request *blk_mq_map_request(struct request_queue *q,
|
|||
struct blk_mq_ctx *ctx;
|
||||
struct request *rq;
|
||||
int rw = bio_data_dir(bio);
|
||||
struct blk_mq_alloc_data alloc_data;
|
||||
|
||||
if (unlikely(blk_mq_queue_enter(q))) {
|
||||
bio_endio(bio, -EIO);
|
||||
|
@ -1171,7 +1159,9 @@ static struct request *blk_mq_map_request(struct request_queue *q,
|
|||
rw |= REQ_SYNC;
|
||||
|
||||
trace_block_getrq(q, bio, rw);
|
||||
rq = __blk_mq_alloc_request(q, hctx, ctx, rw, GFP_ATOMIC, false);
|
||||
blk_mq_set_alloc_data(&alloc_data, q, GFP_ATOMIC, false, ctx,
|
||||
hctx);
|
||||
rq = __blk_mq_alloc_request(&alloc_data, rw);
|
||||
if (unlikely(!rq)) {
|
||||
__blk_mq_run_hw_queue(hctx);
|
||||
blk_mq_put_ctx(ctx);
|
||||
|
@ -1179,8 +1169,11 @@ static struct request *blk_mq_map_request(struct request_queue *q,
|
|||
|
||||
ctx = blk_mq_get_ctx(q);
|
||||
hctx = q->mq_ops->map_queue(q, ctx->cpu);
|
||||
rq = __blk_mq_alloc_request(q, hctx, ctx, rw,
|
||||
__GFP_WAIT|GFP_ATOMIC, false);
|
||||
blk_mq_set_alloc_data(&alloc_data, q,
|
||||
__GFP_WAIT|GFP_ATOMIC, false, ctx, hctx);
|
||||
rq = __blk_mq_alloc_request(&alloc_data, rw);
|
||||
ctx = alloc_data.ctx;
|
||||
hctx = alloc_data.hctx;
|
||||
}
|
||||
|
||||
hctx->queued++;
|
||||
|
@ -1288,6 +1281,8 @@ static void blk_sq_make_request(struct request_queue *q, struct bio *bio)
|
|||
return;
|
||||
|
||||
rq = blk_mq_map_request(q, bio, &data);
|
||||
if (unlikely(!rq))
|
||||
return;
|
||||
|
||||
if (unlikely(is_flush_fua)) {
|
||||
blk_mq_bio_to_request(rq, bio);
|
||||
|
@ -1562,6 +1557,8 @@ static void blk_mq_exit_hw_queues(struct request_queue *q,
|
|||
if (i == nr_queue)
|
||||
break;
|
||||
|
||||
blk_mq_tag_idle(hctx);
|
||||
|
||||
if (set->ops->exit_hctx)
|
||||
set->ops->exit_hctx(hctx, i);
|
||||
|
||||
|
@ -1779,7 +1776,7 @@ static void blk_mq_add_queue_tag_set(struct blk_mq_tag_set *set,
|
|||
struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
|
||||
{
|
||||
struct blk_mq_hw_ctx **hctxs;
|
||||
struct blk_mq_ctx *ctx;
|
||||
struct blk_mq_ctx __percpu *ctx;
|
||||
struct request_queue *q;
|
||||
unsigned int *map;
|
||||
int i;
|
||||
|
|
|
@ -69,4 +69,49 @@ struct blk_align_bitmap {
|
|||
unsigned long depth;
|
||||
} ____cacheline_aligned_in_smp;
|
||||
|
||||
static inline struct blk_mq_ctx *__blk_mq_get_ctx(struct request_queue *q,
|
||||
unsigned int cpu)
|
||||
{
|
||||
return per_cpu_ptr(q->queue_ctx, cpu);
|
||||
}
|
||||
|
||||
/*
|
||||
* This assumes per-cpu software queueing queues. They could be per-node
|
||||
* as well, for instance. For now this is hardcoded as-is. Note that we don't
|
||||
* care about preemption, since we know the ctx's are persistent. This does
|
||||
* mean that we can't rely on ctx always matching the currently running CPU.
|
||||
*/
|
||||
static inline struct blk_mq_ctx *blk_mq_get_ctx(struct request_queue *q)
|
||||
{
|
||||
return __blk_mq_get_ctx(q, get_cpu());
|
||||
}
|
||||
|
||||
static inline void blk_mq_put_ctx(struct blk_mq_ctx *ctx)
|
||||
{
|
||||
put_cpu();
|
||||
}
|
||||
|
||||
struct blk_mq_alloc_data {
|
||||
/* input parameter */
|
||||
struct request_queue *q;
|
||||
gfp_t gfp;
|
||||
bool reserved;
|
||||
|
||||
/* input & output parameter */
|
||||
struct blk_mq_ctx *ctx;
|
||||
struct blk_mq_hw_ctx *hctx;
|
||||
};
|
||||
|
||||
static inline void blk_mq_set_alloc_data(struct blk_mq_alloc_data *data,
|
||||
struct request_queue *q, gfp_t gfp, bool reserved,
|
||||
struct blk_mq_ctx *ctx,
|
||||
struct blk_mq_hw_ctx *hctx)
|
||||
{
|
||||
data->q = q;
|
||||
data->gfp = gfp;
|
||||
data->reserved = reserved;
|
||||
data->ctx = ctx;
|
||||
data->hctx = hctx;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -193,7 +193,9 @@ static void mtip_put_int_command(struct driver_data *dd, struct mtip_cmd *cmd)
|
|||
static struct request *mtip_rq_from_tag(struct driver_data *dd,
|
||||
unsigned int tag)
|
||||
{
|
||||
return blk_mq_tag_to_rq(dd->queue->queue_hw_ctx[0], tag);
|
||||
struct blk_mq_hw_ctx *hctx = dd->queue->queue_hw_ctx[0];
|
||||
|
||||
return blk_mq_tag_to_rq(hctx->tags, tag);
|
||||
}
|
||||
|
||||
static struct mtip_cmd *mtip_cmd_from_tag(struct driver_data *dd,
|
||||
|
|
|
@ -155,7 +155,7 @@ void blk_mq_free_request(struct request *rq);
|
|||
bool blk_mq_can_queue(struct blk_mq_hw_ctx *);
|
||||
struct request *blk_mq_alloc_request(struct request_queue *q, int rw,
|
||||
gfp_t gfp, bool reserved);
|
||||
struct request *blk_mq_tag_to_rq(struct blk_mq_hw_ctx *hctx, unsigned int tag);
|
||||
struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag);
|
||||
|
||||
struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *, const int ctx_index);
|
||||
struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set *, unsigned int, int);
|
||||
|
|
|
@ -335,7 +335,7 @@ struct request_queue {
|
|||
unsigned int *mq_map;
|
||||
|
||||
/* sw queues */
|
||||
struct blk_mq_ctx *queue_ctx;
|
||||
struct blk_mq_ctx __percpu *queue_ctx;
|
||||
unsigned int nr_queues;
|
||||
|
||||
/* hw dispatch queues */
|
||||
|
|
Загрузка…
Ссылка в новой задаче