All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Harris <jim.harris@samsung.com>
To: "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: [PATCH v2] cxl/region: don't try to cleanup after cxl_region_setup_targets() fails
Date: Wed, 11 Oct 2023 14:51:31 +0000	[thread overview]
Message-ID: <169703589120.1202031.14696100866518083806.stgit@bgt-140510-bm03.eng.stellus.in> (raw)
In-Reply-To: <169696311899.1171696.7812961484055097837.stgit@bgt-140510-bm03.eng.stellus.in>

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>
---
 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)


  parent reply	other threads:[~2023-10-11 14:51 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
     [not found]   ` <CGME20231011145132uscas1p13e9fb6dadfa3d5b61fc410449122a013@uscas1p1.samsung.com>
2023-10-11 14:51     ` Jim Harris [this message]
2023-10-11 14:57       ` [PATCH v2] " Dan Carpenter
2023-10-11 20:41       ` Jonathan Cameron
2023-10-13 16:57       ` Dave Jiang
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=169703589120.1202031.14696100866518083806.stgit@bgt-140510-bm03.eng.stellus.in \
    --to=jim.harris@samsung.com \
    --cc=dan.carpenter@linaro.org \
    --cc=dan.j.williams@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.