From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Sasha Levin <sashal@kernel.org>,
Revanth Rajashekar <revanth.rajashekar@intel.com>,
Christoph Hellwig <hch@lst.de>,
linux-nvme@lists.infradead.org
Subject: [PATCH AUTOSEL 5.10 22/41] nvme: check the PRINFO bit before deciding the host buffer length
Date: Fri, 29 Jan 2021 10:36:53 -0500 [thread overview]
Message-ID: <20210129153713.1592185-22-sashal@kernel.org> (raw)
In-Reply-To: <20210129153713.1592185-1-sashal@kernel.org>
From: Revanth Rajashekar <revanth.rajashekar@intel.com>
[ Upstream commit 4d6b1c95b974761c01cbad92321b82232b66d2a2 ]
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.
Signed-off-by: Revanth Rajashekar <revanth.rajashekar@intel.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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 34cb59b2fcd67..4ec5f05dabe1d 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1489,8 +1489,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.27.0
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next parent reply other threads:[~2021-01-29 15:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20210129153713.1592185-1-sashal@kernel.org>
2021-01-29 15:36 ` Sasha Levin [this message]
2021-01-29 15:36 ` [PATCH AUTOSEL 5.10 23/41] nvme-rdma: avoid request double completion for concurrent nvme_rdma_timeout Sasha Levin
2021-01-29 15:36 ` [PATCH AUTOSEL 5.10 24/41] nvme-tcp: avoid request double completion for concurrent nvme_tcp_timeout Sasha Levin
2021-01-29 15:36 ` [PATCH AUTOSEL 5.10 25/41] nvme-pci: allow use of cmb on v1.4 controllers Sasha Levin
2021-01-29 15:36 ` [PATCH AUTOSEL 5.10 26/41] nvmet: set right status on error in id-ns handler Sasha Levin
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=20210129153713.1592185-22-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=revanth.rajashekar@intel.com \
--cc=stable@vger.kernel.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