From nobody Tue Oct 7 01:58:29 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2084.outbound.protection.outlook.com [40.107.93.84]) (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 D6B522BEFE0; Tue, 15 Jul 2025 19:12:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606740; cv=fail; b=GAVM5L7oFd7nqRJtv3JEjSZ0lv6aS5/rHOhaomXIy2cjtbfM1xITgyz053b/UTJng12T0YCBTv99suxiZ54i5aNfTlBuZCMmO+HvY4cr6YhIAyh3UCwBz81+E+xYN3ZBKgg416NCLVQWvpbo5PmT1FxG9w0jj4Yvn+XdD+8Njx4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606740; c=relaxed/simple; bh=X1VZXt2XLYYfCHT5FVPV3Rvtz+gp9AO6cwmLQ1b3JEc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nB84mLDRR9/nZ4vVQkaxEojD0pCL5MWAchdQZv3g1lIrcjzJ9+JfOywGAA2nPNf3nZVK+Y36xgj28P2OV15HoTZ9k/42cIBVKX1fLDASvj7/U9c2T3D55NIRRgQBiQ0Rcjhqk/EbbsZZ/4FugFxvi0LoSqVeOPJ1hOwr6yyOk8I= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=QVZ66lj1; arc=fail smtp.client-ip=40.107.93.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="QVZ66lj1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=k+qKInttHswNO/0xPSZgrWKSPVfuF1gjnl4oC4eO7evL1E4kpu4Irlul/Ia9FM7fYztMuzzFRN5Xyg0nraRY9/UeW0WQjrGw8xBjxZ5Mmv1tG+gxjtTsNV+aU+QZ3kSehMc7xzjzGqw7rJ5pEjWtSrImZ2CFme+AIM8bI2MrHCWQjkr5tx9uKWaA01RNSacnfmCujTpbEnwQ3ZFz/+hR36cfgRidvonV9hWtj1ALeJiGhR6WVIZzC1dk1gpHVzogXvX7ZXTGKbwT9EvrQbQC6PyBhWJQuEuSrS/2Q0nEX5t41DO8WVW01+qnib9bNr3R0L2vFPfydiKQGxTVD0hR8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=obdbZ2nggGv32RMKCX0JcK8gukoePWqWBiHZk7BFGqk=; b=xC/xvtnYgEj4Pl+wgTBbXk444oUIQ/ZAxT2itZrNmaoM+v//l9WJfXx2G+VWbXyIS0w1tvKiWpTLfQOmA5jDG5AU5qfLMuw5XmM9hr0YinjgZ2/jSZMpZzG+Si/VtqzQZJNq+avAmP0NcULY2rnDxGqZ/29ml3kbPdesf8U7yfgJMi4UgnOdWJ2aDoBnhxkeG3ldrRCMeIE9gaaq6RTB4XYdoIjyQ2RkOfxU6t32FHOg84hulDsUSS3usNbQcrmABkPkhJzeaA9vEcK/NGDlfu+ABr/yJPAwGBjsNpan3ZXyPIhs39geOqoG+RCvrLiD0hYtbV/fTgvA4rrx6L7gLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=obdbZ2nggGv32RMKCX0JcK8gukoePWqWBiHZk7BFGqk=; b=QVZ66lj1AdivZx+9fIR2HU/koaSU1eRuWf0jE6c5jdBh3ON66Gd4dnb+Ds63nVE0SwhEHDqefWJGfC4V9ARUyXDThpkM+IQrMuQUJGAbfcBudovcSyycMIz3jl4eTRC5AgzcMNTKOxf8e31fBY3Qrho8y0Wvqu4si2+7G62JQMI= Received: from BL1PR13CA0204.namprd13.prod.outlook.com (2603:10b6:208:2be::29) by DS0PR12MB7728.namprd12.prod.outlook.com (2603:10b6:8:13a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.25; Tue, 15 Jul 2025 19:12:16 +0000 Received: from MN1PEPF0000F0E2.namprd04.prod.outlook.com (2603:10b6:208:2be:cafe::81) by BL1PR13CA0204.outlook.office365.com (2603:10b6:208:2be::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8943.17 via Frontend Transport; Tue, 15 Jul 2025 19:12:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E2.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:12:16 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:12:13 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 01/20] cxl/region: Move helper functions closer to their users Date: Tue, 15 Jul 2025 21:11:24 +0200 Message-ID: <20250715191143.1023512-2-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E2:EE_|DS0PR12MB7728:EE_ X-MS-Office365-Filtering-Correlation-Id: 189126a2-6169-4180-d699-08ddc3d38335 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?8VmzMQ8WSAS8qeNLz+KC/O4C4pImMqBUfGRg3q5XAibHwp2mSupX5om1AAiG?= =?us-ascii?Q?er9WAG0CIwPQCx82iMfH0aw97C9H2sW/YwSVWtC0+cvC6w4VnZ1MbraOWJTZ?= =?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XvYBMob3NUPrn/z8?= =?us-ascii?Q?bzrbLYMA058Q1go6jT7U4rzsfxx4C77t9evJYYrvpMrUnaGChwHW5ukovNqv?= =?us-ascii?Q?fWJsneiBw8aN39YUvh4cCOKuQB01mDf3sffQKlL09fxr8wG6PPh+Gnoxc3zJ?= =?us-ascii?Q?F9tjiZFjcsGz5fxqhEHsf741m0O+BFDiw+4QdnlQ/iBHG5Z8FTjzy/Ku+Giz?= =?us-ascii?Q?iOEd+4ukl3YeplTGddCKtlPTiqJ3XM0XmsEZSEEmlIV9QWE3h9SuF77k1tri?= =?us-ascii?Q?BR0idkB3jS13ae4LSCBZe8AZixOiMUGTR8msbT6Llu20xBZNGKdsSH0qOlV3?= =?us-ascii?Q?xYzmfXUR9duLgS5Q5WsYf9TQXt7rpKpHEDo6EJG7T5+U9ZSICkb5nkDYLQs7?= =?us-ascii?Q?mq6wYz5jrhr8Hxpz+h8vu0jiQxf/E/JjVcPZ03+rjGuPkgH6F65iyy3I5r30?= =?us-ascii?Q?3hcq7gUgTmpTeXjMwTuCrBRh46kzjjN89MzTCd0pfNmmWo+Oo1Cvq8Y7O3AL?= =?us-ascii?Q?UZJ3e1frGTouhETG+1NOIm4wOOC79yrHOvgE?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(36860700013)(376014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:12:16.2910 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 189126a2-6169-4180-d699-08ddc3d38335 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7728 Content-Type: text/plain; charset="utf-8" Just moving code around without any changes. Move helper functions closer to their users. This simplifies code and a rework and reduces the diffstat of follow-on patches. In particular, do the following: Place cxl_region_alloc() and unregister_region() before devm_cxl_add_region(). Have cxl_region_alloc() first as it is used in devm_cxl_add_region() first. Group match_region_by_range() and cxl_find_region_by_range() as both belong together. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 126 +++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 08ac7f483562..f22ad20b0db9 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2365,56 +2365,6 @@ static struct cxl_region *to_cxl_region(struct devic= e *dev) return container_of(dev, struct cxl_region, dev); } =20 -static void unregister_region(void *_cxlr) -{ - struct cxl_region *cxlr =3D _cxlr; - struct cxl_region_params *p =3D &cxlr->params; - int i; - - device_del(&cxlr->dev); - - /* - * Now that region sysfs is shutdown, the parameter block is now - * read-only, so no need to hold the region rwsem to access the - * region parameters. - */ - for (i =3D 0; i < p->interleave_ways; i++) - detach_target(cxlr, i); - - cxl_region_iomem_release(cxlr); - put_device(&cxlr->dev); -} - -static struct lock_class_key cxl_region_key; - -static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd,= int id) -{ - struct cxl_region *cxlr; - struct device *dev; - - cxlr =3D kzalloc(sizeof(*cxlr), GFP_KERNEL); - if (!cxlr) { - memregion_free(id); - return ERR_PTR(-ENOMEM); - } - - dev =3D &cxlr->dev; - device_initialize(dev); - lockdep_set_class(&dev->mutex, &cxl_region_key); - dev->parent =3D &cxlrd->cxlsd.cxld.dev; - /* - * Keep root decoder pinned through cxl_region_release to fixup - * region id allocations - */ - get_device(dev->parent); - device_set_pm_not_required(dev); - dev->bus =3D &cxl_bus_type; - dev->type =3D &cxl_region_type; - cxlr->id =3D id; - - return cxlr; -} - static bool cxl_region_update_coordinates(struct cxl_region *cxlr, int nid) { int cset =3D 0; @@ -2498,6 +2448,56 @@ static int cxl_region_calculate_adistance(struct not= ifier_block *nb, return NOTIFY_STOP; } =20 +static struct lock_class_key cxl_region_key; + +static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd,= int id) +{ + struct cxl_region *cxlr; + struct device *dev; + + cxlr =3D kzalloc(sizeof(*cxlr), GFP_KERNEL); + if (!cxlr) { + memregion_free(id); + return ERR_PTR(-ENOMEM); + } + + dev =3D &cxlr->dev; + device_initialize(dev); + lockdep_set_class(&dev->mutex, &cxl_region_key); + dev->parent =3D &cxlrd->cxlsd.cxld.dev; + /* + * Keep root decoder pinned through cxl_region_release to fixup + * region id allocations + */ + get_device(dev->parent); + device_set_pm_not_required(dev); + dev->bus =3D &cxl_bus_type; + dev->type =3D &cxl_region_type; + cxlr->id =3D id; + + return cxlr; +} + +static void unregister_region(void *_cxlr) +{ + struct cxl_region *cxlr =3D _cxlr; + struct cxl_region_params *p =3D &cxlr->params; + int i; + + device_del(&cxlr->dev); + + /* + * Now that region sysfs is shutdown, the parameter block is now + * read-only, so no need to hold the region rwsem to access the + * region parameters. + */ + for (i =3D 0; i < p->interleave_ways; i++) + detach_target(cxlr, i); + + cxl_region_iomem_release(cxlr); + put_device(&cxlr->dev); +} + /** * devm_cxl_add_region - Adds a region to a decoder * @cxlrd: root decoder @@ -3277,6 +3277,19 @@ static int match_region_by_range(struct device *dev,= const void *data) return 0; } =20 +static struct cxl_region * +cxl_find_region_by_range(struct cxl_root_decoder *cxlrd, struct range *hpa) +{ + struct device *region_dev; + + region_dev =3D device_find_child(&cxlrd->cxlsd.cxld.dev, hpa, + match_region_by_range); + if (!region_dev) + return NULL; + + return to_cxl_region(region_dev); +} + static int cxl_extended_linear_cache_resize(struct cxl_region *cxlr, struct resource *res) { @@ -3419,19 +3432,6 @@ static struct cxl_region *construct_region(struct cx= l_root_decoder *cxlrd, return cxlr; } =20 -static struct cxl_region * -cxl_find_region_by_range(struct cxl_root_decoder *cxlrd, struct range *hpa) -{ - struct device *region_dev; - - region_dev =3D device_find_child(&cxlrd->cxlsd.cxld.dev, hpa, - match_region_by_range); - if (!region_dev) - return NULL; - - return to_cxl_region(region_dev); -} - int cxl_add_to_region(struct cxl_endpoint_decoder *cxled) { struct range *hpa =3D &cxled->cxld.hpa_range; --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2050.outbound.protection.outlook.com [40.107.243.50]) (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 B197D2C033C; Tue, 15 Jul 2025 19:12:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606745; cv=fail; b=Tcv5TVFZEdDgNo06G2WJYHI1UeQx523/kOSjQMdGs1uhXEOr9Tnwyvd+QTjq4ZKOHVmEuFfe2b4juizFnqNiAPIydspUtI6yYaf52oMyOI6Jmkv7Vlnu47FQcdtigSwAsN3EGrOjKHK0u6DCbrp3GTKIA77sodIKX/FNBMUeTnc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606745; c=relaxed/simple; bh=ejHY0fkm+wbijd5VaRpiTXNwJgv6hb46AkMRP8SUVp4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R6Zz/5tHmlDYMNKcVyTRploOqoQoRArd+M67K2hy3vi6XGjidf12AtzCcycgAyscfc49j3JLQFtT3g6m4j2FrBykrkypvoMhEOi2q/ahRzwux3hWWywa6zqLXfVFGo9TXWO08RMk791bTUigZlW/dXmrElkFjg8mnNd+EShJ6Js= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=fTmQX4W8; arc=fail smtp.client-ip=40.107.243.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="fTmQX4W8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NN8KHUh0B9BTtzBgxjOxkMxY2+SrKHtj5Sr3AeLHMRBavMy2YKbRerUUr//RBXspGa0lHHBK7BQbh7fRrNmGDTXRvKkTFNP1FdvKEqhncI0pDINGIpRAO19ekjs5g9F6kh5n3XiqVCIiVQJqYzJAtD1fKGlVHWbpwY799eNRaM39i88vFeEVbHC5GYSYPLv7ZDV54vIa0RBLsyWnNLqBf7VTeZka5PI0W+YM+z1exQqVzk69SJhA2Emqdxhir5eIszfsEpVk9TL7BmGcyHU/JHtoxs1foDSYRyE6NW4mD8KEC5qrhtdPadL5dhzXElzsZmGTHsb9JSfu+2RgADlD4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7m83iI6fl3+GwB0FSLDg5iv/NED2RUacVj32MwYPAR8=; b=tu5gVyMW1lmbuHn3vM089xctIqHpYZf68uY/ZzvF99lqmycMW2z223H9Y0MvWyIXhc3J2RwKJRfl3ec8Yt8dnOrN6VQcbd+LCJMjiwIs8vjh8rrABkV14gCmT+QaocB0jtlRmZl4cAjNipcXMVklBWlJv6lOeAGqcQ6lFRFVmJrD2ZkOMg9YceC1VKhrAzF0zgOjZB3sXcKFxeK0g07S9pUZFK/lgp8er4JQGEkVa+X6LGnyPk2rW8b6a2Z/V9BU2jsdF0W88O/m8btxOJpfkRN1eW1v+h4JMcFIntumhxNm8hzoG0Rl5xgpcYED8eygXkWTbISmWa5ucZFCIdvHcw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7m83iI6fl3+GwB0FSLDg5iv/NED2RUacVj32MwYPAR8=; b=fTmQX4W85laa2vdfzLBN1IAlnzZoOUu/8SzklvhtRrkffHh/BZG0s2gtq/F09ajGPyegUZHj1LfTgH+uFjETqxw5S8053QU302AzLkZuTasU33dS6j4N/PcCt5gqXSMvVeD06+ziC3PIcAz6E+nzUWcwAksPfcUoXF2kZDOSl+4= Received: from BN8PR15CA0037.namprd15.prod.outlook.com (2603:10b6:408:80::14) by SJ5PPF0AEDE5C3D.namprd12.prod.outlook.com (2603:10b6:a0f:fc02::989) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.26; Tue, 15 Jul 2025 19:12:21 +0000 Received: from MN1PEPF0000F0E5.namprd04.prod.outlook.com (2603:10b6:408:80:cafe::2) by BN8PR15CA0037.outlook.office365.com (2603:10b6:408:80::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8943.19 via Frontend Transport; Tue, 15 Jul 2025 19:12:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E5.mail.protection.outlook.com (10.167.242.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:12:20 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:12:17 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 02/20] cxl/region: Store root decoder in struct cxl_region Date: Tue, 15 Jul 2025 21:11:25 +0200 Message-ID: <20250715191143.1023512-3-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E5:EE_|SJ5PPF0AEDE5C3D:EE_ X-MS-Office365-Filtering-Correlation-Id: fdd2e6b4-76ee-477d-ed41-08ddc3d385b4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?dy6cU2cRuGe+QXJIN1+6AOZEQA8fF/oRNK81omiDLWqglZXLHeuM8ENuTSp7?= =?us-ascii?Q?X9TLs9L2fGW7AJS/f4c6aj6U4638omS7LzC0vYiqy3H5o8loQnY/KXigHckC?= =?us-ascii?Q?9XpPz4WOjScZECMdzx8LYIGVVibvIcGcIi6Ffamccf1jiTnyHqq411LxO52C?= =?us-ascii?Q?YietKWIiTyB4WXMbEx+1iaxCMG7TrtTzsOxhsTsG047ILSgugobnPC4kPr8Y?= =?us-ascii?Q?LNtlBf/nH+SzjPSuL/uS4wq76uEgTlABYGrATB3kzC2yS4OepJDKCPmV/KRQ?= =?us-ascii?Q?XoRSKNKfCVOJh9KR0Lh2b9dWu6KMm6MW8PDw1IWDFu9St/P7TxKnmxT6QtaT?= =?us-ascii?Q?mMBQUTl8ARpSlESX3co78xSBA9RmUOo24vI7eH7AihjhIGPzG9sqyxcxi2PI?= =?us-ascii?Q?Nd2RQg+zPskKcUYxpQuWucGnykGMDCFBnLSLkDqWmyrWjXXFTASrZnBGmty0?= =?us-ascii?Q?Jhu/6Sao9CcJSLiQ5R2qqqlrudDRsw+S/AHwg2ITpYh7Xa+GjtY0UrTUBdm2?= =?us-ascii?Q?ZBtImKKQWd4M6N1n0qMub9eBGbiKkTnpW8fIaQELcNEx5y7tbPCh44LPG7Ur?= =?us-ascii?Q?KjBP/qaC7VFOl/YolEwwfIrBMYWXvmc4G+qcA0BlL3G1pR1jCpSYnFrHaLtF?= =?us-ascii?Q?L0yXUOl0sgKbwUZveenGiR//GSJFUxRqKH3im1DJHH1xsqbc+r3qZuvT/YYr?= =?us-ascii?Q?l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EXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(1800799024)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:12:20.4794 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fdd2e6b4-76ee-477d-ed41-08ddc3d385b4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E5.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ5PPF0AEDE5C3D Content-Type: text/plain; charset="utf-8" A region is always bound to a root decoder. The region's associated root decoder is often needed. Add it to struct cxl_region. This simpifies code by removing dynamic lookups and removing the root decoder argument from the function argument list where possible. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 33 +++++++++++++++++---------------- drivers/cxl/cxl.h | 2 ++ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index f22ad20b0db9..a18ab5e30138 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -467,9 +467,9 @@ static ssize_t interleave_ways_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { - struct cxl_root_decoder *cxlrd =3D to_cxl_root_decoder(dev->parent); - struct cxl_decoder *cxld =3D &cxlrd->cxlsd.cxld; struct cxl_region *cxlr =3D to_cxl_region(dev); + struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; + struct cxl_decoder *cxld =3D &cxlrd->cxlsd.cxld; struct cxl_region_params *p =3D &cxlr->params; unsigned int val, save; int rc; @@ -535,9 +535,9 @@ static ssize_t interleave_granularity_store(struct devi= ce *dev, struct device_attribute *attr, const char *buf, size_t len) { - struct cxl_root_decoder *cxlrd =3D to_cxl_root_decoder(dev->parent); - struct cxl_decoder *cxld =3D &cxlrd->cxlsd.cxld; struct cxl_region *cxlr =3D to_cxl_region(dev); + struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; + struct cxl_decoder *cxld =3D &cxlrd->cxlsd.cxld; struct cxl_region_params *p =3D &cxlr->params; int rc, val; u16 ig; @@ -617,7 +617,7 @@ static DEVICE_ATTR_RO(mode); =20 static int alloc_hpa(struct cxl_region *cxlr, resource_size_t size) { - struct cxl_root_decoder *cxlrd =3D to_cxl_root_decoder(cxlr->dev.parent); + struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; struct cxl_region_params *p =3D &cxlr->params; struct resource *res; u64 remainder =3D 0; @@ -1320,7 +1320,7 @@ static int cxl_port_setup_targets(struct cxl_port *po= rt, struct cxl_region *cxlr, struct cxl_endpoint_decoder *cxled) { - struct cxl_root_decoder *cxlrd =3D to_cxl_root_decoder(cxlr->dev.parent); + struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; int parent_iw, parent_ig, ig, iw, rc, inc =3D 0, pos =3D cxled->pos; struct cxl_port *parent_port =3D to_cxl_port(port->dev.parent); struct cxl_region_ref *cxl_rr =3D cxl_rr_load(port, cxlr); @@ -1679,10 +1679,10 @@ static int cxl_region_validate_position(struct cxl_= region *cxlr, } =20 static int cxl_region_attach_position(struct cxl_region *cxlr, - struct cxl_root_decoder *cxlrd, struct cxl_endpoint_decoder *cxled, const struct cxl_dport *dport, int pos) { + struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); struct cxl_switch_decoder *cxlsd =3D &cxlrd->cxlsd; struct cxl_decoder *cxld =3D &cxlsd->cxld; @@ -1919,7 +1919,7 @@ static int cxl_region_sort_targets(struct cxl_region = *cxlr) static int cxl_region_attach(struct cxl_region *cxlr, struct cxl_endpoint_decoder *cxled, int pos) { - struct cxl_root_decoder *cxlrd =3D to_cxl_root_decoder(cxlr->dev.parent); + struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); struct cxl_dev_state *cxlds =3D cxlmd->cxlds; struct cxl_region_params *p =3D &cxlr->params; @@ -2024,8 +2024,7 @@ static int cxl_region_attach(struct cxl_region *cxlr, ep_port =3D cxled_to_port(cxled); dport =3D cxl_find_dport_by_dev(root_port, ep_port->host_bridge); - rc =3D cxl_region_attach_position(cxlr, cxlrd, cxled, - dport, i); + rc =3D cxl_region_attach_position(cxlr, cxled, dport, i); if (rc) return rc; } @@ -2048,7 +2047,7 @@ static int cxl_region_attach(struct cxl_region *cxlr, if (rc) return rc; =20 - rc =3D cxl_region_attach_position(cxlr, cxlrd, cxled, dport, pos); + rc =3D cxl_region_attach_position(cxlr, cxled, dport, pos); if (rc) return rc; =20 @@ -2323,8 +2322,8 @@ static const struct attribute_group *region_groups[] = =3D { =20 static void cxl_region_release(struct device *dev) { - struct cxl_root_decoder *cxlrd =3D to_cxl_root_decoder(dev->parent); struct cxl_region *cxlr =3D to_cxl_region(dev); + struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; int id =3D atomic_read(&cxlrd->region_id); =20 /* @@ -2470,6 +2469,8 @@ static struct cxl_region *cxl_region_alloc(struct cxl= _root_decoder *cxlrd, int i * region id allocations */ get_device(dev->parent); + cxlr->cxlrd =3D cxlrd; + device_set_pm_not_required(dev); dev->bus =3D &cxl_bus_type; dev->type =3D &cxl_region_type; @@ -2905,7 +2906,7 @@ static bool cxl_is_hpa_in_chunk(u64 hpa, struct cxl_r= egion *cxlr, int pos) u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd, u64 dpa) { - struct cxl_root_decoder *cxlrd =3D to_cxl_root_decoder(cxlr->dev.parent); + struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; u64 dpa_offset, hpa_offset, bits_upper, mask_upper, hpa; struct cxl_region_params *p =3D &cxlr->params; struct cxl_endpoint_decoder *cxled =3D NULL; @@ -3293,7 +3294,7 @@ cxl_find_region_by_range(struct cxl_root_decoder *cxl= rd, struct range *hpa) static int cxl_extended_linear_cache_resize(struct cxl_region *cxlr, struct resource *res) { - struct cxl_root_decoder *cxlrd =3D to_cxl_root_decoder(cxlr->dev.parent); + struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; struct cxl_region_params *p =3D &cxlr->params; resource_size_t size =3D resource_size(res); resource_size_t cache_size, start; @@ -3329,9 +3330,9 @@ static int cxl_extended_linear_cache_resize(struct cx= l_region *cxlr, } =20 static int __construct_region(struct cxl_region *cxlr, - struct cxl_root_decoder *cxlrd, struct cxl_endpoint_decoder *cxled) { + struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); struct range *hpa =3D &cxled->cxld.hpa_range; struct cxl_region_params *p; @@ -3423,7 +3424,7 @@ static struct cxl_region *construct_region(struct cxl= _root_decoder *cxlrd, return cxlr; } =20 - rc =3D __construct_region(cxlr, cxlrd, cxled); + rc =3D __construct_region(cxlr, cxled); if (rc) { devm_release_action(port->uport_dev, unregister_region, cxlr); return ERR_PTR(rc); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 0730f92df038..58c9db0bfb93 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -508,6 +508,7 @@ enum cxl_partition_mode { * struct cxl_region - CXL region * @dev: This region's device * @id: This region's id. Id is globally unique across all regions + * @cxlrd: Region's root decoder * @mode: Operational mode of the mapped capacity * @type: Endpoint decoder target type * @cxl_nvb: nvdimm bridge for coordinating @cxlr_pmem setup / shutdown @@ -521,6 +522,7 @@ enum cxl_partition_mode { struct cxl_region { struct device dev; int id; + struct cxl_root_decoder *cxlrd; enum cxl_partition_mode mode; enum cxl_decoder_type type; struct cxl_nvdimm_bridge *cxl_nvb; --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2066.outbound.protection.outlook.com [40.107.100.66]) (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 963CA2BDC26; Tue, 15 Jul 2025 19:12:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606752; cv=fail; b=sywdDp+7iF91nMHdK85Ny1aCP6+DbHMZmWbectHV9mKshwXObRrSnRwEmOlO9EqVZ0JcmJyrkAPpbpjWy0EbT8Vjsgx0BhWI+LUhZAy4geqMCap1FqYkydOPtF0BkWjlSUZqdWwB14KVgF7PPKN/fwhboYHDULtcl+NAWlokmNw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606752; c=relaxed/simple; bh=CeYtmnUlMbpDqENrRvZOGfm0mI284O3dKdSZNCquw1M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QH0ahCDwoGOpOZyRsHDYIeY22q6b9yO77hsA4nk1xkL0LST1mWveReew9oPT/e4vZtvWLAid46kutxJtOQ6DyF4PHD6/rJVJ0X101ymdPm5A38NdBe+AcgYx1ZMXjuhTKN/F9x8kYzxRGqd0WEYW25exJsA+FrOqy1jdL5BArgw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=NDhLloxV; arc=fail smtp.client-ip=40.107.100.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="NDhLloxV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=C/z2WLg/MPqzTacFIuaKa3oB97c9Y1RCeQNc8LaR3VTeMnID3RaNJtFrbgDWkSNzQ4v4yMtMFFQVYDDyqPKeXUqbqZpol6FQVi7gE/5eyPOKG6x6Qzl0N4gAX2qRgjEhOPeqDP8V8YEOZgPk6kMa3u13MbtiAGY0Ww82crWI83wywhTOWfJ3XxbP6LYHdMyk9L+o5SoUcSPgBjrTSWTbonzYev63rbPkPDH5kz/cjMQBKLiWPBfWReD0Yxy3GYoIWDiZLC67GI+Br6RYdTjCsgJ1s6HFF0SLiB0y52YQ7EhQqFkrUB2hoIR0CM76LkyKW/YEni5dV60b4+CCiz3xYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oX/zHQGaOX8IFzAw90vyuQa3/aY4GWAgfDg+7V1Wtn0=; b=flUcOIGUY1p1rrUxyBXOdkRA1tfZ/1JTtdkz8JRI8idcV2fNkRNiY9d6OL3Bar/ioK/OOlP+8tD13SchwmHQ+kOHeqFbhzFz+WFFAjxmiXE4OgeOoVKWlJ8LTlOuUchpn0GR3kYKwiR0xcoOSuPhkaP0mIb2qsu/xhXahb8wiJeKX9vdFFvG7kAoXwdXHXMmrDfZvYwtZ6AHFZVPv+NvKhedVQCZk8GZ45gUKdEEs2wW1sY6Jb1qO0VcfPGBC8bUA09hzyUT5NiCJji4Fz7EBWmrawmk4TPo3pW40nv/tWSp+IHE8OIYviHBr4NPqyKXZs6tCqkJu3D60wvrBCpygQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=temperror (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=temperror action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oX/zHQGaOX8IFzAw90vyuQa3/aY4GWAgfDg+7V1Wtn0=; b=NDhLloxVkbSCjAx/b9HQ356yfM3wwWrQt1KAG5Wd8q31oj0lnKxQAfpDM96Ut9k7iFBw0OnDdIS3SSJdEOX4WxPBeX45CZYF35WdgrNgC5d6TBhgf/F41ha28d5IlQf9jcJvRkFyBcHBRLEzmZGqQzaz2xB6dbD4Yz6C3VKk2Tk= Received: from BN9PR03CA0317.namprd03.prod.outlook.com (2603:10b6:408:112::22) by CYXPR12MB9280.namprd12.prod.outlook.com (2603:10b6:930:e4::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8922.27; Tue, 15 Jul 2025 19:12:25 +0000 Received: from MN1PEPF0000F0E3.namprd04.prod.outlook.com (2603:10b6:408:112:cafe::cc) by BN9PR03CA0317.outlook.office365.com (2603:10b6:408:112::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.33 via Frontend Transport; Tue, 15 Jul 2025 19:12:25 +0000 X-MS-Exchange-Authentication-Results: spf=temperror (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=temperror action=none header.from=amd.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of amd.com: DNS Timeout) Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E3.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:12:23 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:12:20 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 03/20] cxl/region: Remove region id handling from cxl_region_alloc() Date: Tue, 15 Jul 2025 21:11:26 +0200 Message-ID: <20250715191143.1023512-4-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E3:EE_|CYXPR12MB9280:EE_ X-MS-Office365-Filtering-Correlation-Id: 66d696f9-a833-49bd-f21a-08ddc3d387bc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?K232a0Ky1fO6E6XmKUyyforGRYgnZNkTnJaFNpB877P4hBSa6gHUtdaboi+g?= =?us-ascii?Q?bAfZxDs9K6glj87UZOMqPFvVrJo9rdzZmvnB/nbNxG2xS3/YPBbE7mMLRoMs?= =?us-ascii?Q?Kmf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mco43PoZR2g?= =?us-ascii?Q?1isICiEykNvVCoOZU1TTd/nh9bWCM3hTnYQpTy5+vdKpJcljRA0eqrfaY8RT?= =?us-ascii?Q?Vcz+NxOJKHJ9ZjL1Af7Rm4hpvH2Nn/QNeBP/UTFKYldaFa7zqGxp1s3FvlFF?= =?us-ascii?Q?mJ6QRPd8qRToPahJuof8PdiiLm0X1NLigiGPGiP3HAR1Hycf0Xbl11yToLjB?= =?us-ascii?Q?a2lWbPajG8llCLa5DpXOawlegwmPat8MR0I8wU5rTMcdMiT8xhWBygHBD82K?= =?us-ascii?Q?PA3I1nJd7bHEhFPDjnOYWhPF+rlM8e5k9uJwslv8CV9/UOuWpD5j8ccNFySY?= =?us-ascii?Q?4PgIc8oLkNfEanMHEeCaqLMSYPcNhZS5UUKUkm6h8cbVQg0WlhSYld5OzHul?= =?us-ascii?Q?8us23PhC1+xyKTyDuFmz9uts1aM30EQKHiuac+OCCZC4X2Uvd1Zn3OVjCyzv?= =?us-ascii?Q?M/TyHtihEawMhr6+ryOeg8UCkyhIWaMGCzdvUGqhwQG/n4yxPnvoAI/gwnJE?= =?us-ascii?Q?jiXUsyclJUAy52aIkHJ0SzIemQXU09XAGqnI?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(36860700013)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:12:23.8855 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 66d696f9-a833-49bd-f21a-08ddc3d387bc X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E3.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYXPR12MB9280 Content-Type: text/plain; charset="utf-8" The region's id is not needed to allocate the region. Move the region id handling out of cxl_region_alloc(). This simplifies the function interface and allows the implementation of an early region allocation when an id is not yet assigned. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index a18ab5e30138..b968050ad3d7 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2449,16 +2449,14 @@ static int cxl_region_calculate_adistance(struct no= tifier_block *nb, =20 static struct lock_class_key cxl_region_key; =20 -static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd,= int id) +static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd) { struct cxl_region *cxlr; struct device *dev; =20 cxlr =3D kzalloc(sizeof(*cxlr), GFP_KERNEL); - if (!cxlr) { - memregion_free(id); + if (!cxlr) return ERR_PTR(-ENOMEM); - } =20 dev =3D &cxlr->dev; device_initialize(dev); @@ -2474,7 +2472,6 @@ static struct cxl_region *cxl_region_alloc(struct cxl= _root_decoder *cxlrd, int i device_set_pm_not_required(dev); dev->bus =3D &cxl_bus_type; dev->type =3D &cxl_region_type; - cxlr->id =3D id; =20 return cxlr; } @@ -2522,13 +2519,18 @@ static struct cxl_region *devm_cxl_add_region(struc= t cxl_root_decoder *cxlrd, struct device *dev; int rc; =20 - cxlr =3D cxl_region_alloc(cxlrd, id); - if (IS_ERR(cxlr)) + cxlr =3D cxl_region_alloc(cxlrd); + if (IS_ERR(cxlr)) { + memregion_free(id); return cxlr; + } + cxlr->mode =3D mode; cxlr->type =3D type; =20 dev =3D &cxlr->dev; + cxlr->id =3D id; + rc =3D dev_set_name(dev, "region%d", id); if (rc) goto err; --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2082.outbound.protection.outlook.com [40.107.220.82]) (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 E725F2C033C; Tue, 15 Jul 2025 19:12:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606752; cv=fail; b=XApdKBweRLRPc1UOX8speDpYDrMhwm/AFAzZUkqgyWxSGQtdxBqbbUhUJFgLq1faOQezjRrnNN99xftA9yBJd33SOij/gN9RaITQP01XydMI38u4RUplRn6dYmaITUoMa34Q3/K/QfdH+56PlvfatIlczFA+CLUSLf7OX9hWPko= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606752; c=relaxed/simple; bh=KnSDYoRsx/kYW84iZ+pr87WT0nABJmWv1udbmEw3zfo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jnON8+wHSvbpi3nomiMDPdWGWQ/Adt7ok0NUzsQMFny4YDUd+5KIbtYntbdJzK8yv3b1W5SWo38dn54BAaW91LW/D+15cXJhTSFsjypsuL7lzFkogBiRfCosRG/RX1ufiWru4kyI6gSwUvyjw/LiwT6LdykpX/i+CbLzx1fVqZg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=5dKwcXkT; arc=fail smtp.client-ip=40.107.220.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="5dKwcXkT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Idm0IkzfYKA9TV7p9ZXN/NlJ2IxLBe/CG2NF6A/sVVRjejAXctb7IVOy7dXRPmP9u7fZI8OdEyaay/buB7AHXXWxbRna70T5Mg0OkDiuTQXeV6Wbj+wtJRCWh9emFqYmRB4u89OuP9Q6IrqJyxfYvIMxEEMLLE3eUEA32Jrg6MSBBPpglRow8Vj+pykkAEZPx7Np7XtThUEbOXYaNg+IiHrhCGfIy8cHwEn+r+Rkx+rHR6LfVWWPFjT/jqgZAARXyG9p4qljjn0vvfT6SUdI+VfTdXXFnIiFnTNpN45voNuKTPYhrB0CAvaruBw2FkSrbXw8+OYruaCDF3/EC9OYPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=E8qHLuVPCC0yF2XZxAr/H7oKMAeY7Acs70I9Os36jfA=; b=CVVRIztdPbyyOFxV3EDfsING4Vm0fhVaxF4WYEyDDo5I44JPep7lIyKBKqxYkIgTrWRYqzuIidB5ZyttiEU5wN4arz1YDk8yjAYXbaJOB5RrH3NQa/kuSFNLi1zFB04YQOdKIWNCdg//oOk+2hsT8BX8fMhT43pJTZqLqqeXEg0aeIp8mn1NUrWneO7cLY+GjR3QVtDsBhB/fHcAbJzyDupyGvzFLAQK2Ut3+siHHkMSynTZZ3CTEr7vhp9yATpePMU1m/H960emdGC1m+YPAQA5BCl3pPjpZLqanNPOvYehZtROqchn01YnW6yGcT9jrdU2Y6/W2lMyvzpDvfNQ9A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E8qHLuVPCC0yF2XZxAr/H7oKMAeY7Acs70I9Os36jfA=; b=5dKwcXkTs8BTIHMPZNfzigRbv21XTFWSmPdRxf1LlPXxfuQ/1IFIw8Zdqs2kcfDqpDJv+TzQXmjpA62uZ51tiyC6yOuuM7urkGvtUpO559922o7GDauFD9ORSExtyIgmKyNHDel/HVVxDbLR42lQxqpP1FecstJgjLIqgcWHeZ0= Received: from BN9PR03CA0323.namprd03.prod.outlook.com (2603:10b6:408:112::28) by CY1PR12MB9582.namprd12.prod.outlook.com (2603:10b6:930:fe::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8922.32; Tue, 15 Jul 2025 19:12:28 +0000 Received: from MN1PEPF0000F0E3.namprd04.prod.outlook.com (2603:10b6:408:112:cafe::44) by BN9PR03CA0323.outlook.office365.com (2603:10b6:408:112::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8943.19 via Frontend Transport; Tue, 15 Jul 2025 19:12:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E3.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:12:27 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:12:24 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 04/20] cxl/region: Add region registration code to new function register_region() Date: Tue, 15 Jul 2025 21:11:27 +0200 Message-ID: <20250715191143.1023512-5-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E3:EE_|CY1PR12MB9582:EE_ X-MS-Office365-Filtering-Correlation-Id: 41b4de4f-ecda-4920-b898-08ddc3d38a16 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|7416014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?pm4IXbmCzMtpOBLrPf5RqTmxnIrPoA2pvujh43MAcDXPFTECxG9td1CR5SCt?= =?us-ascii?Q?BmhqDsQd0sM6IKamNokkzf3x1wfsnnfyR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0iNdZvkyt0IoonBWL2Y6QzyHZOKeO+7gSqtexcDESW1V2VdU?= =?us-ascii?Q?ijH9sB0rh0dNay63BAVd7ipLRWR3M4yBVO5cBvVOMNHJojXggDb6gJ4I/K1O?= =?us-ascii?Q?tckdLyDhni8iRnHBC+NOxHBDMTeYm+ekx0yw/5UlRLmrjnM+wP/zAyiswTU9?= =?us-ascii?Q?vMdZWXKtw9FgwoNQrDdvkjPT8B+WGV7A60vfAKk5xZKp0F5lXlAijMD1Nym+?= =?us-ascii?Q?tKg9ccZSSfEkCz+xQu/vzN+sfVkxhwG25kg7EQoGEo8fUhd59m2bNn0upXfv?= =?us-ascii?Q?YuS6EDor8lDktmRrquyNmvXVerx+d9YDmS/QKbCYHoxyxTTOwO0X+NyoRgic?= =?us-ascii?Q?oQiD3z4OyJS5snDu1Ix6FnvbL8jRYL5dKbX1Q1B7TP+r8VGw5SVVKFQR2Nb2?= =?us-ascii?Q?CLGLdxcjNbpyJ7LRIQELHkUkK3NvxzxO2No4vK5hrIFsob62JNFhjGTbRJDr?= =?us-ascii?Q?pKIu39eOJDtLyupmNVeCywDiz2drvEXNssfkc0zf3mjAZvcW8GZz8+x/fxYj?= =?us-ascii?Q?oF0+rsD9xpbI5QkCJCt7j/5PqgGf+oxZV/tq?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(376014)(7416014)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:12:27.8279 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 41b4de4f-ecda-4920-b898-08ddc3d38a16 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E3.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB9582 Content-Type: text/plain; charset="utf-8" Separate code to register a region from its creation. This splits the region setup into a creation and registration part. This helps grouping the code, adds a counterpart to unregister_region() and esp. simplifies the error handling paths as there is a single exit for a put_device() on errors. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 66 +++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index b968050ad3d7..8e2521c6c845 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2326,6 +2326,9 @@ static void cxl_region_release(struct device *dev) struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; int id =3D atomic_read(&cxlrd->region_id); =20 + if (cxlr->id < 0) + goto out; + /* * Try to reuse the recently idled id rather than the cached * next id to prevent the region id space from increasing @@ -2468,6 +2471,7 @@ static struct cxl_region *cxl_region_alloc(struct cxl= _root_decoder *cxlrd) */ get_device(dev->parent); cxlr->cxlrd =3D cxlrd; + cxlr->id =3D -1; =20 device_set_pm_not_required(dev); dev->bus =3D &cxl_bus_type; @@ -2496,6 +2500,30 @@ static void unregister_region(void *_cxlr) put_device(&cxlr->dev); } =20 +static int register_region(struct cxl_region *cxlr, int id) +{ + struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; + struct device *dev =3D &cxlr->dev; + int rc; + + rc =3D memregion_alloc(GFP_KERNEL); + if (rc < 0) + return rc; + + if (atomic_cmpxchg(&cxlrd->region_id, id, rc) !=3D id) { + memregion_free(rc); + return -EBUSY; + } + + cxlr->id =3D id; + + rc =3D dev_set_name(dev, "region%d", cxlr->id); + if (rc) + return rc; + + return device_add(dev); +} + /** * devm_cxl_add_region - Adds a region to a decoder * @cxlrd: root decoder @@ -2516,40 +2544,29 @@ static struct cxl_region *devm_cxl_add_region(struc= t cxl_root_decoder *cxlrd, { struct cxl_port *port =3D to_cxl_port(cxlrd->cxlsd.cxld.dev.parent); struct cxl_region *cxlr; - struct device *dev; int rc; =20 cxlr =3D cxl_region_alloc(cxlrd); - if (IS_ERR(cxlr)) { - memregion_free(id); + if (IS_ERR(cxlr)) return cxlr; - } =20 cxlr->mode =3D mode; cxlr->type =3D type; =20 - dev =3D &cxlr->dev; - cxlr->id =3D id; - - rc =3D dev_set_name(dev, "region%d", id); - if (rc) - goto err; - - rc =3D device_add(dev); - if (rc) - goto err; + rc =3D register_region(cxlr, id); + if (rc) { + put_device(&cxlr->dev); + return ERR_PTR(rc); + } =20 rc =3D devm_add_action_or_reset(port->uport_dev, unregister_region, cxlr); if (rc) return ERR_PTR(rc); =20 dev_dbg(port->uport_dev, "%s: created %s\n", - dev_name(&cxlrd->cxlsd.cxld.dev), dev_name(dev)); - return cxlr; + dev_name(cxlr->dev.parent), dev_name(&cxlr->dev)); =20 -err: - put_device(dev); - return ERR_PTR(rc); + return cxlr; } =20 static ssize_t __create_region_show(struct cxl_root_decoder *cxlrd, char *= buf) @@ -2572,8 +2589,6 @@ static ssize_t create_ram_region_show(struct device *= dev, static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd, enum cxl_partition_mode mode, int id) { - int rc; - switch (mode) { case CXL_PARTMODE_RAM: case CXL_PARTMODE_PMEM: @@ -2583,15 +2598,6 @@ static struct cxl_region *__create_region(struct cxl= _root_decoder *cxlrd, return ERR_PTR(-EINVAL); } =20 - rc =3D memregion_alloc(GFP_KERNEL); - if (rc < 0) - return ERR_PTR(rc); - - if (atomic_cmpxchg(&cxlrd->region_id, id, rc) !=3D id) { - memregion_free(rc); - return ERR_PTR(-EBUSY); - } - return devm_cxl_add_region(cxlrd, id, mode, CXL_DECODER_HOSTONLYMEM); } =20 --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2084.outbound.protection.outlook.com [40.107.94.84]) (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 D3C942C1592; Tue, 15 Jul 2025 19:12:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606755; cv=fail; b=L4nnTkgYjwO2BQJX2JxgMAz2agV/1ovdchCz7HUecMjqGEvrsHC0fyiwMr6mXOTKXywzGgZfvHBv76EAFxyoOSHdCbclA1IFAabjZO2AXkqXaaiJd40KnvJ8muLz9fWo5R6IzuEhVTo6RvqTTaAKr4suZv8XzXM+roIR0bXEiRY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606755; c=relaxed/simple; bh=i+xYiQFoSj4rc0y0K7uu6YZfhpk3Fw69Hw0W33HvZco=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mAq6OpslHpJYlXLxtUesr1M9U+yRJiKXCNsbZ2RAc+LqgVCXIFZ3vlz6ZvSR1YcjZwmJ6p1iXNq48sZ2AJjcPuW60HZxU9jLushq17VOwjTIXipVB57A9UzvCPj6tpeJEt6RCTg3LtqtdU2fcm0WCglzmQU8okbI0C+CteJUzAs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=VNgKLKxK; arc=fail smtp.client-ip=40.107.94.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="VNgKLKxK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Euqm1o7qJ1w0Tdr0XvDSNBRRy+cUgLts4y3zJBPcvwMxSA26fpgptmmpFgS1vtFBDSkptbVoU1/ntmqFjZqBRPmrxlhU3ZHCrN24RQzu8nhiTrKSq/1WSe5OkQZwgNyXzeSJpjLVSyDQyijv6NG5Qn062JtN5w0KzcDfvdm2OULczJKgOf+heP2cJBBXabtaedja+2k25r4048VGLoU0CdDsuU9aqucwa6k05LXy/kHKjGhGIiLNUiHCoF48sdwm+YXuQooI43aV/GtP6RAE6ppomyN0IE/pywdGnPonqtcNpVJCvvAUFULgWwgIONHoCLTq+Yx5ib/PXWXM9piyJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NQxHZ/bINGh6Py2yq0MjfnNd2TrXpktrG72jjoy6VIA=; b=cRGuIuAGT1fymO5+uhqgOd5ZzME3tYjQDC2uDIKaiD2FeofCW1/s7G+ob1VDcBcrs4Q0ekpID4vxw8R5PSAHgkjpk0MX0AWgrDnY1R556FN8pPj0IIUoyIupOz4/nIlCHzhkwGNzPbILK4lQUcziCn8ezIV25beg5iFUkZM7qmnGEaUB5qNJpdVmzpQTwQJKlC4NxDEuOg1kLHiJhyJyLRxlehiTrmzg9BAWMY7egmSx7sH5a5lijZ2EgJNFZfw056cLJVkx1cdYqtKET+Cdu+UeAV1q6DrMO9nmj4zfYauw2pHbTMAfzAoL8eIZMO63VITQ26NuX6Ty0wctrCoGKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NQxHZ/bINGh6Py2yq0MjfnNd2TrXpktrG72jjoy6VIA=; b=VNgKLKxK/kQiIAqAf1pwFFacP0dj224qL0a9kA0DBkBfJ0u2vk2G+Th4R2Yy5sHxIVuPu8HetGqnrH2Ypw7sYybUUB/YF8rRHoPKrYu28vtZuP9tiZybwm5dOLIQhBWGB3s2fT+PDtBOuGa18PA3BhxR6u3jRkQ3IvlorzqUCGw= Received: from BL1PR13CA0196.namprd13.prod.outlook.com (2603:10b6:208:2be::21) by SA0PR12MB4381.namprd12.prod.outlook.com (2603:10b6:806:70::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8922.33; Tue, 15 Jul 2025 19:12:31 +0000 Received: from MN1PEPF0000F0E2.namprd04.prod.outlook.com (2603:10b6:208:2be:cafe::3b) by BL1PR13CA0196.outlook.office365.com (2603:10b6:208:2be::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8943.17 via Frontend Transport; Tue, 15 Jul 2025 19:12:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E2.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:12:31 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:12:28 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 05/20] cxl/region: Separate cxl_region_alloc() from devm_cxl_add_region() Date: Tue, 15 Jul 2025 21:11:28 +0200 Message-ID: <20250715191143.1023512-6-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E2:EE_|SA0PR12MB4381:EE_ X-MS-Office365-Filtering-Correlation-Id: ac094824-1cdc-43f3-3bc9-08ddc3d38c4a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|7416014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?CvZ4VqIBV0wIo7zKyMQskso1d6AuQTmveEIIL0TdNLzSw/j/vPC5faKpIokF?= =?us-ascii?Q?Nb7De08wh5C+uY+qugZSkzb2NkKpzRZc5a9miehWd6WAW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nVCYmiBb0tv6e4cGQhznh9IqKNNbRqHXKytynunaaappzna?= =?us-ascii?Q?G8EXkwDbJNmcnhEQRZg7ZOy8ajzLJcQUUZI4b9E+mVbjr4r2KxNY2hF8gFj+?= =?us-ascii?Q?WEBwNXcKE1i+TVVj/sJ/kDOoOiIauFZhPMrtE8OYB6OnF6nVWrVCYAU4Jufo?= =?us-ascii?Q?gwGuMRdwboefgXgsxa9LvLh7LUgTJiwdxBNyJWRaSjw3z2xttAVG/+jiBCXY?= =?us-ascii?Q?NAD9/J6twZIln3acRcqwZQOAOulaxZzOhwTQk2OXcKTAlY6cTqyoQmcThMbM?= =?us-ascii?Q?g/S2U2RECk9BWQCU/kZyylfhOWqbBp3StRqFVMv8M8VGkdpne01eg96y1NW2?= =?us-ascii?Q?5fvsBIbt3oCbbG+M3o/g+UkrePUFbMLYxIMVCOq81CCuGenJdj/CY1o+wpea?= =?us-ascii?Q?jMNspLPSrcsaIVuUZrCkjzA0bbi36Ofq3XKzGtp80yHTx2OBPyT63cqfB8o6?= =?us-ascii?Q?6GrXrNF4kfCdkcuUPh9uvenN8JreIH1vpeuhfRaQixzlISM9wy4gqumSh+Pd?= =?us-ascii?Q?aenbN6YPWP+BeNZubL2Ghq0iCEFQwMb6xwrX?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(1800799024)(7416014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:12:31.5222 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ac094824-1cdc-43f3-3bc9-08ddc3d38c4a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4381 Content-Type: text/plain; charset="utf-8" In interleaving configs multiple endpoint decoders connect to the same region. The region's parameters must be the same for all endpoint decoders that share the interleaving setup. During initialization, the region's parameters are determined for each endpoint decoder. If a region for the same hpa range already exists, no new region is created and the existing one is reused. To simplify region setup and the collection of the region parameters, separate region allocation from its registration. This allows it to allocate and setup a region before checking the parameters with existing other regions and adding it to the cxl tree or releasing it and instead reusing an existing region. Here, only separate cxl_region_alloc() from devm_cxl_add_region(). Signed-off-by: Robert Richter Reviewed-by: Joshua Hahn --- drivers/cxl/core/region.c | 41 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 8e2521c6c845..cfcd286251d5 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2525,34 +2525,26 @@ static int register_region(struct cxl_region *cxlr,= int id) } =20 /** - * devm_cxl_add_region - Adds a region to a decoder - * @cxlrd: root decoder - * @id: memregion id to create, or memregion_free() on failure - * @mode: mode for the endpoint decoders of this region - * @type: select whether this is an expander or accelerator (type-2 or typ= e-3) + * devm_cxl_add_region - Adds a region to the CXL hierarchy. + * @cxlr: region to be added + * @id: memregion id to create must match current @port_id of the + * region's @cxlrd * * This is the second step of region initialization. Regions exist within = an * address space which is mapped by a @cxlrd. * - * Return: 0 if the region was added to the @cxlrd, else returns negative = error - * code. The region will be named "regionZ" where Z is the unique region n= umber. + * Return: Pointer to the region if the region could be registered + * (for use in a tail call). The region will be named "regionZ" where + * Z is the unique region number. On errors, devm_cxl_add_region() + * returns an encoded negative error code and releases or unregisters + * @cxlr. */ -static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxl= rd, - int id, - enum cxl_partition_mode mode, - enum cxl_decoder_type type) +static struct cxl_region *devm_cxl_add_region(struct cxl_region *cxlr, int= id) { + struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; struct cxl_port *port =3D to_cxl_port(cxlrd->cxlsd.cxld.dev.parent); - struct cxl_region *cxlr; int rc; =20 - cxlr =3D cxl_region_alloc(cxlrd); - if (IS_ERR(cxlr)) - return cxlr; - - cxlr->mode =3D mode; - cxlr->type =3D type; - rc =3D register_region(cxlr, id); if (rc) { put_device(&cxlr->dev); @@ -2589,6 +2581,8 @@ static ssize_t create_ram_region_show(struct device *= dev, static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd, enum cxl_partition_mode mode, int id) { + struct cxl_region *cxlr; + switch (mode) { case CXL_PARTMODE_RAM: case CXL_PARTMODE_PMEM: @@ -2598,7 +2592,14 @@ static struct cxl_region *__create_region(struct cxl= _root_decoder *cxlrd, return ERR_PTR(-EINVAL); } =20 - return devm_cxl_add_region(cxlrd, id, mode, CXL_DECODER_HOSTONLYMEM); + cxlr =3D cxl_region_alloc(cxlrd); + if (IS_ERR(cxlr)) + return cxlr; + + cxlr->mode =3D mode; + cxlr->type =3D CXL_DECODER_HOSTONLYMEM; + + return devm_cxl_add_region(cxlr, id); } =20 static ssize_t create_region_store(struct device *dev, const char *buf, --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2046.outbound.protection.outlook.com [40.107.220.46]) (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 6E1E32C031D; Tue, 15 Jul 2025 19:12:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606763; cv=fail; b=U8EAwU/YJ+ZsIZMS2o0KXLSp7Kzq+omDMxueqr2Fq/5gZ+w1fePw3LFyFU7FXA2PpiPQbJFAKKzNq6U+2pjJhFzgphg/2q0guBXe1thKe2ZlN/oPsOYLEa5dVL3y+gKugMlfQfLkMCT7IzTSGbY+jfrRW0lSuX+FGj1OV9hZxCY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606763; c=relaxed/simple; bh=2gTW1k9i6G+krJSvdKALYPWznxNj6CaPJAqS/ehLz04=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dz68g6xpt9R+4gGoPkK558WEcbJ3A8CRSxIqHRXLc2y7G5Op5+Wf4SA4qfmfrbaGGm+3B7WmNd7FRJ6AXL9e0GbxfkerYLbBiqY/kmpm9OZaveL3KPbKWndnDSeDmNZkO7ffNkU5vHvLHsac90r5nxa1ZbN9ROgquSUAPCYgDZk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=R6h8gNhC; arc=fail smtp.client-ip=40.107.220.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="R6h8gNhC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZyWafG+qbU1/IkAwQmbIMW52B5ks6lC1e532jaCQMopXPuPcKAFAKSFF0d1EIRQOUgsdAUJ/52C+ZNtXSlV7hosI6YwSRCggmtTRc87SYoJ1Qp3V6WACll6Hja9ya7OxCZ14mSaCmcA4OzwoL4Kr8+RqqZPMt3azdfzkWrOMvd51DGW0JzCy8mIHCYsmQ4Zycxz1g0C6xglJuOZ4uxDH0yKjkroBoVJBfKxmqfiYJTdYQwdo73PDUV3V4Nn3ZfZqnV3LXWmByhvT0Zo2JddBQOHugIvXymh/8TNwS0lVvg746LtuTtTwB+EhWn4x829mS+R7ZRphMISnweWeUyZFjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gO+/ojJMPmly9SXbOOyJ8th1e1/qTb17631L5LZ1DTs=; b=cSNVOKXAbKSYLBVAGIApgWT53fdNZ+sPk4bkRWFSZIUF6JFTOOIpLN0D75oVrKO7S++LcQZNA1syXv5zsuuQ7RILyy0vbsiVmljyOvz01si8P0Z8B0PAgQzC5bUF4mwQa0STRPZ01rsqNRX8FcwtaHlpRKF6nm0LzMp0ofXuWNvQrzOjFA6OkzP1XjnOkO3iEX0kGaqJpv7eeVtYOKSvaxBKYqnYDyBCUKRjm3rtXuSl1OqUlhpbJ1AIBwQhhfK8/RKisU8BylHP328ZQIKHI8yxnRAy+T3msB7Xj2eh/IiL6CWWVZX0mdkW1zqlihe7V/SwbnhXVMguIWDhabKDUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gO+/ojJMPmly9SXbOOyJ8th1e1/qTb17631L5LZ1DTs=; b=R6h8gNhCvFHuLYwaezkcEhAJjf0QGU2mVBVMY+B4uzcJTOrJb/wQ748v+3FoAjlBPkX0oiynKcpdEfM2O4En90RpRC5RlhfJowZZDCUi8was0oFnbvg3peyuKQqQ8K2DDjXWmtzJ74h/0W8GlxQXMT8HprwQeKv9Uh9MXW6tcMg= Received: from MN0PR03CA0030.namprd03.prod.outlook.com (2603:10b6:208:52f::19) by CY8PR12MB7587.namprd12.prod.outlook.com (2603:10b6:930:9a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.26; Tue, 15 Jul 2025 19:12:37 +0000 Received: from MN1PEPF0000F0DE.namprd04.prod.outlook.com (2603:10b6:208:52f:cafe::3e) by MN0PR03CA0030.outlook.office365.com (2603:10b6:208:52f::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.33 via Frontend Transport; Tue, 15 Jul 2025 19:12:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0DE.mail.protection.outlook.com (10.167.242.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:12:35 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:12:32 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 06/20] cxl/region: Remove dev_err() from cxl_find_root_decoder() Date: Tue, 15 Jul 2025 21:11:29 +0200 Message-ID: <20250715191143.1023512-7-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0DE:EE_|CY8PR12MB7587:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a59f139-6eff-4c74-98e4-08ddc3d38e6d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|7416014|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?MvVQLe/eD5gFxh3/doZ5BDeiFVQJFqoIVj0L7DRtMoXTTkjJeq6cQ30HM55q?= =?us-ascii?Q?6Lax09bEUu/B5NtqxK9vdpaXun479H3hTQHS5A7wLroP1WGshly+dhKqJWPq?= =?us-ascii?Q?8ai2iVdjkpn+9He9vji/7CKFhIz2UnFqWXDJwSehyl4WlU6CloJhW5dyTwE+?= =?us-ascii?Q?2vxkcIUinCOL/t2zkrq7sGWluXd4MhsjtlXQFBXoKbILSF+2L/BEHQaFBMZb?= =?us-ascii?Q?fC0vGEUO7sIs6dOQ4SA0rYWhmCt69YQGVOmVrHF3gw5JaxP4AlFMhp+G9ZR3?= =?us-ascii?Q?9V4cTktfkxPRUSPWsphZxp5fCnv8BGrW5H4YPURTUeMLKRxQNs7V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V4kXMCGsPLwQ9haMuFCVYP2opLBrTaS4C7sZqZEHMW?= =?us-ascii?Q?9jl8kDR3tQLWWEUc2KBt1Zz4fyqDvYZiHF8LfT7CPbMQMcLqsZ3i6RoY9H6s?= =?us-ascii?Q?OBE4rTk2idqZSrgiWjFide6pePIIqOK0iO7RsIXx8v4+BIlZgq5PQ2K2Q17o?= =?us-ascii?Q?TYlHQYJ5VdX9ZcwXhfqbSkqSzbrEtKHwq8AYEykFRSYszy6HXJ6sFI6Moa23?= =?us-ascii?Q?BdM+0TLYYRJzSrFOIdcSrh7beaqvEUfKEAJrYqT32eTOGHOGoJQOBMqam7Fl?= =?us-ascii?Q?ZoE41WUcp2ql1Jp3lSRTERmHGaXMncO5wQ27?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(7416014)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:12:35.1113 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0a59f139-6eff-4c74-98e4-08ddc3d38e6d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7587 Content-Type: text/plain; charset="utf-8" cxl_find_root_decoder() is a small helper function. Remove dev_err() from there and instead move it to the next higher level where other messages are generated too and all parameters are available to generate the message. This simplifies code in cxl_find_root_decoder(). Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index cfcd286251d5..760455c760e8 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3250,22 +3250,14 @@ cxl_port_find_switch_decoder(struct cxl_port *port,= struct range *hpa) static struct cxl_root_decoder * cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled) { - struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); struct cxl_port *port =3D cxled_to_port(cxled); struct cxl_root *cxl_root __free(put_cxl_root) =3D find_cxl_root(port); - struct cxl_decoder *root, *cxld =3D &cxled->cxld; - struct range *hpa =3D &cxld->hpa_range; + struct range *hpa =3D &cxled->cxld.hpa_range; + struct cxl_decoder *root; =20 root =3D cxl_port_find_switch_decoder(&cxl_root->port, hpa); - if (!root) { - dev_err(cxlmd->dev.parent, - "%s:%s no CXL window for range %#llx:%#llx\n", - dev_name(&cxlmd->dev), dev_name(&cxld->dev), - cxld->hpa_range.start, cxld->hpa_range.end); - return NULL; - } =20 - return to_cxl_root_decoder(&root->dev); + return root ? to_cxl_root_decoder(&root->dev) : NULL; } =20 static int match_region_by_range(struct device *dev, const void *data) @@ -3444,6 +3436,7 @@ static struct cxl_region *construct_region(struct cxl= _root_decoder *cxlrd, =20 int cxl_add_to_region(struct cxl_endpoint_decoder *cxled) { + struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); struct range *hpa =3D &cxled->cxld.hpa_range; struct cxl_region_params *p; bool attach =3D false; @@ -3451,8 +3444,14 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *c= xled) =20 struct cxl_root_decoder *cxlrd __free(put_cxl_root_decoder) =3D cxl_find_root_decoder(cxled); - if (!cxlrd) + + if (!cxlrd) { + dev_err(cxlmd->dev.parent, + "%s:%s no CXL window for range %#llx:%#llx\n", + dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), + hpa->start, hpa->end); return -ENXIO; + } =20 /* * Ensure that if multiple threads race to construct_region() for @hpa --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2046.outbound.protection.outlook.com [40.107.220.46]) (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 6DD522BFC8F; Tue, 15 Jul 2025 19:12:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606762; cv=fail; b=WZPaqI6tiiPbE3EzWl3CfcJ7QjRDVGf1uajEyVEwQ6GMzXt3i+JIgcdDX4lXux186xIoD97oIvNXMDOJQ1UGTC6XSkRFt3hngu4vYlRCWuwhs4+yK+fPgsUizlnkv/IpRMlPpFRDMhyJMD4gTKITROf2AcBW/chAxpxRuqqhrIY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606762; c=relaxed/simple; bh=YPflJ2iwGhrDOpZBmXmQEAoQ5Q3IIVhQAZNtjw7Nfv8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EsYx9L49Vxf9rlZ6a7IxVeAnE4SUlCmQeb43/mcSN6cOnVH+p1hq+NJwbJXQQxoClgN3DyZv8ud45m4FLxliWcbENesDtvntylWuGakYI3hnnNSWIxi3T3KfAhjU2XWohp84e4O2xqv1weOJfiASPnn4kR8bEPijwxn/z+yC8SY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=zzkIlVqi; arc=fail smtp.client-ip=40.107.220.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="zzkIlVqi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=zQQs+2RDBj9xoS8+XuQx1EbQCqitffxSZ1kzT/KBOWJyNJ66ji/ehFZDa1IxiQ2S+Cgo83MjOuDggh/fjIxfgp/ETTaBiWHpXdKSxZ8vhwx6hGxXISq64gNRbZkg+27FxmCHVKJd59IFJjvTMgZi6dspJZwCoDMlMTI6fRBYdv33aGCjJJSb79bPE0wIQ91XDJ+IUwxQJk9ACvmm6dQTWGHzGlCEenAd4bft61k1kHm9ELhbmMQDx7G+CDFj4OWDhuTM1MqniPiVov7UIy1RfKjHpw3bAK06wTw5wuH+kTf6hVf+q1fm5LCbLbFEcAM8HzpT5+a+tUln5U0OmPgowA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ToaKCAv3br0JjcGH2sMDpHLhJlVnaJfLBO5Pui5UXzo=; b=czvuwWH51v1LLo63i0Evl7SSo4M5sgWHUu8FLZdGuLg76vaM1n0BNwzQV4ZKc63bexxNZ7QOfcmJk1UVBM4TVcoicWGmMj5Z5rMadkg5NHe6wsGarPyVTCi1UxbH+FXz8VumBbOUBMC1a6vN0OQaonnmoDjRUbOfKurexzgHmAkjrFiBgPRBVJOUcW5d/aCx9u2tRwUrOMt/yNPMHOkQ395KEcS+e3JAryzhwFXuEMM3Ue1kndN5NwxZgYfOfz+lJQnI2uWS9HYiF4yATH+6YofyE/LOMz9iQB+89FenzT7xL52b5qVCIdNBzldzvA0ADuZUcaHts1U5xR1tdNRVwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ToaKCAv3br0JjcGH2sMDpHLhJlVnaJfLBO5Pui5UXzo=; b=zzkIlVqiRL9cBD5/HTEBDuNqQz4a3cyZm4OoUEP55WmdamftgmbWY+4PD70DXB6CaOfX4C1n0o4TXPQS+4h3rlHvRPmiPS1oLDb6ESHTbAHPrpievlToHqzkCfckuOKdbFeOwmax8Ad4gf8l81fIasFgyzR26mXQOsevCpvt+D0= Received: from BN9PR03CA0080.namprd03.prod.outlook.com (2603:10b6:408:fc::25) by SA1PR12MB9492.namprd12.prod.outlook.com (2603:10b6:806:459::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8922.33; Tue, 15 Jul 2025 19:12:38 +0000 Received: from MN1PEPF0000F0E4.namprd04.prod.outlook.com (2603:10b6:408:fc:cafe::64) by BN9PR03CA0080.outlook.office365.com (2603:10b6:408:fc::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.33 via Frontend Transport; Tue, 15 Jul 2025 19:12:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E4.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:12:38 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:12:35 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 07/20] cxl/region: Add new function cxl_endpoint_get_region() to simplify cxl_add_to_region() Date: Tue, 15 Jul 2025 21:11:30 +0200 Message-ID: <20250715191143.1023512-8-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E4:EE_|SA1PR12MB9492:EE_ X-MS-Office365-Filtering-Correlation-Id: 82910b2a-dbd1-4536-dd80-08ddc3d39083 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?TrsvExiT0gI/ux1gB/WryP4IvTcbRNdD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yvBvjsRIq2dp8Aej29pT5TBDMGdUs4h3QgTg8dbfIWYd1NzLoatu?= =?us-ascii?Q?MNAkqzMDBRMnXYnZSAuNfh2iDPqHq2stCAJUSsekzewofHasIwzjnrnkAyeT?= =?us-ascii?Q?/fP1iZuuGQSE4VqtnE1jw++62L1sn6a6rWmbH2Iez5DT+TdT+0+RqPAOaiLt?= =?us-ascii?Q?TVlQ3p5DKTtTbh/3v5cOyuy0ID1XjAlq9P2XgsR0EU8O5FJanMiXrAirVkzQ?= =?us-ascii?Q?N0yJcw/eTW7KM8pIMpCy+OtgbSxSm6ciRBHJY5ACmJZH8Qbzkv8RsAyKdkgD?= =?us-ascii?Q?R7fxBdMaMBZXMU/RguPM3Wvd9BTYLtKCaY4cA4LyzQVn9vhu0uShV65ytSFr?= =?us-ascii?Q?8jzgIg8UgqLb+lPVuyUbaTOWSb6cK2ln2azn9ZSZRG/4tgT8qjHt0spDR0Sh?= =?us-ascii?Q?t2Rjrr6f//z+cTApJqSiPuHBucZA4m1xeZzWdPuMYVSt+f9X819FWSdDTM3R?= =?us-ascii?Q?OHyDudn3WQV14g1249ydtQcguFMYXJ3mUTY7kqUUVcp/DewZNrvAu6lZyCEb?= =?us-ascii?Q?825VOfIXohG3RLH4F3/2CJ7JcZqOLgFLCWpLSa/GJl9Lg/9MsAKqlYqKwZ5q?= =?us-ascii?Q?q2dqhGT/mAp9IiWsQc/lgyodkpncSNpGin/h?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:12:38.6120 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 82910b2a-dbd1-4536-dd80-08ddc3d39083 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E4.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB9492 Content-Type: text/plain; charset="utf-8" Reduce complexity of cxl_add_to_region() by adding the new function cxl_endpoint_get_region(). The function handles the creation and construction of a region, if a region already exists, that will be used instead. The split in two functions helps grouping the code, simplifies the error handlers and further reworks, and reduces both functions' complexity and number of local variables. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 760455c760e8..57ee758bdece 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3396,7 +3396,7 @@ static int __construct_region(struct cxl_region *cxlr, dev_name(&cxlr->dev), p->res, p->interleave_ways, p->interleave_granularity); =20 - /* ...to match put_device() in cxl_add_to_region() */ + /* Pair with cxl_find_region_by_range() in cxl_endpoint_get_region(). */ get_device(&cxlr->dev); =20 return 0; @@ -3434,13 +3434,12 @@ static struct cxl_region *construct_region(struct c= xl_root_decoder *cxlrd, return cxlr; } =20 -int cxl_add_to_region(struct cxl_endpoint_decoder *cxled) +static struct cxl_region * +cxl_endpoint_get_region(struct cxl_endpoint_decoder *cxled) { struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); struct range *hpa =3D &cxled->cxld.hpa_range; - struct cxl_region_params *p; - bool attach =3D false; - int rc; + struct cxl_region *cxlr; =20 struct cxl_root_decoder *cxlrd __free(put_cxl_root_decoder) =3D cxl_find_root_decoder(cxled); @@ -3450,23 +3449,31 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *= cxled) "%s:%s no CXL window for range %#llx:%#llx\n", dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), hpa->start, hpa->end); - return -ENXIO; + return ERR_PTR(-ENXIO); } =20 /* * Ensure that if multiple threads race to construct_region() for @hpa * one does the construction and the others add to that. */ - mutex_lock(&cxlrd->range_lock); - struct cxl_region *cxlr __free(put_cxl_region) =3D - cxl_find_region_by_range(cxlrd, hpa); + guard(mutex)(&cxlrd->range_lock); + + cxlr =3D cxl_find_region_by_range(cxlrd, hpa); if (!cxlr) - cxlr =3D construct_region(cxlrd, cxled); - mutex_unlock(&cxlrd->range_lock); + return construct_region(cxlrd, cxled); =20 - rc =3D PTR_ERR_OR_ZERO(cxlr); - if (rc) - return rc; + return cxlr; +} + +int cxl_add_to_region(struct cxl_endpoint_decoder *cxled) +{ + struct cxl_region *cxlr; + struct cxl_region_params *p; + bool attach =3D false; + + cxlr =3D cxl_endpoint_get_region(cxled); + if (IS_ERR(cxlr)) + return PTR_ERR(cxlr); =20 attach_target(cxlr, cxled, -1, TASK_UNINTERRUPTIBLE); =20 @@ -3486,7 +3493,7 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cx= led) p->res); } =20 - return rc; + return 0; } EXPORT_SYMBOL_NS_GPL(cxl_add_to_region, "CXL"); =20 --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2058.outbound.protection.outlook.com [40.107.220.58]) (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 878E52C3745; Tue, 15 Jul 2025 19:12:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606767; cv=fail; b=AHT2voD6mAaohZAGk9purxnXj+HkGGrWXMoWNKw6icXrtlXO2EiWqh+ozeHMg/m4Wc6JbSC+Md0jMnMke5QyN9u/3JiQ9ISmHuDw625+O9TfKuqxj1LTrTGugWpcm5c+6NnY39HvDPc0cMujQ/EbT6vYeuyV7BKUbKwm4TYanqg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606767; c=relaxed/simple; bh=gjw6zz3ovQZ8Q0LQwNWWu1wB6p70udPJC/6Q7BR/ftw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=g3NWeLJnqCYdLihgpjpRKslYxAr4eMjaqUMbW+ev7fVah8y37Z6CGfxGHe59+1IDmaQ3NXVpXCMgXwbJI2PU4wvZrDCYv6vgvlXm09M6HVsvAX4875P/+8ST7Fg8uluZhmlucn1nc7gUJfqrIoBs17qiL3u/Ob2L332d3b8Du6k= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=2DvNt1kj; arc=fail smtp.client-ip=40.107.220.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="2DvNt1kj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JhDZa1tRn71+mH7hmoSkrzfcRE0yRcLOonh8YkzrKfPM2238DaTJSdCYaBw3qVNq2Vdne/bpGpIpqNGr7PktQ8v+dZhZ2B1VwV34tho7ivrMPH1lgnDs2u54GnbUS2VZjeIilVJzeVRPN/GzJna/0jxO0+KqGiOINHdRzQbSrlClZaKEcAECdk9C8dkoztQkfViLILvWwdvXRp4NCM7Eeu+JADStNWuL85hvaKgXPI48P005Fh3yCUWOJR6/2QkjjD3JORHUeyNVIM2osSakMQaTDBvfW0Yx+QEucHPQy002rZ4bH7tdaQTkAlwdFryKMn/+AB3xMGAg1uakgr/3NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XXosJKZrP/dFUC4LnXSOu3kVkoziDtuXk5Ds72nt4f0=; b=sYn6eCt5F4u/L46cPFRtVwcB0Ga/0LIA04GmbWD2cpCMvX0VPbb3pTbGrIkg92H7CG6gTLtjvPhgPz34JiaeYWADQwO20T4K2aq7MH8t8PAF1u+xjuaEPOfxLP7zJKL8DhiBb3f2rgQeBt8YPiQ6urNF/EUhb5SFHPDMi9VSoTEQ5ClveFfzkEnmcU/M1fb4mf9UVkAMtUana8AoX7PcUGS7oUATugJPKBV25XVlWjt5uwy+SaymurejRvBfaBNNT9DlAjOll7BFBmT7l6E6t7SDCB0S8LDw0VY0K2jvK3U4UdIn2JqV/8UptHidY/AbJI/J/tSpyvbroquZ3synfg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XXosJKZrP/dFUC4LnXSOu3kVkoziDtuXk5Ds72nt4f0=; b=2DvNt1kjHTRNDsZjfjzyfYmw3sy1ck8GF2+0fj2LfeCj0PdzbcUv0Nyy13VLkgfR26hr0b2wKbObGEco2Dmthb6Ods2cm+ByKTnRwxVMivqp1NqQek33TrjPXKX+wkm5sgBm8YIBqxApz0xGTkkjrwzVi6+MMGqHP5KJYs4q2So= Received: from BN0PR03CA0015.namprd03.prod.outlook.com (2603:10b6:408:e6::20) by DS0PR12MB7560.namprd12.prod.outlook.com (2603:10b6:8:133::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.35; Tue, 15 Jul 2025 19:12:42 +0000 Received: from MN1PEPF0000F0E0.namprd04.prod.outlook.com (2603:10b6:408:e6::4) by BN0PR03CA0015.outlook.office365.com (2603:10b6:408:e6::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.32 via Frontend Transport; Tue, 15 Jul 2025 19:12:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E0.mail.protection.outlook.com (10.167.242.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:12:42 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:12:39 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 08/20] cxl/region: Rework memregion id allocation and move it to register_region() Date: Tue, 15 Jul 2025 21:11:31 +0200 Message-ID: <20250715191143.1023512-9-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E0:EE_|DS0PR12MB7560:EE_ X-MS-Office365-Filtering-Correlation-Id: bd7c84f5-e80d-4dd9-1bb6-08ddc3d392aa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?O0AeTtRAD/3ldxCkwEXOz+ageMstrKSrIGjlo4B+fJFNFB6G9JH6eROh/DZY?= =?us-ascii?Q?BkyS7i5MLLVXAAiQF0bAALFQasB2hAkO7JX3IvdgoryTZfpDBSrLwnqR6ZAG?= =?us-ascii?Q?Hy+FQXQEyeK7NIcBkA1n6wNCzD+C3uW5MqST7An1x/LCLC29aM+rRYFPccTe?= =?us-ascii?Q?Npbc3YYwl1Bz8c79Kg/em2wxiP+onVhiA5zgC/nv1LBiJhsHCqxZdjQzdd0m?= =?us-ascii?Q?w6FuhGsLHSKBYD2TsCP5ZTDCH31VgTkHr84OhwjXNCncck1NU7iYbN55R1si?= =?us-ascii?Q?7sux1Vh8j0VkLbJTRKiZaH2bNS1VlCErzmCDM2qRSMwhstfBg62KSxICsy7M?= =?us-ascii?Q?Cx73RLTdtOh2E3bSdXdnnrFf/X/WN2AD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TCMlD+WlMVjW00hFRJeOMBY2Zk48eV/a2WSSkaWTexL3dnVxpTF+I1hZD4F?= =?us-ascii?Q?zvUex+Vwjsw4ZTqgurcsqZ6P0sPyCkeJNFOovLr4b2vn4jlTevht9DdPbzw6?= =?us-ascii?Q?rONdCy2KOXgZPDnOFV+QX/wIgt4QQvpXi+q6wuddA540Xng83ab62L6fES1Y?= =?us-ascii?Q?MWaZ8O7Zu5b9GKs6Wbqq5Oi3gUyKvc5wbxdluqXHqPSicXjpyCoR11A+Wanf?= =?us-ascii?Q?qpJ00ajYKohuV8WiXk4GUuLnoxmxpRht8gT9?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:12:42.2135 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bd7c84f5-e80d-4dd9-1bb6-08ddc3d392aa X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E0.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7560 Content-Type: text/plain; charset="utf-8" Make the atomic_cmpxchg() loop an inner loop of register_region(). Simplify calling of __create_region() by modifying the @port_id function argument to accept a value of -1 to indicates that an available memregion id should be assigned to the region. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 57ee758bdece..34ffd726859e 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2504,18 +2504,34 @@ static int register_region(struct cxl_region *cxlr,= int id) { struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; struct device *dev =3D &cxlr->dev; - int rc; + int old, match, rc; =20 rc =3D memregion_alloc(GFP_KERNEL); if (rc < 0) return rc; =20 - if (atomic_cmpxchg(&cxlrd->region_id, id, rc) !=3D id) { + if (id < 0) + match =3D atomic_read(&cxlrd->region_id); + else + match =3D id; + + for (; match >=3D 0;) { + old =3D atomic_cmpxchg(&cxlrd->region_id, match, rc); + if (old =3D=3D match) + break; + if (id >=3D 0) + break; + match =3D old; + } + + if (match < 0 || match !=3D old) { memregion_free(rc); + if (match < 0) + return -ENXIO; return -EBUSY; } =20 - cxlr->id =3D id; + cxlr->id =3D old; =20 rc =3D dev_set_name(dev, "region%d", cxlr->id); if (rc) @@ -2528,7 +2544,8 @@ static int register_region(struct cxl_region *cxlr, i= nt id) * devm_cxl_add_region - Adds a region to the CXL hierarchy. * @cxlr: region to be added * @id: memregion id to create must match current @port_id of the - * region's @cxlrd + * region's @cxlrd. A negative value indicates that an available + * memregion id should be assigned to the region. * * This is the second step of region initialization. Regions exist within = an * address space which is mapped by a @cxlrd. @@ -3412,11 +3429,7 @@ static struct cxl_region *construct_region(struct cx= l_root_decoder *cxlrd, int rc, part =3D READ_ONCE(cxled->part); struct cxl_region *cxlr; =20 - do { - cxlr =3D __create_region(cxlrd, cxlds->part[part].mode, - atomic_read(&cxlrd->region_id)); - } while (IS_ERR(cxlr) && PTR_ERR(cxlr) =3D=3D -EBUSY); - + cxlr =3D __create_region(cxlrd, cxlds->part[part].mode, -1); if (IS_ERR(cxlr)) { dev_err(cxlmd->dev.parent, "%s:%s: %s failed assign region: %ld\n", --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2077.outbound.protection.outlook.com [40.107.220.77]) (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 4F65A2D12E1; Tue, 15 Jul 2025 19:12:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606771; cv=fail; b=bPhzRogJ3HiiB7p6rqQjsSVwpm3LGxQZkdgTSCQZbZQWBI01kwhXa3XlD0xlTx3brPCwAEmNjPJ+GskD3nAOCwNet8NZNXV1bxKsP9U19izvEaeAOsZvRFCGh4Koxni57ZL75Jg9mGYDpeCSfs9zoBq8d+/p8Lmml43Axksqu/4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606771; c=relaxed/simple; bh=fwg+zat8Y+6cP8PUz1cF3YiqNeLpwPyk7ZPGgeYqLt0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lC6t9YPz60m9W+NzUAOGplqE0m6l9VJQQUE3/rmn0QTVaybGre6nr99iGwiMTshmJySWN7Q0hu0oohc2Jy34JvDCe9ZnVDfSChNaj3wGnYWnTEoEfPvxVLyXNhYecRZ9ikutOHN+UrQTgly/Ae4+NFJhhp5gvubCGX84GNOdPy8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Nsg9WEyb; arc=fail smtp.client-ip=40.107.220.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Nsg9WEyb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LGlI5gT2oa3ESRdk3DbE1ZbpypXus7ecGjhqFm9IT1I4P8hpWJKNHuXqa2wDsqR6+Gy/13QT/vWOmjH5biNvZU07APtaUiHrZl8eUtG6tqEWcfvhxC5T9n3HnHpmE5PsKSOcy9v0IT8mb7T97Krv8fjivKjK2cqURE1dFVXc19Re6qxFrr+AnAX6fTGhpZO4wbra5etPuQ5rVhrT+ovfk54KUFL8QHLanMNihqoxZg9mqfAj+vChK3oNQfSjcJmPOjaY6ykKH4Dwjgxfd7cbaabKcCpuJLmuBliEYzBl+xTlYGsOTRIs5jo6+2GDRStymuwa7BoaI/PG6Kaw64pdew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fu5T17ZnFlDyQ6w7gT7xNmGannZ0XZgkBTEY7zmWIcM=; b=No0ghvjybIjDUEFnMFdXCWlblO209Kg2wlBJk2CdMrNOXSejBG8YBKqvdBNTRyKDdRSdEcHfBwXTJzhN6jMG4kvi9ERkT0vogl6VjWpR9cxuRgs/019f8BpXkwcYlGomgJiMGXFnfjDI4yW2prNBQ5/ufqghxwHFNCiMZ54VXYGSyK1N2d6ivtBinnvko8IfnGihuzhbnSihwhgZ7X5Q1Ct2D+HcHN5iL6V60YnfqjIeI2ycRWrbbfwl0zXR57Il2F/FVPji0a3iALMWkxixKDJ6odR6JxD0y75q4qSnFZBThru0e9pQ9g3XtyV4tDepBMRFR2fjSXHbQuzbV/E+Nw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fu5T17ZnFlDyQ6w7gT7xNmGannZ0XZgkBTEY7zmWIcM=; b=Nsg9WEybUEGyOVx/orkCeL1ARAJjSEpXtj5mTDkAnh7Z5ONNyKLIgDhEcRNWd7ycCHbsiT7b4HsU1Fugjhz/zPnLCLu3qNorajyy3h4oRP8BrwLXSP2kbh4fSuJp/dEGEff0rJ0eXXLuLniy9c3Ka2L8BcZYaH+C+c4yCpFfsqo= Received: from BL1PR13CA0106.namprd13.prod.outlook.com (2603:10b6:208:2b9::21) by SN7PR12MB6861.namprd12.prod.outlook.com (2603:10b6:806:266::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.25; Tue, 15 Jul 2025 19:12:46 +0000 Received: from MN1PEPF0000F0DF.namprd04.prod.outlook.com (2603:10b6:208:2b9:cafe::59) by BL1PR13CA0106.outlook.office365.com (2603:10b6:208:2b9::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8943.17 via Frontend Transport; Tue, 15 Jul 2025 19:12:46 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0DF.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:12:45 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:12:42 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 09/20] cxl/region: Change __construct_region() to use it as a tail function call Date: Tue, 15 Jul 2025 21:11:32 +0200 Message-ID: <20250715191143.1023512-10-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0DF:EE_|SN7PR12MB6861:EE_ X-MS-Office365-Filtering-Correlation-Id: 497ae509-ea31-4fbe-1eb9-08ddc3d394d6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?PpLEcIz2Ub5M+FOnpboFYEB927HAi79+RMP0P1Ydf7Lf43LIs7Rwc6mWKuuX?= =?us-ascii?Q?5NIl6mD0cHSYW94jRNrdQBKuW+d74I8u3eyKplgP829NRZzbET7lYjwcSz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73GBmNQJAx4VFiJmFcxmlAqro05yEa6Q3CU/OufU?= =?us-ascii?Q?xEMRJfEURMZrtlGTnOrprmhTw0KCzZLleq4nvrW9EBrJENQg0FVduZw+Kt/o?= =?us-ascii?Q?AM5iIb75SLCoLjH4MjKDnfVsdkGXXEtgSDjEcnqYOQnWyLxKdA+Yxa4w8nol?= =?us-ascii?Q?3Ily8VBZlt5mkERhOQGI02xi1H/+nTKukPIo27JKNWEaK80IlEzqQxODgK4a?= =?us-ascii?Q?cs2uBPwyxcL7fWQkadPjavbxPv7uHwLyP4A2xRRf3WyNcmam06dJzBBM/0nr?= =?us-ascii?Q?AkdSej3kKP0gSmqDB3xyWiznU2nefydTots7gQogSe5bxbrohrmeQ+Fa/3yh?= =?us-ascii?Q?aZGTnyOj2KFCFF9EH/n+9inQgX6y15mZeOHmZfH1fLBEj5po1hrn7ob+q4+j?= =?us-ascii?Q?b+LHYS/yvivK1AxQl6iAjx9cgn4No5si4UqvKuKBfYjxeBUOWjya/htHlZL/?= =?us-ascii?Q?58hF18/9Gu9TeIxPy/giI8e1xfhZRspxskDkX8WCvKWLh/feDTNbtmxJAf9F?= =?us-ascii?Q?QxYMzY45rT+J0MmZainas7gRnZ5+ofHQ9O5h?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(82310400026)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:12:45.8617 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 497ae509-ea31-4fbe-1eb9-08ddc3d394d6 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0DF.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6861 Content-Type: text/plain; charset="utf-8" Change the function interface of __construct_region() to use it as a tail function call. Use the new cleanup helper early_region_unregister to unregister the region in case of errors directly in __construct_region(). This avoids additional error handling after calling the function. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 34ffd726859e..4743421c6db5 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2540,6 +2540,15 @@ static int register_region(struct cxl_region *cxlr, = int id) return device_add(dev); } =20 +static void early_region_unregister(struct cxl_region *cxlr) +{ + struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; + struct cxl_port *port =3D to_cxl_port(cxlrd->cxlsd.cxld.dev.parent); + + devm_release_action(port->uport_dev, unregister_region, cxlr); +} +DEFINE_FREE(early_region_unregister, struct cxl_region *, if (!IS_ERR_OR_N= ULL(_T)) early_region_unregister(_T)) + /** * devm_cxl_add_region - Adds a region to the CXL hierarchy. * @cxlr: region to be added @@ -3347,9 +3356,10 @@ static int cxl_extended_linear_cache_resize(struct c= xl_region *cxlr, return 0; } =20 -static int __construct_region(struct cxl_region *cxlr, - struct cxl_endpoint_decoder *cxled) +static struct cxl_region *__construct_region(struct cxl_region *__cxlr, + struct cxl_endpoint_decoder *cxled) { + struct cxl_region *cxlr __free(early_region_unregister) =3D __cxlr; struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); struct range *hpa =3D &cxled->cxld.hpa_range; @@ -3364,14 +3374,14 @@ static int __construct_region(struct cxl_region *cx= lr, "%s:%s: %s autodiscovery interrupted\n", dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), __func__); - return -EBUSY; + return ERR_PTR(-EBUSY); } =20 set_bit(CXL_REGION_F_AUTO, &cxlr->flags); =20 res =3D kmalloc(sizeof(*res), GFP_KERNEL); if (!res) - return -ENOMEM; + return ERR_PTR(-ENOMEM); =20 *res =3D DEFINE_RES_MEM_NAMED(hpa->start, range_len(hpa), dev_name(&cxlr->dev)); @@ -3406,7 +3416,7 @@ static int __construct_region(struct cxl_region *cxlr, =20 rc =3D sysfs_update_group(&cxlr->dev.kobj, get_cxl_region_target_group()); if (rc) - return rc; + return ERR_PTR(rc); =20 dev_dbg(cxlmd->dev.parent, "%s:%s: %s %s res: %pr iw: %d ig: %d\n", dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), __func__, @@ -3416,7 +3426,7 @@ static int __construct_region(struct cxl_region *cxlr, /* Pair with cxl_find_region_by_range() in cxl_endpoint_get_region(). */ get_device(&cxlr->dev); =20 - return 0; + return no_free_ptr(cxlr); } =20 /* Establish an empty region covering the given HPA range */ @@ -3424,9 +3434,8 @@ static struct cxl_region *construct_region(struct cxl= _root_decoder *cxlrd, struct cxl_endpoint_decoder *cxled) { struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); - struct cxl_port *port =3D cxlrd_to_port(cxlrd); struct cxl_dev_state *cxlds =3D cxlmd->cxlds; - int rc, part =3D READ_ONCE(cxled->part); + int part =3D READ_ONCE(cxled->part); struct cxl_region *cxlr; =20 cxlr =3D __create_region(cxlrd, cxlds->part[part].mode, -1); @@ -3438,13 +3447,7 @@ static struct cxl_region *construct_region(struct cx= l_root_decoder *cxlrd, return cxlr; } =20 - rc =3D __construct_region(cxlr, cxled); - if (rc) { - devm_release_action(port->uport_dev, unregister_region, cxlr); - return ERR_PTR(rc); - } - - return cxlr; + return __construct_region(cxlr, cxled); } =20 static struct cxl_region * --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2087.outbound.protection.outlook.com [40.107.220.87]) (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 5FBC42D1F7E; Tue, 15 Jul 2025 19:12:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606773; cv=fail; b=KWCcoNMMzW91VN5PPjoxCqHNj/gts54IMtoAobN084ksU7vL7PJkRkdlobk/XyV5KIb6Rlkwwso8IAGQcEunVwvkkOcbttJ2HW7bU2sxrkrluh5/USo2hWt7sCxnsfmPZlLl+4kniKvxL2oaXF8KsFqWRrfaPRAeKr5yKItgbbs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606773; c=relaxed/simple; bh=PfimUmjYTXZYZG+7c/GYoZRCPmc4ErUp5mSva0THOo0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sfPeLQEN9tOJFasss8g1UBIcErj+1WdIXLWGvBN+S2vMozHu0ZWCce34awcm+atDeTd+T7xXp/tRdIYqpDZ9+N1qC+QbfZWIZTvS5oE6T3/aUte7oP8msHLMSr6Eto9YB9SOgUu97HGZ8pM6AKOfZbf7Hwzm66SKsYumH4FEj7M= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=hXhEpGBi; arc=fail smtp.client-ip=40.107.220.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="hXhEpGBi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IHRRgUja6C0/9VOw6Y1ttazMfElamNhZxiBmjk4IK4x5cUhys8wPspYdandK+SDV+vVd+bx+Of2YmRMERclrX8a9ACHi89ZCjoGh0+cpgtXxwtM9v8BKQqJQk51nfHzn2JrnCngGaw06oOYnVJcYIltxxAimiO3DOmMCcEnx+AXclfVhVnzEp6S0BAsEr8idbroRWobjcN5ASg6MBL1BynlltE8FOPYc8+rZ/75wmIVBxOQ9BfbkdEnFwzskhn2t1aoZsjBmJNBbgqvY9mEtNLoWjfn5dlXhDWbPgOJYdoMgh1jeLdMMXTKI4lwOx17sMMtOqbiSPsc2Diz97bqDvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Hl2hS5yQdZjoObmKIpxoMbRmmaG+1UfRqSP1SOH1ZiQ=; b=t0QID4kr0F1I91C1VEiBhwHLZjlD5hrvlWJxarG8Cnqd/H2bsezsZtAxYjObUSeMp0IjctT56T6DrQcFVUnA5HF4UHbY9ArKAkf0PvnqwWOvvJfmZY9cQq3DJGxArtdWVxXhFi9PIPZ7UMHnGnwp0QP10XQCcEbYaAIBWFUGfidDo1ZKJcofi8lcAdLpKA5UkzSH8g4qnXAwwA26QeCHsUJwylesuuQ+v9svUWTjdHWX+7CMUM6Xy5JwFkBx+EQoubQPHO5j6fp7yc0yW+auvUC6eBHLCWkXegWrYPxdhx6/GKon740WM6KJpgM6vq2gSYMA/aAxjjUuc6HZucUEhQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Hl2hS5yQdZjoObmKIpxoMbRmmaG+1UfRqSP1SOH1ZiQ=; b=hXhEpGBiZBobkXEWp2gnz6VFgWdBmYPLD1VvtpqVjFAqhtvpcJbwyZwCGtzvH6au9i3WnP+vbBFdsNOTTikL+oaSBKrI4pzQjMWCzcy2LscrVXFXROKXo1DAgSRiGY1mbXbEed66aWnfWG1Z/UXgtXaNzI8J/LG4jyPaEwepl9k= Received: from BN8PR15CA0070.namprd15.prod.outlook.com (2603:10b6:408:80::47) by SJ2PR12MB9116.namprd12.prod.outlook.com (2603:10b6:a03:557::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8922.33; Tue, 15 Jul 2025 19:12:50 +0000 Received: from MN1PEPF0000F0E5.namprd04.prod.outlook.com (2603:10b6:408:80:cafe::6a) by BN8PR15CA0070.outlook.office365.com (2603:10b6:408:80::47) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8943.17 via Frontend Transport; Tue, 15 Jul 2025 19:12:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E5.mail.protection.outlook.com (10.167.242.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:12:50 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:12:46 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 10/20] cxl/region: Remove __construct_region() Date: Tue, 15 Jul 2025 21:11:33 +0200 Message-ID: <20250715191143.1023512-11-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E5:EE_|SJ2PR12MB9116:EE_ X-MS-Office365-Filtering-Correlation-Id: c6adb343-0181-4fce-9c0e-08ddc3d39767 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?7QMgsWP1mwbO21zgf6cH31AdiwIIC/s5Xi+Cr1Wk2AuTTT3uHnHiVZMBwD86?= =?us-ascii?Q?iF2MuNI8LEhPvGX/zlcZadsnbwdJNYP4t7USy05Hyc/76USC97IESCS1m2ZE?= =?us-ascii?Q?jniCkz5DcCO+IAGh/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Q?1krJhmP45OgIT3s03cSbNKTyvSNSg89twI6flhycqllJKJLRjIXAVYQr7gJC?= =?us-ascii?Q?GNPODcOps/Z+1w+KKnbDWk6MoPvYUrz7xEuk1hujHJ+8wnRg6F6lkhOu7DAP?= =?us-ascii?Q?yDCTJNrUxELp55nhMaA1CKb5a9+yC2J39SUqybGcRGPFk8dZaBnjC+xSAyWf?= =?us-ascii?Q?LlZ7E5D0551I7m6sWprmFyQYsmiNaZudrLphdUBx0AMGILPbx3EIEzlkDNiU?= =?us-ascii?Q?lHzaqBUTHwQ+sJym5j5ldU0J+WMMTT+OhxvDOVKvZTNMOjlxYQoc9sjY7Vic?= =?us-ascii?Q?JImOdbC+wLivkcZ9OBktiTH8JmjpXKkNsNS/tSM56EL93t8HSmyv6Hrtfusy?= =?us-ascii?Q?8zKSicWwJ1HseuLktO2n7Qjsq3v5XDrJMDG9hpBqk+YoOVleCJWZwl4KpIlD?= =?us-ascii?Q?on4VlTzSvX5eQgFct7bWlCesOq/qIiU9YyL+K+mRlmr7qY57qknQ0RBrjzR3?= =?us-ascii?Q?qB0YG4+fqBImJbDWYInhHKgdwBXBsgG6TSz6?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:12:50.1699 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c6adb343-0181-4fce-9c0e-08ddc3d39767 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E5.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB9116 Content-Type: text/plain; charset="utf-8" There is nothing left the function does in addition to construct_region(). Remove __construct_region() entirely. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 42 ++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 4743421c6db5..edd1cd9ef022 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3356,18 +3356,31 @@ static int cxl_extended_linear_cache_resize(struct = cxl_region *cxlr, return 0; } =20 -static struct cxl_region *__construct_region(struct cxl_region *__cxlr, - struct cxl_endpoint_decoder *cxled) +/* Establish an empty region covering the given HPA range */ +static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, + struct cxl_endpoint_decoder *cxled) { - struct cxl_region *cxlr __free(early_region_unregister) =3D __cxlr; - struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); + struct cxl_dev_state *cxlds =3D cxlmd->cxlds; + int part =3D READ_ONCE(cxled->part); struct range *hpa =3D &cxled->cxld.hpa_range; struct cxl_region_params *p; struct resource *res; int rc; =20 + struct cxl_region *cxlr __free(early_region_unregister) =3D + __create_region(cxlrd, cxlds->part[part].mode, -1); + + if (IS_ERR(cxlr)) { + dev_err(cxlmd->dev.parent, + "%s:%s: %s failed assign region: %ld\n", + dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), + __func__, PTR_ERR(cxlr)); + return cxlr; + } + guard(rwsem_write)(&cxl_region_rwsem); + p =3D &cxlr->params; if (p->state >=3D CXL_CONFIG_INTERLEAVE_ACTIVE) { dev_err(cxlmd->dev.parent, @@ -3429,27 +3442,6 @@ static struct cxl_region *__construct_region(struct = cxl_region *__cxlr, return no_free_ptr(cxlr); } =20 -/* Establish an empty region covering the given HPA range */ -static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, - struct cxl_endpoint_decoder *cxled) -{ - struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); - struct cxl_dev_state *cxlds =3D cxlmd->cxlds; - int part =3D READ_ONCE(cxled->part); - struct cxl_region *cxlr; - - cxlr =3D __create_region(cxlrd, cxlds->part[part].mode, -1); - if (IS_ERR(cxlr)) { - dev_err(cxlmd->dev.parent, - "%s:%s: %s failed assign region: %ld\n", - dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), - __func__, PTR_ERR(cxlr)); - return cxlr; - } - - return __construct_region(cxlr, cxled); -} - static struct cxl_region * cxl_endpoint_get_region(struct cxl_endpoint_decoder *cxled) { --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2081.outbound.protection.outlook.com [40.107.243.81]) (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 12E9D2E1747; Tue, 15 Jul 2025 19:12:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606782; cv=fail; b=igwqSvOLgCmYjHmWcGHn/vpDvlwZBWc+wozZJjgnu5n65KkN7heSMmFD49kq0u+pUY9Tn4Bz+B3893K9YDBGjSc/whhpxfs6DasI/M5QcjimpqBBsxsuF/0eD9eDDW/X0ekrDWJSHAofUpO9Ee/9fUdLtWcfS7S6Im/9bRWmlNI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606782; c=relaxed/simple; bh=n3OZhbsnicJk1jnXtMDi8sksHVoeIA+q8w3TY5o/v3Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QBZpGfpURbHNNc/fzV0SRsuQt8CzVtDvv4td1sSg7be5nwZ2VdDMNXLh13963FU1no7p+f8m5ekAp9MLxTTjaqyN5WdYixKfX/lSD/y6Ci+33spSV8s8xlzhNYE2XNji4vOmyWZ1c+D9sjMEGcVeXDIjs3LO+FKryIEoYdVq7VQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=3LEFotU3; arc=fail smtp.client-ip=40.107.243.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="3LEFotU3" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HSNfzv7W0M1OOH+8ZUFE25+3NL6WDVWeeyvWoDzmlP/8isyhvn9DomJuDWUeD+H7XtAxQHQA4gOiQKKs806ND2mibOFnNxfnbCPNN6gopaksyozDg7+5obAgnqEbx0U4/1idSLNT63/rHLDUIlSAbmJ8fUMj7elAde305H4EE/goZ1G02JP8vruV+W0GLyZdQNrjGk4eww05K+lV6iT/ZKzZDPm4IlP8UsAfi0hY40LETNp6FVHL+3LP2jPJBxJL0mH/tea6tskmdUpapHeHMEDZ9xQ8AwcaUDzaTccNehBASWcb3apIdh93apR1zvttraKzDUbhVggXDS2Xr5RGcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Jiv//rQwga+RHZSWBbBVbi+NCZb1ljietdHmK5Psmoc=; b=rkvaQoZs36NUeP2tPR5A5VUbk5AR94ZAVJG52rQu5lAfy2JhwZxVEiTreyu5u1pY+hunp4t7iEDQr+nnQhMiZrZVunYBqoGvs3cahfbp/WrFz0t/YiKN1iSPdNovXUh36g+E7qDp6d6jNfRk7l9Z1kdIfNBlMg9D8U6VraKNaG/V7WtGS7sC7AluZ+MRpmj2DlkTGlju/MDNenKm0RLxfr7CX0T0ij+4x/q0ravG+XbGGDaCXgCtor7WX506QSAtglLfwRyorrSLJgpRSbsAy6Pbw2BgEyCW6BhSnmQznCrQl0r+gcutm+68TrOkYXPgaTsQZAxOSDrJ1ZYx3wovoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Jiv//rQwga+RHZSWBbBVbi+NCZb1ljietdHmK5Psmoc=; b=3LEFotU3ksaRFLIm/QTO+isO6U3NYeVqJOCiU3Tpgy2u5dWqtvUDPPIz4qnnhi8jHr3mHoKRtVvJGcwpf6RvJXzYTCMqtNczSTHlUJiXNbhZhTzT/I+LOsPyFuP28tmAQgtngMOfB59r1p2iaWXwubdDY6+wLlmuzYS0lw7Qkng= Received: from BN0PR03CA0007.namprd03.prod.outlook.com (2603:10b6:408:e6::12) by DS2PR12MB9824.namprd12.prod.outlook.com (2603:10b6:8:2be::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8922.32; Tue, 15 Jul 2025 19:12:54 +0000 Received: from MN1PEPF0000F0E0.namprd04.prod.outlook.com (2603:10b6:408:e6:cafe::4e) by BN0PR03CA0007.outlook.office365.com (2603:10b6:408:e6::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8943.17 via Frontend Transport; Tue, 15 Jul 2025 19:12:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E0.mail.protection.outlook.com (10.167.242.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:12:53 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:12:50 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 11/20] cxl/region: Separate auto-generated region cration code path Date: Tue, 15 Jul 2025 21:11:34 +0200 Message-ID: <20250715191143.1023512-12-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E0:EE_|DS2PR12MB9824:EE_ X-MS-Office365-Filtering-Correlation-Id: eee4f820-8498-4b93-ea02-08ddc3d39981 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?/gnfO8tOIr2u7WcQFM1cQ91qENmZ7aQJTTPLgM2OAZWSA11YSoqSaQCUCZz9?= =?us-ascii?Q?eb4kYQh6uTsPsHUm81KvzTO7N2R+23pA2UQAclAmpVEwpwVIp/ZK0WIZkg0d?= =?us-ascii?Q?Q0Cc/MZKeNdJdFywzmCmoj0D220t8Em00PvVtmle6fHPBwq0fJHA8hP2gRnN?= =?us-ascii?Q?Gp0NgOa+dk0Xoa4ffAwz7vNqZ2bzMzK+jpYSiTq7gUuIqZ1A8JY0qcVqrzu2?= =?us-ascii?Q?X2hYws9snh2Wr+0Fqt8njrlArRiPeffg98s5TKkW8Yslc+r9/JFScW9/NexC?= =?us-ascii?Q?AC8sSeeTHImkdS9JMtySETIXySHLZFXCvXFTBGKyVzoNO3OLxa04j3fLxicW?= =?us-ascii?Q?Ub2z+4ikcnmnQ8qwwCk4lHUsL/vUqTWEt3rHNm7vvEAsQB5z/BAavgEIaMuR?= =?us-ascii?Q?2RLhifRHheHcMhhO7ZYeLLzojZGXHqH3PzpgYUzc0i2NqdGsRQDe45ahkDGJ?= =?us-ascii?Q?+x1LTKkHz0grQAG54tJlQfLyTq5NpYqctXR6ZdZLLJZojFv3dZoFCRJuKw/F?= =?us-ascii?Q?/rcLoftJsZa9cgt6EIJdvdfsfqvijtNZbn2l6ujibXtjKKMs6ljvHxi5U5tS?= =?us-ascii?Q?3MwqynftxxXNkqx4cJ8tgrKai3cpm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?Q?gEJzDIhR2sfiDOVLUY0yN/yNIibg1vVigVkG?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:12:53.6991 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eee4f820-8498-4b93-ea02-08ddc3d39981 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E0.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS2PR12MB9824 Content-Type: text/plain; charset="utf-8" For further optimizations, separate auto-generated region cration code path from the one used by sysfs. Introduce the new function create_region() that is used to auto-create a region. __create_region() will be used as a sysfs helper function. The separation helps to simplify both code paths as implementation of both largely diverged already. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index edd1cd9ef022..ba59fa726cf3 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2609,15 +2609,6 @@ static struct cxl_region *__create_region(struct cxl= _root_decoder *cxlrd, { struct cxl_region *cxlr; =20 - switch (mode) { - case CXL_PARTMODE_RAM: - case CXL_PARTMODE_PMEM: - break; - default: - dev_err(&cxlrd->cxlsd.cxld.dev, "unsupported mode %d\n", mode); - return ERR_PTR(-EINVAL); - } - cxlr =3D cxl_region_alloc(cxlrd); if (IS_ERR(cxlr)) return cxlr; @@ -3356,6 +3347,30 @@ static int cxl_extended_linear_cache_resize(struct c= xl_region *cxlr, return 0; } =20 +static struct cxl_region *create_region(struct cxl_root_decoder *cxlrd, + enum cxl_partition_mode mode, int id) +{ + struct cxl_region *cxlr; + + switch (mode) { + case CXL_PARTMODE_RAM: + case CXL_PARTMODE_PMEM: + break; + default: + dev_err(&cxlrd->cxlsd.cxld.dev, "unsupported mode %d\n", mode); + return ERR_PTR(-EINVAL); + } + + cxlr =3D cxl_region_alloc(cxlrd); + if (IS_ERR(cxlr)) + return cxlr; + + cxlr->mode =3D mode; + cxlr->type =3D CXL_DECODER_HOSTONLYMEM; + + return devm_cxl_add_region(cxlr, id); +} + /* Establish an empty region covering the given HPA range */ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, struct cxl_endpoint_decoder *cxled) @@ -3369,7 +3384,7 @@ static struct cxl_region *construct_region(struct cxl= _root_decoder *cxlrd, int rc; =20 struct cxl_region *cxlr __free(early_region_unregister) =3D - __create_region(cxlrd, cxlds->part[part].mode, -1); + create_region(cxlrd, cxlds->part[part].mode, -1); =20 if (IS_ERR(cxlr)) { dev_err(cxlmd->dev.parent, --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2072.outbound.protection.outlook.com [40.107.223.72]) (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 E97A92C08DB; Tue, 15 Jul 2025 19:12:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606781; cv=fail; b=fIy5yDEcqV/wBjZ6gg9l8Pw6WuvLMGKzsSZ/a4SKBAs7TP9OuGx1Pe9sDKMiSudt8U36k2eheehif4toCJXvlA5s0gZZ9wiCb1k+KJKriuPOxnU+YQ2idPvZJorKwdBcnTZoX9/oeC1zdAN4LND7Oi3PEc4HqkcFUEVaOE97Qeo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606781; c=relaxed/simple; bh=7rkOzc0pNXYw32ET4EPBwamRXsisiAG7bVOSj00C7mE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rUYGqddxK9szPir7vbO2GzIr3FHXvOv7yuaxU9+mSSXxTfHICaNF7OyHHBtdPBCNq8whckBdrmdLNXbHoVVlaDCEssuIBAoe9qBRucqnppUMHjpNHTpufN0Zz3481/9nLFpoofzDu2z5lKwsUTMNAwD2Wi1OOVjyoAr+4e5kP2c= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=JQ98j7dl; arc=fail smtp.client-ip=40.107.223.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="JQ98j7dl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tdIZL9n4LZ+aPNvC1oN9riJWAsSwRGGWfXWCYUNmdKOjAMIDry/irOOBlmBFKSxjVH0i7IzJGf2BlD7XxTrlcvnTNeHewdbi7WLj1UmVnnOpVZxTUdESukqg4b51rG3nYZCb9stZRBinlnxuj4Nan8KZyocdoS7S5tD0mJa5dFeigMv6dhgCN9v0lCoaIk6uR8rH49A3OYHLVyKU43WkMuBzCuKNo7DlGyfBPTE6TSnxQkZ9nqgtoGObK15/DAg6uHS0TBTwU8GNOmbX1HOXJ50cKzwKBPe0eihunJed7SlQKBziJKsDYVQgK0hAMRxkx7Wtqd3K1uMTozi0ymhseQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/Ymm3+6bxzLkLKlgBdQAgUzL3ALUtBl5vYa/b2KdOMA=; b=dEjDi26aWrbiRxDLIPU5pS47jAS1oOet12lL8XjRSsOgJe/njVC5akyCgD+AFLriPXE3KCSECE0lXDAYUcxZZ+PAz32iC9fyIumcqpcMVb3pEROtAloeO4+k4gL5ctVAwjvZU+8s4caq02QCoHi3UCQRuIP7/FiGAP+2Gle1uN/g+glGci3l/jwejdVGezXeB192TSmp6Ax/CH6cJwdZKdPisJ2WwQuqFidpI5AcZ/wf+LObDzYs7dldWu4ACwNvcjZ+l0eXOC/k+gbV2Eo11kBGPNzVcUCUmQd/oA+6JWcZYGsTGPHlPM9EX33/PzAsUA+DzWbj6+W3u9tC92NFKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/Ymm3+6bxzLkLKlgBdQAgUzL3ALUtBl5vYa/b2KdOMA=; b=JQ98j7dlYoJhjJixd3ypKGtTclY96yiH4kMktpbtWYHN0fjEpIjtnMZFot+WHFf+u1rquvQySDnxfu6hTO5RIPQPYJWbX38G0Sq9R0z6TlIsyRaHQe36lRlYX17pcBHMQeR483EtYP0xO6SYENudJ1MP+FRMZjZo8Obj2cj+iTs= Received: from BN8PR15CA0072.namprd15.prod.outlook.com (2603:10b6:408:80::49) by DM4PR12MB5771.namprd12.prod.outlook.com (2603:10b6:8:62::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8922.25; Tue, 15 Jul 2025 19:12:57 +0000 Received: from MN1PEPF0000F0E5.namprd04.prod.outlook.com (2603:10b6:408:80:cafe::17) by BN8PR15CA0072.outlook.office365.com (2603:10b6:408:80::49) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.33 via Frontend Transport; Tue, 15 Jul 2025 19:12:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E5.mail.protection.outlook.com (10.167.242.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:12:57 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:12:54 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 12/20] cxl/region: Remove region creation code from construct_region() Date: Tue, 15 Jul 2025 21:11:35 +0200 Message-ID: <20250715191143.1023512-13-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E5:EE_|DM4PR12MB5771:EE_ X-MS-Office365-Filtering-Correlation-Id: 4f479979-32fc-4f05-6744-08ddc3d39bac X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?sYzkfQD0vKhd8WHD0oFBmW8gc0lJ2xjO8BEf/35bkBANHbFOHtq22nhSGHYn?= =?us-ascii?Q?AGsaF7hZIDb/E54OIAp2ZK4uxGzyoHi376RO57S8qavKcI02D2/D/lrsSINl?= =?us-ascii?Q?Rr1pX4nDYlfZzPaDjBkYcX3DWPcYemuBSgSDWc5PFsJReJuI5v3HxYN2fovJ?= =?us-ascii?Q?XlNGDFCkyfcgW9LdrY6tDSUk32NvKjWIOOPdNcJkWgYUbEkBmYlrnZJGrcnS?= =?us-ascii?Q?DUUNyu6TwvilQfna3vmL3YeNfRJjS1HrCLcXhoUvxkBQq7wt3GssGgTCVDZ0?= =?us-ascii?Q?rkkB/SuUI5x3WLgOojdlO1SGTSTMtIUAoxx/3fIpr0Lsum4xVrWK7hxOfp0L?= =?us-ascii?Q?/CtFtEYlRo9qYQFHUJguIRUrX/aDQ8hMAYGgF7EHDGWzvSYM6NCiuobdT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p8HCXoW21O7Toy5rawRs9PSDYRLdf5ZfbnlwK?= =?us-ascii?Q?nbpTWZU0GZlM5Rn7/3Ka7IcqWokfIsfpOi/IO89I8YvKSp6fpeLktuSqL+dc?= =?us-ascii?Q?+DITYNmLD1UZqZoYkZw7pydCwJOLUqhXXFhY5Z0+uyWdpwd5GwWI1pcNEpvi?= =?us-ascii?Q?LFJyxiy5DxCQ3gupnDVKv99jPbRW+tlSReZVdXIDxXZlEsxq7xRXon1q5Lf7?= =?us-ascii?Q?ptKT9MINgZMoWKnVcgR/Br2NPFG8Y2ANHCCt?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:12:57.3246 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4f479979-32fc-4f05-6744-08ddc3d39bac X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E5.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5771 Content-Type: text/plain; charset="utf-8" Remove region creation code from construct_region() to clearly split the code. This simplifies the function interface of construct_region() and reduces the number of local variables there. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index ba59fa726cf3..f88b7f86f0f5 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3348,9 +3348,14 @@ static int cxl_extended_linear_cache_resize(struct c= xl_region *cxlr, } =20 static struct cxl_region *create_region(struct cxl_root_decoder *cxlrd, - enum cxl_partition_mode mode, int id) + struct cxl_endpoint_decoder *cxled) { + struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); + struct cxl_dev_state *cxlds =3D cxlmd->cxlds; + int part =3D READ_ONCE(cxled->part); + enum cxl_partition_mode mode =3D cxlds->part[part].mode; struct cxl_region *cxlr; + struct cxl_region_params *p; =20 switch (mode) { case CXL_PARTMODE_RAM: @@ -3367,8 +3372,13 @@ static struct cxl_region *create_region(struct cxl_r= oot_decoder *cxlrd, =20 cxlr->mode =3D mode; cxlr->type =3D CXL_DECODER_HOSTONLYMEM; + set_bit(CXL_REGION_F_AUTO, &cxlr->flags); =20 - return devm_cxl_add_region(cxlr, id); + p =3D &cxlr->params; + p->interleave_ways =3D cxled->cxld.interleave_ways; + p->interleave_granularity =3D cxled->cxld.interleave_granularity; + + return devm_cxl_add_region(cxlr, -1); } =20 /* Establish an empty region covering the given HPA range */ @@ -3376,15 +3386,13 @@ static struct cxl_region *construct_region(struct c= xl_root_decoder *cxlrd, struct cxl_endpoint_decoder *cxled) { struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); - struct cxl_dev_state *cxlds =3D cxlmd->cxlds; - int part =3D READ_ONCE(cxled->part); struct range *hpa =3D &cxled->cxld.hpa_range; struct cxl_region_params *p; struct resource *res; int rc; =20 struct cxl_region *cxlr __free(early_region_unregister) =3D - create_region(cxlrd, cxlds->part[part].mode, -1); + create_region(cxlrd, cxled); =20 if (IS_ERR(cxlr)) { dev_err(cxlmd->dev.parent, @@ -3405,8 +3413,6 @@ static struct cxl_region *construct_region(struct cxl= _root_decoder *cxlrd, return ERR_PTR(-EBUSY); } =20 - set_bit(CXL_REGION_F_AUTO, &cxlr->flags); - res =3D kmalloc(sizeof(*res), GFP_KERNEL); if (!res) return ERR_PTR(-ENOMEM); @@ -3438,8 +3444,6 @@ static struct cxl_region *construct_region(struct cxl= _root_decoder *cxlrd, } =20 p->res =3D res; - p->interleave_ways =3D cxled->cxld.interleave_ways; - p->interleave_granularity =3D cxled->cxld.interleave_granularity; p->state =3D CXL_CONFIG_INTERLEAVE_ACTIVE; =20 rc =3D sysfs_update_group(&cxlr->dev.kobj, get_cxl_region_target_group()); --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2054.outbound.protection.outlook.com [40.107.102.54]) (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 100952C1580; Tue, 15 Jul 2025 19:13:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606785; cv=fail; b=UiC/w7N29opoqa/Gq9TqZ5SpkeznMUdvoIGYaOWIlAhLB+EAFVDn0NWuiqHXr3601cxlmc6ZUTcblfN4Vt1IM9DgjNTPGZ9E7l6LI4poGCrMhzbAMq2mV342BGoxMZNuRuQ591k2QZ9k0TJoFxJoKD+GSCtrEPmFrEOqxXDYlJM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606785; c=relaxed/simple; bh=lUKcDOwFmSTbd6685WiIwqAkpp41IB62Nb2Sycfl32c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dz6x2dtWGzkz/rryBM6WofzlSA8xF5ddNpWi50HZC7cDSaKKgQH25PhNhAyvr2CwX8PFybRipvLVpcurfO/pV/rewQWbAXnrPc9tr9ucE6BGTvdDO+5UCGv1ebl+o47jhSAs6oAlmoPiNCZJcLUevfTnpFDK+c9W0Zw05g+H0tE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Woeljeh6; arc=fail smtp.client-ip=40.107.102.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Woeljeh6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=erk7XIfQeQS2lNl8qviMzJJ9f0koIeYX/8mhs8yzNZ/AK84E6MJ6Dt4CEJDF3tvkvxbR4k/bbd+BBHl2BuA/nVNvc0AEx/fsRaIQrzNGfAtjkgpe5eTPL+mXa4QkA70jRyHiDMtV8tGOYwGAlIFpQ+pNlvlexazBLNZ7CDu0zGZnn89Na5VzfN9kmB9xn9bo68qiz0sdwtvERje/daYRlawOYhvmvbRsubKeVpXtERs4cm2UCT2QPVxaoRGgd7BKcARb3LHcBVovuzH3Zce9ndq/2yE3ooMOe/VREILIDwO0CHnkHInxhbB5rET0klPm4GkNvOldP6Jk8D8+G34cCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=F0QitDETod/rta9q+e+tEsMX+fS7pTjqcBOphQQNxj0=; b=QwxxZwPuKI39v6mmVRzc1OFD6sLe8Vj5Kd+qNWnzkBbAckAXwhTrK7pnV/6EJA/02PBMVu282hd3VNkYxG5Pk9GI3AU18F9b8p684/vNepzuEyUSqPz16A7Z31S0yCsadaRkTmxSV6BpFUBpxq0TkYY9EJGv83xoEzWSnzzzlPWUJe9L3yFaCZHaQfn6JZpOh09LZ7BfeAiGku6YCeMBsjHS/Tn+LnHqO7PFq8kfTq+usrxenpNgEtjuNjcaqw0ToCjN8jJOGYcyE5vv8h5sXtP5KW1x7pDAoJxNINDJ60kSnnJIf257v5WCam/VgXtahGGGeztjpoyGuX3djboQvQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F0QitDETod/rta9q+e+tEsMX+fS7pTjqcBOphQQNxj0=; b=Woeljeh68vg43HNOi9o/gekkzytQ2md33OBqAo/Sc6AHwBhw//9EzJcvygJqWFSshCSmP3UqE3mHW9kGnMy+z8JHJSxY22/G6Xh6L/gBpT4CkLc/OyxwsX3TK3IkHlIFXG284SXvt4QtOcFK+0HpWKNr/2VkinY0C81r18ZG4jQ= Received: from BL1PR13CA0091.namprd13.prod.outlook.com (2603:10b6:208:2b9::6) by DS0PR12MB7608.namprd12.prod.outlook.com (2603:10b6:8:13b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.29; Tue, 15 Jul 2025 19:13:00 +0000 Received: from MN1PEPF0000F0DF.namprd04.prod.outlook.com (2603:10b6:208:2b9:cafe::b0) by BL1PR13CA0091.outlook.office365.com (2603:10b6:208:2b9::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8943.17 via Frontend Transport; Tue, 15 Jul 2025 19:13:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0DF.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:13:00 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:12:57 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 13/20] cxl/region: Move devm_cxl_add_region() out of create_region() Date: Tue, 15 Jul 2025 21:11:36 +0200 Message-ID: <20250715191143.1023512-14-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0DF:EE_|DS0PR12MB7608:EE_ X-MS-Office365-Filtering-Correlation-Id: 63eb09b1-6d4c-485b-565f-08ddc3d39d9e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?wrUyb7IgHVvr34lP6UnYJ9Cdh04WAfEDZF+UMSzTecxrHq8UFCP2wje0IknP?= =?us-ascii?Q?9HorBAO7nU1iy4merVFYBcSaCtn6e5sN+R0pxmh/HCBeiMM+iUe0L5/OycOd?= =?us-ascii?Q?JkGUV5nNMaooTlYrDH3gajN7ed7XmSDfqxsFBwMMCsVZGTg7fxb5hYXQtrCS?= =?us-ascii?Q?Xce0v3cO+Bz1d3QQEYaCDrG7bjk6t5rb5jnnqI2LTFUgWHyQGx1BnhXy0NoG?= =?us-ascii?Q?lZiULHKoPm+1k4ST1FIDccaen+nVzQbbLNTlcTUFP3NWflA6ttfkiQA+eL+C?= =?us-ascii?Q?fFFQvowJ84Uh2ZOSSB+o8CLfrAZA3Z+G+G5+VgnHRIB31LdpjgsxlsENQ0/4?= =?us-ascii?Q?6/YTkXCJfRHSA8regxf88ri7fk+Ic4gcdAMC+6lWSbeXDlSw5Y6C7dlksW1C?= =?us-ascii?Q?zSCd+hiY4IRGxUFNfiUZag6TJ54znqGoI6RVvz+UA/Nt/Jg5D1FCCeyr5t3V?= =?us-ascii?Q?iTpUDvHtywtLfac3MbAUZ1v0El8cWELRJ29gGfZjDqUsdrWgOwNPg4WjJdhv?= =?us-ascii?Q?/C2wRVgGZLv6Dj1CtbnASG2iRpOvD8/DfCKfLjAZNiz+nnFmMwR3XFeBzVu4?= =?us-ascii?Q?OZmpPyuhn++O2cV8E1ets13fWqb5wuxjrpZjHQmhgm82yGHpb8LuThX32Lsg?= =?us-ascii?Q?GV1w+x7NbDp6oYq3mRfIaTHpESmh/bWTL2SLxFvPTVg2k/9i5m5+pctIt+ZY?= =?us-ascii?Q?Yy/gtLdAJuBZIc3hMN2FPgOJWw1j5a+dEby4hV7vMo5vG+8kyku0/dvaojv1?= =?us-ascii?Q?2dUggzWj6W4eyCNuuFKfbqvGNFeGtBFVVygw04+ISoweCPVsjlt47/RcK126?= =?us-ascii?Q?k98QE1fcLU2Y7QvR48U82q9mg+1vgTVfrfg6h5WuSkUUN6fSAlA6ikxrA88b?= =?us-ascii?Q?v07kRf7J5U1tqZluo3P4duU8b10k58uNr3Q4x7UZ/NndDrdlqYuwesEC4LJE?= =?us-ascii?Q?Ykba8AO4pcgR6guuLzZTp0mnsr1JpIxmFXFvEiA/3RkrLkgyNVvP0dd1TWzg?= =?us-ascii?Q?wg+5HtFmNd12hrgqRrBFyLGC+9eIxPF2xtDUzUO91sNgm1jXkD3JrszzaftG?= =?us-ascii?Q?ZZ0IKDUvRX4ve7JKbQ3UfkMYdNcN9Vj5Pf7nYFISf66QhpZjOBTvJvtLTWiq?= =?us-ascii?Q?eBUz/7wzqvh44fgHIwALIpOjF671EjMjP45TYsGUEF9yxLdf1idwxea/y70F?= =?us-ascii?Q?1SSd/AcvWDPP0XCLEpk5RrFdvLR21EwUWr8doF0bYR0EVA00JI6vW0ZZiuVh?= =?us-ascii?Q?Qs0a0tDBb25sMBV2BRpzQJiBTBRz6DkZKdwvlesprd7dQe8BJkrsEfhOXasG?= =?us-ascii?Q?+urFKnvGnOcSmZeLdWBvrrdO1/CgHddPqI2NJKLLC2Lh+aiVg+5g3vnaue67?= =?us-ascii?Q?2jm/7xuGx8emd3uzMk47PrBebm7XJ08vFpmT8aVWpcP4Mmem9uHpx9dL+wHX?= =?us-ascii?Q?2Ow9XLWy4NT5WMYyGZJntQLB63TGIvpruMVSn0I6wR7o0dRJUbtmTtu4rTJ1?= =?us-ascii?Q?962Yz65ZzBDWtJhh4hxkTBS/hvILXQAIWzXY?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:13:00.5965 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63eb09b1-6d4c-485b-565f-08ddc3d39d9e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0DF.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7608 Content-Type: text/plain; charset="utf-8" To further separate creation and registration of a region, move devm_cxl_add_region() out of create_region(). Also, adjust error messages to still cover all errors in case create_region() fails. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index f88b7f86f0f5..e06cc92ad3e2 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3367,8 +3367,13 @@ static struct cxl_region *create_region(struct cxl_r= oot_decoder *cxlrd, } =20 cxlr =3D cxl_region_alloc(cxlrd); - if (IS_ERR(cxlr)) + if (IS_ERR(cxlr)) { + dev_err(cxlmd->dev.parent, + "%s:%s: %s failed to allocate region: %ld\n", + dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), + __func__, PTR_ERR(cxlr)); return cxlr; + } =20 cxlr->mode =3D mode; cxlr->type =3D CXL_DECODER_HOSTONLYMEM; @@ -3378,7 +3383,7 @@ static struct cxl_region *create_region(struct cxl_ro= ot_decoder *cxlrd, p->interleave_ways =3D cxled->cxld.interleave_ways; p->interleave_granularity =3D cxled->cxld.interleave_granularity; =20 - return devm_cxl_add_region(cxlr, -1); + return cxlr; } =20 /* Establish an empty region covering the given HPA range */ @@ -3394,9 +3399,13 @@ static struct cxl_region *construct_region(struct cx= l_root_decoder *cxlrd, struct cxl_region *cxlr __free(early_region_unregister) =3D create_region(cxlrd, cxled); =20 + if (IS_ERR(cxlr)) + return cxlr; + + cxlr =3D devm_cxl_add_region(cxlr, -1); if (IS_ERR(cxlr)) { dev_err(cxlmd->dev.parent, - "%s:%s: %s failed assign region: %ld\n", + "%s:%s: %s failed to add region: %ld\n", dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), __func__, PTR_ERR(cxlr)); return cxlr; --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2054.outbound.protection.outlook.com [40.107.100.54]) (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 971912E3AEE; Tue, 15 Jul 2025 19:13:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606790; cv=fail; b=lG1IAVCEh08LDRtfihCIP/HFyBEre5s3X0OazcDSCT2ZK/QGSrJoFFzi42KBt+qFiZuci7mw/vf1UGCE9/MCQreB0nrtyvTPnUgPIZuFlqelbBIkIhyPOwYMavZS6v/DmVLjzn0C50zeNWLbK50/waVZxm18ANc+bYHJpQA8WKc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606790; c=relaxed/simple; bh=VJlAn/M0tH8MCKLqStYcD55P1XWIFtP7ArAMCyOYr2U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aPDt/9HHCg0tcoSeurexC57uy2G0j3B2GWWzY2SdfLXn6EyvA2amMil/Anwc55Yd3cL05R6aH8r663oBRhSNDr6fewbuSwPV6PJhTjGUbxtnO7UZaRgN0Awu2U9cVh6RpQsURi3LzeR6mFa+rEG+AkKGjiY3l9yvoevqdR8YOD4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=eULrF5qM; arc=fail smtp.client-ip=40.107.100.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="eULrF5qM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=H3x4wjp2D9XNXvYzS/Y/PIRZTCz/Htapti2GwqS+WHEK1b9cc5qKc45Fi7GO+JKG3m5FFXY4vnvqhoOmBjdJSqn9UJmtjegysGulpT1l6uIk08SslAiRY7XzNNKCxmIlRnKPdyJeHPWTB5GDcMfjyEOHn4nEL7dpgWs99GlEL5B554i8P7w7xbjUjAeilBhnRfq2rxYzQZZNhNeV7Hql8qL2AA0/HgwFJNAXgpwy5zH25+WuERog9fuoV3LOPNmVzR1SV6kEhfZS7aZNTlxXJ2bznEevo78zVqTyOB6n4gKqJvUqTcloXGjn+Q9oQk1Nhy9yej2mk62wXVN6y/m48w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GTV7Lw/hIWnVAOLtWx6xTLCi3IRVg50whF3OfUC9F4g=; b=FTpnjm9l7dMKEJAHL7XN6O+DBg0w95C/RXEMUX3ZYcmHclhbIO6zula+W1ihcoqnJonXAQ1kPgeGihg1SXztoy/FjKH/EcX7CNe2Tm+RFwXViS//IOJzAWkKk+0x6L/eY11x6xVFZ5wEal1XVs4PcCGhhMw1ALpoSsdYYNp3CxIUnGAUWZJqEpuOWlo0rbG5iR6hkm7etE7kiLSWsGLKVjUkOrDOp6xVTfI4qvGeNq866xec2EWNIQc99t1ChiY6LguuWRgmnPQe84V8OZg5aQwiI/ZEtGb+yu0Q4iGRysydRxKlo5vRnSLev5nYLFVBVtsTJh/asuRWNxyc+sSwig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GTV7Lw/hIWnVAOLtWx6xTLCi3IRVg50whF3OfUC9F4g=; b=eULrF5qMlHBQeOMFezJpuYMzJzGquPFc+YjpueCEGWoLClcyB+H0RZQWWuUVS9Hlr6LqUB38iYPu/hdXpPB2ngv9HtlvMiqyb3R/7BXGPkoiJ1lHoKCUGPx5Z54X8vmU1RG8rNTZCnZpO+iX8Ydc7rzjnJnkmXgmEMHc+mdhHcc= Received: from BN8PR15CA0061.namprd15.prod.outlook.com (2603:10b6:408:80::38) by PH7PR12MB8425.namprd12.prod.outlook.com (2603:10b6:510:240::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.30; Tue, 15 Jul 2025 19:13:05 +0000 Received: from MN1PEPF0000F0E5.namprd04.prod.outlook.com (2603:10b6:408:80:cafe::ab) by BN8PR15CA0061.outlook.office365.com (2603:10b6:408:80::38) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.33 via Frontend Transport; Tue, 15 Jul 2025 19:13:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E5.mail.protection.outlook.com (10.167.242.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:13:05 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:13:01 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 14/20] cxl/region: Prepare removal of @cxlrd argument from create_region() Date: Tue, 15 Jul 2025 21:11:37 +0200 Message-ID: <20250715191143.1023512-15-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E5:EE_|PH7PR12MB8425:EE_ X-MS-Office365-Filtering-Correlation-Id: 8640800f-f1f8-4274-0224-08ddc3d3a085 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|7416014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?e/2GpkNGwDWoMFg66SXYfsv3HM6BBm1b2LRXr0lt1lD1yi/b0kLsZr0D9xFl?= =?us-ascii?Q?CrKd/gF6KR1NK1OHqvxKGcaO14Va7A3803Zg/bL7y0ys/WeaqfRYY+mwQUfd?= =?us-ascii?Q?hXESjHl9NC2hEuCtIw9zklXjbZQK2WYxske8paCNzn5l2e3DsJcH/31sSPeL?= =?us-ascii?Q?4c6/jeCQv1pPBSGxSltw+6TnLdUzUQWOAFbgJFvVtTpLLALj27HWFBEGux+E?= =?us-ascii?Q?51BMozmxJvrOi/wejf98EWl5qtRdkGa+NatgTy8JL7cEB3JVeCG2yNRy75JY?= =?us-ascii?Q?7bLsfe2rhyb2EuZXnsrFOlhCkzM3gRLh4AicrhzsaszUU69s6HpH/v1uXBfp?= =?us-ascii?Q?ZXww18268Fhc2oF5//iyESlaGqk1yBmp6Gl/QpNmzu+H8un4tuZBQMG58SuL?= =?us-ascii?Q?9o4hHNsY/Ax+fdw1oDrUMCUiD4LujcZx5yc2BMrXarPUrAOPn1yE4hE6Y5g9?= =?us-ascii?Q?trJAEC/WIVpHkOXheqrE2JORFqKk3KWkY/smt62XTbRLkd/Pw/X+QqnCz7FV?= =?us-ascii?Q?MZeHV2NDe6AkTQTjyhnG2oStCfqcrbv9kcfFzlZ7fhmU9HWlOuDcnpknqhqB?= =?us-ascii?Q?itdPcd+D9KwAEhTSISX3fjBV5W/sbMQ1TSLe6Iz2sj+zi5rVsz8B52E0IhMb?= =?us-ascii?Q?ByBnJuxWDnKWaz7sabpf3xYJt70kJ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TRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:13:05.4617 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8640800f-f1f8-4274-0224-08ddc3d3a085 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E5.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8425 Content-Type: text/plain; charset="utf-8" The @cxlrd function argument will be removed. Rework the error message and use the memdev's parent as reference device, which is typically the associated pci_dev. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index e06cc92ad3e2..9adec670432a 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3362,7 +3362,10 @@ static struct cxl_region *create_region(struct cxl_r= oot_decoder *cxlrd, case CXL_PARTMODE_PMEM: break; default: - dev_err(&cxlrd->cxlsd.cxld.dev, "unsupported mode %d\n", mode); + dev_err(cxlmd->dev.parent, + "%s:%s: %s unsupported mode %d\n", + dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), + __func__, mode); return ERR_PTR(-EINVAL); } =20 --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2056.outbound.protection.outlook.com [40.107.212.56]) (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 5422A2C159D; Tue, 15 Jul 2025 19:13:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606792; cv=fail; b=SmvLDdzYhBwI0QLNTH22LAfMbLDIDt1zfO7x29dPvMwkTXNIrPe0sJ3oMTqD+hOl2CSCAVnCP2nlF7BhjJq8PvQRmTkGMTVb25DoItt59Bd+Ia5SH/NsHIF8xjztOiwnLot/gcgIMAVS7PjZ+pXDsysjx428YmEkUja/BJziswI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606792; c=relaxed/simple; bh=tBfIr5xbBnu1Pw3spvp+np10nJb+B+o0U8RbWo8/vVE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h4+9jxUSHNdtrKyWfNLKjjFY3k37lt8E0K+StavS2z5OakGTFBJlIGsk8LLpiRV0eqm8GXvXtK5Qqk/QmYN4p3hVTBRf2CKAd7LznM6zPkv4yMNvkB2/gW5iMeLe7PNzJYOoVcqd0UxxXwUphFhhcH3OZFV1xNJm25DtZMrAgfk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=5KCEy0xh; arc=fail smtp.client-ip=40.107.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="5KCEy0xh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Mbt2bUNaOEgK0Nnb4f9KrdXCPsW+t4NSc90OxgBbhn6PpYN7WSb1hF9ZcLaPLZWskJoSsz/7l0cob11DrXVtvxkI+IiHcKesKJb/OFvyw/g5wZPrpeQkS8ABWq0cmjsvKZdSQyQdLNMJoQosxEUMIAE4Zs6wXpGsA6mMVp9EtkUXpZOC3kqWVjFPQ9rnEIGX9MvZS/38kvcp3gJ5nVSR/EMGzYw+FdfPrSvc8lr1upc0qvfiTcUmFqTOcN+/i+R5VxbImpiaHbtIAYKeGzg1E+LMzdSLEBUUowvHxGXNNuuE8AH9G3z4wUO2Z5rlMf6Ikz79kKrNxL76t3OTs0NR4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=s0PJlIvnuMl+jSinX3K5Lm16u/7zzzp3f3NSyJmB8uc=; b=rofwYIec8kENc8BsksXQgLFqDcgYxw0JYVWLqar02yJ41JwDmlBg0BrsP08/UoofkaR12acvVjibLG5txHggAXOX3gfR7+YYeeLq/tEjV7cvdz3KTtzTbYnIx0+FK4Tpa1piFW9wOS2EsY0vOBguoRFDm1ll5efA5vEsQnDRR/TK1Ab8ZEaqw6xz0o/ldNh4jq4oS8wiVIwB0KG3ck+uhAUCUJeZd3oVMIUaZks87ZWz5omcJCTsvAGnio4KRGfl3xmavFmjdLp3+XZzeWxE9LfcF2co5HlDbiyag8EP+E95cFjS3xKQ32vDWHCRtp3qnuuyNr5mjsmUx31ueWPtBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=s0PJlIvnuMl+jSinX3K5Lm16u/7zzzp3f3NSyJmB8uc=; b=5KCEy0xhfkuykETtNN1JTBx7HoIb8ab5thODtyW17ecalDdxuQcSyrmnBcR6rqwpV0x/ei/PKx5MPapPHTDjGEPrlHsCgod+aEyfqIUsOASgMP08OdJbVf0ye2qFTU6BqOUtO3EeUHw6/U1YxxY6Fj38wSMP5pCwRtbrQ5eig44= Received: from BN8PR15CA0065.namprd15.prod.outlook.com (2603:10b6:408:80::42) by IA1PR12MB6236.namprd12.prod.outlook.com (2603:10b6:208:3e4::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.27; Tue, 15 Jul 2025 19:13:07 +0000 Received: from MN1PEPF0000F0E5.namprd04.prod.outlook.com (2603:10b6:408:80:cafe::62) by BN8PR15CA0065.outlook.office365.com (2603:10b6:408:80::42) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8943.17 via Frontend Transport; Tue, 15 Jul 2025 19:13:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E5.mail.protection.outlook.com (10.167.242.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:13:07 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:13:04 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 15/20] cxl/region: Prepare removal of @cxled argument from construct_region() Date: Tue, 15 Jul 2025 21:11:38 +0200 Message-ID: <20250715191143.1023512-16-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E5:EE_|IA1PR12MB6236:EE_ X-MS-Office365-Filtering-Correlation-Id: 231912bd-3830-4abb-6da0-08ddc3d3a1c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?UfkcDxmXO80/leVGAFO7T7HXIjxpRDMloqYaQ5TFSIUgfq/Aszu3PUFxIOMj?= =?us-ascii?Q?LsDscNhaeDTUAuIWecjVzNvBgXweBzyJ4gtdkpYprKqKdIEmeTDxinSRUmx0?= =?us-ascii?Q?PonjdGwCOMp2wZsaMCU17Z+zvMZ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aS7EfO6+4e9Mz6YCOHhKleLjA1buB50Xz3L1monCuNHmPZoSWF?= =?us-ascii?Q?KbtkPmhIB4VTPGHkgmeBo4wNtZUIm0zrYyB4cEESQVOVgG+8C3rmsI7ife4b?= =?us-ascii?Q?pM4cRtTaIkbpkQBguZIEgif1yFwJDoXvjViuJAmP5lHpVfjvAFz4GMBU3BT6?= =?us-ascii?Q?fPP4ahK5JRQYOv0lpjPsBPihcE815rub3t64U716SLo+nDuCfmGoAAEJ3gWt?= =?us-ascii?Q?bCjfmt9KyCB9DOknTtBp3zR/Fa9BgrwhJDvIKqpIBlDNSz+HXhkWE8maevGA?= =?us-ascii?Q?UevttzR9wu3t+ZaWCeh4A2/E3VGNR1JHBA7X8+x35YlaJK6UJ0o95LNRVGxA?= =?us-ascii?Q?g1AOQ+UVZFq2QgMI8mYbS17IXKTBnfBpuUh158E2QV4nQBppojf9dcoovkqj?= =?us-ascii?Q?u79Q4qBDtR0dlCCl7K1yGybtSgvS877/PR6dddMssq3b4grMZwM4Fy2gnwUa?= =?us-ascii?Q?lQfbmaSwvte9z8j859C2qlAU5YIoc9dzcpqZ?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(376014)(7416014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:13:07.5622 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 231912bd-3830-4abb-6da0-08ddc3d3a1c5 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E5.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6236 Content-Type: text/plain; charset="utf-8" The @cxled function argument will be removed. Rework all error messages and use the root decoder as reference device. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 9adec670432a..81ff9956a128 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3393,7 +3393,7 @@ static struct cxl_region *create_region(struct cxl_ro= ot_decoder *cxlrd, static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, struct cxl_endpoint_decoder *cxled) { - struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); + struct device *cxlrd_dev =3D &cxlrd->cxlsd.cxld.dev; struct range *hpa =3D &cxled->cxld.hpa_range; struct cxl_region_params *p; struct resource *res; @@ -3407,10 +3407,9 @@ static struct cxl_region *construct_region(struct cx= l_root_decoder *cxlrd, =20 cxlr =3D devm_cxl_add_region(cxlr, -1); if (IS_ERR(cxlr)) { - dev_err(cxlmd->dev.parent, - "%s:%s: %s failed to add region: %ld\n", - dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), - __func__, PTR_ERR(cxlr)); + dev_err(cxlrd_dev->parent, + "%s: %s failed to add region: %ld\n", + dev_name(cxlrd_dev), __func__, PTR_ERR(cxlr)); return cxlr; } =20 @@ -3418,10 +3417,8 @@ static struct cxl_region *construct_region(struct cx= l_root_decoder *cxlrd, =20 p =3D &cxlr->params; if (p->state >=3D CXL_CONFIG_INTERLEAVE_ACTIVE) { - dev_err(cxlmd->dev.parent, - "%s:%s: %s autodiscovery interrupted\n", - dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), - __func__); + dev_err(cxlr->dev.parent, "%s: %s autodiscovery interrupted\n", + dev_name(&cxlr->dev), __func__); return ERR_PTR(-EBUSY); } =20 @@ -3439,8 +3436,9 @@ static struct cxl_region *construct_region(struct cxl= _root_decoder *cxlrd, * prevent the region from functioning. Only causes cxl list showing * incorrect region size. */ - dev_warn(cxlmd->dev.parent, - "Extended linear cache calculation failed rc:%d\n", rc); + dev_warn(cxlr->dev.parent, + "%s: %s Extended linear cache calculation failed rc:%d\n", + dev_name(&cxlr->dev), __func__, rc); } =20 rc =3D insert_resource(cxlrd->res, res); @@ -3449,10 +3447,8 @@ static struct cxl_region *construct_region(struct cx= l_root_decoder *cxlrd, * Platform-firmware may not have split resources like "System * RAM" on CXL window boundaries see cxl_region_iomem_release() */ - dev_warn(cxlmd->dev.parent, - "%s:%s: %s %s cannot insert resource\n", - dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), - __func__, dev_name(&cxlr->dev)); + dev_warn(cxlr->dev.parent, "%s: %s cannot insert resource\n", + dev_name(&cxlr->dev), __func__); } =20 p->res =3D res; @@ -3462,9 +3458,8 @@ static struct cxl_region *construct_region(struct cxl= _root_decoder *cxlrd, if (rc) return ERR_PTR(rc); =20 - dev_dbg(cxlmd->dev.parent, "%s:%s: %s %s res: %pr iw: %d ig: %d\n", - dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), __func__, - dev_name(&cxlr->dev), p->res, p->interleave_ways, + dev_dbg(cxlr->dev.parent, "%s: %s res: %pr iw: %d ig: %d\n", + dev_name(&cxlr->dev), __func__, p->res, p->interleave_ways, p->interleave_granularity); =20 /* Pair with cxl_find_region_by_range() in cxl_endpoint_get_region(). */ --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2050.outbound.protection.outlook.com [40.107.236.50]) (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 E5D822E4275; Tue, 15 Jul 2025 19:13:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606798; cv=fail; b=PsmlZRbvCNc6r0ggAatIkhFnd/wVGsezeBke8FUjAqE7s/5pt8duHgpT7Qnn+8H2dzS6QwH7TUdUCWwZL81LAk1xPj0hRwFR/9G344gtL7NbH0JZd7uSTc4JeujfJ3g/Nz1o2CfmbV9Am5MHUYqT0ja53Z7u6kWoOavoEz6lflk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606798; c=relaxed/simple; bh=hTc6Zudht4VurUuMqqJfz4ga/sj3ijr7WFOpVzhdags=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nfEohkmk8PV5UrqJs6Brihllr8WQxC/Vg87AvKxSotpFpH82qPeXQHpzVSmbZNbtdgd5MRHLwI6uvJawW1iPeLeunC4J8TriPh3O3YUD6bnAn6I5bzncVfe/Z3Vgkd+zfiblTVkHny+Z7j4P3sz37s4PNc9aNEz96GLLbTAAmVA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=YBs1HH63; arc=fail smtp.client-ip=40.107.236.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="YBs1HH63" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qKsQJcRMMcZ1Vf5cU3uY4fHMvbSB3gk/nCvCSAS5L4xRTM7mrGCZUwOFvFJ9GuHG4H/t0f9tV8PjJeil/alvqmaXp0u2WyW2wBfJClRicoDf1r9925zOT+AdLTZT7gJGSozKwVygEIVKBYLY2RfS026gKikDGRWK+VJm+wny67d4XnQ2MX5t8pu4AAIFX3DxnHxVhCkEuP5ymHh62bZv7pNswfqpcx1DLPFSykf+jQH6Ejg11mg8ycyqeswJ9Gb0g77uVSNt0iQf8UF9St4tsfc6Rg9N6jz2IF0UGox4z/Mge+R43rS1hjrrIa8DNHmS0qZUYL2FLckS+4sfMeqDDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0M1m0Dtye9vC9n16riLzOtCiIVg3iyYJZyk66Ms8Uvs=; b=q0efxYMwccQdeIJ6q5Ab+84OsM/B7XXz13+Sb8p+F6FdXoLnt4AVSL9IsO1ZJNKz4ePcBOJWyo6lI7IUcEn0mH3eVsXWXC6OgUWtkP29ZbSTVu4XloS85TR/UaA4sLAncA///y9lBEhJG77p3q5mzkQGR9ktNDNwnCLoUaUyHAwlzch2Nq8L+Qf4a1dHG3UsHBr1GDoMmJPX7oTEUTjwhRbzeftsyz4vjaYr2pDNDBm4kGblU9vudu9yOh9Kz0yO98GDbLtUuSiB5n3tku8lpMK6hJlscZhtVfzmk/kx3KEuZP0UroZW5fyc4oxk9Oz2WJSUc7neKfIuwvM6eI+LFQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0M1m0Dtye9vC9n16riLzOtCiIVg3iyYJZyk66Ms8Uvs=; b=YBs1HH635EzGSN1ZgPrVfD5FhxWtq8c4C6REqjbq5dvnMAkXsVTwQ1yd8bgMjGtnBMkNJC9w/955jHAgaxRlSbimvyxoY26V3uzZifDGZZ3voVCvh70qik39AGs/HGH35s1ENviqq/C69MQgNSZEAIqFLBPOILYxIbEob8ER2Oo= Received: from BN9PR03CA0328.namprd03.prod.outlook.com (2603:10b6:408:112::33) by DM4PR12MB6592.namprd12.prod.outlook.com (2603:10b6:8:8a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.20; Tue, 15 Jul 2025 19:13:11 +0000 Received: from MN1PEPF0000F0E3.namprd04.prod.outlook.com (2603:10b6:408:112:cafe::c1) by BN9PR03CA0328.outlook.office365.com (2603:10b6:408:112::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8943.17 via Frontend Transport; Tue, 15 Jul 2025 19:13:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E3.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:13:11 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:13:08 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 16/20] cxl/region: Introduce @hpa_range to struct cxl_region Date: Tue, 15 Jul 2025 21:11:39 +0200 Message-ID: <20250715191143.1023512-17-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E3:EE_|DM4PR12MB6592:EE_ X-MS-Office365-Filtering-Correlation-Id: 768133f5-d53b-4ddf-088f-08ddc3d3a40a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|36860700013|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?exwerZaCsvu+zX45ey2EM5TrGour4Q5PUKmU6np9IzUPfBlaTey9LmuYkdjK?= =?us-ascii?Q?Pj1X2+bq7s+717ngy07yx+Rctzf2Dko4iiXREWFs3E+v5CsCgYOkkznF/TpS?= =?us-ascii?Q?GqEXo4vJJ/nL4JLaPF8RSyNvI6AxHXn2QCEBBIBiuNo09CClZhBeejYfIZ//?= =?us-ascii?Q?5D3Yvd/54ib5OVJpEWSv1AYeNLkSwuIm4bwiNbYizTGxO0CIwNSSi6Q7WZDS?= =?us-ascii?Q?k4GWPcr+5Ac1TiASFyVHHx1b3+EwctcFWrJ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ascii?Q?ytS5XA6jDyuGgX5w/mDi9TuBWG7q7qc6O6IHQIMXzxrocNzPBwBaN9f7jEKe?= =?us-ascii?Q?Rsxx8eX9MgzhVWajZsoXNpURfIj2Ogc3HCPsQ9fMSF8DpJMQWkA6jNmZ0ER7?= =?us-ascii?Q?yivVwPnzYGgJ58vD9VKbRYKhj8mQxbM24lq/e7oaBDQJIfFH/n0SpYxjMQgz?= =?us-ascii?Q?4ypIl347BhfBOl8sYzBK2i1bKim0NmzS7u1FWGrzmaLJTtgMG4TcAk5enh3O?= =?us-ascii?Q?NTQUbRDPHBmgv8JBwYGsoZxF+DZGbOGJij4oKdBySBMf6AuSN7HzVJ+oKJPd?= =?us-ascii?Q?ZdY22zwt08oFGwSJ0DhWVqwvbslwftfaIFxQOIYdwrvrlpMMtVvKKp1SGvON?= =?us-ascii?Q?by/MGi5q+4wT3Ab2voDkLR1ip3SBotDS4o/H?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(376014)(36860700013)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:13:11.3672 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 768133f5-d53b-4ddf-088f-08ddc3d3a40a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E3.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6592 Content-Type: text/plain; charset="utf-8" Each region has a known host physical address (HPA) range it is assigned to. All assigned ports to that region share the same hpa range. The region's address range is the system's physical address (SPA) range. That is, for regions there is hpa =3D=3D spa. As systems with address translation have hpa !=3D spa, track the region's spa range and introduce @hpa_range to struct cxl_region. The introduction of @hpa_range also helps further reworking construct_region() in order to move the create_region() call out of the function and remove @cxled from the parameter list. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 18 ++++++++++++++++++ drivers/cxl/cxl.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 81ff9956a128..7e21946072a5 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -653,6 +653,11 @@ static int alloc_hpa(struct cxl_region *cxlr, resource= _size_t size) return PTR_ERR(res); } =20 + cxlr->hpa_range =3D (struct range) { + .start =3D res->start, + .end =3D res->end, + }; + p->res =3D res; p->state =3D CXL_CONFIG_INTERLEAVE_ACTIVE; =20 @@ -689,8 +694,14 @@ static int free_hpa(struct cxl_region *cxlr) if (p->state >=3D CXL_CONFIG_ACTIVE) return -EBUSY; =20 + cxlr->hpa_range =3D (struct range) { + .start =3D 0, + .end =3D -1, + }; + cxl_region_iomem_release(cxlr); p->state =3D CXL_CONFIG_IDLE; + return 0; } =20 @@ -2496,6 +2507,11 @@ static void unregister_region(void *_cxlr) for (i =3D 0; i < p->interleave_ways; i++) detach_target(cxlr, i); =20 + cxlr->hpa_range =3D (struct range) { + .start =3D 0, + .end =3D -1, + }; + cxl_region_iomem_release(cxlr); put_device(&cxlr->dev); } @@ -3354,6 +3370,7 @@ static struct cxl_region *create_region(struct cxl_ro= ot_decoder *cxlrd, struct cxl_dev_state *cxlds =3D cxlmd->cxlds; int part =3D READ_ONCE(cxled->part); enum cxl_partition_mode mode =3D cxlds->part[part].mode; + struct range *hpa =3D &cxled->cxld.hpa_range; struct cxl_region *cxlr; struct cxl_region_params *p; =20 @@ -3381,6 +3398,7 @@ static struct cxl_region *create_region(struct cxl_ro= ot_decoder *cxlrd, cxlr->mode =3D mode; cxlr->type =3D CXL_DECODER_HOSTONLYMEM; set_bit(CXL_REGION_F_AUTO, &cxlr->flags); + cxlr->hpa_range =3D *hpa; =20 p =3D &cxlr->params; p->interleave_ways =3D cxled->cxld.interleave_ways; diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 58c9db0bfb93..cdca44556039 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -509,6 +509,7 @@ enum cxl_partition_mode { * @dev: This region's device * @id: This region's id. Id is globally unique across all regions * @cxlrd: Region's root decoder + * @hpa_range: Address range occupied by the region * @mode: Operational mode of the mapped capacity * @type: Endpoint decoder target type * @cxl_nvb: nvdimm bridge for coordinating @cxlr_pmem setup / shutdown @@ -523,6 +524,7 @@ struct cxl_region { struct device dev; int id; struct cxl_root_decoder *cxlrd; + struct range hpa_range; enum cxl_partition_mode mode; enum cxl_decoder_type type; struct cxl_nvdimm_bridge *cxl_nvb; --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2071.outbound.protection.outlook.com [40.107.95.71]) (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 140832BF3DF; Tue, 15 Jul 2025 19:13:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606799; cv=fail; b=MCeX/LHWUg0ksg08nILgrz5YV4zJg6hgssXfYK1aJlz3M2keJlAWKEgXmR1jgr6+1yfJSopo4B7BI6qGnyYU0mvo/NELP46PBqErL8Sj420c7JpiGvQzPuB0znh5sIjGX2j54l7xF4pzG6vkJrntQN/vVE0+2mRvTE5YOw6bmOo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606799; c=relaxed/simple; bh=soOF9h3wFmnbioLrUOc9eV0EwXtAYDTdzXmVDVGpdeo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o/tVEPx8JEsi67P3HjY1F/uD96q452/YvImgrs5W70Hj9FmKe0V6i58/vQKRDG7UcTT+tX919VTgO2x1sksnlpsJmNnHRjFKOdGdO5vE5e11lxGwKjFSztx9YMUyoMs1rftJTCMnpEopEOcLmS9NgdvEu3bgZLBf825IStKy/+Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=xTxGVqTV; arc=fail smtp.client-ip=40.107.95.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="xTxGVqTV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KkJzvNGw/g9JA6T4jxC8bZ2SpJIR8qEob9MEjKXo2M/kd+D/QKHY0COvEOIlRX9IpM2hk694JIyKiOSx9y8DNhrG0C/mC+ShsrzqNLvz+Ql4X+dl3hiY9xHqMM5o89p9aRoJs2gfisr/gDaVBx6OAD/CgiIY4yUp7dALn2GFY8hmFBoYYHEub2ADCykjqDSLJDgB0w1Cd69nnyfwlyCfIwHDpbp9EJgk6HCfHzyhJC0W4bMlrYY67guynOGbYSK4oiwXw5vgjOZbE44VPVoELejgu9eiNJi2msoEYSIMriaa5sRDzbYihxokdYRiws0hUialHkx14Kc0T3zx7MgY8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=O/LUlWHZBl0viWNFdTOh+eOl/Gxsttp9OAcvUdIIJQ0=; b=cVhH7x2qabu/8e0hmyz1drV4iefCNHtrzy5Malsiqwpn+XDvbv7N+eI5InSjZBr3GLZL4VIZ8sr3SFM57VGNACv1dIIpihY8OzhOwXUF19H+ht41P06iD5gB63Nh5jD2LqrB7jZOcFAxjoXMe9kAWBVm11xp3TlMqxu2kHv8Ke0jWjKdvwTZHPYrOCPA+eAScZQpJOOq0kEdB2Tl62SwAPXS8k8vGNYRPm+4fp5SFwI+16MW3bKCqpK3Y3ZM+f8qO6YANqkA7xch6coZGE8hvrYUvbexvLD9YP3sypqLvfmb+oqt3pVdhWkvqTEadyCyleZViiQSE8G9GRsZMeuDCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=O/LUlWHZBl0viWNFdTOh+eOl/Gxsttp9OAcvUdIIJQ0=; b=xTxGVqTVn8ROWaShkfQ0f1nVQ/iK6zElpxWhVb+E1gYb+2Gvud7Vqr0xWSJaaF9UEDZKcVxoew5xR7AmyFfRzSkDZ2JVtXunFs79x5m5xu/FgEn22t14Q4qufLiCIjd3iVSvfeBvQPJj6IdbcyeaDi2M3yNZ+9kxr6PLrfGqAqo= Received: from MN0PR03CA0022.namprd03.prod.outlook.com (2603:10b6:208:52f::21) by IA0PPF44635DB8D.namprd12.prod.outlook.com (2603:10b6:20f:fc04::bcc) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.25; Tue, 15 Jul 2025 19:13:15 +0000 Received: from MN1PEPF0000F0DE.namprd04.prod.outlook.com (2603:10b6:208:52f:cafe::34) by MN0PR03CA0022.outlook.office365.com (2603:10b6:208:52f::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.33 via Frontend Transport; Tue, 15 Jul 2025 19:13:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0DE.mail.protection.outlook.com (10.167.242.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:13:15 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:13:11 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 17/20] cxl/region: Remove create_region() call from construct_region() Date: Tue, 15 Jul 2025 21:11:40 +0200 Message-ID: <20250715191143.1023512-18-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0DE:EE_|IA0PPF44635DB8D:EE_ X-MS-Office365-Filtering-Correlation-Id: 5bd92de5-565b-44f8-766b-08ddc3d3a67b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|7416014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?61ImbZz7Du3XSWAfaEYgtJLDTivSyYEq4dFwOT1axpBWnLyb9D0CAa7do8r6?= =?us-ascii?Q?VPYPbHX6JU311SokGFvKy/ZIFGBuzugdbkT272+q9cu2UAu6RbZuoZw/CIZb?= =?us-ascii?Q?RcUaQbwK6pJ5Ma+O3bIV8kjQOm9orpIWIKLewMNL1QJnmsm5+r2BW3V6o749?= =?us-ascii?Q?N3Hun1DVq5957c4WYo+hlbzIceT9JlFIHqv2/HoBg/1W84WCC6UejyTZ2fqD?= =?us-ascii?Q?FHD7AsnG+A+diZbMX4HnxwXmXVWF+vRcqEgb2FmxYBsbAh67GPyQHetG+pN5?= =?us-ascii?Q?JUba3EUFETXkSK3D7EhqSUpHRwKZeDhjiFMfN7SAwLvdnwzqqDUKABVX1+Fl?= =?us-ascii?Q?I9dFEMrHDbAvyGO4VSfQCPqGti/ykncpllSq+5P1Kt6F3eEFtYuVU9lgrnfr?= =?us-ascii?Q?N80Gi2C4dnMWifhqq7+IN031q5gFCF5p87kkZi0ekgGQFpYVbebGsUWXlg4e?= =?us-ascii?Q?4R0bPJLa1zvnn/GTTK4VStFEsOjVO/AeS3MrBWsrOupVeoR4IMf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yAODexKsaa7kI71Fb4zLpyqhDp5zlJ?= =?us-ascii?Q?IMlpmoIL0WSmij8AA0xk2ynUVeLTQrCuuls60be1cqdbCAdcumcqT95+IbwC?= =?us-ascii?Q?NEHt+W3GxBTQhHmSiM09uXPfFfTiVIQdxSBZ?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(376014)(7416014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:13:15.4621 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5bd92de5-565b-44f8-766b-08ddc3d3a67b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PPF44635DB8D Content-Type: text/plain; charset="utf-8" To separate the creation and construction of a region, remove the create_region() call from construct_region(). This makes the @cxled function argument in construct_region() obsolete, remove it and instead start using @hpa_range of struct cxl_region, which is initialized using the endpoint decoders hpa range. The region creation is moved to cxl_endpoint_get_region(). Use put_device() to remove the created region if another region is found for the same hpa range. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 7e21946072a5..a81278fbb0ab 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3363,6 +3363,7 @@ static int cxl_extended_linear_cache_resize(struct cx= l_region *cxlr, return 0; } =20 +/* Establish a region for the endpoint decoder */ static struct cxl_region *create_region(struct cxl_root_decoder *cxlrd, struct cxl_endpoint_decoder *cxled) { @@ -3407,23 +3408,17 @@ static struct cxl_region *create_region(struct cxl_= root_decoder *cxlrd, return cxlr; } =20 -/* Establish an empty region covering the given HPA range */ -static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, - struct cxl_endpoint_decoder *cxled) +static struct cxl_region *construct_region(struct cxl_region *__cxlr) { - struct device *cxlrd_dev =3D &cxlrd->cxlsd.cxld.dev; - struct range *hpa =3D &cxled->cxld.hpa_range; + struct device *cxlrd_dev =3D &__cxlr->cxlrd->cxlsd.cxld.dev; struct cxl_region_params *p; + struct range *hpa; struct resource *res; int rc; =20 struct cxl_region *cxlr __free(early_region_unregister) =3D - create_region(cxlrd, cxled); - - if (IS_ERR(cxlr)) - return cxlr; + devm_cxl_add_region(__cxlr, -1); =20 - cxlr =3D devm_cxl_add_region(cxlr, -1); if (IS_ERR(cxlr)) { dev_err(cxlrd_dev->parent, "%s: %s failed to add region: %ld\n", @@ -3444,6 +3439,7 @@ static struct cxl_region *construct_region(struct cxl= _root_decoder *cxlrd, if (!res) return ERR_PTR(-ENOMEM); =20 + hpa =3D &cxlr->hpa_range; *res =3D DEFINE_RES_MEM_NAMED(hpa->start, range_len(hpa), dev_name(&cxlr->dev)); =20 @@ -3459,7 +3455,7 @@ static struct cxl_region *construct_region(struct cxl= _root_decoder *cxlrd, dev_name(&cxlr->dev), __func__, rc); } =20 - rc =3D insert_resource(cxlrd->res, res); + rc =3D insert_resource(cxlr->cxlrd->res, res); if (rc) { /* * Platform-firmware may not have split resources like "System @@ -3491,7 +3487,7 @@ cxl_endpoint_get_region(struct cxl_endpoint_decoder *= cxled) { struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); struct range *hpa =3D &cxled->cxld.hpa_range; - struct cxl_region *cxlr; + struct cxl_region *cxlr, *new; =20 struct cxl_root_decoder *cxlrd __free(put_cxl_root_decoder) =3D cxl_find_root_decoder(cxled); @@ -3504,15 +3500,21 @@ cxl_endpoint_get_region(struct cxl_endpoint_decoder= *cxled) return ERR_PTR(-ENXIO); } =20 + new =3D create_region(cxlrd, cxled); + if (IS_ERR(new)) + return new; + /* * Ensure that if multiple threads race to construct_region() for @hpa * one does the construction and the others add to that. */ - guard(mutex)(&cxlrd->range_lock); + guard(mutex)(&new->cxlrd->range_lock); =20 - cxlr =3D cxl_find_region_by_range(cxlrd, hpa); + cxlr =3D cxl_find_region_by_range(new->cxlrd, &new->hpa_range); if (!cxlr) - return construct_region(cxlrd, cxled); + return construct_region(new); + + put_device(&new->dev); =20 return cxlr; } --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2079.outbound.protection.outlook.com [40.107.92.79]) (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 31CD02E49B2; Tue, 15 Jul 2025 19:13:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606803; cv=fail; b=k1yF1yLwISrCqXNa8b8GgSZT2ksM3+25Vdt1f/YU7zSIjYlgPZNp5+Jj+98BUAbCt85oKw1n63UuI2xc8YKzRzHBqRE4EC3epKXOBaaPe/mI0xZsrb7V3QCu4Iwm+C+6h/QpWYICxWLUm05OrhVL3BwQMmIcnV7k6++dBz4BNTA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606803; c=relaxed/simple; bh=YqYRD6cMmeU8zWvgKtTZTaMTlw/d3KZydlJoUkAY5wU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CS7gmi/A0j6JGgxnpOz8zQKAqG02/BuviEgCBdBAESX7eDoVdJ/aLpl9hPnJzW6x5ZZjRCxhuOHs1A84/+isWFkxqPPSDIbpKomxxHctCLQskyWSoB87ICIcR8y6x7FGzeX3WN/MGOLbWzJ0yfMhyZVlHS/3/hHqviI5R0gqfLQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=TShaogew; arc=fail smtp.client-ip=40.107.92.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="TShaogew" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NgCTrIwKVHbeE83T6HTH8tOEueqMyH4mGBwAPzLrZkNhnbb3Kc11s9Zm64hTSZkUvJp212oOcKMxqAY55KyZK6GlCOBsBMKOOwI/faMh9wq2BUGIsMh+J2Kmavdg0LNpHL9MLwRfpGWUFRTLQp3cUysz5GQBxLMaVzu6Gu8/sgc05LqxAr3uNJA4b/Nn3e3NWqc/sPtvYnMQP5zm/YMq9qF97OlRyfFoBMZbJtU2nxjPI8q7tgYWh9pocJI86mp6uiLBhpJnFUV/znddEOMO388p/E5St1nBhpHEpNsYHo+acLJ059NdORMzWj1ZcVfTamArqvPShtsACNv4wsp98A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZAbupYQwRFPKUHjGa7BBisamIazRMX4m8XgRJrCoRFg=; b=vBnSeyPQPsCfPo/dRvNjULgo6F8pjq0NQ4VjBUaYR0o0LTnxtqCAAo9YW14kpyMHmB7R67Ihnen9JCSrdrpB+kSc1/IhD7QJ9ML2tv/NQ/Vwsu9apomFekt4fubR+O4xZ48qQh1ARdbb+LERIaXavzJjgcCK0TifH/lGIwwhIP9OXiZHe3BAbgTWQxY6HmVNNHaAYyVF5kQ4ubdbJ2A9G+zPw7NJy0cyxw9zsryS0wvk8aOEqz84H4la2/BPHsC5XlA0Kec+2juqUKrreSdRBbfNnDBmToUvyxvfRea0XTXSsklFO/XoI9hUdSz169cbXPAz5AQgfulpxNGB0LaIVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZAbupYQwRFPKUHjGa7BBisamIazRMX4m8XgRJrCoRFg=; b=TShaogewQpMbxPeOJh4DyYl3edBjL7sFtmpMWMBD5nZBn59U9czy3FRtC9Fdp2BxySg0lNx8/Y97g22M2Zu0nUA1Yk89ltluTAl9Sy7oLtrH/LnyqHNBV30M3rTJnrOks4Q5kRyQFHQYRzkLlXiMXk5wiZkfeuxsBsJUjzGzOLs= Received: from BL1PR13CA0103.namprd13.prod.outlook.com (2603:10b6:208:2b9::18) by SA0PR12MB4480.namprd12.prod.outlook.com (2603:10b6:806:99::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.35; Tue, 15 Jul 2025 19:13:18 +0000 Received: from MN1PEPF0000F0DF.namprd04.prod.outlook.com (2603:10b6:208:2b9:cafe::43) by BL1PR13CA0103.outlook.office365.com (2603:10b6:208:2b9::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8943.17 via Frontend Transport; Tue, 15 Jul 2025 19:13:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0DF.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:13:18 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:13:15 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 18/20] cxl/region: Determine root decoder in create_region() Date: Tue, 15 Jul 2025 21:11:41 +0200 Message-ID: <20250715191143.1023512-19-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0DF:EE_|SA0PR12MB4480:EE_ X-MS-Office365-Filtering-Correlation-Id: 02f16205-a1d8-4367-16e1-08ddc3d3a83b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?OzU9dkPm/lCL4pWghJja+nL/1GRnHzgSHvDfYoCpcyYWge20gD6O0CO8PgmQ?= =?us-ascii?Q?DWy/F/H7jEpFwmyK9qGEbRVh3hM5tQ5eNVgO0WIn9OmMFipJYVRffXe9f5Il?= =?us-ascii?Q?SX4NZa9p9HtoPP24wFI3yuC6/SDJGeb9w7exzqAt7HJLOm2pgM+HzqwaWffA?= =?us-ascii?Q?sWgt8zxN5qK6BAAS8S9KI5HHnapIzXFbvCXG66ODKrYyMd2eXcSb7R1QlxGU?= =?us-ascii?Q?1J1Ihi0HH8bVctqgT+vTUb9X2O/VnLqf5mvM0CX0HuZVq1hnUyxo/j/5NgRm?= =?us-ascii?Q?/KZF1kJ2uH1DK5/GFAB86cnj6iqnAj/VltQ01l8ptHYVn7VUgqiMpC9BxJbX?= =?us-ascii?Q?b+PDSMYdJthMa3a0Ko0VhxGqsmoQXz095pe6xcfY7P2hFpM0/H+mspeLLBBZ?= =?us-ascii?Q?1/ikLwbgj4ld6v+6YnHg4XXbjzdnr/eVPl6ytbSKrQsDQeeaYQfcATIinz7T?= =?us-ascii?Q?Q3/U1IhbuFbj4S3D1apeoycclo12mNO2Dm+0PM+Hj8GyfmZuNarab9adkDzJ?= =?us-ascii?Q?2EiUbzOTFIMaS5qc4FF0Gsl93zaKfUyC0Eny/hX3PmGSMFhAnTBY17VTHFii?= =?us-ascii?Q?CEMLPPUymj00L5KSH87jAIFAx9NH1SWrBrGUA2qsAOqbRczd6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FS+N4HpSGHhqEl2KqSrKT0WJhj7PWr+an?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(82310400026)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:13:18.3999 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 02f16205-a1d8-4367-16e1-08ddc3d3a83b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0DF.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4480 Content-Type: text/plain; charset="utf-8" Each endpoint decoder is a root decoder assigned to. It is determined using the endpoint decoders HPA range. Move function cxl_find_root_decoder() that determines the root decoder to create_region(). Remove the @cxlrd argument of create_region(), it is no longer needed. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index a81278fbb0ab..8faef2b2ee05 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3364,8 +3364,7 @@ static int cxl_extended_linear_cache_resize(struct cx= l_region *cxlr, } =20 /* Establish a region for the endpoint decoder */ -static struct cxl_region *create_region(struct cxl_root_decoder *cxlrd, - struct cxl_endpoint_decoder *cxled) +static struct cxl_region *create_region(struct cxl_endpoint_decoder *cxled) { struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); struct cxl_dev_state *cxlds =3D cxlmd->cxlds; @@ -3375,6 +3374,17 @@ static struct cxl_region *create_region(struct cxl_r= oot_decoder *cxlrd, struct cxl_region *cxlr; struct cxl_region_params *p; =20 + struct cxl_root_decoder *cxlrd __free(put_cxl_root_decoder) =3D + cxl_find_root_decoder(cxled); + + if (!cxlrd) { + dev_err(cxlmd->dev.parent, + "%s:%s no CXL window for range %#llx:%#llx\n", + dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), + hpa->start, hpa->end); + return ERR_PTR(-ENXIO); + } + switch (mode) { case CXL_PARTMODE_RAM: case CXL_PARTMODE_PMEM: @@ -3485,22 +3495,9 @@ static struct cxl_region *construct_region(struct cx= l_region *__cxlr) static struct cxl_region * cxl_endpoint_get_region(struct cxl_endpoint_decoder *cxled) { - struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); - struct range *hpa =3D &cxled->cxld.hpa_range; struct cxl_region *cxlr, *new; =20 - struct cxl_root_decoder *cxlrd __free(put_cxl_root_decoder) =3D - cxl_find_root_decoder(cxled); - - if (!cxlrd) { - dev_err(cxlmd->dev.parent, - "%s:%s no CXL window for range %#llx:%#llx\n", - dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), - hpa->start, hpa->end); - return ERR_PTR(-ENXIO); - } - - new =3D create_region(cxlrd, cxled); + new =3D create_region(cxled); if (IS_ERR(new)) return new; =20 --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2075.outbound.protection.outlook.com [40.107.101.75]) (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 482C42E2EEB; Tue, 15 Jul 2025 19:13:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606805; cv=fail; b=sqIdcvaExd3hnci0ylatZrQHndao3WJNssih4Af07IfX+3ZN/4PW2A85iChD2DJnfPKvP6RzAqbN/IssXmhrCYJ6g2lAxTmrdISJCd5eH2Z8Ryph2UH8QDQhHjRf91uf+6G+Vsx2/OYczyM0B8N8/KBpV+kas+wprNSpj8JTXqI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606805; c=relaxed/simple; bh=q7/Quzog/z1S7GdBmQNKcSjWKXQfNqcSDOvx121aSAU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JcnhLM5m17mjStbKRnTr9t61hYzsVaNL4rQfWjbt7VuxDWJGCzxH9nLu0BV0xbVlh+GRkPMlrw705QbjDpe/V9cUMvb4gf0KM+kRwiZfCyuz6qWM9tUh2MFzpkJSzUqb6037cfRwR6g2q4Bq2DYhTZsoo3TQVVyG7i0AVDEz4/Q= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=e07XADwC; arc=fail smtp.client-ip=40.107.101.75 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="e07XADwC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aASpwme+rv1TknGFVyc3n08Z6rBdYpPrdbi3+rVnKz9x8b/9gpNcX/ePrG9S504uDK1MdyMlQI5NPI/VL3d5oLrD0HIAzSNFnGoL9d12vwaBW/bUwitKOekamOLfPjTyXWe6lbo490tg1FvtjLXroEcJm/ZyE4FeXFDxwTX4Aguuscg4ntdR7/BYbCftRWs34fkgNaDQzGOqUyiCaLplhHEjTaCs1rG7NALTZRvoUA2ECCiA9JL/0gnrPbF6VR9cLa6yG6i3nARSdScQlv7c/5BsdPkubxFJCMq2qhzojf3y+fdPxkdv2FBdYyQ228ibPS/iU6/+6awFY0X18AwV5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FAfWeQxiBLO4H/xWl3X7UtxdCFjhWh2Bgk5OZ+6FXJg=; b=Oji+aoqLSKU8g02J2fyJbM/83QF7wx5qjedyPfjGcAoKvCJ7UnNgKrpHhuMYG5FvPqCNyrlfo648pYZb2hpJFK0NYPaKSOYHY4+ok8QsNCTQFxcJeRPj4iiJzhP83xx2ZlopzU0DqvPV4f8PyDBOB7BeRSZJjn/wGDqS+uqdTLDrmRg8cV8sJikrG/briSkpDfDE6NuOqPWZWdOykacAlqteFMcY5akyfupVXA5pc6nddGfnvHDpNXj8aRT/3a5UzgPvGMY8/SoDnuxllqTnx+TJNEGbpUPouP2iQru4DnhuWloqmwGRoYWCk4QjHxufG4GhkidJehzbELk32tsJ/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FAfWeQxiBLO4H/xWl3X7UtxdCFjhWh2Bgk5OZ+6FXJg=; b=e07XADwCKheuWgx2atWbppRUX5DwElZj7qsM3uiytdN8ncBXw6eRqRDZd7pNTiJnSJQHm3YHdQ5rMEJmZ4nhKUfoUBWQrGx0fQdMDB6QK99gnz6jHKcJYJugDVNeSNGBQO+db/etHoh4hwtftYD/dFcG6wV4Ggf+TGS23a1PFqI= Received: from BL1PR13CA0062.namprd13.prod.outlook.com (2603:10b6:208:2b8::7) by SA3PR12MB7997.namprd12.prod.outlook.com (2603:10b6:806:307::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.19; Tue, 15 Jul 2025 19:13:22 +0000 Received: from MN1PEPF0000F0E1.namprd04.prod.outlook.com (2603:10b6:208:2b8:cafe::ab) by BL1PR13CA0062.outlook.office365.com (2603:10b6:208:2b8::7) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8943.17 via Frontend Transport; Tue, 15 Jul 2025 19:13:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E1.mail.protection.outlook.com (10.167.242.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:13:21 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:13:18 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 19/20] cxl/region: Add function to find a region's duplicate Date: Tue, 15 Jul 2025 21:11:42 +0200 Message-ID: <20250715191143.1023512-20-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E1:EE_|SA3PR12MB7997:EE_ X-MS-Office365-Filtering-Correlation-Id: eb0e6622-11f4-47d2-3d61-08ddc3d3aa50 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|7416014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?vAPVXm4bS25SAQTwshG+/H5CrsxB61vHXxvgr+5lBRGwxTgenDxqsc+UNHUZ?= =?us-ascii?Q?P5JiKWbgW/iDiItKAwhUs+gANbkDsmM+LYUHFTRLwtPUIQAQnz07QueVkqmR?= =?us-ascii?Q?9YsihuxA5DE0WEiVnZ4o8B5S6Wj+L8zW+dnVKiCbt9OcW1zavYzF6a4G6oCG?= =?us-ascii?Q?mmJJ2bWl9GhUqk+hjrG1v+rmFpMD2l4wGA9yJvEVwzYF84Ygd7S88iykNLUx?= =?us-ascii?Q?iz2epQfHm2dVPc9asPVtNHicg3VFAo7x9fIQ1/1cHjtS53gJQAvdAf/iwiUj?= =?us-ascii?Q?WQlVJIc0sUQgUZQp4YQ1cpNLExfWr+J/pZwGrpVraYdjwaq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Pi/32x7uhovoitXATEAT8phg+OG/vNGy9VFE8PG7?= =?us-ascii?Q?HW/X+rh/HAbQA14a40eqa1h01GAgyBMlfuOs/WzlP1uRkyUdPncT0wpmXptI?= =?us-ascii?Q?r/f2dcwAtT+Sw+dpBzMCoAPGmHhHCYgc8Y4mh5ffOeUmhSkTwGOH2VyRJIlO?= =?us-ascii?Q?HxOb3DylXENx2zThdcZ6LTapKPCN1sPWWGN/9E+yU+ZLyX2XNFrNNTu6pSF8?= =?us-ascii?Q?03r0XZvOJ3wRdQtxhR3o5zamyGiAnR3Qhg3Ezq9KN1TO5Lnt/Xw6CPERl+dx?= =?us-ascii?Q?3UcyLR8S8A8ZCIdOP/hkS8iNsqHhRltbPgwS?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(36860700013)(7416014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:13:21.8917 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eb0e6622-11f4-47d2-3d61-08ddc3d3aa50 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E1.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7997 Content-Type: text/plain; charset="utf-8" Before registering a region, there is a check if a region with the same parameters already exists. Rename the existing function cxl_find_region_by_range() to cxl_region_find_duplicate() and modify the argument list to only pass the @cxlr argument, which also simplifies the function's interface. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 8faef2b2ee05..5c30c417de1a 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3312,9 +3312,10 @@ static int match_region_by_range(struct device *dev,= const void *data) return 0; } =20 -static struct cxl_region * -cxl_find_region_by_range(struct cxl_root_decoder *cxlrd, struct range *hpa) +static struct cxl_region *cxl_region_find_duplicate(struct cxl_region *cxl= r) { + struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; + struct range *hpa =3D &cxlr->hpa_range; struct device *region_dev; =20 region_dev =3D device_find_child(&cxlrd->cxlsd.cxld.dev, hpa, @@ -3486,7 +3487,7 @@ static struct cxl_region *construct_region(struct cxl= _region *__cxlr) dev_name(&cxlr->dev), __func__, p->res, p->interleave_ways, p->interleave_granularity); =20 - /* Pair with cxl_find_region_by_range() in cxl_endpoint_get_region(). */ + /* Pair with cxl_region_find_duplicate() in cxl_endpoint_get_region(). */ get_device(&cxlr->dev); =20 return no_free_ptr(cxlr); @@ -3502,12 +3503,13 @@ cxl_endpoint_get_region(struct cxl_endpoint_decoder= *cxled) return new; =20 /* - * Ensure that if multiple threads race to construct_region() for @hpa - * one does the construction and the others add to that. + * Ensure that if multiple threads race to construct_region() + * for the hpa range one does the construction and the others + * add to that. */ guard(mutex)(&new->cxlrd->range_lock); =20 - cxlr =3D cxl_find_region_by_range(new->cxlrd, &new->hpa_range); + cxlr =3D cxl_region_find_duplicate(new); if (!cxlr) return construct_region(new); =20 --=20 2.39.5 From nobody Tue Oct 7 01:58:29 2025 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2055.outbound.protection.outlook.com [40.107.223.55]) (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 F1ED92BE053; Tue, 15 Jul 2025 19:13:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606812; cv=fail; b=BYHSrGvd2vVbtno293xei0cjsK6Hx/urL3jhOySXUv4Zs4uvz4NDVMCPTFTRg+DDAdZ9EcjVjsakRwptwtZPFVONl6ApHNeCbtMrn0/8bZdFyALR5MwvQxOufVqY7xrWn4A2s4xTO4HL4dpCkTKUssYmEOxeqww7x/bpOfiXVi4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752606812; c=relaxed/simple; bh=Xu0GA1YJAwCvRDFLYnxWCkdKgP9XzJ3RnijdHULK26s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bEMKt3Iy74aV47qyVHZdUv5AtAkAgSc0e71K8olDGoAeGW4KohsljGxhe0uywnYi8zITrrXv+1S+ipD5u1e9Zq6IHyXtJcikzjRwzRxkrUrDzdaJslNfyI88XC1A3uxcBaR846ViAbpt+1rEKZxugZsfI0zH5SORpqAT8CipL4c= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=PEeQJNx6; arc=fail smtp.client-ip=40.107.223.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="PEeQJNx6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QWxxbOycbRyzCPw7cGPZZsW8s3yThWCFhQgNear3c/jn9GsNrZBsaBWednh7tvhlA+Tu19AcUdIcwtjUozPdbz7JfvGBY0Wq/TYyn893FB4NXzTbalXrH3Z9UCEtokPWO4kIY6nzbnRNiuU+7CZU68gJ10Il0ER+Mej/mUUEw+fFW0CrpL7FHDvp8WmPO7pfRhmgrl7iuvntknAV5u1eFWpjfgLLlQgny70CFsuxMqSbfISAqbZPYh3XPrxR0mvZPdZB8u2JpmbV00U5c4QBuTcPOIWAtO0SlRy49wuk1SZ2dpWsxnss1SXvwxoetD0dyijxqYV8Js4I+iuQOt6Qkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HVOhtcGltJs4OysNnljLDQxy3rYgb6c3UF6qSZethfE=; b=wGqz1Yxw08Yd3PasQ5Ws6T7dgBEir0DSCYAgg5Xp50Y2ExLk1eNocpqxA3SupMNKFtjAbKrLWMJXc5IOPjzMFzX03jCeoiJIimGozzk0T3/sWwyfLKkeG2phDvy7RPK2uZUV3T6+4AvxhOhUHwWLrlaI7UYQcOQu2vRgCNP9axzMbyCBG6iy9bvDbUEndj7UMIqRMpii92c2JvUCz6QHTIRdVkruXGBCG45CrP+0pc3daU9tUXOgRVTXOuDQhgs/Ib+Cwzuo5vGIVFJCsxk+W+XY0gP0JvAAdFuEDJGK6/9A6U3tXt/c9XuUrOsNEzTFqLVR3KpCGuizYMM5HgNXng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HVOhtcGltJs4OysNnljLDQxy3rYgb6c3UF6qSZethfE=; b=PEeQJNx6jJETKj5Gkr4LJAo0hCl4jG0BSYNWML7dRDyBzwDlOfXqACYOMHqYGjA+k953eh1Lx55YQEjdMMXB1opmzvxJyHtJUrbZ9hfELD54n3904fm9DYITSzxGyAe/bJn4IxWIhpGbt928KqGUX0y8Pjx5AMLwjyoMrEcJ7Ro= Received: from BN9PR03CA0070.namprd03.prod.outlook.com (2603:10b6:408:fc::15) by CY8PR12MB7658.namprd12.prod.outlook.com (2603:10b6:930:9e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8922.33; Tue, 15 Jul 2025 19:13:25 +0000 Received: from MN1PEPF0000F0E4.namprd04.prod.outlook.com (2603:10b6:408:fc:cafe::7c) by BN9PR03CA0070.outlook.office365.com (2603:10b6:408:fc::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8922.32 via Frontend Transport; Tue, 15 Jul 2025 19:13:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E4.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8922.22 via Frontend Transport; Tue, 15 Jul 2025 19:13:25 +0000 Received: from rric.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 15 Jul 2025 14:13:22 -0500 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Robert Richter Subject: [PATCH v1 20/20] cxl/region: Early check region's interleaving configuration Date: Tue, 15 Jul 2025 21:11:43 +0200 Message-ID: <20250715191143.1023512-21-rrichter@amd.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715191143.1023512-1-rrichter@amd.com> References: <20250715191143.1023512-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E4:EE_|CY8PR12MB7658:EE_ X-MS-Office365-Filtering-Correlation-Id: 5e3b6ff4-e935-4e75-3e5f-08ddc3d3ac62 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?2QRRWu/9UyCh5AKvd/nWKurHX/fCLoIzSeLwtXUkApIBIc/ePer0D5M+4t9E?= =?us-ascii?Q?qAp95qDi3427aXD1wFrAeAm3UEoDWri7wUG7NBmRJ77da+FZ5PetzVi5+qSs?= =?us-ascii?Q?aDQOkZQeC70BsIKyKl1gPyh8vOOmOfn/kLvmhREPfz7MyEX292GQh+YtJhOX?= =?us-ascii?Q?wbgDf+JESps3cpPRYN6rEFbXN2BehbxVkzAw2R//2nK+8i4VsrDMMWBVInAx?= =?us-ascii?Q?8FXDiVesJDPJeof24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-ascii?Q?USBPYoySAXEawSiXXDBShbYqfWXW4Dlg7yvmEvSoyhPUhY87NpHUtoR20NIH?= =?us-ascii?Q?YIkRX0SvlQi5U6EgNK1TQ9yjxL1k8Ly0f5jYlDO0hRTOaUToORRK1G9syeQh?= =?us-ascii?Q?QiAR7ccunrCBPGihS4Mxqv6nvno+y5Qt2vOe3MBSR1ae22HgWpuU6Wh/8eHp?= =?us-ascii?Q?q+2ETGVsra5zYw6BBXMQ6P7qhp1x4CHVyEUoOpwP5VwdVIfcwXX2Yl0RjhkB?= =?us-ascii?Q?KEx4aCcQi0yo8a4i+CwgJr5Z1Wa6jh486JITWBqgoMYyX6WRKxqvc/FhKBhy?= =?us-ascii?Q?zrsAOy8pl+xX7Qas43CYx0+5oYVviDeLTu0lGo9L/su3LqIGrjQYWRChFg9X?= =?us-ascii?Q?BA8tDgAnj4h1sQ4lpWYHuCQ3BK/yd3sr/thx?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 19:13:25.3682 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5e3b6ff4-e935-4e75-3e5f-08ddc3d3ac62 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E4.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7658 Content-Type: text/plain; charset="utf-8" In interleaving configurations multiple endpoint decoders share the same region. All endpoint decoders must be configured with the same region parameters. Right now a check is done late during initialization in cxl_region_attach(), and an already existing region for the same hpa range could be bound to the endpoint decoder. That region may have a different interleaving configuration. To reuse the region's interleaving configuration parameters for endpoint bringup with address translation, make sure the interleaving parameters are always correct and add an early check for this. Add a function cxl_region_check() to check memory mode, memory type and the interleaving parameters. This ensures an endpoint decoder will only be attached to a region with matching parameters. The region's parameters can be used during endpoint decoder enumeration. Also, a config mismatch is detected early before trying to attach the region. This helps to identify and handle errors at an early stage. Signed-off-by: Robert Richter --- drivers/cxl/core/region.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 5c30c417de1a..aca02d011c57 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3493,10 +3493,42 @@ static struct cxl_region *construct_region(struct c= xl_region *__cxlr) return no_free_ptr(cxlr); } =20 +static int cxl_region_check(struct device *dev, + struct cxl_region *cxlr, + struct cxl_region *new) +{ + struct cxl_region_params *p =3D &cxlr->params; + struct cxl_region_params *np =3D &new->params; + + if (cxlr->mode !=3D new->mode) { + dev_dbg(dev, "%s: region mode mismatch: %d vs %d\n", + dev_name(&cxlr->dev), cxlr->mode, new->mode); + return -EINVAL; + } + + if (cxlr->type !=3D new->type) { + dev_dbg(dev, "%s: region type mismatch: %d vs %d\n", + dev_name(&cxlr->dev), cxlr->type, new->type); + return -ENXIO; + } + + if (p->interleave_ways !=3D np->interleave_ways || + p->interleave_granularity !=3D np->interleave_granularity) { + dev_dbg(dev, "%s: interleaving config mismatch: %dx%d vs %dx%d\n", + dev_name(&cxlr->dev), + p->interleave_ways, p->interleave_granularity, + np->interleave_ways, np->interleave_granularity); + return -ENXIO; + } + + return 0; +} + static struct cxl_region * cxl_endpoint_get_region(struct cxl_endpoint_decoder *cxled) { struct cxl_region *cxlr, *new; + int rc; =20 new =3D create_region(cxled); if (IS_ERR(new)) @@ -3513,8 +3545,15 @@ cxl_endpoint_get_region(struct cxl_endpoint_decoder = *cxled) if (!cxlr) return construct_region(new); =20 + rc =3D cxl_region_check(&cxled->cxld.dev, cxlr, new); + put_device(&new->dev); =20 + if (rc) { + put_device(&cxlr->dev); + return ERR_PTR(rc); + } + return cxlr; } =20 --=20 2.39.5