From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from MW6PR02CU001.outbound.protection.outlook.com (mail-westus2azon11012030.outbound.protection.outlook.com [52.101.48.30]) (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 52EE33043A2; Wed, 11 Feb 2026 22:10:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.48.30 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770847848; cv=fail; b=dLuCOifEHVIEDgaP1OH50cpDzAJhedcHsdz2PKozqyZ+QgGV/Ucgn3o4cYl0xpcN9kOfCHePqygEDrcQpieOHgY5LywEYa99Hfw7o5rY31Z09IKRvJTY9yl1fwCRMLs3yVu4b5RzWy8jYmTNrJw+Ksn2mD4WNpf0hL0dxjZmWw0= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770847848; c=relaxed/simple; bh=HArMugFUP3u7j+GNHRmG8C0hg3A2JKUvYG6/Jxe7fh4=; h=Message-ID:Date:MIME-Version:From:Subject:To:CC:References: In-Reply-To:Content-Type; b=Mf3DSv/upAnJh+2QVwvQ2rX1eXIstXpzcWYQdq0f8cK69aCKt0JJ0VbkJoOo+CSFbJ6KC0m8xVNe+jTCtBbr2cPjl/go374r9hsSp6ImogwlkPuBLZ94e+xl5U0VgZcIsfexVp8Sy55Kc+1HEY4YegIC0vhPsb1CqSTX3vairfo= 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=UAz3CD0J; arc=fail smtp.client-ip=52.101.48.30 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="UAz3CD0J" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hxkz/LeqonTE6tOFkFva8P0OqfBNmj72bmvPsxvu/MSI+KsSujKgF+kci9Xyke/QX0O3cEamTUt0TYP5nEBy3pEqHN5xTMUirF2kyDmJuRLwUXhL36D/fqpiR5trdw6TpFCtUf3hXNyS5tyOo8jHpdv5Qa0sV0i91kPygpgt8YE4PQD3/R5gEACqA4m8AjXOMpfLApPFhHIM6kp/jM1RTAQ0QMVu9oAN8wHuQAvK/PAfXstfAwbn6+cbQHenKKAA2jgJMpMalXEWX48Q9qt9nsr2y8uQA9d9N6zxYa8SoS6TR/cUiBJ38LqZtNOJX355laylQNoCUepSCzcT4oVMAg== 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=bg+GeCT+OKIeGl4f33hAKV0RI0cOjIrvBgC5fcB+oyY=; b=uWLR7i6HoXuJXo5Kkq9D3QhP8XBbYxWk19MlwgV6D9EGA0A0Cgcb5NS3EkNxZWYy7mwZ6EJVATyKqS4GQs1aDsDubDiK4G6HoIkdfBCRCqAh5dCK4ktDWOsEviVc2g+I4SPt38AVdhgtMb/1ArCaMzT5udlrVav5/sAtvYb6HtlzodE+WV48cS8qmHmPZdVE/hV/tAGD4N+nF1CA1mkssadDQZ0/YsTNu6nEYWaUr2P5j0mzH3lrCx8jq/tHDJCQ+M/bJHT5hyCEebsF66OcqyqPHmI/k/I1yFKGN4ePdgMT6QFYfBwHyoQPEgNmvIOS8VHUAGHscGn2Y0/YGabCZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=huawei.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=bg+GeCT+OKIeGl4f33hAKV0RI0cOjIrvBgC5fcB+oyY=; b=UAz3CD0JlKC7XnDmwxHUfeyQ/9AorB0JQEZpCyupyxUD2gpGcJAO/lDqZhM98Q3WRYDVo1X9A/tgyYYwvmhNHTwPYvmrbwhiJsB7XepnKN67beITJc0OiSbLvFBZd1Vw+4DRNp5/vhCizfQ5GU+ubZ9eJhSvAqu2YCvEZz7cMW4= Received: from MW4PR03CA0228.namprd03.prod.outlook.com (2603:10b6:303:b9::23) by CY8PR12MB8362.namprd12.prod.outlook.com (2603:10b6:930:7e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9611.10; Wed, 11 Feb 2026 22:10:42 +0000 Received: from CO1PEPF000075EE.namprd03.prod.outlook.com (2603:10b6:303:b9:cafe::a4) by MW4PR03CA0228.outlook.office365.com (2603:10b6:303:b9::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9611.8 via Frontend Transport; Wed, 11 Feb 2026 22:10:37 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CO1PEPF000075EE.mail.protection.outlook.com (10.167.249.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9611.8 via Frontend Transport; Wed, 11 Feb 2026 22:10:40 +0000 Received: from [10.31.203.44] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Wed, 11 Feb 2026 16:10:39 -0600 Message-ID: Date: Wed, 11 Feb 2026 16:10:39 -0600 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: "Cheatham, Benjamin" Subject: Re: [PATCH v23 12/22] cxl: Define a driver interface for HPA free space enumeration To: CC: Alejandro Lucero , Jonathan Cameron , , , , , , , , , References: <20260201155438.2664640-1-alejandro.lucero-palau@amd.com> <20260201155438.2664640-13-alejandro.lucero-palau@amd.com> Content-Language: en-US In-Reply-To: <20260201155438.2664640-13-alejandro.lucero-palau@amd.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000075EE:EE_|CY8PR12MB8362:EE_ X-MS-Office365-Filtering-Correlation-Id: 7d0f4b8b-973c-417a-46b7-08de69ba64b1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700013|1800799024|13003099007|7053199007; X-Microsoft-Antispam-Message-Info: =?utf-8?B?Y0FoSzhFMmgrTVFFQmQ1bVl6VTJjRDI1K0JXL1l3VlBqaThsYWhmdWJhcDE5?= =?utf-8?B?WVpoOGtPUDZJU2xSQWY0Y1lQT3FUOGExaDBnSGRjd1R2emxyMDMxejM2Nytv?= =?utf-8?B?UHBkeD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ZrYW5GSjBa?= =?utf-8?B?QVJaUlZiZXcxUDdZSnpaTUd3REpXN0JTV3ZxdUUrdWY4ckdxeEJqZkZ3SUFx?= =?utf-8?B?UkFLazBiNUpUd0JZc3lRTy9jeklKQSs2SkcxRjF5MEhFaWpqVkxnS2tuNXAy?= =?utf-8?B?YmpHQS9QSE1IckdzS21iUG1YWjZ3MmlON2huUW9QdlZ6ZFRlQkdkK1NVTFZS?= =?utf-8?B?a2xOOFVoL2JEMVBQVVdGV1dLN0JvZzZSaHVwSWtVV0NVc3pQejFWN0Fjbk0x?= =?utf-8?B?eUsyR2pOZVV5anBvTGdkY0JENlVUVCtWcmU4S1NFS25VU1lWTWdyWlRBeHFk?= =?utf-8?B?U25GNU9GNEZoaitkeHZya1hCY1J3PT0=?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(82310400026)(36860700013)(1800799024)(13003099007)(7053199007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: X2MVV2NGB950JFHS1NJgHJNrcl9QQ3oYlfDYN/DmkWyRKTtSK5gsyMRduaDdV+bCWGaZ1g4bivLpEKIoqmm4WcD8eg1mSiKuDbfbsVcYzIe/4wqxPh58uBTUoFBdtrkRxNLS+7UldRYjGpNMM0h/ncxb+5cn3kYOpxOB9HAudf9M1YqNfYJmM1wXQGjr2Z19e9b3UFslPX/dlz9vnotTaophCkW5r+YxXcvAM3SderjB0JuW+BZV4fKTYNuPQxeCMCyofW/AQQdYrW1URPCn8eafVDSiye8fCj3lZyw6OpyAFo7GWwbFwJpTuCPh8YdpGTj7//HUQyJtw6UuCTIlR11D0+8oRoUReMFiYFgCrcYyQkPHSiayFIO4fperT3XZBc5og6InoTYZRZFBZFFFYnbImypzd7mHESxMzJeYkAe2G2lWSgZp2I1LaJAij38s X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Feb 2026 22:10:40.6565 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7d0f4b8b-973c-417a-46b7-08de69ba64b1 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000075EE.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8362 On 2/1/2026 9:54 AM, alejandro.lucero-palau@amd.com wrote: > From: Alejandro Lucero > > CXL region creation involves allocating capacity from Device Physical > Address (DPA) and assigning it to decode a given Host Physical Address > (HPA). Before determining how much DPA to allocate the amount of available > HPA must be determined. Also, not all HPA is created equal, some HPA > targets RAM, some targets PMEM, some is prepared for device-memory flows > like HDM-D and HDM-DB, and some is HDM-H (host-only). > > In order to support Type2 CXL devices, wrap all of those concerns into > an API that retrieves a root decoder (platform CXL window) that fits the > specified constraints and the capacity available for a new region. > > Add a complementary function for releasing the reference to such root > decoder. > > Based on https://lore.kernel.org/linux-cxl/168592159290.1948938.13522227102445462976.stgit@dwillia2-xfh.jf.intel.com/ > > Signed-off-by: Alejandro Lucero > Reviewed-by: Jonathan Cameron > --- > drivers/cxl/core/region.c | 164 ++++++++++++++++++++++++++++++++++++++ > drivers/cxl/cxl.h | 3 + > include/cxl/cxl.h | 6 ++ > 3 files changed, 173 insertions(+) > > diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c > index 954b8fcdbac6..bdefd088f5f1 100644 > --- a/drivers/cxl/core/region.c > +++ b/drivers/cxl/core/region.c > @@ -705,6 +705,170 @@ static int free_hpa(struct cxl_region *cxlr) > return 0; > } > > +struct cxlrd_max_context { > + struct device * const *host_bridges; > + int interleave_ways; > + unsigned long flags; > + resource_size_t max_hpa; > + struct cxl_root_decoder *cxlrd; > +}; > + > +static int find_max_hpa(struct device *dev, void *data) > +{ > + struct cxlrd_max_context *ctx = data; > + struct cxl_switch_decoder *cxlsd; > + struct cxl_root_decoder *cxlrd; > + struct resource *res, *prev; > + struct cxl_decoder *cxld; > + resource_size_t free = 0; > + resource_size_t max; > + int found = 0; > + > + if (!is_root_decoder(dev)) > + return 0; > + > + cxlrd = to_cxl_root_decoder(dev); > + cxlsd = &cxlrd->cxlsd; > + cxld = &cxlsd->cxld; > + > + if ((cxld->flags & ctx->flags) != ctx->flags) { > + dev_dbg(dev, "flags not matching: %08lx vs %08lx\n", > + cxld->flags, ctx->flags); > + return 0; > + } > + > + for (int i = 0; i < ctx->interleave_ways; i++) { > + for (int j = 0; j < ctx->interleave_ways; j++) { > + if (ctx->host_bridges[i] == cxlsd->target[j]->dport_dev) { > + found++; > + break; > + } > + } > + } This may be over complicated. I'm not quite sure how it works (I'm just slow today I guess), but I understand what the intention is based on the debug print below. My issue is that ctx->host_bridges is only set to 1 host bridge (endpoint->host_bridge) in cxl_get_hpa_freespace(), which is the only caller of this function. At that point, why have the outer loop at all? At that point, you could also simplify ctx->host_bridges to only be a struct device * const. Maybe this gets called elsewhere later on in the series? I haven't looked at the rest yet. If I'm wrong, then I'd probably add a comment saying what the cxlsd->target[] entries are supposed to be pointing at. > + > + if (found != ctx->interleave_ways) { > + dev_dbg(dev, > + "Not enough host bridges. Found %d for %d interleave ways requested\n", > + found, ctx->interleave_ways); > + return 0; > + } > + > + /* > + * Walk the root decoder resource range relying on cxl_rwsem.region to > + * preclude sibling arrival/departure and find the largest free space > + * gap. > + */ > + lockdep_assert_held_read(&cxl_rwsem.region); > + res = cxlrd->res->child; > + > + /* With no resource child the whole parent resource is available */ > + if (!res) > + max = resource_size(cxlrd->res); > + else > + max = 0; > + > + for (prev = NULL; res; prev = res, res = res->sibling) { > + if (!prev && res->start == cxlrd->res->start && > + res->end == cxlrd->res->end) { > + max = resource_size(cxlrd->res); > + break; > + } > + /* > + * Sanity check for preventing arithmetic problems below as a > + * resource with size 0 could imply using the end field below > + * when set to unsigned zero - 1 or all f in hex. > + */ > + if (prev && !resource_size(prev)) > + continue; > + > + if (!prev && res->start > cxlrd->res->start) { > + free = res->start - cxlrd->res->start; > + max = max(free, max); > + } > + if (prev && res->start > prev->end + 1) { > + free = res->start - prev->end + 1; > + max = max(free, max); > + } > + } > + > + if (prev && prev->end + 1 < cxlrd->res->end + 1) { > + free = cxlrd->res->end + 1 - prev->end + 1; > + max = max(free, max); > + } > + > + dev_dbg(cxlrd_dev(cxlrd), "found %pa bytes of free space\n", &max); > + if (max > ctx->max_hpa) { > + if (ctx->cxlrd) > + put_device(cxlrd_dev(ctx->cxlrd)); > + get_device(cxlrd_dev(cxlrd)); > + ctx->cxlrd = cxlrd; > + ctx->max_hpa = max; > + } > + return 0; > +} > + > +/** > + * cxl_get_hpa_freespace - find a root decoder with free capacity per constraints > + * @cxlmd: the mem device requiring the HPA > + * @interleave_ways: number of entries in @host_bridges > + * @flags: CXL_DECODER_F flags for selecting RAM vs PMEM, and Type2 device > + * @max_avail_contig: output parameter of max contiguous bytes available in the > + * returned decoder > + * > + * Returns a pointer to a struct cxl_root_decoder > + * > + * The return tuple of a 'struct cxl_root_decoder' and 'bytes available given > + * in (@max_avail_contig))' is a point in time snapshot. If by the time the > + * caller goes to use this decoder and its capacity is reduced then caller needs > + * to loop and retry. > + * > + * The returned root decoder has an elevated reference count that needs to be > + * put with cxl_put_root_decoder(cxlrd). > + */ > +struct cxl_root_decoder *cxl_get_hpa_freespace(struct cxl_memdev *cxlmd, > + int interleave_ways, > + unsigned long flags, > + resource_size_t *max_avail_contig) > +{ > + struct cxlrd_max_context ctx = { > + .flags = flags, > + .interleave_ways = interleave_ways, > + }; > + struct cxl_port *root_port; > + struct cxl_port *endpoint; > + > + endpoint = cxlmd->endpoint; > + if (!endpoint) { > + dev_dbg(&cxlmd->dev, "endpoint not linked to memdev\n"); > + return ERR_PTR(-ENXIO); > + } > + > + ctx.host_bridges = &endpoint->host_bridge; Mentioned earlier, interleave_ways is effectively hardcoded to 1 (unless I'm misunderstanding something). I think what you want here is to go to the CXL root and pass in the children (i.e. host bridges)? I'm not sure of what the fix is to get the intended behavior. It may be worth getting rid of the interleave_ways portion of this function and add it later when someone needs it. You could also explain it's hard coded to 1/unused in the doc comment if you know of an immediate need for it. > + > + struct cxl_root *root __free(put_cxl_root) = find_cxl_root(endpoint); > + if (!root) { > + dev_dbg(&endpoint->dev, "endpoint is not related to a root port\n"); > + return ERR_PTR(-ENXIO); > + } > + > + root_port = &root->port; > + scoped_guard(rwsem_read, &cxl_rwsem.region) > + device_for_each_child(&root_port->dev, &ctx, find_max_hpa); Can just use a guard() here. > + > + if (!ctx.cxlrd) > + return ERR_PTR(-ENOMEM); > + > + *max_avail_contig = ctx.max_hpa; > + return ctx.cxlrd; > +} > +EXPORT_SYMBOL_NS_GPL(cxl_get_hpa_freespace, "CXL"); > + > +void cxl_put_root_decoder(struct cxl_root_decoder *cxlrd) > +{ > + put_device(cxlrd_dev(cxlrd)); > +} > +EXPORT_SYMBOL_NS_GPL(cxl_put_root_decoder, "CXL"); > + > static ssize_t size_store(struct device *dev, struct device_attribute *attr, > const char *buf, size_t len) > { > diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h > index 944c5d1ccceb..c7d9b2c2908f 100644 > --- a/drivers/cxl/cxl.h > +++ b/drivers/cxl/cxl.h > @@ -706,6 +706,9 @@ struct cxl_root_decoder *to_cxl_root_decoder(struct device *dev); > struct cxl_switch_decoder *to_cxl_switch_decoder(struct device *dev); > struct cxl_endpoint_decoder *to_cxl_endpoint_decoder(struct device *dev); > bool is_root_decoder(struct device *dev); > + > +#define cxlrd_dev(cxlrd) (&(cxlrd)->cxlsd.cxld.dev) > + > bool is_switch_decoder(struct device *dev); > bool is_endpoint_decoder(struct device *dev); > struct cxl_root_decoder *cxl_root_decoder_alloc(struct cxl_port *port, > diff --git a/include/cxl/cxl.h b/include/cxl/cxl.h > index 92880c26b2d5..834dc7e78934 100644 > --- a/include/cxl/cxl.h > +++ b/include/cxl/cxl.h > @@ -255,4 +255,10 @@ struct cxl_endpoint_decoder *cxl_get_committed_decoder(struct cxl_memdev *cxlmd, > struct range; > int cxl_get_region_range(struct cxl_region *region, struct range *range); > void cxl_unregister_region(struct cxl_region *cxlr); > +struct cxl_port; > +struct cxl_root_decoder *cxl_get_hpa_freespace(struct cxl_memdev *cxlmd, > + int interleave_ways, > + unsigned long flags, > + resource_size_t *max); > +void cxl_put_root_decoder(struct cxl_root_decoder *cxlrd); > #endif /* __CXL_CXL_H__ */