Skip to content

Commit ae53aea

Browse files
committed
Merge tag 'nvme-5.18-2022-03-17' of git://git.infradead.org/nvme into for-5.18/drivers
Pull NVMe updates from Christoph: "Second round of nvme updates for Linux 5.18 - add lockdep annotations for in-kernel sockets (Chris Leech) - use vmalloc for ANA log buffer (Hannes Reinecke) - kerneldoc fixes (Chaitanya Kulkarni) - cleanups (Guoqing Jiang, Chaitanya Kulkarni, me) - warn about shared namespaces without multipathing (me)" * tag 'nvme-5.18-2022-03-17' of git://git.infradead.org/nvme: nvme: warn about shared namespaces without CONFIG_NVME_MULTIPATH nvme: remove nvme_alloc_request and nvme_alloc_request_qid nvme: cleanup how disk->disk_name is assigned nvmet: move the call to nvmet_ns_changed out of nvmet_ns_revalidate nvmet: use snprintf() with PAGE_SIZE in configfs nvmet: don't fold lines nvmet-rdma: fix kernel-doc warning for nvmet_rdma_device_removal nvmet-fc: fix kernel-doc warning for nvmet_fc_unregister_targetport nvmet-fc: fix kernel-doc warning for nvmet_fc_register_targetport nvme-tcp: lockdep: annotate in-kernel sockets nvme-tcp: don't fold the line nvme-tcp: don't initialize ret variable nvme-multipath: call bio_io_error in nvme_ns_head_submit_bio nvme-multipath: use vmalloc for ANA log buffer
2 parents bcfe9b6 + ce8d786 commit ae53aea

15 files changed

Lines changed: 138 additions & 110 deletions

File tree

drivers/block/loop.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,7 @@ static void loop_remove(struct loop_device *lo)
20922092
del_gendisk(lo->lo_disk);
20932093
blk_cleanup_disk(lo->lo_disk);
20942094
blk_mq_free_tag_set(&lo->tag_set);
2095+
20952096
mutex_lock(&loop_ctl_mutex);
20962097
idr_remove(&loop_index_idr, lo->lo_number);
20972098
mutex_unlock(&loop_ctl_mutex);

drivers/nvme/host/core.c

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -639,13 +639,8 @@ static inline void nvme_clear_nvme_request(struct request *req)
639639
req->rq_flags |= RQF_DONTPREP;
640640
}
641641

