From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52987) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxELA-0001wA-8P for qemu-devel@nongnu.org; Tue, 26 May 2015 08:52:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YxEL6-0004Z1-1u for qemu-devel@nongnu.org; Tue, 26 May 2015 08:52:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33949) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxEL5-0004Yt-R0 for qemu-devel@nongnu.org; Tue, 26 May 2015 08:52:11 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t4QCqBmp019706 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 26 May 2015 08:52:11 -0400 Message-ID: <55646C76.7070807@redhat.com> Date: Tue, 26 May 2015 14:52:06 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1430152117-100558-1-git-send-email-pbonzini@redhat.com> <1430152117-100558-30-git-send-email-pbonzini@redhat.com> <20150526124936.GB13749@ad.nay.redhat.com> In-Reply-To: <20150526124936.GB13749@ad.nay.redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit 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: Fam Zheng Cc: qemu-devel@nongnu.org, stefanha@redhat.com, mst@redhat.com On 26/05/2015 14:49, Fam Zheng wrote: > It would be nicer to introduce a memory_region_is_ram(MemoryRegion *mr), the > ~(ram_addr_t) duplications are too many. Is RAM_ADDR_INVALID okay too? Paolo > 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 >>