Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vincent Donnefort" <vdonnefort@google.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v9 06/10] arm64: Implement can_set_direct_map_range()
Date: Wed, 02 Sep 2026 11:06:46 +0000	[thread overview]
Message-ID: <20260902110647.258B31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902104712.2399797-7-vdonnefort@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Lockless page table walk uses standard offset macros causing naked dereferences and unsafe multiple reads on folded levels.
- [High] The lockless walk loop fails to advance correctly when page-table levels are folded, silently skipping range checks.
--

commit de12d2156510af8d2a1f0b0adad3f96ba3b75cda
Author: Vincent Donnefort <vdonnefort@google.com>
Subject: arm64: Implement can_set_direct_map_range()

This commit adds an implementation for can_set_direct_map_range() on ARM64.
For systems where can_set_direct_map() is false, it verifies if a subregion
of the direct map is mapped at the last level by performing a lockless page
table walk.

> diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
> index 58898ae53f5d1..c59ef17eb0d06 100644
> --- a/arch/arm64/mm/pageattr.c
> +++ b/arch/arm64/mm/pageattr.c
[ ... ]
> +bool can_set_direct_map_range(struct page *page, unsigned long nr_pages)
> +{
[ ... ]
> +	/*
> +	 * If !can_set_direct_map() then no one can split blocks and it is safe
> +	 * to walk the page-table lockless.
> +	 */
> +	while (addr < end) {
> +		pud_t *pudp, pud;
> +		pmd_t *pmdp, pmd;
> +		pgd_t *pgdp;
> +		p4d_t *p4dp;
> +
> +		pgdp = pgd_offset_k(addr);
> +		if (pgd_none(READ_ONCE(*pgdp)))
> +			return false;
> +
> +		p4dp = p4d_offset(pgdp, addr);
[Severity: High]
Does this standard offset macro perform multiple reads of the same entry when
page-table levels are folded?

When lockless walk logic assumes all levels are live without checking for
folded levels, blindly applying multi-level READ_ONCE() causes the same
memory location to be read multiple times, risking stale or torn reads.

> +		if (p4d_none(READ_ONCE(*p4dp)))
> +			return false;
> +
> +		pudp = pud_offset(p4dp, addr);
> +		pud = READ_ONCE(*pudp);
> +		if (pud_none(pud) || pud_leaf(pud))
> +			return false;
> +
> +		pmdp = pmd_offset(pudp, addr);
[Severity: High]
Does this generic offset macro dereference the shared page table pointer
without using READ_ONCE()?

The generic pmd_offset() dereferences *pudp internally. This introduces a
naked dereference and data race during a lockless walk.

> +		pmd = READ_ONCE(*pmdp);
> +		if (pmd_none(pmd) || pmd_leaf(pmd))
> +			return false;
> +
> +		addr = pmd_addr_end(addr, end);
[Severity: High]
Can this fail to advance the loop correctly when page-table levels are
folded?

On a system with 2-level paging (like 64KB pages with 42-bit VA) where PMD
is folded, pmd_addr_end() unconditionally evaluates to the provided end
address.

If this occurs, the loop would only check the first entry and immediately skip
the remainder of the range, falsely returning true. This could allow modifying
direct map regions containing block mappings, subsequently triggering a
WARN_ON_ONCE and -EINVAL failure in pageattr_pmd_entry() because the
modification size won't align with the block size.

> +	}
> +
> +	return true;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260902104712.2399797-1-vdonnefort@google.com?part=6

  reply	other threads:[~2026-09-02 11:06 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 10:47 [PATCH v9 00/10] arm64: Unmap FF-A lent memory from direct map Vincent Donnefort
2026-09-02 10:47 ` [PATCH v9 01/10] memblock: Introduce MEMBLOCK_LLMAP Vincent Donnefort
2026-09-02 10:47 ` [PATCH v9 02/10] of: reserved_mem: Introduce "ll-map" property Vincent Donnefort
2026-09-02 11:02   ` sashiko-bot
2026-09-02 17:24   ` Rob Herring
2026-09-03 10:03     ` Vincent Donnefort
2026-09-02 10:47 ` [PATCH v9 03/10] set_memory.h: Introduce can_set_direct_map_range() Vincent Donnefort
2026-09-02 10:47 ` [PATCH v9 04/10] set_memory.h: Introduce __set_direct_map*() Vincent Donnefort
2026-09-02 10:47 ` [PATCH v9 05/10] arm64: can_set_direct_map() if BBML3 Vincent Donnefort
2026-09-02 11:09   ` sashiko-bot
2026-09-02 10:47 ` [PATCH v9 06/10] arm64: Implement can_set_direct_map_range() Vincent Donnefort
2026-09-02 11:06   ` sashiko-bot [this message]
2026-09-02 10:47 ` [PATCH v9 07/10] arm64: Implement __set_direct_map*() Vincent Donnefort
2026-09-02 10:47 ` [PATCH v9 08/10] arm64: Add support for MEMBLOCK_LLMAP Vincent Donnefort
2026-09-02 10:47 ` [PATCH v9 09/10] firmware: arm_ffa: Introduce ffa-lend-pool Vincent Donnefort
2026-09-02 11:06   ` sashiko-bot
2026-09-02 17:38   ` Rob Herring
2026-09-03 10:10     ` Vincent Donnefort
2026-09-02 10:47 ` [PATCH v9 10/10] optee: Add support for arm,ffa-lend-pool Vincent Donnefort
2026-09-02 11:09   ` sashiko-bot
2026-09-02 13:27 ` [PATCH v9 00/10] arm64: Unmap FF-A lent memory from direct map Vincent Donnefort

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=20260902110647.258B31F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vdonnefort@google.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