linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] nvme: fix miss command type check
  2023-05-26 11:04 ` [PATCH] nvme: fix miss command type check min15.li
@ 2023-05-26  7:57   ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2023-05-26  7:57 UTC (permalink / raw)
  To: min15.li; +Cc: kbusch, axboe, hch, sagi, linux-nvme, linux-kernel

> +	if (!ns) {

Instead of all the extra indentation just return early here if ns
is set.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] nvme: fix miss command type check
       [not found] <CGME20230526030614epcas5p4ca2cac6dc85dd8609b62e5802c06fb40@epcas5p4.samsung.com>
@ 2023-05-26 11:04 ` min15.li
  2023-05-26  7:57   ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: min15.li @ 2023-05-26 11:04 UTC (permalink / raw)
  To: kbusch, axboe, hch, sagi; +Cc: linux-nvme, linux-kernel, min15.li

In the function nvme_passthru_end(),only the value of the command opcode is
checked, without checking the command type (IO command or Admin command).
When we send a Dataset Management command (The opcode of the Dataset
Management command is the same as the Set Feature command),kernel
thinks it is a set feature command, then sets the controller's keep
 alive interval, and calls nvme_keep_alive_work().

Signed-off-by: min15.li <min15.li@samsung.com>
---
 drivers/nvme/host/core.c       | 33 +++++++++++++++++----------------
 drivers/nvme/host/ioctl.c      |  2 +-
 drivers/nvme/host/nvme.h       |  2 +-
 drivers/nvme/target/passthru.c |  2 +-
 4 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 1f0cbb77b249..fc2ad8584110 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1115,7 +1115,7 @@ u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode)
 }
 EXPORT_SYMBOL_NS_GPL(nvme_passthru_start, NVME_TARGET_PASSTHRU);
 
-void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects,
+void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 effects,
 		       struct nvme_command *cmd, int status)
 {
 	if (effects & NVME_CMD_EFFECTS_CSE_MASK) {
@@ -1132,25 +1132,26 @@ void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects,
 		nvme_queue_scan(ctrl);
 		flush_work(&ctrl->scan_work);
 	}
-
-	switch (cmd->common.opcode) {
-	case nvme_admin_set_features:
-		switch (le32_to_cpu(cmd->common.cdw10) & 0xFF) {
-		case NVME_FEAT_KATO:
-			/*
-			 * Keep alive commands interval on the host should be
-			 * updated when KATO is modified by Set Features
-			 * commands.
-			 */
-			if (!status)
-				nvme_update_keep_alive(ctrl, cmd);
+	if (!ns) {
+		switch (cmd->common.opcode) {
+		case nvme_admin_set_features:
+			switch (le32_to_cpu(cmd->common.cdw10) & 0xFF) {
+			case NVME_FEAT_KATO:
+				/*
+				 * Keep alive commands interval on the host should be
+				 * updated when KATO is modified by Set Features
+				 * commands.
+				 */
+				if (!status)
+					nvme_update_keep_alive(ctrl, cmd);
+				break;
+			default:
+				break;
+			}
 			break;
 		default:
 			break;
 		}
-		break;
-	default:
-		break;
 	}
 }
 EXPORT_SYMBOL_NS_GPL(nvme_passthru_end, NVME_TARGET_PASSTHRU);
diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
index 81c5c9e38477..f15e7330b75a 100644
--- a/drivers/nvme/host/ioctl.c
+++ b/drivers/nvme/host/ioctl.c
@@ -254,7 +254,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
 	blk_mq_free_request(req);
 
 	if (effects)
-		nvme_passthru_end(ctrl, effects, cmd, ret);
+		nvme_passthru_end(ctrl, ns, effects, cmd, ret);
 
 	return ret;
 }
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index a2d4f59e0535..2dd52739236e 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -1077,7 +1077,7 @@ u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 			 u8 opcode);
 u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode);
 int nvme_execute_rq(struct request *rq, bool at_head);
-void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects,
+void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 effects,
 		       struct nvme_command *cmd, int status);
 struct nvme_ctrl *nvme_ctrl_from_file(struct file *file);
 struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid);
diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c
index 511c980d538d..71a9c1cc57f5 100644
--- a/drivers/nvme/target/passthru.c
+++ b/drivers/nvme/target/passthru.c
@@ -243,7 +243,7 @@ static void nvmet_passthru_execute_cmd_work(struct work_struct *w)
 	blk_mq_free_request(rq);
 
 	if (effects)
-		nvme_passthru_end(ctrl, effects, req->cmd, status);
+		nvme_passthru_end(ctrl, ns, effects, req->cmd, status);
 }
 
 static enum rq_end_io_ret nvmet_passthru_req_done(struct request *rq,
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-26  7:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20230526030614epcas5p4ca2cac6dc85dd8609b62e5802c06fb40@epcas5p4.samsung.com>
2023-05-26 11:04 ` [PATCH] nvme: fix miss command type check min15.li
2023-05-26  7:57   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).