From patchwork Fri Sep 26 07:32:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Tao X-Patchwork-Id: 393546 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 764651400F1 for ; Fri, 26 Sep 2014 17:36:58 +1000 (EST) Received: from localhost ([::1]:45160 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XXQ5H-0007Go-2L for incoming@patchwork.ozlabs.org; Fri, 26 Sep 2014 03:36:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59200) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XXQ4v-00070E-L7 for qemu-devel@nongnu.org; Fri, 26 Sep 2014 03:36:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XXQ4r-0003Gk-26 for qemu-devel@nongnu.org; Fri, 26 Sep 2014 03:36:33 -0400 Received: from [59.151.112.132] (port=6349 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XXQ4q-0003EE-Mu for qemu-devel@nongnu.org; Fri, 26 Sep 2014 03:36:28 -0400 X-IronPort-AV: E=Sophos;i="5.04,603,1406563200"; d="scan'208";a="36507030" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Sep 2014 15:31:39 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s8Q7YhSt023925; Fri, 26 Sep 2014 15:34:43 +0800 Received: from G08FNSTD100614.fnst.cn.fujitsu.com (10.167.226.102) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Fri, 26 Sep 2014 15:34:45 +0800 From: Hu Tao To: Date: Fri, 26 Sep 2014 15:32:09 +0800 Message-ID: X-Mailer: git-send-email 1.9.3 MIME-Version: 1.0 X-Originating-IP: [10.167.226.102] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: Paolo Bonzini Subject: [Qemu-devel] [PATCH] exec: don't exit if failed to preallocate memory for memory-backend-file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When using monitor command object_add to add a memory backend file but failed to preallocate memory for it, qemu exits silently. So a unexpected user input, e.g. a too large size of memory-backend-file can crash the guest. This is the case of -mem-prealloc, not memory-backend-file,prealloc=y. The problem can be reproduced as follows: 1. run qemu with -mem-prealloc: ./x86_64-softmmu/qemu-system-x86_64 -hda f18.img \ -m 512 -mem-prealloc -qmp unix:/tmp/m,server,nowait \ -monitor stdio -enable-kvm 2. add a memory-backend-file object from qemu monitor whose size is larger than host memory(assume host has 4G memory total): (qemu)object_add memory-backend-file,size=4G,mem-path=/hugepages,id=mem-file0 Without this patch, qemu quits with message: unable to map backing store for hugepages: Cannot allocate memory With this patch, qemu gives the same message, but continues running. Signed-off-by: Hu Tao --- exec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index 759055d..eed5da2 100644 --- a/exec.c +++ b/exec.c @@ -1163,9 +1163,9 @@ static void *file_ram_alloc(RAMBlock *block, return area; error: - if (mem_prealloc) { + if (area && area != MAP_FAILED) { error_report("%s\n", error_get_pretty(*errp)); - exit(1); + munmap(area, memory); } return NULL; }