Skip to content

Commit ffb8e45

Browse files
committed
Merge tag 'for-linus-20190329' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: "Small set of fixes that should go into this series. This contains: - compat signal mask fix for io_uring (Arnd) - EAGAIN corner case for direct vs buffered writes for io_uring (Roman) - NVMe pull request from Christoph with various little fixes - sbitmap ws_active fix, which caused a perf regression for shared tags (me) - sbitmap bit ordering fix (Ming) - libata on-stack DMA fix (Raymond)" * tag 'for-linus-20190329' of git://git.kernel.dk/linux-block: nvmet: fix error flow during ns enable nvmet: fix building bvec from sg list nvme-multipath: relax ANA state check nvme-tcp: fix an endianess miss-annotation libata: fix using DMA buffers on stack io_uring: offload write to async worker in case of -EAGAIN sbitmap: order READ/WRITE freed instance and setting clear bit blk-mq: fix sbitmap ws_active for shared tags io_uring: fix big-endian compat signal mask handling blk-mq: update comment for blk_mq_hctx_has_pending() blk-mq: use blk_mq_put_driver_tag() to put tag
2 parents 7376e39 + 7bca889 commit ffb8e45

File tree

10 files changed

+88
-43
lines changed

10 files changed

+88
-43
lines changed

block/blk-flush.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
220220
blk_mq_tag_set_rq(hctx, flush_rq->tag, fq->orig_rq);
221221
flush_rq->tag = -1;
222222
} else {
223-
blk_mq_put_driver_tag_hctx(hctx, flush_rq);
223+
blk_mq_put_driver_tag(flush_rq);
224224
flush_rq->internal_tag = -1;
225225
}
226226

@@ -324,7 +324,7 @@ static void mq_flush_data_end_io(struct request *rq, blk_status_t error)
324324

325325
if (q->elevator) {
326326
WARN_ON(rq->tag < 0);
327-
blk_mq_put_driver_tag_hctx(hctx, rq);
327+
blk_mq_put_driver_tag(rq);
328328
}
329329

