Received: from eggs.gnu.org ([140.186.70.92]:58078) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QJTkl-00076q-DR for qemu-devel@nongnu.org; Mon, 09 May 2011 12:56:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QJTkk-0007E0-Di for qemu-devel@nongnu.org; Mon, 09 May 2011 12:56:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45456) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QJTkk-0007Dw-6g for qemu-devel@nongnu.org; Mon, 09 May 2011 12:56:14 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p49GuCLb019386 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 9 May 2011 12:56:12 -0400 From: Alex Williamson Date: Mon, 09 May 2011 10:56:11 -0600 Message-ID: <20110509165531.12175.79287.stgit@s20.home> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [RFC PATCH] virtio-balloon: Re-register memory as balloon deflates List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com When we balloon a guest, we currently use madvise to let the underlying VM know our intentions for those pages. As the balloon inflates (pages given back to the host), MMU notifiers in the host let us detach the pages. When we deflate the balloon and retrieve pages back from the host, I'm not sure how we inform drivers about this. It seems like we need something like below to re-map these pages in qemu. Ideally we might also map them to IO_MEM_UNASSIGNED when we madvise DONTNEED, but that would probably blow-up kvm's slot map. With something like this, I can support ballooning with vfio assigned devices. An MMU notifier in the vfio kernel module unmaps pages as they get marked DONTNEED, and this allows us to re-map them as they get marked WILLNEED. If there's already something in place to handle this, please send a pointer. Thanks, Alex Signed-off-by: Alex Williamson --- hw/virtio-balloon.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c index 70a8710..96b7d7b 100644 --- a/hw/virtio-balloon.c +++ b/hw/virtio-balloon.c @@ -108,16 +108,20 @@ static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq) uint32_t pfn; while (iov_to_buf(elem.out_sg, elem.out_num, &pfn, offset, 4) == 4) { - ram_addr_t pa; + target_phys_addr_t pa; ram_addr_t addr; - pa = (ram_addr_t)ldl_p(&pfn) << VIRTIO_BALLOON_PFN_SHIFT; + pa = (target_phys_addr_t)ldl_p(&pfn) << VIRTIO_BALLOON_PFN_SHIFT; offset += 4; addr = cpu_get_physical_page_desc(pa); if ((addr & ~TARGET_PAGE_MASK) != IO_MEM_RAM) continue; + if (vq == s->dvq) { + cpu_register_physical_memory(pa, TARGET_PAGE_SIZE, addr); + } + /* Using qemu_get_ram_ptr is bending the rules a bit, but should be OK because we only want a single page. */ balloon_page(qemu_get_ram_ptr(addr), !!(vq == s->dvq));