qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Hollis Blanchard <hollisb@us.ibm.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: Hollis Blanchard <hollisb@us.ibm.com>,
	qemu-devel@nongnu.org, kvm@vger.kernel.org,
	Avi Kivity <avi@redhat.com>
Subject: [Qemu-devel] [PATCH] [v2] Remove TARGET_PAGE_SIZE from virtio interface
Date: Mon,  1 Dec 2008 12:19:30 -0600	[thread overview]
Message-ID: <1228155570-9913-1-git-send-email-hollisb@us.ibm.com> (raw)
In-Reply-To: <1227650239-14162-1-git-send-email-aliguori@us.ibm.com>

TARGET_PAGE_SIZE should only be used internal to qemu, not in guest/host
interfaces. The virtio frontend code in Linux uses two constants (PFN shift
and vring alignment) for the interface, so update qemu to match.

I've tested this with PowerPC KVM and confirmed that it fixes virtio problems
when using non-TARGET_PAGE_SIZE pages in the guest.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
---
Corrects a silly bug in v1.

Paul Brook doesn't like the idea of a generic align() macro, so vring_align()
is correct.
---
 hw/virtio.c |   16 +++++++++++++---
 hw/virtio.h |    6 ++++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/hw/virtio.c b/hw/virtio.c
index e4224ab..0134b0b 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -51,6 +51,14 @@
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION           0
 
+/* How many bits to shift physical queue address written to QUEUE_PFN.
+ * 12 is historical, and due to x86 page size. */
+#define VIRTIO_PCI_QUEUE_ADDR_SHIFT    12
+
+/* The alignment to use between consumer and producer parts of vring.
+ * x86 pagesize again. */
+#define VIRTIO_PCI_VRING_ALIGN         4096
+
 /* QEMU doesn't strictly need write barriers since everything runs in
  * lock-step.  We'll leave the calls to wmb() in though to make it obvious for
  * KVM or if kqemu gets SMP support.
@@ -110,7 +118,9 @@ static void virtqueue_init(VirtQueue *vq, target_phys_addr_t pa)
 {
     vq->vring.desc = pa;
     vq->vring.avail = pa + vq->vring.num * sizeof(VRingDesc);
-    vq->vring.used = TARGET_PAGE_ALIGN(vq->vring.avail + offsetof(VRingAvail, ring[vq->vring.num]));
+    vq->vring.used = vring_align(vq->vring.avail +
+                                 offsetof(VRingAvail, ring[vq->vring.num]),
+                                 VIRTIO_PCI_VRING_ALIGN);
 }
 
 static inline uint64_t vring_desc_addr(VirtQueue *vq, int i)
@@ -386,7 +396,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
         vdev->features = val;
         break;
     case VIRTIO_PCI_QUEUE_PFN:
-        pa = (ram_addr_t)val << TARGET_PAGE_BITS;
+        pa = (ram_addr_t)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT;
         vdev->vq[vdev->queue_sel].pfn = val;
         if (pa == 0)
             virtio_reset(vdev);
@@ -660,7 +670,7 @@ void virtio_load(VirtIODevice *vdev, QEMUFile *f)
         if (vdev->vq[i].pfn) {
             target_phys_addr_t pa;
 
-            pa = (ram_addr_t)vdev->vq[i].pfn << TARGET_PAGE_BITS;
+            pa = (ram_addr_t)vdev->vq[i].pfn << VIRTIO_PCI_QUEUE_ADDR_SHIFT;
             virtqueue_init(&vdev->vq[i], pa);
         }
     }
diff --git a/hw/virtio.h b/hw/virtio.h
index 1df8f83..ae92ece 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -47,6 +47,12 @@
 /* This means don't interrupt guest when buffer consumed. */
 #define VRING_AVAIL_F_NO_INTERRUPT    1
 
+static inline target_phys_addr_t vring_align(target_phys_addr_t addr,
+                                             unsigned long align)
+{
+    return (addr + align - 1) & ~(align - 1);
+}
+
 typedef struct VirtQueue VirtQueue;
 typedef struct VirtIODevice VirtIODevice;
 
-- 
1.5.6.5

  parent reply	other threads:[~2008-12-01 18:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-25 21:57 [Qemu-devel] [PATCH 1/2] Virtio core support Anthony Liguori
2008-11-25 21:57 ` [Qemu-devel] [PATCH 2/2] Virtio block device support Anthony Liguori
2008-11-26 18:24   ` Hollis Blanchard
2008-12-01 20:20   ` Hollis Blanchard
2008-12-01 20:22     ` Anthony Liguori
2008-11-26 18:11 ` [Qemu-devel] [PATCH 1/1] " Hollis Blanchard
2008-11-26 18:17   ` Hollis Blanchard
2008-11-26 18:22 ` [Qemu-devel] [PATCH] Remove TARGET_PAGE_SIZE from virtio interface Hollis Blanchard
2008-11-26 18:29   ` [Qemu-devel] " Hollis Blanchard
2008-12-01 18:19 ` Hollis Blanchard [this message]
2008-12-04 19:58   ` [Qemu-devel] Re: [PATCH] [v2] " Anthony Liguori

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=1228155570-9913-1-git-send-email-hollisb@us.ibm.com \
    --to=hollisb@us.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.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).