From patchwork Wed Nov 2 01:05:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9408367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1239360721 for ; Wed, 2 Nov 2016 01:06:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F00EE29AD2 for ; Wed, 2 Nov 2016 01:06:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E154F29C08; Wed, 2 Nov 2016 01:06:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 49E9A29AD2 for ; Wed, 2 Nov 2016 01:06:50 +0000 (UTC) Received: from localhost ([::1]:52012 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1k0v-0003e9-Ij for patchwork-qemu-devel@patchwork.kernel.org; Tue, 01 Nov 2016 21:06:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45395) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1k0X-0003aS-It for qemu-devel@nongnu.org; Tue, 01 Nov 2016 21:06:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1k0S-0006YJ-9M for qemu-devel@nongnu.org; Tue, 01 Nov 2016 21:06:25 -0400 Received: from mga05.intel.com ([192.55.52.43]:40691) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c1k0S-0006Xw-1q for qemu-devel@nongnu.org; Tue, 01 Nov 2016 21:06:20 -0400 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP; 01 Nov 2016 18:06:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,582,1473145200"; d="scan'208";a="26705357" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.148]) by orsmga004.jf.intel.com with ESMTP; 01 Nov 2016 18:06:17 -0700 From: Haozhong Zhang To: Paolo Bonzini , Eduardo Habkost Date: Wed, 2 Nov 2016 09:05:51 +0800 Message-Id: <20161102010551.2723-1-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161027042300.5929-3-haozhong.zhang@intel.com> References: <20161027042300.5929-3-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.43 Subject: [Qemu-devel] [RESEND PATCH v2 2/3] exec.c: check memory backend file size with 'size' option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Igor Mammedov , Richard Henderson , qemu-devel@nongnu.org, Haozhong Zhang , Peter Crosthwaite Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP If the memory backend file is not large enough to hold the required 'size', Qemu will report error and exit. Signed-off-by: Haozhong Zhang Message-Id: <20161027042300.5929-3-haozhong.zhang@intel.com> Reviewed-by: Eduardo Habkost --- Changes in RESEND: * Use format string RAM_ADDR_FMT for variable 'memory'. This change is to fix the build error. * Add Eduardo's r-b. * Add the message id of this thread. --- exec.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/exec.c b/exec.c index a2b371a..23c21c2 100644 --- a/exec.c +++ b/exec.c @@ -1316,6 +1316,13 @@ static void *file_ram_alloc(RAMBlock *block, goto error; } + if (file_size > 0 && file_size < memory) { + error_setg(errp, "backing store %s size 0x%" PRIx64 + " does not match 'size' option 0x" RAM_ADDR_FMT, + path, file_size, memory); + goto error; + } + memory = ROUND_UP(memory, block->page_size); /*