All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] qemu: define and use VIRTIO_PFN_SHIFT
@ 2008-11-06 10:54 ` Mark McLoughlin
  0 siblings, 0 replies; 28+ messages in thread
From: Mark McLoughlin @ 2008-11-06 10:54 UTC (permalink / raw)
  To: kvm-ia64

On Wed, 2008-11-05 at 22:49 -0600, Hollis Blanchard wrote:

> diff --git a/qemu/hw/virtio.c b/qemu/hw/virtio.c
> --- a/qemu/hw/virtio.c
> +++ b/qemu/hw/virtio.c
> @@ -56,6 +56,10 @@
>   */
>  #define wmb() do { } while (0)
>  
> +#define VRING_PAGE_SIZE (1<<12)
> +
> +#define ALIGN(x, a)  (((x)+(a)-1) & ~((a)-1))

Might be better to do:

#define VRING_PAGE_SIZE (1<<12)
#define VRING_PAGE_MASK ~(VRING_PAGE_SIZE - 1)
#define VRING_PAGE_ALIGN(x) (((x) + VRING_PAGE_SIZE - 1) & VRING_PAGE_MASK)

Cheers,
Mark


^ permalink raw reply	[flat|nested] 28+ messages in thread
* Re: dynamic virtio page size
@ 2008-11-06 23:27 ` Hollis Blanchard
  0 siblings, 0 replies; 28+ messages in thread
From: Hollis Blanchard @ 2008-11-06 23:27 UTC (permalink / raw)
  To: kvm-ia64

On Thu, 2008-11-06 at 14:02 -0600, Anthony Liguori wrote:
> Hollis Blanchard wrote:
> > I wanted to make sure people on non-x86 architectures couldn't run into
> > vring-size related problems that didn't also appear on x86.
> >   
> 
> Having a VRING_SHIFT and a VRING_PAGE_SIZE where VRING_PAGE_SIZE != (1 
> << VRING_SHIFT) is almost certainly going to break things in unexpected 
> ways because it's going against common understanding of the relationship 
> between shift and page_size.

In the patch I sent, they are named VIRTIO_PFN_SHIFT and
VRING_PAGE_SIZE. In fact, the first could really be named
VIRTIO_PCI_PFN_SHIFT or even more specific, which hopefully would
alleviate the confusion.

Anyways, I've been trying to implement your other idea, which was to
advertise a "virtio page size" from the host to the guest. Since the
virtio IO space is only 20 bytes long, and it's full, we need to offer a
feature bit to notify the guest that the IO space has been expanded. 

       virtio's PCI IO resource
------------------------------------
|    20 bytes    |                 |
------------------------------------
   virtio-pci       virtio-<device>
    specific          specific
      data              data

If guests don't acknowledge the feature, the host pretends the
VIRTIO_PAGE_SIZE register (which would be the new IO offset 20) doesn't
exist, and reads to offset 20 instead return the device-specific config
data.

Problem: the guest has not yet acknowledged the advertised features
before accessing device-specific data. So in the virtio-blk/virtio-pci
case, virtio_dev_probe() calls virtblk_probe() *before*
vp_finalize_features(). virtblk_probe() uses virtio_config_val(), which
returns the wrong data because the new yet unknown feature flag is still
set. (Of course, we can't just fix the ordering guest-side, because that
breaks backwards compatibility.)

It seems to me that virtio-pci configuration is not very flexible. I
think I'm going to continue revising the hardcoded page size patches I
sent earlier...

-- 
Hollis Blanchard
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 28+ messages in thread
* [PATCH] qemu: define and use VIRTIO_PFN_SHIFT
@ 2008-11-06  4:49 Hollis Blanchard
  0 siblings, 0 replies; 28+ messages in thread
From: Hollis Blanchard @ 2008-11-06  4:49 UTC (permalink / raw)
  To: rusty; +Cc: kvm, kvm-ppc, kvm-ia64

# HG changeset patch
# User Hollis Blanchard <hollisb@us.ibm.com>
# Date 1225946837 21600
# Node ID 43a111ea61b542d3823e2a11d017e7b06b7ec254
# Parent  b63967268af119e0faa4adc3086cdef857815548
qemu: define and use VIRTIO_PFN_SHIFT

The virtio front and back ends must agree about how big a pfn really is. Since
qemu has no idea what "page size" the guest may be using, it must be
independent of TARGET_PAGE_BITS.

This patch should have no functional effect on x86 or ia64, but I'd like an ack from the
ia64 guys.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>

diff --git a/qemu/hw/virtio.c b/qemu/hw/virtio.c
--- a/qemu/hw/virtio.c
+++ b/qemu/hw/virtio.c
@@ -56,6 +56,10 @@
  */
 #define wmb() do { } while (0)
 
+#define VRING_PAGE_SIZE (1<<12)
+
+#define ALIGN(x, a)  (((x)+(a)-1) & ~((a)-1))
+
 /* virt queue functions */
 
 static void *virtio_map_gpa(target_phys_addr_t addr, size_t size)
