You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
mm: close PageTail race
Commit bf6bddf192 ("mm: introduce compaction and migration for
ballooned pages") introduces page_count(page) into memory compaction
which dereferences page->first_page if PageTail(page).
This results in a very rare NULL pointer dereference on the
aforementioned page_count(page). Indeed, anything that does
compound_head(), including page_count() is susceptible to racing with
prep_compound_page() and seeing a NULL or dangling page->first_page
pointer.
This patch uses Andrea's implementation of compound_trans_head() that
deals with such a race and makes it the default compound_head()
implementation. This includes a read memory barrier that ensures that
if PageTail(head) is true that we return a head page that is neither
NULL nor dangling. The patch then adds a store memory barrier to
prep_compound_page() to ensure page->first_page is set.
This is the safest way to ensure we see the head page that we are
expecting, PageTail(page) is already in the unlikely() path and the
memory barriers are unfortunately required.
Hugetlbfs is the exception, we don't enforce a store memory barrier
during init since no race is possible.
Signed-off-by: David Rientjes <rientjes@google.com>
Cc: Holger Kiehl <Holger.Kiehl@dwd.de>
Cc: Christoph Lameter <cl@linux.com>
Cc: Rafael Aquini <aquini@redhat.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
committed by
Linus Torvalds
parent
aa15aa0e86
commit
668f9abbd4
@@ -444,7 +444,7 @@ static void break_cow(struct rmap_item *rmap_item)
|
||||
static struct page *page_trans_compound_anon(struct page *page)
|
||||
{
|
||||
if (PageTransCompound(page)) {
|
||||
struct page *head = compound_trans_head(page);
|
||||
struct page *head = compound_head(page);
|
||||
/*
|
||||
* head may actually be splitted and freed from under
|
||||
* us but it's ok here.
|
||||
|
||||
+1
-1
@@ -1651,7 +1651,7 @@ int soft_offline_page(struct page *page, int flags)
|
||||
{
|
||||
int ret;
|
||||
unsigned long pfn = page_to_pfn(page);
|
||||
struct page *hpage = compound_trans_head(page);
|
||||
struct page *hpage = compound_head(page);
|
||||
|
||||
if (PageHWPoison(page)) {
|
||||
pr_info("soft offline: %#lx page already poisoned\n", pfn);
|
||||
|
||||
+3
-1
@@ -369,9 +369,11 @@ void prep_compound_page(struct page *page, unsigned long order)
|
||||
__SetPageHead(page);
|
||||
for (i = 1; i < nr_pages; i++) {
|
||||
struct page *p = page + i;
|
||||
__SetPageTail(p);
|
||||
set_page_count(p, 0);
|
||||
p->first_page = page;
|
||||
/* Make sure p->first_page is always valid for PageTail() */
|
||||
smp_wmb();
|
||||
__SetPageTail(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ static void put_compound_page(struct page *page)
|
||||
}
|
||||
|
||||
/* __split_huge_page_refcount can run under us */
|
||||
page_head = compound_trans_head(page);
|
||||
page_head = compound_head(page);
|
||||
|
||||
/*
|
||||
* THP can not break up slab pages so avoid taking
|
||||
@@ -253,7 +253,7 @@ bool __get_page_tail(struct page *page)
|
||||
*/
|
||||
unsigned long flags;
|
||||
bool got;
|
||||
struct page *page_head = compound_trans_head(page);
|
||||
struct page *page_head = compound_head(page);
|
||||
|
||||
/* Ref to put_compound_page() comment. */
|
||||
if (!__compound_tail_refcounted(page_head)) {
|
||||
|
||||
Reference in New Issue
Block a user