From patchwork Thu Jul 3 06:10:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Tao X-Patchwork-Id: 366568 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 13214140078 for ; Thu, 3 Jul 2014 16:13:42 +1000 (EST) Received: from localhost ([::1]:57974 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X2aH6-0005R2-5r for incoming@patchwork.ozlabs.org; Thu, 03 Jul 2014 02:13:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X2aGZ-0004Sw-G9 for qemu-devel@nongnu.org; Thu, 03 Jul 2014 02:13:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X2aGU-0001FZ-Qi for qemu-devel@nongnu.org; Thu, 03 Jul 2014 02:13:07 -0400 Received: from [59.151.112.132] (port=3934 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X2aGU-0001FO-Eq for qemu-devel@nongnu.org; Thu, 03 Jul 2014 02:13:02 -0400 X-IronPort-AV: E=Sophos;i="5.00,824,1396972800"; d="scan'208";a="32775968" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 03 Jul 2014 14:10:18 +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 s636Cxf4026902; Thu, 3 Jul 2014 14:12:59 +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; Thu, 3 Jul 2014 14:13:05 +0800 From: Hu Tao To: Date: Thu, 3 Jul 2014 14:10:56 +0800 Message-ID: X-Mailer: git-send-email 1.9.3 In-Reply-To: References: 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: Yasunori Goto , "Michael S. Tsirkin" , Paolo Bonzini , Igor Mammedov Subject: [Qemu-devel] [PATCH for 2.1 2/2] memory-backend-file: improve error handling 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 This patch fixes two problems of memory-backend-file: 1. If user adds a memory-backend-file object using object_add command, specifying a non-existing directory for property mem-path, qemu will core dump with message: /nonexistingdir: No such file or directory Bad ram offset fffffffffffff000 Aborted (core dumped) 2. If user adds a memory-backend-file object using object_add command, specifying a size that is less than huge page size, qemu will core dump with message: Bad ram offset fffffffffffff000 Aborted (core dumped) Signed-off-by: Hu Tao --- exec.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/exec.c b/exec.c index 8c2a91d..35c2dcb 100644 --- a/exec.c +++ b/exec.c @@ -996,7 +996,7 @@ void qemu_mutex_unlock_ramlist(void) #define HUGETLBFS_MAGIC 0x958458f6 -static long gethugepagesize(const char *path) +static long gethugepagesize(const char *path, Error **errp) { struct statfs fs; int ret; @@ -1006,7 +1006,7 @@ static long gethugepagesize(const char *path) } while (ret != 0 && errno == EINTR); if (ret != 0) { - perror(path); + error_setg_errno(errp, errno, "failed to stat file %s", path); return 0; } @@ -1024,17 +1024,19 @@ static void *file_ram_alloc(RAMBlock *block, char *filename; char *sanitized_name; char *c; - void *area; + void *area = NULL; int fd; unsigned long hpagesize; - hpagesize = gethugepagesize(path); + hpagesize = gethugepagesize(path, errp); if (!hpagesize) { goto error; } if (memory < hpagesize) { - return NULL; + error_setg(errp, "memory size 0x" RAM_ADDR_FMT " should be larger " + "than huge page size 0x%" PRIx64, memory, hpagesize); + goto error; } if (kvm_enabled() && !kvm_has_sync_mmu()) { @@ -1094,8 +1096,8 @@ static void *file_ram_alloc(RAMBlock *block, return area; error: - if (mem_prealloc) { - exit(1); + if (area && area != MAP_FAILED) { + munmap(area, memory); } return NULL; }