642-
static inline unsigned int nvme_req_op(struct nvme_command *cmd)
643-
{
644-
return nvme_is_write(cmd) ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN;
645-
}
646-
647-
static inline void nvme_init_request(struct request *req,
648-
struct nvme_command *cmd)
642+
/* initialize a passthrough request */
643+
void nvme_init_request(struct request *req, struct nvme_command *cmd)
649644
{
650645
if (req->q->queuedata)
651646
req->timeout = NVME_IO_TIMEOUT;
@@ -661,30 +656,7 @@ static inline void nvme_init_request(struct request *req,
661656
nvme_clear_nvme_request(req);
662657
memcpy(nvme_req(req)->cmd, cmd, sizeof(*cmd));
663658
}
664-
665-
struct request *nvme_alloc_request(struct request_queue *q,
666-
struct nvme_command *cmd, blk_mq_req_flags_t flags)
667-
{
668-
struct request *req;
669-
670-
req = blk_mq_alloc_request(q, nvme_req_op(cmd), flags);
671-
if (!IS_ERR(req))
672-
nvme_init_request(req, cmd);
673-
return req;
674-
}
675-
EXPORT_SYMBOL_GPL(nvme_alloc_request);
676-
677-
static struct request *nvme_alloc_request_qid(struct request_queue *q,
678-
struct nvme_command *cmd, blk_mq_req_flags_t flags, int qid)
679-
{
680-
struct request *req;
681-
682-
req = blk_mq_alloc_request_hctx(q, nvme_req_op(cmd), flags,
683-
qid ? qid - 1 : 0);
684-
if (!IS_ERR(req))
685-
nvme_init_request(req, cmd);
686-
return req;
687-
}
659+
EXPORT_SYMBOL_GPL(nvme_init_request);
688660

689661
/*
690662
* For something we're not in a state to send to the device the default action
@@ -1110,11 +1082,14 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
11101082
int ret;
11111083

11121084
if (qid == NVME_QID_ANY)
1113-
req = nvme_alloc_request(q, cmd, flags);
1085+
req = blk_mq_alloc_request(q, nvme_req_op(cmd), flags);
11141086
else
1115-
req = nvme_alloc_request_qid(q, cmd, flags, qid);
1087+
req = blk_mq_alloc_request_hctx(q, nvme_req_op(cmd), flags,
1088+
qid ? qid - 1 : 0);
1089+
11161090
if (IS_ERR(req))
11171091
return PTR_ERR(req);
1092+
nvme_init_request(req, cmd);
11181093

11191094
if (timeout)
11201095
req->timeout = timeout;
@@ -1304,14 +1279,15 @@ static void nvme_keep_alive_work(struct work_struct *work)
13041279
return;
13051280
}
13061281

1307-
rq = nvme_alloc_request(ctrl->admin_q, &ctrl->ka_cmd,
1308-
BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT);
1282+
rq = blk_mq_alloc_request(ctrl->admin_q, nvme_req_op(&ctrl->ka_cmd),
1283+
BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT);
13091284
if (IS_ERR(rq)) {
13101285
/* allocation failure, reset the controller */
13111286
dev_err(ctrl->device, "keep-alive failed: %ld\n", PTR_ERR(rq));
13121287
nvme_reset_ctrl(ctrl);
13131288
return;
13141289
}
1290+
nvme_init_request(rq, &ctrl->ka_cmd);
13151291

13161292
rq->timeout = ctrl->kato * HZ;
13171293
rq->end_io_data = ctrl;
@@ -3879,6 +3855,14 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid,
38793855
nsid);
38803856
goto out_put_ns_head;
38813857
}
3858+
3859+
if (!multipath && !list_empty(&head->list)) {
3860+
dev_warn(ctrl->device,
3861+
"Found shared namespace %d, but multipathing not supported.\n",
3862+
nsid);
3863+
dev_warn_once(ctrl->device,
3864+
"Support for shared namespaces without CONFIG_NVME_MULTIPATH is deprecated and will be removed in Linux 6.0\n.");
3865+
}
38823866
}
38833867

38843868
list_add_tail_rcu(&ns->siblings, &head->list);
@@ -3967,13 +3951,27 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid,
39673951
goto out_cleanup_disk;
39683952

39693953
/*
3970-
* Without the multipath code enabled, multiple controller per
3971-
* subsystems are visible as devices and thus we cannot use the
3972-
* subsystem instance.
3954+
* If multipathing is enabled, the device name for all disks and not
3955+
* just those that represent shared namespaces needs to be based on the
3956+
* subsystem instance. Using the controller instance for private
3957+
* namespaces could lead to naming collisions between shared and private
3958+
* namespaces if they don't use a common numbering scheme.
3959+
*
3960+
* If multipathing is not enabled, disk names must use the controller
3961+
* instance as shared namespaces will show up as multiple block
3962+
* devices.
39733963
*/
3974-
if (!nvme_mpath_set_disk_name(ns, disk->disk_name, &disk->flags))
3964+
if (ns->head->disk) {
3965+
sprintf(disk->disk_name, "nvme%dc%dn%d", ctrl->subsys->instance,
3966+
ctrl->instance, ns->head->instance);
3967+
disk->flags |= GENHD_FL_HIDDEN;
3968+
} else if (multipath) {
3969+
sprintf(disk->disk_name, "nvme%dn%d", ctrl->subsys->instance,
3970+
ns->head->instance);
3971+
} else {
39753972
sprintf(disk->disk_name, "nvme%dn%d", ctrl->instance,
39763973
ns->head->instance);
3974+
}
39773975

39783976
if (nvme_update_ns_info(ns, id))
39793977
goto out_unlink_ns;

