From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2044.outbound.protection.outlook.com [40.107.237.44]) (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 6A7331E1E04; Fri, 6 Jun 2025 17:53:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.44 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749232412; cv=fail; b=GB4CXNAzY52vlG4+yM8NF/GBCCUQ6Zg/BcypzeAhcB8CbPnH9PkIY025EBBIyGd/h90wdhLAurLt1zqYKSkYHr0hEBdRH+fd//q8tO1i2vNmuj6qMmEAIH5lQI7yZIHVCizqRB6s+65NrI1/r2k37KonVVIi4g+BCjeWvTMxnlw= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749232412; c=relaxed/simple; bh=taHXxjpPrnxj6HP/DTMXUqcUll124lXB7IhycCTNM9E=; h=Message-ID:Date:Subject:To:Cc:References:From:In-Reply-To: Content-Type:MIME-Version; b=P/zuq6HQaqEey6xj7SX/NG6uoXZA0lxDkhQGwK/9CBob1HSExbWQS9z/WXO11Wtc5ss/oopIaJcvpFG6VkzVfDT/qsPWo4UxA+ATvfLPU+OpUlYOVa5vUYa482K9b+08hBPWsY+c8ynzaM7vfwfMXX5s+wIO0+eX1se56aog2Rc= 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=ULHoPa45; arc=fail smtp.client-ip=40.107.237.44 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="ULHoPa45" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YH2UBhEPmcZEujBmIvcqq1BS2lBLxM/92Z78xAQngGjh6TLxiVG0UxdQ2pKi2Q+CnnustMt4DlJ7gO5I4c6rsy9xl0Ld7qvtPdi/+JeJTwny3MUAbmetBFninzDi41vX2zYDhN0OgAkFLVrwXE+SNIqud9zwfWvv+twMsMRkIi+qpmleWQmPyIEmQF6aTFBbAzoc64gt/PHUQFWdt0I7tuVDuLNPEzjDUB3UF+wms6K7c/ZiIkBc/cToe54BipG4WxBvGpkn+OYyatldvqVu1v+AoqD++Lf3hmTJOLufEc5auVBG1juPtxiXFdu0RFFSlUGrWtMMdXYP4EOrqzjzKw== 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=xQjJLHeepOvbFeZt4T6ArMQ8+UJlF/ITImUijJAyedE=; b=kRx/HsqcvjyMXfyh72LtYsfKBk1GjG930b646DjJyvNGojHvaPVn4PSRks/bhllwtBKjwTiVkh35liM7Do++EuTmgcLLuozrlBm1qxTi4LZeIOYsH4Zp7pKkFfbEEcUVG8mSQixhuyjkOuhPh4f1DOdfZSCVHC2+e3l0g3XLvRbKNmKvEKwKrovMmEgz77eEHnDca1sU65yHikNydafgX2SFnipeTaRuT1DL21i4GbFZI7+VIurG7lXtxpgC/1n7YHTB1on6Z4pEUYUw6HlMPHIDGP23OEYfxDUXT1tlLnFFsGBvjuIG2Fw3VYNmz8vn5UynmNQWIAA7TMTY+pGPvA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none 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=xQjJLHeepOvbFeZt4T6ArMQ8+UJlF/ITImUijJAyedE=; b=ULHoPa45qtqjVI1K8XEsCa/SjQ4ikAZVFByKajwIzlPLTIjIt56Sc//VTHEz3ltVGTTAGvPxiHxq3UKvYFQGwrEsqErx5x9H9kAMvnS7ufUo0f9LugHBTIM0Jmd85MT3YfA6RULSpQDPfbwwy0G8WDojHqP/34hKFH6w5NEz0aw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from MW4PR12MB7142.namprd12.prod.outlook.com (2603:10b6:303:220::6) by SJ1PR12MB6338.namprd12.prod.outlook.com (2603:10b6:a03:455::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8792.35; Fri, 6 Jun 2025 17:53:25 +0000 Received: from MW4PR12MB7142.namprd12.prod.outlook.com ([fe80::e5b2:cd7c:ba7d:4be3]) by MW4PR12MB7142.namprd12.prod.outlook.com ([fe80::e5b2:cd7c:ba7d:4be3%3]) with mapi id 15.20.8792.038; Fri, 6 Jun 2025 17:53:24 +0000 Message-ID: <8e077620-b1aa-4c51-9f66-58a9739aeb75@amd.com> Date: Fri, 6 Jun 2025 10:53:22 -0700 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 5/7] cxl/region: Introduce SOFT RESERVED resource removal on region teardown To: "Zhijian Li (Fujitsu)" , "linux-cxl@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "nvdimm@lists.linux.dev" , "linux-fsdevel@vger.kernel.org" , "linux-pm@vger.kernel.org" Cc: Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Matthew Wilcox , Jan Kara , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Li Ming , Jeff Johnson , Ying Huang , "Xingtao Yao (Fujitsu)" , Peter Zijlstra , Greg KH , Nathan Fontenot , Terry Bowman , Robert Richter , Benjamin Cheatham , PradeepVineshReddy Kodamati References: <20250603221949.53272-1-Smita.KoralahalliChannabasappa@amd.com> <20250603221949.53272-6-Smita.KoralahalliChannabasappa@amd.com> <3e045950-9ffb-4a9b-9793-958a16db0c33@fujitsu.com> Content-Language: en-US From: "Koralahalli Channabasappa, Smita" In-Reply-To: <3e045950-9ffb-4a9b-9793-958a16db0c33@fujitsu.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BYAPR21CA0014.namprd21.prod.outlook.com (2603:10b6:a03:114::24) To MW4PR12MB7142.namprd12.prod.outlook.com (2603:10b6:303:220::6) Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW4PR12MB7142:EE_|SJ1PR12MB6338:EE_ X-MS-Office365-Filtering-Correlation-Id: 169f02ce-2fda-4375-a6a4-08dda5230843 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?utf-8?B?dnZOcHVvZ085QXBiZjlWcG5OYnphbElwbGNUMzJkZlY0T3kyYVJHTnk5UXBm?= =?utf-8?B?WHVUeW9zWXFMcGNNVmd4YTl1VEtwcyt3dFIrUW1Yb1JQNHpxQjJGa0ZJL1Zz?= =?utf-8?B?bFo3WjJHWlBWcXlMaDhOdDJHUWVGTmxjRVlqZ25HMDZCOFpBYXh0bU9raXVn?= =?utf-8?B?QWNQeU1hRTQvSk02UVZ3Q3ZWSS9vWldOMFZXVE9abVpNTjN5ZGdqc0pjR2ha?= =?utf-8?B?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1VlMvcEpQK3c5bzRjTTJEa0pRS0pW?= =?utf-8?B?MkIrZ0o1cWZDcWFaK0pYOGtDR01qZkI1b3ZMT0lITzE0bXJOSEJiTWJRQk1E?= =?utf-8?B?bWozUVFwMnNyY3NmQ3ZML2J4aGZPOWl4aWppRnJmWHNBVm50aVFuMXYvRW9L?= =?utf-8?B?RFhvWEwzbnVMblhTMGtJS1lMZEEvQUpIRk5CVjN0Nzc4OWwyRXNyZWE1ZUxq?= =?utf-8?B?dDJsa1BJK0tTYnBxSlJHTHF3eDh0OGcxd0k0YUN6cXFzVUx4WFIvSXoxZmxj?= =?utf-8?B?b1RiandrbWcwWXdtcDY0bm95QTAyaDNhUjFQeERpZlphWWcwZUQwN3VveDZo?= =?utf-8?B?VS9YeERXdk9mb2RxdmFyVmpwN1lrZEZzMHJCQjNZT2pKc3JtUUJvcnNrcFFJ?= =?utf-8?B?aTdqV21kcDB0bDU3Z0I1UGtQQUJla2YvU1hXaXBBTGl6QngvMXhBaEx0T3hE?= =?utf-8?Q?k3wm3U+m4igE/4efzWREEqIrr?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 169f02ce-2fda-4375-a6a4-08dda5230843 X-MS-Exchange-CrossTenant-AuthSource: MW4PR12MB7142.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2025 17:53:23.9646 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VrveUT8CuRkuwmVzfwGsrzrcJB/MTnKn/dUSzz9UJxZmUK3bPLhlOPeHNZ2s0LQXYAKybBBcpqwfNsHcyjZk2Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6338 On 6/5/2025 9:16 PM, Zhijian Li (Fujitsu) wrote: > > The term "region teardown" in the subject line appears inaccurate. > > > As I understand, cxl_region_softreserv_update() should work only > when the region is ready, but the current logic only guarantees that the *memdev* is ready. > > Is there truly no timing gap between region readiness and memdev readiness? > If this assumption is true, could we document this relationship in both the commit log and code comments? > > > Thanks > Zhijian I think you're right in pointing this out. We cannot guarantee region readiness unless there's an explicit ordering or dependency ensuring that cxl_region_probe() always completes after or synchronously with memdev probing and wait_for_device_probe(). I don't believe we currently have such a guarantee. I was considering adding a null check for cxlr->params.res in __cxl_region_softreserv_update(), along with a comment like below: static int __cxl_region_softreserv_update(struct resource *soft, void *_cxlr) { struct cxl_region *cxlr = _cxlr; struct resource *res = cxlr->params.res; /* * Skip if the region has not yet been fully initialized. * * This code assumes all cxl_region devices have completed * probing before this function runs, and that params.res is * valid. */ if (!res) return 0; .. .. } This would prevent a null dereference and make the assumption around region readiness more explicit. That said, I'd appreciate input from Terry, Nathan, or others on whether there's a better way to guarantee that region creation has completed by the time this function is invoked. Thanks Smita > > > On 04/06/2025 06:19, Smita Koralahalli wrote: >> Reworked from a patch by Alison Schofield >> >> Previously, when CXL regions were created through autodiscovery and their >> resources overlapped with SOFT RESERVED ranges, the soft reserved resource >> remained in place after region teardown. This left the HPA range >> unavailable for reuse even after the region was destroyed. >> >> Enhance the logic to reliably remove SOFT RESERVED resources associated >> with a region, regardless of alignment or hierarchy in the iomem tree. >> >> Link: https://lore.kernel.org/linux-cxl/29312c0765224ae76862d59a17748c8188fb95f1.1692638817.git.alison.schofield@intel.com/ >> Co-developed-by: Alison Schofield >> Signed-off-by: Alison Schofield >> Co-developed-by: Terry Bowman >> Signed-off-by: Terry Bowman >> Signed-off-by: Smita Koralahalli >> --- >> drivers/cxl/acpi.c | 2 + >> drivers/cxl/core/region.c | 151 ++++++++++++++++++++++++++++++++++++++ >> drivers/cxl/cxl.h | 5 ++ >> 3 files changed, 158 insertions(+) >> >> diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c >> index 978f63b32b41..1b1388feb36d 100644 >> --- a/drivers/cxl/acpi.c >> +++ b/drivers/cxl/acpi.c >> @@ -823,6 +823,8 @@ static void cxl_softreserv_mem_work_fn(struct work_struct *work) >> * and cxl_mem drivers are loaded. >> */ >> wait_for_device_probe(); >> + >> + cxl_region_softreserv_update(); >> } >> static DECLARE_WORK(cxl_sr_work, cxl_softreserv_mem_work_fn); >> >> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c >> index 109b8a98c4c7..3a5ca44d65f3 100644 >> --- a/drivers/cxl/core/region.c >> +++ b/drivers/cxl/core/region.c >> @@ -3443,6 +3443,157 @@ int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled) >> } >> EXPORT_SYMBOL_NS_GPL(cxl_add_to_region, "CXL"); >> >> +static int add_soft_reserved(resource_size_t start, resource_size_t len, >> + unsigned long flags) >> +{ >> + struct resource *res = kmalloc(sizeof(*res), GFP_KERNEL); >> + int rc; >> + >> + if (!res) >> + return -ENOMEM; >> + >> + *res = DEFINE_RES_MEM_NAMED(start, len, "Soft Reserved"); >> + >> + res->desc = IORES_DESC_SOFT_RESERVED; >> + res->flags = flags; >> + rc = insert_resource(&iomem_resource, res); >> + if (rc) { >> + kfree(res); >> + return rc; >> + } >> + >> + return 0; >> +} >> + >> +static void remove_soft_reserved(struct cxl_region *cxlr, struct resource *soft, >> + resource_size_t start, resource_size_t end) >> +{ >> + struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent); >> + resource_size_t new_start, new_end; >> + int rc; >> + >> + /* Prevent new usage while removing or adjusting the resource */ >> + guard(mutex)(&cxlrd->range_lock); >> + >> + /* Aligns at both resource start and end */ >> + if (soft->start == start && soft->end == end) >> + goto remove; >> + >> + /* Aligns at either resource start or end */ >> + if (soft->start == start || soft->end == end) { >> + if (soft->start == start) { >> + new_start = end + 1; >> + new_end = soft->end; >> + } else { >> + new_start = soft->start; >> + new_end = start - 1; >> + } >> + >> + rc = add_soft_reserved(new_start, new_end - new_start + 1, >> + soft->flags); >> + if (rc) >> + dev_warn(&cxlr->dev, "cannot add new soft reserved resource at %pa\n", >> + &new_start); >> + >> + /* Remove the original Soft Reserved resource */ >> + goto remove; >> + } >> + >> + /* >> + * No alignment. Attempt a 3-way split that removes the part of >> + * the resource the region occupied, and then creates new soft >> + * reserved resources for the leading and trailing addr space. >> + */ >> + new_start = soft->start; >> + new_end = soft->end; >> + >> + rc = add_soft_reserved(new_start, start - new_start, soft->flags); >> + if (rc) >> + dev_warn(&cxlr->dev, "cannot add new soft reserved resource at %pa\n", >> + &new_start); >> + >> + rc = add_soft_reserved(end + 1, new_end - end, soft->flags); >> + if (rc) >> + dev_warn(&cxlr->dev, "cannot add new soft reserved resource at %pa + 1\n", >> + &end); >> + >> +remove: >> + rc = remove_resource(soft); >> + if (rc) >> + dev_warn(&cxlr->dev, "cannot remove soft reserved resource %pr\n", >> + soft); >> +} >> + >> +/* >> + * normalize_resource >> + * >> + * The walk_iomem_res_desc() returns a copy of a resource, not a reference >> + * to the actual resource in the iomem_resource tree. As a result, >> + * __release_resource() which relies on pointer equality will fail. >> + * >> + * This helper walks the children of the resource's parent to find and >> + * return the original resource pointer that matches the given resource's >> + * start and end addresses. >> + * >> + * Return: Pointer to the matching original resource in iomem_resource, or >> + * NULL if not found or invalid input. >> + */ >> +static struct resource *normalize_resource(struct resource *res) >> +{ >> + if (!res || !res->parent) >> + return NULL; >> + >> + for (struct resource *res_iter = res->parent->child; >> + res_iter != NULL; res_iter = res_iter->sibling) { >> + if ((res_iter->start == res->start) && >> + (res_iter->end == res->end)) >> + return res_iter; >> + } >> + >> + return NULL; >> +} >> + >> +static int __cxl_region_softreserv_update(struct resource *soft, >> + void *_cxlr) >> +{ >> + struct cxl_region *cxlr = _cxlr; >> + struct resource *res = cxlr->params.res; >> + >> + /* Skip non-intersecting soft-reserved regions */ >> + if (soft->end < res->start || soft->start > res->end) >> + return 0; >> + >> + soft = normalize_resource(soft); >> + if (!soft) >> + return -EINVAL; >> + >> + remove_soft_reserved(cxlr, soft, res->start, res->end); >> + >> + return 0; >> +} >> + >> +int cxl_region_softreserv_update(void) >> +{ >> + struct device *dev = NULL; >> + >> + while ((dev = bus_find_next_device(&cxl_bus_type, dev))) { >> + struct device *put_dev __free(put_device) = dev; >> + struct cxl_region *cxlr; >> + >> + if (!is_cxl_region(dev)) >> + continue; >> + >> + cxlr = to_cxl_region(dev); >> + >> + walk_iomem_res_desc(IORES_DESC_SOFT_RESERVED, >> + IORESOURCE_MEM, 0, -1, cxlr, >> + __cxl_region_softreserv_update); >> + } >> + >> + return 0; >> +} >> +EXPORT_SYMBOL_NS_GPL(cxl_region_softreserv_update, "CXL"); >> + >> u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa) >> { >> struct cxl_region_ref *iter; >> diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h >> index 1ba7d39c2991..fc39c4b24745 100644 >> --- a/drivers/cxl/cxl.h >> +++ b/drivers/cxl/cxl.h >> @@ -859,6 +859,7 @@ struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev); >> int cxl_add_to_region(struct cxl_port *root, >> struct cxl_endpoint_decoder *cxled); >> struct cxl_dax_region *to_cxl_dax_region(struct device *dev); >> +int cxl_region_softreserv_update(void); >> u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa); >> #else >> static inline bool is_cxl_pmem_region(struct device *dev) >> @@ -878,6 +879,10 @@ static inline struct cxl_dax_region *to_cxl_dax_region(struct device *dev) >> { >> return NULL; >> } >> +static inline int cxl_region_softreserv_update(void) >> +{ >> + return 0; >> +} >> static inline u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, >> u64 spa) >> {