From: sashiko-bot@kernel.org
To: "Baolin Wang" <baolin.wang@linux.alibaba.com>,
akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org
Cc: riel@surriel.com, liam@infradead.org, vbabka@kernel.org,
rppt@kernel.org, surenb@google.com, mhocko@suse.com,
harry@kernel.org, jannh@google.com, lance.yang@linux.dev,
qi.zheng@linux.dev, pfalcato@suse.de, linux-mm@kvack.org
Subject: Re: [PATCH] mm: use memory barriers for non PMD-sized folios to sync
Date: Thu, 12 Nov 2026 06:07:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-210496@kernel.org> (raw)
In-Reply-To: <09736bc2e01bec0ca7436733078c82c7e0cc6627.1794376686.git.baolin.wang@linux.alibaba.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mm: sync_with_folio_pmd_zap() triggers BUILD_BUG() when huge
leaves disabled
--
commit 6fcd156071f8ff19dadc585e086208ca97feaaa2
Author: Baolin Wang <baolin.wang@linux.alibaba.com>
mm: use memory barriers for non PMD-sized folios to sync
This commit replaces the PMD lock in sync_with_folio_pmd_zap() with an
smp_rmb() paired with an smp_wmb() in zap_pte_range() when synchronizing
concurrent zapping of non-PMD-sized folios.
> diff --git a/mm/internal.h b/mm/internal.h
> index cd3675c044e0a..a277bf4841f80 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -592,6 +592,7 @@ void pmd_install(struct mm_struct *mm, pmd_t *pmd, pgtable_t *pte);
> * sync_with_folio_pmd_zap - sync with concurrent zapping of folios
> * @mm: The mm_struct.
> * @pmdp: Pointer to the pmd that was found to be pmd_none().
> + * @nr_pages: The number of pages in the folio.
> *
> * When we find a pmd_none() while unmapping a folio without holding the PTL,
> * zap_huge_pmd() may have cleared the PMD but not yet updated the folio
> @@ -600,13 +601,30 @@ void pmd_install(struct mm_struct *mm, pmd_t *pmd, pgtable_t *pte);
> * against later mapcount reads. Skipping the PMD without synchronization
> * could make folio unmapping code assume that unmapping failed.
> *
> - * Wait for concurrent zapping to complete by grabbing the PTL.
> + * Wait for concurrent zapping to complete by grabbing the PTL for PMD-sized
> + * folios, otherwise smp_rmb() is sufficient.
> */
> -static inline void sync_with_folio_pmd_zap(struct mm_struct *mm, pmd_t *pmdp)
> +static inline void sync_with_folio_pmd_zap(struct mm_struct *mm, pmd_t *pmdp,
> + unsigned int nr_pages)
> {
> - spinlock_t *ptl = pmd_lock(mm, pmdp);
> + if (nr_pages >= HPAGE_PMD_NR) {
> + spinlock_t *ptl = pmd_lock(mm, pmdp);
>
> - spin_unlock(ptl);
> + spin_unlock(ptl);
> + return;
> + }
[Severity: High]
Does evaluating HPAGE_PMD_NR against the runtime nr_pages argument break
the build when CONFIG_PGTABLE_HAS_HUGE_LEAVES is disabled?
When both CONFIG_TRANSPARENT_HUGEPAGE and CONFIG_HUGETLB_PAGE are
disabled, HPAGE_PMD_SHIFT expands to a BUILD_BUG():
include/linux/huge_mm.h:
#ifdef CONFIG_PGTABLE_HAS_HUGE_LEAVES
#define HPAGE_PMD_SHIFT PMD_SHIFT
#define HPAGE_PUD_SHIFT PUD_SHIFT
#else
#define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
#define HPAGE_PUD_SHIFT ({ BUILD_BUG(); 0; })
#endif
#define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
#define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
Because zap_pmd_range() and page_vma_mapped_walk() call
sync_with_folio_pmd_zap() unconditionally, the compiler cannot eliminate
the HPAGE_PMD_NR evaluation and triggers BUILD_BUG(). Guarding the check
with IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) avoids evaluating
HPAGE_PMD_NR when transparent hugepages are disabled.
--
Sashiko AI review · https://sashiko.dev/#/patchset/09736bc2e01bec0ca7436733078c82c7e0cc6627.1794376686.git.baolin.wang@linux.alibaba.com?part=1
prev parent reply other threads:[~2026-11-12 6:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 6:06 [PATCH] mm: use memory barriers for non PMD-sized folios to sync Baolin Wang
2026-11-11 7:48 ` David Hildenbrand (Arm)
2026-11-11 8:43 ` Baolin Wang
2026-11-11 9:22 ` David Hildenbrand (Arm)
2026-11-11 11:12 ` Baolin Wang
2026-11-12 6:07 ` 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-210496@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=harry@kernel.org \
--cc=jannh@google.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=pfalcato@suse.de \
--cc=qi.zheng@linux.dev \
--cc=riel@surriel.com \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=surenb@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.