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
Unified · Split
| @@ -220,7 +220,7 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error) · 219 unmodified lines | ||
| 220 | 220 | blk_mq_tag_set_rq(hctx, flush_rq->tag, fq->orig_rq); |
| 221 | 221 | flush_rq->tag = -1; |
| 222 | 222 | } else { |
| 223 | − blk_mq_put_driver_tag_hctx(hctx, flush_rq); | |
| 223 | + blk_mq_put_driver_tag(flush_rq); | |
| 224 | 224 | flush_rq->internal_tag = -1; |
| 225 | 225 | } |
| 226 | 226 | |
| @@ -324,7 +324,7 @@ static void mq_flush_data_end_io(struct request *rq, blk_status_t error) · 97 unmodified lines | ||
| 324 | 324 | |
| 325 | 325 | if (q->elevator) { |
| 326 | 326 | WARN_ON(rq->tag < 0); |
| 327 | − blk_mq_put_driver_tag_hctx(hctx, rq); | |
| 327 | + blk_mq_put_driver_tag(rq); | |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /* |
| @@ -59,7 +59,8 @@ static int blk_mq_poll_stats_bkt(const struct request *rq) · 58 unmodified lines | ||
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /* |
| 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. | |
| 63 | 64 | */ |
| 64 | 65 | static bool blk_mq_hctx_has_pending(struct blk_mq_hw_ctx *hctx) |
| 65 | 66 | { |
| @@ -1071,7 +1072,13 @@ static int blk_mq_dispatch_wake(wait_queue_entry_t *wait, unsigned mode, · 1005 unmodified lines | ||
| 1071 | 1072 | hctx = container_of(wait, struct blk_mq_hw_ctx, dispatch_wait); |
| 1072 | 1073 | |
| 1073 | 1074 | 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 | + } | |
| 1075 | 1082 | spin_unlock(&hctx->dispatch_wait_lock); |
| 1076 | 1083 | |
| 1077 | 1084 | blk_mq_run_hw_queue(hctx, true); |
| @@ -1087,6 +1094,7 @@ static int blk_mq_dispatch_wake(wait_queue_entry_t *wait, unsigned mode, · 9 unmodified lines | ||
| 1087 | 1094 | static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx *hctx, |
| 1088 | 1095 | struct request *rq) |
| 1089 | 1096 | { |
| 1097 | + struct sbitmap_queue *sbq = &hctx->tags->bitmap_tags; | |
| 1090 | 1098 | struct wait_queue_head *wq; |
| 1091 | 1099 | wait_queue_entry_t *wait; |
| 1092 | 1100 | bool ret; |
| @@ -1109,7 +1117,7 @@ static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx *hctx, · 16 unmodified lines | ||
| 1109 | 1117 | if (!list_empty_careful(&wait->entry)) |
| 1110 | 1118 | return false; |
| 1111 | 1119 | |
| 1112 | − wq = &bt_wait_ptr(&hctx->tags->bitmap_tags, hctx)->wait; | |
| 1120 | + wq = &bt_wait_ptr(sbq, hctx)->wait; | |
| 1113 | 1121 | |
| 1114 | 1122 | spin_lock_irq(&wq->lock); |
| 1115 | 1123 | spin_lock(&hctx->dispatch_wait_lock); |
| @@ -1119,6 +1127,7 @@ static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx *hctx, · 3 unmodified lines | ||
| 1119 | 1127 | return false; |
| 1120 | 1128 | } |
| 1121 | 1129 | |
| 1130 | + atomic_inc(&sbq->ws_active); | |
| 1122 | 1131 | wait->flags &= ~WQ_FLAG_EXCLUSIVE; |
| 1123 | 1132 | __add_wait_queue(wq, wait); |
| 1124 | 1133 | |
| @@ -1139,6 +1148,7 @@ static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx *hctx, · 14 unmodified lines | ||
| 1139 | 1148 | * someone else gets the wakeup. |
| 1140 | 1149 | */ |
| 1141 | 1150 | list_del_init(&wait->entry); |
| 1151 | + atomic_dec(&sbq->ws_active); | |
| 1142 | 1152 | spin_unlock(&hctx->dispatch_wait_lock); |
| 1143 | 1153 | spin_unlock_irq(&wq->lock); |
| 1144 | 1154 | |
| @@ -224,15 +224,6 @@ static inline void __blk_mq_put_driver_tag(struct blk_mq_hw_ctx *hctx, · 223 unmodified lines | ||
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | |
| 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 | − | |
| 236 | 227 | static inline void blk_mq_put_driver_tag(struct request *rq) |
| 237 | 228 | { |
| 238 | 229 | if (rq->tag == -1 || rq->internal_tag == -1) |
| @@ -52,38 +52,52 @@ static int eject_tray(struct ata_device *dev) · 51 unmodified lines | ||
| 52 | 52 | /* Per the spec, only slot type and drawer type ODD can be supported */ |
| 53 | 53 | static enum odd_mech_type zpodd_get_mech_type(struct ata_device *dev) |
| 54 | 54 | { |
| 55 | − char buf[16]; | |
| 55 | + char *buf; | |
| 56 | 56 | unsigned int ret; |
| 57 | − struct rm_feature_desc *desc = (void *)(buf + 8); | |
| 57 | + struct rm_feature_desc *desc; | |
| 58 | 58 | struct ata_taskfile tf; |
| 59 | 59 | static const char cdb[] = { GPCMD_GET_CONFIGURATION, |
| 60 | 60 | 2, /* only 1 feature descriptor requested */ |
| 61 | 61 | 0, 3, /* 3, removable medium feature */ |
| 62 | 62 | 0, 0, 0,/* reserved */ |
| 63 | − 0, sizeof(buf), | |
| 63 | + 0, 16, | |
| 64 | 64 | 0, 0, 0, |
| 65 | 65 | }; |
| 66 | 66 | |
| 67 | + buf = kzalloc(16, GFP_KERNEL); | |
| 68 | + if (!buf) | |
| 69 | + return ODD_MECH_TYPE_UNSUPPORTED; | |
| 70 | + desc = (void *)(buf + 8); | |
| 71 | + | |
| 67 | 72 | ata_tf_init(dev, &tf); |
| 68 | 73 | tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 69 | 74 | tf.command = ATA_CMD_PACKET; |
| 70 | 75 | tf.protocol = ATAPI_PROT_PIO; |
| 71 | − tf.lbam = sizeof(buf); | |
| 76 | + tf.lbam = 16; | |
| 72 | 77 | |
| 73 | 78 | 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); | |
| 76 | 82 | return ODD_MECH_TYPE_UNSUPPORTED; |
| 83 | + } | |
| 77 | 84 | |
| 78 | − if (be16_to_cpu(desc->feature_code) != 3) | |
| 85 | + if (be16_to_cpu(desc->feature_code) != 3) { | |
| 86 | + kfree(buf); | |
| 79 | 87 | return ODD_MECH_TYPE_UNSUPPORTED; |
| 88 | + } | |
| 80 | 89 | |
| 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); | |
| 82 | 92 | 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); | |
| 84 | 96 | return ODD_MECH_TYPE_DRAWER; |
| 85 | − else | |
| 97 | + } else { | |
| 98 | + kfree(buf); | |
| 86 | 99 | return ODD_MECH_TYPE_UNSUPPORTED; |
| 100 | + } | |
| 87 | 101 | } |
| 88 | 102 | |
| 89 | 103 | /* Test if ODD is zero power ready by sense code */ |
| @@ -404,15 +404,12 @@ static inline bool nvme_state_is_live(enum nvme_ana_state state) · 403 unmodified lines | ||
| 404 | 404 | static void nvme_update_ns_ana_state(struct nvme_ana_group_desc *desc, |
| 405 | 405 | struct nvme_ns *ns) |
| 406 | 406 | { |
| 407 | − enum nvme_ana_state old; | |
| 408 | − | |
| 409 | 407 | mutex_lock(&ns->head->lock); |
| 410 | − old = ns->ana_state; | |
| 411 | 408 | ns->ana_grpid = le32_to_cpu(desc->grpid); |
| 412 | 409 | ns->ana_state = desc->state; |
| 413 | 410 | clear_bit(NVME_NS_ANA_PENDING, &ns->flags); |
| 414 | 411 | |
| 415 | − if (nvme_state_is_live(ns->ana_state) && !nvme_state_is_live(old)) | |
| 412 | + if (nvme_state_is_live(ns->ana_state)) | |
| 416 | 413 | nvme_mpath_set_live(ns); |
| 417 | 414 | mutex_unlock(&ns->head->lock); |
| 418 | 415 | } |
| @@ -627,7 +627,7 @@ static int nvme_tcp_recv_pdu(struct nvme_tcp_queue *queue, struct sk_buff *skb, · 626 unmodified lines | ||
| 627 | 627 | return ret; |
| 628 | 628 | } |
| 629 | 629 | |
| 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) | |
| 631 | 631 | { |
| 632 | 632 | union nvme_result res = {}; |
| 633 | 633 | |
| @@ -509,7 +509,7 @@ int nvmet_ns_enable(struct nvmet_ns *ns) · 508 unmodified lines | ||
| 509 | 509 | |
| 510 | 510 | ret = nvmet_p2pmem_ns_enable(ns); |
| 511 | 511 | if (ret) |
| 512 | − goto out_unlock; | |
| 512 | + goto out_dev_disable; | |
| 513 | 513 | |
| 514 | 514 | list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) |
| 515 | 515 | nvmet_p2pmem_ns_add_p2p(ctrl, ns); |
| @@ -550,7 +550,7 @@ out_unlock: · 34 unmodified lines | ||
| 550 | 550 | out_dev_put: |
| 551 | 551 | list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) |
| 552 | 552 | pci_dev_put(radix_tree_delete(&ctrl->p2p_ns_map, ns->nsid)); |
| 553 | − | |
| 553 | +out_dev_disable: | |
| 554 | 554 | nvmet_ns_dev_disable(ns); |
| 555 | 555 | goto out_unlock; |
| 556 | 556 | } |
| @@ -75,11 +75,11 @@ err: · 74 unmodified lines | ||
| 75 | 75 | return ret; |
| 76 | 76 | } |
| 77 | 77 | |
| 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) | |
| 79 | 79 | { |
| 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; | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | 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) · 42 unmodified lines | ||
| 128 | 128 | |
| 129 | 129 | static bool nvmet_file_execute_io(struct nvmet_req *req, int ki_flags) |
| 130 | 130 | { |
| 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; | |
| 133 | 132 | unsigned long bv_cnt = 0; |
| 134 | 133 | bool is_sync = false; |
| 135 | 134 | size_t len = 0, total_len = 0; |
| 136 | 135 | ssize_t ret = 0; |
| 137 | 136 | loff_t pos; |
| 138 | − | |
| 137 | + int i; | |
| 138 | + struct scatterlist *sg; | |
| 139 | 139 | |
| 140 | 140 | if (req->f.mpool_alloc && nr_bvec > NVMET_MAX_MPOOL_BVEC) |
| 141 | 141 | is_sync = true; |
| @@ -147,8 +147,8 @@ static bool nvmet_file_execute_io(struct nvmet_req *req, int ki_flags) · 5 unmodified lines | ||
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | 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); | |
| 152 | 152 | len += req->f.bvec[bv_cnt].bv_len; |
| 153 | 153 | total_len += req->f.bvec[bv_cnt].bv_len; |
| 154 | 154 | bv_cnt++; |
| @@ -225,7 +225,7 @@ static void nvmet_file_submit_buffered_io(struct nvmet_req *req) · 70 unmodified lines | ||
| 225 | 225 | |
| 226 | 226 | static void nvmet_file_execute_rw(struct nvmet_req *req) |
| 227 | 227 | { |
| 228 | − ssize_t nr_bvec = DIV_ROUND_UP(req->data_len, PAGE_SIZE); | |
| 228 | + ssize_t nr_bvec = req->sg_cnt; | |
| 229 | 229 | |
| 230 | 230 | if (!req->sg_cnt || !nr_bvec) { |
| 231 | 231 | nvmet_req_complete(req, 0); |
| @@ -1022,6 +1022,8 @@ static int io_write(struct io_kiocb *req, const struct sqe_submit *s, · 1021 unmodified lines | ||
| 1022 | 1022 | |
| 1023 | 1023 | ret = rw_verify_area(WRITE, file, &kiocb->ki_pos, iov_count); |
| 1024 | 1024 | if (!ret) { |
| 1025 | + ssize_t ret2; | |
| 1026 | + | |
| 1025 | 1027 | /* |
| 1026 | 1028 | * Open-code file_start_write here to grab freeze protection, |
| 1027 | 1029 | * 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, · 8 unmodified lines | ||
| 1036 | 1038 | SB_FREEZE_WRITE); |
| 1037 | 1039 | } |
| 1038 | 1040 | 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 | + } | |
| 1040 | 1054 | } |
| 1041 | 1055 | out_free: |
| 1042 | 1056 | kfree(iovec); |
| @@ -1968,7 +1982,15 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, · 925 unmodified lines | ||
| 1968 | 1982 | return 0; |
| 1969 | 1983 | |
| 1970 | 1984 | 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 | + | |
| 1972 | 1994 | if (ret) |
| 1973 | 1995 | return ret; |
| 1974 | 1996 | } |
| @@ -591,6 +591,17 @@ EXPORT_SYMBOL_GPL(sbitmap_queue_wake_up); · 590 unmodified lines | ||
| 591 | 591 | void sbitmap_queue_clear(struct sbitmap_queue *sbq, unsigned int nr, |
| 592 | 592 | unsigned int cpu) |
| 593 | 593 | { |
| 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(); | |
| 594 | 605 | sbitmap_deferred_clear_bit(&sbq->sb, nr); |
| 595 | 606 | |
| 596 | 607 | /* |