[patch 2/3] QEMU: balloon: dont allow target larger than ram size

Marcelo Tosatti
2008-03-12T19:17:22Z

[-- Attachment #1: larger-ram-size --]
[-- Type: text/plain, Size: 1064 bytes --]

Truncate the target size to be at most ram size.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Index: kvm-userspace.balloon/qemu/hw/virtio-balloon.c
===================================================================
--- kvm-userspace.balloon.orig/qemu/hw/virtio-balloon.c
+++ kvm-userspace.balloon/qemu/hw/virtio-balloon.c
@@ -16,6 +16,7 @@
#include "pc.h"
#include "balloon.h"
#include "sysemu.h"
+#include "console.h"

#include <sys/mman.h>

@@ -115,6 +116,10 @@ static ram_addr_t virtio_balloon_to_targ
VirtIOBalloon *dev = opaque;

if (target) {
+ if (target > ram_size) {
+ term_printf("target larger than ram size, truncating\n");
+ target = ram_size;
+ }
dev->num_pages = (ram_size - target) >> TARGET_PAGE_BITS;
virtio_notify_config(&dev->vdev);
}