From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxEIi-0007dl-Bn for qemu-devel@nongnu.org; Tue, 26 May 2015 08:49:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YxEIe-0002yV-8V for qemu-devel@nongnu.org; Tue, 26 May 2015 08:49:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55011) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxEIe-0002yM-0v for qemu-devel@nongnu.org; Tue, 26 May 2015 08:49:40 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 9BDE38E90B for ; Tue, 26 May 2015 12:49:39 +0000 (UTC) Date: Tue, 26 May 2015 20:49:36 +0800 From: Fam Zheng Message-ID: <20150526124936.GB13749@ad.nay.redhat.com> References: <1430152117-100558-1-git-send-email-pbonzini@redhat.com> <1430152117-100558-30-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1430152117-100558-30-git-send-email-pbonzini@redhat.com> Subject: Re: [Qemu-devel] [PATCH 29/29] memory: strengthen assertions on mr->terminates List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org, stefanha@redhat.com, mst@redhat.com On Mon, 04/27 18:28, Paolo Bonzini wrote: > mr->terminates alone doesn't guarantee that we are looking at a RAM region. > mr->ram_addr also has to be checked, in order to distinguish RAM and I/O > regions. > > IOMMU regions were not setting mr->ram_addr to a bogus value, do it now > so that the assertions would fire for IOMMU regions as well. > > Signed-off-by: Paolo Bonzini It would be nicer to introduce a memory_region_is_ram(MemoryRegion *mr), the ~(ram_addr_t) duplications are too many. Fam > --- > memory.c | 15 ++++++++------- > 1 file changed, 8 insertions(+), 7 deletions(-) > > diff --git a/memory.c b/memory.c > index bb86b4b..82d9df6 100644 > --- a/memory.c > +++ b/memory.c > @@ -1242,6 +1242,7 @@ void memory_region_init_iommu(MemoryRegion *mr, > memory_region_init(mr, owner, name, size); > mr->iommu_ops = ops, > mr->terminates = true; /* then re-forwards */ > + mr->ram_addr = ~(ram_addr_t)0; > notifier_list_init(&mr->iommu_notify); > } > > @@ -1382,14 +1383,14 @@ void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client) > bool memory_region_get_dirty(MemoryRegion *mr, hwaddr addr, > hwaddr size, unsigned client) > { > - assert(mr->terminates); > + assert(mr->terminates && mr->ram_addr != ~(ram_addr_t)0); > return cpu_physical_memory_get_dirty(mr->ram_addr + addr, size, client); > } > > void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr, > hwaddr size) > { > - assert(mr->terminates); > + assert(mr->terminates && mr->ram_addr != ~(ram_addr_t)0); > cpu_physical_memory_set_dirty_range(mr->ram_addr + addr, size, > memory_region_get_dirty_log_mask(mr)); > } > @@ -1397,7 +1398,7 @@ void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr, > bool memory_region_test_and_clear_dirty(MemoryRegion *mr, hwaddr addr, > hwaddr size, unsigned client) > { > - assert(mr->terminates); > + assert(mr->terminates && mr->ram_addr != ~(ram_addr_t)0); > return cpu_physical_memory_test_and_clear_dirty(mr->ram_addr + addr, > size, client); > } > @@ -1442,7 +1443,7 @@ void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode) > void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr, > hwaddr size, unsigned client) > { > - assert(mr->terminates); > + assert(mr->terminates && mr->ram_addr != ~(ram_addr_t)0); > cpu_physical_memory_test_and_clear_dirty(mr->ram_addr + addr, size, > client); > } > @@ -1453,7 +1454,7 @@ int memory_region_get_fd(MemoryRegion *mr) > return memory_region_get_fd(mr->alias); > } > > - assert(mr->terminates); > + assert(mr->terminates && mr->ram_addr != ~(ram_addr_t)0); > > return qemu_get_ram_fd(mr->ram_addr & TARGET_PAGE_MASK); > } > @@ -1464,14 +1465,14 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr) > return memory_region_get_ram_ptr(mr->alias) + mr->alias_offset; > } > > - assert(mr->terminates); > + assert(mr->terminates && mr->ram_addr != ~(ram_addr_t)0); > > return qemu_get_ram_ptr(mr->ram_addr & TARGET_PAGE_MASK); > } > > void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize, Error **errp) > { > - assert(mr->terminates); > + assert(mr->terminates && mr->ram_addr != ~(ram_addr_t)0); > > qemu_ram_resize(mr->ram_addr, newsize, errp); > } > -- > 1.8.3.1 >