All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme: Check the PRINFO bit and the Metadata size before deciding the host buffer length
@ 2021-01-11 16:26 Revanth Rajashekar
  2021-01-11 16:47 ` Keith Busch
  0 siblings, 1 reply; 2+ messages in thread
From: Revanth Rajashekar @ 2021-01-11 16:26 UTC (permalink / raw)
  To: linux-nvme; +Cc: Keith Busch, Revanth Rajashekar, hch, Jonathan Derrick

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>
---
 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


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] nvme: Check the PRINFO bit and the Metadata size before deciding the host buffer length
  2021-01-11 16:26 [PATCH] nvme: Check the PRINFO bit and the Metadata size before deciding the host buffer length Revanth Rajashekar
@ 2021-01-11 16:47 ` Keith Busch
  0 siblings, 0 replies; 2+ messages in thread
From: Keith Busch @ 2021-01-11 16:47 UTC (permalink / raw)
  To: Revanth Rajashekar; +Cc: Jonathan Derrick, hch, linux-nvme

On Mon, Jan 11, 2021 at 09:26:02AM -0700, Revanth Rajashekar wrote:
> +#define NVME_PRINFO_CTRL_BIT (13)

This bit already defined as 'NVME_RW_PRINFO_PRACT'.

>  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;

You can remove this variable.

> 
>  	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.

> +	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)) 

> +		meta_len = 0;
> +		metadata = NULL;
> +	}

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-11 16:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11 16:26 [PATCH] nvme: Check the PRINFO bit and the Metadata size before deciding the host buffer length Revanth Rajashekar
2021-01-11 16:47 ` Keith Busch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.