From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4XLs-0001uI-CR for qemu-devel@nongnu.org; Wed, 31 Jul 2013 10:26:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V4XLl-0001vV-ML for qemu-devel@nongnu.org; Wed, 31 Jul 2013 10:26:08 -0400 Received: from cantor2.suse.de ([195.135.220.15]:37648 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4Wo7-00058A-El for qemu-devel@nongnu.org; Wed, 31 Jul 2013 09:51:15 -0400 Message-ID: <51F9164C.8070205@suse.de> Date: Wed, 31 Jul 2013 15:51:08 +0200 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1375276272-15988-1-git-send-email-armbru@redhat.com> <1375276272-15988-8-git-send-email-armbru@redhat.com> In-Reply-To: <1375276272-15988-8-git-send-email-armbru@redhat.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 for 1.6 7/8] exec: Don't abort when we can't allocate guest memory List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: peter.maydell@linaro.org, stefano.stabellini@eu.citrix.com, mtosatti@redhat.com, qemu-devel@nongnu.org, agraf@suse.de, borntraeger@de.ibm.com, mkletzan@redhat.com, pbonzini@redhat.com, rth@twiddle.net Am 31.07.2013 15:11, schrieb Markus Armbruster: > We abort() on memory allocation failure. abort() is appropriate for > programming errors. Maybe most memory allocation failures are > programming errors, maybe not. But guest memory allocation failure > isn't, and aborting when the user asks for more memory than we can > provide is not nice. exit(1) instead, and do it in just one place, so > the error message is consistent. >=20 > Tested-by: Christian Borntraeger > Signed-off-by: Markus Armbruster > --- > exec.c | 5 +++++ > target-s390x/kvm.c | 6 +----- > util/oslib-posix.c | 4 +--- > util/oslib-win32.c | 5 +---- > 4 files changed, 8 insertions(+), 12 deletions(-) >=20 > diff --git a/exec.c b/exec.c > index 231d04e..0cfca3a 100644 > --- a/exec.c > +++ b/exec.c > @@ -1162,6 +1162,11 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t si= ze, void *host, > } > if (!new_block->host) { > new_block->host =3D phys_mem_alloc(size); > + if (!new_block->host) { > + fprintf(stderr, "Cannot set up guest memory '%s': %s\n= ", > + new_block->mr->name, strerror(errno)); This could use error_report() while at it, but still Reviewed-by: Andreas F=E4rber Thought I had ack'ed it long ago, but I guess something minor changed. Cheers, Andreas > + exit(1); > + } > memory_try_enable_merging(new_block->host, size); > } > } > diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c > index b5351e6..c4a0fdd 100644 > --- a/target-s390x/kvm.c > +++ b/target-s390x/kvm.c > @@ -331,11 +331,7 @@ static void *legacy_s390_alloc(ram_addr_t size) > mem =3D mmap((void *) 0x800000000ULL, size, > PROT_EXEC|PROT_READ|PROT_WRITE, > MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0); > - if (mem =3D=3D MAP_FAILED) { > - fprintf(stderr, "Allocating RAM failed\n"); > - abort(); > - } > - return mem; > + return mem =3D=3D MAP_FAILED ? NULL : mem; > } > =20 > int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoi= nt *bp) > diff --git a/util/oslib-posix.c b/util/oslib-posix.c > index 3dc8b1b..253bc3d 100644 > --- a/util/oslib-posix.c > +++ b/util/oslib-posix.c > @@ -112,9 +112,7 @@ void *qemu_anon_ram_alloc(size_t size) > size_t offset =3D QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_= t)ptr; > =20 > if (ptr =3D=3D MAP_FAILED) { > - fprintf(stderr, "Failed to allocate %zu B: %s\n", > - size, strerror(errno)); > - abort(); > + return NULL; > } > =20 > ptr +=3D offset; > diff --git a/util/oslib-win32.c b/util/oslib-win32.c > index 961fbf5..983b7a2 100644 > --- a/util/oslib-win32.c > +++ b/util/oslib-win32.c > @@ -65,10 +65,7 @@ void *qemu_anon_ram_alloc(size_t size) > /* FIXME: this is not exactly optimal solution since VirtualAlloc > has 64Kb granularity, but at least it guarantees us that the > memory is page aligned. */ > - if (!size) { > - abort(); > - } > - ptr =3D qemu_oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_R= EADWRITE)); > + ptr =3D VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE); > trace_qemu_anon_ram_alloc(size, ptr); > return ptr; > } >=20 --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg