From: Dave Jiang <dave.jiang@intel.com>
To: John Groves <john@jagalactic.com>, John Groves <John@Groves.net>,
Dan Williams <djbw@kernel.org>
Cc: John Groves <jgroves@micron.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Matthew Wilcox <willy@infradead.org>, Jan Kara <jack@suse.cz>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>,
Miklos Szeredi <miklos@szeredi.hu>,
Alison Schofield <alison.schofield@intel.com>,
Ira Weiny <iweiny@kernel.org>,
Jonathan Cameron <jic23@kernel.org>,
"nvdimm@lists.linux.dev" <nvdimm@lists.linux.dev>,
"linux-cxl@vger.kernel.org" <linux-cxl@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH V2 5/7] dax: fix holder_ops race in fs_put_dax()
Date: Tue, 26 May 2026 17:16:19 -0700 [thread overview]
Message-ID: <e7655b88-c56d-4d9a-8ae1-68eb9448bb87@intel.com> (raw)
In-Reply-To: <0100019e5120c6c2-6fee7a58-7fb8-4c80-a229-4b5573e0e2c0-000000@email.amazonses.com>
On 5/22/26 12:19 PM, John Groves wrote:
> From: John Groves <John@Groves.net>
>
> Clear holder_ops before holder_data so that a concurrent fs_dax_get()
> cannot have its newly installed holder_ops overwritten. Also add a
> kerneldoc comment documenting that fs_put_dax() must only be called
> by the current holder.
>
> Fixes: eec38f5d86d27 ("dax: add fs_dax_get() for devdax")
> Signed-off-by: John Groves <john@groves.net>
Couple things from Claude that may be worth taking a look at:
1. Memory ordering is now load-bearing and missing
The whole correctness argument depends on the reader observing holder_ops =
NULL before observing holder_data = NULL. The patch uses a plain store
followed by cmpxchg. On x86 plain stores are ordered, but on arm64/ppc they
are not — the reader can observe cmpxchg's release of holder_data while still
seeing the old holder_ops. That puts us back in the dangerous (holder_data ==
NULL, holder_ops == old) state on weakly-ordered arches.
Required:
smp_store_release(&dax_dev->holder_ops, NULL); /* publish ops=NULL first */
cmpxchg(&dax_dev->holder_data, holder, NULL); /* then release holder_data
*/
And the reader in dax_holder_notify_failure should use
smp_load_acquire/READ_ONCE because today it reads dax_dev->holder_ops twice
(line 334 and line 339), allowing tearing or stale-cache reads. Pre-existing
weakness, but this patch is what makes the ordering matter.
kill_dax (line 461-462) has the same naked-store pattern — it should be made
consistent.
2. Unconditional holder_ops = NULL is a behavior regression
Pre-patch was defensive: if a caller passed the wrong holder, the cmpxchg
failed and nothing got cleared.
Post-patch clears holder_ops unconditionally whenever dax_dev && holder is
truthy. A wrong-holder fs_put_dax() now actively damages the legitimate
holder's state — sets holder_ops to NULL while holder_data retains the
legitimate holder's pointer. From that point, all dax_holder_notify_failure()
calls return -EOPNOTSUPP, silently breaking the legitimate holder's
poison-recovery path.
DJ
> ---
> drivers/dax/super.c | 24 ++++++++++++++++++++++--
> 1 file changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dax/super.c b/drivers/dax/super.c
> index 25cf99dd9360b..fa1d2a6eb2408 100644
> --- a/drivers/dax/super.c
> +++ b/drivers/dax/super.c
> @@ -116,11 +116,31 @@ EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev);
>
> #if IS_ENABLED(CONFIG_FS_DAX)
>
> +/**
> + * fs_put_dax() - release holder ownership of a dax_device
> + * @dax_dev: dax device to release (may be NULL)
> + * @holder: the holder pointer previously passed to fs_dax_get() or
> + * fs_dax_get_by_bdev(); must match exactly, as it is used
> + * in a cmpxchg to atomically release ownership
> + *
> + * Must only be called by the current holder. Clears holder_ops before
> + * holder_data to avoid a race where a concurrent fs_dax_get() could have
> + * its newly installed holder_ops overwritten.
> + */
> void fs_put_dax(struct dax_device *dax_dev, void *holder)
> {
> - if (dax_dev && holder &&
> - cmpxchg(&dax_dev->holder_data, holder, NULL) == holder)
> + if (dax_dev && holder) {
> + /*
> + * Clear holder_ops before holder_data so that a concurrent
> + * fs_dax_get() cannot have its newly installed holder_ops
> + * overwritten. holder_ops is only consulted when holder_data
> + * is non-NULL, so clearing ops first is safe — any in-flight
> + * holder_notify_failure() will see the old holder_data with
> + * NULL ops (a no-op) rather than new ops with wrong context.
> + */
> dax_dev->holder_ops = NULL;
> + cmpxchg(&dax_dev->holder_data, holder, NULL);
> + }
> put_dax(dax_dev);
> }
> EXPORT_SYMBOL_GPL(fs_put_dax);
next prev parent reply other threads:[~2026-05-27 0:16 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260522191804.79088-1-john@jagalactic.com>
2026-05-22 19:18 ` [PATCH V2 0/7] Fixes to the previously-merged drivers/dax/fsdev series John Groves
[not found] ` <20260522191843.79132-1-john@jagalactic.com>
2026-05-22 19:18 ` [PATCH V2 1/7] dax: fix misleading comment about share/index union in dax_folio_reset_order() John Groves
2026-05-26 23:07 ` Dave Jiang
2026-05-29 23:41 ` John Groves
[not found] ` <20260522191851.79150-1-john@jagalactic.com>
2026-05-22 19:18 ` [PATCH V2 2/7] dax/fsdev: fix multi-range offset, vmemmap_shift leak, and probe error cleanup John Groves
2026-05-26 23:22 ` Dave Jiang
2026-05-29 23:59 ` John Groves
[not found] ` <20260522191859.79167-1-john@jagalactic.com>
2026-05-22 19:19 ` [PATCH V2 3/7] dax/fsdev: fix kaddr for multi-range and fail probe on invalid pgmap offset John Groves
2026-05-26 23:31 ` Dave Jiang
2026-05-30 0:04 ` John Groves
[not found] ` <20260522191907.79187-1-john@jagalactic.com>
2026-05-22 19:19 ` [PATCH V2 4/7] dax/fsdev: clamp direct_access return to current physical range John Groves
2026-05-27 0:00 ` Dave Jiang
2026-05-30 13:06 ` John Groves
[not found] ` <20260522191917.79204-1-john@jagalactic.com>
2026-05-22 19:19 ` [PATCH V2 5/7] dax: fix holder_ops race in fs_put_dax() John Groves
2026-05-27 0:16 ` Dave Jiang [this message]
2026-05-30 14:02 ` John Groves
2026-05-30 14:32 ` John Groves
[not found] ` <20260522191925.79227-1-john@jagalactic.com>
2026-05-22 19:19 ` [PATCH V2 6/7] dax: replace exported dax_dev_get() with non-allocating dax_dev_find() John Groves
2026-05-27 0:28 ` Dave Jiang
2026-05-30 14:19 ` John Groves
[not found] ` <20260522191937.79247-1-john@jagalactic.com>
2026-05-22 19:19 ` [PATCH V2 7/7] dax: fsdev.c minor formatting cleanup John Groves
2026-05-27 0:31 ` Dave Jiang
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=e7655b88-c56d-4d9a-8ae1-68eb9448bb87@intel.com \
--to=dave.jiang@intel.com \
--cc=John@Groves.net \
--cc=alison.schofield@intel.com \
--cc=brauner@kernel.org \
--cc=djbw@kernel.org \
--cc=iweiny@kernel.org \
--cc=jack@suse.cz \
--cc=jgroves@micron.com \
--cc=jic23@kernel.org \
--cc=john@jagalactic.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=nvdimm@lists.linux.dev \
--cc=viro@zeniv.linux.org.uk \
--cc=vishal.l.verma@intel.com \
--cc=willy@infradead.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
Powered by JetHome