From: Alison Schofield <alison.schofield@intel.com>
To: <junho.cha@xcena.com>
Cc: <linux-cxl@vger.kernel.org>, Dave Jiang <dave.jiang@intel.com>,
Li Ming <ming.li@zohomail.com>,
Vishal Verma <vishal.l.verma@intel.com>,
"Richard Cheng" <icheng@nvidia.com>,
Jonathan Cameron <jic23@kernel.org>,
"Davidlohr Bueso" <dave@stgolabs.net>,
Ben Cheatham <benjamin.cheatham@amd.com>,
"Ira Weiny" <iweiny@kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] cxl/region: Reject freeing the HPA of a region with attached targets
Date: Wed, 2 Dec 2026 19:39:24 -0800 [thread overview]
Message-ID: <axDkbO2ixy_-VUbK@aschofie-mobl2.lan> (raw)
In-Reply-To: <20261124-junhomax-fix-cxl-region-free-hpa-targets-v1-1-9229ae407595@xcena.com>
On Tue, Nov 24, 2026 at 06:15:47PM +0900, Junho Cha via B4 Relay wrote:
> From: Junho Cha <junho.cha@xcena.com>
>
> free_hpa() only refuses once the region is CXL_CONFIG_ACTIVE. With
> some targets attached, root can write 0 to size, which returns the
> region to CXL_CONFIG_IDLE and lets interleave_ways,
> interleave_granularity and size change while the attached endpoint
> decoders keep their old settings.
>
> The region can then be committed with endpoint decoders that do not
> match it. If interleave_ways shrinks so that an attached target's
> position is out of range, attaching targets until nr_targets reaches
> the new interleave_ways can lead to a NULL dereference in
> cxl_region_setup_targets(). Deleting the region and later unbinding
> that target's memdev can lead to a use-after-free in
> __cxl_decoder_detach(). All three were reproduced with cxl_test.
>
> Refuse to free the HPA while any target is attached. libcxl never
> writes 0 to size, so cxl-cli is not affected.
Hi Junho,
Thanks for the patch! Great minds think alike ... that would be you
and DaveJ. DaveJ passed me patches in this space to look over and post
but I am still fussing with them. One of those patches addresses this
case, but I see no reason to hold your patch back. Let's get this one
in shape, and applied and I will continue to work DaveJ's set on top
of it.
FYI DaveJ's set addresses a more broader case of the kernel handing
out HPA that decoders still decode.
I have one change request for you below...
>
> Fixes: 384e624bb211 ("cxl/region: Attach endpoint decoders")
> Cc: stable@vger.kernel.org
> Signed-off-by: Junho Cha <junho.cha@xcena.com>
> ---
> Tested with cxl_test before and after the change on cxl/next, v6.12 and
> v6.16. The patch applies unchanged to v6.1, v6.6, v6.12 and v6.18.
> Writing 0 to size after detaching all targets still works. Before
> commit b3a88225519c ("cxl/region: Consolidate cxl_decoder_kill_region()
> and cxl_region_detach()"), the use-after-free case only triggers a
> warning.
> ---
> drivers/cxl/core/region.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 237172b33f55..53965f1e4719 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -772,6 +772,10 @@ static int free_hpa(struct cxl_region *cxlr)
> if (!p->res)
> return 0;
>
> + /* Attached targets hold the current geometry, detach them first */
> + if (p->nr_targets)
> + return -EBUSY;
> +
> if (p->state >= CXL_CONFIG_ACTIVE)
> return -EBUSY;
I suggest removing the CXL_CONFIG_ACTIVE test.
After your new test that state check is dead code, not defensive code.
It's going to make every reader stop and think about whether it can
still fire. It cannot. Every path that puts a region at ACTIVE or
above has all its targets attached.
Please v2 with that and I will tag this one.
-- Alison
>
>
> ---
> base-commit: 32af7819352bae9c690ebe277a44eceb501d5c68
> change-id: 20261124-junhomax-fix-cxl-region-free-hpa-targets-0838a7a4e93d
>
> Best regards,
> --
> Junho Cha <junho.cha@xcena.com>
>
>
prev parent reply other threads:[~2026-12-03 3:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 9:15 Junho Cha via B4 Relay
2026-12-03 3:39 ` Alison Schofield [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=axDkbO2ixy_-VUbK@aschofie-mobl2.lan \
--to=alison.schofield@intel.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=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®