All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Tiwei Bie <tiwei.bie@intel.com>
Cc: virtio-dev@lists.oasis-open.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org, wexu@redhat.com
Subject: Re: [PATCH net-next v2 2/5] virtio_ring: support creating packed ring
Date: Wed, 12 Sep 2018 12:12:48 -0400	[thread overview]
Message-ID: <20180912120900-mutt-send-email-mst__17656.0535481714$1536768652$gmane$org@kernel.org> (raw)
In-Reply-To: <20180912075140.GA22545@debian>

On Wed, Sep 12, 2018 at 03:51:40PM +0800, Tiwei Bie wrote:
> On Mon, Sep 10, 2018 at 10:28:37AM +0800, Tiwei Bie wrote:
> > On Fri, Sep 07, 2018 at 10:03:24AM -0400, Michael S. Tsirkin wrote:
> > > On Wed, Jul 11, 2018 at 10:27:08AM +0800, Tiwei Bie wrote:
> > > > This commit introduces the support for creating packed ring.
> > > > All split ring specific functions are added _split suffix.
> > > > Some necessary stubs for packed ring are also added.
> > > > 
> > > > Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
> > > 
> [...]
> > > > +
> > > > +/*
> > > > + * The layout for the packed ring is a continuous chunk of memory
> > > > + * which looks like this.
> > > > + *
> > > > + * struct vring_packed {
> > > > + *	// The actual descriptors (16 bytes each)
> > > > + *	struct vring_packed_desc desc[num];
> > > > + *
> > > > + *	// Padding to the next align boundary.
> > > > + *	char pad[];
> > > > + *
> > > > + *	// Driver Event Suppression
> > > > + *	struct vring_packed_desc_event driver;
> > > > + *
> > > > + *	// Device Event Suppression
> > > > + *	struct vring_packed_desc_event device;
> > > > + * };
> > > > + */
> > > 
> > > Why not just allocate event structures separately?
> > > Is it a win to have them share a cache line for some reason?
> 
> Users may call vring_new_virtqueue() with preallocated
> memory to setup the ring, e.g.:
> 
> https://github.com/torvalds/linux/blob/11da3a7f84f1/drivers/s390/virtio/virtio_ccw.c#L513-L522
> https://github.com/torvalds/linux/blob/11da3a7f84f1/drivers/misc/mic/vop/vop_main.c#L306-L307
> 
> Below is the corresponding definition in split ring:
> 
> https://github.com/oasis-tcs/virtio-spec/blob/89dd55f5e606/split-ring.tex#L64-L78
> 
> If my understanding is correct, this is just for legacy
> interfaces, and we won't define layout in packed ring
> and don't need to support vring_new_virtqueue() in packed
> ring. Is it correct? Thanks!

mic doesn't support 1.0 yet but ccw does.

It's probably best to look into converting ccw to
virtio_create_virtqueue, then you can just fail
vring_new_virtqueue for packed.

Cornelia, are there any gotchas to look out for?