330330
/*

block/blk-mq.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ static int blk_mq_poll_stats_bkt(const struct request *rq)
5959
}
6060

6161
/*
62-
* Check if any of the ctx's have pending work in this hardware queue
62+
* Check if any of the ctx, dispatch list or elevator
63+
* have pending work in this hardware queue.
6364
*/
6465
static bool blk_mq_hctx_has_pending(struct blk_mq_hw_ctx *hctx)
6566
{
@@ -1071,7 +1072,13 @@ static int blk_mq_dispatch_wake(wait_queue_entry_t *wait, unsigned mode,
10711072
hctx = container_of(wait, struct blk_mq_hw_ctx, dispatch_wait);
10721073

10731074
spin_lock(&hctx->dispatch_wait_lock);
1074-
list_del_init(&wait->entry);
1075+
if (!list_empty(&wait->entry)) {
1076+
struct sbitmap_queue *sbq;
1077+
1078+
list_del_init(&wait->entry);
1079+
sbq = &hctx->tags->bitmap_tags;
1080+
atomic_dec(&sbq->ws_active);
1081+
}
10751082
spin_unlock(&hctx->dispatch_wait_lock);
10761083

10771084
blk_mq_run_hw_queue(hctx, true);
@@ -1087,6 +1094,7 @@ static int blk_mq_dispatch_wake(wait_queue_entry_t *wait, unsigned mode,
10871094
static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx *hctx,
10881095
struct request *rq)
10891096
{
1097+
struct sbitmap_queue *sbq = &hctx->tags->bitmap_tags;
10901098
struct wait_queue_head *wq;
10911099
wait_queue_entry_t *wait;
10921100
bool ret;
@@ -1109,7 +1117,7 @@ static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx *hctx,
11091117
if (!list_empty_careful(&wait->entry))
11101118
return false;
11111119

1112-
wq = &bt_wait_ptr(&hctx->tags->bitmap_tags, hctx)->wait;
1120+
wq = &bt_wait_ptr(sbq, hctx)->wait;
11131121

11141122
spin_lock_irq(&wq->lock);
11151123
spin_lock(&hctx->dispatch_wait_lock);
@@ -1119,6 +1127,7 @@ static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx *hctx,
11191127
return false;
11201128
}
11211129

1130+
atomic_inc(&sbq->ws_active);
11221131
wait->flags &= ~WQ_FLAG_EXCLUSIVE;
11231132
__add_wait_queue(wq, wait);
11241133

@@ -1139,6 +1148,7 @@ static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx *hctx,
11391148
* someone else gets the wakeup.
11401149
*/
11411150
list_del_init(&wait->entry);
1151+
atomic_dec(&sbq->ws_active);
11421152
spin_unlock(&hctx->dispatch_wait_lock);
11431153
spin_unlock_irq(&wq->lock);
11441154

block/blk-mq.h

-9
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,6 @@ static inline void __blk_mq_put_driver_tag(struct blk_mq_hw_ctx *hctx,
224224
}
225225
}
226226

227-
static inline void blk_mq_put_driver_tag_hctx(struct blk_mq_hw_ctx *hctx,
228-
struct request *rq)
229-
{
230-
if (rq->tag == -1 || rq->internal_tag == -1)
231-
return;
232-
233-
__blk_mq_put_driver_tag(hctx, rq);
234-
}
235-
236227
static inline void blk_mq_put_driver_tag(struct request *rq)
237228
{
238229
if (rq->tag == -1 || rq->internal_tag == -1)

drivers/ata/libata-zpodd.c

+24-10
Original file line numberDiff line numberDiff line change
@@ -52,38 +52,52 @@ static int eject_tray(struct ata_device *dev)
5252
/* Per the spec, only slot type and drawer type ODD can be supported */
5353
static enum odd_mech_type zpodd_get_mech_type(struct ata_device *dev)
5454
{
55-
char buf[16];
55+
char *buf;
5656
unsigned int ret;
57-
struct rm_feature_desc *desc = (void *)(buf + 8);
57+
struct rm_feature_desc *desc;
5858
struct ata_taskfile tf;
5959
static const char cdb[] = { GPCMD_GET_CONFIGURATION,
6060
2, /* only 1 feature descriptor requested */
6161
0, 3, /* 3, removable medium feature */
6262
0, 0, 0,/* reserved */
63-
0, sizeof(buf),
63+
0, 16,
6464
0, 0, 0,
6565
};
6666

67+
buf = kzalloc(16, GFP_KERNEL);
68+
if (!buf)
69+
return ODD_MECH_TYPE_UNSUPPORTED;
70+
desc = (void *)(buf + 8);
71+
6772
ata_tf_init(dev, &tf);
6873
tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
6974
tf.command = ATA_CMD_PACKET;
7075
tf.protocol = ATAPI_PROT_PIO;
71-
tf.lbam = sizeof(buf);
76+
tf.lbam = 16;
7277

7378
ret = ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE,
74-
buf, sizeof(buf), 0);
75-
if (ret)
79+
buf, 16, 0);
80+
if (ret) {
81+
kfree(buf);
7682
return ODD_MECH_TYPE_UNSUPPORTED;
83+
}
7784

78-
if (be16_to_cpu(desc->feature_code) != 3)
85+
if (be16_to_cpu(desc->feature_code) != 3) {
86+
kfree(buf);
7987
return ODD_MECH_TYPE_UNSUPPORTED;
88+
}
8089

81-
if (desc->mech_type == 0 && desc->load == 0 && desc->eject == 1)
90+
if (desc->mech_type == 0 && desc->load == 0 && desc->eject == 1) {
91+
kfree(buf);
8292
return ODD_MECH_TYPE_SLOT;
83-
else if (desc->mech_type == 1 && desc->load == 0 && desc->eject == 1)
93+
} else if (desc->mech_type == 1 && desc->load == 0 &&
94+
desc->eject == 1) {
95+
kfree(buf);
8496
return ODD_MECH_TYPE_DRAWER;
85-
else
97+
} else {
98+
kfree(buf);
8699
return ODD_MECH_TYPE_UNSUPPORTED;
100+
}
87101
}
88102

