linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: keith.busch@intel.com (Busch, Keith)
Subject: [PATCH 12/18] nvme: use the block layer for userspace passthrough metadata
Date: Fri, 16 Oct 2015 20:04:19 +0000	[thread overview]
Message-ID: <20151016200418.GA27553@localhost.localdomain> (raw)
In-Reply-To: <1444975128-8768-13-git-send-email-hch@lst.de>

On Fri, Oct 16, 2015@07:58:42AM +0200, Christoph Hellwig wrote:
> Use the integrity API to pass through metadata from userspace.  For PI
> enabled devices this means that we now validate the reftag, which seems
> like an unintentional ommission in the old code.

More trouble. The below works for IO but not admin. There is no
"namespace" associated with the queue's queuedata, so there's no way to
send passthrough commands to the admin queue with metadata. I don't think
anyone cares as there is no admin command that carries such a payload.

Since the admin queuedata is NULL, we can just check for NULL before
proceeding with metadata setup, but need to be aware of this if the
admin queue ever does define queuedata.

My fault for not regression testing before posting the previous fix. The
diff to correct this new issue is at the end of this email.

> @@ -101,19 +105,77 @@ int nvme_submit_user_cmd(struct request_queue *q, struct nvme_command *cmd,
>  		if (ret)
>  			goto out;
>  		bio = req->bio;
> +		bio->bi_bdev = bdget_disk(ns->disk, 0);
> +		if (!bio->bi_bdev) {
> +			ret = -ENODEV;
> +			goto out_unmap;
> +		}
> +
> +		if (meta_buffer) {
> +			struct bio_integrity_payload *bip;
> +
> +			meta = kmalloc(meta_len, GFP_KERNEL);
> +			if (!meta) {
> +				ret = -ENOMEM;
> +				goto out_unmap;
> +			}
> +
> +			if (write) {
> +				if (copy_from_user(meta, meta_buffer,
> +						meta_len)) {
> +					ret = -EFAULT;
> +					goto out_free_meta;
> +				}
> +			}
> +
> +			bip = bio_integrity_alloc(bio, GFP_KERNEL, 1);
> +			if (!bip) {
> +				ret = -ENOMEM;
> +				goto out_free_meta;
> +			}
> +
> +			bip->bip_iter.bi_size = meta_len;
> +			bip->bip_iter.bi_sector = meta_seed;
> +
> +			ret = bio_integrity_add_page(bio, virt_to_page(meta),
> +					meta_len, offset_in_page(meta));
> +			if (ret != meta_len) {
> +				ret = -ENOMEM;
> +				goto out_free_meta;
> +			}
> +		}
>  	}
>  
> -	blk_execute_rq(req->q, NULL, req, 0);
> -	if (bio)
> -		blk_rq_unmap_user(bio);
> +	blk_execute_rq(req->q, ns->disk, req, 0);
> +	ret = req->errors;
>  	if (result)
>  		*result = (u32)(uintptr_t)req->special;
> -	ret = req->errors;
> +	if (meta && !ret && !write) {
> +		if (copy_to_user(meta_buffer, meta, meta_len))
> +			ret = -EFAULT;
> +	}
> +
> + out_free_meta:
> +	kfree(meta);
> + out_unmap:
> +	if (bio) {
> +		if (bio->bi_bdev)
> +			bdput(bio->bi_bdev);
> +		blk_rq_unmap_user(bio);
> +	}
>   out:
>  	blk_mq_free_request(req);
>  	return ret;
>  }

---
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index b8c72d2..c8f9a71 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -156,6 +156,10 @@ int __nvme_submit_user_cmd(struct request_queue *q, struct nvme_command *cmd,
 		if (ret)
 			goto out;
 		bio = req->bio;
+
+		if (!ns)
+			goto submit;
+
 		bio->bi_bdev = bdget_disk(ns->disk, 0);
 		if (!bio->bi_bdev) {
 			ret = -ENODEV;
@@ -196,8 +200,8 @@ int __nvme_submit_user_cmd(struct request_queue *q, struct nvme_command *cmd,
 			}
 		}
 	}
-
-	blk_execute_rq(req->q, ns->disk, req, 0);
+ submit:
+	blk_execute_rq(req->q, ns ? ns->disk : NULL, req, 0);
 	ret = req->errors;
 	if (result)
 		*result = (u32)(uintptr_t)req->special;
