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

Keith Busch kbusch at kernel.org
Mon Jan 11 11:47:29 EST 2021


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



More information about the Linux-nvme mailing list