Skip to content

Commit d9a9755

Browse files
committed
Merge branch 'nvme-5.7' of git://git.infradead.org/nvme into block-5.7
Pull NVMe fixes from Christoph. * 'nvme-5.7' of git://git.infradead.org/nvme: nvmet-rdma: fix double free of rdma queue nvme-fc: Revert "add module to ops template to allow module references" nvme: fix deadlock caused by ANA update wrong locking nvmet-rdma: fix bonding failover possible NULL deref nvmet: fix NULL dereference when removing a referral nvme: inherit stable pages constraint in the mpath stack device nvme-tcp: fix possible crash in recv error flow nvme-tcp: don't poll a non-live queue nvme-tcp: fix possible crash in write_zeroes processing nvmet-fc: fix typo in comment nvme-rdma: Replace comma with a semicolon nvme-fcloop: fix deallocation of working context nvme: fix compat address handling in several ioctls
2 parents d3ef553 + 21f9024 commit d9a9755

File tree

12 files changed

+242
-131
lines changed

12 files changed

+242
-131
lines changed

drivers/nvme/host/core.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <linux/blkdev.h>
88
#include <linux/blk-mq.h>
9+
#include <linux/compat.h>
910
#include <linux/delay.h>
1011
#include <linux/errno.h>
1112
#include <linux/hdreg.h>
@@ -1252,6 +1253,18 @@ static void nvme_enable_aen(struct nvme_ctrl *ctrl)
12521253
queue_work(nvme_wq, &ctrl->async_event_work);
12531254
}
12541255

1256+
/*
1257+
* Convert integer values from ioctl structures to user pointers, silently
1258+
* ignoring the upper bits in the compat case to match behaviour of 32-bit
1259+
* kernels.
1260+
*/
1261+
static void __user *nvme_to_user_ptr(uintptr_t ptrval)
1262+
{
1263+
if (in_compat_syscall())
1264+
ptrval = (compat_uptr_t)ptrval;
1265+
return (void __user *)ptrval;
1266+
}
1267+
12551268
static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
12561269
{
12571270
struct nvme_user_io io;
@@ -1275,7 +1288,7 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
12751288

12761289
length = (io.nblocks + 1) << ns->lba_shift;
12771290
meta_len = (io.nblocks + 1) * ns->ms;
1278-
metadata = (void __user *)(uintptr_t)io.metadata;
1291+
metadata = nvme_to_user_ptr(io.metadata);
12791292

12801293
if (ns->ext) {
12811294
length += meta_len;
@@ -1298,7 +1311,7 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
12981311
c.rw.appmask = cpu_to_le16(io.appmask);
12991312

13001313
return nvme_submit_user_cmd(ns->queue, &c,
1301-
(void __user *)(uintptr_t)io.addr, length,
1314+
nvme_to_user_ptr(io.addr), length,
13021315
metadata, meta_len, lower_32_bits(io.slba), NULL, 0);
13031316
}
13041317

@@ -1418,9 +1431,9 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
14181431

14191432
effects = nvme_passthru_start(ctrl, ns, cmd.opcode);
14201433
status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c,
1421-
(void __user *)(uintptr_t)cmd.addr, cmd.data_len,
1422-
(void __user *)(uintptr_t)cmd.metadata,
1423-
cmd.metadata_len, 0, &result, timeout);
1434+
nvme_to_user_ptr(cmd.addr), cmd.data_len,
1435+
nvme_to_user_ptr(cmd.metadata), cmd.metadata_len,
1436+
0, &result, timeout);
14241437
nvme_passthru_end(ctrl, effects);
14251438

14261439
if (status >= 0) {
@@ -1465,8 +1478,8 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
14651478

14661479
effects = nvme_passthru_start(ctrl, ns, cmd.opcode);
14671480
status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c,
1468-
(void __user *)(uintptr_t)cmd.addr, cmd.data_len,
1469-
(void __user *)(uintptr_t)cmd.metadata, cmd.metadata_len,
1481+
nvme_to_user_ptr(cmd.addr), cmd.data_len,
1482+
nvme_to_user_ptr(cmd.metadata), cmd.metadata_len,
14701483
0, &cmd.result, timeout);
14711484
nvme_passthru_end(ctrl, effects);
14721485

