From: David Gibson <david@gibson.dropbear.id.au>
To: Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: thuth@linux.vnet.ibm.com, rusty@rustcorp.com.au, mst@redhat.com,
qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org
Subject: Re: [Qemu-devel] [PATCH RFC v6 07/20] virtio: allow virtio-1 queue layout
Date: Thu, 22 Jan 2015 13:06:09 +1100 [thread overview]
Message-ID: <20150122020609.GI27371@voom.fritz.box> (raw)
In-Reply-To: <1418304322-7546-8-git-send-email-cornelia.huck@de.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 8325 bytes --]
On Thu, Dec 11, 2014 at 02:25:09PM +0100, Cornelia Huck wrote:
> For virtio-1 devices, we allow a more complex queue layout that doesn't
> require descriptor table and rings on a physically-contigous memory area:
> add virtio_queue_set_rings() to allow transports to set this up.
>
> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> ---
> hw/virtio/virtio-mmio.c | 3 +++
> hw/virtio/virtio.c | 53 ++++++++++++++++++++++++++++----------------
> include/hw/virtio/virtio.h | 3 +++
> 3 files changed, 40 insertions(+), 19 deletions(-)
>
> diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
> index 43b7e02..0c9b63b 100644
> --- a/hw/virtio/virtio-mmio.c
> +++ b/hw/virtio/virtio-mmio.c
> @@ -244,8 +244,11 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value,
> case VIRTIO_MMIO_QUEUENUM:
> DPRINTF("mmio_queue write %d max %d\n", (int)value, VIRTQUEUE_MAX_SIZE);
> virtio_queue_set_num(vdev, vdev->queue_sel, value);
> + /* Note: only call this function for legacy devices */
It's not clear to me if this is an assertion that this *does* only
call the function for legacy devices or a fixme, that it *should* only
call the function for legacy devices.
> + virtio_queue_update_rings(vdev, vdev->queue_sel);
> break;
> case VIRTIO_MMIO_QUEUEALIGN:
> + /* Note: this is only valid for legacy devices */
> virtio_queue_set_align(vdev, vdev->queue_sel, value);
> break;
> case VIRTIO_MMIO_QUEUEPFN:
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 8f69ffa..57190ba 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -69,7 +69,6 @@ typedef struct VRing
> struct VirtQueue
> {
> VRing vring;
> - hwaddr pa;
> uint16_t last_avail_idx;
> /* Last used index value we have signalled on */
> uint16_t signalled_used;
> @@ -92,15 +91,18 @@ struct VirtQueue
> };
>
> /* virt queue functions */
> -static void virtqueue_init(VirtQueue *vq)
> +void virtio_queue_update_rings(VirtIODevice *vdev, int n)
Perhaps something in the name to emphasise that this is only for <v1.0
devices?
> {
> - hwaddr pa = vq->pa;
> + VRing *vring = &vdev->vq[n].vring;
>
> - vq->vring.desc = pa;
> - vq->vring.avail = pa + vq->vring.num * sizeof(VRingDesc);
> - vq->vring.used = vring_align(vq->vring.avail +
> - offsetof(VRingAvail, ring[vq->vring.num]),
> - vq->vring.align);
> + if (!vring->desc) {
> + /* not yet setup -> nothing to do */
> + return;
> + }
> + vring->avail = vring->desc + vring->num * sizeof(VRingDesc);
> + vring->used = vring_align(vring->avail +
> + offsetof(VRingAvail, ring[vring->num]),
> + vring->align);
Would it make sense to implement this in terms of
virtio_queue_set_rings()?
> }
>
> static inline uint64_t vring_desc_addr(VirtIODevice *vdev, hwaddr desc_pa,
> @@ -605,7 +607,6 @@ void virtio_reset(void *opaque)
> vdev->vq[i].vring.avail = 0;
> vdev->vq[i].vring.used = 0;
> vdev->vq[i].last_avail_idx = 0;
> - vdev->vq[i].pa = 0;
> vdev->vq[i].vector = VIRTIO_NO_VECTOR;
> vdev->vq[i].signalled_used = 0;
> vdev->vq[i].signalled_used_valid = false;
> @@ -708,13 +709,21 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>
> void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr)
> {
> - vdev->vq[n].pa = addr;
> - virtqueue_init(&vdev->vq[n]);
> + vdev->vq[n].vring.desc = addr;
> + virtio_queue_update_rings(vdev, n);
> }
>
> hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n)
> {
> - return vdev->vq[n].pa;
> + return vdev->vq[n].vring.desc;
> +}
> +
> +void virtio_queue_set_rings(VirtIODevice *vdev, int n, hwaddr desc,
> + hwaddr avail, hwaddr used)
> +{
> + vdev->vq[n].vring.desc = desc;
> + vdev->vq[n].vring.avail = avail;
> + vdev->vq[n].vring.used = used;
> }
>
> void virtio_queue_set_num(VirtIODevice *vdev, int n, int num)
> @@ -728,7 +737,6 @@ void virtio_queue_set_num(VirtIODevice *vdev, int n, int num)
> return;
> }
> vdev->vq[n].vring.num = num;
> - virtqueue_init(&vdev->vq[n]);
> }
>
> int virtio_queue_get_num(VirtIODevice *vdev, int n)
> @@ -748,6 +756,11 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)
> BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
> VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
>
> + /* virtio-1 compliant devices cannot change the aligment */
> + if (virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) {
> + error_report("tried to modify queue alignment for virtio-1 device");
> + return;
> + }
> /* Check that the transport told us it was going to do this
> * (so a buggy transport will immediately assert rather than
> * silently failing to migrate this state)
> @@ -755,7 +768,7 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)
> assert(k->has_variable_vring_alignment);
>
> vdev->vq[n].vring.align = align;
> - virtqueue_init(&vdev->vq[n]);
> + virtio_queue_update_rings(vdev, n);
> }
>
> void virtio_queue_notify_vq(VirtQueue *vq)
> @@ -949,7 +962,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
> if (k->has_variable_vring_alignment) {
> qemu_put_be32(f, vdev->vq[i].vring.align);
> }
> - qemu_put_be64(f, vdev->vq[i].pa);
> + /* XXX virtio-1 devices */
> + qemu_put_be64(f, vdev->vq[i].vring.desc);
> qemu_put_be16s(f, &vdev->vq[i].last_avail_idx);
> if (k->save_queue) {
> k->save_queue(qbus->parent, i, f);
> @@ -1044,13 +1058,14 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
> if (k->has_variable_vring_alignment) {
> vdev->vq[i].vring.align = qemu_get_be32(f);
> }
> - vdev->vq[i].pa = qemu_get_be64(f);
> + vdev->vq[i].vring.desc = qemu_get_be64(f);
> qemu_get_be16s(f, &vdev->vq[i].last_avail_idx);
> vdev->vq[i].signalled_used_valid = false;
> vdev->vq[i].notification = true;
>
> - if (vdev->vq[i].pa) {
> - virtqueue_init(&vdev->vq[i]);
> + if (vdev->vq[i].vring.desc) {
> + /* XXX virtio-1 devices */
> + virtio_queue_update_rings(vdev, i);
> } else if (vdev->vq[i].last_avail_idx) {
> error_report("VQ %d address 0x0 "
> "inconsistent with Host index 0x%x",
> @@ -1084,7 +1099,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
> }
>
> for (i = 0; i < num; i++) {
> - if (vdev->vq[i].pa) {
> + if (vdev->vq[i].vring.desc) {
> uint16_t nheads;
> nheads = vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_avail_idx;
> /* Check it isn't doing strange things with descriptor numbers. */
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index 68c40db..b63ced3 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -224,6 +224,9 @@ void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr);
> hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n);
> void virtio_queue_set_num(VirtIODevice *vdev, int n, int num);
> int virtio_queue_get_num(VirtIODevice *vdev, int n);
> +void virtio_queue_set_rings(VirtIODevice *vdev, int n, hwaddr desc,
> + hwaddr avail, hwaddr used);
> +void virtio_queue_update_rings(VirtIODevice *vdev, int n);
> void virtio_queue_set_align(VirtIODevice *vdev, int n, int align);
> void virtio_queue_notify(VirtIODevice *vdev, int n);
> uint16_t virtio_queue_vector(VirtIODevice *vdev, int n);
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2015-01-22 2:24 UTC|newest]
Thread overview: 82+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-11 13:25 [Qemu-devel] [PATCH RFC v6 00/20] qemu: towards virtio-1 host support Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 01/20] linux-headers/virtio_config: Update with VIRTIO_F_VERSION_1 Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 02/20] virtio: cull virtio_bus_set_vdev_features Cornelia Huck
2015-01-22 1:24 ` David Gibson
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 03/20] virtio: feature bit manipulation helpers Cornelia Huck
2014-12-11 14:29 ` Thomas Huth
2015-01-22 1:25 ` David Gibson
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 04/20] virtio: add feature checking helpers Cornelia Huck
2014-12-11 14:46 ` Thomas Huth
2014-12-11 17:05 ` Michael S. Tsirkin
2014-12-12 8:37 ` Cornelia Huck
2014-12-12 10:07 ` Cornelia Huck
2015-01-22 1:28 ` David Gibson
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 05/20] virtio: support more feature bits Cornelia Huck
2014-12-12 10:06 ` Thomas Huth
2014-12-12 10:17 ` Cornelia Huck
2015-01-22 1:40 ` David Gibson
2015-01-22 1:43 ` David Gibson
2015-01-28 15:59 ` Cornelia Huck
2015-01-29 0:11 ` David Gibson
2015-01-29 9:24 ` Thomas Huth
2015-01-29 10:01 ` David Gibson
2015-01-29 10:54 ` Michael S. Tsirkin
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 06/20] virtio: endianness checks for virtio 1.0 devices Cornelia Huck
2015-01-20 10:29 ` Stefan Hajnoczi
2015-01-22 1:54 ` David Gibson
2015-01-23 16:09 ` Greg Kurz
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 07/20] virtio: allow virtio-1 queue layout Cornelia Huck
2015-01-22 2:06 ` David Gibson [this message]
2015-01-28 16:07 ` Cornelia Huck
2015-01-29 0:14 ` David Gibson
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 08/20] dataplane: allow virtio-1 devices Cornelia Huck
2015-01-20 10:43 ` Stefan Hajnoczi
2015-01-20 12:56 ` Cornelia Huck
2015-01-20 14:47 ` Stefan Hajnoczi
2015-01-22 2:12 ` David Gibson
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 09/20] s390x/css: Add a callback for when subchannel gets disabled Cornelia Huck
2015-01-20 10:50 ` Stefan Hajnoczi
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 10/20] s390x/virtio-ccw: add virtio set-revision call Cornelia Huck
2015-01-20 11:00 ` Stefan Hajnoczi
2015-01-20 11:08 ` Stefan Hajnoczi
2015-01-21 11:23 ` Cornelia Huck
2015-01-21 11:51 ` Thomas Huth
2015-01-21 12:39 ` Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 11/20] s390x/virtio-ccw: support virtio-1 set_vq format Cornelia Huck
2015-01-20 11:06 ` Stefan Hajnoczi
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 12/20] virtio: disallow late feature changes for virtio-1 Cornelia Huck
2014-12-12 10:55 ` Thomas Huth
2014-12-12 11:18 ` Cornelia Huck
2014-12-12 11:25 ` Thomas Huth
2015-01-20 11:14 ` Stefan Hajnoczi
2015-01-22 2:15 ` David Gibson
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 13/20] virtio: allow to fail setting status Cornelia Huck
2014-12-30 12:25 ` Michael S. Tsirkin
2015-01-07 16:13 ` Cornelia Huck
2015-01-07 19:08 ` Michael S. Tsirkin
2015-01-08 7:20 ` Cornelia Huck
2015-01-08 8:09 ` Michael S. Tsirkin
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 14/20] s390x/virtio-ccw: enable virtio 1.0 Cornelia Huck
2015-01-20 11:15 ` Stefan Hajnoczi
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 15/20] virtio-net: no writeable mac for virtio-1 Cornelia Huck
2015-01-20 11:19 ` Stefan Hajnoczi
2015-01-22 16:31 ` Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 16/20] virtio-net: support longer header Cornelia Huck
2015-01-20 13:18 ` Stefan Hajnoczi
2015-01-21 16:06 ` Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 17/20] virtio-net: enable virtio 1.0 Cornelia Huck
2014-12-16 13:10 ` Michael S. Tsirkin
2014-12-18 16:57 ` Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 18/20] virtio: support revision-specific features Cornelia Huck
2014-12-28 8:32 ` Michael S. Tsirkin
2015-01-07 16:22 ` Cornelia Huck
2015-01-07 19:10 ` Michael S. Tsirkin
2015-01-30 14:08 ` Cornelia Huck
2015-02-01 21:29 ` Michael S. Tsirkin
2015-02-02 14:10 ` Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 19/20] virtio-blk: revision specific feature bits Cornelia Huck
2014-12-28 10:24 ` Michael S. Tsirkin
2015-01-07 16:29 ` Cornelia Huck
2015-01-07 19:11 ` Michael S. Tsirkin
2015-01-30 14:10 ` Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 20/20] vhost: 64 bit features Cornelia Huck
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=20150122020609.GI27371@voom.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=cornelia.huck@de.ibm.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rusty@rustcorp.com.au \
--cc=thuth@linux.vnet.ibm.com \
--cc=virtualization@lists.linux-foundation.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 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).