Skip to contentSkip to conversation

mm-close-pagetail-race.patch removed from -mm tree

merged [email protected] 1 participant 1 message Mar 6, 2014

Subsystems (9)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

Subject: [merged] mm-close-pagetail-race.patch removed from -mm tree
To: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
From: [email protected]
Date: Thu, 06 Mar 2014 12:37:22 -0800

The patch titled
Subject: mm: close PageTail race
has been removed from the -mm tree. Its filename was
mm-close-pagetail-race.patch

This patch was dropped because it was merged into mainline or a subsystem tree

------------------------------------------------------
From: David Rientjes <[email protected]>
Subject: mm: close PageTail race

Since "mm, compaction: avoid isolating pinned pages", it has been possible for page_count(page) to race with prep_compound_page() by finding PageTail(page) set with a NULL or dangling page->first_page.

"mm, page_alloc: make first_page visible before PageTail" adds a store memory barrier to prep_compound_page() to ensure page->first_page is set, but nothing is preventing compound_head() from seeing a dangling head page.

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.

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.

Cc Holger Kiehl <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Rafael Aquini <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Rik van Riel <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>

---

 drivers/block/aoe/aoecmd.c      |    4 +-
 drivers/vfio/vfio_iommu_type1.c |    4 +-
 fs/proc/page.c                  |    5 +--
 include/linux/huge_mm.h         |   41 ------------------------------
 include/linux/mm.h              |   14 ++++++++--
 mm/ksm.c                        |    2 -
 mm/memory-failure.c             |    2 -
 mm/swap.c                       |    4 +-
 8 files changed, 22 insertions(+), 54 deletions(-)
drivers/block/aoe/aoecmd.c renamed from drivers/block/aoe/aoecmd.c~mm-close-pagetail-race +2 -2
diff -puN drivers/block/aoe/aoecmd.c~mm-close-pagetail-race drivers/block/aoe/aoecmd.c
@@ -874,7 +874,7 @@ bio_pageinc(struct bio *bio)
 		/* Non-zero page count for non-head members of
 		 * compound pages is no longer allowed by the kernel.
 		 */
-		page = compound_trans_head(bv.bv_page);
+		page = compound_head(bv.bv_page);
 		atomic_inc(&page->_count);
 	}
 }
@@ -887,7 +887,7 @@ bio_pagedec(struct bio *bio)
 	struct bvec_iter iter;
 
 	bio_for_each_segment(bv, bio, iter) {
-		page = compound_trans_head(bv.bv_page);
+		page = compound_head(bv.bv_page);
 		atomic_dec(&page->_count);
 	}
 }
drivers/vfio/vfio_iommu_type1.c renamed from drivers/vfio/vfio_iommu_type1.c~mm-close-pagetail-race +2 -2
diff -puN drivers/vfio/vfio_iommu_type1.c~mm-close-pagetail-race drivers/vfio/vfio_iommu_type1.c
@@ -186,12 +186,12 @@ static bool is_invalid_reserved_pfn(unsi
 	if (pfn_valid(pfn)) {
 		bool reserved;
 		struct page *tail = pfn_to_page(pfn);
-		struct page *head = compound_trans_head(tail);
+		struct page *head = compound_head(tail);
 		reserved = !!(PageReserved(head));
 		if (head != tail) {
 			/*
 			 * "head" is not a dangling pointer
-			 * (compound_trans_head takes care of that)
+			 * (compound_head takes care of that)
 			 * but the hugepage may have been split
 			 * from under us (and we may not hold a
 			 * reference count on the head page so it can
fs/proc/page.c renamed from fs/proc/page.c~mm-close-pagetail-race +2 -3
diff -puN fs/proc/page.c~mm-close-pagetail-race fs/proc/page.c
@@ -121,9 +121,8 @@ u64 stable_page_flags(struct page *page)
 	 * just checks PG_head/PG_tail, so we need to check PageLRU/PageAnon
 	 * to make sure a given page is a thp, not a non-huge compound page.
 	 */
-	else if (PageTransCompound(page) &&
-		 (PageLRU(compound_trans_head(page)) ||
-		  PageAnon(compound_trans_head(page))))
+	else if (PageTransCompound(page) && (PageLRU(compound_head(page)) ||
+					     PageAnon(compound_head(page))))
 		u |= 1 << KPF_THP;
 
 	/*
include/linux/huge_mm.h renamed from include/linux/huge_mm.h~mm-close-pagetail-race +0 -41

53 lines not on this page · raw message

include/linux/mm.h renamed from include/linux/mm.h~mm-close-pagetail-race +12 -2
diff -puN include/linux/mm.h~mm-close-pagetail-race include/linux/mm.h
@@ -399,8 +399,18 @@ static inline void compound_unlock_irqre
 
 static inline struct page *compound_head(struct page *page)
 {
-	if (unlikely(PageTail(page)))
-		return page->first_page;
+	if (unlikely(PageTail(page))) {
+		struct page *head = page->first_page;
+
+		/*
+		 * page->first_page may be a dangling pointer to an old
+		 * compound page, so recheck that it is still a tail
+		 * page before returning.
+		 */
+		smp_rmb();
+		if (likely(PageTail(page)))
+			return head;
+	}
 	return page;
 }
 
mm/ksm.c renamed from mm/ksm.c~mm-close-pagetail-race +1 -1
diff -puN mm/ksm.c~mm-close-pagetail-race mm/ksm.c
@@ -444,7 +444,7 @@ static void break_cow(struct 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.
mm/memory-failure.c renamed from mm/memory-failure.c~mm-close-pagetail-race +1 -1
diff -puN mm/memory-failure.c~mm-close-pagetail-race mm/memory-failure.c
@@ -1651,7 +1651,7 @@ int soft_offline_page(struct page *page,
 {
 	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);
mm/swap.c renamed from mm/swap.c~mm-close-pagetail-race +2 -2
diff -puN mm/swap.c~mm-close-pagetail-race mm/swap.c
@@ -98,7 +98,7 @@ static void put_compound_page(struct pag
 	}
 
 	/* __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)) {

_

Patches currently in -mm which might be from [email protected] are

origin.patch
kthread-ensure-locality-of-task_struct-allocations.patch arch-x86-mm-kmemcheck-kmemcheckc-use-kstrtoint-instead-of-sscanf.patch mm-slab-slub-use-page-list-consistently-instead-of-page-lru.patch mm-compaction-ignore-pageblock-skip-when-manually-invoking-compaction.patch mm-vmscan-shrink_slab-rename-max_pass-freeable.patch mm-hugetlb-mark-some-bootstrap-functions-as-__init.patch mm-compaction-avoid-isolating-pinned-pages.patch
mm-compactionc-mark-function-as-static.patch
mm-memoryc-mark-functions-as-static.patch
mm-mmapc-mark-function-as-static.patch
mm-process_vm_accessc-mark-function-as-static.patch mm-process_vm_accessc-mark-function-as-static-fix.patch mm-page_cgroupc-mark-functions-as-static.patch
mm-nobootmemc-mark-function-as-static.patch
include-linux-mmh-remove-ifdef-condition.patch mm-readaheadc-fix-readahead-failure-for-memoryless-numa-nodes-and-limit-readahead-pages.patch mmnuma-reorganize-change_pmd_range.patch
mmnuma-reorganize-change_pmd_range-fix.patch move-mmu-notifier-call-from-change_protection-to-change_pmd_range.patch mm-exclude-memory-less-nodes-from-zone_reclaim.patch memcg-slab-never-try-to-merge-memcg-caches.patch
memcg-slab-cleanup-memcg-cache-creation.patch memcg-slab-separate-memcg-vs-root-cache-creation-paths.patch memcg-slab-unregister-cache-from-memcg-before-starting-to-destroy-it.patch memcg-slab-do-not-destroy-children-caches-if-parent-has-aliases.patch slub-adjust-memcg-caches-when-creating-cache-alias.patch slub-rework-sysfs-layout-for-memcg-caches.patch mm-revert-thp-make-madv_hugepage-check-for-mm-def_flags.patch mm-revert-thp-make-madv_hugepage-check-for-mm-def_flags-ignore-madv_hugepage-on-s390-to-prevent-sigsegv-in-qemu.patch mm-thp-add-vm_init_def_mask-and-prctl_thp_disable.patch exec-kill-the-unnecessary-mm-def_flags-setting-in-load_elf_binary.patch fork-collapse-copy_flags-into-copy_process.patch
mm-mempolicy-rename-slab_node-for-clarity.patch
mm-mempolicy-remove-per-process-flag.patch res_counter-remove-interface-for-locked-charging-and-uncharging.patch kernel-resourcec-make-reallocate_resource-static.patch
mm-utilc-add-kstrimdup.patch fault-injection-set-bounds-on-what-proc-self-make-it-fail-accepts.patch fault-injection-set-bounds-on-what-proc-self-make-it-fail-accepts-fix.patch
linux-next.patch