From: sashiko-bot@kernel.org
To: "Shivank Garg" <shivankg@amd.com>
Cc: linux-cxl@vger.kernel.org, "Chuck Lever" <cel@kernel.org>,
damon@lists.linux.dev, "Jeff Layton" <jlayton@kernel.org>,
kvm@vger.kernel.org, dsterba@suse.cz,
"Anna Schumaker" <anna@kernel.org>
Subject: Re: [PATCH RFC 11/11] mm/migrate: pass migrate_control to migrate_folio()
Date: Wed, 02 Sep 2026 11:10:56 +0000 [thread overview]
Message-ID: <20260902111057.5F8F61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902-migrate-refactor-shivank-v1-11-9dcca87669c4@amd.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] JFS metapage migration crashes or leaks references because it accesses `src->private` after `filemap_migrate_folio()` has detached it.
--
commit 0c092f89cb8cd82947c067576e2c9c259c2c1dc2
Author: Shivank Garg <shivankg@amd.com>
mm/migrate: pass migrate_control to migrate_folio()
This commit updates migrate_folio() callbacks across various filesystems to
accept a migrate_control structure instead of a simple migrate_mode enum.
This change allows additional policy information to reach folio-specific
migration code, while preserving the existing migration mode behavior.
> diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c
> index 41fe12e641cee..7958edacb4971 100644
> --- a/fs/jfs/jfs_metapage.c
> +++ b/fs/jfs/jfs_metapage.c
[ ... ]
> @@ -241,7 +241,7 @@ static int __metapage_migrate_folio(struct address_space *mapping,
> if (metapage_locked(mp))
> return -EAGAIN;
>
> - rc = filemap_migrate_folio(mapping, dst, src, mode);
> + rc = filemap_migrate_folio(mapping, dst, src, ctl);
[Severity: High]
This isn't a bug introduced by this patch, but does this code crash or leak
folio references during migration due to accessing a detached private pointer?
When __metapage_migrate_folio() calls filemap_migrate_folio(), the migration
core delegates to __migrate_folio(). That function moves the private data
from the source to the destination folio:
mm/migrate.c:__migrate_folio() {
...
if (src_private)
folio_attach_private(dst, folio_detach_private(src));
...
}
This detaches the JFS meta_anchor or metapage pointer, leaving src->private
as NULL.
Shortly after the filemap_migrate_folio() call returns successfully, the JFS
code calls remove_metapage(src, mp). When MPS_PER_PAGE > 1, remove_metapage()
reads the now-NULL src->private pointer:
fs/jfs/jfs_metapage.c:remove_metapage() {
struct meta_anchor *a = folio->private;
...
BUG_ON(a->mp[index] != mp);
...
}
Dereferencing 'a' here triggers a severe NULL pointer dereference and kernel
panic.
Alternatively, if MPS_PER_PAGE == 1, insert_metapage(dst, mp) is called.
Since dst->private is already set to mp by the migration core, the call to
folio_attach_private(dst, mp) inside insert_metapage() succeeds but
increments the destination folio's refcount a second time. The subsequent
remove_metapage(src, mp) calls folio_detach_private(src) which does nothing
since it is already NULL. Can this path permanently leak a folio reference
count?
> if (rc)
> return rc;
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com?part=11
prev parent reply other threads:[~2026-09-02 11:11 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 10:52 [PATCH RFC 00/11] mm/migrate: separate migration paths and carry migration policy Shivank Garg
2026-09-02 10:52 ` [PATCH RFC 01/11] mm/migrate: extract folio unmap phase Shivank Garg
2026-09-02 11:02 ` sashiko-bot
2026-09-02 10:52 ` [PATCH RFC 02/11] mm/migrate: handle retries in migrate_folios_move() Shivank Garg
2026-09-02 11:01 ` sashiko-bot
2026-09-02 10:52 ` [PATCH RFC 03/11] mm/migrate: factor out folio splitting on allocation failure Shivank Garg
2026-09-02 11:06 ` sashiko-bot
2026-09-02 10:52 ` [PATCH RFC 04/11] mm/migrate: use a dedicated list for hugetlb folios Shivank Garg
2026-09-02 11:02 ` sashiko-bot
2026-09-02 10:52 ` [PATCH RFC 05/11] mm/migrate: add a dedicated movable_ops migration pass Shivank Garg
2026-09-02 11:04 ` sashiko-bot
2026-09-02 10:52 ` [PATCH RFC 06/11] mm/migrate: rename migrate_pages_batch() to migrate_folios_batch() Shivank Garg
2026-09-02 11:02 ` sashiko-bot
2026-09-02 10:52 ` [PATCH RFC 07/11] mm/migrate: add migrate_lru_folios() entry point Shivank Garg
2026-09-02 11:03 ` sashiko-bot
2026-09-02 10:52 ` [PATCH RFC 08/11] mm/migrate: move LRU batching into migrate_lru_folios() Shivank Garg
2026-09-02 11:00 ` sashiko-bot
2026-09-02 10:52 ` [PATCH RFC 09/11] mm/migrate: thread migration policy through a control struct Shivank Garg
2026-09-02 11:06 ` sashiko-bot
2026-09-02 11:19 ` [sos-linux-ext-patches] " Garg, Shivank
2026-09-02 10:52 ` [PATCH RFC 10/11] mm/migrate: pass migrate_control to migrate_pages() Shivank Garg
2026-09-02 11:11 ` sashiko-bot
2026-09-02 10:52 ` [PATCH RFC 11/11] mm/migrate: pass migrate_control to migrate_folio() Shivank Garg
2026-09-02 11:10 ` Jan Kara
2026-09-02 11:10 ` 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=20260902111057.5F8F61F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=anna@kernel.org \
--cc=cel@kernel.org \
--cc=damon@lists.linux.dev \
--cc=dsterba@suse.cz \
--cc=jlayton@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shivankg@amd.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