drivers/nvme/host/ioctl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ static int nvme_submit_user_cmd(struct request_queue *q,
6666
void *meta = NULL;
6767
int ret;
6868

69-
req = nvme_alloc_request(q, cmd, 0);
69+
req = blk_mq_alloc_request(q, nvme_req_op(cmd), 0);
7070
if (IS_ERR(req))
7171
return PTR_ERR(req);
72+
nvme_init_request(req, cmd);
7273

7374
if (timeout)
7475
req->timeout = timeout;

drivers/nvme/host/multipath.c

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
#include <linux/backing-dev.h>
77
#include <linux/moduleparam.h>
8+
#include <linux/vmalloc.h>
89
#include <trace/events/block.h>
910
#include "nvme.h"
1011

11-
static bool multipath = true;
12+
bool multipath = true;
1213
module_param(multipath, bool, 0444);
1314
MODULE_PARM_DESC(multipath,
1415
"turn on native support for multiple controllers per subsystem");
@@ -79,28 +80,6 @@ void nvme_mpath_start_freeze(struct nvme_subsystem *subsys)
7980
blk_freeze_queue_start(h->disk->queue);
8081
}
8182

82-
/*
83-
* If multipathing is enabled we need to always use the subsystem instance
84-
* number for numbering our devices to avoid conflicts between subsystems that
85-
* have multiple controllers and thus use the multipath-aware subsystem node
86-
* and those that have a single controller and use the controller node
87-
* directly.
88-
*/
89-
bool nvme_mpath_set_disk_name(struct nvme_ns *ns, char *disk_name, int *flags)
90-
{
91-
if (!multipath)
92-
return false;
93-
if (!ns->head->disk) {
94-
sprintf(disk_name, "nvme%dn%d", ns->ctrl->subsys->instance,
95-
ns->head->instance);
96-
return true;
97-
}
98-
sprintf(disk_name, "nvme%dc%dn%d", ns->ctrl->subsys->instance,
99-
ns->ctrl->instance, ns->head->instance);
100-
*flags = GENHD_FL_HIDDEN;
101-
return true;
102-
}
103-
10483
void nvme_failover_req(struct request *req)
10584
{
10685
struct nvme_ns *ns = req->q->queuedata;
@@ -386,8 +365,7 @@ static void nvme_ns_head_submit_bio(struct bio *bio)
386365
} else {
387366
dev_warn_ratelimited(dev, "no available path - failing I/O\n");
388367

389-
bio->bi_status = BLK_STS_IOERR;
390-
bio_endio(bio);
368+
bio_io_error(bio);
391369
}
392370

393371
srcu_read_unlock(&head->srcu, srcu_idx);
@@ -898,7 +876,7 @@ int nvme_mpath_init_identify(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
898876
if (ana_log_size > ctrl->ana_log_size) {
899877
nvme_mpath_stop(ctrl);
900878
nvme_mpath_uninit(ctrl);
901-
ctrl->ana_log_buf = kmalloc(ana_log_size, GFP_KERNEL);
879+
ctrl->ana_log_buf = kvmalloc(ana_log_size, GFP_KERNEL);
902880
if (!ctrl->ana_log_buf)
903881
return -ENOMEM;
904882
}
@@ -915,7 +893,7 @@ int nvme_mpath_init_identify(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
915893

916894
void nvme_mpath_uninit(struct nvme_ctrl *ctrl)
917895
{
918-
kfree(ctrl->ana_log_buf);
896+
kvfree(ctrl->ana_log_buf);
919897
ctrl->ana_log_buf = NULL;
920898
ctrl->ana_log_size = 0;
921899
}

drivers/nvme/host/nvme.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,13 @@ void nvme_wait_freeze(struct nvme_ctrl *ctrl);
698698
int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout);
699699
void nvme_start_freeze(struct nvme_ctrl *ctrl);
700700

701+
static inline unsigned int nvme_req_op(struct nvme_command *cmd)
702+
{
703+
return nvme_is_write(cmd) ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN;
704+
}
705+
701706
#define NVME_QID_ANY -1
702-
struct request *nvme_alloc_request(struct request_queue *q,
703-
struct nvme_command *cmd, blk_mq_req_flags_t flags);
707+
void nvme_init_request(struct request *req, struct nvme_command *cmd);
704708
void nvme_cleanup_cmd(struct request *req);
705709
blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req);
706710
blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl,
@@ -770,7 +774,6 @@ void nvme_mpath_unfreeze(struct nvme_subsystem *subsys);
770774
void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys);
771775
void nvme_mpath_start_freeze(struct nvme_subsystem *subsys);
772776
void nvme_mpath_default_iopolicy(struct nvme_subsystem *subsys);
773-
bool nvme_mpath_set_disk_name(struct nvme_ns *ns, char *disk_name, int *flags);
774777
void nvme_failover_req(struct request *req);
775778
void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl);
776779
int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl,struct nvme_ns_head *head);
@@ -793,20 +796,17 @@ static inline void nvme_trace_bio_complete(struct request *req)
793796
trace_block_bio_complete(ns->head->disk->queue, req->bio);
794797
}
795798

