NOT FOR MERGE nvmet code to exercise CCR/CQT
Subsystems (3)
cover NOT FOR MERGE nvmet code to exercise CCR/CQT
This code is not for check-in or as an RFC.
This post is just an FYI of code used on the target for a functional test for CCR/CQT for this presentation:
https://lore.kernel.org/linux-nvme/CAPpK+O03nHvHGESXsDDARz_kgbNkmeHmu-G3XWto7CqHtyVedQ@mail.gmail.com/
The code by Chris Leech comes from the NVMe Cancel implemetation posted here:
https://lore.kernel.org/linux-nvme/[email protected]/
Code built on:
v3 of the CCR+CQT patches as described here:
https://lore.kernel.org/linux-nvme/[email protected]/T
* 011e0880d366 - nvmet: report NPDGL and NPDAL (8 weeks ago) <Caleb Sander Mateos> (which was nvme-next a few weeks ago):
Chris Leech (3):
nvmet: put all nvmet_req.execute calls behind a function name
nvmet: add delay debugfs file to nvmet_ctrl
nvmet: delay requests
Mohamed Khalfella (4):
fixup: nvme fix CCR command
nvmet: Added debugfs fatal opcode
nvmet: kill nvme controller when fatal opcode is received Force CCR operation to fail
drivers/nvme/target/Kconfig | 19 ++++++++ drivers/nvme/target/admin-cmd.c | 11 ++--- drivers/nvme/target/core.c | 37 ++++++++++++++++ drivers/nvme/target/debugfs.c | 78 +++++++++++++++++++++++++++++++++ drivers/nvme/target/fc.c | 4 +- drivers/nvme/target/loop.c | 2 +- drivers/nvme/target/nvmet.h | 17 +++++++ drivers/nvme/target/rdma.c | 4 +- drivers/nvme/target/tcp.c | 4 +- include/linux/nvme.h | 4 +- 10 files changed, 166 insertions(+), 14 deletions(-)
Signature · 1 line
2.54.0
PATCH 1/7 fixup: nvme fix CCR command
From: Mohamed Khalfella <[email protected]>
--- include/linux/nvme.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/nvme.h +2 -2
@@ -1247,9 +1247,9 @@ struct nvme_cross_ctrl_reset_cmd {__le32 nsid;__le64 rsvd2[2 ];union nvme_data_ptr dptr; -__u8 rsvd10; -__u8 ciu;__le16 icid; +__u8 ciu; +__u8 rsvd10;__le32 cdw11;__le64 cirn;__le32 cdw14;
Signature · 1 line
2.54.0
PATCH 2/7 nvmet: put all nvmet_req.execute calls behind a function name
In reply to Randy JenningsFrom: Chris Leech <[email protected]>
This is setup for being able to manipluate the outstanding requests.
--- drivers/nvme/target/fc.c | 4 ++-- drivers/nvme/target/loop.c | 2 +- drivers/nvme/target/nvmet.h | 1 + drivers/nvme/target/rdma.c | 4 ++-- drivers/nvme/target/tcp.c | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-)
drivers/nvme/target/fc.c +2 -2
@@ -2391,7 +2391,7 @@ nvmet_fc_fod_op_done(struct nvmet_fc_fcp_iod *fod) }/* data transfer complete, resume with nvmet layer */ - fod->req.execute (&fod->req); +nvmet_execute_request (&fod->req);break ;case NVMET_FCOP_READDATA :
@@ -2600,7 +2600,7 @@ nvmet_fc_handle_fcp_rqst(struct nvmet_fc_tgtport *tgtport,* can invoke the nvmet_layer now. If read data, cmd completion will * push the data */ - fod->req.execute (&fod->req); +nvmet_execute_request (&fod->req);return ; transport_error:
drivers/nvme/target/loop.c +1 -1
@@ -127,7 +127,7 @@ static void nvme_loop_execute_work(struct work_struct *work)struct nvme_loop_iod *iod = container_of(work, struct nvme_loop_iod, work); - iod->req.execute (&iod->req); +nvmet_execute_request (&iod->req); } static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx,
drivers/nvme/target/nvmet.h +1 -0
@@ -994,4 +994,5 @@ struct nvmet_feat_arbitration { u8 ab; }; +static inline void nvmet_execute_request (struct nvmet_req *req) { req->execute (req); }#endif /* _NVMET_H */
drivers/nvme/target/rdma.c +2 -2
@@ -773,7 +773,7 @@ static void nvmet_rdma_read_data_done(struct ib_cq *cq, struct ib_wc *wc)if (unlikely (status))nvmet_req_complete (&rsp->req, status);else - rsp->req.execute (&rsp->req); +nvmet_execute_request (&rsp->req); }static void nvmet_rdma_write_data_done (struct ib_cq *cq,struct ib_wc *wc)
@@ -958,7 +958,7 @@ static bool nvmet_rdma_execute_command(struct nvmet_rdma_rsp *rsp) queue->cm_id->port_num, &rsp->read_cqe, NULL))nvmet_req_complete (&rsp->req,NVME_SC_DATA_XFER_ERROR ); }else { - rsp->req.execute (&rsp->req); +nvmet_execute_request (&rsp->req); }return true;
drivers/nvme/target/tcp.c +2 -2
@@ -606,7 +606,7 @@ static void nvmet_tcp_execute_request(struct nvmet_tcp_cmd *cmd)if (unlikely (cmd->flags &NVMET_TCP_F_INIT_FAILED ))nvmet_tcp_queue_response (&cmd->req);else - cmd->req.execute (&cmd->req); +nvmet_execute_request (&cmd->req); }static int nvmet_try_send_data_pdu (struct nvmet_tcp_cmd *cmd)
@@ -1072,7 +1072,7 @@ static int nvmet_tcp_done_recv_pdu(struct nvmet_tcp_queue *queue) goto out; } - queue->cmd->req.execute (&queue->cmd->req); +nvmet_execute_request (&queue->cmd->req); out:nvmet_prepare_receive_pdu (queue);return ret;
Signature · 1 line
2.54.0
PATCH 3/7 nvmet: add delay debugfs file to nvmet_ctrl
In reply to Randy JenningsFrom: Chris Leech <[email protected]>
Creates an delay attribute file on the controler in debugfs /sys/kernel/debug/nvmet/<subsystem>/ctrlN/delay
Reading this file returns two numbers, a reqeust delay count and a delay time in ms. Each delayed request will decrement the delay count until it reaches 0.
Writing to this file can set both the delay and count at once, or just the count to trigger more delays.
# delay the next 5 request by 5 seconds each echo 5 5000 > delay
# set the delay time to 3 seconds without starting a count echo 0 3000 > delay
# delay to the next 5 requests by the current delay time echo 5 > delay
--- drivers/nvme/target/Kconfig | 9 ++++++++ drivers/nvme/target/debugfs.c | 40 +++++++++++++++++++++++++++++++++++ drivers/nvme/target/nvmet.h | 4 ++++ 3 files changed, 53 insertions(+)
drivers/nvme/target/Kconfig +9 -0
@@ -127,3 +127,12 @@ config NVME_TARGET_PCI_EPF capable PCI controller. If unsure, say N. + +config NVME_TARGET_DELAY_REQUESTS + bool "NVMe over Fabrics target request delay" + depends on NVME_TARGET && NVME_TARGET_DEBUGFS + help + This is a testing feature to allow delaying request completion in an + NVMe over Fabrics target, which allows for support of the cancel command. + + If unsure, say N.
drivers/nvme/target/debugfs.c +40 -0
@@ -170,6 +170,42 @@ static int nvmet_ctrl_instance_cirn_show(struct seq_file *m, void *p) }NVMET_DEBUGFS_ATTR (nvmet_ctrl_instance_cirn); +#if IS_ENABLED (CONFIG_NVME_TARGET_DELAY_REQUESTS ) +static int nvmet_ctrl_delay_show (struct seq_file *m,void *p) +{ +struct nvmet_ctrl *ctrl = m->private; +int delay_count =atomic_read (&ctrl->delay_count); + +seq_printf (m,"%u %u\n" , delay_count, ctrl->delay_msec); +return 0 ; +} + +static ssize_t nvmet_ctrl_delay_write (struct file *file,const char __user *buf, +size_t count,loff_t *ppos) +{ +struct seq_file *m = file->private_data; +struct nvmet_ctrl *ctrl = m->private; +char delay_buf[22 ] = {}; +int delay_count; +int delay_msec; +int n; + +if (count >=sizeof (delay_buf)) +return -EINVAL ; +if (copy_from_user (delay_buf, buf, count)) +return -EFAULT ; + + n =sscanf (delay_buf,"%u %u" , &delay_count, &delay_msec); +if (n <1 || n >2 ) +return -EINVAL ; +if (n ==2 ) + ctrl->delay_msec = delay_msec; +atomic_set (&ctrl->delay_count, delay_count); +return count; +} +NVMET_DEBUGFS_RW_ATTR (nvmet_ctrl_delay); +#endif /* CONFIG_NVME_TARGET_DELAY_REQUESTS */ +int nvmet_debugfs_ctrl_setup (struct nvmet_ctrl *ctrl) {char name[32 ];
@@ -205,6 +241,10 @@ int nvmet_debugfs_ctrl_setup(struct nvmet_ctrl *ctrl) &nvmet_ctrl_instance_ciu_fops);debugfs_create_file ("cirn" ,S_IRUSR , ctrl->debugfs_dir, ctrl, &nvmet_ctrl_instance_cirn_fops); +#if IS_ENABLED (CONFIG_NVME_TARGET_DELAY_REQUESTS ) +debugfs_create_file ("delay" ,S_IWUSR , ctrl->debugfs_dir, ctrl, + &nvmet_ctrl_delay_fops); +#endif return 0 ; }
drivers/nvme/target/nvmet.h +4 -0
@@ -313,6 +313,10 @@ struct nvmet_ctrl {#endif #ifdef CONFIG_NVME_TARGET_TCP_TLS struct key *tls_key; +#endif +#ifdef CONFIG_NVME_TARGET_DELAY_REQUESTS +atomic_t delay_count; +u32 delay_msec;#endif struct nvmet_pr_log_mgr pr_log_mgr; };
Signature · 1 line
2.54.0
PATCH 4/7 nvmet: delay requests
In reply to Randy JenningsFrom: Chris Leech <[email protected]>
Allow requests to be delayed for testing.
--- drivers/nvme/target/core.c | 30 ++++++++++++++++++++++++++++++ drivers/nvme/target/nvmet.h | 8 ++++++++ 2 files changed, 38 insertions(+)
drivers/nvme/target/core.c +30 -0
@@ -6,7 +6,9 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/module.h> #include <linux/random.h> +#include <linux/jiffies.h> #include <linux/rculist.h> +#include <linux/workqueue.h> #include <linux/pci-p2pdma.h> #include <linux/scatterlist.h>
@@ -1891,6 +1893,34 @@ ssize_t nvmet_ctrl_host_traddr(struct nvmet_ctrl *ctrl,return ctrl->ops->host_traddr (ctrl, traddr, traddr_len); } +#if IS_ENABLED (CONFIG_NVME_TARGET_DELAY_REQUESTS ) +static void nvmet_delayed_execute_req (struct work_struct *work) { +struct nvmet_req *req = + container_of(to_delayed_work(work), struct nvmet_req, req_work); + req->execute (req); +} + +void nvmet_execute_request (struct nvmet_req *req) { +struct nvmet_ctrl *ctrl = req->sq->ctrl; +int delay_count; +u32 delay_msec; + +if (unlikely (req->sq->qid ==0 )) +return req->execute (req); + +if (ctrl) { + delay_count =atomic_dec_if_positive (&ctrl->delay_count) +1 ; + delay_msec = ctrl->delay_msec; + } +if (!(ctrl && delay_count && delay_msec)) +return req->execute (req); + +INIT_DELAYED_WORK (&req->req_work, nvmet_delayed_execute_req); +queue_delayed_work (nvmet_wq, &req->req_work,msecs_to_jiffies (delay_msec)); +} +EXPORT_SYMBOL_GPL (nvmet_execute_request); +#endif +static struct nvmet_subsys *nvmet_find_get_subsys (struct nvmet_port *port,const char *subsysnqn) {
drivers/nvme/target/nvmet.h +8 -0
@@ -511,6 +511,9 @@ struct nvmet_req {u16 error_loc;u64 error_slba;struct nvmet_pr_per_ctrl_ref *pc_ref; +#if IS_ENABLED (CONFIG_NVME_TARGET_DELAY_REQUESTS ) +struct delayed_work req_work; +#endif };#define NVMET_MAX_MPOOL_BVEC 16
@@ -998,5 +1001,10 @@ struct nvmet_feat_arbitration { u8 ab; }; +#if IS_ENABLED (CONFIG_NVME_TARGET_DELAY_REQUESTS ) +void nvmet_execute_request (struct nvmet_req *req); +#else static inline void nvmet_execute_request (struct nvmet_req *req) { req->execute (req); } +#endif +#endif /* _NVMET_H */
Signature · 1 line
2.54.0
PATCH 5/7 nvmet: Added debugfs fatal opcode
In reply to Randy JenningsFrom: Mohamed Khalfella <[email protected]>
--- drivers/nvme/target/Kconfig | 10 +++++++++ drivers/nvme/target/debugfs.c | 38 +++++++++++++++++++++++++++++++++++ drivers/nvme/target/nvmet.h | 4 ++++ 3 files changed, 52 insertions(+)
drivers/nvme/target/Kconfig +10 -0
@@ -136,3 +136,13 @@ config NVME_TARGET_DELAY_REQUESTS NVMe over Fabrics target, which allows for support of the cancel command. If unsure, say N. + +config NVME_TARGET_FATAL_OPCODE + bool "NVMe over Fabrics target fatal opcode" + depends on NVME_TARGET && NVME_TARGET_DEBUGFS + help + This is a testing feature to allow specifying an nvme opcode as fatal + opcode. When nvme controller receives fatal opcode it will execute + the request with specified delay and drop the connections to initiator. + + If unsure, say N.
drivers/nvme/target/debugfs.c +38 -0
@@ -206,6 +206,39 @@ static ssize_t nvmet_ctrl_delay_write(struct file *file, const char __user *buf,NVMET_DEBUGFS_RW_ATTR (nvmet_ctrl_delay);#endif /* CONFIG_NVME_TARGET_DELAY_REQUESTS */ +#if IS_ENABLED (CONFIG_NVME_TARGET_FATAL_OPCODE ) +static int nvmet_ctrl_fatal_opcode_show (struct seq_file *m,void *p) +{ +struct nvmet_ctrl *ctrl = m->private; + +seq_printf (m,"%02x %u\n" , ctrl->fopcode, ctrl->fopcode_delay_ms); +return 0 ; +} + +static ssize_t nvmet_ctrl_fatal_opcode_write (struct file *file,const char __user *buf, +size_t count,loff_t *ppos) +{ +struct seq_file *m = file->private_data; +struct nvmet_ctrl *ctrl = m->private; +char fopcode_buf[22 ] = {}; +int fopcode_delay_ms, n; +uint8_t fopcode; + +if (count >=sizeof (fopcode_buf)) +return -EINVAL ; +if (copy_from_user (fopcode_buf, buf, count)) +return -EFAULT ; + + n =sscanf (fopcode_buf,"%hhx %u" , &fopcode, &fopcode_delay_ms); +if (n !=2 ) +return -EINVAL ; + ctrl->fopcode = fopcode; + ctrl->fopcode_delay_ms = fopcode_delay_ms; +return count; +} +NVMET_DEBUGFS_RW_ATTR (nvmet_ctrl_fatal_opcode); +#endif /* CONFIG_NVME_TARGET_FATAL_OPCODE */ +int nvmet_debugfs_ctrl_setup (struct nvmet_ctrl *ctrl) {char name[32 ];
@@ -245,6 +278,11 @@ int nvmet_debugfs_ctrl_setup(struct nvmet_ctrl *ctrl)debugfs_create_file ("delay" ,S_IWUSR , ctrl->debugfs_dir, ctrl, &nvmet_ctrl_delay_fops);#endif + +#if IS_ENABLED (CONFIG_NVME_TARGET_FATAL_OPCODE ) +debugfs_create_file ("fopcode" ,S_IWUSR , ctrl->debugfs_dir, ctrl, + &nvmet_ctrl_fatal_opcode_fops); +#endif return 0 ; }
drivers/nvme/target/nvmet.h +4 -0
@@ -317,6 +317,10 @@ struct nvmet_ctrl {#ifdef CONFIG_NVME_TARGET_DELAY_REQUESTS atomic_t delay_count;u32 delay_msec; +#endif +#ifdef CONFIG_NVME_TARGET_FATAL_OPCODE +uint8_t fopcode; +u32 fopcode_delay_ms;#endif struct nvmet_pr_log_mgr pr_log_mgr; };
Signature · 1 line
2.54.0
PATCH 6/7 nvmet: kill nvme controller when fatal opcode is received
In reply to Randy JenningsFrom: Mohamed Khalfella <[email protected]>
--- drivers/nvme/target/core.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/nvme/target/core.c +7 -0
@@ -1909,12 +1909,19 @@ void nvmet_execute_request(struct nvmet_req *req) {return req->execute (req);if (ctrl) { +if (req->cmd->common.opcode == ctrl->fopcode) { + delay_msec = ctrl->fopcode_delay_ms; +nvmet_ctrl_fatal_error (ctrl); + goto delay; + } + delay_count =atomic_dec_if_positive (&ctrl->delay_count) +1 ; delay_msec = ctrl->delay_msec; }if (!(ctrl && delay_count && delay_msec))return req->execute (req); +delay:INIT_DELAYED_WORK (&req->req_work, nvmet_delayed_execute_req);queue_delayed_work (nvmet_wq, &req->req_work,msecs_to_jiffies (delay_msec)); }
Signature · 1 line
2.54.0
PATCH 7/7 Force CCR operation to fail
In reply to Randy JenningsFrom: Mohamed Khalfella <[email protected]>
--- drivers/nvme/target/admin-cmd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/nvme/target/admin-cmd.c +6 -5
@@ -626,13 +626,11 @@ static void nvmet_execute_get_log_page_ccr(struct nvmet_req *req)mutex_lock (&ctrl->lock);list_for_each_entry (ccr, &ctrl->ccr_list, entry) {u8 flags =NVME_CCR_FLAGS_VALIDATED |NVME_CCR_FLAGS_INITIATED ; -u8 status = ccr->ctrl ?NVME_CCR_STATUS_IN_PROGRESS : -NVME_CCR_STATUS_SUCCESS ; log->entries[index].icid =cpu_to_le16 (ccr->icid); log->entries[index].ciu = ccr->ciu; log->entries[index].acid =cpu_to_le16 (0xffff ); - log->entries[index].ccrs = status; + log->entries[index].ccrs =NVME_CCR_STATUS_FAILED ; log->entries[index].ccrf = flags; index++; }
@@ -1725,8 +1723,11 @@ void nvmet_execute_cross_ctrl_reset(struct nvmet_req *req) out_unlock:mutex_unlock (&sctrl->lock); -if (status ==NVME_SC_SUCCESS ) -nvmet_ctrl_fatal_error (ictrl); +if (status ==NVME_SC_SUCCESS ) { +nvmet_add_async_event (sctrl,NVME_AER_NOTICE , +NVME_AER_NOTICE_CCR_COMPLETED , +NVME_LOG_CCR ); + }nvmet_ctrl_put (ictrl); out:nvmet_req_complete (req, status);
Signature · 1 line
2.54.0
Sagi Grimberg
maintainerWas another round of this patch set submitted randy?
No. this was only to show what testing was reported for this presentation:
https://lore.kernel.org/linux-nvme/CAPpK+O03nHvHGESXsDDARz_kgbNkmeHmu-G3XWto7CqHtyVedQ@mail.gmail.com/
Quoted 2 lines · Sagi Grimberg
Was another round of this patch set submitted randy?