Skip to content

Commit 6b0868c

Browse files
committed
mm/compaction.c: correct zone boundary handling when resetting pageblock skip hints
Mikhail Gavrilo reported the following bug being triggered in a Fedora kernel based on 5.1-rc1 but it is relevant to a vanilla kernel. kernel: page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p)) kernel: ------------[ cut here ]------------ kernel: kernel BUG at include/linux/mm.h:1021! kernel: invalid opcode: 0000 [#1] SMP NOPTI kernel: CPU: 6 PID: 116 Comm: kswapd0 Tainted: G C 5.1.0-0.rc1.git1.3.fc31.x86_64 #1 kernel: Hardware name: System manufacturer System Product Name/ROG STRIX X470-I GAMING, BIOS 1201 12/07/2018 kernel: RIP: 0010:__reset_isolation_pfn+0x244/0x2b0 kernel: Code: fe 06 e8 0f 8e fc ff 44 0f b6 4c 24 04 48 85 c0 0f 85 dc fe ff ff e9 68 fe ff ff 48 c7 c6 58 b7 2e 8c 4c 89 ff e8 0c 75 00 00 <0f> 0b 48 c7 c6 58 b7 2e 8c e8 fe 74 00 00 0f 0b 48 89 fa 41 b8 01 kernel: RSP: 0018:ffff9e2d03f0fde8 EFLAGS: 00010246 kernel: RAX: 0000000000000034 RBX: 000000000081f380 RCX: ffff8cffbddd6c20 kernel: RDX: 0000000000000000 RSI: 0000000000000006 RDI: ffff8cffbddd6c20 kernel: RBP: 0000000000000001 R08: 0000009898b94613 R09: 0000000000000000 kernel: R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000100000 kernel: R13: 0000000000100000 R14: 0000000000000001 R15: ffffca7de07ce000 kernel: FS: 0000000000000000(0000) GS:ffff8cffbdc00000(0000) knlGS:0000000000000000 kernel: CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 kernel: CR2: 00007fc1670e9000 CR3: 00000007f5276000 CR4: 00000000003406e0 kernel: Call Trace: kernel: __reset_isolation_suitable+0x62/0x120 kernel: reset_isolation_suitable+0x3b/0x40 kernel: kswapd+0x147/0x540 kernel: ? finish_wait+0x90/0x90 kernel: kthread+0x108/0x140 kernel: ? balance_pgdat+0x560/0x560 kernel: ? kthread_park+0x90/0x90 kernel: ret_from_fork+0x27/0x50 He bisected it down to e332f74 ("mm, compaction: be selective about what pageblocks to clear skip hints"). The problem is that the patch in question was sloppy with respect to the handling of zone boundaries. In some instances, it was possible for PFNs outside of a zone to be examined and if those were not properly initialised or poisoned then it would trigger the VM_BUG_ON. This patch corrects the zone boundary issues when resetting pageblock skip hints and Mikhail reported that the bug did not trigger after 30 hours of testing. Link: http://lkml.kernel.org/r/[email protected] Fixes: e332f74 ("mm, compaction: be selective about what pageblocks to clear skip hints") Reported-by: Mikhail Gavrilov <[email protected]> Tested-by: Mikhail Gavrilov <[email protected]> Cc: Daniel Jordan <[email protected]> Cc: Qian Cai <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: Mel Gorman <[email protected]>
1 parent 79a3aaa commit 6b0868c

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

mm/compaction.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ __reset_isolation_pfn(struct zone *zone, unsigned long pfn, bool check_source,
242242
bool check_target)
243243
{
244244
struct page *page = pfn_to_online_page(pfn);
245+
struct page *block_page;
245246
struct page *end_page;
246247
unsigned long block_pfn;
247248

@@ -267,20 +268,26 @@ __reset_isolation_pfn(struct zone *zone, unsigned long pfn, bool check_source,
267268
get_pageblock_migratetype(page) != MIGRATE_MOVABLE)
268269
return false;
269270

271+
/* Ensure the start of the pageblock or zone is online and valid */
272+
block_pfn = pageblock_start_pfn(pfn);
273+
block_page = pfn_to_online_page(max(block_pfn, zone->zone_start_pfn));
274+
if (block_page) {
275+
page = block_page;
276+
pfn = block_pfn;
277+
}
278+
279+
/* Ensure the end of the pageblock or zone is online and valid */
280+
block_pfn += pageblock_nr_pages;
281+
block_pfn = min(block_pfn, zone_end_pfn(zone) - 1);
282+
end_page = pfn_to_online_page(block_pfn);
283+
if (!end_page)
284+
return false;
285+
270286
/*
271287
* Only clear the hint if a sample indicates there is either a
272288
* free page or an LRU page in the block. One or other condition
273289
* is necessary for the block to be a migration source/target.
274290
*/
275-
block_pfn = pageblock_start_pfn(pfn);
276-
pfn = max(block_pfn, zone->zone_start_pfn);
277-
page = pfn_to_page(pfn);
278-
if (zone != page_zone(page))
279-
return false;
280-
pfn = block_pfn + pageblock_nr_pages;
281-
pfn = min(pfn, zone_end_pfn(zone));
282-
end_page = pfn_to_page(pfn);
283-
284291
do {
285292
if (pfn_valid_within(pfn)) {
286293
if (check_source && PageLRU(page)) {
@@ -309,7 +316,7 @@ __reset_isolation_pfn(struct zone *zone, unsigned long pfn, bool check_source,
309316
static void __reset_isolation_suitable(struct zone *zone)
310317
{
311318
unsigned long migrate_pfn = zone->zone_start_pfn;
312-
unsigned long free_pfn = zone_end_pfn(zone);
319+
unsigned long free_pfn = zone_end_pfn(zone) - 1;
313320
unsigned long reset_migrate = free_pfn;
314321
unsigned long reset_free = migrate_pfn;
315322
bool source_set = false;

0 commit comments

Comments
 (0)