Re: [PATCH v4 2/7] mm: memory_failure: Allow truncate_error_folio to return MF_DELAYED

From: Ackerley Tng

Date: Wed Jun 17 2026 - 09:16:21 EST


Lisa Wang <wyihan@xxxxxxxxxx> writes:

> The .error_remove_folio a_ops is used by different filesystems to handle
> folio truncation upon discovery of a memory failure in the memory
> associated with the given folio.
>
> Currently, MF_DELAYED is treated as an error, causing "Failed to punch
> page" to be written to the console. MF_DELAYED is then relayed to the
> caller of truncate_error_folio() as MF_FAILED. This further causes
> memory_failure() to return -EBUSY, which then always causes a SIGBUS.
>
> This is also implies that regardless of whether the thread's memory
> corruption kill policy is PR_MCE_KILL_EARLY or PR_MCE_KILL_LATE, a
> memory failure with MF_DELAYED will always cause a SIGBUS.
>
> Update truncate_error_folio() to return MF_DELAYED to the caller if the
> .error_remove_folio() callback reports MF_DELAYED.
>
> Signed-off-by: Lisa Wang <wyihan@xxxxxxxxxx>
> ---
> mm/memory-failure.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> index 2e53b3024391..3aff0c981fcd 100644
> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c
> @@ -941,10 +941,12 @@ static int truncate_error_folio(struct folio *folio, unsigned long pfn,
> if (mapping->a_ops->error_remove_folio) {
> int err = mapping->a_ops->error_remove_folio(mapping, folio);
>
> - if (err != 0)
> + if (err == MF_DELAYED)
> + ret = err;

Perhaps better to set ret = MF_DELAYED directly so that it saves the
reader one step of connecting err == MF_DELAYED with ret = err, but not
a big issue.

Reviewed-by: Ackerley Tng <ackerleytng@xxxxxxxxxx>

> + else if (err != 0)
> pr_info("%#lx: Failed to punch page: %d\n", pfn, err);
> else if (!filemap_release_folio(folio, GFP_NOIO))
> - pr_info("%#lx: failed to release buffers\n", pfn);
> + pr_info("%#lx: Failed to release buffers\n", pfn);
> else
> ret = MF_RECOVERED;
> } else {
>
> --
> 2.54.0.1013.g208068f2d8-goog