From: <dan.j.williams@intel.com>
To: Gregory Price <gourry@gourry.net>, <linux-cxl@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <kernel-team@meta.com>,
<dave@stgolabs.net>, <jonathan.cameron@huawei.com>,
<dave.jiang@intel.com>, <alison.schofield@intel.com>,
<vishal.l.verma@intel.com>, <ira.weiny@intel.com>,
<dan.j.williams@intel.com>
Subject: Re: [PATCH v2] cxl/memdev: fix deadlock in cxl_memdev_autoremove() on attach failure
Date: Wed, 11 Feb 2026 08:44:21 -0800 [thread overview]
Message-ID: <698cb1e536bde_8c3210028@dwillia2-mobl4.notmuch> (raw)
In-Reply-To: <20260211151601.2082584-1-gourry@gourry.net>
Gregory Price wrote:
> cxl_memdev_autoremove() takes device_lock(&cxlmd->dev) via guard(device)
> and then calls cxl_memdev_unregister() when the attach callback was
> provided but cxl_mem_probe() failed to bind.
>
> cxl_memdev_unregister() calls
> cdev_device_del()
> device_del()
> bus_remove_device()
> device_release_driver()
>
> This path is reached when a driver uses the @attach parameter to
> devm_cxl_add_memdev() and the CXL topology fails to enumerate (e.g.
> DVSEC range registers decode outside platform-defined CXL ranges,
> causing the endpoint port probe to fail).
>
> Fixes: 29317f8dc6ed ("cxl/mem: Introduce cxl_memdev_attach for CXL-dependent operation")
> Signed-off-by: Gregory Price <gourry@gourry.net>
> ---
> drivers/cxl/core/memdev.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
> index af3d0cc65138..281acb3b9abe 100644
> --- a/drivers/cxl/core/memdev.c
> +++ b/drivers/cxl/core/memdev.c
> @@ -1089,10 +1089,8 @@ static int cxlmd_add(struct cxl_memdev *cxlmd, struct cxl_dev_state *cxlds)
> DEFINE_FREE(put_cxlmd, struct cxl_memdev *,
> if (!IS_ERR_OR_NULL(_T)) put_device(&_T->dev))
>
> -static struct cxl_memdev *cxl_memdev_autoremove(struct cxl_memdev *cxlmd)
> +static bool cxl_memdev_did_attach(struct cxl_memdev *cxlmd)
> {
> - int rc;
> -
> /*
> * If @attach is provided fail if the driver is not attached upon
> * return. Note that failure here could be the result of a race to
> @@ -1100,7 +1098,14 @@ static struct cxl_memdev *cxl_memdev_autoremove(struct cxl_memdev *cxlmd)
> * succeeded and then cxl_mem unbound before the lock is acquired.
> */
> guard(device)(&cxlmd->dev);
> - if (cxlmd->attach && !cxlmd->dev.driver) {
> + return (cxlmd->attach && !cxlmd->dev.driver);
> +}
> +
> +static struct cxl_memdev *cxl_memdev_autoremove(struct cxl_memdev *cxlmd)
> +{
> + int rc;
> +
> + if (cxl_memdev_did_attach(cxlmd)) {
Oh, looks like the polarity of the return is flipped from the name. So
either:
s/cxl_memdev_did_attach/cxl_memdev_attach_failed/
...or make the return:
if (!cxlmd->attach)
return true;
if (cxlmd->dev.driver)
return true;
return false;
...and the make the check:
if (!cxl_memdev_did_attach(cxlmd))
I am partial to cxl_memdev_attach_failed() because that avoids the
ambiguity of the !cxlmd->attach case which is ok with "cxlmd->dev.driver
== NULL".
prev parent reply other threads:[~2026-02-11 16:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-11 15:16 [PATCH v2] cxl/memdev: fix deadlock in cxl_memdev_autoremove() on attach failure Gregory Price
2026-02-11 16:44 ` dan.j.williams [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=698cb1e536bde_8c3210028@dwillia2-mobl4.notmuch \
--to=dan.j.williams@intel.com \
--cc=alison.schofield@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=gourry@gourry.net \
--cc=ira.weiny@intel.com \
--cc=jonathan.cameron@huawei.com \
--cc=kernel-team@meta.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