@@ -95,8 +99,8 @@ static void *virtio_map_gpa(target_phys_
 
 static size_t virtqueue_size(int num)
 {
-    return TARGET_PAGE_ALIGN((sizeof(VRingDesc) * num) +
-			     (sizeof(VRingAvail) + sizeof(uint16_t) * num)) +
+    return ALIGN((sizeof(VRingDesc) * num) + (sizeof(VRingAvail) +
+		 sizeof(uint16_t) * num), VRING_PAGE_SIZE) +
 	(sizeof(VRingUsed) + sizeof(VRingUsedElem) * num);
 }
 
@@ -104,7 +108,7 @@ static void virtqueue_init(VirtQueue *vq
 {
     vq->vring.desc = p;
     vq->vring.avail = p + vq->vring.num * sizeof(VRingDesc);
-    vq->vring.used = (void *)TARGET_PAGE_ALIGN((unsigned long)&vq->vring.avail->ring[vq->vring.num]);
+    vq->vring.used = (void *)ALIGN((unsigned long)&vq->vring.avail->ring[vq->vring.num], VRING_PAGE_SIZE);
 }
 
 static unsigned virtqueue_next_desc(VirtQueue *vq, unsigned int i)
@@ -241,7 +245,7 @@ static void virtio_ioport_write(void *op
 	vdev->features = val;
 	break;
     case VIRTIO_PCI_QUEUE_PFN:
-	pa = (ram_addr_t)val << TARGET_PAGE_BITS;
+	pa = (ram_addr_t)val << VIRTIO_PFN_SHIFT;
 	vdev->vq[vdev->queue_sel].pfn = val;
 	if (pa == 0) {
             virtio_reset(vdev);
@@ -519,7 +523,7 @@ void virtio_load(VirtIODevice *vdev, QEM
 	    size_t size;
 	    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_PFN_SHIFT;
 	    size = virtqueue_size(vdev->vq[i].vring.num);
 	    virtqueue_init(&vdev->vq[i], virtio_map_gpa(pa, size));
 	}
diff --git a/qemu/target-i386/cpu.h b/qemu/target-i386/cpu.h
--- a/qemu/target-i386/cpu.h
+++ b/qemu/target-i386/cpu.h
@@ -751,6 +751,8 @@ static inline int cpu_get_time_fast(void
 
 #define TARGET_PAGE_BITS 12
 
+#define VIRTIO_PFN_SHIFT 12
+
 #define CPUState CPUX86State
 #define cpu_init cpu_x86_init
 #define cpu_exec cpu_x86_exec
diff --git a/qemu/target-ia64/cpu.h b/qemu/target-ia64/cpu.h
--- a/qemu/target-ia64/cpu.h
+++ b/qemu/target-ia64/cpu.h
@@ -30,6 +30,8 @@
 #define TARGET_LONG_BITS 64
 
 #define TARGET_PAGE_BITS 16
+
+#define VIRTIO_PFN_SHIFT 16
 
 #define ELF_MACHINE	EM_IA_64
 
diff --git a/qemu/target-ppc/cpu.h b/qemu/target-ppc/cpu.h
--- a/qemu/target-ppc/cpu.h
+++ b/qemu/target-ppc/cpu.h
@@ -54,6 +54,8 @@
 #endif /* defined(TARGET_PPCEMB) */
 
 #endif /* defined (TARGET_PPC64) */
+
+#define VIRTIO_PFN_SHIFT 10
 
 #include "cpu-defs.h"
 

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2008-11-10  5:55 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-06 10:54 [PATCH] qemu: define and use VIRTIO_PFN_SHIFT Mark McLoughlin
2008-11-06 10:54 ` Mark McLoughlin
2008-11-06 10:54 ` Mark McLoughlin
2008-11-06 14:01 ` Anthony Liguori
2008-11-06 14:01   ` Anthony Liguori
2008-11-06 14:01   ` Anthony Liguori
2008-11-06 19:02 ` Hollis Blanchard
2008-11-06 19:02   ` Hollis Blanchard
2008-11-06 19:02   ` Hollis Blanchard
2008-11-06 20:02 ` Anthony Liguori
2008-11-06 20:02   ` Anthony Liguori
2008-11-06 20:02   ` Anthony Liguori
2008-11-07  1:38 ` Zhang, Xiantao
2008-11-07  1:38   ` Zhang, Xiantao
2008-11-07  1:38   ` Zhang, Xiantao
2008-11-07  5:05 ` Hollis Blanchard
2008-11-07  5:05   ` Hollis Blanchard
2008-11-07  5:05   ` Hollis Blanchard
2008-11-10  5:55 ` Zhang, Xiantao
2008-11-10  5:55   ` Zhang, Xiantao
2008-11-10  5:55   ` Zhang, Xiantao
  -- strict thread matches above, loose matches on Subject: below --
2008-11-06 23:27 dynamic virtio page size Hollis Blanchard
2008-11-06 23:27 ` Hollis Blanchard
2008-11-06 23:27 ` Hollis Blanchard
2008-11-06 23:32 ` Hollis Blanchard
2008-11-06 23:32   ` Hollis Blanchard
2008-11-06 23:32   ` Hollis Blanchard
2008-11-06  4:49 [PATCH] qemu: define and use VIRTIO_PFN_SHIFT Hollis Blanchard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.