Patch "mm: page_alloc: fix CMA and HIGHATOMIC landing on the wrong buddy list" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    mm: page_alloc: fix CMA and HIGHATOMIC landing on the wrong buddy list

to the 6.1-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-page_alloc-fix-cma-and-highatomic-landing-on-the-.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 65647c5732d410e694b93da2cffed9f76a5e599b
Author: Johannes Weiner <hannes@xxxxxxxxxxx>
Date:   Mon Sep 11 14:11:08 2023 -0400

    mm: page_alloc: fix CMA and HIGHATOMIC landing on the wrong buddy list
    
    [ Upstream commit 7b086755fb8cdbb6b3e45a1bbddc00e7f9b1dc03 ]
    
    Commit 4b23a68f9536 ("mm/page_alloc: protect PCP lists with a spinlock")
    bypasses the pcplist on lock contention and returns the page directly to
    the buddy list of the page's migratetype.
    
    For pages that don't have their own pcplist, such as CMA and HIGHATOMIC,
    the migratetype is temporarily updated such that the page can hitch a ride
    on the MOVABLE pcplist.  Their true type is later reassessed when flushing
    in free_pcppages_bulk().  However, when lock contention is detected after
    the type was already overridden, the bypass will then put the page on the
    wrong buddy list.
    
    Once on the MOVABLE buddy list, the page becomes eligible for fallbacks
    and even stealing.  In the case of HIGHATOMIC, otherwise ineligible
    allocations can dip into the highatomic reserves.  In the case of CMA, the
    page can be lost from the CMA region permanently.
    
    Use a separate pcpmigratetype variable for the pcplist override.  Use the
    original migratetype when going directly to the buddy.  This fixes the bug
    and should make the intentions more obvious in the code.
    
    Originally sent here to address the HIGHATOMIC case:
    https://lore.kernel.org/lkml/20230821183733.106619-4-hannes@xxxxxxxxxxx/
    
    Changelog updated in response to the CMA-specific bug report.
    
    [mgorman@xxxxxxxxxxxxxxxxxxx: updated changelog]
    Link: https://lkml.kernel.org/r/20230911181108.GA104295@xxxxxxxxxxx
    Fixes: 4b23a68f9536 ("mm/page_alloc: protect PCP lists with a spinlock")
    Signed-off-by: Johannes Weiner <hannes@xxxxxxxxxxx>
    Reported-by: Joe Liu <joe.liu@xxxxxxxxxxxx>
    Reviewed-by: Vlastimil Babka <vbabka@xxxxxxx>
    Cc: <stable@xxxxxxxxxxxxxxx>
    Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 90082f75660f2..ca017c6008b7c 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3448,7 +3448,7 @@ void free_unref_page(struct page *page, unsigned int order)
 	struct per_cpu_pages *pcp;
 	struct zone *zone;
 	unsigned long pfn = page_to_pfn(page);
-	int migratetype;
+	int migratetype, pcpmigratetype;
 
 	if (!free_unref_page_prepare(page, pfn, order))
 		return;
@@ -3456,24 +3456,24 @@ void free_unref_page(struct page *page, unsigned int order)
 	/*
 	 * We only track unmovable, reclaimable and movable on pcp lists.
 	 * Place ISOLATE pages on the isolated list because they are being
-	 * offlined but treat HIGHATOMIC as movable pages so we can get those
-	 * areas back if necessary. Otherwise, we may have to free
+	 * offlined but treat HIGHATOMIC and CMA as movable pages so we can
+	 * get those areas back if necessary. Otherwise, we may have to free
 	 * excessively into the page allocator
 	 */
-	migratetype = get_pcppage_migratetype(page);
+	migratetype = pcpmigratetype = get_pcppage_migratetype(page);
 	if (unlikely(migratetype >= MIGRATE_PCPTYPES)) {
 		if (unlikely(is_migrate_isolate(migratetype))) {
 			free_one_page(page_zone(page), page, pfn, order, migratetype, FPI_NONE);
 			return;
 		}
-		migratetype = MIGRATE_MOVABLE;
+		pcpmigratetype = MIGRATE_MOVABLE;
 	}
 
 	zone = page_zone(page);
 	pcp_trylock_prepare(UP_flags);
 	pcp = pcp_spin_trylock(zone->per_cpu_pageset);
 	if (pcp) {
-		free_unref_page_commit(zone, pcp, page, migratetype, order);
+		free_unref_page_commit(zone, pcp, page, pcpmigratetype, order);
 		pcp_spin_unlock(pcp);
 	} else {
 		free_one_page(zone, page, pfn, order, migratetype, FPI_NONE);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux