From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hollis Blanchard Subject: Re: [PATCH] [v2] linux: virtio: Standardize virtio's concept of "page size" Date: Thu, 13 Nov 2008 15:48:33 -0600 Message-ID: <1226612913.5339.42.camel@localhost.localdomain> References: <200811122251.14159.rusty@rustcorp.com.au> <1226506591.19156.10.camel@localhost.localdomain> <200811130844.57749.rusty@rustcorp.com.au> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Cc: aliguori@us.ibm.com, markmc@redhat.com, xiantao.zhang@intel.com, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org To: Rusty Russell Return-path: Received: from e36.co.us.ibm.com ([32.97.110.154]:47465 "EHLO e36.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751819AbYKMVsl (ORCPT ); Thu, 13 Nov 2008 16:48:41 -0500 In-Reply-To: <200811130844.57749.rusty@rustcorp.com.au> Sender: kvm-owner@vger.kernel.org List-ID: On Thu, 2008-11-13 at 08:44 +1030, Rusty Russell wrote: > > 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. Signed-off-by: Hollis Blanchard --- Only build-tested. diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -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--; } diff --git a/include/linux/virtio_balloon.h b/include/linux/virtio_balloon.h --- a/include/linux/virtio_balloon.h +++ b/include/linux/virtio_balloon.h @@ -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. */ -- Hollis Blanchard IBM Linux Technology Center