[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1425308310-2318-6-git-send-email-bhe@redhat.com>
Date: Mon, 2 Mar 2015 22:58:26 +0800
From: Baoquan He <bhe@...hat.com>
To: hpa@...or.com, yinghai@...nel.org, keescook@...omium.org,
vgoyal@...hat.com, luto@...capital.net, akpm@...ux-foundation.org,
tglx@...utronix.de, mingo@...hat.com
Cc: linux-kernel@...r.kernel.org, Baoquan He <bhe@...hat.com>
Subject: [PATCH v2 5/9] add mem_min_overlap to find the first avoid region within a memory region
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 <bhe@...hat.com>
---
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists