Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L8KLX-0008Ge-V0 for qemu-devel@nongnu.org; Thu, 04 Dec 2008 14:58:48 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L8KLX-0008Fb-3b for qemu-devel@nongnu.org; Thu, 04 Dec 2008 14:58:47 -0500 Received: from [199.232.76.173] (port=56015 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L8KLW-0008FS-WB for qemu-devel@nongnu.org; Thu, 04 Dec 2008 14:58:47 -0500 Received: from savannah.gnu.org ([199.232.41.3]:45124 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L8KLW-0002H6-LQ for qemu-devel@nongnu.org; Thu, 04 Dec 2008 14:58:46 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1L8KLW-0006li-8L for qemu-devel@nongnu.org; Thu, 04 Dec 2008 19:58:46 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1L8KLW-0006le-3B for qemu-devel@nongnu.org; Thu, 04 Dec 2008 19:58:46 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 04 Dec 2008 19:58:46 +0000 Subject: [Qemu-devel] [5871] Remove TARGET_PAGE_SIZE from virtio interface (Hollis Blanchard) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 5871 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5871 Author: aliguori Date: 2008-12-04 19:58:45 +0000 (Thu, 04 Dec 2008) Log Message: ----------- Remove TARGET_PAGE_SIZE from virtio interface (Hollis Blanchard) 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 Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/hw/virtio.c trunk/hw/virtio.h Modified: trunk/hw/virtio.c =================================================================== --- trunk/hw/virtio.c 2008-12-04 19:52:44 UTC (rev 5870) +++ trunk/hw/virtio.c 2008-12-04 19:58:45 UTC (rev 5871) @@ -52,6 +52,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. @@ -147,7 +155,9 @@ { 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) @@ -501,7 +511,7 @@ 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); @@ -776,7 +786,7 @@ 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); } } Modified: trunk/hw/virtio.h =================================================================== --- trunk/hw/virtio.h 2008-12-04 19:52:44 UTC (rev 5870) +++ trunk/hw/virtio.h 2008-12-04 19:58:45 UTC (rev 5871) @@ -48,6 +48,12 @@ struct VirtQueue; +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;