From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755862AbbCBO7f (ORCPT ); Mon, 2 Mar 2015 09:59:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55152 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755842AbbCBO7d (ORCPT ); Mon, 2 Mar 2015 09:59:33 -0500 From: Baoquan He To: hpa@zytor.com, yinghai@kernel.org, keescook@chromium.org, vgoyal@redhat.com, luto@amacapital.net, akpm@linux-foundation.org, tglx@linutronix.de, mingo@redhat.com Cc: linux-kernel@vger.kernel.org, Baoquan He Subject: [PATCH v2 5/9] add mem_min_overlap to find the first avoid region within a memory region Date: Mon, 2 Mar 2015 22:58:26 +0800 Message-Id: <1425308310-2318-6-git-send-email-bhe@redhat.com> In-Reply-To: <1425308310-2318-1-git-send-email-bhe@redhat.com> References: <1425308310-2318-1-git-send-email-bhe@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Given a memory region mem_min_overlap will iterate all avoid region to find the first one which overlap with it. This function will be used later. Signed-off-by: Baoquan He --- arch/x86/boot/compressed/aslr.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/arch/x86/boot/compressed/aslr.c b/arch/x86/boot/compressed/aslr.c index 26610a2..ded3959 100644 --- a/arch/x86/boot/compressed/aslr.c +++ b/arch/x86/boot/compressed/aslr.c @@ -213,6 +213,38 @@ static bool mem_avoid_overlap(struct mem_vector *img) return false; } +static unsigned long mem_min_overlap(struct mem_vector *img, struct mem_vector *out) +{ + int i; + struct setup_data *ptr; + unsigned long min = img->start + img->size; + + for (i = 0; i < MEM_AVOID_MAX; i++) { + if (mem_overlaps(img, &mem_avoid[i]) && (mem_avoid[i].start < min) ) { + *out = mem_avoid[i]; + min = mem_avoid[i].start; + } + } + + /* Check all entries in the setup_data linked list. */ + ptr = (struct setup_data *)(unsigned long)real_mode->hdr.setup_data; + while (ptr) { + struct mem_vector avoid; + + avoid.start = (unsigned long)ptr; + avoid.size = sizeof(*ptr) + ptr->len; + + if (mem_overlaps(img, &avoid) && (avoid.start < min) ) { + *out = avoid; + min = avoid.start; + } + + ptr = (struct setup_data *)(unsigned long)ptr->next; + } + + return min; +} + static unsigned long slots[CONFIG_RANDOMIZE_BASE_MAX_OFFSET / CONFIG_PHYSICAL_ALIGN]; -- 1.9.3