Skip to content

[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] sync bugfixes for mm/rmap: interface overhaul #1972

Merged
opsiff merged 4 commits into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-07-10-mm
Jul 10, 2026
Merged

[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] sync bugfixes for mm/rmap: interface overhaul #1972
opsiff merged 4 commits into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-07-10-mm

Conversation

@opsiff

@opsiff opsiff commented Jul 10, 2026

Copy link
Copy Markdown
Member

#1969

Summary by Sourcery

Align rmap and hugepage handling with upstream fixes to improve correctness of THP and folio dirty accounting.

Bug Fixes:

  • Relax rmap sanity checks for large folios to account for driver-allocated folios in mixed VMAs.
  • Ensure do_set_pmd uses the folio order consistently and correctly derives the page from the folio when installing PMD-sized THPs.
  • Fix THP and migration entry paths to correctly mark backing folios dirty based on pmd state.

Enhancements:

  • Replace legacy folio_set_dirty uses with folio_mark_dirty to match the updated folio dirty-tracking interface.

David Hildenbrand and others added 4 commits July 10, 2026 11:53
mainline inclusion
from mainline-v6.8-rc1
category: bugfix

Unfortunately, vm_insert_page() and friends and up passing
driver-allocated folios into folio_add_file_rmap_pte() using
insert_page_into_pte_locked().

While these driver-allocated folios can be compound pages (large folios),
they are not proper "rmappable" folios.

In these VM_MIXEDMAP VMAs, there isn't really the concept of a reverse
mapping, so long-term, we should clean that up and not call into rmap
code.

For the time being, document how we can end up in rmap code with large
folios that are not marked rmappable.

Link: https://lkml.kernel.org/r/793c5cee-d5fc-4eb1-86a2-39e05686233d@redhat.com
Fixes: 68f0320 ("mm/rmap: convert folio_add_file_rmap_range() into folio_add_file_rmap_[pte|ptes|pmd]()")
Reported-by: syzbot+50ef73537bbc393a25bb@syzkaller.appspotmail.com
Closes: https://lkml.kernel.org/r/000000000000014174060e09316e@google.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Yin Fengwei <fengwei.yin@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 9c59386)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.8-rc3
category: bugfix

The correct folio replacement for "set_page_dirty()" is
"folio_mark_dirty()", not "folio_set_dirty()".  Using the latter won't
properly inform the FS using the dirty_folio() callback.

This has been found by code inspection, but likely this can result in some
real trouble.

Link: https://lkml.kernel.org/r/20240122175407.307992-1-david@redhat.com
Fixes: a8e61d5 ("mm/huge_memory: page_remove_rmap() -> folio_remove_rmap_pmd()")
Signed-off-by: David Hildenbrand <david@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit db44c65)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
…nge()

mainline inclusion
from mainline-v6.8-rc3
category: bugfix

The correct folio replacement for "set_page_dirty()" is
"folio_mark_dirty()", not "folio_set_dirty()".  Using the latter won't
properly inform the FS using the dirty_folio() callback.

This has been found by code inspection, but likely this can result in some
real trouble when zapping dirty PTEs that point at clean pagecache folios.

Yuezhang Mo said: "Without this fix, testing the latest exfat with
xfstests, test cases generic/029 and generic/030 will fail."

Link: https://lkml.kernel.org/r/20240122171751.272074-1-david@redhat.com
Fixes: c462650 ("mm/memory: page_remove_rmap() -> folio_remove_rmap_pte()")
Signed-off-by: David Hildenbrand <david@redhat.com>
Reported-by: Ryan Roberts <ryan.roberts@arm.com>
Closes: https://lkml.kernel.org/r/2445cedb-61fb-422c-8bfb-caf0a2beed62@arm.com
Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit e4e3df2)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.10-rc6
category: bugfix

