Patch "mm: prevent double decrease of nr_reserved_highatomic" has been added to the 4.4-stable tree
Subsystems (3)
This is a note to let you know that I've just added the patch titled
mm: prevent double decrease of nr_reserved_highatomic
to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
mm-prevent-double-decrease-of-nr_reserved_highatomic.patch
and it can be found in the queue-4.4 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
4855e4a7f29d6d10b0b9c84e189c770c9a94e91eMon Sep 17 00:00:00 2001
From: Minchan Kim <[email protected]>
Date: Mon, 12 Dec 2016 16:42:08 -0800
Subject: mm: prevent double decrease of nr_reserved_highatomic
From: Minchan Kim <[email protected]>
commit 4855e4a7f29d6d10b0b9c84e189c770c9a94e91e upstream.
There is race between page freeing and unreserved highatomic.
CPU 0 CPU 1
free_hot_cold_page
mt = get_pfnblock_migratetype set_pcppage_migratetype(page, mt)
unreserve_highatomic_pageblock spin_lock_irqsave(&zone->lock) move_freepages_block set_pageblock_migratetype(page) spin_unlock_irqrestore(&zone->lock)
free_pcppages_bulk
__free_one_page(mt) <- mt is stale
By above race, a page on CPU 0 could go non-highorderatomic free list since the pageblock's type is changed. By that, unreserve logic of highorderatomic can decrease reserved count on a same pageblock severak times and then it will make mismatch between nr_reserved_highatomic and the number of reserved pageblock.
So, this patch verifies whether the pageblock is highatomic or not and decrease the count only if the pageblock is highatomic.
--- mm/page_alloc.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
mm/page_alloc.c +18 -6
@@ -1748,13 +1748,25 @@ static void unreserve_highatomic_pageblo struct page, lru);/* -* It should never happen but changes to locking could -* inadvertently allow a per-cpu drain to add pages -* to MIGRATE_HIGHATOMIC while unreserving so be safe -* and watch for underflows. +* In page freeing path, migratetype change is racy so +* we can counter several free pages in a pageblock +* in this loop althoug we changed the pageblock type +* from highatomic to ac->migratetype. So we should +* adjust the count once. */ - zone->nr_reserved_highatomic -=min (pageblock_nr_pages, - zone->nr_reserved_highatomic); +if (get_pageblock_migratetype (page) == +MIGRATE_HIGHATOMIC ) { +/* +* It should never happen but changes to +* locking could inadvertently allow a per-cpu +* drain to add pages to MIGRATE_HIGHATOMIC +* while unreserving so be safe and watch for +* underflows. +*/ + zone->nr_reserved_highatomic -=min ( + pageblock_nr_pages, + zone->nr_reserved_highatomic); + }/* * Convert to ac->migratetype and avoid the normal
Patches currently in stable-queue which might be from [email protected] are
queue-4.4/mm-prevent-double-decrease-of-nr_reserved_highatomic.patch