Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Muchun Song" <songmuchun@bytedance.com>,
	"Oscar Salvador" <osalvador@suse.de>,
	"David Hildenbrand" <david@kernel.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>
Cc: "Muchun Song" <muchun.song@linux.dev>,
	"Liam R . Howlett" <liam@infradead.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Michal Hocko" <mhocko@suse.com>,
	"Miaohe Lin" <linmiaohe@huawei.com>,
	"Naoya Horiguchi" <nao.horiguchi@gmail.com>,
	"Lance Yang" <lance.yang@linux.dev>,
	"Qi Zheng" <qi.zheng@linux.dev>,
	linux-mm@kvack.org
Subject: Re: [PATCH 2/2] mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized
Date: Fri, 04 Dec 2026 07:23:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-249308@kernel.org> (raw)
In-Reply-To: <20261204065009.1392156-3-songmuchun@bytedance.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] mm: circular header include breaks LoongArch build in
  vmemmap-optimization.h
- [Medium] mm: folio_vmemmap_optimized() flips too early during
  vmemmap_restore_folio()
--

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

mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized

This commit replaces folio_test_hugetlb_vmemmap_optimized() with
folio_vmemmap_optimized() across hugetlb and memory-failure paths and
removes the HPG_vmemmap_optimized flag and its explicit updates.

> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 11ab74970738f..781e5a8a99d00 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -1503,7 +1503,7 @@ void remove_hugetlb_folio(struct hstate *h, struct folio *folio,
>  	 * pages.  Otherwise, someone (memory error handling) may try to write
>  	 * to tail struct pages.
>  	 */
> -	if (!folio_test_hugetlb_vmemmap_optimized(folio))
> +	if (!folio_vmemmap_optimized(folio))
>  		__folio_clear_hugetlb(folio);

[Severity: High]
Does folio_vmemmap_optimized() break the LoongArch build via a circular
header include?

In commit "mm/vmemmap-optimization: track optimization state in shared
vmemmap pages", include/linux/vmemmap-optimization.h switched to including
linux/mm.h and added the inline helper folio_vmemmap_optimized(), which
calls folio_order().

On LoongArch, arch/loongarch/include/asm/pgtable.h unconditionally includes
linux/vmemmap-optimization.h.  When a translation unit includes linux/mm.h
first, linux/mm.h -> linux/pgtable.h -> asm/pgtable.h ->
linux/vmemmap-optimization.h skips the nested linux/mm.h include because
_LINUX_MM_H is already defined, so folio_order() is undeclared when
folio_vmemmap_optimized() is parsed.

Conversely, including linux/pgtable.h or asm/pgtable.h before linux/mm.h
pulls in linux/mm.h while both pgtable headers are still incomplete.

[ ... ]

> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> index 227148d116dd9..2e39a6d453e4b 100644
> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c

[ ... ]

> @@ -2025,7 +2025,7 @@ void folio_clear_hugetlb_hwpoison(struct folio *folio)
>  {
>  	if (folio_test_hugetlb_raw_hwp_unreliable(folio))
>  		return;
> -	if (folio_test_hugetlb_vmemmap_optimized(folio))
> +	if (folio_vmemmap_optimized(folio))
>  		return;
>  	folio_clear_hwpoison(folio);
>  	folio_free_raw_hwp(folio, true);

[Severity: Medium]
Can folio_vmemmap_optimized() return false before vmemmap_restore_folio()
finishes restoring all tail PTEs, causing SetPageHWPoison() to write to the
shared tail page?

folio_vmemmap_optimized() checks PageVmemmapOptimized() on the first tail
struct page at start + VMEMMAP_OPTIMIZATION_SIZE.  vmemmap_restore_folio()
walks tail PTEs in ascending order and overwrites that first PTE while the
remaining tail PTEs still map the shared tail page and before the TLB is
flushed.

Previously, __hugetlb_vmemmap_restore_folio() cleared HPG_vmemmap_optimized
only after vmemmap_restore_folio() returned.  With the flag removed, a
racing hwpoison_filter() rejection on a free HVO folio can observe
folio_vmemmap_optimized() == false mid-restore:

CPU0                              CPU1
try_memory_failure_hugetlb()
  get_huge_page_for_hwpoison()
    /* free HVO folio, no ref;
       drops hugetlb_lock and
       vmemmap_remap_rwsem */
                                  dissolve_free_hugetlb_folio()
                                    remove_hugetlb_folio()
                                    hugetlb_vmemmap_restore_folio()
                                      vmemmap_restore_range()
                                        /* overwrites first tail PTE;
                                           remaining tail PTEs still
                                           map shared tail page */
  if (hwpoison_filter(p))
    folio_clear_hugetlb_hwpoison()
      folio_vmemmap_optimized()
        /* returns false */
      folio_free_raw_hwp(..., true)
        SetPageHWPoison(p->page)  <-- writes to shared tail page

For bootmem-preallocated HVO gigantic folios whose shared tail PTEs are
mapped read-only, this write causes a kernel page fault.  For runtime HVO
folios with writable shared tail PTEs, it sets PG_hwpoison on the global
shared tail page, corrupting struct page state across all HVO folios in
that zone and order.

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


      reply	other threads:[~2026-12-04  7:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  6:50 [PATCH 0/2] mm: Track vmemmap optimization state in shared backing pages Muchun Song
2026-12-04  6:50 ` [PATCH 1/2] mm/vmemmap-optimization: track optimization state in shared vmemmap pages Muchun Song
2026-12-04  7:23   ` sashiko-bot
2026-12-04  6:50 ` [PATCH 2/2] mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized Muchun Song
2026-12-04  7:23   ` sashiko-bot [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=sashiko-outbox-249308@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linmiaohe@huawei.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=nao.horiguchi@gmail.com \
    --cc=osalvador@suse.de \
    --cc=qi.zheng@linux.dev \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=songmuchun@bytedance.com \
    --cc=vbabka@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