799+
extern bool multipath;
796800
extern struct device_attribute dev_attr_ana_grpid;
797801
extern struct device_attribute dev_attr_ana_state;
798802
extern struct device_attribute subsys_attr_iopolicy;
799803

800804
#else
805+
#define multipath false
801806
static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl)
802807
{
803808
return false;
804809
}
805-
static inline bool nvme_mpath_set_disk_name(struct nvme_ns *ns, char *disk_name,
806-
int *flags)
807-
{
808-
return false;
809-
}
810810
static inline void nvme_failover_req(struct request *req)
811811
{
812812
}

drivers/nvme/host/pci.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,9 @@ static int nvme_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
424424
return 0;
425425
}
426426

427-
static int nvme_init_request(struct blk_mq_tag_set *set, struct request *req,
428-
unsigned int hctx_idx, unsigned int numa_node)
427+
static int nvme_pci_init_request(struct blk_mq_tag_set *set,
428+
struct request *req, unsigned int hctx_idx,
429+
unsigned int numa_node)
429430
{
430431
struct nvme_dev *dev = set->driver_data;
431432
struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
@@ -1428,12 +1429,13 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
14281429
"I/O %d QID %d timeout, aborting\n",
14291430
req->tag, nvmeq->qid);
14301431

1431-
abort_req = nvme_alloc_request(dev->ctrl.admin_q, &cmd,
1432-
BLK_MQ_REQ_NOWAIT);
1432+
abort_req = blk_mq_alloc_request(dev->ctrl.admin_q, nvme_req_op(&cmd),
1433+
BLK_MQ_REQ_NOWAIT);
14331434
if (IS_ERR(abort_req)) {
14341435
atomic_inc(&dev->ctrl.abort_limit);
14351436
return BLK_EH_RESET_TIMER;
14361437
}
1438+
nvme_init_request(abort_req, &cmd);
14371439

14381440
abort_req->end_io_data = NULL;
14391441
blk_execute_rq_nowait(abort_req, false, abort_endio);
@@ -1722,7 +1724,7 @@ static const struct blk_mq_ops nvme_mq_admin_ops = {
17221724
.queue_rq = nvme_queue_rq,
17231725
.complete = nvme_pci_complete_rq,
17241726
.init_hctx = nvme_admin_init_hctx,
1725-
.init_request = nvme_init_request,
1727+
.init_request = nvme_pci_init_request,
17261728
.timeout = nvme_timeout,
17271729
};
17281730

