Linux CXL
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Muchun Song" <songmuchun@bytedance.com>
Cc: nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org
Subject: Re: [PATCH] mm: warn on unaligned compound zone device ranges
Date: Fri, 16 Oct 2026 13:22:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-174381@kernel.org> (raw)
In-Reply-To: <20261016131334.3419393-1-songmuchun@bytedance.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mm: out-of-bounds struct page write due to unhandled unaligned range
--

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

mm: warn on unaligned compound zone device ranges

A compound page of order N must start at a PFN aligned to 2^N pages.
Therefore, a range used to initialize compound pages must start on a
compound-page boundary and contain an integral number of compound pages.

Link: https://lore.kernel.org/r/20261016053944.2579541-1-songmuchun@bytedance.com
Link: https://lore.kernel.org/r/20261016054914.2601510-1-songmuchun@bytedance.com

> diff --git a/mm/mm_init.c b/mm/mm_init.c
> index 4c17a892924d2..01ced0553ce9b 100644
> --- a/mm/mm_init.c
> +++ b/mm/mm_init.c
> @@ -1142,6 +1142,8 @@ void __ref memmap_init_zone_device(struct zone *zone,
>  	if (!nr_pages)
>  		return;
>  
> +	VM_WARN_ON(!IS_ALIGNED(start_pfn | nr_pages, pfns_per_compound));
> +

[Severity: High]
This warning detects the unaligned range, but does this still allow an
out-of-bounds write if execution continues?

If nr_pages is not a multiple of pfns_per_compound, the main initialization
loop in memmap_init_zone_device() advances by pfns_per_compound chunks:

	for (; pfn < end_pfn; pfn += pfns_per_compound) {
		...
		memmap_init_compound(page, pfn, zone_idx, nid, pgmap,
				     compound_nr_pages(pfn, pgmap));
	}

And memmap_init_compound() will then write exactly pfns_per_compound entries
(since compound_nr_pages() returns pfns_per_compound), ignoring the actual
end of the zone-device range:

	for (pfn = head_pfn + 2; pfn < end_pfn; pfn++)
		zone_device_page_init_from_template(pfn_to_page(pfn), ...);

Could this overrun the allocated range and corrupt adjacent struct pages?

Additionally, since VM_WARN_ON is compiled out without CONFIG_DEBUG_VM,
could this result in silent memory corruption on production kernels?

Should we abort the initialization when an unaligned range is detected?

>  	/*
>  	 * Seed the reusable head-page template from the first real struct
>  	 * page. The normal page-init and refcount helpers must operate on

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

  reply	other threads:[~2026-10-16 13:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 13:13 [PATCH] mm: warn on unaligned compound zone device ranges Muchun Song
2026-10-16 13:22 ` sashiko-bot [this message]
2026-10-17  2:21 ` Andrew Morton
2026-10-17  2:25   ` 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-174381@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --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