From patchwork Fri Jul 12 20:36:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 258800 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DFC982C0380 for ; Sat, 13 Jul 2013 06:54:49 +1000 (EST) Received: from localhost ([::1]:36001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxkMZ-0002fz-Sy for incoming@patchwork.ozlabs.org; Fri, 12 Jul 2013 16:54:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39964) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxkM7-0002b0-1t for qemu-devel@nongnu.org; Fri, 12 Jul 2013 16:54:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UxkM2-0006SF-F4 for qemu-devel@nongnu.org; Fri, 12 Jul 2013 16:54:18 -0400 Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa ([2001:8b0:1d0::1]:58562 helo=mnementh.archaic.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxkM2-0006Rq-4L for qemu-devel@nongnu.org; Fri, 12 Jul 2013 16:54:14 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Uxk5P-00069T-Ad; Fri, 12 Jul 2013 21:37:03 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 12 Jul 2013 21:36:58 +0100 Message-Id: <1373661422-23606-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1373661422-23606-1-git-send-email-peter.maydell@linaro.org> References: <1373661422-23606-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: Anthony Liguori , David Gibson , kvmarm@lists.cs.columbia.edu, Alexander Graf , patches@linaro.org Subject: [Qemu-devel] [PATCH v2 4/8] virtio: Support transports which can specify the vring alignment X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Support virtio transports which can specify the vring alignment (ie where the guest communicates this to the host) by providing a new virtio_queue_set_align() function. (The default alignment remains as before.) Transports which wish to make use of this must set the has_variable_vring_alignment field in their VirtioBusClass struct to true; they can then change the alignment via virtio_queue_set_align(). Signed-off-by: Peter Maydell --- hw/virtio/virtio.c | 32 +++++++++++++++++++++++++++++--- include/hw/virtio/virtio-bus.h | 6 ++++++ include/hw/virtio/virtio.h | 1 + 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 01b05f3..09f62c6 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -19,8 +19,11 @@ #include "qemu/atomic.h" #include "hw/virtio/virtio-bus.h" -/* The alignment to use between consumer and producer parts of vring. - * x86 pagesize again. */ +/* + * The alignment to use between consumer and producer parts of vring. + * x86 pagesize again. This is the default, used by transports like PCI + * which don't provide a means for the guest to tell the host the alignment. + */ #define VIRTIO_PCI_VRING_ALIGN 4096 typedef struct VRingDesc @@ -54,6 +57,7 @@ typedef struct VRingUsed typedef struct VRing { unsigned int num; + unsigned int align; hwaddr desc; hwaddr avail; hwaddr used; @@ -93,7 +97,7 @@ static void virtqueue_init(VirtQueue *vq) vq->vring.avail = pa + vq->vring.num * sizeof(VRingDesc); vq->vring.used = vring_align(vq->vring.avail + offsetof(VRingAvail, ring[vq->vring.num]), - VIRTIO_PCI_VRING_ALIGN); + vq->vring.align); } static inline uint64_t vring_desc_addr(hwaddr desc_pa, int i) @@ -687,6 +691,21 @@ int virtio_queue_get_id(VirtQueue *vq) return vq - &vdev->vq[0]; } +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); + + /* 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) + */ + assert(k->has_variable_vring_alignment); + + vdev->vq[n].vring.align = align; + virtqueue_init(&vdev->vq[n]); +} + void virtio_queue_notify_vq(VirtQueue *vq) { if (vq->vring.desc) { @@ -727,6 +746,7 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, abort(); vdev->vq[i].vring.num = queue_size; + vdev->vq[i].vring.align = VIRTIO_PCI_VRING_ALIGN; vdev->vq[i].handle_output = handle_output; return &vdev->vq[i]; @@ -833,6 +853,9 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f) break; qemu_put_be32(f, vdev->vq[i].vring.num); + if (k->has_variable_vring_alignment) { + qemu_put_be32(f, vdev->vq[i].vring.align); + } qemu_put_be64(f, vdev->vq[i].pa); qemu_put_be16s(f, &vdev->vq[i].last_avail_idx); if (k->save_queue) { @@ -889,6 +912,9 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f) for (i = 0; i < num; i++) { vdev->vq[i].vring.num = qemu_get_be32(f); + if (k->has_variable_vring_alignment) { + vdev->vq[i].vring.align = qemu_get_be32(f); + } vdev->vq[i].pa = qemu_get_be64(f); qemu_get_be16s(f, &vdev->vq[i].last_avail_idx); vdev->vq[i].signalled_used_valid = false; diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h index 9ed60f9..9217f85 100644 --- a/include/hw/virtio/virtio-bus.h +++ b/include/hw/virtio/virtio-bus.h @@ -62,6 +62,12 @@ typedef struct VirtioBusClass { * This is called by virtio-bus just before the device is unplugged. */ void (*device_unplug)(DeviceState *d); + /* + * Does the transport have variable vring alignment? + * (ie can it ever call virtio_queue_set_align()?) + * Note that changing this will break migration for this transport. + */ + bool has_variable_vring_alignment; } VirtioBusClass; struct VirtioBusState { diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 95c4772..6c2cee6 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -200,6 +200,7 @@ 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_align(VirtIODevice *vdev, int n, int align); void virtio_queue_notify(VirtIODevice *vdev, int n); uint16_t virtio_queue_vector(VirtIODevice *vdev, int n); void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector);