Skip to contentSkip to conversation

nvme: Check the PRINFO bit and the Metadata size before deciding the host buffer length

PATCH Superseded Revanth Rajashekar 2 participants 2 messages Jan 11, 2021 NVMe

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: Check the PRINFO bit and the Metadata size before deciding the host buffer length

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.

---
 drivers/nvme/host/core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/nvme/host/core.c +8 -0
index 7a9642719..5efacd596 100644
@@ -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

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

maintainer
#1 lore raw
Quoted 1 line · Revanth Rajashekar

+#define NVME_PRINFO_CTRL_BIT (13)

This bit already defined as 'NVME_RW_PRINFO_PRACT'.

drivers/nvme/host/core.c static void __user *nvme_to_user_ptr(uintptr_t ptrval) · line 1283

Quoted 7 lines

static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio) {

drivers/nvme/host/core.c +1 -0
 	struct nvme_user_io io;
 	struct nvme_command c;
 	unsigned length, meta_len;
 	void __user *metadata;
+	unsigned long control;

You can remove this variable.

drivers/nvme/host/core.c static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio) · line 1302

Quoted 8 lines
drivers/nvme/host/core.c +1 -0
 	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);

You're checking the bit with the CPU arch's native endianness, so you shouldn't be byte swapping here for BE archs.

drivers/nvme/host/core.c static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio) · line 1304

Quoted 1 line
drivers/nvme/host/core.c +1 -0
+	if (test_bit(NVME_PRINFO_CTRL_BIT, &control) && ns->ms == 8) {

No need for the "test_bit()" here, you can just do:

	if (io.control & NVME_RW_PRINFO_PRACT && ms == 8)) 

drivers/nvme/host/core.c static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio) · line 1307

Quoted 3 lines
drivers/nvme/host/core.c +3 -0
+		meta_len = 0;
+		metadata = NULL;
+	}

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme