From mboxrd@z Thu Jan 1 00:00:00 1970 From: Liming Wang Subject: [PATCH 2/3] kvm tools: check negative value of num_pages Date: Thu, 11 Aug 2011 15:21:59 +0800 Message-ID: <1313047319-20293-1-git-send-email-walimisdev@gmail.com> References: <1313047370.3456.3.camel@lappy> Mime-Version: 1.0 Content-Type: text/plain Cc: Sasha Levin , Ingo Molnar , Asias He , To: Pekka Enberg Return-path: Received: from mail.windriver.com ([147.11.1.11]:43376 "EHLO mail.windriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751121Ab1HKHiJ (ORCPT ); Thu, 11 Aug 2011 03:38:09 -0400 In-Reply-To: <1313047370.3456.3.camel@lappy> Sender: kvm-owner@vger.kernel.org List-ID: If num_pages is negative, balloon will make kernel crash with "out of memory". So we check this value to avoid it to be negative. Signed-off-by: Liming Wang --- tools/kvm/virtio/balloon.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/kvm/virtio/balloon.c b/tools/kvm/virtio/balloon.c index 854d04b..941023e 100644 --- a/tools/kvm/virtio/balloon.c +++ b/tools/kvm/virtio/balloon.c @@ -220,10 +220,14 @@ static struct ioport_operations virtio_bln_io_ops = { static void handle_sigmem(int sig) { - if (sig == SIGKVMADDMEM) + if (sig == SIGKVMADDMEM) { bdev.config.num_pages += 256; - else + } else { + if (bdev.config.num_pages < 256){ + return; + } bdev.config.num_pages -= 256; + } /* Notify that the configuration space has changed */ bdev.isr = VIRTIO_PCI_ISR_CONFIG; -- 1.7.0.4