From mboxrd@z Thu Jan 1 00:00:00 1970 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) From: Igor Mitsyanko Date: Sun, 10 Mar 2013 18:21:49 +0400 Message-Id: <1362925309-3852-4-git-send-email-i.mitsyanko@gmail.com> In-Reply-To: <1362925309-3852-1-git-send-email-i.mitsyanko@gmail.com> References: <1362925309-3852-1-git-send-email-i.mitsyanko@gmail.com> Subject: [Qemu-devel] [PATCH 3/3] memory_region_init_ram_ptr: only allow n*TARGET_PAGE_SIZE memory sizes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: i.mitsyanko@gmail.com, peter.maydell@linaro.org, afaerber@suse.de, anthony@codemonkey.ws, pbonzini@redhat.com 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; -- 1.7.5.4