89103
/* Test if ODD is zero power ready by sense code */

drivers/nvme/host/multipath.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,12 @@ static inline bool nvme_state_is_live(enum nvme_ana_state state)
404404
static void nvme_update_ns_ana_state(struct nvme_ana_group_desc *desc,
405405
struct nvme_ns *ns)
406406
{
407-
enum nvme_ana_state old;
408-
409407
mutex_lock(&ns->head->lock);
410-
old = ns->ana_state;
411408
ns->ana_grpid = le32_to_cpu(desc->grpid);
412409
ns->ana_state = desc->state;
413410
clear_bit(NVME_NS_ANA_PENDING, &ns->flags);
414411

415-
if (nvme_state_is_live(ns->ana_state) && !nvme_state_is_live(old))
412+
if (nvme_state_is_live(ns->ana_state))
416413
nvme_mpath_set_live(ns);
417414
mutex_unlock(&ns->head->lock);
418415
}

drivers/nvme/host/tcp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ static int nvme_tcp_recv_pdu(struct nvme_tcp_queue *queue, struct sk_buff *skb,
627627
return ret;
628628
}
629629

630-
static inline void nvme_tcp_end_request(struct request *rq, __le16 status)
630+
static inline void nvme_tcp_end_request(struct request *rq, u16 status)
631631
{
632632
union nvme_result res = {};
633633

drivers/nvme/target/core.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ int nvmet_ns_enable(struct nvmet_ns *ns)
509509

510510
ret = nvmet_p2pmem_ns_enable(ns);
511511
if (ret)
512-
goto out_unlock;
512+
goto out_dev_disable;
513513

514514
list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry)
515515
nvmet_p2pmem_ns_add_p2p(ctrl, ns);
@@ -550,7 +550,7 @@ int nvmet_ns_enable(struct nvmet_ns *ns)
550550
out_dev_put:
551551
list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry)
552552
pci_dev_put(radix_tree_delete(&ctrl->p2p_ns_map, ns->nsid));
553-
553+
out_dev_disable:
554554
nvmet_ns_dev_disable(ns);
555555
goto out_unlock;
556556
}

drivers/nvme/target/io-cmd-file.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
7575
return ret;
7676
}
7777

78-
static void nvmet_file_init_bvec(struct bio_vec *bv, struct sg_page_iter *iter)
78+
static void nvmet_file_init_bvec(struct bio_vec *bv, struct scatterlist *sg)
7979
{
80-
bv->bv_page = sg_page_iter_page(iter);
81-
bv->bv_offset = iter->sg->offset;
82-
bv->bv_len = PAGE_SIZE - iter->sg->offset;
80+
bv->bv_page = sg_page(sg);
81+
bv->bv_offset = sg->offset;
82+
bv->bv_len = sg->length;
8383
}
8484

