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