From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34928) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VZSED-00058o-Rj for qemu-devel@nongnu.org; Thu, 24 Oct 2013 17:14:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VZSE5-0007F8-4b for qemu-devel@nongnu.org; Thu, 24 Oct 2013 17:14:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:65132) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VZSE4-0007ER-S5 for qemu-devel@nongnu.org; Thu, 24 Oct 2013 17:13:53 -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 r9OLDps6026877 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 24 Oct 2013 17:13:51 -0400 Message-Id: <20131024211249.723543071@amt.cnet> Date: Thu, 24 Oct 2013 19:12:00 -0200 From: Marcelo Tosatti References: <20131024211158.064049176@amt.cnet> Content-Disposition: inline; filename=align-ram-to-1gb-pagesize Subject: [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: qemu-devel@nongnu.org Cc: aarcange@redhat.com, pbonzini@redhat.com, Marcelo Tosatti , gleb@redhat.com 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); + } 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); + } }