Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Muchun Song" <songmuchun@bytedance.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Madhavan Srinivasan" <maddy@linux.ibm.com>
Cc: "Muchun Song" <muchun.song@linux.dev>,
	"David Hildenbrand" <david@kernel.org>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Ritesh Harjani" <ritesh.list@gmail.com>,
	"Aneesh Kumar K . V" <aneesh.kumar@linux.ibm.com>,
	"Pavithra Prakash" <pavrampu@linux.ibm.com>,
	"Lance Yang" <lance.yang@linux.dev>,
	"Qi Zheng" <qi.zheng@linux.dev>,
	linux-mm@kvack.org, "Chris Down" <chris@chrisdown.name>
Subject: Re: [PATCH v2 4/7] mm/sparse-vmemmap: support PMD mappings spanning sections
Date: Sat, 05 Dec 2026 04:01:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-251033@kernel.org> (raw)
In-Reply-To: <20261205032627.4745-5-songmuchun@bytedance.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm: vmemmap_populate_hugepages() omits section size in
  existing-PMD guard
--

commit 55f747691766c81eafac3af7d218b9f6c570e480
Author: Muchun Song <muchun.song@linux.dev>

mm/sparse-vmemmap: support PMD mappings spanning sections

This commit updates vmemmap_populate_hugepages() to reuse an existing
PMD vmemmap mapping for an HVO-capable section and disable HVO on that
section, warning and returning -EOPNOTSUPP only when the section's
compound page size is at least PMD_SIZE / sizeof(struct page).

> diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
> index 9bcde4f695232..2dc0b3533c3e6 100644
> --- a/mm/sparse-vmemmap.c
> +++ b/mm/sparse-vmemmap.c

[ ... ]

> @@ -492,8 +492,23 @@ int __meminit vmemmap_populate_hugepages(unsigned long start, unsigned long end,
>  				return -ENOMEM;
>  			}
>  		} else if (vmemmap_check_pmd(pmd, node, addr, next)) {
> -			if (WARN_ON_ONCE(section_vmemmap_optimizable(ms)))
> +			unsigned long nr_pages = 1UL << section_compound_order(ms);
> +
> +			/*
> +			 * A naturally aligned HVO compound page covering a full
> +			 * PMD-sized vmemmap range cannot share that range with
> +			 * a neighboring section. An existing PMD mapping is
> +			 * therefore unexpected.
> +			 */
> +			if (WARN_ON_ONCE(nr_pages >= PMD_SIZE / sizeof(struct page)))
>  				return -EOPNOTSUPP;
> +
> +			/*
> +			 * A PMD mapping from a neighboring section may also cover
> +			 * this section. Reuse its ordinary vmemmap backing and
> +			 * disable HVO.
> +			 */
> +			section_set_compound_order(ms, 0);
>  			continue;
>  		}

[Severity: Medium]
Should this check also reject an existing PMD mapping when the section
itself is at least PMD-sized?

An HVO-capable section is always section-aligned, so when
PAGES_PER_SECTION >= PMD_SIZE / sizeof(struct page) it owns one or more
complete PMDs and cannot share one with a neighboring section.

On x86-64 (SECTION_SIZE_BITS = 27), a 2 MiB device-dax mapping has
nr_pages = 512, which is smaller than PMD_SIZE / sizeof(struct page).
An unexpected leftover PMD therefore bypasses WARN_ON_ONCE() and
-EOPNOTSUPP and silently disables HVO instead.

On a multi-PMD section (such as 128-byte struct page on x86-64), an
earlier PMD can already be populated via
vmemmap_optimizable_pte_populate() with PAGE_KERNEL_RO shared tail PTEs.

If a later PMD in the same section hits section_set_compound_order(ms, 0),
sparse_add_section() and memmap_init_compound_page() treat the whole
section as non-HVO and write to those read-only tail pages, causing a
kernel write fault.

Checking section_vmemmap_optimizable(ms) together with
max(nr_pages, PAGES_PER_SECTION) >= PMD_SIZE / sizeof(struct page) would
reject unexpected PMDs on full-PMD and multi-PMD sections while keeping
non-HVO subsection reuse working.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205032627.4745-1-songmuchun@bytedance.com?part=4


  reply	other threads:[~2026-12-05  4:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  3:26 [PATCH v2 0/7] mm: Generalize HVO vmemmap population Muchun Song
2026-12-05  3:26 ` [PATCH v2 1/7] mm/sparse-vmemmap: use page-table constructors for runtime tables Muchun Song
2026-12-05  3:26 ` [PATCH v2 2/7] mm/sparse-vmemmap: align page-table helpers with core MM Muchun Song
2026-12-05  3:26 ` [PATCH v2 3/7] mm/sparse-vmemmap: introduce vmemmap_optimizable_pte_populate Muchun Song
2026-12-05  3:26 ` [PATCH v2 4/7] mm/sparse-vmemmap: support PMD mappings spanning sections Muchun Song
2026-12-05  4:01   ` sashiko-bot [this message]
2026-12-05  3:26 ` [PATCH v2 5/7] powerpc/mm: remove radix-specific vmemmap PMD overrides Muchun Song
2026-12-05  4:01   ` sashiko-bot
2026-12-05  3:26 ` [PATCH v2 6/7] powerpc/mm: fix uninitialized ZONE_DEVICE struct pages with PMDs Muchun Song
2026-12-05  3:26 ` [PATCH v2 7/7] powerpc/mm: reuse generic HVO vmemmap population Muchun Song

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=sashiko-outbox-251033@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=chris@chrisdown.name \
    --cc=david@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=linux-mm@kvack.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=muchun.song@linux.dev \
    --cc=pavrampu@linux.ibm.com \
    --cc=qi.zheng@linux.dev \
    --cc=ritesh.list@gmail.com \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=songmuchun@bytedance.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