Skip to content

Commit

Permalink
mm/memory-failure: pass the folio and the page to collect_procs()
Browse files Browse the repository at this point in the history
[ Upstream commit 376907f ]

Patch series "Three memory-failure fixes".

I've been looking at the memory-failure code and I believe I have found
three bugs that need fixing -- one going all the way back to 2010!  I'll
have more patches later to use folios more extensively but didn't want
these bugfixes to get caught up in that.

This patch (of 3):

Both collect_procs_anon() and collect_procs_file() iterate over the VMA
interval trees looking for a single pgoff, so it is wrong to look for the
pgoff of the head page as is currently done.  However, it is also wrong to
look at page->mapping of the precise page as this is invalid for tail
pages.  Clear up the confusion by passing both the folio and the precise
page to collect_procs().

Link: https://lkml.kernel.org/r/20231218135837.3310403-1-willy@infradead.org
Link: https://lkml.kernel.org/r/20231218135837.3310403-2-willy@infradead.org
Fixes: 415c64c ("mm/memory-failure: split thp earlier in memory error handling")
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Matthew Wilcox (Oracle) authored and gregkh committed Jan 10, 2024
1 parent 393155f commit bf07fda
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions mm/memory-failure.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,9 @@ struct task_struct *task_early_kill(struct task_struct *tsk, int force_early)
/*
* Collect processes when the error hit an anonymous page.
*/
static void collect_procs_anon(struct page *page, struct list_head *to_kill,
int force_early)
static void collect_procs_anon(struct folio *folio, struct page *page,
struct list_head *to_kill, int force_early)
{
struct folio *folio = page_folio(page);
struct vm_area_struct *vma;
struct task_struct *tsk;
struct anon_vma *av;
Expand Down Expand Up @@ -633,12 +632,12 @@ static void collect_procs_anon(struct page *page, struct list_head *to_kill,
/*
* Collect processes when the error hit a file mapped page.
*/
static void collect_procs_file(struct page *page, struct list_head *to_kill,
int force_early)
static void collect_procs_file(struct folio *folio, struct page *page,
struct list_head *to_kill, int force_early)
{
struct vm_area_struct *vma;
struct task_struct *tsk;
struct address_space *mapping = page->mapping;
struct address_space *mapping = folio->mapping;
pgoff_t pgoff;

i_mmap_lock_read(mapping);
Expand Down Expand Up @@ -704,17 +703,17 @@ static void collect_procs_fsdax(struct page *page,
/*
* Collect the processes who have the corrupted page mapped to kill.
*/
static void collect_procs(struct page *page, struct list_head *tokill,
int force_early)
static void collect_procs(struct folio *folio, struct page *page,
struct list_head *tokill, int force_early)
{
if (!page->mapping)
if (!folio->mapping)
return;
if (unlikely(PageKsm(page)))
collect_procs_ksm(page, tokill, force_early);
else if (PageAnon(page))
collect_procs_anon(page, tokill, force_early);
collect_procs_anon(folio, page, tokill, force_early);
else
collect_procs_file(page, tokill, force_early);
collect_procs_file(folio, page, tokill, force_early);
}

struct hwpoison_walk {
Expand Down Expand Up @@ -1602,7 +1601,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn,
* mapped in dirty form. This has to be done before try_to_unmap,
* because ttu takes the rmap data structures down.
*/
collect_procs(hpage, &tokill, flags & MF_ACTION_REQUIRED);
collect_procs(folio, p, &tokill, flags & MF_ACTION_REQUIRED);

if (PageHuge(hpage) && !PageAnon(hpage)) {
/*
Expand Down Expand Up @@ -1772,7 +1771,7 @@ static int mf_generic_kill_procs(unsigned long long pfn, int flags,
* SIGBUS (i.e. MF_MUST_KILL)
*/
flags |= MF_ACTION_REQUIRED | MF_MUST_KILL;
collect_procs(&folio->page, &to_kill, true);
collect_procs(folio, &folio->page, &to_kill, true);

unmap_and_kill(&to_kill, pfn, folio->mapping, folio->index, flags);
unlock:
Expand Down

0 comments on commit bf07fda

Please sign in to comment.