8585
static ssize_t nvmet_file_submit_bvec(struct nvmet_req *req, loff_t pos,
@@ -128,14 +128,14 @@ static void nvmet_file_io_done(struct kiocb *iocb, long ret, long ret2)
128128

129129
static bool nvmet_file_execute_io(struct nvmet_req *req, int ki_flags)
130130
{
131-
ssize_t nr_bvec = DIV_ROUND_UP(req->data_len, PAGE_SIZE);
132-
struct sg_page_iter sg_pg_iter;
131+
ssize_t nr_bvec = req->sg_cnt;
133132
unsigned long bv_cnt = 0;
134133
bool is_sync = false;
135134
size_t len = 0, total_len = 0;
136135
ssize_t ret = 0;
137136
loff_t pos;
138-
137+
int i;
138+
struct scatterlist *sg;
139139

140140
if (req->f.mpool_alloc && nr_bvec > NVMET_MAX_MPOOL_BVEC)
141141
is_sync = true;
@@ -147,8 +147,8 @@ static bool nvmet_file_execute_io(struct nvmet_req *req, int ki_flags)
147147
}
148148

149149
memset(&req->f.iocb, 0, sizeof(struct kiocb));
150-
for_each_sg_page(req->sg, &sg_pg_iter, req->sg_cnt, 0) {
151-
nvmet_file_init_bvec(&req->f.bvec[bv_cnt], &sg_pg_iter);
150+
for_each_sg(req->sg, sg, req->sg_cnt, i) {
151+
nvmet_file_init_bvec(&req->f.bvec[bv_cnt], sg);
152152
len += req->f.bvec[bv_cnt].bv_len;
153153
total_len += req->f.bvec[bv_cnt].bv_len;
154154
bv_cnt++;
@@ -225,7 +225,7 @@ static void nvmet_file_submit_buffered_io(struct nvmet_req *req)
225225

226226
static void nvmet_file_execute_rw(struct nvmet_req *req)
227227
{
228-
ssize_t nr_bvec = DIV_ROUND_UP(req->data_len, PAGE_SIZE);
228+
ssize_t nr_bvec = req->sg_cnt;
229229

230230
if (!req->sg_cnt || !nr_bvec) {
231231
nvmet_req_complete(req, 0);

fs/io_uring.c

+24-2
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,8 @@ static int io_write(struct io_kiocb *req, const struct sqe_submit *s,
10221022

10231023
ret = rw_verify_area(WRITE, file, &kiocb->ki_pos, iov_count);
10241024
if (!ret) {
1025+
ssize_t ret2;
1026+
10251027
/*
10261028
* Open-code file_start_write here to grab freeze protection,
10271029
* which will be released by another thread in
@@ -1036,7 +1038,19 @@ static int io_write(struct io_kiocb *req, const struct sqe_submit *s,
10361038
SB_FREEZE_WRITE);
10371039
}
10381040
kiocb->ki_flags |= IOCB_WRITE;
1039-
io_rw_done(kiocb, call_write_iter(file, kiocb, &iter));
1041+
1042+
ret2 = call_write_iter(file, kiocb, &iter);
1043+
if (!force_nonblock || ret2 != -EAGAIN) {
1044+
io_rw_done(kiocb, ret2);
1045+
} else {
1046+
/*
1047+
* If ->needs_lock is true, we're already in async
1048+
* context.
1049+
*/
1050+
if (!s->needs_lock)
1051+
io_async_list_note(WRITE, req, iov_count);
1052+
ret = -EAGAIN;
1053+
}
10401054
}
10411055
out_free:
10421056
kfree(iovec);
@@ -1968,7 +1982,15 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
19681982
return 0;
19691983

19701984
if (sig) {
1971-
ret = set_user_sigmask(sig, &ksigmask, &sigsaved, sigsz);
1985+
#ifdef CONFIG_COMPAT
1986+
if (in_compat_syscall())
1987+
ret = set_compat_user_sigmask((const compat_sigset_t __user *)sig,
1988+
&ksigmask, &sigsaved, sigsz);
1989+
else
1990+
#endif
1991+
ret = set_user_sigmask(sig, &ksigmask,
1992+
&sigsaved, sigsz);
1993+
19721994
if (ret)
19731995
return ret;
19741996
}

lib/sbitmap.c

+11
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,17 @@ EXPORT_SYMBOL_GPL(sbitmap_queue_wake_up);
591591
void sbitmap_queue_clear(struct sbitmap_queue *sbq, unsigned int nr,
592592
unsigned int cpu)
593593
{
594+
/*
595+
* Once the clear bit is set, the bit may be allocated out.
596+
*
597+
* Orders READ/WRITE on the asssociated instance(such as request
598+
* of blk_mq) by this bit for avoiding race with re-allocation,
599+
* and its pair is the memory barrier implied in __sbitmap_get_word.
600+
*
601+
* One invariant is that the clear bit has to be zero when the bit
602+
* is in use.
603+
*/
604+
smp_mb__before_atomic();
594605
sbitmap_deferred_clear_bit(&sbq->sb, nr);
595606

596607
/*

0 commit comments

Comments
 (0)