--

  reply	other threads:[~2015-10-16 20:04 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-16  5:58 nvme driver split V2 Christoph Hellwig
2015-10-16  5:58 ` [PATCH 01/18] nvme: add missing unmaps in nvme_queue_rq Christoph Hellwig
2015-10-20 10:04   ` Sagi Grimberg
2015-10-20 14:07     ` Busch, Keith
2015-10-16  5:58 ` [PATCH 02/18] nvme: move struct nvme_iod to pci.c Christoph Hellwig
2015-10-20 10:04   ` Sagi Grimberg
2015-10-16  5:58 ` [PATCH 03/18] nvme: split command submission helpers out of pci.c Christoph Hellwig
2015-10-20 10:07   ` Sagi Grimberg
2015-10-21 18:48   ` J Freyensee
2015-10-16  5:58 ` [PATCH 04/18] nvme: add a vendor field to struct nvme_dev Christoph Hellwig
2015-10-20 10:08   ` Sagi Grimberg
2015-10-21 18:58   ` J Freyensee
2015-10-21 19:10     ` Busch, Keith
2015-10-16  5:58 ` [PATCH 05/18] nvme: use offset instead of a struct for registers Christoph Hellwig
2015-10-16 17:30   ` Busch, Keith
2015-10-21 20:28   ` J Freyensee
2015-10-16  5:58 ` [PATCH 06/18] nvme: split a new struct nvme_ctrl out of struct nvme_dev Christoph Hellwig
2015-10-20 10:19   ` Sagi Grimberg
2015-10-20 10:26     ` Christoph Hellwig
2015-10-20 10:44       ` Sagi Grimberg
2015-10-20 11:30         ` Christoph Hellwig
2015-10-21 14:40           ` Sagi Grimberg
2015-10-21 21:23   ` J Freyensee
2015-10-21 22:51     ` Busch, Keith
2015-10-22  0:15       ` J Freyensee
2015-10-22  7:37     ` Christoph Hellwig
2015-10-16  5:58 ` [PATCH 07/18] nvme: simplify nvme_setup_prps calling convention Christoph Hellwig
2015-10-20 10:30   ` Sagi Grimberg
2015-10-16  5:58 ` [PATCH 08/18] nvme: refactor nvme_queue_rq Christoph Hellwig
2015-10-16  5:58 ` [PATCH 09/18] nvme: move nvme_error_status to common code Christoph Hellwig
2015-10-20 10:54   ` Sagi Grimberg
2015-10-16  5:58 ` [PATCH 10/18] nvme: move nvme_setup_flush and nvme_setup_rw " Christoph Hellwig
2015-10-20 11:01   ` Sagi Grimberg
2015-10-21  6:55     ` Christoph Hellwig
2015-10-21 14:41       ` Sagi Grimberg
2015-10-16  5:58 ` [PATCH 11/18] nvme: split __nvme_submit_sync_cmd Christoph Hellwig
2015-10-16  5:58 ` [PATCH 12/18] nvme: use the block layer for userspace passthrough metadata Christoph Hellwig
2015-10-16 20:04   ` Busch, Keith [this message]
2015-10-18 18:22     ` Christoph Hellwig
2015-10-16  5:58 ` [PATCH 13/18] nvme: move block_device_operations and ns/ctrl freeing to common code Christoph Hellwig
2015-10-16  5:58 ` [PATCH 14/18] nvme: add explicit quirk handling Christoph Hellwig
2015-10-16  5:58 ` [PATCH 15/18] nvme: add a common helper to read Identify Controller data Christoph Hellwig
2015-10-21 22:44   ` J Freyensee
2015-10-22  7:38     ` Christoph Hellwig
2015-10-16  5:58 ` [PATCH 16/18] nvme: move the call to nvme_init_identify earlier Christoph Hellwig
2015-10-16  5:58 ` [PATCH 17/18] nvme: move namespace scanning to common code Christoph Hellwig
2015-10-16  6:14   ` Ming Lin
2015-10-16  6:16     ` Christoph Hellwig
2015-10-21 23:27   ` J Freyensee
2015-10-22  7:39     ` Christoph Hellwig
2015-10-22 13:48       ` Busch, Keith
2015-10-22 16:30         ` Christoph Hellwig
2015-10-22 21:24           ` Busch, Keith
2015-10-23  5:41             ` Christoph Hellwig
2015-10-16  5:58 ` [PATCH 18/18] nvme: move chardev and sysfs interface " Christoph Hellwig
2015-10-22  0:11   ` J Freyensee
2015-10-22  7:45     ` Christoph Hellwig
2015-10-22 18:36       ` J Freyensee
2015-10-22 18:59         ` Jon Derrick

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151016200418.GA27553@localhost.localdomain \
    --to=keith.busch@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).