From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Nicholas A. Bellinger" <nab@daterainc.com>
Cc: target-devel <target-devel@vger.kernel.org>,
linux-scsi <linux-scsi@vger.kernel.org>,
kvm-devel <kvm@vger.kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Nicholas Bellinger <nab@linux-iscsi.org>
Subject: Re: [PATCH 4/8] vhost/scsi: Change vhost_scsi_map_to_sgl to accept iov ptr + len
Date: Fri, 30 Jan 2015 12:51:19 +0200 [thread overview]
Message-ID: <20150130105119.GA21531@redhat.com> (raw)
In-Reply-To: <1422605552-24797-5-git-send-email-nab@daterainc.com>
On Fri, Jan 30, 2015 at 08:12:28AM +0000, Nicholas A. Bellinger wrote:
> From: Nicholas Bellinger <nab@linux-iscsi.org>
>
> This patch changes vhost_scsi_map_to_sgl() parameters to accept virtio
> iovec ptr + len when determing pages_nr.
>
> This is currently done with iov_num_pages() -> PAGE_ALIGN, so allow
> the same parameters as well.
>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
> ---
> drivers/vhost/scsi.c | 37 +++++++++++++++----------------------
> 1 file changed, 15 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
> index 9c5ac23..049e603 100644
> --- a/drivers/vhost/scsi.c
> +++ b/drivers/vhost/scsi.c
> @@ -220,10 +220,10 @@ static struct workqueue_struct *tcm_vhost_workqueue;
> static DEFINE_MUTEX(tcm_vhost_mutex);
> static LIST_HEAD(tcm_vhost_list);
>
> -static int iov_num_pages(struct iovec *iov)
> +static int iov_num_pages(void __user *iov_base, size_t iov_len)
> {
> - return (PAGE_ALIGN((unsigned long)iov->iov_base + iov->iov_len) -
> - ((unsigned long)iov->iov_base & PAGE_MASK)) >> PAGE_SHIFT;
> + return (PAGE_ALIGN((unsigned long)iov_base + iov_len) -
> + ((unsigned long)iov_base & PAGE_MASK)) >> PAGE_SHIFT;
> }
>
> static void tcm_vhost_done_inflight(struct kref *kref)
> @@ -777,25 +777,18 @@ vhost_scsi_get_tag(struct vhost_virtqueue *vq, struct tcm_vhost_tpg *tpg,
> * Returns the number of scatterlist entries used or -errno on error.
> */
> static int
> -vhost_scsi_map_to_sgl(struct tcm_vhost_cmd *tv_cmd,
> +vhost_scsi_map_to_sgl(struct tcm_vhost_cmd *cmd,
> + void __user *ptr,
> + size_t len,
> struct scatterlist *sgl,
> - unsigned int sgl_count,
> - struct iovec *iov,
> - struct page **pages,
> bool write)
> {
> - unsigned int npages = 0, pages_nr, offset, nbytes;
> + unsigned int npages = 0, offset, nbytes;
> + unsigned int pages_nr = iov_num_pages(ptr, len);
> struct scatterlist *sg = sgl;
> - void __user *ptr = iov->iov_base;
> - size_t len = iov->iov_len;
> + struct page **pages = cmd->tvc_upages;
> int ret, i;
>
> - pages_nr = iov_num_pages(iov);
> - if (pages_nr > sgl_count) {
> - pr_err("vhost_scsi_map_to_sgl() pages_nr: %u greater than"
> - " sgl_count: %u\n", pages_nr, sgl_count);
> - return -ENOBUFS;
> - }
> if (pages_nr > TCM_VHOST_PREALLOC_UPAGES) {
> pr_err("vhost_scsi_map_to_sgl() pages_nr: %u greater than"
> " preallocated TCM_VHOST_PREALLOC_UPAGES: %u\n",
> @@ -840,7 +833,7 @@ vhost_scsi_map_iov_to_sgl(struct tcm_vhost_cmd *cmd,
> int ret, i;
>
> for (i = 0; i < niov; i++)
> - sgl_count += iov_num_pages(&iov[i]);
> + sgl_count += iov_num_pages(iov[i].iov_base, iov[i].iov_len);
>
A helper function for this loop seems in order as well?
> if (sgl_count > TCM_VHOST_PREALLOC_SGLS) {
> pr_err("vhost_scsi_map_iov_to_sgl() sgl_count: %u greater than"
> @@ -856,8 +849,8 @@ vhost_scsi_map_iov_to_sgl(struct tcm_vhost_cmd *cmd,
> pr_debug("Mapping iovec %p for %u pages\n", &iov[0], sgl_count);
>
> for (i = 0; i < niov; i++) {
> - ret = vhost_scsi_map_to_sgl(cmd, sg, sgl_count, &iov[i],
> - cmd->tvc_upages, write);
> + ret = vhost_scsi_map_to_sgl(cmd, iov[i].iov_base, iov[i].iov_len,
> + sg, write);
> if (ret < 0) {
> for (i = 0; i < cmd->tvc_sgl_count; i++) {
> struct page *page = sg_page(&cmd->tvc_sgl[i]);
> @@ -884,7 +877,7 @@ vhost_scsi_map_iov_to_prot(struct tcm_vhost_cmd *cmd,
> int ret, i;
>
> for (i = 0; i < niov; i++)
> - prot_sgl_count += iov_num_pages(&iov[i]);
> + prot_sgl_count += iov_num_pages(iov[i].iov_base, iov[i].iov_len);
>
> if (prot_sgl_count > TCM_VHOST_PREALLOC_PROT_SGLS) {
> pr_err("vhost_scsi_map_iov_to_prot() sgl_count: %u greater than"
> @@ -899,8 +892,8 @@ vhost_scsi_map_iov_to_prot(struct tcm_vhost_cmd *cmd,
> cmd->tvc_prot_sgl_count = prot_sgl_count;
>
> for (i = 0; i < niov; i++) {
> - ret = vhost_scsi_map_to_sgl(cmd, prot_sg, prot_sgl_count, &iov[i],
> - cmd->tvc_upages, write);
> + ret = vhost_scsi_map_to_sgl(cmd, iov[i].iov_base, iov[i].iov_len,
> + prot_sg, write);
> if (ret < 0) {
> for (i = 0; i < cmd->tvc_prot_sgl_count; i++) {
> struct page *page = sg_page(&cmd->tvc_prot_sgl[i]);
> --
> 1.9.1
next prev parent reply other threads:[~2015-01-30 10:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-30 8:12 [PATCH 0/8] vhost/scsi: Add ANY_LAYOUT support Nicholas A. Bellinger
2015-01-30 8:12 ` [PATCH 1/8] lib/iovec: Add memcpy_fromiovec_out library function Nicholas A. Bellinger
2015-01-30 9:33 ` Paolo Bonzini
2015-02-01 7:15 ` Nicholas A. Bellinger
2015-01-30 8:12 ` [PATCH 2/8] vhost/scsi: Convert completion path to use memcpy_toiovecend Nicholas A. Bellinger
2015-01-30 8:12 ` [PATCH 3/8] vhost/scsi: Fix incorrect early vhost_scsi_handle_vq failures Nicholas A. Bellinger
2015-01-30 8:12 ` [PATCH 4/8] vhost/scsi: Change vhost_scsi_map_to_sgl to accept iov ptr + len Nicholas A. Bellinger
2015-01-30 10:51 ` Michael S. Tsirkin [this message]
2015-02-01 7:24 ` Nicholas A. Bellinger
2015-01-30 8:12 ` [PATCH 5/8] vhost/scsi: Add common vhost_scsi_queue_desc code Nicholas A. Bellinger
2015-01-30 8:12 ` [PATCH 6/8] vhost/scsi: Add ANY_LAYOUT prerequisites Nicholas A. Bellinger
2015-01-30 8:12 ` [PATCH 7/8] vhost/scsi: Add ANY_LAYOUT support Nicholas A. Bellinger
2015-01-30 8:12 ` [PATCH 8/8] vhost/scsi: Set VIRTIO_F_ANY_LAYOUT + VIRTIO_F_VERSION_1 feature bits Nicholas A. Bellinger
2015-02-02 8:15 ` [PATCH 0/8] vhost/scsi: Add ANY_LAYOUT support Christoph Hellwig
2015-02-03 0:22 ` Nicholas A. Bellinger
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=20150130105119.GA21531@redhat.com \
--to=mst@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=nab@daterainc.com \
--cc=nab@linux-iscsi.org \
--cc=pbonzini@redhat.com \
--cc=target-devel@vger.kernel.org \
/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 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.