@@ -1732,7 +1734,7 @@ static const struct blk_mq_ops nvme_mq_ops = {
17321734
.complete = nvme_pci_complete_rq,
17331735
.commit_rqs = nvme_commit_rqs,
17341736
.init_hctx = nvme_init_hctx,
1735-
.init_request = nvme_init_request,
1737+
.init_request = nvme_pci_init_request,
17361738
.map_queues = nvme_pci_map_queues,
17371739
.timeout = nvme_timeout,
17381740
.poll = nvme_poll,
@@ -2475,9 +2477,10 @@ static int nvme_delete_queue(struct nvme_queue *nvmeq, u8 opcode)
24752477
cmd.delete_queue.opcode = opcode;
24762478
cmd.delete_queue.qid = cpu_to_le16(nvmeq->qid);
24772479

2478-
req = nvme_alloc_request(q, &cmd, BLK_MQ_REQ_NOWAIT);
2480+
req = blk_mq_alloc_request(q, nvme_req_op(&cmd), BLK_MQ_REQ_NOWAIT);
24792481
if (IS_ERR(req))
24802482
return PTR_ERR(req);
2483+
nvme_init_request(req, &cmd);
24812484

24822485
req->end_io_data = nvmeq;
24832486

drivers/nvme/host/tcp.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,44 @@ static int so_priority;
3030
module_param(so_priority, int, 0644);
3131
MODULE_PARM_DESC(so_priority, "nvme tcp socket optimize priority");
3232

33+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
34+
/* lockdep can detect a circular dependency of the form
35+
* sk_lock -> mmap_lock (page fault) -> fs locks -> sk_lock
36+
* because dependencies are tracked for both nvme-tcp and user contexts. Using
37+
* a separate class prevents lockdep from conflating nvme-tcp socket use with
38+
* user-space socket API use.
39+
*/
40+
static struct lock_class_key nvme_tcp_sk_key[2];
41+
static struct lock_class_key nvme_tcp_slock_key[2];
42+
43+
static void nvme_tcp_reclassify_socket(struct socket *sock)
44+
{
45+
struct sock *sk = sock->sk;
46+
47+
if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
48+
return;
49+
50+
switch (sk->sk_family) {
51+
case AF_INET:
52+
sock_lock_init_class_and_name(sk, "slock-AF_INET-NVME",
53+
&nvme_tcp_slock_key[0],
54+
"sk_lock-AF_INET-NVME",
55+
&nvme_tcp_sk_key[0]);
56+
break;
57+
case AF_INET6:
58+
sock_lock_init_class_and_name(sk, "slock-AF_INET6-NVME",
59+
&nvme_tcp_slock_key[1],
60+
"sk_lock-AF_INET6-NVME",
61+
&nvme_tcp_sk_key[1]);
62+
break;
63+
default:
64+
WARN_ON_ONCE(1);
65+
}
66+
}
67+
#else
68+
static void nvme_tcp_reclassify_socket(struct socket *sock) { }
69+
#endif
70+
3371
enum nvme_tcp_send_state {
3472
NVME_TCP_SEND_CMD_PDU = 0,
3573
NVME_TCP_SEND_H2C_PDU,
@@ -1427,6 +1465,8 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
14271465
goto err_destroy_mutex;
14281466
}
14291467

1468+
nvme_tcp_reclassify_socket(queue->sock);
1469+
14301470
/* Single syn retry */
14311471
tcp_sock_set_syncnt(queue->sock->sk, 1);
14321472

@@ -1674,7 +1714,7 @@ static void nvme_tcp_stop_io_queues(struct nvme_ctrl *ctrl)
16741714

16751715
static int nvme_tcp_start_io_queues(struct nvme_ctrl *ctrl)
16761716
{
1677-
int i, ret = 0;
1717+
int i, ret;
16781718

16791719
for (i = 1; i < ctrl->queue_count; i++) {
16801720
ret = nvme_tcp_start_queue(ctrl, i);
@@ -1714,8 +1754,7 @@ static int __nvme_tcp_alloc_io_queues(struct nvme_ctrl *ctrl)
17141754
int i, ret;
17151755

17161756
for (i = 1; i < ctrl->queue_count; i++) {
1717-
ret = nvme_tcp_alloc_queue(ctrl, i,
1718-
ctrl->sqsize + 1);
1757+
ret = nvme_tcp_alloc_queue(ctrl, i, ctrl->sqsize + 1);
17191758
if (ret)
17201759
goto out_free_queues;
17211760
}

0 commit comments

Comments
 (0)