From: Alison Schofield <alison.schofield@intel.com>
To: <junho.cha@xcena.com>
Cc: Dave Jiang <dave.jiang@intel.com>, <linux-cxl@vger.kernel.org>,
"Davidlohr Bueso" <dave@stgolabs.net>,
Jonathan Cameron <jic23@kernel.org>,
Vishal Verma <vishal.l.verma@intel.com>,
Ira Weiny <iweiny@kernel.org>, Li Ming <ming.li@zohomail.com>,
Ben Cheatham <benjamin.cheatham@amd.com>,
"Alejandro Lucero" <alucerop@amd.com>,
Richard Cheng <icheng@nvidia.com>, <linux-kernel@vger.kernel.org>,
Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH v3] cxl/region: Fix self-deadlock when cxl_memdev_attach_region() fails
Date: Thu, 3 Dec 2026 19:15:38 -0800 [thread overview]
Message-ID: <axIwWn0VU0LX4SZ3@aschofie-mobl2.lan> (raw)
In-Reply-To: <20261204-junhomax-fix-cxl-attach-region-deadlock-v3-1-8008f8f72d4a@xcena.com>
On Fri, Dec 04, 2026 at 10:53:26AM +0900, Junho Cha via B4 Relay wrote:
> From: Junho Cha <junho.cha@xcena.com>
>
> A devres allocation failure during cxl_mem probe can deadlock the
> probing task. devm_add_action_or_reset() then runs
> endpoint_unregister_region(), which waits for cxl_rwsem.region for
> write while the task holds it for read. The wait is killable, but a
> fatal signal can interrupt the detach and leave the decoder attached
> to an unregistered region. Lockdep also reports an inversion: the
> cleanup takes cxlrd->regions_lock under cxl_rwsem.dpa, while
> cxl_add_to_region() takes it before both rwsems.
>
> Register the action with devm_add_action() while holding both rwsems,
> so the region cannot be detached between validation and registration.
> If registration fails, release both rwsems before unregistering the
> region to avoid the self-deadlock and the lock order inversion. Keep
> the endpoint device lock held throughout.
>
> Tested with cxl_test (type2_test=1), failing the devres allocation
> through failslab with the stack filter limited to
> cxl_memdev_attach_region(). Probe returned -ENOMEM, the region was
> unregistered, and lockdep reported no inversion.
Thanks for the updates!
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
In the future, be aware that folks will expect you to reply to the
review feedback in the prior revisions email thread. In this case,
you did add my name in the changelog and this was very fresh in my
mind, so I didn't gripe. However, replies are proper ettiquite, and
others (including me) might no be so forgiving next time, so best
to set a pattern of doing so.
Documentation/process/submitting-patches.rst, line 313. The key passage:
"Your patch will almost certainly get comments from reviewers on ways in
which the patch can be improved, in the form of a reply to your email.
You must respond to those comments; ignoring reviewers is a good way to
get ignored in return. You can simply reply to their emails to answer
their comments.
>
> Fixes: d8dcb0b74b04 ("cxl/region: Introduce devm_cxl_probe_mem()")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Link: https://lore.kernel.org/all/20260805080537.7489E1F000E9@smtp.kernel.org/
> Signed-off-by: Junho Cha <junho.cha@xcena.com>
> ---
> Dave pointed at this reset path while reviewing the Type2 multipf
> series [1]. This is a standalone fix for the existing code that keeps
> the region teardown when registering the action fails.
>
> [1] https://lore.kernel.org/linux-cxl/6bc33514-8bfb-44d6-8fde-28f45dff5eb9@intel.com/
> ---
> Changes in v3:
> - Rewrite the commit log as a short summary (Alison).
> - Rename the out-parameter to region_out and the caller's variable to
> cxlr, and drop the comment before the call (Alison).
> - Link to v2: https://patch.msgid.link/20261119-junhomax-fix-cxl-attach-region-deadlock-v2-1-32ddef645e52@xcena.com
>
> Changes in v2:
> - Register the action under both rwsems as before and only run the
> unwind after dropping them. v1 left a window where the region could
> be detached before the action was registered (Ben).
> - Add Reported-by/Link for Sashiko.
> - Drop Alejandro's Reviewed-by, since the fix changed.
> - Link to v1: https://patch.msgid.link/20261117-junhomax-fix-cxl-attach-region-deadlock-v1-1-f373a135edd2@xcena.com
> ---
> drivers/cxl/core/region.c | 31 +++++++++++++++++++++++--------
> 1 file changed, 23 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 237172b33f55..e22a0e3a4590 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -4437,7 +4437,8 @@ static int first_mapped_decoder(struct device *dev, const void *data)
> * Runs in cxl_mem_probe context after successful endpoint probe, assumes the
> * simple case of single mapped decoder per memdev.
> */
> -int cxl_memdev_attach_region(struct cxl_memdev *cxlmd)
> +static int __cxl_memdev_attach_region(struct cxl_memdev *cxlmd,
> + struct cxl_region **region_out)
> {
> struct cxl_attach_region *attach =
> container_of(cxlmd->attach, typeof(*attach), attach);
> @@ -4446,10 +4447,6 @@ int cxl_memdev_attach_region(struct cxl_memdev *cxlmd)
> struct cxl_region *cxlr;
> int rc;
>
> - /* hold endpoint lock to setup autoremove of the region */
> - guard(device)(&endpoint->dev);
> - if (!endpoint->dev.driver)
> - return -ENXIO;
> guard(rwsem_read)(&cxl_rwsem.region);
> guard(rwsem_read)(&cxl_rwsem.dpa);
>
> @@ -4484,10 +4481,11 @@ int cxl_memdev_attach_region(struct cxl_memdev *cxlmd)
>
> /* Only teardown regions that pass validation, ignore the rest */
> get_device(&cxlr->dev);
> - rc = devm_add_action_or_reset(&endpoint->dev,
> - endpoint_unregister_region, cxlr);
> - if (rc)
> + rc = devm_add_action(&endpoint->dev, endpoint_unregister_region, cxlr);
> + if (rc) {
> + *region_out = cxlr;
> return rc;
> + }
>
> attach->hpa_range = (struct range) {
> .start = cxlr->params.res->start,
> @@ -4495,6 +4493,23 @@ int cxl_memdev_attach_region(struct cxl_memdev *cxlmd)
> };
> return 0;
> }
> +
> +int cxl_memdev_attach_region(struct cxl_memdev *cxlmd)
> +{
> + struct cxl_port *endpoint = cxlmd->endpoint;
> + struct cxl_region *cxlr = NULL;
> + int rc;
> +
> + /* hold endpoint lock to setup autoremove of the region */
> + guard(device)(&endpoint->dev);
> + if (!endpoint->dev.driver)
> + return -ENXIO;
> +
> + rc = __cxl_memdev_attach_region(cxlmd, &cxlr);
> + if (cxlr)
> + endpoint_unregister_region(cxlr);
> + return rc;
> +}
> EXPORT_SYMBOL_FOR_MODULES(cxl_memdev_attach_region, "cxl_mem");
>
> /*
>
> ---
> base-commit: 32af7819352bae9c690ebe277a44eceb501d5c68
> change-id: 20261113-junhomax-fix-cxl-attach-region-deadlock-fc0a425f7265
>
> Best regards,
> --
> Junho Cha <junho.cha@xcena.com>
>
>
next prev parent reply other threads:[~2026-12-04 3:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 1:53 Junho Cha via B4 Relay
2026-12-04 3:15 ` Alison Schofield [this message]
2026-12-04 4:55 ` 차준호
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=axIwWn0VU0LX4SZ3@aschofie-mobl2.lan \
--to=alison.schofield@intel.com \
--cc=alucerop@amd.com \
--cc=benjamin.cheatham@amd.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=icheng@nvidia.com \
--cc=iweiny@kernel.org \
--cc=jic23@kernel.org \
--cc=junho.cha@xcena.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.li@zohomail.com \
--cc=sashiko-bot@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®