From patchwork Mon May 9 16:56:11 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 94824 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D57B3B6F1B for ; Tue, 10 May 2011 02:56:32 +1000 (EST) Received: from localhost ([::1]:60334 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QJTky-0007Bc-Vw for incoming@patchwork.ozlabs.org; Mon, 09 May 2011 12:56:28 -0400 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 Received: from s20.home (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p49GuBrd017063; Mon, 9 May 2011 12:56:12 -0400 From: Alex Williamson To: qemu-devel@nongnu.org Date: Mon, 09 May 2011 10:56:11 -0600 Message-ID: <20110509165531.12175.79287.stgit@s20.home> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: alex.williamson@redhat.com Subject: [Qemu-devel] [RFC PATCH] virtio-balloon: Re-register memory as balloon deflates X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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));