From patchwork Sun Mar 10 14:21:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mitsyanko X-Patchwork-Id: 226448 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E71C72C0314 for ; Mon, 11 Mar 2013 01:23:37 +1100 (EST) Received: from localhost ([::1]:49108 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEhA0-0004gm-5F for incoming@patchwork.ozlabs.org; Sun, 10 Mar 2013 10:23:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEh8Y-0002PO-RM for qemu-devel@nongnu.org; Sun, 10 Mar 2013 10:22:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UEh8U-0003Dt-A8 for qemu-devel@nongnu.org; Sun, 10 Mar 2013 10:22:06 -0400 Received: from mail-lb0-f172.google.com ([209.85.217.172]:44197) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEh8U-0003Dg-2o for qemu-devel@nongnu.org; Sun, 10 Mar 2013 10:22:02 -0400 Received: by mail-lb0-f172.google.com with SMTP id n8so2493862lbj.31 for ; Sun, 10 Mar 2013 07:22:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=kT8HUMOBx7v8hVdSn25Jei0FttL9/vnH7CZXXqI2DCc=; b=jUfabPesDVuDNmvY1rGSHWFJc/gQWEWcrAAnyJvodbUSMgjYOq+zHI69ZT83Yg74vN mizcodVlrNVNwwiAmaMUgkscz7XvHMenjOMjddLoy/X1iaPiXgfB2mZUJ9Vko4phPwkU Y0ZxeqcIalELvCYENmEFVrhXirOOWjgxq5+bgB0tLCNnrUrz8m6hrju+M/BBuzSsTTLF PfzAYrDPWOROiPzAYBAmjiDA6WyRndgQaNsaUWsLq5c3pmlbMjNvuqQ7uGcN+gPILJdD Dwb21MKzKjZniGpsZolATJmRKPzr1IMp/dqX1K3A/rDhOzff82eS//7X/Z11G8AR9q78 NBqQ== X-Received: by 10.152.144.105 with SMTP id sl9mr7484737lab.4.1362925321150; Sun, 10 Mar 2013 07:22:01 -0700 (PDT) Received: from localhost ([79.164.43.133]) by mx.google.com with ESMTPS id go12sm5692122lab.3.2013.03.10.07.21.59 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 10 Mar 2013 07:22:00 -0700 (PDT) From: Igor Mitsyanko To: qemu-devel@nongnu.org Date: Sun, 10 Mar 2013 18:21:49 +0400 Message-Id: <1362925309-3852-4-git-send-email-i.mitsyanko@gmail.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1362925309-3852-1-git-send-email-i.mitsyanko@gmail.com> References: <1362925309-3852-1-git-send-email-i.mitsyanko@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.217.172 Cc: i.mitsyanko@gmail.com, peter.maydell@linaro.org, afaerber@suse.de, anthony@codemonkey.ws, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 3/3] memory_region_init_ram_ptr: only allow n*TARGET_PAGE_SIZE memory sizes 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 Registering memory regions using preallocated memory which size is not a multiple of target page size will result in inconsistency in QEMU memory system. Do not allow to do that at all by checking for that case (and asserting) in memory_region_init_ram_ptr(). Signed-off-by: Igor Mitsyanko --- include/exec/memory.h | 2 +- memory.c | 1 + 2 files changed, 2 insertions(+), 1 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 2322732..87b9292 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -279,7 +279,7 @@ void memory_region_init_ram(MemoryRegion *mr, * * @mr: the #MemoryRegion to be initialized. * @name: the name of the region. - * @size: size of the region. + * @size: size of the region. Must be a multiple of target page size. * @ptr: memory to be mapped; must contain at least @size bytes. */ void memory_region_init_ram_ptr(MemoryRegion *mr, diff --git a/memory.c b/memory.c index 92a2196..15cb47f 100644 --- a/memory.c +++ b/memory.c @@ -949,6 +949,7 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, uint64_t size, void *ptr) { + assert((size & (TARGET_PAGE_SIZE - 1)) == 0); memory_region_init(mr, name, size); mr->ram = true; mr->terminates = true;