Re: [PATCH 3/3] mm: fail the fault on a malformed swap entry instead of retrying it
From: David Hildenbrand (Arm)
Date: Tue Aug 11 2026 - 11:39:05 EST
On 8/10/26 18:26, Breno Leitao wrote:
> do_swap_page() returns 0 when get_swap_device() fails, which the fault
> handler reads as "handled". For an entry that can never become valid
> the retry takes the same fault again, so the thread spins until it is
> killed.
>
> Return VM_FAULT_SIGBUS for a malformed entry, as the sibling arm
> already does for an unrecognised non-swap entry. A NULL return still
> means swapoff, which is still worth retrying.
>
> Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
> ---
> mm/memory.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index 4238778b66c42..2842cd976f1d3 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -4957,6 +4957,9 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
> /* Prevent swapoff from happening to us. */
> si = get_swap_device(entry);
> if (IS_ERR_OR_NULL(si)) {
> + /* A malformed entry never becomes valid, so don't retry it. */
> + if (IS_ERR(si))
> + ret = VM_FAULT_SIGBUS;
> si = NULL;
> goto out;
Better update the comment above get_swap_device() to include "bad swap entries"
as well. Best do that as part of patch #2.
I didn't look too closely, but conceptually LGTM
--
Cheers,
David