From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:34259) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEl9Z-00083Q-M7 for qemu-devel@nongnu.org; Sun, 10 Mar 2013 14:39:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UEl9W-0004hu-T6 for qemu-devel@nongnu.org; Sun, 10 Mar 2013 14:39:25 -0400 Received: from mail-la0-x22c.google.com ([2a00:1450:4010:c03::22c]:62150) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEl9W-0004ho-LY for qemu-devel@nongnu.org; Sun, 10 Mar 2013 14:39:22 -0400 Received: by mail-la0-f44.google.com with SMTP id eb20so3208965lab.31 for ; Sun, 10 Mar 2013 11:39:21 -0700 (PDT) Message-ID: <513CD355.7020906@gmail.com> Date: Sun, 10 Mar 2013 22:39:17 +0400 From: Igor Mitsyanko MIME-Version: 1.0 References: <1362925309-3852-1-git-send-email-i.mitsyanko@gmail.com> <1362925309-3852-4-git-send-email-i.mitsyanko@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [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: Peter Maydell Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, anthony@codemonkey.ws, afaerber@suse.de On 10.03.2013 18:27, Peter Maydell wrote: > On 10 March 2013 22:21, Igor Mitsyanko wrote: >> 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(). > This is too vague. What exactly is the problem and why can't we > just fix the memory system to correctly handle being passed > small preallocated memory areas? The problem I've personally encountered is the one I described in PATCH 1. When saving a VM state, QEMU is looping forever in ram_save_block() trying to save chipid_and_omr memory region. This is because migration_bitmap_find_and_reset_dirty() works on memory blocks of TARGET_PAGE_SIZE length. There could be other places where problem could occur I think. Its not really related to an actual TARGET_PAGE_SIZE and its length, what important is to be consistent in minimal memory length requirements. For example, when we pass size=1 byte to memory_region_init_ram_ptr(), it sets MemoryRegion::size to 1 byte, but at the same time, it sets corresponding RAMBlock::size to TARGET_PAGE_ALIGN(1). And now we have a situation when some parts of QEMU think that it can access the whole TARGET_PAGE_SIZE region, while we actually allocated only 1 byte for it. Same goes for migration, it operates on TARGET_PAGE_SIZE-length data blocks only. What I mean to say is, it looks like QEMU has an implicit assumption that RAM length should be a multiple of page size length? > >> --- 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); > This in particular seems like a bad idea, because TARGET_PAGE_SIZE > is a per-CPU thing, and we shouldn't be adding more code to QEMU which > will need to be fixed if/when we ever support multiple CPU types in > a single binary. (Also TARGET_PAGE_SIZE isn't necessarily what you > think it is: for instance on ARM it's actually only 1K even though > the standard ARM setup is 4K pages.) > > thanks > -- PMM