From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: [PATCH] virtio-balloon: do not attempt to release more than available pages Date: Wed, 5 Mar 2008 13:28:32 -0300 Message-ID: <20080305162832.GA11563@dmt> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm-devel To: Rusty Russell Return-path: Content-Disposition: inline List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces@lists.sourceforge.net Errors-To: kvm-devel-bounces@lists.sourceforge.net List-Id: kvm.vger.kernel.org Handle the case where the balloon target is larger than total ram size. BUG: unable to handle kernel paging request at 0000000000100100 IP: [] :virtio_balloon:leak__balloon+0x2e/0xbe Signed-off-by: Marcelo Tosatti Index: virtio/virtio_balloon.c =================================================================== --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -122,10 +122,21 @@ static void release_pages_by_pfn(const u } } +static void update_target_size(struct virtio_balloon *vb) +{ + __le32 num_pages = cpu_to_le32(vb->num_pages); + + vb->vdev->config->set(vb->vdev, + offsetof(struct virtio_balloon_config, num_pages), + &num_pages, sizeof(num_pages)); +} + + static void leak_balloon(struct virtio_balloon *vb, size_t num) { struct page *page; + num = min_t(unsigned int, vb->num_pages, num); /* We can only do one array worth at a time. */ num = min(num, ARRAY_SIZE(vb->pfns)); @@ -136,6 +147,12 @@ static void leak_balloon(struct virtio_b vb->num_pages--; } + /* Have nothing to release? update target accordingly. */ + if (vb->num_pfns == 0) { + update_target_size(vb); + return; + } + if (vb->tell_host_first) { tell_host(vb, vb->deflate_vq); release_pages_by_pfn(vb->pfns, vb->num_pfns); ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/