@@ -1884,6 +1897,13 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
18841897
if (ns->head->disk) {
18851898
nvme_update_disk_info(ns->head->disk, ns, id);
18861899
blk_queue_stack_limits(ns->head->disk->queue, ns->queue);
1900+
if (bdi_cap_stable_pages_required(ns->queue->backing_dev_info)) {
1901+
struct backing_dev_info *info =
1902+
ns->head->disk->queue->backing_dev_info;
1903+
1904+
info->capabilities |= BDI_CAP_STABLE_WRITES;
1905+
}
1906+
18871907
revalidate_disk(ns->head->disk);
18881908
}
18891909
#endif

drivers/nvme/host/fc.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ nvme_fc_register_localport(struct nvme_fc_port_info *pinfo,
342342
!template->ls_req || !template->fcp_io ||
343343
!template->ls_abort || !template->fcp_abort ||
344344
!template->max_hw_queues || !template->max_sgl_segments ||
345-
!template->max_dif_sgl_segments || !template->dma_boundary ||
346-
!template->module) {
345+
!template->max_dif_sgl_segments || !template->dma_boundary) {
347346
ret = -EINVAL;
348347
goto out_reghost_failed;
349348
}
@@ -2016,7 +2015,6 @@ nvme_fc_ctrl_free(struct kref *ref)
20162015
{
20172016
struct nvme_fc_ctrl *ctrl =
20182017
container_of(ref, struct nvme_fc_ctrl, ref);
2019-
struct nvme_fc_lport *lport = ctrl->lport;
20202018
unsigned long flags;
20212019

20222020
if (ctrl->ctrl.tagset) {
@@ -2043,7 +2041,6 @@ nvme_fc_ctrl_free(struct kref *ref)
20432041
if (ctrl->ctrl.opts)
20442042
nvmf_free_options(ctrl->ctrl.opts);
20452043
kfree(ctrl);
2046-
module_put(lport->ops->module);
20472044
}
20482045

20492046
static void
@@ -3074,15 +3071,10 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
30743071
goto out_fail;
30753072
}
30763073

3077-
if (!try_module_get(lport->ops->module)) {
3078-
ret = -EUNATCH;
3079-
goto out_free_ctrl;
3080-
}
3081-
30823074
idx = ida_simple_get(&nvme_fc_ctrl_cnt, 0, 0, GFP_KERNEL);
30833075
if (idx < 0) {
30843076
ret = -ENOSPC;
3085-
goto out_mod_put;
3077+
goto out_free_ctrl;
30863078
}
30873079

30883080
ctrl->ctrl.opts = opts;
@@ -3232,8 +3224,6 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
32323224
out_free_ida:
32333225
put_device(ctrl->dev);
32343226
ida_simple_remove(&nvme_fc_ctrl_cnt, ctrl->cnum);
3235-
out_mod_put:
3236-
module_put(lport->ops->module);
32373227
out_free_ctrl:
32383228
kfree(ctrl);
32393229
out_fail:

