Received: from eggs.gnu.org ([140.186.70.92]:35505) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QHFRf-0007dX-Pq for qemu-devel@nongnu.org; Tue, 03 May 2011 09:15:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QHFRe-0002zV-KD for qemu-devel@nongnu.org; Tue, 03 May 2011 09:15:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34993) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QHFRe-0002z6-C3 for qemu-devel@nongnu.org; Tue, 03 May 2011 09:15:18 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p43DFFR0022090 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 3 May 2011 09:15:15 -0400 From: Markus Armbruster References: <20110429031437.3796.49456.stgit@s20.home> Date: Tue, 03 May 2011 15:15:13 +0200 In-Reply-To: <20110429031437.3796.49456.stgit@s20.home> (Alex Williamson's message of "Thu, 28 Apr 2011 21:15:23 -0600") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH] Fix phys memory client - pass guest physical address not region offset List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex Williamson Cc: qemu-devel@nongnu.org, mst@redhat.com Alex Williamson writes: > When we're trying to get a newly registered phys memory client updated > with the current page mappings, we end up passing the region offset > (a ram_addr_t) as the start address rather than the actual guest > physical memory address (target_phys_addr_t). If your guest has less > than 3.5G of memory, these are coincidentally the same thing. If > there's more, the region offset for the memory above 4G starts over > at 0, so the set_memory client will overwrite it's lower memory entries. > > Instead, keep track of the guest phsyical address as we're walking the > tables and pass that to the set_memory client. > > Signed-off-by: Alex Williamson > --- > > exec.c | 10 ++++++---- > 1 files changed, 6 insertions(+), 4 deletions(-) > > diff --git a/exec.c b/exec.c > index 4752af1..e670929 100644 > --- a/exec.c > +++ b/exec.c > @@ -1742,7 +1742,7 @@ static int cpu_notify_migration_log(int enable) > } > > static void phys_page_for_each_1(CPUPhysMemoryClient *client, > - int level, void **lp) > + int level, void **lp, target_phys_addr_t addr) > { > int i; > Aren't you abusing target_phys_addr_t here? It's not a physical address, it needs to be shifted left to become one. By how much depends on level. Please take pity on future maintainers and spell this out in a comment. Perhaps you can code it in a way that makes the parameter an address. Probably no need for a comment then. > @@ -1751,16 +1751,18 @@ static void phys_page_for_each_1(CPUPhysMemoryClient *client, > } > if (level == 0) { > PhysPageDesc *pd = *lp; > + addr <<= L2_BITS + TARGET_PAGE_BITS; > for (i = 0; i < L2_SIZE; ++i) { > if (pd[i].phys_offset != IO_MEM_UNASSIGNED) { > - client->set_memory(client, pd[i].region_offset, > + client->set_memory(client, addr | i << TARGET_PAGE_BITS, > TARGET_PAGE_SIZE, pd[i].phys_offset); > } > } > } else { > void **pp = *lp; > for (i = 0; i < L2_SIZE; ++i) { > - phys_page_for_each_1(client, level - 1, pp + i); > + phys_page_for_each_1(client, level - 1, pp + i, > + (addr << L2_BITS) | i); > } > } > } > @@ -1770,7 +1772,7 @@ static void phys_page_for_each(CPUPhysMemoryClient *client) > int i; > for (i = 0; i < P_L1_SIZE; ++i) { > phys_page_for_each_1(client, P_L1_SHIFT / L2_BITS - 1, > - l1_phys_map + i); > + l1_phys_map + i, i); > } > } > Fix makes sense to me, after some head scratching. A comment explaining the phys map data structure would be helpful. l1_phys_map[] has a comment, but it's devoid of detail.