Skip to content

Commit 37da28d

Browse files
Kefeng Wangopsiff
authored andcommitted
mm: memory-failure: add unmap_poisoned_folio()
Add unmap_poisoned_folio() helper which will be reused by do_migrate_range() from memory hotplug soon. [[email protected]: whitespace tweak, per Miaohe Lin] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Kefeng Wang <[email protected]> Acked-by: David Hildenbrand <[email protected]> Acked-by: Miaohe Lin <[email protected]> Cc: Dan Carpenter <[email protected]> Cc: Jonathan Cameron <[email protected]> Cc: Naoya Horiguchi <[email protected]> Cc: Oscar Salvador <[email protected]> Signed-off-by: Andrew Morton <[email protected]> (cherry picked from commit 16038c4)
1 parent 323b285 commit 37da28d

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

mm/internal.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,8 @@ static inline int find_next_best_node(int node, nodemask_t *used_node_mask)
904904
/*
905905
* mm/memory-failure.c
906906
*/
907+
#ifdef CONFIG_MEMORY_FAILURE
908+
void unmap_poisoned_folio(struct folio *folio, enum ttu_flags ttu);
907909
void shake_folio(struct folio *folio);
908910
extern int hwpoison_filter(struct page *p);
909911

@@ -914,6 +916,12 @@ extern u64 hwpoison_filter_flags_value;
914916
extern u64 hwpoison_filter_memcg;
915917
extern u32 hwpoison_filter_enable;
916918

919+
#else
920+
static inline void unmap_poisoned_folio(struct folio *folio, enum ttu_flags ttu)
921+
{
922+
}
923+
#endif
924+
917925
extern unsigned long __must_check vm_mmap_pgoff(struct file *, unsigned long,
918926
unsigned long, unsigned long,
919927
unsigned long, unsigned long);

mm/memory-failure.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,32 @@ static int get_hwpoison_page(struct page *p, unsigned long flags)
15721572
return ret;
15731573
}
15741574

1575+
void unmap_poisoned_folio(struct folio *folio, enum ttu_flags ttu)
1576+
{
1577+
if (folio_test_hugetlb(folio) && !folio_test_anon(folio)) {
1578+
struct address_space *mapping;
1579+
1580+
/*
1581+
* For hugetlb folios in shared mappings, try_to_unmap
1582+
* could potentially call huge_pmd_unshare. Because of
1583+
* this, take semaphore in write mode here and set
1584+
* TTU_RMAP_LOCKED to indicate we have taken the lock
1585+
* at this higher level.
1586+
*/
1587+
mapping = hugetlb_folio_mapping_lock_write(folio);
1588+
if (!mapping) {
1589+
pr_info("%#lx: could not lock mapping for mapped hugetlb folio\n",
1590+
folio_pfn(folio));
1591+
return;
1592+
}
1593+
1594+
try_to_unmap(folio, ttu|TTU_RMAP_LOCKED);
1595+
i_mmap_unlock_write(mapping);
1596+
} else {
1597+
try_to_unmap(folio, ttu);
1598+
}
1599+
}
1600+
15751601
/*
15761602
* Do all that is necessary to remove user space mappings. Unmap
15771603
* the pages and send SIGBUS to the processes if the data was dirty.
@@ -1633,23 +1659,7 @@ static bool hwpoison_user_mappings(struct folio *folio, struct page *p,
16331659
*/
16341660
collect_procs(folio, p, &tokill, flags & MF_ACTION_REQUIRED);
16351661

1636-
if (folio_test_hugetlb(folio) && !folio_test_anon(folio)) {
1637-
/*
1638-
* For hugetlb pages in shared mappings, try_to_unmap
1639-
* could potentially call huge_pmd_unshare. Because of
1640-
* this, take semaphore in write mode here and set
1641-
* TTU_RMAP_LOCKED to indicate we have taken the lock
1642-
* at this higher level.
1643-
*/
1644-
mapping = hugetlb_folio_mapping_lock_write(folio);
1645-
if (mapping) {
1646-
try_to_unmap(folio, ttu|TTU_RMAP_LOCKED);
1647-
i_mmap_unlock_write(mapping);
1648-
} else
1649-
pr_info("%#lx: could not lock mapping for mapped huge page\n", pfn);
1650-
} else {
1651-
try_to_unmap(folio, ttu);
1652-
}
1662+
unmap_poisoned_folio(folio, ttu);
16531663

16541664
unmap_success = !page_mapped(p);
16551665
if (!unmap_success)

0 commit comments

Comments
 (0)