drivers/nvme/host/multipath.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ static int nvme_update_ana_state(struct nvme_ctrl *ctrl,
510510
if (!nr_nsids)
511511
return 0;
512512

513-
down_write(&ctrl->namespaces_rwsem);
513+
down_read(&ctrl->namespaces_rwsem);
514514
list_for_each_entry(ns, &ctrl->namespaces, list) {
515515
unsigned nsid = le32_to_cpu(desc->nsids[n]);
516516

@@ -521,7 +521,7 @@ static int nvme_update_ana_state(struct nvme_ctrl *ctrl,
521521
if (++n == nr_nsids)
522522
break;
523523
}
524-
up_write(&ctrl->namespaces_rwsem);
524+
up_read(&ctrl->namespaces_rwsem);
525525
return 0;
526526
}
527527

drivers/nvme/host/rdma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ static int nvme_rdma_post_send(struct nvme_rdma_queue *queue,
13501350
int ret;
13511351

13521352
sge->addr = qe->dma;
1353-
sge->length = sizeof(struct nvme_command),
1353+
sge->length = sizeof(struct nvme_command);
13541354
sge->lkey = queue->device->pd->local_dma_lkey;
13551355

13561356
wr.next = NULL;

drivers/nvme/host/tcp.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,14 @@ static inline bool nvme_tcp_async_req(struct nvme_tcp_request *req)
174174
static inline bool nvme_tcp_has_inline_data(struct nvme_tcp_request *req)
175175
{
176176
struct request *rq;
177-
unsigned int bytes;
178177

179178
if (unlikely(nvme_tcp_async_req(req)))
180179
return false; /* async events don't have a request */
181180

182181
rq = blk_mq_rq_from_pdu(req);
183-
bytes = blk_rq_payload_bytes(rq);
184182

185-
return rq_data_dir(rq) == WRITE && bytes &&
186-
bytes <= nvme_tcp_inline_data_size(req->queue);
183+
return rq_data_dir(rq) == WRITE && req->data_len &&
184+
req->data_len <= nvme_tcp_inline_data_size(req->queue);
187185
}
188186

189187
static inline struct page *nvme_tcp_req_cur_page(struct nvme_tcp_request *req)
@@ -1075,7 +1073,7 @@ static void nvme_tcp_io_work(struct work_struct *w)
10751073
if (result > 0)
10761074
pending = true;
10771075
else if (unlikely(result < 0))
1078-
break;
1076+
return;
10791077

10801078
if (!pending)
10811079
return;
@@ -2164,7 +2162,9 @@ static blk_status_t nvme_tcp_map_data(struct nvme_tcp_queue *queue,
21642162

21652163
c->common.flags |= NVME_CMD_SGL_METABUF;
21662164

2167-
if (rq_data_dir(rq) == WRITE && req->data_len &&
2165+
if (!blk_rq_nr_phys_segments(rq))
2166+
nvme_tcp_set_sg_null(c);
2167+
else if (rq_data_dir(rq) == WRITE &&
21682168
req->data_len <= nvme_tcp_inline_data_size(queue))
21692169
nvme_tcp_set_sg_inline(queue, c, req->data_len);
21702170
else
@@ -2191,7 +2191,8 @@ static blk_status_t nvme_tcp_setup_cmd_pdu(struct nvme_ns *ns,
21912191
req->data_sent = 0;
21922192
req->pdu_len = 0;
21932193
req->pdu_sent = 0;
2194-
req->data_len = blk_rq_payload_bytes(rq);
2194+
req->data_len = blk_rq_nr_phys_segments(rq) ?
2195+
blk_rq_payload_bytes(rq) : 0;
21952196
req->curr_bio = rq->bio;
21962197

21972198
if (rq_data_dir(rq) == WRITE &&
@@ -2298,6 +2299,9 @@ static int nvme_tcp_poll(struct blk_mq_hw_ctx *hctx)
22982299
struct nvme_tcp_queue *queue = hctx->driver_data;
22992300
struct sock *sk = queue->sock->sk;
23002301

2302+
if (!test_bit(NVME_TCP_Q_LIVE, &queue->flags))
2303+
return 0;
2304+
23012305
if (sk_can_busy_loop(sk) && skb_queue_empty_lockless(&sk->sk_receive_queue))
23022306
sk_busy_loop(sk, true);
23032307
nvme_tcp_try_recv(queue);

drivers/nvme/target/configfs.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,12 +1098,19 @@ static struct configfs_attribute *nvmet_referral_attrs[] = {
10981098
NULL,
10991099
};
11001100

1101-
static void nvmet_referral_release(struct config_item *item)
1101+
static void nvmet_referral_notify(struct config_group *group,
1102+
struct config_item *item)
11021103
{
11031104
struct nvmet_port *parent = to_nvmet_port(item->ci_parent->ci_parent);
11041105
struct nvmet_port *port = to_nvmet_port(item);
11051106

11061107
nvmet_referral_disable(parent, port);
1108+
}
1109+
1110+
static void nvmet_referral_release(struct config_item *item)
1111+
{
1112+
struct nvmet_port *port = to_nvmet_port(item);
1113+
11071114
kfree(port);
11081115
}
11091116

@@ -1134,6 +1141,7 @@ static struct config_group *nvmet_referral_make(
11341141

11351142
static struct configfs_group_operations nvmet_referral_group_ops = {
11361143
.make_group = nvmet_referral_make,
1144+
.disconnect_notify = nvmet_referral_notify,
11371145
};
11381146

11391147
static const struct config_item_type nvmet_referrals_type = {

drivers/nvme/target/fc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ nvmet_fc_delete_target_queue(struct nvmet_fc_tgt_queue *queue)
684684
disconnect = atomic_xchg(&queue->connected, 0);
685685

686686
spin_lock_irqsave(&queue->qlock, flags);
687-
/* about outstanding io's */
687+
/* abort outstanding io's */
688688
for (i = 0; i < queue->sqsize; fod++, i++) {
689689
if (fod->active) {
690690
spin_lock(&fod->flock);

0 commit comments

Comments
 (0)