From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tiejun Chen Subject: [v8][PATCH 10/17] hvmloader/mem_hole_alloc: skip any overlap with reserved device memory Date: Mon, 1 Dec 2014 17:24:28 +0800 Message-ID: <1417425875-9634-11-git-send-email-tiejun.chen@intel.com> References: <1417425875-9634-1-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-1-git-send-email-tiejun.chen@intel.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: jbeulich@suse.com, ian.jackson@eu.citrix.com, stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com, wei.liu2@citrix.com, kevin.tian@intel.com, tim@xen.org, yang.z.zhang@intel.com Cc: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org 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. Signed-off-by: Tiejun Chen --- tools/firmware/hvmloader/util.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c index 8767897..f3723c7 100644 --- 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, + rdm_start, rdm_end - rdm_start) ) + { + alloc_end = rdm_start; + alloc_start = alloc_end - (nr_mfns << PAGE_SHIFT); + BUG_ON(alloc_up >= alloc_start); + } + } + BUG_ON(alloc_up >= alloc_down); - return alloc_down >> PAGE_SHIFT; + return alloc_start >> PAGE_SHIFT; } void *mem_alloc(uint32_t size, uint32_t align) -- 1.9.1