From patchwork Tue Jun 3 22:19:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Smita Koralahalli X-Patchwork-Id: 893973 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2069.outbound.protection.outlook.com [40.107.237.69]) (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 950BB3FE4; Tue, 3 Jun 2025 22:20:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748989209; cv=fail; b=rAP/bwgfah1g1Uwi2oZ7ht47E9SJl3wvGyjamE0e5zmEZ1MKst65e7VY+g+CaHiy4CaFGXmr2A5aBx10dItwncfifFLUId0G6UeJ1ivY/sa/ZRTfgXufL7p5XGAcyuBLq6qfOhtR0e6NF41P8ccZOHhy7CQHE/srRS7pXzKIung= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748989209; c=relaxed/simple; bh=DOGCLb9gDtpRy7m/Q4mPYHGXU7kd6MmTwsNFIXiYtR8=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=p3ekF/vnjWOboDBdV6fQj+GtjCmXHlbY8wo5kZxeO+ncIgFyDZCPfmq9vnO+7pST9t79EEB/YFWTW3gPfZtsZMq1Tj5JT5FwcrvWqvReZYR9OomrC1O3Pl6oSCckZm6ZbvHKA1RHWtxzPX1NpnuqdixUnqxhH5cmlqfOErL65DU= 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=EG3Cm12i; arc=fail smtp.client-ip=40.107.237.69 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="EG3Cm12i" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kQcS6gCJOKR8BZ4j0uwgkVhp/WQcLn80nnlV347vdY+Vm+CtS3EwAtraDZKVrslsCur9iZU52AaHxBkfV+rLSSeDCiSDrDjitFGTe6WjiSRnf7pB6QseYMahSK6/vwYgbm7AZrjzsvXaqz64ut3aHnJzVOwQKe7KBANE0mHr6q+Sbu6oG82ZYiMD6Az8J2tPZ97dQoN1XoxEzPxXKz3VOZQ6CyxZpPAVD99vq9LmRflpG4Fx9Q0MTfk4kt6Gjm1YOPUstCsiU2j0s8WE/2F8KtlOJzLsoUG+lgBJ9Mc6u3ACRrj3PSip2ihvs6WY1yPNoTdipk67pvMMwnu97y268Q== 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=CFWm5nVKzoziQZxSzIkT0myjQIEY1dbQRUF6RkdNX5w=; b=pmxnjLuEYTrfQuqON0llnlDE5h7luINzSXZOP00UHF/l4vJaie0C0nM93pq3lKMcSE7j1AwBCrq+WBCbRmgl9PDcrKM9PS25dOb9VVcyuPYY/svYonND5LXz8cbbX1qsH9aFU3zJBfVQwskHGzOeqRE7saMDyktK5aRnHsCPV4GN4gu+GR5PAkixLZL0fSduEw15BYP95cRdFMeXNWg+JnRmFM/SuKa86uylN1fgUMzlfjKtaRSf6ggw+ytCB1P/K0ecCS4SGEfAAiCoqH8mH363J/UujWEkUKnn91yxZXe0rUOZuf0vx0FozEts7GhGltQawZavXDeDv+mxkj6Rbw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=CFWm5nVKzoziQZxSzIkT0myjQIEY1dbQRUF6RkdNX5w=; b=EG3Cm12iuRrwZQcWXjItzCQLbMd8NWC+lXEm28O3CdkdSewZ9AWc9rnZXqb9zfNZSP08ZpB/mrhDTDswWkykU7Z78JKDSshphgIYxuLCP8lqvBbhNVjhGKam9p2YcHcP8wU4rFPCA9pyf9SEEG1atT51fqK/oA+jg5f4uUNWUa8= Received: from CY5PR04CA0020.namprd04.prod.outlook.com (2603:10b6:930:1e::10) by DM4PR12MB6157.namprd12.prod.outlook.com (2603:10b6:8:ac::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8792.33; Tue, 3 Jun 2025 22:20:02 +0000 Received: from CY4PEPF0000FCC0.namprd03.prod.outlook.com (2603:10b6:930:1e:cafe::6b) by CY5PR04CA0020.outlook.office365.com (2603:10b6:930:1e::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8792.19 via Frontend Transport; Tue, 3 Jun 2025 22:20:01 +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 CY4PEPF0000FCC0.mail.protection.outlook.com (10.167.242.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8792.29 via Frontend Transport; Tue, 3 Jun 2025 22:20:01 +0000 Received: from ethanolx50f7host.amd.com (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, 3 Jun 2025 17:20:00 -0500 From: Smita Koralahalli To: , , , , 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" , Yao Xingtao , Peter Zijlstra , Greg KH , Nathan Fontenot , Smita Koralahalli , Terry Bowman , Robert Richter , Benjamin Cheatham , PradeepVineshReddy Kodamati , Zhijian Li Subject: [PATCH v4 0/7] Add managed SOFT RESERVE resource handling Date: Tue, 3 Jun 2025 22:19:42 +0000 Message-ID: <20250603221949.53272-1-Smita.KoralahalliChannabasappa@amd.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC0:EE_|DM4PR12MB6157:EE_ X-MS-Office365-Filtering-Correlation-Id: 241e68dc-7ef4-4e63-b345-08dda2ecc89b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|7416014|376014|36860700013; X-Microsoft-Antispam-Message-Info: =?ut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bWvR9Rm8KSuAtuuuSYP9/5Df+3Sm82NKg?= =?utf-8?q?tbHuvLYQQHysiyFQmV1ZdvZJuR3Gvdki15slzcDtE7lbsQ5my+HtDsLD8aFK/MJE2?= =?utf-8?q?DtUu4i4sz3lP8fhX37DYm6WC0s45BC61nq5cZgRV6T6MwMRaBF8wgJsVLq83VVWcr?= =?utf-8?q?HKdp5yHdLmy9NZMRSttqEv1HWg2auCzYBztz6Jm9evxu7Y01bkmX2rzKAmtWJlOj3?= =?utf-8?q?1DIOzPiYZc0hjxu1o0swaG6RURc2ut1SyZK/NFl8lEYV4fs+qe3IpBudwWg4GDq1C?= =?utf-8?q?3LZ3/RmyDEvJQ2TVe2/v5chmLKLqHBfil9GNiXxRsHmdFMzL9Me7BB5oNe5qOynYM?= =?utf-8?q?Q7luzMLfIoi6z/lfEXbbIlX7Fr0zWDkux13HT8jEI698OjcSh2zpx2MuNRnXdYAxK?= =?utf-8?q?/emI3Eo9SPtQ7VC1kUIsFeC4mA91FW0mVH1JbLTkBKngRwKaQWWUviFO4N664hnad?= =?utf-8?q?lh0avIxTJV1T/T+Nc85L27f68Ezq+Q7f8TmW4rPmO3DjK7ha+gWoyyjB1R5m8Gu3s?= =?utf-8?q?//aYhDBnK5CBjcuNXisoAtDe7mmW1QIoqjzDiltDG7btGGdpGs5NfyYimflhGeQhY?= =?utf-8?q?qNMyUaMin7?= 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)(7416014)(376014)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2025 22:20:01.7044 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 241e68dc-7ef4-4e63-b345-08dda2ecc89b 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: CY4PEPF0000FCC0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6157 Add the ability to manage SOFT RESERVE iomem resources prior to them being added to the iomem resource tree. This allows drivers, such as CXL, to remove any pieces of the SOFT RESERVE resource that intersect with created CXL regions. The current approach of leaving the SOFT RESERVE resources as is can cause failures during hotplug of devices, such as CXL, because the resource is not available for reuse after teardown of the device. The approach is to add SOFT RESERVE resources to a separate tree during boot. This allows any drivers to update the SOFT RESERVE resources before they are merged into the iomem resource tree. In addition a notifier chain is added so that drivers can be notified when these SOFT RESERVE resources are added to the ioeme resource tree. The CXL driver is modified to use a worker thread that waits for the CXL PCI and CXL mem drivers to be loaded and for their probe routine to complete. Then the driver walks through any created CXL regions to trim any intersections with SOFT RESERVE resources in the iomem tree. The dax driver uses the new soft reserve notifier chain so it can consume any remaining SOFT RESERVES once they're added to the iomem tree. The following scenarios have been tested: Example 1: Exact alignment, soft reserved is a child of the region |---------- "Soft Reserved" -----------| |-------------- "Region #" ------------| Before: 1050000000-304fffffff : CXL Window 0 1050000000-304fffffff : region0 1050000000-304fffffff : Soft Reserved 1080000000-2fffffffff : dax0.0 1080000000-2fffffffff : System RAM (kmem) After: 1050000000-304fffffff : CXL Window 0 1050000000-304fffffff : region1 1080000000-2fffffffff : dax0.0 1080000000-2fffffffff : System RAM (kmem) Example 2: Start and/or end aligned and soft reserved spans multiple regions |----------- "Soft Reserved" -----------| |-------- "Region #" -------| or |----------- "Soft Reserved" -----------| |-------- "Region #" -------| Before: 850000000-684fffffff : Soft Reserved 850000000-284fffffff : CXL Window 0 850000000-284fffffff : region3 850000000-284fffffff : dax0.0 850000000-284fffffff : System RAM (kmem) 2850000000-484fffffff : CXL Window 1 2850000000-484fffffff : region4 2850000000-484fffffff : dax1.0 2850000000-484fffffff : System RAM (kmem) 4850000000-684fffffff : CXL Window 2 4850000000-684fffffff : region5 4850000000-684fffffff : dax2.0 4850000000-684fffffff : System RAM (kmem) After: 850000000-284fffffff : CXL Window 0 850000000-284fffffff : region3 850000000-284fffffff : dax0.0 850000000-284fffffff : System RAM (kmem) 2850000000-484fffffff : CXL Window 1 2850000000-484fffffff : region4 2850000000-484fffffff : dax1.0 2850000000-484fffffff : System RAM (kmem) 4850000000-684fffffff : CXL Window 2 4850000000-684fffffff : region5 4850000000-684fffffff : dax2.0 4850000000-684fffffff : System RAM (kmem) Example 3: No alignment |---------- "Soft Reserved" ----------| |---- "Region #" ----| Before: 00000000-3050000ffd : Soft Reserved .. .. 1050000000-304fffffff : CXL Window 0 1050000000-304fffffff : region1 1080000000-2fffffffff : dax0.0 1080000000-2fffffffff : System RAM (kmem) After: 00000000-104fffffff : Soft Reserved .. .. 1050000000-304fffffff : CXL Window 0 1050000000-304fffffff : region1 1080000000-2fffffffff : dax0.0 1080000000-2fffffffff : System RAM (kmem) 3050000000-3050000ffd : Soft Reserved v4 updates: - Split first patch into 4 smaller patches. - Correct the logic for cxl_pci_loaded() and cxl_mem_active() to return false at default instead of true. - Cleanup cxl_wait_for_pci_mem() to remove config checks for cxl_pci and cxl_mem. - Fixed multiple bugs and build issues which includes correcting walk_iomem_resc_desc() and calculations of alignments. v3 updates: - Remove srmem resource tree from kernel/resource.c, this is no longer needed in the current implementation. All SOFT RESERVE resources now put on the iomem resource tree. - Remove the no longer needed SOFT_RESERVED_MANAGED kernel config option. - Add the 'nid' parameter back to hmem_register_resource(); - Remove the no longer used soft reserve notification chain (introduced in v2). The dax driver is now notified of SOFT RESERVED resources by the CXL driver. v2 updates: - Add config option SOFT_RESERVE_MANAGED to control use of the separate srmem resource tree at boot. - Only add SOFT RESERVE resources to the soft reserve tree during boot, they go to the iomem resource tree after boot. - Remove the resource trimming code in the previous patch to re-use the existing code in kernel/resource.c - Add functionality for the cxl acpi driver to wait for the cxl PCI and me drivers to load. Smita Koralahalli (7): cxl/region: Avoid null pointer dereference in is_cxl_region() cxl/core: Remove CONFIG_CXL_SUSPEND and always build suspend.o cxl/pci: Add pci_loaded tracking to mark PCI driver readiness cxl/acpi: Add background worker to wait for cxl_pci and cxl_mem probe cxl/region: Introduce SOFT RESERVED resource removal on region teardown dax/hmem: Save the DAX HMEM platform device pointer cxl/dax: Defer DAX consumption of SOFT RESERVED resources until after CXL region creation drivers/cxl/Kconfig | 4 - drivers/cxl/acpi.c | 25 ++++++ drivers/cxl/core/Makefile | 2 +- drivers/cxl/core/region.c | 163 ++++++++++++++++++++++++++++++++++++- drivers/cxl/core/suspend.c | 34 +++++++- drivers/cxl/cxl.h | 7 ++ drivers/cxl/cxlmem.h | 9 -- drivers/cxl/cxlpci.h | 1 + drivers/cxl/pci.c | 2 + drivers/dax/hmem/device.c | 47 +++++------ drivers/dax/hmem/hmem.c | 10 ++- include/linux/dax.h | 11 ++- include/linux/pm.h | 7 -- 13 files changed, 270 insertions(+), 52 deletions(-) Tested-by: Li Zhijian