* [PATCH 6.1.y 2/5] mm/migrate: don't call folio_putback_active_hugetlb() on dst hugetlb folio
2026-06-15 19:42 ` [PATCH 6.1.y 1/5] mm/hugetlb: rename isolate_hugetlb() to folio_isolate_hugetlb() Sasha Levin
@ 2026-06-15 19:42 ` Sasha Levin
2026-06-15 19:42 ` [PATCH 6.1.y 3/5] mm/hugetlb: rename folio_putback_active_hugetlb() to folio_putback_hugetlb() Sasha Levin
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Sasha Levin @ 2026-06-15 19:42 UTC (permalink / raw)
To: stable
Cc: David Hildenbrand, Baolin Wang, Matthew Wilcox (Oracle),
Muchun Song, Sidhartha Kumar, Andrew Morton, Sasha Levin
From: David Hildenbrand <david@redhat.com>
[ Upstream commit ba23f58de896842028b4b33b95530f08288396fe ]
We replaced a simple put_page() by a putback_active_hugepage() call in
commit 3aaa76e125c1 ("mm: migrate: hugetlb: putback destination hugepage
to active list"), to set the "active" flag on the dst hugetlb folio.
Nowadays, we decoupled the "active" list from the flag, by calling the
flag "migratable".
Calling "putback" on something that wasn't allocated is weird and not
future proof, especially if we might reach that path when migration failed
and we just want to free the freshly allocated hugetlb folio.
Let's simply handle the migratable flag and the active list flag in
move_hugetlb_state(), where we know that allocation succeeded and already
handle the temporary flag; use a simple folio_put() to return our
reference.
Link: https://lkml.kernel.org/r/20250113131611.2554758-4-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Stable-dep-of: 3c2d42b8ee34 ("mm/memory-failure: fix hugetlb_lock AA deadlock in get_huge_page_for_hwpoison")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
mm/hugetlb.c | 10 ++++++++++
mm/migrate.c | 8 ++++----
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index bde99cd3525784..bac2a00f7dbf08 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -7537,6 +7537,16 @@ void move_hugetlb_state(struct page *oldpage, struct page *newpage, int reason)
}
spin_unlock_irq(&hugetlb_lock);
}
+
+ /*
+ * Our old page is isolated and has "migratable" cleared until it
+ * is putback. As migration succeeded, set the new page "migratable"
+ * and add it to the active list.
+ */
+ spin_lock_irq(&hugetlb_lock);
+ SetHPageMigratable(newpage);
+ list_move_tail(&newpage->lru, &(page_hstate(newpage))->hugepage_activelist);
+ spin_unlock_irq(&hugetlb_lock);
}
/*
diff --git a/mm/migrate.c b/mm/migrate.c
index 9271f9dbd352a1..328071b861c368 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1460,14 +1460,14 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
list_move_tail(&src->lru, ret);
/*
- * If migration was not successful and there's a freeing callback, use
- * it. Otherwise, put_page() will drop the reference grabbed during
- * isolation.
+ * If migration was not successful and there's a freeing callback,
+ * return the folio to that special allocator. Otherwise, simply drop
+ * our additional reference.
*/
if (put_new_page)
put_new_page(new_hpage, private);
else
- putback_active_hugepage(new_hpage);
+ folio_put(dst);
return rc;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 6.1.y 3/5] mm/hugetlb: rename folio_putback_active_hugetlb() to folio_putback_hugetlb()
2026-06-15 19:42 ` [PATCH 6.1.y 1/5] mm/hugetlb: rename isolate_hugetlb() to folio_isolate_hugetlb() Sasha Levin
2026-06-15 19:42 ` [PATCH 6.1.y 2/5] mm/migrate: don't call folio_putback_active_hugetlb() on dst hugetlb folio Sasha Levin
@ 2026-06-15 19:42 ` Sasha Levin
2026-06-15 19:42 ` [PATCH 6.1.y 4/5] mm/memory-failure: fix missing ->mf_stats count in hugetlb poison Sasha Levin
2026-06-15 19:42 ` [PATCH 6.1.y 5/5] mm/memory-failure: fix hugetlb_lock AA deadlock in get_huge_page_for_hwpoison Sasha Levin
3 siblings, 0 replies; 6+ messages in thread
From: Sasha Levin @ 2026-06-15 19:42 UTC (permalink / raw)
To: stable
Cc: David Hildenbrand, Baolin Wang, Matthew Wilcox (Oracle),
Muchun Song, Sidhartha Kumar, Andrew Morton, Sasha Levin
From: David Hildenbrand <david@redhat.com>
[ Upstream commit b235448e8cab7eea17d164efc7bf55505985ba65 ]
Now that folio_putback_hugetlb() is only called on folios that were
previously isolated through folio_isolate_hugetlb(), let's rename it to
match folio_putback_lru().
Add some kernel doc to clarify how this function is supposed to be used.
Link: https://lkml.kernel.org/r/20250113131611.2554758-5-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Stable-dep-of: 3c2d42b8ee34 ("mm/memory-failure: fix hugetlb_lock AA deadlock in get_huge_page_for_hwpoison")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
include/linux/hugetlb.h | 4 ++--
mm/hugetlb.c | 15 +++++++++++++--
mm/migrate.c | 6 +++---
3 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 0fde057c81f6ce..9a0e8aa442b3e5 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -185,7 +185,7 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
int folio_isolate_hugetlb(struct page *page, struct list_head *list);
int get_hwpoison_huge_page(struct page *page, bool *hugetlb);
int get_huge_page_for_hwpoison(unsigned long pfn, int flags);
-void putback_active_hugepage(struct page *page);
+void folio_putback_hugetlb(struct page *page);
void move_hugetlb_state(struct page *oldpage, struct page *newpage, int reason);
void free_huge_page(struct page *page);
void hugetlb_fix_reserve_counts(struct inode *inode);
@@ -443,7 +443,7 @@ static inline int get_huge_page_for_hwpoison(unsigned long pfn, int flags)
return 0;
}
-static inline void putback_active_hugepage(struct page *page)
+static inline void folio_putback_hugetlb(struct page *page)
{
}
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index bac2a00f7dbf08..20095df62be4ba 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -7440,7 +7440,7 @@ follow_huge_pgd(struct mm_struct *mm, unsigned long address, pgd_t *pgd, int fla
* it is already isolated/non-migratable.
*
* On success, an additional page reference is taken that must be dropped
- * using putback_active_hugepage() to undo the isolation.
+ * using folio_putback_hugetlb() to undo the isolation.
*
* Return: 0 if isolation worked, otherwise -EBUSY.
*/
@@ -7491,7 +7491,18 @@ int get_huge_page_for_hwpoison(unsigned long pfn, int flags)
return ret;
}
-void putback_active_hugepage(struct page *page)
+/**
+ * folio_putback_hugetlb - unisolate a hugetlb page
+ * @page: the isolated hugetlb page
+ *
+ * Putback/un-isolate the hugetlb page that was previous isolated using
+ * folio_isolate_hugetlb(): marking it non-isolated/migratable and putting it
+ * back onto the active list.
+ *
+ * Will drop the additional page reference obtained through
+ * folio_isolate_hugetlb().
+ */
+void folio_putback_hugetlb(struct page *page)
{
spin_lock_irq(&hugetlb_lock);
SetHPageMigratable(page);
diff --git a/mm/migrate.c b/mm/migrate.c
index 328071b861c368..b5311dcb8dbbba 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -142,7 +142,7 @@ void putback_movable_pages(struct list_head *l)
list_for_each_entry_safe(page, page2, l, lru) {
if (unlikely(PageHuge(page))) {
- putback_active_hugepage(page);
+ folio_putback_hugetlb(page);
continue;
}
list_del(&page->lru);
@@ -1371,7 +1371,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
if (folio_ref_count(src) == 1) {
/* page was freed from under us. So we are done. */
- putback_active_hugepage(hpage);
+ folio_putback_hugetlb(hpage);
return MIGRATEPAGE_SUCCESS;
}
@@ -1455,7 +1455,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
folio_unlock(src);
out:
if (rc == MIGRATEPAGE_SUCCESS)
- putback_active_hugepage(hpage);
+ folio_putback_hugetlb(hpage);
else if (rc != -EAGAIN)
list_move_tail(&src->lru, ret);
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 6.1.y 4/5] mm/memory-failure: fix missing ->mf_stats count in hugetlb poison
2026-06-15 19:42 ` [PATCH 6.1.y 1/5] mm/hugetlb: rename isolate_hugetlb() to folio_isolate_hugetlb() Sasha Levin
2026-06-15 19:42 ` [PATCH 6.1.y 2/5] mm/migrate: don't call folio_putback_active_hugetlb() on dst hugetlb folio Sasha Levin
2026-06-15 19:42 ` [PATCH 6.1.y 3/5] mm/hugetlb: rename folio_putback_active_hugetlb() to folio_putback_hugetlb() Sasha Levin
@ 2026-06-15 19:42 ` Sasha Levin
2026-06-15 19:42 ` [PATCH 6.1.y 5/5] mm/memory-failure: fix hugetlb_lock AA deadlock in get_huge_page_for_hwpoison Sasha Levin
3 siblings, 0 replies; 6+ messages in thread
From: Sasha Levin @ 2026-06-15 19:42 UTC (permalink / raw)
To: stable
Cc: Jane Chu, Miaohe Lin, Chris Mason, David Hildenbrand,
David Rientjes, Jiaqi Yan, Liam R. Howlett, Lorenzo Stoakes,
Matthew Wilcox (Oracle), Michal Hocko, Mike Rapoport, Muchun Song,
Naoya Horiguchi, Oscar Salvador, Suren Baghdasaryan,
William Roche, Andrew Morton, Sasha Levin
From: Jane Chu <jane.chu@oracle.com>
[ Upstream commit a148a2040191b12b45b82cb29c281cb3036baf90 ]
When a newly poisoned subpage ends up in an already poisoned hugetlb
folio, 'num_poisoned_pages' is incremented, but the per node ->mf_stats is
not. Fix the inconsistency by designating action_result() to update them
both.
While at it, define __get_huge_page_for_hwpoison() return values in terms
of symbol names for better readibility. Also rename
folio_set_hugetlb_hwpoison() to hugetlb_update_hwpoison() since the
function does more than the conventional bit setting and the fact three
possible return values are expected.
Link: https://lkml.kernel.org/r/20260120232234.3462258-1-jane.chu@oracle.com
Fixes: 18f41fa616ee ("mm: memory-failure: bump memory failure stats to pglist_data")
Signed-off-by: Jane Chu <jane.chu@oracle.com>
Acked-by: Miaohe Lin <linmiaohe@huawei.com>
Cc: Chris Mason <clm@meta.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Jiaqi Yan <jiaqiyan@google.com>
Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Naoya Horiguchi <nao.horiguchi@gmail.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: William Roche <william.roche@oracle.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Stable-dep-of: 3c2d42b8ee34 ("mm/memory-failure: fix hugetlb_lock AA deadlock in get_huge_page_for_hwpoison")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
mm/memory-failure.c | 71 +++++++++++++++++++++++++++------------------
1 file changed, 43 insertions(+), 28 deletions(-)
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 109703dc39080c..1d39bdb434e734 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1730,12 +1730,22 @@ static unsigned long __free_raw_hwp_pages(struct page *hpage, bool move_flag)
return count;
}
-static int hugetlb_set_page_hwpoison(struct page *hpage, struct page *page)
+#define MF_HUGETLB_FREED 0 /* freed hugepage */
+#define MF_HUGETLB_IN_USED 1 /* in-use hugepage */
+#define MF_HUGETLB_NON_HUGEPAGE 2 /* not a hugepage */
+#define MF_HUGETLB_FOLIO_PRE_POISONED 3 /* folio already poisoned */
+#define MF_HUGETLB_PAGE_PRE_POISONED 4 /* exact page already poisoned */
+#define MF_HUGETLB_RETRY 5 /* hugepage is busy, retry */
+/*
+ * Set hugetlb page as hwpoisoned, update page private raw hwpoison list
+ * to keep track of the poisoned pages.
+ */
+static int hugetlb_update_hwpoison(struct page *hpage, struct page *page)
{
struct llist_head *head;
struct raw_hwp_page *raw_hwp;
struct llist_node *t, *tnode;
- int ret = TestSetPageHWPoison(hpage) ? -EHWPOISON : 0;
+ int ret = TestSetPageHWPoison(hpage) ? MF_HUGETLB_FOLIO_PRE_POISONED : 0;
/*
* Once the hwpoison hugepage has lost reliable raw error info,
@@ -1743,13 +1753,13 @@ static int hugetlb_set_page_hwpoison(struct page *hpage, struct page *page)
* so skip to add additional raw error info.
*/
if (HPageRawHwpUnreliable(hpage))
- return -EHWPOISON;
+ return MF_HUGETLB_FOLIO_PRE_POISONED;
head = raw_hwp_list_head(hpage);
llist_for_each_safe(tnode, t, head->first) {
struct raw_hwp_page *p = container_of(tnode, struct raw_hwp_page, node);
if (p->page == page)
- return -EHWPOISON;
+ return MF_HUGETLB_PAGE_PRE_POISONED;
}
raw_hwp = kmalloc(sizeof(struct raw_hwp_page), GFP_ATOMIC);
@@ -1804,41 +1814,38 @@ void hugetlb_clear_page_hwpoison(struct page *hpage)
/*
* Called from hugetlb code with hugetlb_lock held.
- *
- * Return values:
- * 0 - free hugepage
- * 1 - in-use hugepage
- * 2 - not a hugepage
- * -EBUSY - the hugepage is busy (try to retry)
- * -EHWPOISON - the hugepage is already hwpoisoned
*/
int __get_huge_page_for_hwpoison(unsigned long pfn, int flags)
{
struct page *page = pfn_to_page(pfn);
struct page *head = compound_head(page);
- int ret = 2; /* fallback to normal page handling */
bool count_increased = false;
+ int ret, rc;
- if (!PageHeadHuge(head))
+ if (!PageHeadHuge(head)) {
+ ret = MF_HUGETLB_NON_HUGEPAGE;
goto out;
-
- if (flags & MF_COUNT_INCREASED) {
- ret = 1;
+ } else if (flags & MF_COUNT_INCREASED) {
+ ret = MF_HUGETLB_IN_USED;
count_increased = true;
} else if (HPageFreed(head)) {
- ret = 0;
+ ret = MF_HUGETLB_FREED;
} else if (HPageMigratable(head)) {
- ret = get_page_unless_zero(head);
- if (ret)
+ if (get_page_unless_zero(head)) {
+ ret = MF_HUGETLB_IN_USED;
count_increased = true;
+ } else {
+ ret = MF_HUGETLB_FREED;
+ }
} else {
- ret = -EBUSY;
+ ret = MF_HUGETLB_RETRY;
if (!(flags & MF_NO_RETRY))
goto out;
}
- if (hugetlb_set_page_hwpoison(head, page)) {
- ret = -EHWPOISON;
+ rc = hugetlb_update_hwpoison(head, page);
+ if (rc >= MF_HUGETLB_FOLIO_PRE_POISONED) {
+ ret = rc;
goto out;
}
@@ -1854,6 +1861,12 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags)
* with basic operations like hugepage allocation/free/demotion.
* So some of prechecks for hwpoison (pinning, and testing/setting
* PageHWPoison) should be done in single hugetlb_lock range.
+ * Returns:
+ * 0 - not hugetlb, or recovered
+ * -EBUSY - not recovered
+ * -EOPNOTSUPP - hwpoison_filter'ed
+ * -EHWPOISON - folio or exact page already poisoned
+ * -EFAULT - kill_accessing_process finds current->mm null
*/
static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb)
{
@@ -1865,23 +1878,25 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
*hugetlb = 1;
retry:
res = get_huge_page_for_hwpoison(pfn, flags);
- if (res == 2) { /* fallback to normal page handling */
+ if (res == MF_HUGETLB_NON_HUGEPAGE) { /* fallback to normal page handling */
*hugetlb = 0;
return 0;
- } else if (res == -EHWPOISON) {
+ } else if (res == MF_HUGETLB_FOLIO_PRE_POISONED ||
+ res == MF_HUGETLB_PAGE_PRE_POISONED) {
pr_err("%#lx: already hardware poisoned\n", pfn);
+ res = -EHWPOISON;
if (flags & MF_ACTION_REQUIRED) {
head = compound_head(p);
res = kill_accessing_process(current, page_to_pfn(head), flags);
}
return res;
- } else if (res == -EBUSY) {
+ } else if (res == MF_HUGETLB_RETRY) {
if (!(flags & MF_NO_RETRY)) {
flags |= MF_NO_RETRY;
goto retry;
}
action_result(pfn, MF_MSG_UNKNOWN, MF_IGNORED);
- return res;
+ return -EBUSY;
}
head = compound_head(p);
@@ -1890,7 +1905,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
if (hwpoison_filter(p)) {
hugetlb_clear_page_hwpoison(head);
unlock_page(head);
- if (res == 1)
+ if (res == MF_HUGETLB_IN_USED)
put_page(head);
return -EOPNOTSUPP;
}
@@ -1899,7 +1914,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb
* Handling free hugepage. The possible race with hugepage allocation
* or demotion can be prevented by PageHWPoison flag.
*/
- if (res == 0) {
+ if (res == MF_HUGETLB_FREED) {
unlock_page(head);
if (__page_handle_poison(p) > 0) {
page_ref_inc(p);
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 6.1.y 5/5] mm/memory-failure: fix hugetlb_lock AA deadlock in get_huge_page_for_hwpoison
2026-06-15 19:42 ` [PATCH 6.1.y 1/5] mm/hugetlb: rename isolate_hugetlb() to folio_isolate_hugetlb() Sasha Levin
` (2 preceding siblings ...)
2026-06-15 19:42 ` [PATCH 6.1.y 4/5] mm/memory-failure: fix missing ->mf_stats count in hugetlb poison Sasha Levin
@ 2026-06-15 19:42 ` Sasha Levin
3 siblings, 0 replies; 6+ messages in thread
From: Sasha Levin @ 2026-06-15 19:42 UTC (permalink / raw)
To: stable
Cc: Wupeng Ma, Oscar Salvador (SUSE), Muchun Song, Kefeng Wang,
Miaohe Lin, David Hildenbrand, Liam Howlett, Lorenzo Stoakes,
Michal Hocko, Mike Rapoport, Naoya Horiguchi, Suren Baghdasaryan,
Vlastimil Babka, Andrew Morton, Sasha Levin
From: Wupeng Ma <mawupeng1@huawei.com>
[ Upstream commit 3c2d42b8ee345b17a4ba56b0f6492d1ff4c1178e ]
Two concurrent madvise(MADV_HWPOISON) calls on the same hugetlb page can
trigger a recursive spinlock self-deadlock (AA deadlock) on hugetlb_lock
when racing with a concurrent unmap:
thread#0 thread#1
-------- --------
madvise(folio, MADV_HWPOISON)
-> poisons the folio successfully
madvise(folio, MADV_HWPOISON) unmap(folio)
try_memory_failure_hugetlb
get_huge_page_for_hwpoison
spin_lock_irq(&hugetlb_lock) <- held
__get_huge_page_for_hwpoison
hugetlb_update_hwpoison()
-> MF_HUGETLB_FOLIO_PRE_POISONED
goto out:
folio_put()
refcount: 1 -> 0
free_huge_folio()
spin_lock_irqsave(&hugetlb_lock)
-> AA DEADLOCK!
The out: path in __get_huge_page_for_hwpoison() calls folio_put() to drop
the GUP reference while the hugetlb_lock is still held by the hugetlb.c
wrapper get_huge_page_for_hwpoison(). If concurrent unmap has released
the page table mapping reference, folio_put() drops the folio refcount to
zero, triggering free_huge_folio() which attempts to re-acquire the
non-recursive hugetlb_lock.
Fix this by moving hugetlb_lock acquisition from the hugetlb.c wrapper
into get_huge_page_for_hwpoison(). Place spin_unlock_irq() before the
folio_put() at the out: label so the folio is always released outside the
lock.
[akpm@linux-foundation.org: fix race, rename label per Miaohe]
Link: https://sashiko.dev/#/patchset/20260522010305.4099834-1-mawupeng1@huawei.com
Link: https://lore.kernel.org/f39f405e-4b4b-8f79-70fe-a2b5b62114eb@huawei.com
Link: https://lore.kernel.org/20260522010305.4099834-1-mawupeng1@huawei.com
Fixes: 405ce051236c ("mm/hwpoison: fix race between hugetlb free/demotion and memory_failure_hugetlb()")
Signed-off-by: Wupeng Ma <mawupeng1@huawei.com>
Acked-by: Oscar Salvador (SUSE) <osalvador@kernel.org>
Acked-by: Muchun Song <muchun.song@linux.dev>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Acked-by: Miaohe Lin <linmiaohe@huawei.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Naoya Horiguchi <nao.horiguchi@gmail.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
include/linux/hugetlb.h | 6 ------
include/linux/mm.h | 5 -----
mm/hugetlb.c | 10 ----------
mm/memory-failure.c | 19 ++++++++++---------
4 files changed, 10 insertions(+), 30 deletions(-)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 9a0e8aa442b3e5..6b78a0f457d953 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -184,7 +184,6 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
long freed);
int folio_isolate_hugetlb(struct page *page, struct list_head *list);
int get_hwpoison_huge_page(struct page *page, bool *hugetlb);
-int get_huge_page_for_hwpoison(unsigned long pfn, int flags);
void folio_putback_hugetlb(struct page *page);
void move_hugetlb_state(struct page *oldpage, struct page *newpage, int reason);
void free_huge_page(struct page *page);
@@ -438,11 +437,6 @@ static inline int get_hwpoison_huge_page(struct page *page, bool *hugetlb)
return 0;
}
-static inline int get_huge_page_for_hwpoison(unsigned long pfn, int flags)
-{
- return 0;
-}
-
static inline void folio_putback_hugetlb(struct page *page)
{
}
diff --git a/include/linux/mm.h b/include/linux/mm.h
index cf0cc4a64887c9..ac0638a8c38dba 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3429,15 +3429,10 @@ extern atomic_long_t num_poisoned_pages __read_mostly;
extern int soft_offline_page(unsigned long pfn, int flags);
#ifdef CONFIG_MEMORY_FAILURE
extern void memory_failure_queue(unsigned long pfn, int flags);
-extern int __get_huge_page_for_hwpoison(unsigned long pfn, int flags);
#else
static inline void memory_failure_queue(unsigned long pfn, int flags)
{
}
-static inline int __get_huge_page_for_hwpoison(unsigned long pfn, int flags)
-{
- return 0;
-}
#endif
#ifndef arch_memory_failure
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 20095df62be4ba..ee753b2ff09f82 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -7481,16 +7481,6 @@ int get_hwpoison_huge_page(struct page *page, bool *hugetlb)
return ret;
}
-int get_huge_page_for_hwpoison(unsigned long pfn, int flags)
-{
- int ret;
-
- spin_lock_irq(&hugetlb_lock);
- ret = __get_huge_page_for_hwpoison(pfn, flags);
- spin_unlock_irq(&hugetlb_lock);
- return ret;
-}
-
/**
* folio_putback_hugetlb - unisolate a hugetlb page
* @page: the isolated hugetlb page
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 1d39bdb434e734..776a37ae4eb695 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1812,19 +1812,18 @@ void hugetlb_clear_page_hwpoison(struct page *hpage)
free_raw_hwp_pages(hpage, true);
}
-/*
- * Called from hugetlb code with hugetlb_lock held.
- */
-int __get_huge_page_for_hwpoison(unsigned long pfn, int flags)
+static int get_huge_page_for_hwpoison(unsigned long pfn, int flags)
{
struct page *page = pfn_to_page(pfn);
- struct page *head = compound_head(page);
+ struct page *head;
bool count_increased = false;
int ret, rc;
+ spin_lock_irq(&hugetlb_lock);
+ head = compound_head(page);
if (!PageHeadHuge(head)) {
ret = MF_HUGETLB_NON_HUGEPAGE;
- goto out;
+ goto out_unlock;
} else if (flags & MF_COUNT_INCREASED) {
ret = MF_HUGETLB_IN_USED;
count_increased = true;
@@ -1840,17 +1839,19 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags)
} else {
ret = MF_HUGETLB_RETRY;
if (!(flags & MF_NO_RETRY))
- goto out;
+ goto out_unlock;
}
rc = hugetlb_update_hwpoison(head, page);
if (rc >= MF_HUGETLB_FOLIO_PRE_POISONED) {
ret = rc;
- goto out;
+ goto out_unlock;
}
+ spin_unlock_irq(&hugetlb_lock);
return ret;
-out:
+out_unlock:
+ spin_unlock_irq(&hugetlb_lock);
if (count_increased)
put_page(head);
return ret;
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread