From: Alison Schofield <alison.schofield@intel.com>
To: Sungwoo Kim <iam@sung-woo.kim>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
Jonathan Cameron <jonathan.cameron@huawei.com>,
Dave Jiang <dave.jiang@intel.com>,
"Vishal Verma" <vishal.l.verma@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
"Dan Williams" <dan.j.williams@intel.com>,
Ben Widawsky <bwidawsk@kernel.org>,
"Dave Tian" <daveti@purdue.edu>, <linux-cxl@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] cxl/hdm: fix a warning in devm_remove_action()
Date: Tue, 24 Mar 2026 17:46:40 -0700 [thread overview]
Message-ID: <acMwcFT8ng9Hb45K@aschofie-mobl2.lan> (raw)
In-Reply-To: <20260309000810.2632065-2-iam@sung-woo.kim>
On Sun, Mar 08, 2026 at 08:08:10PM -0400, Sungwoo Kim wrote:
> In the following race scenario, devm_remove_action() can be called
> before devm_add_action(), triggering a warning because there is no
> action to remove.
>
> To fix this, extend a critical section to embrace both
> __cxl_dpa_reserve() and devm_add_action().
The fix LGTM. I suggest tightening up the code comment. Now it
talks through the race in detail and also cross-ref another location.
Limit the comment to describing the ordering requirement we need to
preserve. The commit message already captures the full race and
rationale.
Comment update suggestion below-
snip
> +++ b/drivers/cxl/core/hdm.c
> @@ -509,13 +509,20 @@ int devm_cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
> struct cxl_port *port = cxled_to_port(cxled);
> int rc;
>
> - scoped_guard(rwsem_write, &cxl_rwsem.dpa)
> - rc = __cxl_dpa_reserve(cxled, base, len, skipped);
> + guard(rwsem_write)(&cxl_rwsem.dpa);
> + rc = __cxl_dpa_reserve(cxled, base, len, skipped);
>
> if (rc)
> return rc;
>
> - return devm_add_action_or_reset(&port->dev, cxl_dpa_release, cxled);
> + /* See comments in cxl_dpa_alloc()*/
Something like this:
/* Keep reservation and devres registration ordered under dpa lock */
snip
> @@ -613,7 +620,7 @@ static int __cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, u64 size)
> struct resource *p, *last;
> int part;
>
> - guard(rwsem_write)(&cxl_rwsem.dpa);
> + lockdep_assert_held_write(&cxl_rwsem.dpa);
> if (cxled->cxld.region) {
> dev_dbg(dev, "decoder attached to %s\n",
> dev_name(&cxled->cxld.region->dev));
> @@ -679,11 +686,28 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, u64 size)
> struct cxl_port *port = cxled_to_port(cxled);
> int rc;
>
> + guard(rwsem_write)(&cxl_rwsem.dpa);
> rc = __cxl_dpa_alloc(cxled, size);
> if (rc)
> return rc;
>
> - return devm_add_action_or_reset(&port->dev, cxl_dpa_release, cxled);
> + /*
> + * Add the devres action while still holding cxl_rwsem.dpa to prevent
> + * a race with cxl_dpa_free(). Without this, a concurrent cxl_dpa_free()
> + * can observe dpa_res set (by __cxl_dpa_reserve()) and attempt
> + * devm_remove_action() before devm_add_action() has been called,
> + * triggering a WARN_ON in devm_remove_action().
> + * Also, devm_add_action_or_reset() cannot be used here because
> + * cxl_dpa_release() tries to hold the dpa lock that is already held,
> + * causing a self deadlock.
> + */
and like this:
/*
* Hold cxl_rwsem.dpa across allocation and devres registration
* so cxl_dpa_free() cannot observe dpa_res without a matching
* devres action.
*/
snip
next prev parent reply other threads:[~2026-03-25 0:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 0:08 Sungwoo Kim
2026-03-09 19:31 ` Ira Weiny
2026-03-09 20:21 ` Dave Jiang
2026-03-24 4:06 ` Sungwoo Kim
2026-03-25 0:46 ` Alison Schofield [this message]
2026-03-25 22:34 ` Sungwoo Kim
2026-03-25 1:34 ` Dan Williams
2026-03-25 3:47 ` Sungwoo Kim
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=acMwcFT8ng9Hb45K@aschofie-mobl2.lan \
--to=alison.schofield@intel.com \
--cc=bwidawsk@kernel.org \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=daveti@purdue.edu \
--cc=iam@sung-woo.kim \
--cc=ira.weiny@intel.com \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vishal.l.verma@intel.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
all inboxes | Powered by JetHome®