From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ww7Cq-0007bX-4t for qemu-devel@nongnu.org; Sun, 15 Jun 2014 05:58:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ww7Cl-00051v-GB for qemu-devel@nongnu.org; Sun, 15 Jun 2014 05:58:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45794) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ww7Cl-00050Q-6n for qemu-devel@nongnu.org; Sun, 15 Jun 2014 05:58:27 -0400 Date: Sun, 15 Jun 2014 12:58:47 +0300 From: "Michael S. Tsirkin" Message-ID: <20140615095847.GA11294@redhat.com> References: <0c6badd4ed1f0f3af9de36e4b5a17952922fdd05.1402720673.git.hutao@cn.fujitsu.com> <539C815B.3000203@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <539C815B.3000203@redhat.com> Subject: Re: [Qemu-devel] [PATCH RFC 3/4] exec: don't exit unconditionally if failed to allocate memory List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Hu Tao , Igor Mammedov , qemu-devel@nongnu.org, Yasunori Goto On Sat, Jun 14, 2014 at 07:07:39PM +0200, Paolo Bonzini wrote: > Il 14/06/2014 06:48, Hu Tao ha scritto: > >return -1 instead. > > > >Now user can add objects memory-backend-ram on-the-fly, fail it if > >cannot allocate memory rather than quit qemu. > > > >Signed-off-by: Hu Tao > > This needs an audit of all callers or, alternatively, we need to add > memory_region_init_ram_nofail. Better leave it for after the merge. > > Paolo Specifically memory_region_init_ram_from_file does not seem to handle failures. qemu_ram_free chunk also looks weird. Can we not avoid calling free on invalid addresses? > >--- > > backends/hostmem-ram.c | 3 +++ > > exec.c | 6 +++++- > > 2 files changed, 8 insertions(+), 1 deletion(-) > > > >diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c > >index d9a8290..afb305d 100644 > >--- a/backends/hostmem-ram.c > >+++ b/backends/hostmem-ram.c > >@@ -28,6 +28,9 @@ ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) > > path = object_get_canonical_path_component(OBJECT(backend)); > > memory_region_init_ram(&backend->mr, OBJECT(backend), path, > > backend->size); > >+ if (backend->mr.ram_addr == -1) { > >+ error_setg(errp, "can't allocate memory"); > >+ } > > g_free(path); > > } > > > >diff --git a/exec.c b/exec.c > >index 8705cc5..74560e5 100644 > >--- a/exec.c > >+++ b/exec.c > >@@ -1228,7 +1228,7 @@ static ram_addr_t ram_block_add(RAMBlock *new_block) > > if (!new_block->host) { > > fprintf(stderr, "Cannot set up guest memory '%s': %s\n", > > new_block->mr->name, strerror(errno)); > >- exit(1); > >+ return -1; > > } > > memory_try_enable_merging(new_block->host, new_block->length); > > } > >@@ -1356,6 +1356,10 @@ void qemu_ram_free(ram_addr_t addr) > > { > > RAMBlock *block; > > > >+ if (addr == -1) { > >+ return; > >+ } > >+ > > /* This assumes the iothread lock is taken here too. */ > > qemu_mutex_lock_ramlist(); > > QTAILQ_FOREACH(block, &ram_list.blocks, next) { > >