Re: [PATCH v2] x86/mm: Remove the zapped-entry checks
From: Zi Yan
Date: Mon Nov 09 2026 - 22:22:10 EST
On Thu Nov 5, 2026 at 7:03 AM EST, Kiryl Shutsemau wrote:
> From: "Kiryl Shutsemau (Meta)" <kas@xxxxxxxxxx>
>
> Zapping a range calls arch_check_zapped_pte() for every batch of PTEs,
> which is every page for small folios, and arch_check_zapped_pmd() or
> arch_check_zapped_pud() for every huge leaf. Only x86 implements them, as
> out-of-line functions that warn about a shadow stack entry (Write=0,
> Dirty=1) in a VMA without VM_SHADOW_STACK.
>
> The warning is a VM_WARN_ON_ONCE(), so without CONFIG_DEBUG_VM the
> functions are empty, but the calls remain. With the SRSO "Safe RET"
> mitigation the return of every such call mispredicts.
>
> The x86 helpers already keep such entries out of other VMAs.
> pte_wrprotect(), pte_mkdirty(), pte_modify() and their PMD versions go
> through SavedDirty, and only pte_mkwrite() and pmd_mkwrite() on a
> VM_SHADOW_STACK VMA create the combination.
>
> Remove the checks, their callers and pud_shstk(), which has no other
> user.
>
> In a KVM guest on Zen 4 with Safe RET, zapping 4K pages takes one branch
> miss per page fewer. MADV_DONTNEED of 1 GiB gets 6% faster on anonymous
> memory and 8% on shmem, munmap() 5%. THP is unchanged. Without Safe RET
> the difference is within noise.
Nice.
>
> Suggested-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
> Signed-off-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
> ---
> v2:
> - Remove the checks instead of building them only with CONFIG_DEBUG_VM
> (Dave Hansen).
> - Drop the Fixes: tag (Rick Edgecombe).
> - Note that without Safe RET the difference is within noise (Rick
> Edgecombe).
> - Drop Jose's Reviewed-by: the patch is new.
>
> v1: https://lore.kernel.org/all/20261102144001.342837-1-kas@xxxxxxxxxx/
>
Acked-by: Zi Yan <ziy@xxxxxxxxxx>
--
Best Regards,
Yan, Zi