Skip to contentSkip to conversation

mm,x86: fix span coverage in e820_all_mapped()

PATCH In review Xishi Qiu 3 participants 14 messages Dec 10, 2013 – Dec 11, 2013

Subsystems (2)
lore
Share & tools
lore

Xishi Qiu

author
#0 lore raw

PATCH 1/1 mm,x86: fix span coverage in e820_all_mapped()

In the following case, e820_all_mapped() will return 1.
A < start < B-1 and B < end < C, it means <start, end> spans two regions.
<start, end>: [start - end]
e820 addr: ...[A - B-1][B - C]...

---
 arch/x86/kernel/e820.c |   15 +++------------
 1 files changed, 3 insertions(+), 12 deletions(-)
arch/x86/kernel/e820.c +3 -12
index 174da5f..31ecab2 100644
@@ -85,20 +85,11 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 
 		if (type && ei->type != type)
 			continue;
-		/* is the region (part) in overlap with the current region ?*/
+		/* is the region (part) in overlap with the current region ? */
 		if (ei->addr >= end || ei->addr + ei->size <= start)
 			continue;
-
-		/* if the region is at the beginning of <start,end> we move
-		 * start to the end of the region since it's ok until there
-		 */
-		if (ei->addr <= start)
-			start = ei->addr + ei->size;
-		/*
-		 * if start is now at or beyond end, we're done, full
-		 * coverage
-		 */
-		if (start >= end)
+		/* is the region full coverage of <start, end> ? */
+		if (ei->addr <= start && ei->addr + ei->size >= end)
 			return 1;
 	}
 	return 0;
Signature · 1 line
1.7.1
#1 lore raw
Quoted 4 lines · Xishi Qiu

In the following case, e820_all_mapped() will return 1.
A < start < B-1 and B < end < C, it means <start, end> spans two regions.
<start, end>: [start - end]
e820 addr: ...[A - B-1][B - C]...

should be [start, end) right?
and
[A, B),[B, C)

Quoted 14 lines
---
 arch/x86/kernel/e820.c |   15 +++------------
 1 files changed, 3 insertions(+), 12 deletions(-)
arch/x86/kernel/e820.c +0 -0
index 174da5f..31ecab2 100644
@@ -85,20 +85,11 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 
                if (type && ei->type != type)
                        continue;

arch/x86/kernel/e820.c int __init e820_all_mapped(u64 start, u64 end, unsigned type) · line 96

Quoted 10 lines
arch/x86/kernel/e820.c +1 -7
-               /* is the region (part) in overlap with the current region ?*/
+               /* is the region (part) in overlap with the current region ? */
                if (ei->addr >= end || ei->addr + ei->size <= start)
                        continue;
-
-               /* if the region is at the beginning of <start,end> we move
-                * start to the end of the region since it's ok until there
-                */
-               if (ei->addr <= start)
-                       start = ei->addr + ei->size;

so in your case new start will be B ?

next run will be C

Quoted 10 lines
arch/x86/kernel/e820.c +2 -5
-               /*
-                * if start is now at or beyond end, we're done, full
-                * coverage
-                */
-               if (start >= end)
 
 
+               /* is the region full coverage of <start, end> ? */
+               if (ei->addr <= start && ei->addr + ei->size >= end)
                        return 1;
Quoted 2 lines
        }
        return 0;

also e820 should be sanitized already to have [A,C).

or you are talking about [A,B), [B+1, C)
first run start will be B, and next run with [B+1, ...), that will be skipped...
will not return 1.

so old code should be ok.

Thanks

Yinghai

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 10 lines · Yinghai Lu
Quoted 4 lines · Xishi Qiu

In the following case, e820_all_mapped() will return 1.
A < start < B-1 and B < end < C, it means <start, end> spans two regions.
<start, end>: [start - end]
e820 addr: ...[A - B-1][B - C]...

should be [start, end) right?
and
[A, B),[B, C)

What happens if it spans more than two regions?

-hpa

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · Yinghai Lu
Quoted 4 lines · Xishi Qiu

In the following case, e820_all_mapped() will return 1.
A < start < B-1 and B < end < C, it means <start, end> spans two regions.
<start, end>: [start - end]
e820 addr: ...[A - B-1][B - C]...

Quoted 6 lines
Quoted 4 lines

should be [start, end) right?
and
[A, B),[B, C)

What happens if it spans more than two regions?

[A, B), [B+1, C), [C+1, D) ?
start in [A, B), and end in [C+1, D).

old code:
first with [A, B), start set to B.
then with [B+1, C), start still keep as B.
then with [C+1, D), start still keep as B.
at last still return 0...aka not_all_mapped.

old code is still right.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 6 lines · Yinghai Lu
Quoted 2 lines

What happens if it spans more than two regions?

[A, B), [B+1, C), [C+1, D) ?
start in [A, B), and end in [C+1, D).

Quoted 8 lines

old code:
first with [A, B), start set to B. then with [B+1, C), start still keep as B. then with [C+1, D), start still keep as B. at last still return 0...aka not_all_mapped.

old code is still right.

Why not_all_mapped?

-hpa

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
Quoted 13 lines · H. Peter Anvin
Quoted 12 lines · Yinghai Lu
Quoted 2 lines

What happens if it spans more than two regions?

[A, B), [B+1, C), [C+1, D) ?
start in [A, B), and end in [C+1, D).

old code:
first with [A, B), start set to B. then with [B+1, C), start still keep as B. then with [C+1, D), start still keep as B. at last still return 0...aka not_all_mapped.

Quoted 4 lines
Quoted 2 lines

old code is still right.

Why not_all_mapped?

[B, B+1), and [C, C+1) are not there.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw

