From: sashiko-bot@kernel.org
To: "John Groves" <john@jagalactic.com>
Cc: linux-cxl@vger.kernel.org
Subject: Re: [PATCH V6 05/10] dax/fsdev: clear pgmap ops and owner on unbind
Date: Mon, 15 Jun 2026 16:22:30 +0000 [thread overview]
Message-ID: <20260615162230.F18F01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <0100019ecc094b6e-fc163bde-0396-4a33-909f-fb88e740be27-000000@email.amazonses.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Incorrect devres registration order leaves an error path unprotected and introduces a concurrent NULL pointer dereference during unbind.
Pre-existing issues:
- [High] Prematurely clearing folio state on unbind can corrupt memory for concurrent users.
--
commit 7c895b5292c660c81442978247753fce9d42653f
Author: John Groves <John@Groves.net>
Subject: dax/fsdev: clear pgmap ops and owner on unbind
This commit registers a devm action to clear pgmap->ops and pgmap->owner
on unbind. This prevents stale handlers from being executed if the static
device is later rebound to another driver or if the module is unloaded.
> diff --git a/drivers/dax/fsdev.c b/drivers/dax/fsdev.c
> index 0fd5e1293d725..68a4369562f70 100644
> --- a/drivers/dax/fsdev.c
> +++ b/drivers/dax/fsdev.c
[ ... ]
> @@ -306,6 +323,11 @@ static int fsdev_dax_probe(struct dev_dax *dev_dax)
> if (IS_ERR(addr))
> return PTR_ERR(addr);
>
> + /* Drop fsdev's pgmap->ops/owner on unbind so no stale ops survive. */
> + rc = devm_add_action_or_reset(dev, fsdev_clear_pgmap_ops, pgmap);
> + if (rc)
> + return rc;
> +
[Severity: High]
Does registering this action after devm_memremap_pages() cause an issue with
the devres LIFO unbind order?
Since devres unwinds in reverse order, fsdev_clear_pgmap_ops() will run
before the memory is unmapped by the devm_memremap_pages() release action.
This means pgmap->ops and pgmap->owner are set to NULL while the memory map
is still active and its per-CPU refcount is alive.
If a hardware error occurs concurrently during unbind, could memory_failure()
evaluate pgmap_has_memory_failure() as true, but then dereference a newly
NULL pgmap->ops?
mm/memory-failure.c:memory_failure_dev_pagemap() {
...
if (pgmap_has_memory_failure(pgmap)) {
rc = pgmap->ops->memory_failure(pgmap, pfn, 1, flags);
...
}
Similarly, could fsdev_pagemap_memory_failure() dereference a NULL dev_dax
pointer since the owner was cleared early?
Also, if devm_memremap_pages() returns an error, the function returns early
before this devm action is registered. Will the shared static pgmap retain
the stale ops and owner pointers on this error path?
Would moving this registration before devm_memremap_pages() fix both issues?
> /*
> * Clear any stale compound folio state left over from a previous
> * driver (e.g., device_dax with vmemmap_shift). Also register this
> * as a devm action so folio state is cleared on unbind, ensuring
> * clean pages for subsequent drivers (e.g., kmem for system-ram).
> */
> fsdev_clear_folio_state(dev_dax);
> rc = devm_add_action_or_reset(dev, fsdev_clear_folio_state_action,
> dev_dax);
[Severity: High]
This isn't a bug introduced by this patch, but does the preexisting
fsdev_clear_folio_state_action registration suffer from the same LIFO
devres ordering issue?
Because it is registered after devm_memremap_pages(), this action will
also execute before the active page map references drop during unbind.
Since fsdev_clear_folio_state() calls dax_folio_reset_order() to zero out
folio->mapping and folio->share, could this corrupt memory if threads are
performing direct I/O pins (e.g., via get_user_pages) and actively hold
valid references to these pages as compound folios?
Modifying folio metadata while the pages are actively pinned could lead to
refcount imbalances when concurrent users eventually unpin the folios.
Should this action also be moved before devm_memremap_pages()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/0100019ecc080a68-8dc0c99f-ab17-4aa9-83d9-490e9c97ac2e-000000@email.amazonses.com?part=5
next prev parent reply other threads:[~2026-06-15 16:22 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260615160531.17432-1-john@jagalactic.com>
2026-06-15 16:05 ` [PATCH V6 0/10] Fixes to the previously-merged drivers/dax/fsdev series John Groves
2026-06-15 16:06 ` [PATCH V6 01/10] dax: fix misleading comment about share/index union in dax_folio_reset_order() John Groves
2026-06-15 16:06 ` [PATCH V6 02/10] dax/fsdev: fix multi-range offset in memory_failure handler John Groves
2026-06-15 16:25 ` sashiko-bot
2026-06-15 16:06 ` [PATCH V6 03/10] dax/fsdev: clear vmemmap_shift when binding static pgmap John Groves
2026-06-15 16:25 ` sashiko-bot
2026-06-15 16:06 ` [PATCH V6 04/10] dax/fsdev: don't leave a dangling dev_dax->pgmap on probe failure John Groves
2026-06-15 16:18 ` sashiko-bot
2026-06-15 16:07 ` [PATCH V6 05/10] dax/fsdev: clear pgmap ops and owner on unbind John Groves
2026-06-15 16:22 ` sashiko-bot [this message]
2026-06-15 16:07 ` [PATCH V6 06/10] dax/fsdev: use __va(phys) for kaddr in direct_access John Groves
2026-06-15 16:19 ` sashiko-bot
2026-06-15 16:07 ` [PATCH V6 07/10] dax/fsdev: fail probe on invalid pgmap offset John Groves
2026-06-15 18:22 ` sashiko-bot
2026-06-15 16:07 ` [PATCH V6 08/10] dax: read holder_ops once in dax_holder_notify_failure() John Groves
2026-06-15 16:20 ` sashiko-bot
2026-06-15 16:07 ` [PATCH V6 09/10] dax: fix holder_ops race in fs_put_dax() John Groves
2026-06-15 16:23 ` sashiko-bot
2026-06-15 16:07 ` [PATCH V6 10/10] dax: fsdev.c minor formatting cleanup John Groves
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=20260615162230.F18F01F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=john@jagalactic.com \
--cc=linux-cxl@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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