Re: [PATCH v3 0/9] mm: distinguish HW PTE pointers from SW PTE value pointers
From: Muhammad Usama Anjum
Date: Wed Nov 18 2026 - 16:42:39 EST
On 16/11/2026 5:41 pm, Catalin Marinas wrote:
> Hi Usama,
>
> (trimmed the Cc list, some lists reject it as too many recipients)
>
> On Tue, Sep 22, 2026 at 06:12:28PM +0100, Muhammad Usama Anjum wrote:
>> pte_t currently describes both a software PTE value and an element stored
>> in a PTE table. Consequently, pte_t * can point either to a software PTE
>> value, often a stack copy, or to a PTE-table slot. The compiler cannot
>> distinguish these cases. A value pointer can therefore be passed to an
>> interface that expects table storage, while table storage can be read by
>> direct dereference instead of the architecture accessor.
>>
>> This series begins a staged conversion at the PTE level. It introduces
>> hw_pte_t as the element type for PTE-table storage and converts generic
>> MM to use hw_pte_t *. Software PTE values remain pte_t. Interfaces that
>> intentionally return a value through pte_t *, such as install_pte,
>> remain value interfaces; the relevant parameters are named ptentp to
>> make that distinction explicit.
>
> [...]
>
>> PMD, PUD, P4D and PGD storage are deliberately out of scope. They can be
>> converted in later series after the PTE boundary is agreed, avoiding the
>> PMD-specific cases that made an all-level conversion difficult to
>> review.
>
> I looked at this (and the arm64 counterpart) and I'm not fully convinced
> it's worth the effort (but I won't oppose it if the mm folk decide to go
> this route).
I've found direct interest from s390 as well as arm64 devs other than us.
We all want a sustainable solution.
>
> First, I'd like to see all such on-stack p*d pointers addressed as a
> prerequisite (e.g. fix pmd_populate() in __split_huge_zero_page_pmd()).
> If for some reason we deem pmd not fixable, I don't like half (or
> quarter) baked solutions just addressing the pte.
Only pmd pointers conversions may require careful review and some discussion.
Other remaining p*d would be straight forward again. I think if I convert
everything, we'll have 30-35 patches for generic side only. It would a little
time consuming to rebase that again and again.
I think, a simpler plan can be to post the pmd pointer conversion series
as well in the open to get better acceptance of this overall effort.
>
> Second, we could add a run-time page table check, at least for pmd/pte.
> Something like below, gated by CONFIG_PAGE_TABLE_CHECK or
> CONFIG_DEBUG_VM (untested and not entirely sure about using
> PageTable()):
>
> static inline void pgtable_ptr_check(struct mm_struct *mm, const void *p)
> {
> if (object_is_on_stack(p)) {
> WARN_ON_ONCE(1);
> return;
> }
> if (mm != &init_mm && virt_addr_valid(p))
> WARN_ON_ONCE(!PageTable(virt_to_page(p)));
> }
s390 already has CONFIG_STRICT_MM_TYPECHECKS, but that only provides type
checking for page-table values. It cannot distinguish a pointer to
page-table storage from a pointer to a copied value. Consequently, direct
dereferences still appear in generic code and can bypass s390’s
architecture-specific handling. They have been trying to fix [1] differently.
RISC-V has independently encountered the same problem. Some RISC-V
platforms must transform page-table entries whenever they are read from
or written to hardware page tables, so generic code must consistently
use the architecture accessors. They were trying to fix it [2].
These requirements are therefore not specific to arm64. The aim of this
work is to provide architecture interfaces for manipulating page-table
storage correctly and to make accidental bypasses compile-time errors.
Architectures that do not require special handling can retain the generic
representation and trivial accessor implementations.
>
> You already have some coccinelle patches to make the conversion. Could
> we turn them into a coccicheck to detect new uses? With LLM reviews like
> Sashiko, we can probably catch new uses violating the requirement (we
> need to document it).
Coccinelle can identify common syntax, but cannot reliably distinguish the
meaning of two pointers when both are pte_t *.
>
> LLMs and coccicheck won't catch all abuses nor does this series prevent
> one from declaring hw_pte_t on the stack.
By using Coccinelle and LLMs we can still get regressions which arch-es
have been doing over the year.
hw_pte_t * makes accidental violations compilation errors in every build.
Deliberately declaring hw_pte_t on the stack remains possible, but is explicit
and reviewable. (RFC of this series has info on why we aren't using opaque
objects.)
>
> Once the above are in place, I'd look again at these patches and see
> whether they improve code clarity and are worth the churn.
>
> Maybe an argument in favour of these patchsets is future dynamic support
> for FEAT_D128, we'd need to separate the software representation of a
> pte from the hardware one but we've done this before (arm32 non-LPAE has
> different representations).
Yes, that's also the big motivation of this work. We don't want to depend on
the config options to turn on/off features. Arch should be able to turn on/off
code based on the cpu features.
>
> That said, patch 2 (naming the software PTE value pointers ptentp) could
> go in independently. Same for David's suggestion on patch 5 to replace
> the huge_ptep_clear_flush() stub with a plain declaration.
>
> Thanks.
>
This is one time churn for multiple kinds of benefits.
[1] https://lore.kernel.org/linux-s390/e50fb51d-72ac-4ace-b532-5cf32ecd80f1@xxxxxxxxxx
[2] https://lore.kernel.org/all/20251113014656.2605447-7-samuel.holland@xxxxxxxxxx/
--
Thanks,
Usama