Re: [PATCH v3 1/4] s390/mm: Fix handling of _PAGE_UNUSED pte bit

From: Heiko Carstens

Date: Fri Jun 19 2026 - 04:08:43 EST


On Tue, Jun 16, 2026 at 06:51:07PM +0200, Claudio Imbrenda wrote:
> The _PAGE_UNUSED softbit should not really be lying around. Its sole
> purpose is to signal to try_to_unmap_one() and try_to_migrate_one()
> that the page can be discarded instead of being moved / swapped.
>
> KVM has no way to know why a page is being unmapped, so it sets the bit
> on userspace ptes corresponding to unused guest pages every time they
> get unmapped. KVM has no reasonable way to clear the bit once the page
> is in use again.
>
> Without appropriate cleanup, the _PAGE_UNUSED bit will linger around
> and cause guest corruption when a used page is instead thrown out.
>
> While set_ptes() checks and clears the bit, other paths that set new
> ptes did not. This led to used pages being thrown out as if they were
> unused, causing guest corruption.
>
> This patch fixes the issue by clearing the _PAGE_UNUSED bit in
> set_pte(), so whenever a present pte is getting set. The check in
> set_ptes() is then redundant and can be removed.
>
> Also fix gmap_helper_try_set_pte_unused() to only set the bit if the
> pte is present; the _PAGE_UNUSED bit is only defined for present ptes
> and thus should not be set for non-present ptes.
>
> Signed-off-by: Claudio Imbrenda <imbrenda@xxxxxxxxxxxxx>
> Fixes: c98175b7917f ("KVM: s390: Add gmap_helper_set_unused()")
> ---
> arch/s390/include/asm/pgtable.h | 4 ++--
> arch/s390/mm/gmap_helpers.c | 3 ++-
> 2 files changed, 4 insertions(+), 3 deletions(-)

Acked-by: Heiko Carstens <hca@xxxxxxxxxxxxx>