From: Yinghai Lu on
On 03/05/2010 11:49 AM, Ian Campbell wrote:
> This avoids an infinite loop in free_early_partial().
>
> Add a warning to free_early_partial to catch future problems.
>
> Signed-off-by: Ian Campbell <ian.campbell(a)citrix.com>
> Cc: Yinghai Lu <yinghai(a)kernel.org>
> Cc: Peter Zijlstra <peterz(a)infradead.org>
> Cc: Ingo Molnar <mingo(a)elte.hu>
> ---
> arch/x86/kernel/setup_percpu.c | 3 ++-
> kernel/early_res.c | 5 +++++
> 2 files changed, 7 insertions(+), 1 deletions(-)
>
> diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
> index ef6370b..89a3205 100644
> --- a/arch/x86/kernel/setup_percpu.c
> +++ b/arch/x86/kernel/setup_percpu.c
> @@ -140,7 +140,8 @@ static void __init pcpu_fc_free(void *ptr, size_t size)
> #ifdef CONFIG_NO_BOOTMEM
> u64 start = __pa(ptr);
> u64 end = start + size;
> - free_early_partial(start, end);
> + if (start < end)
> + free_early_partial(start, end);
> #else
> free_bootmem(__pa(ptr), size);
> #endif
> diff --git a/kernel/early_res.c b/kernel/early_res.c
> index 3cb2c66..f3a861b 100644
> --- a/kernel/early_res.c
> +++ b/kernel/early_res.c
> @@ -333,6 +333,11 @@ void __init free_early_partial(u64 start, u64 end)
> struct early_res *r;
> int i;
>
> + if (WARN_ONCE(start >= end,
> + "free_early_partial got wrong start/end %#llx/%#llx\n",
> + start, end))
> + return;
> +
> try_next:
> i = find_overlapped_early(start, end);
> if (i >= max_early_res)

Acked-by: Yinghai Lu <yinghai(a)kernel.org>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: H. Peter Anvin on
On 03/19/2010 12:24 PM, Yinghai Lu wrote:
> From: Ian Campbell <ian.campbell(a)citrix.com>
>
> This avoids an infinite loop in free_early_partial().
>
> Add a warning to free_early_partial to catch future problems.

Wouldn't it make more sense to simply make free_early_partial() a noop
for the zero range, instead of pushing all those tests into the callers?
It still might make sense to have a WARN_ONCE() for a *negative* range,
however...

-hpa
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: H. Peter Anvin on
On 03/19/2010 03:18 PM, Yinghai Lu wrote:
> From: Ian Campbell <ian.campbell(a)citrix.com>
>
> This avoids an infinite loop in free_early_partial().
>
> Add a warning to free_early_partial to catch future problems.
>
> -v3: according to hpa, don't bother caller.
>
> Signed-off-by: Ian Campbell <ian.campbell(a)citrix.com>
> Signed-off-by: Yinghai Lu <yinghai(a)kernel.org>
> Cc: Peter Zijlstra <peterz(a)infradead.org>
> Cc: Ingo Molnar <mingo(a)elte.hu>
> ---
> kernel/early_res.c | 5 +++++
> 1 files changed, 5 insertions(+), 0 deletions(-)
>
> diff --git a/kernel/early_res.c b/kernel/early_res.c
> index 3cb2c66..f3a861b 100644
> --- a/kernel/early_res.c
> +++ b/kernel/early_res.c
> @@ -333,6 +333,11 @@ void __init free_early_partial(u64 start, u64 end)
> struct early_res *r;
> int i;
>
> + if (WARN_ONCE(start >= end,
> + "free_early_partial got wrong start/end %#llx/%#llx\n",
> + start, end))
> + return;
> +
> try_next:
> i = find_overlapped_early(start, end);
> if (i >= max_early_res)

No, that's wrong.

The workaround is still needed for the case of equality to avoid the
infinite loop.

So you need an:

if (start == end)
return;

-hpa
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Yinghai Lu on
On 03/19/2010 03:21 PM, H. Peter Anvin wrote:
> On 03/19/2010 03:18 PM, Yinghai Lu wrote:
>> From: Ian Campbell <ian.campbell(a)citrix.com>
>>
>> This avoids an infinite loop in free_early_partial().
>>
>> Add a warning to free_early_partial to catch future problems.
>>
>> -v3: according to hpa, don't bother caller.
>>
>> Signed-off-by: Ian Campbell <ian.campbell(a)citrix.com>
>> Signed-off-by: Yinghai Lu <yinghai(a)kernel.org>
>> Cc: Peter Zijlstra <peterz(a)infradead.org>
>> Cc: Ingo Molnar <mingo(a)elte.hu>
>> ---
>> kernel/early_res.c | 5 +++++
>> 1 files changed, 5 insertions(+), 0 deletions(-)
>>
>> diff --git a/kernel/early_res.c b/kernel/early_res.c
>> index 3cb2c66..f3a861b 100644
>> --- a/kernel/early_res.c
>> +++ b/kernel/early_res.c
>> @@ -333,6 +333,11 @@ void __init free_early_partial(u64 start, u64 end)
>> struct early_res *r;
>> int i;
>>
>> + if (WARN_ONCE(start >= end,
>> + "free_early_partial got wrong start/end %#llx/%#llx\n",
>> + start, end))
>> + return;
>> +
>> try_next:
>> i = find_overlapped_early(start, end);
>> if (i >= max_early_res)
>
> No, that's wrong.
>
> The workaround is still needed for the case of equality to avoid the
> infinite loop.
>
> So you need an:
>
> if (start == end)
> return;
>

confused, do you mean like this
if (start < end), find_overlapped_early will stop the loop.

From: Ian Campbell <ian.campbell(a)citrix.com>

This avoids an infinite loop in free_early_partial().

Add a warning to free_early_partial to catch future problems.

-v3: according to hpa, don't bother caller.

Signed-off-by: Ian Campbell <ian.campbell(a)citrix.com>
Signed-off-by: Yinghai Lu <yinghai(a)kernel.org>
Cc: Peter Zijlstra <peterz(a)infradead.org>
Cc: Ingo Molnar <mingo(a)elte.hu>
---
kernel/early_res.c | 8 ++++++++
1 file changed, 8 insertions(+)

Index: linux-2.6/kernel/early_res.c
===================================================================
--- linux-2.6.orig/kernel/early_res.c
+++ linux-2.6/kernel/early_res.c
@@ -333,6 +333,14 @@ void __init free_early_partial(u64 start
struct early_res *r;
int i;

+ if (start >= end) {
+ WARN_ONCE(1,
+ "free_early_partial got wrong start/end %#llx/%#llx\n",
+ start, end);
+
+ return;
+ }
+
try_next:
i = find_overlapped_early(start, end);
if (i >= max_early_res)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: H. Peter Anvin on
On 03/19/2010 04:24 PM, Yinghai Lu wrote:
>
> confused, do you mean like this
> if (start < end), find_overlapped_early will stop the loop.
>

No.

What I mean is that free_early_partial(), when start == end, is a
legitimate operation that doesn't free anything -- the range is zero
bytes long. Just return.

When start > end, there is an explicit error we should warn about.

-hpa
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/