Skip to contentSkip to conversation

linux: virtio: Standardize virtio's concept of "page size"

PATCH Applied Hollis Blanchard 5 participants 8 messages Nov 11, 2008 – Nov 14, 2008 5 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#2 lore raw
In reply to a message not in the archive
Quoted 6 lines · Rusty Russell
Quoted 1 line · On Tuesday 11 November 2008 10:07:09 Hollis Blanchard wrote:

Both sides of the virtio interface must agree about how big a pfn

really

Quoted 1 line

is. This is particularly an issue on architectures where the page

Quoted 8 lines

size is

Quoted 1 line

configurable (e.g. PowerPC, IA64) -- the interface must be

independent of

Quoted 1 line

PAGE_SHIFT.

Thanks Hollis! Applied, with the following overpatch:

Avi, will you commit the matching qemu patch? (I'm not clear on the patch flow for kvm-userspace qemu virtio patches.)

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#3 lore raw
Quoted 3 lines · Hollis Blanchard

Avi, will you commit the matching qemu patch? (I'm not clear on the patch flow for kvm-userspace qemu virtio patches.)

At this time, I'm accepting qemu/virtio patches (and will apply this one); once virtio is merged in qemu upstream, patches will have to go there as well.

Signature · 1 line
error compiling committee.c: too many arguments to function
#4 lore raw
In reply to a message not in the archive
Quoted 10 lines · On Tuesday 11 November 2008 10:07:09 Hollis Blanchard wrote:

Both sides of the virtio interface must agree about how big a pfn really is. This is particularly an issue on architectures where the page size is configurable (e.g. PowerPC, IA64) -- the interface must be independent of PAGE_SHIFT.

Currently there are three distinct problems:
* The shift count used when passing the physical address of the ring to a PCI-based back end.
* The ring layout itself is padded to span at least two "pages".
* The balloon driver operates in units of "pages".

Hi Hollis,

The more I thought about this, the more I think we're not solving this
as neatly as we could. The trigger was noting that we're breaking the userspace API (vring_size and vring_init are exposed to userspace): I know that qemu cut & pastes, but that's no excuse.

So instead, I've introduced separate constants for each use. Yes,
all these constants are 12/4096. But just to be contrary, at the end is a patch to change lguest to 128. And there's no reason this couldn't change in future using some guest detection scheme.

Patch stream to follow...
Rusty.

#6 lore raw
In reply to a message not in the archive
Quoted 19 lines · Rusty Russell
Quoted 10 lines · On Tuesday 11 November 2008 10:07:09 Hollis Blanchard wrote:

Both sides of the virtio interface must agree about how big a pfn really is. This is particularly an issue on architectures where the page size is configurable (e.g. PowerPC, IA64) -- the interface must be independent of PAGE_SHIFT.

Currently there are three distinct problems:
* The shift count used when passing the physical address of the ring to a PCI-based back end.
* The ring layout itself is padded to span at least two "pages".
* The balloon driver operates in units of "pages".

Hi Hollis,

The more I thought about this, the more I think we're not solving this
as neatly as we could. The trigger was noting that we're breaking the userspace API (vring_size and vring_init are exposed to userspace): I know that qemu cut & pastes, but that's no excuse.

Quoted 4 lines

So instead, I've introduced separate constants for each use. Yes,
all these constants are 12/4096. But just to be contrary, at the end is a patch to change lguest to 128. And there's no reason this couldn't change in future using some guest detection scheme.

OK. I thought it was simpler to just say "4KB everywhere" in all aspects of the virtio interface, but I'm happy as long as we solve the problem somehow. :)

Signature · 7 lines
Hollis Blanchard
IBM Linux Technology Center

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw
Quoted 20 lines · On Thursday 13 November 2008 02:46:31 Hollis Blanchard wrote:
Quoted 19 lines · Rusty Russell
Quoted 10 lines · On Tuesday 11 November 2008 10:07:09 Hollis Blanchard wrote:

Both sides of the virtio interface must agree about how big a pfn really is. This is particularly an issue on architectures where the page size is configurable (e.g. PowerPC, IA64) -- the interface must be independent of PAGE_SHIFT.

Currently there are three distinct problems:
* The shift count used when passing the physical address of the ring to a PCI-based back end.
* The ring layout itself is padded to span at least two "pages".
* The balloon driver operates in units of "pages".

Hi Hollis,

The more I thought about this, the more I think we're not solving this
as neatly as we could. The trigger was noting that we're breaking the userspace API (vring_size and vring_init are exposed to userspace): I know that qemu cut & pastes, but that's no excuse.

Quoted 8 lines
Quoted 4 lines

So instead, I've introduced separate constants for each use. Yes,
all these constants are 12/4096. But just to be contrary, at the end is a patch to change lguest to 128. And there's no reason this couldn't change in future using some guest detection scheme.

OK. I thought it was simpler to just say "4KB everywhere" in all aspects of the virtio interface, but I'm happy as long as we solve the problem somehow. :)

It is simpler, yes, but we can take this opportunity to deconflate them and make things clearer and better than the current code, not just "fix" it.

Note that I still don't have a balloon patch: want to send me one?

Thanks,
Rusty.

#8 lore raw
Quoted 2 lines · Rusty Russell

Note that I still don't have a balloon patch: want to send me one?

linux: virtio-balloon: avoid implicit use of Linux page size in balloon interface

Make the balloon interface always use 4K pages, and convert Linux pfns if necessary. This patch assumes that Linux's PAGE_SHIFT will never be less than 12.

---
Only build-tested.

drivers/virtio/virtio_balloon.c +10 -2
@@ -56,6 +56,14 @@ static struct virtio_device_id id_table[
 	{ 0 },
 };
 
+static u32 page_to_balloon_pfn(struct page *page)
+{
+    unsigned long pfn = page_to_pfn(page);
+
+    /* Convert pfn from Linux page size to balloon page size. */
+    return pfn >> (PAGE_SHIFT - VIRTIO_BALLOON_PFN_SHIFT);
+}
+
 static void balloon_ack(struct virtqueue *vq)
 {
 	struct virtio_balloon *vb;
@@ -99,7 +107,7 @@ static void fill_balloon(struct virtio_b
 			msleep(200);
 			break;
 		}
-		vb->pfns[vb->num_pfns] = page_to_pfn(page);
+		vb->pfns[vb->num_pfns] = page_to_balloon_pfn(page);
 		totalram_pages--;
 		vb->num_pages++;
 		list_add(&page->lru, &vb->pages);
@@ -132,7 +140,7 @@ static void leak_balloon(struct virtio_b
 	for (vb->num_pfns = 0; vb->num_pfns < num; vb->num_pfns++) {
 		page = list_first_entry(&vb->pages, struct page, lru);
 		list_del(&page->lru);
-		vb->pfns[vb->num_pfns] = page_to_pfn(page);
+		vb->pfns[vb->num_pfns] = page_to_balloon_pfn(page);
 		vb->num_pages--;
 	}
 
include/linux/virtio_balloon.h +3 -0
@@ -10,6 +10,9 @@
 /* The feature bitmap for virtio balloon */
 #define VIRTIO_BALLOON_F_MUST_TELL_HOST	0 /* Tell before reclaiming pages */
 
+/* Size of a PFN in the balloon interface. */
+#define VIRTIO_BALLOON_PFN_SHIFT 12
+
 struct virtio_balloon_config
 {
 	/* Number of pages host wants Guest to give up. */
Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#12 lore raw
In reply to a message not in the archive
Quoted 2 lines · Rusty Russell

Note that I still don't have a balloon patch: want to send me one?

qemu: virtio-balloon: don't use TARGET_PAGE_BITS in balloon interface

Make the balloon interface always use 4K pages.

---
Only build-tested.

qemu/hw/virtio-balloon.c +3 -3
@@ -87,7 +87,7 @@ static void virtio_balloon_handle_output
 	    ram_addr_t pa;
 	    ram_addr_t addr;
 
-	    pa = (ram_addr_t)ldl_p(&pfn) << TARGET_PAGE_BITS;
+	    pa = (ram_addr_t)ldl_p(&pfn) << VIRTIO_BALLOON_PFN_SHIFT;
 	    offset += 4;
 
 	    addr = cpu_get_physical_page_desc(pa);
@@ -135,11 +135,11 @@ static ram_addr_t virtio_balloon_to_targ
 	target = ram_size;
 
     if (target) {
-	dev->num_pages = (ram_size - target) >> TARGET_PAGE_BITS;
+	dev->num_pages = (ram_size - target) >> VIRTIO_BALLOON_PFN_SHIFT;
 	virtio_notify_config(&dev->vdev);
     }
 
-    return ram_size - (dev->actual << TARGET_PAGE_BITS);
+    return ram_size - (dev->actual << VIRTIO_BALLOON_PFN_SHIFT);
 }
 
 static void virtio_balloon_save(QEMUFile *f, void *opaque)
qemu/hw/virtio-balloon.h +3 -0
@@ -23,6 +23,9 @@
 /* The feature bitmap for virtio balloon */
 #define VIRTIO_BALLOON_F_MUST_TELL_HOST	0 /* Tell before reclaiming pages */
 
+/* Size of a PFN in the balloon interface. */
+#define VIRTIO_BALLOON_PFN_SHIFT 12
+
 struct virtio_balloon_config
 {
     /* Number of pages host wants Guest to give up. */
Signature · 7 lines
Hollis Blanchard
IBM Linux Technology Center

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#10 lore raw
In reply to a message not in the archive
Quoted 5 lines · On Friday 14 November 2008 08:18:33 Hollis Blanchard wrote:
Quoted 1 line · Rusty Russell

Note that I still don't have a balloon patch: want to send me one?

linux: virtio-balloon: avoid implicit use of Linux page size in balloon interface

Thanks, applied with following diff:

Use tabs to indent, and put BUILD_BUG_ON pagesize assumption.

drivers/virtio/virtio_balloon.c +4 -3
diff -r 50e970613233 drivers/virtio/virtio_balloon.c
@@ -58,10 +58,11 @@
 
 static u32 page_to_balloon_pfn(struct page *page)
 {
-    unsigned long pfn = page_to_pfn(page);
+	unsigned long pfn = page_to_pfn(page);
 
-    /* Convert pfn from Linux page size to balloon page size. */
-    return pfn >> (PAGE_SHIFT - VIRTIO_BALLOON_PFN_SHIFT);
+	BUILD_BUG_ON(PAGE_SHIFT < VIRTIO_BALLOON_PFN_SHIFT);
+	/* Convert pfn from Linux page size to balloon page size. */
+	return pfn >> (PAGE_SHIFT - VIRTIO_BALLOON_PFN_SHIFT);
 }
 
 static void balloon_ack(struct virtqueue *vq)

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html