From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54002) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgDM6-0004NO-N0 for qemu-devel@nongnu.org; Tue, 12 Nov 2013 07:46:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VgDM0-0002RW-LJ for qemu-devel@nongnu.org; Tue, 12 Nov 2013 07:46:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:63699) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgDLz-0002RD-JG for qemu-devel@nongnu.org; Tue, 12 Nov 2013 07:46:00 -0500 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 rACCjwSw025509 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 12 Nov 2013 07:45:58 -0500 Date: Tue, 12 Nov 2013 13:45:51 +0100 From: Igor Mammedov Message-ID: <20131112134551.6aff095e@thinkpad> In-Reply-To: <20131110204753.GA11389@amt.cnet> References: <20131024211158.064049176@amt.cnet> <20131024211249.723543071@amt.cnet> <20131106014930.GA20468@amt.cnet> <20131106015543.GA20766@amt.cnet> <20131106213119.GA15543@amt.cnet> <20131107162459.6bdc39d7@nial.usersys.redhat.com> <20131107215304.GA10866@amt.cnet> <20131110204753.GA11389@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] i386: pc: align gpa<->hpa on 1GB boundary (v5) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marcelo Tosatti Cc: aarcange@redhat.com, gleb@redhat.com, "Michael S. Tsirkin" , qemu-devel@nongnu.org, Gerd Hoffmann , pbonzini@redhat.com On Sun, 10 Nov 2013 18:47:53 -0200 Marcelo Tosatti wrote: [...] > @@ -1177,10 +1182,50 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory, > e820_add_entry(0, below_4g_mem_size, E820_RAM); > if (above_4g_mem_size > 0) { > ram_above_4g = g_malloc(sizeof(*ram_above_4g)); it is a memory leak when "ram-above-4g" is not created > - 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 (guest_info->gb_align) { > + uint64_t holesize = 0x100000000ULL - below_4g_mem_size; > + uint64_t piecetwosize = holesize - align_offset; > + > + assert(piecetwosize <= holesize); > + > + if ((above_4g_mem_size - piecetwosize) > 0) { here is integer overflow, reproducable with: -mem-path /var/lib/hugetlbfs/global/pagesize-1GB -m 3600 > + memory_region_init_alias(ram_above_4g, NULL, "ram-above-4g", > + ram, 0x100000000ULL, > + above_4g_mem_size - piecetwosize); > + 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, piecetwosize); > + memory_region_add_subregion(system_memory, > + 0x100000000ULL + > + above_4g_mem_size - piecetwosize, is there a guaranty that "ram-above-4g-piecetwo" will be mapped immediately after "ram-above-4g" without any gap? if there is no then you might need to change how e820_add_entry() for high ram is handled and possibly CMOS value as well. > + 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); > + } > e820_add_entry(0x100000000ULL, above_4g_mem_size, E820_RAM); > } [...] -- Regards, Igor