From: "Jan Beulich" Subject: Re: [v8][PATCH 10/17] hvmloader/mem_hole_alloc: skip any overlap with reserved device memory Date: Thu, 04 Dec 2014 16:28:52 +0000 Message-ID: <548099D4020000780004CD9C@mail.emea.novell.com> References: <1417425875-9634-1-git-send-email-tiejun.chen@intel.com> <1417425875-9634-11-git-send-email-tiejun.chen@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1417425875-9634-11-git-send-email-tiejun.chen@intel.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Tiejun Chen Cc: kevin.tian@intel.com, wei.liu2@citrix.com, ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com, tim@xen.org, ian.jackson@eu.citrix.com, xen-devel@lists.xen.org, yang.z.zhang@intel.com List-Id: xen-devel@lists.xenproject.org >>> On 01.12.14 at 10:24, wrote: > In some cases like igd_opregion_pgbase, guest will use mem_hole_alloc > to allocate some memory to use in runtime cycle, so we alsoe need to > make sure all reserved device memory don't overlap such a region. While ideally this would get switched to the model outlined for the previous two patches too, it's at least reasonable to keep this simple allocator simple for the time being. > --- a/tools/firmware/hvmloader/util.c > +++ b/tools/firmware/hvmloader/util.c > @@ -416,9 +416,29 @@ static uint32_t alloc_down = RESERVED_MEMORY_DYNAMIC_END; > > xen_pfn_t mem_hole_alloc(uint32_t nr_mfns) > { > + unsigned int i, num = hvm_get_reserved_device_memory_map(); > + uint64_t rdm_start, rdm_end; > + uint32_t alloc_start, alloc_end; > + > alloc_down -= nr_mfns << PAGE_SHIFT; > + alloc_start = alloc_down; > + alloc_end = alloc_start + (nr_mfns << PAGE_SHIFT); > + for ( i = 0; i < num; i++ ) > + { > + rdm_start = (uint64_t)rdm_map[i].start_pfn << PAGE_SHIFT; > + rdm_end = rdm_start + ((uint64_t)rdm_map[i].nr_pages << PAGE_SHIFT); > + if ( check_rdm_hole_conflict((uint64_t)alloc_start, > + (uint64_t)alloc_end, Pointless casts. > + rdm_start, rdm_end - rdm_start) ) > + { > + alloc_end = rdm_start; > + alloc_start = alloc_end - (nr_mfns << PAGE_SHIFT); > + BUG_ON(alloc_up >= alloc_start); This is redundant with the BUG_ON() below afaict. Or at least it would be, if you would properly update allow_down (if you don't you may end up returning the same PFN for two allocations). > + } > + } > + > BUG_ON(alloc_up >= alloc_down); Jan