Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lianghong Liu <liulhong617@163.com>
To: linux-arm-kernel@lists.infradead.org
Cc: will@kernel.org, ardb@kernel.org, Lianghong Liu <liulhong617@163.com>
Subject: Re: [PATCH] arm64: mm: fix accidental linear mapping of no-map reserved memory
Date: Mon, 27 Jul 2026 09:55:58 +0800	[thread overview]
Message-ID: <20260727015527.1@liulhong617.163.com> (raw)
In-Reply-To: <aljkLPTfyAbPaT98@willie-the-truck>

Hi Will,

Thanks for the review. Quick answers to the two open questions.

## What I'm seeing on my system

64K pages (PAGE_SHIFT=16). A no-map reserved region at 0xA2000000 with
size 0x8000 (32 KiB, sub-page). The linear map should skip that hole and
start at 0xA2008000; instead it starts at 0xA2000000 — the whole no-map
region is mapped with PAGE_KERNEL. Debug print in
__create_pgd_mapping_locked():

  create_pgd_mapping: phys 0xa2008000 ...
    after PAGE_MASK align: phys 0xa2000000 - 0xab000000   <- start rounded DOWN into no-map

Cause: for_each_mem_range skips MEMBLOCK_NOMAP regions via
should_skip_region(), but memblock_mark_nomap() splits at byte
boundaries in memblock_isolate_range() (rgn->base = base), so the
*adjacent* region is returned with a sub-page-aligned start/end. That
value then hits
  phys &= PAGE_MASK;
in __create_pgd_mapping_locked(), which rounds the start DOWN and pulls
the mapping back into the no-map page.

So this is a real isolation break, not cosmetic: no-map memory the
firmware asked to leave untouched ends up read/writable in the linear
region.

## On "we might fail to map legitimately mappable pages"

The inward rounding can't lose any page the allocator owns. The buddy
release path uses the exact same inward PFN rounding in
__free_memory_core():
  start_pfn = PFN_UP(start);
  end_pfn   = min(PFN_DOWN(end), max_low_pfn);
  if (start_pfn >= end_pfn) return 0;

So the sub-page sliver at a no-map boundary is never handed to the
allocator and has no struct page backing it — the linear map currently
over-maps bytes the allocator already doesn't manage. The patch just
aligns the linear map to the allocator's own notion of the region, so
no mappable page goes unmapped that isn't already unmapped today.

## On "warn + do nothing"

Happy to add a WARN_ON for a sub-page no-map region adjacent to mappable
memory — useful as a firmware-compat signal — but a warning alone leaves
the no-map memory mapped, so I'd keep the inward rounding with it. If
that reasoning holds I'll send v2 with the WARN added.

Thanks,
Lianghong Liu



  reply	other threads:[~2026-07-27  1:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13  1:02 [PATCH] arm64: mm: fix accidental linear mapping of no-map reserved memory liulhong617
2026-07-16 14:01 ` Will Deacon
2026-07-27  1:55   ` Lianghong Liu [this message]
2026-08-04 13:41     ` Will Deacon
2026-08-04 14:24   ` Ard Biesheuvel
2026-08-06 13:16     ` Will Deacon
2026-08-06 17:11 ` Will Deacon

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=20260727015527.1@liulhong617.163.com \
    --to=liulhong617@163.com \
    --cc=ardb@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=will@kernel.org \
    /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