Ok, the issue I thought we were discussing was actually [A,B) [B,C) [C,D) ...

Quoted 20 lines · Yinghai Lu
Quoted 13 lines · H. Peter Anvin
Quoted 12 lines · Yinghai Lu
Quoted 2 lines

What happens if it spans more than two regions?

[A, B), [B+1, C), [C+1, D) ?
start in [A, B), and end in [C+1, D).

old code:
first with [A, B), start set to B. then with [B+1, C), start still keep as B. then with [C+1, D), start still keep as B. at last still return 0...aka not_all_mapped.

Quoted 4 lines
Quoted 2 lines

old code is still right.

Why not_all_mapped?

[B, B+1), and [C, C+1) are not there.

Signature · 7 lines
Sent from my mobile phone.  Please pardon brevity and lack of formatting.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#7 lore raw
Quoted 2 lines · H. Peter Anvin

Ok, the issue I thought we were discussing was actually [A,B) [B,C) [C,D) ...

Hi Peter,

Yes, in this case the function will return 1.

Thanks,
Xishi Qiu

Quoted 22 lines
Quoted 20 lines · Yinghai Lu
Quoted 13 lines · H. Peter Anvin
Quoted 12 lines · Yinghai Lu
Quoted 2 lines

What happens if it spans more than two regions?

[A, B), [B+1, C), [C+1, D) ?
start in [A, B), and end in [C+1, D).

old code:
first with [A, B), start set to B. then with [B+1, C), start still keep as B. then with [C+1, D), start still keep as B. at last still return 0...aka not_all_mapped.

Quoted 4 lines
Quoted 2 lines

old code is still right.

Why not_all_mapped?

[B, B+1), and [C, C+1) are not there.

author
#8 lore raw
In reply to Yinghai Lu
Quoted 10 lines · Yinghai Lu
Quoted 4 lines · Xishi Qiu

In the following case, e820_all_mapped() will return 1.
A < start < B-1 and B < end < C, it means <start, end> spans two regions.
<start, end>: [start - end]
e820 addr: ...[A - B-1][B - C]...

should be [start, end) right?
and
[A, B),[B, C)

Hi Yinghai,

It is right, in this case the function will return 1.

Quoted 36 lines
Quoted 14 lines
---
 arch/x86/kernel/e820.c |   15 +++------------
 1 files changed, 3 insertions(+), 12 deletions(-)
arch/x86/kernel/e820.c +0 -0
index 174da5f..31ecab2 100644
@@ -85,20 +85,11 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 
                if (type && ei->type != type)
                        continue;

arch/x86/kernel/e820.c int __init e820_all_mapped(u64 start, u64 end, unsigned type) · line 96

Quoted 10 lines
arch/x86/kernel/e820.c +1 -7
-               /* is the region (part) in overlap with the current region ?*/
+               /* is the region (part) in overlap with the current region ? */
                if (ei->addr >= end || ei->addr + ei->size <= start)
                        continue;
-
-               /* if the region is at the beginning of <start,end> we move
-                * start to the end of the region since it's ok until there
-                */
-               if (ei->addr <= start)
-                       start = ei->addr + ei->size;

so in your case new start will be B ?

next run will be C

Quoted 5 lines
arch/x86/kernel/e820.c +0 -5
-               /*
-                * if start is now at or beyond end, we're done, full
-                * coverage
-                */
-               if (start >= end)
Quoted 8 lines

arch/x86/kernel/e820.c int __init e820_all_mapped(u64 start, u64 end, unsigned type) · line 95

Quoted 5 lines
arch/x86/kernel/e820.c +2 -0
+               /* is the region full coverage of <start, end> ? */
+               if (ei->addr <= start && ei->addr + ei->size >= end)
                        return 1;
        }
        return 0;

also e820 should be sanitized already to have [A,C).

Yes, it should be sanitized already, but maybe someone will change the e820 to support some feature, so this function will be a potential bomb.

Quoted 7 lines

or you are talking about [A,B), [B+1, C)
first run start will be B, and next run with [B+1, ...), that will be skipped...
will not return 1.

so old code should be ok.

In this case, old code is right, but I discuss in another one that you wrote above.

Thanks,
Xishi Qiu

Quoted 6 lines

Thanks

Yinghai

.

author
#10 lore raw
Quoted 8 lines · H. Peter Anvin
Quoted 4 lines · Xishi Qiu

In this case, old code is right, but I discuss in another one that you wrote above.

So is there a problem or not? I have lost track...

I think there is a problem.
e.g.
[start, end)=[8, 12), and [A, B)=[0, 10), [B, C)=[10,20), then e820_all_mapped() will return 1, it spans two regions.

Thanks,
Xishi Qiu

Quoted 5 lines

-hpa

author
#12 lore raw
Quoted 10 lines · H. Peter Anvin
Quoted 6 lines · Xishi Qiu

I think there is a problem.
e.g.
[start, end)=[8, 12), and [A, B)=[0, 10), [B, C)=[10,20), then e820_all_mapped() will return 1, it spans two regions.

Why is that a problem?

[start, end) should be included in one region ?

Thanks,
Xishi Qiu

Quoted 5 lines

-hpa

#13 lore raw

Is that an actual requirement of the API?

Quoted 23 lines · Xishi Qiu
Quoted 10 lines · H. Peter Anvin
Quoted 6 lines · Xishi Qiu

I think there is a problem.
e.g.
[start, end)=[8, 12), and [A, B)=[0, 10), [B, C)=[10,20), then e820_all_mapped() will return 1, it spans two regions.

Why is that a problem?

[start, end) should be included in one region ?

Thanks,
Xishi Qiu

Quoted 5 lines

-hpa

Signature · 7 lines
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>