From: Dave Jiang <dave.jiang@intel.com>
To: Jim Harris <jim.harris@samsung.com>,
"linux-cxl@vger.kernel.org" <linux-cxl@vger.kernel.org>,
"dan.carpenter@linaro.org" <dan.carpenter@linaro.org>,
"dan.j.williams@intel.com" <dan.j.williams@intel.com>
Subject: Re: [PATCH v2] cxl/region: don't try to cleanup after cxl_region_setup_targets() fails
Date: Fri, 13 Oct 2023 09:57:12 -0700 [thread overview]
Message-ID: <6fda3467-aa30-4eac-a258-63a4876e0c82@intel.com> (raw)
In-Reply-To: <169703589120.1202031.14696100866518083806.stgit@bgt-140510-bm03.eng.stellus.in>
On 10/11/23 07:51, Jim Harris wrote:
> Patch 5e42bcbc ("cxl/region: decrement ->nr_targets on error in
> cxl_region_attach()") tried to avoid 'eiw' initialization errors when
> ->nr_targets exceeded 16, by just decrementing ->nr_targets when
> cxl_region_setup_targets() failed. Patch 86987c76 ("cxl/region: Cleanup
> target list on attach error") extended that cleanup to also clear
> cxled->pos and p->targets[pos].
>
> The initialization error was incidentally fixed separately by patch
> 8d4285425 ("cxl/region: Fix port setup uninitialized variable warnings")
> which was merged a few days after 5e42bcbc.
>
> But now the original cleanup when cxl_region_setup_targets() fails
> prevents endpoint and switch decoder resources from being reused:
>
> 1) the cleanup does not set the decoder's region to NULL, which results
> in future dpa_size_store() calls returning -EBUSY
> 2) the decoder is not properly freed, which results in future commit
> errors associated with the upstream switch
>
> Now that the initialization errors were fixed separately, the proper
> cleanup for this case is to just return immediately. Then the resources
> associated with this target get cleanup up as normal when the failed
> region is deleted.
>
> The ->nr_targets decrement in the error case also helped prevent
> a p->targets[] array overflow, so add a new check to prevent against
> that overflow.
>
> Tested by trying to create an invalid region for a 2 switch * 2 endpoint
> topology, and then following up with creating a valid region.
>
> Signed-off-by: Jim Harris <jim.harris@samsung.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> drivers/cxl/core/region.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 6d63b8798c29..2b3b3c62d0a7 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -1658,6 +1658,12 @@ static int cxl_region_attach(struct cxl_region *cxlr,
> return -ENXIO;
> }
>
> + if (p->nr_targets >= p->interleave_ways) {
> + dev_dbg(&cxlr->dev, "region already has %d endpoints\n",
> + p->nr_targets);
> + return -EINVAL;
> + }
> +
> ep_port = cxled_to_port(cxled);
> root_port = cxlrd_to_port(cxlrd);
> dport = cxl_find_dport_by_dev(root_port, ep_port->host_bridge);
> @@ -1750,7 +1756,7 @@ static int cxl_region_attach(struct cxl_region *cxlr,
> if (p->nr_targets == p->interleave_ways) {
> rc = cxl_region_setup_targets(cxlr);
> if (rc)
> - goto err_decrement;
> + return rc;
> p->state = CXL_CONFIG_ACTIVE;
> }
>
> @@ -1762,12 +1768,6 @@ static int cxl_region_attach(struct cxl_region *cxlr,
> };
>
> return 0;
> -
> -err_decrement:
> - p->nr_targets--;
> - cxled->pos = -1;
> - p->targets[pos] = NULL;
> - return rc;
> }
>
> static int cxl_region_detach(struct cxl_endpoint_decoder *cxled)
>
next prev parent reply other threads:[~2023-10-13 16:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20231010183840uscas1p294532ae60e6014508efd897fef14fffd@uscas1p2.samsung.com>
2023-10-10 18:38 ` [PATCH] cxl/region: don't try to cleanup after cxl_region_setup_targets() fails Jim Harris
2023-10-11 14:04 ` Dan Carpenter
2023-10-11 14:31 ` Jim Harris
2023-10-11 14:51 ` [PATCH v2] " Jim Harris
2023-10-11 14:57 ` Dan Carpenter
2023-10-11 20:41 ` Jonathan Cameron
2023-10-13 16:57 ` Dave Jiang [this message]
2023-10-24 23:01 ` Dan Williams
2023-10-25 1:37 ` Jim Harris
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=6fda3467-aa30-4eac-a258-63a4876e0c82@intel.com \
--to=dave.jiang@intel.com \
--cc=dan.carpenter@linaro.org \
--cc=dan.j.williams@intel.com \
--cc=jim.harris@samsung.com \
--cc=linux-cxl@vger.kernel.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