linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
Cc: "Nicholas A. Bellinger" <nab@daterainc.com>,
	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>,
	Al Viro <viro@ZenIV.linux.org.uk>, Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH-v3 5/9] vhost/scsi: Add ANY_LAYOUT vhost_virtqueue callback
Date: Wed, 4 Feb 2015 14:16:56 +0100	[thread overview]
Message-ID: <20150204131656.GD15443@redhat.com> (raw)
In-Reply-To: <1423047312.28700.51.camel@haakon3.risingtidesystems.com>

On Wed, Feb 04, 2015 at 02:55:12AM -0800, Nicholas A. Bellinger wrote:
> On Wed, 2015-02-04 at 02:41 -0800, Nicholas A. Bellinger wrote:
> > On Wed, 2015-02-04 at 10:42 +0100, Michael S. Tsirkin wrote:
> > > On Wed, Feb 04, 2015 at 01:40:25AM -0800, Nicholas A. Bellinger wrote:
> > > > > > +		/*
> > > > > > +		 * Any associated T10_PI bytes for the outgoing / incoming
> > > > > > +		 * payloads are included in calculation of exp_data_len here.
> > > > > > +		 */
> > > > > > +		if (out_size > req_size) {
> > > > > > +			data_direction = DMA_TO_DEVICE;
> > > > > > +			exp_data_len = out_size - req_size;
> > > > > > +		} else if (in_size > rsp_size) {
> > > > > > +			data_direction = DMA_FROM_DEVICE;
> > > > > > +			exp_data_len = in_size - rsp_size;
> > > > > > +		} else {
> > > > > > +			data_direction = DMA_NONE;
> > > > > > +			exp_data_len = 0;
> > > > > > +		}
> > > > > 
> > > > > We must validate this doesn't cause exp_data_len to be negative.
> > > > > 
> > > > 
> > > > AFAICT, exp_data_len is always >= 0 here.
> > > 
> > > What guarantees out_size > req_size and in_size > rsp_size,
> > > respectively?
> > > 
> > 
> > Mmm, point taken.
> > 
> > So moving this part after copy_from_iter() ensures that at least
> > req_size bytes exists of out_size.  Making this change now.
> > 
> > For in_size > rsp_size there is no guarantee, and falls back to
> > data_direction = DMA_NONE + exp_data_len = 0;
> > 
> > Is this what you had in mind..?
> > 
> 
> Something akin to:
> 
> diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
> index f72fc56..daf10b7 100644
> --- a/drivers/vhost/scsi.c
> +++ b/drivers/vhost/scsi.c
> @@ -1047,30 +1047,12 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
>  			target = &v_req.lun[1];
>  		}
>  		/*
> -		 * Determine data_direction by calculating the total outgoing
> -		 * iovec sizes / incoming iovec sizes vs. virtio-scsi request /
> -		 * response headers respectively.
> -		 *
>  		 * FIXME: Not correct for BIDI operation
>  		 */
>  		out_size = iov_length(vq->iov, out);
>  		in_size = iov_length(&vq->iov[out], in);
>  
>  		/*
> -		 * Any associated T10_PI bytes for the outgoing / incoming
> -		 * payloads are included in calculation of exp_data_len here.
> -		 */
> -		if (out_size > req_size) {
> -			data_direction = DMA_TO_DEVICE;
> -			exp_data_len = out_size - req_size;
> -		} else if (in_size > rsp_size) {
> -			data_direction = DMA_FROM_DEVICE;
> -			exp_data_len = in_size - rsp_size;
> -		} else {
> -			data_direction = DMA_NONE;
> -			exp_data_len = 0;
> -		}
> -		/*
>  		 * Copy over the virtio-scsi request header, which for a
>  		 * ANY_LAYOUT enabled guest may span multiple iovecs, or a
>  		 * single iovec may contain both the header + outgoing
> @@ -1102,8 +1084,9 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
>  			continue;
>  		}
>  		/*
> -		 * Determine start of T10_PI or data payload iovec based upon
> -		 * data_direction.
> +		 * Determine data_direction by calculating the total outgoing
> +		 * iovec sizes + incoming iovec sizes vs. virtio-scsi request +
> +		 * response headers respectively.
>  		 *
>  		 * For DMA_TO_DEVICE this is out_iter, which is already pointing
>  		 * to the right place.
> @@ -1111,16 +1094,27 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
>  		 * For DMA_FROM_DEVICE, the iovec will be just past the end
>  		 * of the virtio-scsi response header in either the same
>  		 * or immediately following iovec.
> +		 *
> +		 * Any associated T10_PI bytes for the outgoing / incoming
> +		 * payloads are included in calculation of exp_data_len here.
>  		 */
>  		prot_bytes = 0;
>  
> -		if (data_direction == DMA_TO_DEVICE) {
> +		if (out_size > req_size) {
> +			data_direction = DMA_TO_DEVICE;
> +			exp_data_len = out_size - req_size;
>  			data_iter = out_iter;
> -		} else if (data_direction == DMA_FROM_DEVICE) {
> +		} else if (in_size > rsp_size) {
> +			data_direction = DMA_FROM_DEVICE;
> +			exp_data_len = in_size - rsp_size;
> +
>  			iov_iter_init(&in_iter, READ, &vq->iov[out], in,
>  				      rsp_size + exp_data_len);
>  			iov_iter_advance(&in_iter, rsp_size);
>  			data_iter = in_iter;
> +		} else {
> +			data_direction = DMA_NONE;
> +			exp_data_len = 0;
>  		}
>  		/*
>  		 * If T10_PI header + payload is present, setup prot_iter values

Looks good to me.

  reply	other threads:[~2015-02-04 13:16 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-03  6:29 [PATCH-v3 0/9] vhost/scsi: Add ANY_LAYOUT + VERSION_1 support Nicholas A. Bellinger
2015-02-03  6:29 ` [PATCH-v3 1/9] vhost/scsi: Convert completion path to use copy_to_iser Nicholas A. Bellinger
2015-02-03  9:24   ` Michael S. Tsirkin
2015-02-04  8:47     ` Nicholas A. Bellinger
2015-02-03  6:29 ` [PATCH-v3 2/9] vhost/scsi: Fix incorrect early vhost_scsi_handle_vq failures Nicholas A. Bellinger
2015-02-03  6:29 ` [PATCH-v3 3/9] vhost/scsi: Change vhost_scsi_map_to_sgl to accept iov ptr + len Nicholas A. Bellinger
2015-02-03  6:29 ` [PATCH-v3 4/9] vhost/scsi: Add ANY_LAYOUT iov -> sgl mapping prerequisites Nicholas A. Bellinger
2015-02-03  9:32   ` Michael S. Tsirkin
2015-02-04  8:48     ` Nicholas A. Bellinger
2015-02-03  6:29 ` [PATCH-v3 5/9] vhost/scsi: Add ANY_LAYOUT vhost_virtqueue callback Nicholas A. Bellinger
2015-02-03 10:14   ` Michael S. Tsirkin
2015-02-04  9:40     ` Nicholas A. Bellinger
2015-02-04  9:42       ` Michael S. Tsirkin
2015-02-04 10:41         ` Nicholas A. Bellinger
2015-02-04 10:55           ` Nicholas A. Bellinger
2015-02-04 13:16             ` Michael S. Tsirkin [this message]
2015-02-04 13:13           ` Michael S. Tsirkin
2015-02-04 13:15           ` Michael S. Tsirkin
2015-02-03 15:22   ` Michael S. Tsirkin
2015-02-03 23:56   ` Al Viro
2015-02-04  7:14     ` Michael S. Tsirkin
2015-02-04 10:11     ` Nicholas A. Bellinger
2015-02-04 10:20       ` Michael S. Tsirkin
2015-02-04 10:41         ` Nicholas A. Bellinger
2015-02-03  6:30 ` [PATCH-v3 6/9] vhost/scsi: Set VIRTIO_F_ANY_LAYOUT + VIRTIO_F_VERSION_1 feature bits Nicholas A. Bellinger
2015-02-03  9:40   ` Michael S. Tsirkin
2015-02-04  9:13     ` Nicholas A. Bellinger
2015-02-04  9:34       ` Michael S. Tsirkin
2015-02-03  6:30 ` [PATCH-v3 7/9] vhost/scsi: Drop legacy pre virtio v1.0 !ANY_LAYOUT logic Nicholas A. Bellinger
2015-02-03  9:37   ` Michael S. Tsirkin
2015-02-04  9:03     ` Nicholas A. Bellinger
2015-02-03  6:30 ` [PATCH-v3 8/9] vhost/scsi: Drop left-over scsi_tcq.h include Nicholas A. Bellinger
2015-02-03  9:38   ` Michael S. Tsirkin
2015-02-03  6:30 ` [PATCH-v3 9/9] vhost/scsi: Global tcm_vhost -> vhost_scsi rename Nicholas A. Bellinger
2015-02-03  9:38   ` Michael S. Tsirkin
2015-02-03  9:35 ` [PATCH-v3 0/9] vhost/scsi: Add ANY_LAYOUT + VERSION_1 support Michael S. Tsirkin
2015-02-04  8:51   ` 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=20150204131656.GD15443@redhat.com \
    --to=mst@redhat.com \
    --cc=hch@lst.de \
    --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 \
    --cc=viro@ZenIV.linux.org.uk \
    /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).