Skip to contentSkip to conversation

free_early_partial() should permit start == end

PATCH In review Jan Beulich 2 participants 3 messages Mar 26, 2010 – Mar 29, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 free_early_partial() should permit start == end

The per-CPU allocator, when using atom_size == PAGE_SIZE, may call free_area_init_partial() this way.

---
 kernel/early_res.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/early_res.c +2 -2
@@ -335,10 +335,10 @@ void __init free_early_partial(u64 start
 
 try_next:
 	i = find_overlapped_early(start, end);
-	if (i >= max_early_res)
+	r = &early_res[i];
+	if (i >= max_early_res || !r->end)
 		return;
 
-	r = &early_res[i];
 	/* hole ? */
 	if (r->end >= end && r->start <= start) {
 		drop_range_partial(i, start, end);
#1 lore raw
Quoted 16 lines · Jan Beulich

The per-CPU allocator, when using atom_size == PAGE_SIZE, may call free_area_init_partial() this way.

---
 kernel/early_res.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/early_res.c +0 -0
@@ -335,10 +335,10 @@ void __init free_early_partial(u64 start
 
 try_next:

kernel/early_res.c void __init free_early_partial(u64 start · line 344

Quoted 10 lines
kernel/early_res.c +2 -2
 	i = find_overlapped_early(start, end);
-	if (i >= max_early_res)
+	r = &early_res[i];
+	if (i >= max_early_res || !r->end)
 		return;
 
-	r = &early_res[i];
 	/* hole ? */
 	if (r->end >= end && r->start <= start) {
 		drop_range_partial(i, start, end);

can you check if this patch work for you?

Thanks

Yinghai Lu

Subject: [PATCH -v6] x86: do not free zero sized per cpu areas
From: Ian Campbell <[email protected]>

This avoids an infinite loop in free_early_partial().

Add a warning to free_early_partial to catch future problems.

-v5: put back start > end back into WARN_ONCE()
-v6: use one line for if according to linus

---
 kernel/early_res.c |    6 ++++++
 1 file changed, 6 insertions(+)
kernel/early_res.c +6 -0
Index: linux-2.6/kernel/early_res.c
===================================================================
@@ -333,6 +333,12 @@ void __init free_early_partial(u64 start
 	struct early_res *r;
 	int i;
 
+	if (start == end)
+		return;
+
+	if (WARN_ONCE(start > end, "free_early_partial: wrong range [%#llx, %#llx]\n", start, end))
+		return;
+
 try_next:
 	i = find_overlapped_early(start, end);
 	if (i >= max_early_res)
#2 lore raw
Quoted 2 lines
Quoted 1 line
Quoted 1 line

Yinghai Lu <[email protected]> 26.03.10 21:39 >>>

can you check if this patch work for you?

I'm sure it works, too. But I find it less clean to add special case handling instead of just getting the original code right.

Jan