> 
> 
> > 
> > Will do that.
> > 
> > > 
> > > > +static inline void vring_init_packed(struct vring_packed *vr, unsigned int num,
> > > > +				     void *p, unsigned long align)
> > > > +{
> > > > +	vr->num = num;
> > > > +	vr->desc = p;
> > > > +	vr->driver = (void *)ALIGN(((uintptr_t)p +
> > > > +		sizeof(struct vring_packed_desc) * num), align);
> > > > +	vr->device = vr->driver + 1;
> > > > +}
> > > 
> > > What's all this about alignment? Where does it come from?
> > 
> > It comes from the `vring_align` parameter of vring_create_virtqueue()
> > and vring_new_virtqueue():
> > 
> > https://github.com/torvalds/linux/blob/a49a9dcce802/drivers/virtio/virtio_ring.c#L1061
> > https://github.com/torvalds/linux/blob/a49a9dcce802/drivers/virtio/virtio_ring.c#L1123
> > 
> > Should I just ignore it in packed ring?
> > 
> > CCW defined this:
> > 
> > #define KVM_VIRTIO_CCW_RING_ALIGN 4096
> > 
> > I'm not familiar with CCW. Currently, in this patch set, packed ring
> > isn't enabled on CCW dues to some legacy accessors are not implemented
> > in packed ring yet.
> > 
> > > 
> > > > +
> > > > +static inline unsigned vring_size_packed(unsigned int num, unsigned long align)
> > > > +{
> > > > +	return ((sizeof(struct vring_packed_desc) * num + align - 1)
> > > > +		& ~(align - 1)) + sizeof(struct vring_packed_desc_event) * 2;
> > > > +}
> > [...]
> > > > @@ -1129,10 +1388,17 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
> > > >  				      void (*callback)(struct virtqueue *vq),
> > > >  				      const char *name)
> > > >  {
> > > > -	struct vring vring;
> > > > -	vring_init(&vring, num, pages, vring_align);
> > > > -	return __vring_new_virtqueue(index, vring, vdev, weak_barriers, context,
> > > > -				     notify, callback, name);
> > > > +	union vring_union vring;
> > > > +	bool packed;
> > > > +
> > > > +	packed = virtio_has_feature(vdev, VIRTIO_F_RING_PACKED);
> > > > +	if (packed)
> > > > +		vring_init_packed(&vring.vring_packed, num, pages, vring_align);
> > > > +	else
> > > > +		vring_init(&vring.vring_split, num, pages, vring_align);
> > > 
> > > 
> > > vring_init in the UAPI header is more or less a bug.
> > > I'd just stop using it, keep it around for legacy userspace.
> > 
> > Got it. I'd like to do that. Thanks.
> > 
> > > 
> > > > +
> > > > +	return __vring_new_virtqueue(index, vring, packed, vdev, weak_barriers,
> > > > +				     context, notify, callback, name);
> > > >  }
> > > >  EXPORT_SYMBOL_GPL(vring_new_virtqueue);
> > > >  
> > > > @@ -1142,7 +1408,9 @@ void vring_del_virtqueue(struct virtqueue *_vq)
> > > >  
> > > >  	if (vq->we_own_ring) {
> > > >  		vring_free_queue(vq->vq.vdev, vq->queue_size_in_bytes,
> > > > -				 vq->vring.desc, vq->queue_dma_addr);
> > > > +				 vq->packed ? (void *)vq->vring_packed.desc :
> > > > +					      (void *)vq->vring.desc,
> > > > +				 vq->queue_dma_addr);
> > > >  	}
> > > >  	list_del(&_vq->list);
> > > >  	kfree(vq);
> > > > @@ -1184,7 +1452,7 @@ unsigned int virtqueue_get_vring_size(struct virtqueue *_vq)
> > > >  
> > > >  	struct vring_virtqueue *vq = to_vvq(_vq);
> > > >  
> > > > -	return vq->vring.num;
> > > > +	return vq->packed ? vq->vring_packed.num : vq->vring.num;
> > > >  }
> > > >  EXPORT_SYMBOL_GPL(virtqueue_get_vring_size);
> > > >  
> > > > @@ -1227,6 +1495,10 @@ dma_addr_t virtqueue_get_avail_addr(struct virtqueue *_vq)
> > > >  
> > > >  	BUG_ON(!vq->we_own_ring);
> > > >  
> > > > +	if (vq->packed)
> > > > +		return vq->queue_dma_addr + ((char *)vq->vring_packed.driver -
> > > > +				(char *)vq->vring_packed.desc);
> > > > +
> > > >  	return vq->queue_dma_addr +
> > > >  		((char *)vq->vring.avail - (char *)vq->vring.desc);
> > > >  }
> > > > @@ -1238,11 +1510,16 @@ dma_addr_t virtqueue_get_used_addr(struct virtqueue *_vq)
> > > >  
> > > >  	BUG_ON(!vq->we_own_ring);
> > > >  
> > > > +	if (vq->packed)
> > > > +		return vq->queue_dma_addr + ((char *)vq->vring_packed.device -
> > > > +				(char *)vq->vring_packed.desc);
> > > > +
> > > >  	return vq->queue_dma_addr +
> > > >  		((char *)vq->vring.used - (char *)vq->vring.desc);
> > > >  }
> > > >  EXPORT_SYMBOL_GPL(virtqueue_get_used_addr);
> > > >  
> > > > +/* Only available for split ring */
> > > >  const struct vring *virtqueue_get_vring(struct virtqueue *vq)
> > > >  {
> > > >  	return &to_vvq(vq)->vring;
> > > > diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h
> > > > index fab02133a919..992142b35f55 100644
> > > > --- a/include/linux/virtio_ring.h
> > > > +++ b/include/linux/virtio_ring.h
> > > > @@ -60,6 +60,11 @@ static inline void virtio_store_mb(bool weak_barriers,
> > > >  struct virtio_device;
> > > >  struct virtqueue;
> > > >  
> > > > +union vring_union {
> > > > +	struct vring vring_split;
> > > > +	struct vring_packed vring_packed;
> > > > +};
> > > > +
> > > >  /*
> > > >   * Creates a virtqueue and allocates the descriptor ring.  If
> > > >   * may_reduce_num is set, then this may allocate a smaller ring than
> > > > @@ -79,7 +84,8 @@ struct virtqueue *vring_create_virtqueue(unsigned int index,
> > > >  
> > > >  /* Creates a virtqueue with a custom layout. */
> > > >  struct virtqueue *__vring_new_virtqueue(unsigned int index,
> > > > -					struct vring vring,
> > > > +					union vring_union vring,
> > > > +					bool packed,
> > > >  					struct virtio_device *vdev,
> > > >  					bool weak_barriers,
> > > >  					bool ctx,
> > > > -- 
> > > > 2.18.0

  reply	other threads:[~2018-09-12 16:12 UTC|newest]

Thread overview: 167+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-11  2:27 [PATCH net-next v2 0/5] virtio: support packed ring Tiwei Bie
2018-07-11  2:27 ` [virtio-dev] " Tiwei Bie
2018-07-11  2:27 ` Tiwei Bie
2018-07-11  2:27 ` [PATCH net-next v2 1/5] virtio: add packed ring definitions Tiwei Bie
2018-07-11  2:27   ` [virtio-dev] " Tiwei Bie
2018-09-07 13:51   ` Michael S. Tsirkin
2018-09-07 13:51     ` [virtio-dev] " Michael S. Tsirkin
2018-09-10  2:13     ` Tiwei Bie
2018-09-10  2:13       ` [virtio-dev] " Tiwei Bie
2018-09-12 12:53       ` Michael S. Tsirkin
2018-09-12 12:53       ` Michael S. Tsirkin
2018-09-12 12:53         ` [virtio-dev] " Michael S. Tsirkin
2018-09-10  2:13     ` Tiwei Bie
2018-09-07 13:51   ` Michael S. Tsirkin
2018-07-11  2:27 ` Tiwei Bie
2018-07-11  2:27 ` [PATCH net-next v2 2/5] virtio_ring: support creating packed ring Tiwei Bie
2018-07-11  2:27   ` [virtio-dev] " Tiwei Bie
2018-09-07 14:03   ` Michael S. Tsirkin
2018-09-07 14:03   ` Michael S. Tsirkin
2018-09-07 14:03     ` [virtio-dev] " Michael S. Tsirkin
2018-09-10  2:28     ` Tiwei Bie
2018-09-10  2:28       ` [virtio-dev] " Tiwei Bie
2018-09-12  7:51       ` Tiwei Bie
2018-09-12  7:51       ` Tiwei Bie
2018-09-12  7:51         ` [virtio-dev] " Tiwei Bie
2018-09-12 16:12         ` Michael S. Tsirkin [this message]
2018-09-12 16:12         ` Michael S. Tsirkin
2018-09-12 16:12           ` [virtio-dev] " Michael S. Tsirkin
2018-09-12 12:45       ` Michael S. Tsirkin
2018-09-12 12:45         ` [virtio-dev] " Michael S. Tsirkin
2018-09-12 12:45       ` Michael S. Tsirkin
2018-09-10  2:28     ` Tiwei Bie
2018-07-11  2:27 ` Tiwei Bie
2018-07-11  2:27 ` [PATCH net-next v2 3/5] virtio_ring: add packed ring support Tiwei Bie
2018-07-11  2:27   ` [virtio-dev] " Tiwei Bie
2018-09-07 13:49   ` Michael S. Tsirkin
2018-09-07 13:49   ` Michael S. Tsirkin
2018-09-07 13:49     ` [virtio-dev] " Michael S. Tsirkin
2018-09-10  2:03     ` Tiwei Bie
2018-09-10  2:03       ` [virtio-dev] " Tiwei Bie
2018-09-10  2:03       ` Tiwei Bie
2018-09-12 16:22   ` Michael S. Tsirkin
2018-09-12 16:22     ` [virtio-dev] " Michael S. Tsirkin
2018-09-12 16:22   ` Michael S. Tsirkin
2018-11-07 17:48   ` Michael S. Tsirkin
2018-11-07 17:48     ` [virtio-dev] " Michael S. Tsirkin
2018-11-08  1:38     ` Tiwei Bie
2018-11-08  1:38     ` Tiwei Bie
2018-11-08  1:38       ` [virtio-dev] " Tiwei Bie
2018-11-08  8:18       ` Jason Wang
2018-11-08  8:18       ` Jason Wang
2018-11-08  8:18         ` [virtio-dev] " Jason Wang
2018-11-08 11:51         ` Tiwei Bie
2018-11-08 11:51           ` [virtio-dev] " Tiwei Bie
2018-11-08 15:56           ` Michael S. Tsirkin
2018-11-08 15:56           ` Michael S. Tsirkin
2018-11-08 15:56             ` [virtio-dev] " Michael S. Tsirkin
2018-11-09  1:50             ` Tiwei Bie
2018-11-09  1:50             ` Tiwei Bie
2018-11-09  1:50               ` [virtio-dev] " Tiwei Bie
2018-11-09  2:30             ` Jason Wang
2018-11-09  2:30             ` Jason Wang
2018-11-09  2:30               ` [virtio-dev] " Jason Wang
2018-11-09  4:00               ` Michael S. Tsirkin
2018-11-09  4:00                 ` [virtio-dev] " Michael S. Tsirkin
2018-11-09 10:05                 ` Jason Wang
2018-11-09 10:05                   ` [virtio-dev] " Jason Wang
2018-11-09 10:05                 ` Jason Wang
2018-11-09  4:00               ` Michael S. Tsirkin
2018-11-08 11:51         ` Tiwei Bie
2018-11-08 14:14         ` Michael S. Tsirkin
2018-11-08 14:14         ` Michael S. Tsirkin
2018-11-08 14:14           ` [virtio-dev] " Michael S. Tsirkin
2018-11-09  2:25           ` Jason Wang
2018-11-09  2:25             ` [virtio-dev] " Jason Wang
2018-11-09  3:58             ` Michael S. Tsirkin
2018-11-09  3:58             ` Michael S. Tsirkin
2018-11-09  3:58               ` [virtio-dev] " Michael S. Tsirkin
2018-11-09 10:04               ` Jason Wang
2018-11-09 10:04                 ` [virtio-dev] " Jason Wang
2018-11-09 10:04                 ` Jason Wang
2018-11-09  2:25           ` Jason Wang
2018-11-07 17:48   ` Michael S. Tsirkin
2018-07-11  2:27 ` Tiwei Bie
2018-07-11  2:27 ` [PATCH net-next v2 4/5] virtio_ring: add event idx support in packed ring Tiwei Bie
2018-07-11  2:27   ` [virtio-dev] " Tiwei Bie
2018-09-07 14:10   ` Michael S. Tsirkin
2018-09-07 14:10   ` Michael S. Tsirkin
2018-09-07 14:10     ` [virtio-dev] " Michael S. Tsirkin
2018-09-10  2:35     ` Tiwei Bie
2018-09-10  2:35     ` Tiwei Bie
2018-09-10  2:35       ` Tiwei Bie
2018-09-10  2:35       ` Tiwei Bie
2018-07-11  2:27 ` Tiwei Bie
2018-07-11  2:27 ` [PATCH net-next v2 5/5] virtio_ring: enable " Tiwei Bie
2018-07-11  2:27 ` Tiwei Bie
2018-07-11  2:27   ` [virtio-dev] " Tiwei Bie
2018-07-11  2:52 ` [PATCH net-next v2 0/5] virtio: support " Jason Wang
2018-07-11  2:52 ` Jason Wang
2018-07-11  2:52   ` [virtio-dev] " Jason Wang
2018-07-12 21:44 ` David Miller
2018-07-12 21:44   ` David Miller
2018-07-13  0:52   ` Jason Wang
2018-07-13  0:52   ` Jason Wang
2018-07-13  0:52     ` [virtio-dev] " Jason Wang
2018-07-13  3:26   ` Michael S. Tsirkin
2018-07-13  3:26     ` [virtio-dev] " Michael S. Tsirkin
2018-07-13  3:26   ` Michael S. Tsirkin
2018-08-27 14:00 ` Michael S. Tsirkin
2018-08-27 14:00 ` Michael S. Tsirkin
2018-08-27 14:00   ` [virtio-dev] " Michael S. Tsirkin
2018-08-28  5:51   ` Jens Freimann
2018-09-07  1:22   ` Tiwei Bie
2018-09-07  1:22   ` Tiwei Bie
2018-09-07  1:22     ` Tiwei Bie
2018-09-07  1:22     ` Tiwei Bie
2018-09-07 13:00     ` [virtio-dev] " Michael S. Tsirkin
2018-09-07 13:00     ` Michael S. Tsirkin
2018-09-07 13:00       ` Michael S. Tsirkin
2018-09-07 13:00       ` Michael S. Tsirkin
2018-09-10  3:00       ` [virtio-dev] " Tiwei Bie
2018-09-10  3:00       ` Tiwei Bie
2018-09-10  3:00         ` Tiwei Bie
2018-09-10  3:00         ` Tiwei Bie
2018-09-10  3:33         ` [virtio-dev] " Jason Wang
2018-09-10  3:33           ` Jason Wang
2018-09-11  5:37           ` Tiwei Bie
2018-09-11  5:37           ` Tiwei Bie
2018-09-11  5:37             ` Tiwei Bie
2018-09-11  5:37             ` Tiwei Bie
2018-09-12 16:16             ` [virtio-dev] " Michael S. Tsirkin
2018-09-12 16:16               ` Michael S. Tsirkin
2018-09-13  8:59               ` Tiwei Bie
2018-09-13  8:59                 ` Tiwei Bie
2018-09-13  8:59                 ` Tiwei Bie
2018-09-13  9:47                 ` [virtio-dev] " Jason Wang
2018-09-13  9:47                   ` Jason Wang
2018-09-13  9:47                   ` Jason Wang
2018-10-10 14:36                   ` [virtio-dev] " Michael S. Tsirkin
2018-10-10 14:36                     ` Michael S. Tsirkin
2018-10-11 12:12                     ` Tiwei Bie
2018-10-11 12:12                     ` Tiwei Bie
2018-10-11 12:12                       ` Tiwei Bie
2018-10-11 12:12                       ` Tiwei Bie
2018-10-11 13:48                       ` [virtio-dev] " Michael S. Tsirkin
2018-10-11 13:48                       ` Michael S. Tsirkin
2018-10-11 13:48                         ` Michael S. Tsirkin
2018-10-11 14:13                         ` Tiwei Bie
2018-10-11 14:13                           ` Tiwei Bie
2018-10-11 14:17                           ` Michael S. Tsirkin
2018-10-11 14:17                             ` Michael S. Tsirkin
2018-10-11 14:17                             ` Michael S. Tsirkin
2018-10-11 14:34                             ` [virtio-dev] " Tiwei Bie
2018-10-11 14:34                               ` Tiwei Bie
2018-10-11 14:34                               ` Tiwei Bie
2018-10-11 14:34                             ` [virtio-dev] " Tiwei Bie
2018-10-11 14:17                           ` Michael S. Tsirkin
2018-10-11 14:13                         ` Tiwei Bie
2018-10-10 14:36                   ` Michael S. Tsirkin
2018-09-13  9:47                 ` Jason Wang
2018-09-13  8:59               ` Tiwei Bie
2018-09-12 16:16             ` Michael S. Tsirkin
2018-09-10  3:33         ` Jason Wang
2018-09-12 13:06         ` Michael S. Tsirkin
2018-09-12 13:06         ` Michael S. Tsirkin
2018-09-12 13:06           ` Michael S. Tsirkin
2018-09-12 13:06           ` Michael S. Tsirkin

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='20180912120900-mutt-send-email-mst__17656.0535481714$1536768652$gmane$org@kernel.org' \
    --to=mst@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tiwei.bie@intel.com \
    --cc=virtio-dev@lists.oasis-open.org \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=wexu@redhat.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 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.