Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Muhammad Usama Anjum <usama.anjum@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	Ryan Roberts <ryan.roberts@arm.com>,
	Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	Zi Yan <ziy@nvidia.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Samuel Holland <samuel.holland@sifive.com>,
	Peter Xu <peterx@redhat.com>,
	linux-mm@kvack.org, linux-arch@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 0/9] mm: distinguish HW PTE pointers from SW PTE value pointers
Date: Fri, 20 Nov 2026 16:48:44 +0000	[thread overview]
Message-ID: <awB57BlYzicAJzqr@arm.com> (raw)
In-Reply-To: <959a843d-f579-4aa7-8299-c6e9c5d03812@arm.com>

On Wed, Nov 18, 2026 at 09:41:41PM +0000, Muhammad Usama Anjum wrote:
> On 16/11/2026 5:41 pm, Catalin Marinas wrote:
> > On Tue, Sep 22, 2026 at 06:12:28PM +0100, Muhammad Usama Anjum wrote:
> >> 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.

[...]

> > 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.

I didn't ask for the full pmdp conversion but only to see if we can
remove the on-stack uses first. At a quick grep, there are only a few:
pmd_populate() on a local pmd_t in __split_huge_zero_page_pmd(),
__split_huge_pmd_locked() and vmemmap_split_pmd().

> > 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].

I thought these were about direct dereference of the pointer to pte. We
could use some sparse annotations like __ptent (already proposed). The
run-time check is about valid pointer accesses but when the PTE is on
stack.

> > 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 *.

No, that's what we'd use a runtime check for. The incomplete types probably
help, though you can't fully prevent explicit casting.

> > 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.)

I'm not sure what the conclusion was on opaque hw_pte_t. IIRC Lorenzo
also proposed a non-opaque type that Ryan agreed to some time ago. IIUC,
if we take that route, we'd need to go again through all type changes in
this series. On arm64, some of the functions proposed like hw_pte_val(),
__pte_from_hw() would need converting again.

IOW, I'm trying to understand the road to get there, like ptep_advance()
instead of ptep++ and so on. Once we are clear, maybe without a full
patchset, we can go ahead in steps but at the moment it's not clear to
me you won't post another conversion like this soon after.

Anyway, that's not my code, so if the mm folk are happy, please go ahead
with the generic series. I may wait enabling it on arm64 until the
opaque pte type discussion is settled.

> > 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.

It's a lot more work than the pte size here. PTRS_PER_* have different
values, ptep_advance() would be more dynamic. It's doable but it's a lot
more involved and I think the types are the least of our problems. I'm
also waiting to see how many CPUs implement D128 before committing to
supporting it upstream (it doesn't buy us much anyway).

Thanks.

-- 
Catalin


      reply	other threads:[~2026-11-20 16:48 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 17:12 [PATCH v3 0/9] mm: distinguish HW PTE pointers from SW PTE value pointers Muhammad Usama Anjum
2026-09-22 17:12 ` [PATCH v3 1/9] mm: introduce hw_pte_t for PTE table storage Muhammad Usama Anjum
2026-09-30  4:13   ` Anshuman Khandual
2026-09-30 15:27   ` Zi Yan
2026-09-22 17:12 ` [PATCH v3 2/9] mm: rename pointers to software PTE values as ptentp Muhammad Usama Anjum
2026-09-30  4:20   ` Anshuman Khandual
2026-09-22 17:12 ` [PATCH v3 3/9] mm: use hw_pte_t for generic PTE table storage Muhammad Usama Anjum
2026-09-30  4:35   ` Anshuman Khandual
2026-09-30 17:40     ` Muhammad Usama Anjum
2026-10-01 11:25       ` David Hildenbrand (Arm)
2026-10-01 11:26   ` David Hildenbrand (Arm)
2026-09-22 17:12 ` [PATCH v3 4/9] mm: convert PTE table entries in ptep_get() Muhammad Usama Anjum
2026-09-30  5:10   ` Anshuman Khandual
2026-09-30 17:46     ` Muhammad Usama Anjum
2026-10-01 11:27   ` David Hildenbrand (Arm)
2026-09-22 17:12 ` [PATCH v3 5/9] mm: convert PTE table entry to pte Muhammad Usama Anjum
2026-10-01 11:17   ` David Hildenbrand (Arm)
2026-10-02 14:57     ` Muhammad Usama Anjum
2026-09-22 17:12 ` [PATCH v3 6/9] mm: add hw_pte_val for HW PTE storage Muhammad Usama Anjum
2026-10-01 11:19   ` David Hildenbrand (Arm)
2026-10-02 14:59     ` Muhammad Usama Anjum
2026-09-22 17:12 ` [PATCH v3 7/9] mm/kasan: use hw_pte_t for the early shadow PTE table Muhammad Usama Anjum
2026-10-01 11:20   ` David Hildenbrand (Arm)
2026-09-22 17:12 ` [PATCH v3 8/9] drm/i915: use hw_pte_t for PTE range callbacks Muhammad Usama Anjum
2026-10-01 11:21   ` David Hildenbrand (Arm)
2026-09-22 17:12 ` [PATCH v3 9/9] xen: " Muhammad Usama Anjum
2026-10-01 11:22   ` David Hildenbrand (Arm)
2026-09-28  7:09 ` [PATCH v3 0/9] mm: distinguish HW PTE pointers from SW PTE value pointers Alexander Gordeev
2026-11-16 17:41 ` Catalin Marinas
2026-11-16 18:18   ` David Hildenbrand (Arm)
2026-11-18 21:48     ` Muhammad Usama Anjum
2026-11-19 17:00       ` David Hildenbrand (Arm)
2026-11-18 21:41   ` Muhammad Usama Anjum
2026-11-20 16:48     ` Catalin Marinas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awB57BlYzicAJzqr@arm.com \
    --to=catalin.marinas@arm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=david@kernel.org \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=peterx@redhat.com \
    --cc=ryan.roberts@arm.com \
    --cc=samuel.holland@sifive.com \
    --cc=usama.anjum@arm.com \
    --cc=will@kernel.org \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox