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

Christoph Hellwig hch at lst.de
Tue Jan 12 13:39:11 EST 2021


> @@ -1546,6 +1546,11 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
>  	meta_len = (io.nblocks + 1) * ns->ms;
>  	metadata = nvme_to_user_ptr(io.metadata);
> 
> +	if (io.control & NVME_RW_PRINFO_PRACT && ns->ms == 8) {
> +		meta_len = 0;
> +		metadata = NULL;
> +	}
> +

Wouldn't something like:

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

make a little more sense?



More information about the Linux-nvme mailing list