mm: Fix NULL ptr dereference in __count_immobile_pages
Subsystems (2)
PATCH 1/1 mm: Fix NULL ptr dereference in __count_immobile_pages
This patch fixes the following NULL ptr dereference caused by cat /sys/devices/system/memory/memory0/removable:
Pid: 13979, comm: sed Not tainted 3.0.13-0.5-default #1 IBM BladeCenter LS21 -[7971PAM]-/Server Blade
RIP: 0010:[<ffffffff810f41f4>] [<ffffffff810f41f4>] __count_immobile_pages+0x4/0x100 RSP: 0018:ffff880221c37e48 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffffea0000000000 RCX: ffffea0000000000 RDX: 0000000000000000 RSI: ffffea0000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: 0000000000000001 R09: 00000000000146b0 R10: 0000000000000000 R11: ffffffff81328980 R12: 0000160000000000 R13: 6db6db6db6db6db7 R14: 0000000000000001 R15: ffffffff81658af0 FS: 00007fc4e8091700(0000) GS:ffff88023fc80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000698 CR3: 000000023027a000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Process sed (pid: 13979, threadinfo ffff880221c36000, task ffff88022e788480) Stack: ffffea0000000000 ffffea00001c0000 ffffffff810f4324 ffffffff8113e104 0000000000000001 0000000000000001 ffff880232a33ac0 ffff880230c25000 ffff880232a33b28 ffffffff813289c1 ffff88022e7d7d40 ffffffffffffffed Call Trace: [<ffffffff810f4324>] is_pageblock_removable_nolock+0x34/0x40 [<ffffffff8113e104>] is_mem_section_removable+0x74/0xf0 [<ffffffff813289c1>] show_mem_removable+0x41/0x70 [<ffffffff811c053e>] sysfs_read_file+0xfe/0x1c0 [<ffffffff81150be7>] vfs_read+0xc7/0x130 [<ffffffff81150d53>] sys_read+0x53/0xa0 [<ffffffff81448392>] system_call_fastpath+0x16/0x1b [<00007fc4e7bdbea0>] 0x7fc4e7bdbe9f Code: 34 00 0f 1f 44 00 00 48 89 ef be 02 00 00 00 e8 f3 f3 ff ff ba 02 00 00 00 48 89 ee 48 89 df e8 53 f0 ff ff eb b9 90 55 89 d5 53 2b bf 98 06 00 00 48 89 f3 48 81 ef 00 15 00 00 48 81 ff ff
We are crashing because we are trying to dereference NULL zone which came from pfn=0 (struct page ffffea0000000000). According to the boot log this page is marked reserved:
e820 update range: 0000000000000000 - 0000000000010000 (usable) ==> (reserved)
and early_node_map confirms that:
early_node_map[3] active PFN ranges
1: 0x00000010 -> 0x0000009c
1: 0x00000100 -> 0x000bffa3
1: 0x00100000 -> 0x00240000The problem is that memory_present works in PAGE_SECTION_MASK aligned blocks so the reserved range sneaks into the the section as well. This also means that free_area_init_node will not take care of those reserved pages and they stay uninitialized.
When we try to read the removable status we walk through all available sections and hope that the zone is valid for all pages in the section. But this is not true in this case as the zone and nid are not initialized.
We have only one node in this particular case and it is marked as node=1 (rather than 0) and that made the problem visible because page_to_nid will return 0 and there are no zones on the node.
Let's check that the zone is valid and that the given pfn falls into its boundaries and mark the section not removable. This might cause some false positives, probably, but we do not have any sane way to find out whether the page is reserved by the platform or it is just not used for whatever other reasons.
--- mm/page_alloc.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
mm/page_alloc.c +11 -0
@@ -5608,6 +5608,17 @@ __count_immobile_pages(struct zone *zone, struct page *page, int count)bool is_pageblock_removable_nolock (struct page *page) {struct zone *zone =page_zone (page); +unsigned long pfn =page_to_pfn (page); + +/* +* We have to be careful here because we are iterating over memory +* sections which are not zone aware so we might end up outside of +* the zone but still within the section. +*/ +if (!zone || zone->zone_start_pfn > pfn || + zone->zone_start_pfn + zone->spanned_pages <= pfn) +return false; +return __count_immobile_pages (zone, page,0 ); }
Signature · 8 lines
1.7.7.3 -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 85 lines · Michal Hocko
This patch fixes the following NULL ptr dereference caused by cat
/sys/devices/system/memory/memory0/removable:Pid: 13979, comm: sed Not tainted 3.0.13-0.5-default #1 IBM BladeCenter LS21 -[7971PAM]-/Server Blade
RIP: 0010:[<ffffffff810f41f4>] [<ffffffff810f41f4>] __count_immobile_pages+0x4/0x100 RSP: 0018:ffff880221c37e48 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffffea0000000000 RCX: ffffea0000000000 RDX: 0000000000000000 RSI: ffffea0000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: 0000000000000001 R09: 00000000000146b0 R10: 0000000000000000 R11: ffffffff81328980 R12: 0000160000000000 R13: 6db6db6db6db6db7 R14: 0000000000000001 R15: ffffffff81658af0 FS: 00007fc4e8091700(0000) GS:ffff88023fc80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000698 CR3: 000000023027a000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Process sed (pid: 13979, threadinfo ffff880221c36000, task ffff88022e788480) Stack: ffffea0000000000 ffffea00001c0000 ffffffff810f4324 ffffffff8113e104 0000000000000001 0000000000000001 ffff880232a33ac0 ffff880230c25000 ffff880232a33b28 ffffffff813289c1 ffff88022e7d7d40 ffffffffffffffed Call Trace: [<ffffffff810f4324>] is_pageblock_removable_nolock+0x34/0x40 [<ffffffff8113e104>] is_mem_section_removable+0x74/0xf0 [<ffffffff813289c1>] show_mem_removable+0x41/0x70 [<ffffffff811c053e>] sysfs_read_file+0xfe/0x1c0 [<ffffffff81150be7>] vfs_read+0xc7/0x130 [<ffffffff81150d53>] sys_read+0x53/0xa0 [<ffffffff81448392>] system_call_fastpath+0x16/0x1b [<00007fc4e7bdbea0>] 0x7fc4e7bdbe9f Code: 34 00 0f 1f 44 00 00 48 89 ef be 02 00 00 00 e8 f3 f3 ff ff ba 02 00 00 00 48 89 ee 48 89 df e8 53 f0 ff ff eb b9 90 55 89 d5 53 2b bf 98 06 00 00 48 89 f3 48 81 ef 00 15 00 00 48 81 ff ffWe are crashing because we are trying to dereference NULL zone which came from pfn=0 (struct page
ffffea0000000000). According to the boot log this page is marked reserved:
e820 update range: 0000000000000000 - 0000000000010000 (usable) ==> (reserved)and
early_node_mapconfirms that:
early_node_map[3] active PFN ranges1: 0x00000010 -> 0x0000009c 1: 0x00000100 -> 0x000bffa3 1: 0x00100000 -> 0x00240000The problem is that
memory_presentworks inPAGE_SECTION_MASKaligned blocks so the reserved range sneaks into the the section as well. This also means thatfree_area_init_nodewill not take care of those reserved pages and they stay uninitialized.When we try to read the removable status we walk through all available sections and hope that the zone is valid for all pages in the section. But this is not true in this case as the zone and nid are not initialized.
We have only one node in this particular case and it is marked as node=1 (rather than 0) and that made the problem visible becausepage_to_nidwill return 0 and there are no zones on the node.Let's check that the zone is valid and that the given pfn falls into its boundaries and mark the section not removable. This might cause some false positives, probably, but we do not have any sane way to find out whether the page is reserved by the platform or it is just not used for whatever other reasons.
Signed-off-by Michal Hocko <[email protected]>Cc Andrew Morton <[email protected]>Cc Mel Gorman <[email protected]>Cc KAMEZAWA Hiroyuki <[email protected]>Cc Andrea Arcangeli <[email protected]>Cc David Rientjes <[email protected]>--- mm/page_alloc.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)mm/page_alloc.c +4
-0@@ -5608,6 +5608,17 @@ __count_immobile_pages(struct zone *zone, struct page *page, int count)bool is_pageblock_removable_nolock (struct page *page) {struct zone *zone =page_zone (page); +unsigned long pfn =page_to_pfn (page); + +/* +* We have to be careful here because we are iterating over memory
mm/page_alloc.c __count_immobile_pages(struct zone *zone, struct page *page, int count) · line 5624
Quoted 10 lines
mm/page_alloc.c +7
-0+* sections which are not zone aware so we might end up outside of +* the zone but still within the section. +*/ +if (!zone || zone->zone_start_pfn > pfn || + zone->zone_start_pfn + zone->spanned_pages <= pfn) +return false; +return __count_immobile_pages (zone, page,0 ); }
This seems partially bogus, why would
page_zone(page)->zone_start_pfn > page_to_pfn(page) || page_zone(page)->zone_start_pfn + page_zone(page)->spanned_pages <= page_to_pfn(page)
ever be true? That would certainly mean that the struct zone is corrupted and seems to be unnecessary to fix the problem you're addressing.
I think this should be handled in is_mem_section_removable() on the pfn rather than using the struct page in is_pageblock_removable_nolock() and converting back and forth. We should make sure that any page passed to is_pageblock_removable_nolock() is valid.
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 1 line · David Rientjes
On Tue, 10 Jan 2012, Michal Hocko wrote:
[...]
Quoted 28 lines
Quoted 15 lines
mm/page_alloc.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)mm/page_alloc.c +4
-0@@ -5608,6 +5608,17 @@ __count_immobile_pages(struct zone *zone, struct page *page, int count)bool is_pageblock_removable_nolock (struct page *page) {struct zone *zone =page_zone (page); +unsigned long pfn =page_to_pfn (page); + +/* +* We have to be careful here because we are iterating over memory mm/page_alloc.c __count_immobile_pages(struct zone *zone, struct page *page, int count) · line 5624
Quoted 10 lines
mm/page_alloc.c +7
-0+* sections which are not zone aware so we might end up outside of +* the zone but still within the section. +*/ +if (!zone || zone->zone_start_pfn > pfn || + zone->zone_start_pfn + zone->spanned_pages <= pfn) +return false; +return __count_immobile_pages (zone, page,0 ); }This seems partially bogus, why would
Quoted 5 lines
page_zone(page)->zone_start_pfn > page_to_pfn(page) || page_zone(page)->zone_start_pfn + page_zone(page)->spanned_pages <= page_to_pfn(page)ever be true? That would certainly mean that the struct zone is corrupted and seems to be unnecessary to fix the problem you're addressing.
Not really. Consider the case when the node 0 is present. Uninitialized page would lead to node=0, zone=0 and then we have to check for the zone boundaries.
Quoted 4 lines
I think this should be handled in
is_mem_section_removable()on the pfn rather than using the struct page inis_pageblock_removable_nolock()and converting back and forth. We should make sure that any page passed tois_pageblock_removable_nolock()is valid.
Yes, I do not like pfn->page->pfn dance as well and in fact I do not have a strong opinion which one is better. I just put it at the place where we care about zone to be more obvious. If others think that I should move the check one level higher I'll do that. I just think this is more obvious.
Thanks for your comments.
Signature · 13 lines
Michal Hocko SUSE Labs SUSE LINUX s.r.o. Lihovarska 1060/12 190 00 Praha 9 Czech Republic -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 6 lines · On Wed, 11 Jan 2012 09:48:02 +0100 Michal Hocko <[email protected]> wrote:
Quoted 1 line · David Rientjes
On Tue, 10 Jan 2012, Michal Hocko wrote:
[...]
Quoted 3 lines
Quoted 3 lines
mm/page_alloc.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
Quoted 10 lines
Quoted 10 lines
mm/page_alloc.c __count_immobile_pages(struct zone *zone, struct page *page, int count) · line 5612
Quoted 10 lines
mm/page_alloc.c +2
-0@@ -5608,6 +5608,17 @@ __count_immobile_pages(struct zone *zone, struct page *page, int count)bool is_pageblock_removable_nolock (struct page *page) {struct zone *zone =page_zone (page); +unsigned long pfn =page_to_pfn (page); +
Hmm, I don't like to use page_zone() when we know the page may not be initialized. Shouldn't we add
if (!node_online(page_to_nid(page)) return false;
?
But...hmm. I think we should return 'true' here for removing a section with a hole finally....(Now, false will be safe.)
Quoted 33 lines
Quoted 15 lines
mm/page_alloc.c __count_immobile_pages(struct zone *zone, struct page *page, int count) · line 5624
Quoted 12 lines
mm/page_alloc.c +9
-0+/* +* We have to be careful here because we are iterating over memory +* sections which are not zone aware so we might end up outside of +* the zone but still within the section. +*/ +if (!zone || zone->zone_start_pfn > pfn || + zone->zone_start_pfn + zone->spanned_pages <= pfn) +return false; +return __count_immobile_pages (zone, page,0 ); }This seems partially bogus, why would
Quoted 5 lines
page_zone(page)->zone_start_pfn > page_to_pfn(page) || page_zone(page)->zone_start_pfn + page_zone(page)->spanned_pages <= page_to_pfn(page)ever be true? That would certainly mean that the struct zone is corrupted and seems to be unnecessary to fix the problem you're addressing.
Not really. Consider the case when the node 0 is present. Uninitialized page would lead to node=0, zone=0 and then we have to check for the zone boundaries.
Quoted 4 lines
I think this should be handled in
is_mem_section_removable()on the pfn rather than using the struct page inis_pageblock_removable_nolock()and converting back and forth. We should make sure that any page passed tois_pageblock_removable_nolock()is valid.
Quoted 6 lines
Yes, I do not like
pfn->page->pfndance as well and in fact I do not have a strong opinion which one is better. I just put it at the place where we care about zone to be more obvious. If others think that I should move the check one level higher I'll do that. I just think this is more obvious.
Hmm, mem_section and pageblock is a different chunk...
And, IIUC, in some IBM machines, section may includes several zones. Please taking care of that if you move this to is_mem_section_removable()...
Thanks,
-Kame
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 23 lines · KAMEZAWA Hiroyuki
Quoted 6 lines · On Wed, 11 Jan 2012 09:48:02 +0100 Michal Hocko <[email protected]> wrote:
Quoted 1 line · David Rientjes
On Tue, 10 Jan 2012, Michal Hocko wrote:
[...]
Quoted 3 lines
Quoted 3 lines
mm/page_alloc.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)Quoted 10 lines
Quoted 10 lines
mm/page_alloc.c __count_immobile_pages(struct zone *zone, struct page *page, int count) · line 5612
Quoted 10 lines
mm/page_alloc.c +2
-0@@ -5608,6 +5608,17 @@ __count_immobile_pages(struct zone *zone, struct page *page, int count)bool is_pageblock_removable_nolock (struct page *page) {struct zone *zone =page_zone (page); +unsigned long pfn =page_to_pfn (page); +Hmm, I don't like to use
page_zone()when we know the page may not be initialized. Shouldn't we add
Quoted 3 lines
if (!node_online(page_to_nid(page)) return false;?
How is this different? The node won't be initialized in page flags as well.
Quoted 2 lines
But...hmm. I think we should return 'true' here for removing a section with a hole finally....(Now, false will be safe.)
Those pages are reserved (for BIOS I guess) in this particular case so I do not think it is safe to claim that the block is removable. Or am I missing something?
[...]
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
I think this should be handled in
is_mem_section_removable()on the pfn rather than using the struct page inis_pageblock_removable_nolock()and converting back and forth. We should make sure that any page passed tois_pageblock_removable_nolock()is valid.Yes, I do not like
pfn->page->pfndance as well and in fact I do not have a strong opinion which one is better. I just put it at the place where we care about zone to be more obvious. If others think that I should move the check one level higher I'll do that. I just think this is more obvious.
Quoted 3 lines
Hmm,
mem_sectionand pageblock is a different chunk...
And, IIUC, in some IBM machines, section may includes several zones. Please taking care of that if you move this tois_mem_section_removable()...
Thanks for pointing this out.
Quoted 3 lines
Thanks,
-Kame
Thanks for comments.
Signature · 13 lines
Michal Hocko SUSE Labs SUSE LINUX s.r.o. Lihovarska 1060/12 190 00 Praha 9 Czech Republic -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 24 lines · On Thu, 12 Jan 2012 09:27:22 +0100 Michal Hocko <[email protected]> wrote:
Quoted 23 lines · KAMEZAWA Hiroyuki
Quoted 6 lines · On Wed, 11 Jan 2012 09:48:02 +0100 Michal Hocko <[email protected]> wrote:
Quoted 1 line · David Rientjes
On Tue, 10 Jan 2012, Michal Hocko wrote:
[...]
Quoted 3 lines
Quoted 3 lines
mm/page_alloc.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)Quoted 10 lines
Quoted 10 lines
mm/page_alloc.c __count_immobile_pages(struct zone *zone, struct page *page, int count) · line 5612
Quoted 10 lines
mm/page_alloc.c +2
-0@@ -5608,6 +5608,17 @@ __count_immobile_pages(struct zone *zone, struct page *page, int count)bool is_pageblock_removable_nolock (struct page *page) {struct zone *zone =page_zone (page); +unsigned long pfn =page_to_pfn (page); +Hmm, I don't like to use
page_zone()when we know the page may not be initialized. Shouldn't we add
Quoted 7 lines
Quoted 3 lines
if (!node_online(page_to_nid(page)) return false;?
How is this different? The node won't be initialized in page flags as well.
page_zone(page) is
==
static inline struct zone *page_zone(const struct page *page)
{
return &NODE_DATA(page_to_nid(page))->node_zones[page_zonenum(page)];
}==
Then, if the page is unitialized,
&(NODE_DATA(0)->node_zones[0])
If NODE_DATA(0) is NULL, node_zones[0] is NULL just because zone array is placed on the top of struct pglist_data.
I never think someone may change the layout but...Hmm, just a nitpick. please do as you like.
Quoted 7 lines
Quoted 2 lines
But...hmm. I think we should return 'true' here for removing a section with a hole finally....(Now, false will be safe.)
Those pages are reserved (for BIOS I guess) in this particular case so I do not think it is safe to claim that the block is removable. Or am I missing something?
We can't know it's reserved by BIOS or it's just a memory hole by the fact the page wasn't initialized.
Thanks,
-Kame
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 45 lines · KAMEZAWA Hiroyuki
Quoted 24 lines · On Thu, 12 Jan 2012 09:27:22 +0100 Michal Hocko <[email protected]> wrote:
Quoted 23 lines · KAMEZAWA Hiroyuki
Quoted 6 lines · On Wed, 11 Jan 2012 09:48:02 +0100 Michal Hocko <[email protected]> wrote:
Quoted 1 line · David Rientjes
On Tue, 10 Jan 2012, Michal Hocko wrote:
[...]
Quoted 3 lines
Quoted 3 lines
mm/page_alloc.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)Quoted 10 lines
Quoted 10 lines
mm/page_alloc.c __count_immobile_pages(struct zone *zone, struct page *page, int count) · line 5612
Quoted 10 lines
mm/page_alloc.c +2
-0@@ -5608,6 +5608,17 @@ __count_immobile_pages(struct zone *zone, struct page *page, int count)bool is_pageblock_removable_nolock (struct page *page) {struct zone *zone =page_zone (page); +unsigned long pfn =page_to_pfn (page); +Hmm, I don't like to use
page_zone()when we know the page may not be initialized. Shouldn't we addQuoted 7 lines
Quoted 3 lines
if (!node_online(page_to_nid(page)) return false;?
How is this different? The node won't be initialized in page flags as well.
page_zone(page)is
==
static inline struct zone *page_zone(const struct page *page){ return &NODE_DATA(page_to_nid(page))->node_zones[page_zonenum(page)]; }==
Then, if the page is unitialized,
Quoted 7 lines
&(NODE_DATA(0)->node_zones[0])If
NODE_DATA(0)is NULL, node_zones[0] is NULL just because zone array is placed on the top of structpglist_data.I never think someone may change the layout but...Hmm, just a nitpick. please do as you like.
Yes, fair point. See the follow up patch bellow.
Quoted 10 lines
Quoted 7 lines
Quoted 2 lines
But...hmm. I think we should return 'true' here for removing a section with a hole finally....(Now, false will be safe.)
Those pages are reserved (for BIOS I guess) in this particular case so I do not think it is safe to claim that the block is removable. Or am I missing something?
We can't know it's reserved by BIOS or it's just a memory hole by the fact the page wasn't initialized.
OK, so then we should return false to mark to block non removable, right?
---
Quoted 64 lines · On Thu, 12 Jan 2012 10:23:14 +0100 Michal Hocko <[email protected]> wrote:
Quoted 45 lines · KAMEZAWA Hiroyuki
Quoted 24 lines · On Thu, 12 Jan 2012 09:27:22 +0100 Michal Hocko <[email protected]> wrote:
Quoted 23 lines · KAMEZAWA Hiroyuki
Quoted 6 lines · On Wed, 11 Jan 2012 09:48:02 +0100 Michal Hocko <[email protected]> wrote:
Quoted 1 line · David Rientjes
On Tue, 10 Jan 2012, Michal Hocko wrote:
[...]
Quoted 3 lines
Quoted 3 lines
mm/page_alloc.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)Quoted 10 lines
Quoted 10 lines
mm/page_alloc.c __count_immobile_pages(struct zone *zone, struct page *page, int count) · line 5612
Quoted 10 lines
mm/page_alloc.c +2
-0@@ -5608,6 +5608,17 @@ __count_immobile_pages(struct zone *zone, struct page *page, int count)bool is_pageblock_removable_nolock (struct page *page) {struct zone *zone =page_zone (page); +unsigned long pfn =page_to_pfn (page); +Hmm, I don't like to use
page_zone()when we know the page may not be initialized. Shouldn't we addQuoted 7 lines
Quoted 3 lines
if (!node_online(page_to_nid(page)) return false;?
How is this different? The node won't be initialized in page flags as well.
page_zone(page)is
==
static inline struct zone *page_zone(const struct page *page){ return &NODE_DATA(page_to_nid(page))->node_zones[page_zonenum(page)]; }==
Then, if the page is unitialized,
Quoted 7 lines
&(NODE_DATA(0)->node_zones[0])If
NODE_DATA(0)is NULL, node_zones[0] is NULL just because zone array is placed on the top of structpglist_data.I never think someone may change the layout but...Hmm, just a nitpick. please do as you like.
Yes, fair point. See the follow up patch bellow.
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
But...hmm. I think we should return 'true' here for removing a section with a hole finally....(Now, false will be safe.)
Those pages are reserved (for BIOS I guess) in this particular case so I do not think it is safe to claim that the block is removable. Or am I missing something?
Quoted 5 lines
Quoted 2 lines
We can't know it's reserved by BIOS or it's just a memory hole by the fact the page wasn't initialized.
OK, so then we should return false to mark to block non removable, right?
Ok.
Quoted 35 lines
---
From04f74e6f0ebf28f61650d63f8884e8855fb21b55Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 12 Jan 2012 10:19:04 +0100
Subject: [PATCH] mm:__count_immobile_pagesmake sure the node is online
page_zonerequires to have an online node otherwise we are accessing NULLNODE_DATA. This is not an issue at the moment becausenode_zonesare located at the structure beginning but this might change in the future so better be careful about that.Signed-off-by Michal Hocko <[email protected]>Signed-off-by KAMEZAWA Hiroyuki <[email protected]>--- mm/page_alloc.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-)mm/page_alloc.c +3
-2@@ -5607,14 +5607,21 @@ __count_immobile_pages(struct zone *zone, struct page *page, int count)bool is_pageblock_removable_nolock (struct page *page) { -struct zone *zone =page_zone (page); -unsigned long pfn =page_to_pfn (page); +struct zone *zone; +unsigned long pfn;/* * We have to be careful here because we are iterating over memory * sections which are not zone aware so we might end up outside of * the zone but still within the section. +* We have to take care about the node as well. If the node is offline
mm/page_alloc.c __count_immobile_pages(struct zone *zone, struct page *page, int count) · line 5627
Quoted 10 lines
mm/page_alloc.c +6
-0+* its NODE_DATA will be NULL - see page_zone. */ +if (!node_online (page_to_nid (page))) +return false; + + zone =page_zone (page); + pfn =page_to_pfn (page);if (!zone || zone->zone_start_pfn > pfn || zone->zone_start_pfn + zone->spanned_pages <= pfn)return false;
!zone check can be removed because of node_online() check.
Thanks,
-Kame
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/1 mm: __count_immobile_pages make sure the node is online
On Thu 12-01-12 18:33:23, KAMEZAWA Hiroyuki wrote:
[...]
Quoted 38 lines
Quoted 38 lines
From
04f74e6f0ebf28f61650d63f8884e8855fb21b55Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 12 Jan 2012 10:19:04 +0100
Subject: [PATCH] mm:__count_immobile_pagesmake sure the node is online
page_zonerequires to have an online node otherwise we are accessing NULLNODE_DATA. This is not an issue at the moment becausenode_zonesare located at the structure beginning but this might change in the future so better be careful about that.Signed-off-by Michal Hocko <[email protected]>Signed-off-by KAMEZAWA Hiroyuki <[email protected]>--- mm/page_alloc.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-)mm/page_alloc.c +6
-2@@ -5607,14 +5607,21 @@ __count_immobile_pages(struct zone *zone, struct page *page, int count)bool is_pageblock_removable_nolock (struct page *page) { -struct zone *zone =page_zone (page); -unsigned long pfn =page_to_pfn (page); +struct zone *zone; +unsigned long pfn;/* * We have to be careful here because we are iterating over memory * sections which are not zone aware so we might end up outside of * the zone but still within the section. +* We have to take care about the node as well. If the node is offline +* its NODE_DATA will be NULL - see page_zone. */ +if (!node_online (page_to_nid (page))) +return false;
Quoted 8 lines
mm/page_alloc.c __count_immobile_pages(struct zone *zone, struct page *page, int count) · line 5627
Quoted 6 lines
mm/page_alloc.c +3
-0+ + zone =page_zone (page); + pfn =page_to_pfn (page);if (!zone || zone->zone_start_pfn > pfn || zone->zone_start_pfn + zone->spanned_pages <= pfn)return false;!zone check can be removed because of
node_online()check.
Yes you are right. Fixed bellow:
---
Re: [PATCH] mm: __count_immobile_pages make sure the node is online
Quoted 5 lines · Michal Hocko
From
39de8df13532150fc4518dad0cb3f6fd88745b8aMon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 12 Jan 2012 10:19:04 +0100
Subject: [PATCH] mm:__count_immobile_pagesmake sure the node is online
Quoted 7 lines
page_zonerequires to have an online node otherwise we are accessing NULLNODE_DATA. This is not an issue at the moment becausenode_zonesare located at the structure beginning but this might change in the future so better be careful about that.Signed-off-by Michal Hocko <[email protected]>Signed-off-by KAMEZAWA Hiroyuki <[email protected]>
Be aware that this is not the version picked up by Andrew. It would not hurt to resend as V2 with a changelog and a note saying it replaces mm-fix-null-ptr-dereference-in-__count_immobile_pages.patch in mmotm. This is just in case the wrong one gets merged due to this thread getting lost in the noise of Andrew's inbox.
Signature · 9 lines
Mel Gorman SUSE Labs -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH] mm: __count_immobile_pages make sure the node is online
Quoted 11 lines · Mel Gorman
Quoted 10 lines · Michal Hocko
From
39de8df13532150fc4518dad0cb3f6fd88745b8aMon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 12 Jan 2012 10:19:04 +0100
Subject: [PATCH] mm:__count_immobile_pagesmake sure the node is online
page_zonerequires to have an online node otherwise we are accessing NULLNODE_DATA. This is not an issue at the moment becausenode_zonesare located at the structure beginning but this might change in the future so better be careful about that.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Michal Hocko <[email protected]>Signed-off-by KAMEZAWA Hiroyuki <[email protected]>Acked-by Mel Gorman <[email protected]>
Thanks
Quoted 5 lines
Be aware that this is not the version picked up by Andrew. It would not hurt to resend as V2 with a changelog and a note saying it replaces mm-fix-null-ptr-dereference-in-__count_immobile_pages.patch in mmotm. This is just in case the wrong one gets merged due to this thread getting lost in the noise of Andrew's inbox.
I guess that both of them should be merged. This one as a follow up fix. That's why I made it separate and didn't repost the whole patch. The original patch is much more obvious why it fixes the issue this one is to have everything clear.
Signature · 13 lines
Michal Hocko SUSE Labs SUSE LINUX s.r.o. Lihovarska 1060/12 190 00 Praha 9 Czech Republic -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerRe: [PATCH] mm: __count_immobile_pages make sure the node is online
Quoted 6 lines · On Thu, 12 Jan 2012 13:35:55 +0100 Michal Hocko <[email protected]> wrote:
Quoted 5 lines · Mel Gorman
On Thu, Jan 12, 2012 at 11:05:21AM +0100, Michal Hocko wrote:
Be aware that this is not the version picked up by Andrew. It would not hurt to resend as V2 with a changelog and a note saying it replaces mm-fix-null-ptr-dereference-in-__count_immobile_pages.patch in mmotm.
They're rather different things? According to the changelogs, mm-fix-null-ptr-dereference-in-__count_immobile_pages.patch fixes a known-to-occur oops. mm-__count_immobile_pages-make-sure-the-node-is-online.patch fixes a bug which might happen in the future if we change the node_zones layut?
So I'm thinking that mm-fix-null-ptr-dereference-in-__count_immobile_pages.patch is 3.3 and -stable material, whereas this patch (mm-__count_immobile_pages-make-sure-the-node-is-online.patch) is 3.3 material. (Actually, it's 3.4 material which I shall stuff into 3.3 because the amount of MM material which we're putting into 3.3 is just off the charts and I fear that 3.4 will be similar)
Quoted 2 lines
Quoted 2 lines
This is just in case the wrong one gets merged due to this thread getting lost in the noise of Andrew's inbox.
It won't get lost, but there's a higher-than-usual chance of delays if the patch happens during the merge window: if I see a lengthy patch thread I'll move it into my to-apply folder for consideration later on. So I will look at it, but it might be after the merge window. We can still apply a fix after the merge window of course, but this all might end up leaving buggy code in the tree for longer than we'd like.
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH] mm: __count_immobile_pages make sure the node is online
Quoted 10 lines · Andrew Morton
Quoted 6 lines · On Thu, 12 Jan 2012 13:35:55 +0100 Michal Hocko <[email protected]> wrote:
Quoted 5 lines · Mel Gorman
On Thu, Jan 12, 2012 at 11:05:21AM +0100, Michal Hocko wrote:
Be aware that this is not the version picked up by Andrew. It would not hurt to resend as V2 with a changelog and a note saying it replaces mm-fix-null-ptr-dereference-in-__count_immobile_pages.patch in mmotm.
Quoted 5 lines
They're rather different things? According to the changelogs, mm-fix-null-ptr-dereference-in-__count_immobile_pages.patch fixes a known-to-occur oops. mm-__count_immobile_pages-make-sure-the-node-is-online.patch fixes a bug which might happen in the future if we change the
node_zoneslayut?
Yes, and that's the reason why I posted it as a separate patch. I could also have squashed both patches together and it would work the same way but I think that the zone issue wouldn't be that obvious.
Quoted 8 lines
So I'm thinking that mm-fix-null-ptr-dereference-in-__count_immobile_pages.patch is 3.3 and -stable material, whereas this patch (mm-__count_immobile_pages-make-sure-the-node-is-online.patch) is 3.3 material. (Actually, it's 3.4 material which I shall stuff into 3.3 because the amount of MM material which we're putting into 3.3 is just off the charts and I fear that 3.4 will be similar)
Agreed
Thanks
Signature · 13 lines
Michal Hocko SUSE Labs SUSE LINUX s.r.o. Lihovarska 1060/12 190 00 Praha 9 Czech Republic -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH] mm: __count_immobile_pages make sure the node is online
In reply to Andrew MortonQuoted 10 lines · Andrew Morton
Quoted 6 lines · On Thu, 12 Jan 2012 13:35:55 +0100 Michal Hocko <[email protected]> wrote:
Quoted 5 lines · Mel Gorman
On Thu, Jan 12, 2012 at 11:05:21AM +0100, Michal Hocko wrote:
Be aware that this is not the version picked up by Andrew. It would not hurt to resend as V2 with a changelog and a note saying it replaces mm-fix-null-ptr-dereference-in-__count_immobile_pages.patch in mmotm.
Quoted 6 lines
They're rather different things? According to the changelogs, mm-fix-null-ptr-dereference-in-__count_immobile_pages.patch fixes a known-to-occur oops. mm-__count_immobile_pages-make-sure-the-node-is-online.patch fixes a bug which might happen in the future if we change the
node_zoneslayut?
That's fine. I thought the second patch was so closely related that they would be collapsed together and both sent to stable. There is no particular advantage to doing this and keeping them separate is fine.
FWIW, my ack applied to both patches in that case.
Quoted 8 lines
So I'm thinking that mm-fix-null-ptr-dereference-in-__count_immobile_pages.patch is 3.3 and -stable material, whereas this patch (mm-__count_immobile_pages-make-sure-the-node-is-online.patch) is 3.3 material. (Actually, it's 3.4 material which I shall stuff into 3.3 because the amount of MM material which we're putting into 3.3 is just off the charts and I fear that 3.4 will be similar)
Ok, sounds good. Thanks.
Quoted 10 lines
Quoted 2 lines
Quoted 2 lines
This is just in case the wrong one gets merged due to this thread getting lost in the noise of Andrew's inbox.
It won't get lost, but there's a higher-than-usual chance of delays if the patch happens during the merge window: if I see a lengthy patch thread I'll move it into my to-apply folder for consideration later on. So I will look at it, but it might be after the merge window. We can still apply a fix after the merge window of course, but this all might end up leaving buggy code in the tree for longer than we'd like.
Understood.
Signature · 9 lines
Mel Gorman SUSE Labs -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 2 lines · On Tue, 10 Jan 2012 17:30:22 +0100 Michal Hocko <[email protected]> wrote:
This patch fixes the following NULL ptr dereference caused by cat
/sys/devices/system/memory/memory0/removable:
Which is world-readable, I assume?
Quoted 10 lines
...
mm/page_alloc.c +3
-0@@ -5608,6 +5608,17 @@ __count_immobile_pages(struct zone *zone, struct page *page, int count)bool is_pageblock_removable_nolock (struct page *page) {struct zone *zone =page_zone (page); +unsigned long pfn =page_to_pfn (page); + +/*
mm/page_alloc.c __count_immobile_pages(struct zone *zone, struct page *page, int count) · line 5623
Quoted 10 lines
mm/page_alloc.c +8
-0+* We have to be careful here because we are iterating over memory +* sections which are not zone aware so we might end up outside of +* the zone but still within the section. +*/ +if (!zone || zone->zone_start_pfn > pfn || + zone->zone_start_pfn + zone->spanned_pages <= pfn) +return false; +return __count_immobile_pages (zone, page,0 ); }
So I propose that we backport it into -stable?
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Andrew Morton
Quoted 2 lines · On Tue, 10 Jan 2012 17:30:22 +0100 Michal Hocko <[email protected]> wrote:
This patch fixes the following NULL ptr dereference caused by cat
/sys/devices/system/memory/memory0/removable:Which is world-readable, I assume?
Right. But considering that we haven't seen any report like that it seems that the HW is rather rare
Quoted 15 lines
Quoted 15 lines
...
mm/page_alloc.c +7
-0@@ -5608,6 +5608,17 @@ __count_immobile_pages(struct zone *zone, struct page *page, int count)bool is_pageblock_removable_nolock (struct page *page) {struct zone *zone =page_zone (page); +unsigned long pfn =page_to_pfn (page); + +/* +* We have to be careful here because we are iterating over memory +* sections which are not zone aware so we might end up outside of +* the zone but still within the section. +*/
Quoted 8 lines
mm/page_alloc.c __count_immobile_pages(struct zone *zone, struct page *page, int count) · line 5623
Quoted 6 lines
mm/page_alloc.c +4
-0+if (!zone || zone->zone_start_pfn > pfn || + zone->zone_start_pfn + zone->spanned_pages <= pfn) +return false; +return __count_immobile_pages (zone, page,0 ); }So I propose that we backport it into -stable?
Agreed.
Signature · 13 lines
Michal Hocko SUSE Labs SUSE LINUX s.r.o. Lihovarska 1060/12 190 00 Praha 9 Czech Republic -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>