Re: [PATCH 3/3] mm: fail the fault on a malformed swap entry instead of retrying it

From: Pedro Falcato

Date: Wed Aug 12 2026 - 07:22:28 EST


On Mon, Aug 10, 2026 at 09:26:51AM -0700, 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.

What kind of SIGBUS do you get from this? as in the si_code. Out of all
the options

#define BUS_ADRALN 1 /* invalid address alignment */
#define BUS_ADRERR 2 /* non-existent physical address */
#define BUS_OBJERR 3 /* object specific hardware error */
/* hardware memory error consumed on a machine check: action required */
#define BUS_MCEERR_AR 4
/* hardware memory error detected in process but not consumed: action optional*/
#define BUS_MCEERR_AO 5

I would say this would fit none of them. The default (AFAICT) would be
BUS_ADRERR, and I think that one is quite overloaded with meaning (namely,
with regards to memory-mapped IO past EOF, or EIO on file IO). I wouldn't
love to also use it for this, IMO.

>
> 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;
> }
>
> --
> 2.53.0-Meta
>

--
Pedro