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 <walimisdev@xxxxxxxxx> --- tools/kvm/virtio/balloon.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/tools/kvm/virtio/balloon.c b/tools/kvm/virtio/balloon.c index 854d04b..0223ee4 100644 --- a/tools/kvm/virtio/balloon.c +++ b/tools/kvm/virtio/balloon.c @@ -222,8 +222,13 @@ static void handle_sigmem(int sig) { if (sig == SIGKVMADDMEM) bdev.config.num_pages += 256; - else + else { bdev.config.num_pages -= 256; + if ((s32)bdev.config.num_pages < 0){ + bdev.config.num_pages = 0; + return; + } + } /* Notify that the configuration space has changed */ bdev.isr = VIRTIO_PCI_ISR_CONFIG; -- 1.7.0.4 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html