From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38734) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VZUku-00016f-1k for qemu-devel@nongnu.org; Thu, 24 Oct 2013 19:56:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VZUkl-0003Ra-G0 for qemu-devel@nongnu.org; Thu, 24 Oct 2013 19:55:55 -0400 Received: from mail-wi0-x229.google.com ([2a00:1450:400c:c05::229]:51425) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VZUkl-0003RT-6G for qemu-devel@nongnu.org; Thu, 24 Oct 2013 19:55:47 -0400 Received: by mail-wi0-f169.google.com with SMTP id cb5so315283wib.4 for ; Thu, 24 Oct 2013 16:55:46 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <5269B378.6040409@redhat.com> Date: Fri, 25 Oct 2013 00:55:36 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <20131024211158.064049176@amt.cnet> <20131024211249.723543071@amt.cnet> In-Reply-To: <20131024211249.723543071@amt.cnet> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [patch 2/2] i386: pc: align gpa<->hpa on 1GB boundary List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marcelo Tosatti Cc: aarcange@redhat.com, qemu-devel@nongnu.org, gleb@redhat.com Il 24/10/2013 22:12, Marcelo Tosatti ha scritto: > Align guest physical address and host physical address > beyond guest 4GB on a 1GB boundary, in case hugetlbfs is used. > > Otherwise 1GB TLBs cannot be cached for the range. > > Signed-off-by: Marcelo Tosatti > > Index: qemu/hw/i386/pc.c > =================================================================== > --- qemu.orig/hw/i386/pc.c > +++ qemu/hw/i386/pc.c > @@ -1116,8 +1116,9 @@ FWCfgState *pc_memory_init(MemoryRegion > { > int linux_boot, i; > MemoryRegion *ram, *option_rom_mr; > - MemoryRegion *ram_below_4g, *ram_above_4g; > + MemoryRegion *ram_below_4g, *ram_above_4g, *ram_above_4g_piecetwo; > FWCfgState *fw_cfg; > + unsigned long hpagesize; > > linux_boot = (kernel_filename != NULL); > > @@ -1129,6 +1130,7 @@ FWCfgState *pc_memory_init(MemoryRegion > memory_region_init_ram(ram, NULL, "pc.ram", > below_4g_mem_size + above_4g_mem_size); > vmstate_register_ram_global(ram); > + hpagesize = qemu_get_ram_hpagesize(ram->ram_addr); > *ram_memory = ram; > ram_below_4g = g_malloc(sizeof(*ram_below_4g)); > memory_region_init_alias(ram_below_4g, NULL, "ram-below-4g", ram, > @@ -1136,10 +1138,46 @@ FWCfgState *pc_memory_init(MemoryRegion > memory_region_add_subregion(system_memory, 0, ram_below_4g); > if (above_4g_mem_size > 0) { > ram_above_4g = g_malloc(sizeof(*ram_above_4g)); > - memory_region_init_alias(ram_above_4g, NULL, "ram-above-4g", ram, > - below_4g_mem_size, above_4g_mem_size); > - memory_region_add_subregion(system_memory, 0x100000000ULL, > + > + /* > + * > + * If 1GB hugepages are used to back guest RAM, map guest address > + * space in the range [ramsize,ramsize+holesize] to the ram block > + * range [holestart, 4GB] > + * > + * 0 h 4G [ramsize,ramsize+holesize] > + * > + * guest-addr-space [ ] [ ][xxx] > + * /----------/ > + * contiguous-ram-block [ ][xxx][ ] > + * > + * So that memory beyond 4GB is aligned on a 1GB boundary, > + * at the host physical address space. > + * > + */ > + if (hpagesize == (1<<30)) { > + unsigned long holesize = 0x100000000ULL - below_4g_mem_size; > + > + memory_region_init_alias(ram_above_4g, NULL, "ram-above-4g", ram, > + 0x100000000ULL, > + above_4g_mem_size - holesize); > + memory_region_add_subregion(system_memory, 0x100000000ULL, > + ram_above_4g); > + > + ram_above_4g_piecetwo = g_malloc(sizeof(*ram_above_4g_piecetwo)); > + memory_region_init_alias(ram_above_4g_piecetwo, NULL, > + "ram-above-4g-piecetwo", ram, > + 0x100000000ULL - holesize, holesize); > + memory_region_add_subregion(system_memory, > + 0x100000000ULL + > + above_4g_mem_size - holesize, > + ram_above_4g_piecetwo); Why break it in two? You can just allocate extra holesize bytes in the "ram" MemoryRegion, and not map the part that corresponds to [0x100000000ULL - holesize, 0x100000000ULL). Also, as Peter said this cannot depend on host considerations. Just do it unconditionally, but only for new machine types (pc-1.8 and q35-1.8, since unfortunately we're too close to hard freeze). Paolo > + } else { > + memory_region_init_alias(ram_above_4g, NULL, "ram-above-4g", ram, > + below_4g_mem_size, above_4g_mem_size); > + memory_region_add_subregion(system_memory, 0x100000000ULL, > ram_above_4g); > + } > }