Re: [PATCH 15/32] mm/huge_memory: don't map huge PFN entries if the arch restricts PFNs
From: Jose A. Perez de Azpillaga
Date: Sun Nov 29 2026 - 15:41:27 EST
On 11/29/26 11:06 AM, David Hildenbrand (Arm) wrote:
> change_huge_pmd() and change_huge_pud() temporarily invalidate huge
> entries, for example during mprotect(). The invalidated entry is not
> present, but still contains the PFN.
>
> On x86 with L1TF, we invert the PFN of a not-present entry, which for a
> PFN at or above l1tf_pfn_limit() points into the lower half of the
> physical address space, where RAM might be. That's why
> pfn_modify_allowed() forbids such entries for unprivileged users. But
> we never check it when mapping huge PFN entries.
>
> This was not a problem as long as only DAX used huge PFN mappings,
> where all PFNs have a memory map. But vfio-pci now maps BARs, which can
> be at or above the limit, with huge entries.
>
> Consequently, an unprivileged user with access to such a BAR can make us
> temporarily create not-present entries that point at RAM, which is what
> the L1TF mitigation is supposed to prevent.
>
> Let's fix it by not mapping huge PFN entries at all in
> vmf_insert_pfn_pmd() and vmf_insert_pfn_pud() if the architecture
> restricts PFN modifications, and fall back to PTEs instead. We clear
> PTEs instead of invalidating them when modifying them, and mprotect()
> already checks for PROT_NONE PTEs.
>
> This only affects old CPUs that suffer from L1TF; not worth optimizing
> for.
>
> This has low urgency, as it requires a CPU affected by L1TF and access
> to a vfio-pci device.
>
> Fixes: f9e54c3a2f5b ("vfio/pci: implement huge_fault support")
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Chris Mason <mason@xxxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> ---
> mm/huge_memory.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 0b4834f843c73..38b16333d3987 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -1732,6 +1732,13 @@ vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, unsigned long pfn,
> if (unlikely(is_huge_zero_pfn(pfn)))
> return VM_FAULT_SIGBUS;
>
> + /*
> + * Disallow huge mappings if we cannot reliably temporarily invalidate
> + * them later.
> + */
> + if (arch_has_pfn_modify_check())
> + return VM_FAULT_FALLBACK;
if I'm not wrong, that only checks the CPU, not the PFN, so
drm_gem_shmem RAM pages lose the PMD mappings too. is that okay?
--
cheers,
jose a. p-a