From: Naveen <naveen.n1@samsung.com>
To: qemu-devel@nongnu.org
Cc: fam@euphon.net, kwolf@redhat.com, anuj.singh@samsung.com,
jg123.choi@samsung.com, qemu-block@nongnu.org,
k.jensen@samsung.com, Naveen <naveen.n1@samsung.com>,
d.palani@samsung.com, mreitz@redhat.com, its@irrelevant.dk,
Minwoo Im <minwoo.im.dev@gmail.com>,
stefanha@redhat.com, kbusch@kernel.org, prakash.v@samsung.com,
raphel.david@samsung.com
Subject: hw/nvme: fix verification of select field in namespace attachment
Date: Mon, 23 Aug 2021 16:33:33 +0530 [thread overview]
Message-ID: <1629716613-26819-1-git-send-email-naveen.n1@samsung.com> (raw)
In-Reply-To: CGME20210823114601epcas5p17b488aeeae3dd41d32ab3df4fd235256@epcas5p1.samsung.com
Fix is added to check for reserved value in select field for
namespace attachment
Signed-off-by: Naveen Nagar <naveen.n1@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
cc: Minwoo Im <minwoo.im.dev@gmail.com>
---
hw/nvme/ctrl.c | 13 +++++++++----
include/block/nvme.h | 5 +++++
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 6baf9e0..2c59c74 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -5191,7 +5191,7 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
uint16_t list[NVME_CONTROLLER_LIST_SIZE] = {};
uint32_t nsid = le32_to_cpu(req->cmd.nsid);
uint32_t dw10 = le32_to_cpu(req->cmd.cdw10);
- bool attach = !(dw10 & 0xf);
+ uint8_t sel = dw10 & 0xf;
uint16_t *nr_ids = &list[0];
uint16_t *ids = &list[1];
uint16_t ret;
@@ -5224,7 +5224,8 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
return NVME_NS_CTRL_LIST_INVALID | NVME_DNR;
}
- if (attach) {
+ switch (sel) {
+ case NVME_NS_ATTACHMENT_ATTACH:
if (nvme_ns(ctrl, nsid)) {
return NVME_NS_ALREADY_ATTACHED | NVME_DNR;
}
@@ -5235,7 +5236,8 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
nvme_attach_ns(ctrl, ns);
nvme_select_iocs_ns(ctrl, ns);
- } else {
+ break;
+ case NVME_NS_ATTACHMENT_DETACH:
if (!nvme_ns(ctrl, nsid)) {
return NVME_NS_NOT_ATTACHED | NVME_DNR;
}
@@ -5244,8 +5246,11 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
ns->attached--;
nvme_update_dmrsl(ctrl);
+ break;
+ default:
+ return NVME_INVALID_FIELD | NVME_DNR;
}
-
+
/*
* Add namespace id to the changed namespace id list for event clearing
* via Get Log Page command.
diff --git a/include/block/nvme.h b/include/block/nvme.h
index 77aae01..e3bd47b 100644
--- a/include/block/nvme.h
+++ b/include/block/nvme.h
@@ -1154,6 +1154,11 @@ enum NvmeIdCtrlCmic {
NVME_CMIC_MULTI_CTRL = 1 << 1,
};
+enum NvmeNsAttachmentOperation {
+ NVME_NS_ATTACHMENT_ATTACH = 0x0,
+ NVME_NS_ATTACHMENT_DETACH = 0x1,
+};
+
#define NVME_CTRL_SQES_MIN(sqes) ((sqes) & 0xf)
#define NVME_CTRL_SQES_MAX(sqes) (((sqes) >> 4) & 0xf)
#define NVME_CTRL_CQES_MIN(cqes) ((cqes) & 0xf)
--
1.8.3.1
next parent reply other threads:[~2021-08-23 14:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20210823114601epcas5p17b488aeeae3dd41d32ab3df4fd235256@epcas5p1.samsung.com>
2021-08-23 11:03 ` Naveen [this message]
2021-08-24 6:31 ` hw/nvme: fix verification of select field in namespace attachment Klaus Jensen
2021-09-06 6:04 ` Klaus Jensen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1629716613-26819-1-git-send-email-naveen.n1@samsung.com \
--to=naveen.n1@samsung.com \
--cc=anuj.singh@samsung.com \
--cc=d.palani@samsung.com \
--cc=fam@euphon.net \
--cc=its@irrelevant.dk \
--cc=jg123.choi@samsung.com \
--cc=k.jensen@samsung.com \
--cc=kbusch@kernel.org \
--cc=kwolf@redhat.com \
--cc=minwoo.im.dev@gmail.com \
--cc=mreitz@redhat.com \
--cc=prakash.v@samsung.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=raphel.david@samsung.com \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).