yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-exec-Don-t-abort-when-we-can-t-allocate-guest-memory.patch

218e99
From 37bd9dc61bdc4d1a295403360cb0dcab7fbb8936 Mon Sep 17 00:00:00 2001
218e99
From: Markus Armbruster <armbru@redhat.com>
218e99
Date: Wed, 18 Sep 2013 09:31:08 +0200
218e99
Subject: [PATCH 24/29] exec: Don't abort when we can't allocate guest memory
218e99
MIME-Version: 1.0
218e99
Content-Type: text/plain; charset=UTF-8
218e99
Content-Transfer-Encoding: 8bit
218e99
218e99
RH-Author: Markus Armbruster <armbru@redhat.com>
218e99
Message-id: <1379496669-22778-8-git-send-email-armbru@redhat.com>
218e99
Patchwork-id: 54425
218e99
O-Subject: [PATCH 7.0 qemu-kvm 7/8] exec: Don't abort when we can't allocate guest memory
218e99
Bugzilla: 1009328
218e99
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
218e99
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
218e99
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
218e99
From: Markus Armbruster <armbru@redhat.com>
218e99
218e99
We abort() on memory allocation failure.  abort() is appropriate for
218e99
programming errors.  Maybe most memory allocation failures are
218e99
programming errors, maybe not.  But guest memory allocation failure
218e99
isn't, and aborting when the user asks for more memory than we can
218e99
provide is not nice.  exit(1) instead, and do it in just one place, so
218e99
the error message is consistent.
218e99
218e99
Tested-by: Christian Borntraeger <borntraeger@de.ibm.com>
218e99
Signed-off-by: Markus Armbruster <armbru@redhat.com>
218e99
Reviewed-by: Andreas Färber <afaerber@suse.de>
218e99
Acked-by: Laszlo Ersek <lersek@redhat.com>
218e99
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
218e99
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
218e99
Message-id: 1375276272-15988-8-git-send-email-armbru@redhat.com
218e99
Signed-off-by: Anthony Liguori <anthony@codemonkey.ws>
218e99
(cherry picked from commit 39228250ce6cf67eb1c3799791d271f53c5c6347)
218e99
---
218e99
 exec.c             | 5 +++++
218e99
 target-s390x/kvm.c | 6 +-----
218e99
 util/oslib-posix.c | 4 +---
218e99
 util/oslib-win32.c | 5 +----
218e99
 4 files changed, 8 insertions(+), 12 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 exec.c             |    5 +++++
218e99
 target-s390x/kvm.c |    6 +-----
218e99
 util/oslib-posix.c |    4 +---
218e99
 util/oslib-win32.c |    5 +----
218e99
 4 files changed, 8 insertions(+), 12 deletions(-)
218e99
218e99
diff --git a/exec.c b/exec.c
218e99
index a75c200..9117a59 100644
218e99
--- a/exec.c
218e99
+++ b/exec.c
218e99
@@ -1097,6 +1097,11 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
218e99
         }
218e99
         if (!new_block->host) {
218e99
             new_block->host = phys_mem_alloc(size);
218e99
+            if (!new_block->host) {
218e99
+                fprintf(stderr, "Cannot set up guest memory '%s': %s\n",
218e99
+                        new_block->mr->name, strerror(errno));
218e99
+                exit(1);
218e99
+            }
218e99
             memory_try_enable_merging(new_block->host, size);
218e99
         }
218e99
     }
218e99
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
218e99
index 0b18db4..a106e62 100644
218e99
--- a/target-s390x/kvm.c
218e99
+++ b/target-s390x/kvm.c
218e99
@@ -331,11 +331,7 @@ static void *legacy_s390_alloc(ram_addr_t size)
218e99
     mem = mmap((void *) 0x800000000ULL, size,
218e99
                PROT_EXEC|PROT_READ|PROT_WRITE,
218e99
                MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
218e99
-    if (mem == MAP_FAILED) {
218e99
-        fprintf(stderr, "Allocating RAM failed\n");
218e99
-        abort();
218e99
-    }
218e99
-    return mem;
218e99
+    return mem == MAP_FAILED ? NULL : mem;
218e99
 }
218e99
 
218e99
 int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)
218e99
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
218e99
index 3dc8b1b..253bc3d 100644
218e99
--- a/util/oslib-posix.c
218e99
+++ b/util/oslib-posix.c
218e99
@@ -112,9 +112,7 @@ void *qemu_anon_ram_alloc(size_t size)
218e99
     size_t offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr;
218e99
 
218e99
     if (ptr == MAP_FAILED) {
218e99
-        fprintf(stderr, "Failed to allocate %zu B: %s\n",
218e99
-                size, strerror(errno));
218e99
-        abort();
218e99
+        return NULL;
218e99
     }
218e99
 
218e99
     ptr += offset;
218e99
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
218e99
index 961fbf5..983b7a2 100644
218e99
--- a/util/oslib-win32.c
218e99
+++ b/util/oslib-win32.c
218e99
@@ -65,10 +65,7 @@ void *qemu_anon_ram_alloc(size_t size)
218e99
     /* FIXME: this is not exactly optimal solution since VirtualAlloc
218e99
        has 64Kb granularity, but at least it guarantees us that the
218e99
        memory is page aligned. */
218e99
-    if (!size) {
218e99
-        abort();
218e99
-    }
218e99
-    ptr = qemu_oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE));
218e99
+    ptr = VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
218e99
     trace_qemu_anon_ram_alloc(size, ptr);
218e99
     return ptr;
218e99
 }
218e99
-- 
218e99
1.7.1
218e99