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 <mtosa...@redhat.com> > > 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); > + } > }