From patchwork Wed Oct 11 14:51:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Harris X-Patchwork-Id: 13417536 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78E216AA4 for ; Wed, 11 Oct 2023 14:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="FTZ/JCRX" Received: from mailout2.w2.samsung.com (mailout2.w2.samsung.com [211.189.100.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20A8692 for ; Wed, 11 Oct 2023 07:51:34 -0700 (PDT) Received: from uscas1p1.samsung.com (unknown [182.198.245.206]) by mailout2.w2.samsung.com (KnoxPortal) with ESMTP id 20231011145132usoutp02cd29716b52278ffba92be745fe537b11~NFSc60hxv0629306293usoutp024; Wed, 11 Oct 2023 14:51:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w2.samsung.com 20231011145132usoutp02cd29716b52278ffba92be745fe537b11~NFSc60hxv0629306293usoutp024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1697035892; bh=n6PLo5y73SrWV/T9Hqq5wS+gs4mAFXjnG7ZU6PWUBWg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FTZ/JCRXzSOdEpcbIRVwxYRmcgDZgsZ2R47x/PJ2x7dJE78wpgGS2N9S7UbOSYIoa QZZmIrDb2mzskfw6EJR77AGoCnrDBsSrkjX1pUpYslsD4g9MkCyks6IxvHOJU2eK3U LOTaQHqRlsI5XQDwnw61gVRnuBsr09LCk5yp0xIo= Received: from ussmges2new.samsung.com (u111.gpu85.samsung.co.kr [203.254.195.111]) by uscas1p2.samsung.com (KnoxPortal) with ESMTP id 20231011145132uscas1p2ccca950254a592e62e5e82501d41faa3~NFScugkSq0590205902uscas1p2j; Wed, 11 Oct 2023 14:51:32 +0000 (GMT) Received: from uscas1p1.samsung.com ( [182.198.245.206]) by ussmges2new.samsung.com (USCPEMTA) with SMTP id 6C.5B.40279.476B6256; Wed, 11 Oct 2023 10:51:32 -0400 (EDT) Received: from ussmgxs2new.samsung.com (u91.gpu85.samsung.co.kr [203.254.195.91]) by uscas1p1.samsung.com (KnoxPortal) with ESMTP id 20231011145132uscas1p13e9fb6dadfa3d5b61fc410449122a013~NFSccoPrq2384123841uscas1p1_; Wed, 11 Oct 2023 14:51:32 +0000 (GMT) X-AuditID: cbfec36f-4cbfe70000009d57-f2-6526b6741948 Received: from SSI-EX1.ssi.samsung.com ( [105.128.2.146]) by ussmgxs2new.samsung.com (USCPEXMTA) with SMTP id 93.11.31200.476B6256; Wed, 11 Oct 2023 10:51:32 -0400 (EDT) Received: from SSI-EX2.ssi.samsung.com (105.128.2.227) by SSI-EX1.ssi.samsung.com (105.128.2.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.1.2375.24; Wed, 11 Oct 2023 07:51:31 -0700 Received: from SSI-EX2.ssi.samsung.com ([105.128.2.227]) by SSI-EX2.ssi.samsung.com ([105.128.2.227]) with mapi id 15.01.2375.024; Wed, 11 Oct 2023 07:51:31 -0700 From: Jim Harris To: "linux-cxl@vger.kernel.org" , "dan.carpenter@linaro.org" , "dan.j.williams@intel.com" Subject: [PATCH v2] cxl/region: don't try to cleanup after cxl_region_setup_targets() fails Thread-Topic: [PATCH v2] cxl/region: don't try to cleanup after cxl_region_setup_targets() fails Thread-Index: AQHZ/FJsHCzEUiok5USCGGYrUKwmDQ== Date: Wed, 11 Oct 2023 14:51:31 +0000 Message-ID: <169703589120.1202031.14696100866518083806.stgit@bgt-140510-bm03.eng.stellus.in> In-Reply-To: <169696311899.1171696.7812961484055097837.stgit@bgt-140510-bm03.eng.stellus.in> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [105.128.2.176] Content-ID: <00288EF0763F06439161218DB6C0CC56@ssi.samsung.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupileLIzCtJLcpLzFFi42LZduzrOd2SbWqpBp/my1t8mNfKbjF96gVG i/OzTrE4MHss3vOSyePOtT1sHp83yQUwR3HZpKTmZJalFunbJXBlvP38lq3glEzFl4mz2BsY 30h3MXJySAiYSLxv2cIMYgsJrGSUmNVm2sXIBWS3Mkl0rL3IBlN0dPNuNojEWkaJjrYvjBDO J0aJX1+PsEI4yxglLi89zA7SwiagKfHryhomkIQISMvt7mlgs4QFYiWenbwIViQikCTxfO4U NghbT6KxqRHsEBYBVYnra7czgti8AjES+7qWg9VwAtkblxwH62UUEJP4fgpkAScHs4C4xK0n 85kgbhWUWDR7DzOELSbxb9dDqB8UJe5/fwnUywFUrymxfpc+hGknsX0bP8QURYkp3Q/ZIbYK Spyc+YQFolNS4uCKGywgr0gILOSQ6H9xFirhIvH10yGotdISf+8ug7KzJVau72ACmS8hUCDR cCQIImwtsfDPeqiL+ST+/nrEOIFReRaSB2YhHDcL4bhZSI6bheS4BYysqxjFS4uLc9NTi43y Usv1ihNzi0vz0vWS83M3MQKTy+l/h/N3MF6/9VHvECMTB+MhRgkOZiUR3keZKqlCvCmJlVWp RfnxRaU5qcWHGKU5WJTEeQ1tTyYLCaQnlqRmp6YWpBbBZJk4OKUamEyW5q/XPqBspuFafeK3 mnKXhYDdAmcVRW0P3dlWynN7NIo4C84vEb6347Rj5f+pxlnhu0Tm5pXqmq39edpWb/FPdZmC juXaCuZ2yUceb75RFX5zJl/1k3eWU8oOFgac++CYo3hmbtr+qHTOD4F6rT38fHIxi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3nNkZls48uaFBo/Ks0nNR 5i7/lk1rf/c33P1ZsMo7suSQoq7gYofbe/J5pr67H79+C++t1rT1qfO+Fqevb3N+sX3TDO/D N3Zfyt/vlGp79d1r/6kFN4QCbQ4YhimxFGckGmoxFxUnAgBUjO3gLgMAAA== X-CMS-MailID: 20231011145132uscas1p13e9fb6dadfa3d5b61fc410449122a013 CMS-TYPE: 301P X-CMS-RootMailID: 20231011145132uscas1p13e9fb6dadfa3d5b61fc410449122a013 References: <169696311899.1171696.7812961484055097837.stgit@bgt-140510-bm03.eng.stellus.in> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 Acked-by: Dan Carpenter Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang --- 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)