[PATCH] nvme: Check the PRINFO bit and the Metadata size before deciding the host buffer length
Revanth Rajashekar
revanth.rajashekar at intel.com
Mon Jan 11 11:26:02 EST 2021
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 at intel.com>
---
drivers/nvme/host/core.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 7a9642719..5efacd596 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1273,12 +1273,14 @@ static void __user *nvme_to_user_ptr(uintptr_t ptrval)
return (void __user *)ptrval;
}
+#define NVME_PRINFO_CTRL_BIT (13)
static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
{
struct nvme_user_io io;
struct nvme_command c;
unsigned length, meta_len;
void __user *metadata;
+ unsigned long control;
if (copy_from_user(&io, uio, sizeof(io)))
return -EFAULT;
@@ -1297,6 +1299,12 @@ 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);
+ control = cpu_to_le16(io.control);
+
+ if (test_bit(NVME_PRINFO_CTRL_BIT, &control) && ns->ms == 8) {
+ meta_len = 0;
+ metadata = NULL;
+ }
if (ns->ext) {
length += meta_len;
--
2.17.1
More information about the Linux-nvme
mailing list