From: Revanth Rajashekar <revanth.rajashekar@intel.com>
To: <linux-nvme@lists.infradead.org>
Cc: Keith Busch <kbusch@kernel.org>,
Revanth Rajashekar <revanth.rajashekar@intel.com>,
hch@lst.de, Jonathan Derrick <jonathan.derrick@intel.com>
Subject: [PATCH v3] nvme: Check the PRINFO bit and the Metadata size before deciding the host buffer length
Date: Thu, 14 Jan 2021 18:55:07 -0700 [thread overview]
Message-ID: <20210115015507.45615-1-revanth.rajashekar@intel.com> (raw)
According to NVMe spec v1.4, section 8.3.1, the PRINFO bit and
the metadata size play a vital role in deteriming the host buffer size.
If PRIFNO bit is set and MS==8, the host doesn't add the metadata buffer,
instead the controller adds it.
Changes from v2:
1. Use sizeof(struct t10_pi_tuple) to check against MS.
2. Use if-else statements to set the meta_len and metadata
Changes from v1:
1. Remove the definition 'NVME_PRINFO_CTRL_BIT'
2. Remove variable 'control'
3. Remove test_bit and check the bit with the CPU arch's native endianness
Signed-off-by: Revanth Rajashekar <revanth.rajashekar@intel.com>
---
drivers/nvme/host/core.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f320273fc672..ec9f8f686460 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1543,8 +1543,21 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
}
length = (io.nblocks + 1) << ns->lba_shift;
- meta_len = (io.nblocks + 1) * ns->ms;
- metadata = nvme_to_user_ptr(io.metadata);
+
+ if ((io.control & NVME_RW_PRINFO_PRACT) &&
+ ns->ms == sizeof(struct t10_pi_tuple)) {
+ /*
+ * Protection information is stripped/inserted by the
+ * controller.
+ */
+ if (nvme_to_user_ptr(io.metadata))
+ return -EINVAL;
+ meta_len = 0;
+ metadata = NULL;
+ } else {
+ meta_len = (io.nblocks + 1) * ns->ms;
+ metadata = nvme_to_user_ptr(io.metadata);
+ }
if (ns->features & NVME_NS_EXT_LBAS) {
length += meta_len;
--
2.17.1
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next reply other threads:[~2021-01-15 2:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-15 1:55 Revanth Rajashekar [this message]
2021-01-18 17:59 ` [PATCH v3] nvme: Check the PRINFO bit and the Metadata size before deciding the host buffer length Christoph Hellwig
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=20210115015507.45615-1-revanth.rajashekar@intel.com \
--to=revanth.rajashekar@intel.com \
--cc=hch@lst.de \
--cc=jonathan.derrick@intel.com \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
/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