From patchwork Thu Jun 27 13:04:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 18158 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 387C125E0F for ; Thu, 27 Jun 2013 13:24:39 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id m1sf1194284ves.11 for ; Thu, 27 Jun 2013 06:24:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=0wHPvuGx/60rrfyZNJqKKBClUDS1bpbVw1rzDcHecUg=; b=SsE1QAfdi3IM/HrzdoQIUWWyOLuuEEtYY/mHTYzZqm7h7wCt+LYbwV9ba72Rs/vrBJ yNVjlIZW1dCoj92hMK4HszA9+qHGUQjpwDJOHFh5wSVpGY+hWdloUIiudK2BcEZKU+3E sID8VNG8WaDlwe63jfN0u57hiNmfyb8gFP8QQDBdWc0hVSdXljKyw0qErqUFE203EMpq NbqaDEB1M2/37WIdO7vSielv7n3h+lYW37mArEzYZ36r4U6B2XiSfXPkMlB/FkINGGZ1 KRtXbfFYPZsXSg2Oz07X20o/u145lazQBQII3xmfNTgipxSaZd2B42P/RAZPjE6zT+ih pkgw== X-Received: by 10.236.45.4 with SMTP id o4mr4772204yhb.6.1372339478944; Thu, 27 Jun 2013 06:24:38 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.86.7 with SMTP id l7ls769660qez.51.gmail; Thu, 27 Jun 2013 06:24:38 -0700 (PDT) X-Received: by 10.220.123.195 with SMTP id q3mr765364vcr.64.1372339478850; Thu, 27 Jun 2013 06:24:38 -0700 (PDT) Received: from mail-vb0-f52.google.com (mail-vb0-f52.google.com [209.85.212.52]) by mx.google.com with ESMTPS id j17si778752vcl.48.2013.06.27.06.24.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Jun 2013 06:24:38 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.52 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.52; Received: by mail-vb0-f52.google.com with SMTP id f12so613858vbg.39 for ; Thu, 27 Jun 2013 06:24:38 -0700 (PDT) X-Received: by 10.58.119.233 with SMTP id kx9mr3594266veb.3.1372339478763; Thu, 27 Jun 2013 06:24:38 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.165.8 with SMTP id yu8csp148422veb; Thu, 27 Jun 2013 06:24:38 -0700 (PDT) X-Received: by 10.14.110.194 with SMTP id u42mr9046603eeg.128.1372339477102; Thu, 27 Jun 2013 06:24:37 -0700 (PDT) Received: from mnementh.archaic.org.uk (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]) by mx.google.com with ESMTPS id g7si1843846eew.135.2013.06.27.06.24.36 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 27 Jun 2013 06:24:37 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1UsBs0-00012B-76; Thu, 27 Jun 2013 14:04:16 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, kvmarm@lists.cs.columbia.edu, Anthony Liguori , Alexander Graf , KONRAD Frederic , David Gibson Subject: [PATCH 4/8] virtio: Support transports which can specify the vring alignment Date: Thu, 27 Jun 2013 14:04:11 +0100 Message-Id: <1372338255-3934-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1372338255-3934-1-git-send-email-peter.maydell@linaro.org> References: <1372338255-3934-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQkDT0wFz9Z3rQROJm6/DzN3Bwyxddsq1XXSqruR0sgL00oEx2XxfIDT6A+78Ta+PZntYJT3 X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.52 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 8805b8a..9e1a580 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) @@ -685,6 +689,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) { @@ -725,6 +744,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]; @@ -831,6 +851,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) { @@ -887,6 +910,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);