The requirement that the head page be passed to do_set_pmd() was added in
commit ef37b2e ("mm/memory: page_add_file_rmap() ->
folio_add_file_rmap_[pte|pmd]()") and prevents pmd-mapping in the
finish_fault() and filemap_map_pages() paths if the page to be inserted is
anything but the head page for an otherwise suitable vma and pmd-sized
page.

Matthew said:

: We're going to stop using PMDs to map large folios unless the fault is
: within the first 4KiB of the PMD.  No idea how many workloads that
: affects, but it only needs to be backported as far as v6.8, so we may
: as well backport it.

Link: https://lkml.kernel.org/r/20240611153216.2794513-1-abrestic@rivosinc.com
Fixes: ef37b2e ("mm/memory: page_add_file_rmap() -> folio_add_file_rmap_[pte|pmd]()")
Signed-off-by: Andrew Bresticker <abrestic@rivosinc.com>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Hugh Dickins <hughd@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit ab1ffc8)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@sourcery-ai

sourcery-ai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Synchronizes rmap-related bugfixes and interface changes from upstream by relaxing folio rmap sanity checks, switching several MM paths from folio_set_dirty() to folio_mark_dirty(), and fixing THP PMD setup to consistently derive the page from the folio after order validation.

File-Level Changes

Change Details Files
Relax rmap folio sanity checking to accommodate driver-allocated large folios and document required future handling.
  • Remove strict assertion tying large folios to folio_test_large_rmappable() in rmap sanity checks.
  • Add explanatory TODO comment about VM_MIXEDMAP VMA handling and rmap-compatible folios.
  • Keep other folio/page consistency checks and nr_pages validation unchanged.
include/linux/rmap.h
Use folio_mark_dirty() instead of folio_set_dirty() in key MM code paths handling PTE/PMD dirty state propagation.
  • Change zap_pte_range to mark folios dirty with folio_mark_dirty() when a dirty PTE is zapped for non-anon folios.
  • Update huge PMD split path to call folio_mark_dirty() when pmd_dirty() but folio is not yet dirty.
  • Update PMD migration entry setup to call folio_mark_dirty() on dirty PMDs before creating migration entries.
mm/memory.c
mm/huge_memory.c
Correct THP PMD setup logic to rely solely on folio order and to consistently set the page pointer from the folio after validation.
  • Remove redundant check comparing the incoming page pointer to &folio->page when setting a PMD for THP.
  • Require only that folio_order(folio) matches HPAGE_PMD_ORDER before proceeding.
  • Explicitly assign page = &folio->page once order is validated to ensure consistent page/folio pairing.
mm/memory.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

@opsiff: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
github-trigger-obs-ci fa1d802 link true /test github-trigger-obs-ci

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In __folio_rmap_sanity_checks(), the previous large_rmappable check is dropped entirely and replaced with a TODO; consider either tightening the comment to describe the current expected invariants for VM_MIXEDMAP folios or adding a targeted VM_WARN_ON for clearly invalid cases to avoid silently masking real bugs.
  • In do_set_pmd(), you now unconditionally derive page from the folio after only checking the folio order; if non-head pages can still legitimately reach this path, it may be safer to assert that page == &folio->page (e.g. via VM_WARN_ON) or otherwise document the invariant that only head pages are expected here.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In __folio_rmap_sanity_checks(), the previous large_rmappable check is dropped entirely and replaced with a TODO; consider either tightening the comment to describe the current expected invariants for VM_MIXEDMAP folios or adding a targeted VM_WARN_ON for clearly invalid cases to avoid silently masking real bugs.
- In do_set_pmd(), you now unconditionally derive `page` from the folio after only checking the folio order; if non-head pages can still legitimately reach this path, it may be safer to assert that `page == &folio->page` (e.g. via VM_WARN_ON) or otherwise document the invariant that only head pages are expected here.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from opsiff. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@opsiff opsiff merged commit c11e1d8 into deepin-community:linux-6.6.y Jul 10, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants