From patchwork Thu Jan 16 17:42:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Fontenot X-Patchwork-Id: 13942077 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C52BFC02187 for ; Thu, 16 Jan 2025 17:42:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A5176B0085; Thu, 16 Jan 2025 12:42:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 554406B0088; Thu, 16 Jan 2025 12:42:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CE556B0089; Thu, 16 Jan 2025 12:42:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1C8736B0085 for ; Thu, 16 Jan 2025 12:42:49 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CB3881C82CB for ; Thu, 16 Jan 2025 17:42:48 +0000 (UTC) X-FDA: 83014035216.05.EE2ADC8 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2050.outbound.protection.outlook.com [40.107.237.50]) by imf26.hostedemail.com (Postfix) with ESMTP id E987B140010 for ; Thu, 16 Jan 2025 17:42:45 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=gbLgNKu4; spf=pass (imf26.hostedemail.com: domain of Nathan.Fontenot@amd.com designates 40.107.237.50 as permitted sender) smtp.mailfrom=Nathan.Fontenot@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737049366; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ES3Oj0e/tNMqS405e+zMLmMRPFZCzhTcxi5HBSVEc8o=; b=fC4lC58NEMEfovSoOOVBsKRKiyNCDsN+PHIS82n8j2p+f5+lCp+q5Jz4z7buudkT6zZeEn IQFS329XtJPPOFQ8fn448hHaQRoNYT7sLptTvANglzK3wCO4PhQnE+X8AV0/4LSPWk2wM6 l1XIKoUVmslP38+bXrQdScZGoAkw9cA= ARC-Authentication-Results: i=2; imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=gbLgNKu4; spf=pass (imf26.hostedemail.com: domain of Nathan.Fontenot@amd.com designates 40.107.237.50 as permitted sender) smtp.mailfrom=Nathan.Fontenot@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1737049366; a=rsa-sha256; cv=pass; b=56aBaFAA9OUTO6ZX0yeMrviuYdnKtnV690FEzh7L8M7fMz/ERIaCINRF1rTeHJMp73rVja GFekw/Tgx+Hk2Hr4VtHqXrNhEJwjwdwfPzUGmQdKDrfyCy43n4Hr++qbj4HY9vN7Hicxkv yNmNdo2xXLbMO8sI5DWcoiNhwxxj82Y= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OdLLlCkgS8sD719F68n1NpThzAy8B3RtO7DldUrtsc+QfBIMG9nO2AoIcAmdSFV85UbjsPKvm5Aa1HXEDh4YmK9O6vXjxpydxRVYiv4noF3V0MIF0oW06C8ORzJc1DdcqZZhdas0aIC/SwgBN419ouYvXNB7wNVpyegUnddE+RgGT99QHjBUUBBgvdfQGzQc7zXl247PHuah7ae6s++8IWAGPxAhg7Zc7n6mGhkIvd07c1T80pHT2/6yLiQ2KBW7osQ/01tsRdpt5tleANxV91A6xkghv36/+KKNfcohzkPhObJCHOsryalxQj1ynTPbogj4FBARgtxCu0xhfzpZ8A== 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=ES3Oj0e/tNMqS405e+zMLmMRPFZCzhTcxi5HBSVEc8o=; b=WeyJa+BjpK42UN0nh/k58+cWmDpRYpcsoplWC37lQoGvaw33rRBdtMrUdllMycyT9/x4Wq5eKy+bsBnGiKxO6EcbAp+rKmdfdn2/ifX0u/erobsFgI3IMZJkC+OkMK1KuSgsC9t9fDIAGXc7VwV2cBW5BOHu+A2i44STaFtwUsgpTuP0hidznzzSIOe9dwjDhI4H5/Y4GkgNSkqvO1wRAfqn3cw+u1c6dxNAiU0MyPDVYiY5/+wIBA3/EGZNEMe1BlrIE5+kJEZtQ/Gs/+crkxH7rpT9BzyPzerp5sG7+aL9z0L5TZcX9lG27T9S656ajQ38CKw1EXUNvfC3S5jNKg== 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=ES3Oj0e/tNMqS405e+zMLmMRPFZCzhTcxi5HBSVEc8o=; b=gbLgNKu4dCCgLrXuhVBQB5aW9IG2suJvt85UhZD2u85GKuXCF9RHiy+430ajSg/VNU79SWsToSOpFSNEwuzjuLUmJLJm56Q2Gmu1zQEtMtNQY07MnPrMVrlrgthNETRr+Xyiils0Q7Elw5yjJAa0JAu3ijOemVvyChHiqKFqYIs= Received: from BN8PR16CA0013.namprd16.prod.outlook.com (2603:10b6:408:4c::26) by MN0PR12MB6247.namprd12.prod.outlook.com (2603:10b6:208:3c1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.14; Thu, 16 Jan 2025 17:42:41 +0000 Received: from BL6PEPF0001AB75.namprd02.prod.outlook.com (2603:10b6:408:4c:cafe::42) by BN8PR16CA0013.outlook.office365.com (2603:10b6:408:4c::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.16 via Frontend Transport; Thu, 16 Jan 2025 17:42:41 +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 BL6PEPF0001AB75.mail.protection.outlook.com (10.167.242.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8356.11 via Frontend Transport; Thu, 16 Jan 2025 17:42:41 +0000 Received: from AUSNAFONTEN1.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; Thu, 16 Jan 2025 11:42:40 -0600 From: Nathan Fontenot To: CC: , , , Subject: [PATCH v2 1/4] kernel/resource: Introduce managed SOFT RESERVED resources Date: Thu, 16 Jan 2025 11:42:05 -0600 Message-ID: <1800b17449d1c231292c85f59b226aff39a81552.1737046620.git.nathan.fontenot@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BL6PEPF0001AB75:EE_|MN0PR12MB6247:EE_ X-MS-Office365-Filtering-Correlation-Id: ed52cced-8c3f-4421-b356-08dd36552d00 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: qvWTrq1veNnUkforj9xJ1dC/yo+9QW3PnuPk4Vxb49lyP6ClPuaoQk/ySQv12NtmWdjghqIvhiYXuFEZxmNjeNFWSJJlsSStBTV7X0T+IxLz0fYCULy7iF2r/bR422heHCkjC1W9l0qPhU3hRzARuGJkFCqf9g1/4WaTf5SJuu+qpQvDlzGPxFtjQLNFuDj1jTMmn1cyt9Sjq1eZsnJFmjCx7IxSuHroOX89bZQJ0h6vR/iSflSGXn/xO0MuBTm5dYLN56bzmOFAeV/Nk1wdkW1XixDIcfXKly6cut75GqF5EqtK3dehlpq1dEi5vII40msB7IV4PSwImyFZpQc9O2yStYF4hyJHDl2bpFieUVOGyrEs2zSOpQhbJDiCiRaZwcKh7iy2SAUC//eFv1KY6eNHWA1nYMaIPaJZa/OAYP3NmVKNRgRCNMaJAMCtko4I6MkvP+BNnzm46Awwitqii0JFqe3pAWeJvS3BbBUdRwlkZHwkXIyrRLMJjgHX0sO3/1HtQBizWXbOKwf23Odm5/GLBhljNr6tesVF6Aa/oKzNuq/3rtTjGJ3NnHg75cyEqVI4xZ5/XypkYkKUEo0Avl1wxt4LQeyYxvvbgmfM27ZlpCYhUlWcgK2psutRnJVSyz+H2d9+Cq1sgvFexIYPtA4xj93jQTeVom31iEbNIRaKAWvRbYPK9ovaQkM09c0kLp0R0U5oShjTLdoKeBiGSaj6e+Lnft0eD1kZ/3JgQp00LYyJ6TGnpRlcAV4JFaLEfWfahSRfMEO7L5ezPnWrYhn8gqPQVyecCDJKaWzd5cR3nQJLqrOz1aIbZAEPhcDoO0bomkDoDhlc/j94Sbhw2PcW1skwhznGmLk8f8pbNjLxQv60h/uLln0tXqsGS0uufad6sTXNusWZdguHK5LLSzUoYFcod0H0d49jUweoStXRfSnmG7mvsR17K2AgDwziJrujUc2DdU2FgPhyszY1X0n10O8Dz0UhHGiuv/5F9hJFyPmS7UKCoTlwIhuNnh9u+yQ81go7PfE8Icnh9CP0+P++MPKFkUOES3GrSDFNYADgbtvWpYr/Qbd04FIkgACh1TkmpRpyk2cJZYkBaL+ggUhJLPep3D/KV5iJuJJ0X09a/GQuBEsa37OyFRKUin2ElCF0ekRn+7VOxTCtJPRtwgITml/xDcxIJ/Rcbk9aboNpx1hNfKp7QF/TMq+0hpnBPsp7fKseg+2zQhiCM3zQFtqypiG3hU97QV04RiKaoHSZ6YTjtmQh2GjS9EP8bp6uXMs7xX7hJ/BNF6e61N7S7+U6EmhA3NISN0vNsWLuHvIV8YRW3Yp1aqWkav0GWFt6Gcb9iznxr1P8NVcZpweFJ6+/RZVJMV8ILXmBjhho5BdG9WgeJXFEjZjyDJESoBLsTc3EQ2LT5x4HucbHNlpB8hZF3cwTxjCPjjDRmB4dV26uOO/GLAZhAUscIoM9VfXHDpP72ZYZu0Rb5McBGhoULjlNQ8EpQaYO+xsBZbLfUOs= 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)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 17:42:41.0837 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ed52cced-8c3f-4421-b356-08dd36552d00 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: BL6PEPF0001AB75.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6247 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E987B140010 X-Stat-Signature: 8c8m85eiq7ouigxbphzixuqdtz1eccu9 X-Rspam-User: X-HE-Tag: 1737049365-646058 X-HE-Meta: U2FsdGVkX1/Ipv8Xun2oEyJHIQU7r39Q7a5C5efDzt6qOVheO+ihrJeQeqp8xU28OO1b9k+sSM2Gu+Crg2/TVzg71CfTYwCTmJ0kLRudRLkX198HYGEexmL09JeWzB6kSoCr3suJp7tbB4eecdkQ+R6avKJ7RGTlWBc9jJDhlj3ypaPUB04EF6ERsaebBLBeyeDLQ6P7QNlOEzV2ngwU/7O2p4veQ4PYhL469WGZtDR2Nbw0F2hBE7913OEoKCg8f7mm0swNd+wHo8MBGe76SBAOY7ATUoGfpC3lKL7Kq7LgZV0OmD0BMdQDPZVzVtvypZ0neciPNVoW1LBdbcB4EaHjM/gHF4CCQ5p7dbcdZEU9afr9PAfBn7s54MOn1QB3J9wCV6nYm9JOMQiMgl4ub19Eis9NdBiENgiiIf+6RT3lIJKAlZ6OYaTEZlUfPJoG7RcDYbkM+AXV3j8SJaiG8pPLZp+0eo005+elFVXqoeETWHbV9oIHM+Q4mn6jOZ/1SXO0C7r3KvJPMA+b09lAxfGY80NDDfDLaKSamw9msavawFS+Ssw7ZNue0tqflL4nsE5PO72sp+XG2nSax7+b7K5JPaBHMSgSeCsp7jevqVYfPblckdfB7QIA59lBWrfg1zXbGy9kPqr7NnLu5Rn1H5wsyvsKqRe4o2SYeYuPoOPxQDfwupOeSsdajHLiNcanZwzpgz9CkTTN5LozPGJpMtEOf/DqUHVaOFDiave1h2cCI5mNz9RZyN2I6pfVzCFmWxg6k3OBe7GmI8AD5OYlBckzjwwTIKakCwrCt8/cy/fzb2PjyP7ZebeiO8W/FVme1Mb9IUGG2FWpCKoqSfzVS7UW6WzqPwfoFl5C/VXW2TYFDAx0hHg1Q8lnONyzBK1OwZ4yIibOCBZX7z10zjfaZQqFTSv7Vra/GumUwkySh34jHEkVsObxUh8m2Spoo5olyvPMpdXgxgQSjpI7efa /TEXf7p6 JAostzYvuCIo4xJK9u+YS/L6PDIBiGA16GXjw6b7xg8MfQNvFsPZzFvtaRemXYJ/1QihVA1hpL689ZexaCct7I0l7GLhOQStE30v9J/PTY3HG65+IBZVu5YijItRtTmcplkjCW+TdF1WBmrftC6ahljF7H2/kEbK6eNOCRUfeSZQtoTueg+g6hA4H9fBsXToLQWo6MzlF3o6x/zPpjRkcXyXBm+JmrAzk2ekErj+E1UBIHo1bIAZf2vyX9GtqcL0DL7rXMfwgqzKDlTZ4WFIS6enlCBCllBmSe662H5vUEs12nAMU3dN0rW4zl74r2hKGxrjDVvF4+kNsmNuYsOQteqigF1ZZ/EW0EIHqgNmny4sjjlERXtB6+W4rblBCgTb15sXzSu200u2FWZnq4y0v7GfNyvedLFdb7P0DKGXdFVgUIbriJ5c0CQjX8Z7CYlqoGcVodbmocx3A4VE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Introduce the ability to manage SOFT RESERVED kernel resources prior to these resources being placed in the iomem resource tree. This provides the ability for drivers to update SOFT RESERVED resources that intersect with their memory resources. During boot, any resources marked as IORES_DESC_SOFT_RESERVED are placed on the soft reserve resource tree. Once boot completes all resources are placed on the iomem resource tree. This behavior is gated by a new kernel option CONFIG_SOFT_RESERVED_MANAGED. As part of this update two new interfaces are added for management of the SOFT RESERVED resources. The release_srmem_region_adjustable() routine allows for removing pieces of SOFT RESERVED resources. The the merge_srmem_resources() allows drivers to merge any remaining SOFT RESERVED resources into the iomem resource tree once updatea are complete. Signed-off-by: Nathan Fontenot --- include/linux/ioport.h | 9 +++++ kernel/resource.c | 79 +++++++++++++++++++++++++++++++++++++++--- lib/Kconfig | 4 +++ 3 files changed, 87 insertions(+), 5 deletions(-) diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 6e9fb667a1c5..2c95cf0be45e 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -249,6 +249,15 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start); int adjust_resource(struct resource *res, resource_size_t start, resource_size_t size); resource_size_t resource_alignment(struct resource *res); + +#ifdef CONFIG_SOFT_RESERVED_MANAGED +void merge_srmem_resources(void); +extern void release_srmem_region_adjustable(resource_size_t start, + resource_size_t size); +#else +static inline void merge_srmem_resources(void) { } +#endif + static inline resource_size_t resource_size(const struct resource *res) { return res->end - res->start + 1; diff --git a/kernel/resource.c b/kernel/resource.c index a83040fde236..9db420078a3f 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -48,6 +48,14 @@ struct resource iomem_resource = { }; EXPORT_SYMBOL(iomem_resource); +static struct resource srmem_resource = { + .name = "Soft Reserved mem", + .start = 0, + .end = -1, + .flags = IORESOURCE_MEM, + .desc = IORES_DESC_SOFT_RESERVED, +}; + static DEFINE_RWLOCK(resource_lock); static struct resource *next_resource(struct resource *p, bool skip_children) @@ -818,6 +826,19 @@ static struct resource * __insert_resource(struct resource *parent, struct resou { struct resource *first, *next; + if (IS_ENABLED(CONFIG_SOFT_RESERVED_MANAGED)) { + /* + * During boot SOFT RESERVED resources are placed on the srmem + * resource tree. These resources may be updated later in boot, + * for example see the CXL driver, prior to being merged into + * the iomem resource tree. + */ + if (system_state < SYSTEM_RUNNING && + parent == &iomem_resource && + new->desc == IORES_DESC_SOFT_RESERVED) + parent = &srmem_resource; + } + for (;; parent = first) { first = __request_resource(parent, new); if (!first) @@ -1336,11 +1357,12 @@ void __release_region(struct resource *parent, resource_size_t start, } EXPORT_SYMBOL(__release_region); -#ifdef CONFIG_MEMORY_HOTREMOVE /** - * release_mem_region_adjustable - release a previously reserved memory region + * release_region_adjustable - release a previously reserved memory region + * @parent: resource tree to release resource from * @start: resource start address * @size: resource region size + * @busy_check: check for IORESOURCE_BUSY * * This interface is intended for memory hot-delete. The requested region * is released from a currently busy memory resource. The requested region @@ -1356,9 +1378,11 @@ EXPORT_SYMBOL(__release_region); * assumes that all children remain in the lower address entry for * simplicity. Enhance this logic when necessary. */ -void release_mem_region_adjustable(resource_size_t start, resource_size_t size) +static void release_region_adjustable(struct resource *parent, + resource_size_t start, + resource_size_t size, + bool busy_check) { - struct resource *parent = &iomem_resource; struct resource *new_res = NULL; bool alloc_nofail = false; struct resource **p; @@ -1395,7 +1419,7 @@ void release_mem_region_adjustable(resource_size_t start, resource_size_t size) if (!(res->flags & IORESOURCE_MEM)) break; - if (!(res->flags & IORESOURCE_BUSY)) { + if (busy_check && !(res->flags & IORESOURCE_BUSY)) { p = &res->child; continue; } @@ -1445,6 +1469,51 @@ void release_mem_region_adjustable(resource_size_t start, resource_size_t size) write_unlock(&resource_lock); free_resource(new_res); } + +#ifdef CONFIG_SOFT_RESERVED_MANAGED +/** + * merge_srmem_resources - merge srmem resources into the iomem resource tree + * + * This is intended to allow kernel drivers that manage the SOFT RESERVED + * resources to merge any remaining resources into the iomem resource tree + * once any updates have been made. + */ +void merge_srmem_resources(void) +{ + struct resource *res, *next; + int rc; + + for (res = srmem_resource.child; res; res = next) { + next = next_resource(res, true); + + write_lock(&resource_lock); + + if (WARN_ON(__release_resource(res, true))) { + write_unlock(&resource_lock); + continue; + } + + if (WARN_ON(__insert_resource(&iomem_resource, res))) + __insert_resource(&srmem_resource, res); + + write_unlock(&resource_lock); + } +} +EXPORT_SYMBOL_GPL(merge_srmem_resources); + +void release_srmem_region_adjustable(resource_size_t start, + resource_size_t size) +{ + release_region_adjustable(&srmem_resource, start, size, false); +} +EXPORT_SYMBOL(release_srmem_region_adjustable); +#endif + +#ifdef CONFIG_MEMORY_HOTREMOVE +void release_mem_region_adjustable(resource_size_t start, resource_size_t size) +{ + release_region_adjustable(&iomem_resource, start, size, true); +} #endif /* CONFIG_MEMORY_HOTREMOVE */ #ifdef CONFIG_MEMORY_HOTPLUG diff --git a/lib/Kconfig b/lib/Kconfig index b38849af6f13..4f4011334051 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -777,3 +777,7 @@ config POLYNOMIAL config FIRMWARE_TABLE bool + +config SOFT_RESERVED_MANAGED + bool + default n From patchwork Thu Jan 16 17:42:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Fontenot X-Patchwork-Id: 13942078 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C454C02183 for ; Thu, 16 Jan 2025 17:43:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 297CC6B0089; Thu, 16 Jan 2025 12:43:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 248476B008A; Thu, 16 Jan 2025 12:43:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09B006B008C; Thu, 16 Jan 2025 12:43:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D90B76B0089 for ; Thu, 16 Jan 2025 12:43:05 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8DCD3B082E for ; Thu, 16 Jan 2025 17:43:05 +0000 (UTC) X-FDA: 83014035930.06.E5164FA Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2050.outbound.protection.outlook.com [40.107.94.50]) by imf04.hostedemail.com (Postfix) with ESMTP id 6D11340012 for ; Thu, 16 Jan 2025 17:43:02 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=TyzNYf7x; spf=pass (imf04.hostedemail.com: domain of Nathan.Fontenot@amd.com designates 40.107.94.50 as permitted sender) smtp.mailfrom=Nathan.Fontenot@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737049382; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HBU4OM2e/K9qgr8+Hy0dp7OoswFL4Z2DWJlCcpmN5AM=; b=oLANzUOvbi9icVH3aEpQgkNTkfQHWcIhvl6jkSVp6CG9OY5EeQ5TMrsX1N/5mZpmG+zWt+ 1CaJa9JJT1nKSL/pFN5wvhkFFx3fu9z7Nw+9uGiF7v4RL7cyjN05G2ONZNxCM9ANZmLr7t SmSjDylHK044Jhht3YtrNS/TBpWViBo= ARC-Authentication-Results: i=2; imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=TyzNYf7x; spf=pass (imf04.hostedemail.com: domain of Nathan.Fontenot@amd.com designates 40.107.94.50 as permitted sender) smtp.mailfrom=Nathan.Fontenot@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1737049382; a=rsa-sha256; cv=pass; b=nJoli6jKs0RnERHOqYDprkhr9a5a+J/0XZCgfTHkCtQkcyrhPU9zdOWpWTBQlP6y9oJtdW f+rMD1gjhU8VwoLq9KSZqiwT7oAny5FaQkrEYIV8L+pG3dZzKrkPAzqGz2CqIaiPGCzgnT btWoc+Q/ez14apVXAaDQOTPfWwKoVz8= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=p5PjuMmfOXWpTU4z8bUycDEqu+PQUDbnc3SUCcImCihc3LQ6HsNqnQcKM6Au87w73asuHeHf35Ll/SlBAiSGS9C161mL3TmKM2qoWJjPxE3+7saO+w/LcB2jpu5jUKjpR6ofOIjH8cCnlwyQ2WG0wU4byCijPYJxpvfYUwvTafVlDnfXcDp7QUTbsodrX2h26epfCllqjEoPhRxHNM8rQHlAoAxqaNGGNG2gTbcAGA3WXEfBPtBAUmhrk2xE7kXtYsIJjwq3jdHws741ANAxAKhvmjmYSI+mGfvc53xUcGXTTEZkmCsin+r/QwK7f4oihxcbSlm8gjWM1rTLa3JpGg== 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=HBU4OM2e/K9qgr8+Hy0dp7OoswFL4Z2DWJlCcpmN5AM=; b=AyyKRPj8hdNf3EUVvcI2vbScleeM/qAnP5EB+vLGF4FeeOrxgrrYCEXfl+1PpAOVh8Hh+1Yq5kV3qQ7w8dYdfs82A6NbhRNDnKjD7rh/tk3QV3FWb+KxdPCLKYIyPwZy92rPpvQp+DFaSsUcBhO/DnulKHbqapOb7aSIvORihVpRPmhLP28SplXbGiVOHohDTcEOp++OpHBrwZv1Xrxo5Am4xaXBq8VJD4EOhCGfXKXc3PJENs4VtFcQZMjyA7q9AH1V/6rhSuaqUyPKblQ+epVoKGM4NnFjDCahEecDHBm3wvkGjIaJkZSPPU16ihZPHnUHVJUa8LF5yt3uvLu/Wg== 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=HBU4OM2e/K9qgr8+Hy0dp7OoswFL4Z2DWJlCcpmN5AM=; b=TyzNYf7x0lYnlAeo5UFOZtwfFFrmBROpXjdAVz34SWllE/s+vzqjb7/JNCdV/0XKXxuO1Uv6Qb1h4kGHREXppYMJUNNIKCSkW3VMj3IU60q6c5/KUcYduSmgtfLpDD3Nu7SfJtDBJ4YK036VE+6hQ7lDVCCqllO74llGB63Go+I= Received: from MN2PR01CA0063.prod.exchangelabs.com (2603:10b6:208:23f::32) by PH7PR12MB6882.namprd12.prod.outlook.com (2603:10b6:510:1b8::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.13; Thu, 16 Jan 2025 17:42:57 +0000 Received: from BL6PEPF0001AB71.namprd02.prod.outlook.com (2603:10b6:208:23f:cafe::b) by MN2PR01CA0063.outlook.office365.com (2603:10b6:208:23f::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.14 via Frontend Transport; Thu, 16 Jan 2025 17:43:03 +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 BL6PEPF0001AB71.mail.protection.outlook.com (10.167.242.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8356.11 via Frontend Transport; Thu, 16 Jan 2025 17:42:57 +0000 Received: from AUSNAFONTEN1.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; Thu, 16 Jan 2025 11:42:56 -0600 From: Nathan Fontenot To: CC: , , , Subject: [PATCH v2 2/4] cxl: Update Soft Reserve resources upon region creation Date: Thu, 16 Jan 2025 11:42:06 -0600 Message-ID: <46f9193747024c336b998da64585f2dc2b58a5d1.1737046620.git.nathan.fontenot@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BL6PEPF0001AB71:EE_|PH7PR12MB6882:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a19366e-56dd-4793-a079-08dd365536d8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: 4L+T2/yRWpx+c5CjHLqt7Wy40u2FVDXVrZ1uNTjzjO1oirU2eMsTiYHHuHGv5PNElyZv7axmsr+WkgtVgVb7b4x7xSPjs4b9FhnMgmFt77g8K/eGDkHiRT5j95FW4w43mgD0t7K5qdbYrpSqMYjX9CYOpMx82Gd7vxASkYxx+wSovAlRtfd71hK5ZRrT+kEsNwN4X0BjJ4z4g2JYZIt84Xjl+y2cfBdKSOrSrNNCn3vkLuIGknewaTHi/CdHLNBKoBwubLfQXek7xHCKYvX2I1TVLBhOQrf/5dwfNzEKPtVb0vKQ6d51L2DQGkTqRdnlEBP+Ao+KEQb8c1BVM7IjBqxC/zVDGcrgkUxx0EowApOCn/5lXo/eD1QDFtHV6UTIv5ZijVquZRvJqa0lhPcPBdtZhYAHXA+UTvmC1nzsIiCchjvEW4leQq4ADKnvdIFHoP4cYzhQu5dMvjI/fG1fnVoLaw9t8MyYBLJPUBWaDeJ4YibJ91pVgUb2WkTiB08LoaoO9gRQdW4SWdJD5ED3y0gjNXFjXi2YHp2UoVs3r6hsDuUYau2rClRVdRv5DnH5rYnpQHMk0zia3KV/MJsFAQmNoPtxFvnZdAIeysOqnJFTpCZ0GN50khidnrVzQdb82Zn+BQ8qC/GRb03kfBt7xhRsDd7gEG6NxdOMeYt70xh/4A8iymyuMcX+4e1rlQyY5Re1BgJTg+xCRgTQfG6zBU0ifwMfdNXF/lf7LPJswDGbVJ2pE/m6kDoe3dMHHNjxRTQeX7jRK0Mc35IQcNvDh770NwLQoUDzp2rAo7jZkp/6UVsOyENLmBfMgu5MSMSXfEPWrlpIZTFwfZw+Md0jW9/gtB4DWe7A/ZBBUt27KNQxB1ntZnKX73vUhsX8k3sZKKHBnepiVT7pj+CbwjdwsmCs74A8RKYRxHqAulSHaIxafvfCi+n8tRvZYOdR0aZQJunQTkEgnksA+mpU2L7hIwcEC1DT7kT6dJrw5IycWmWnPCf7s7d5msBuUVV5vVu7y0jJ2pw3g8HltFIeBdW5WCcWRpDmGQYUHK1DgEj6bsNhUrBesgNqHntUmphyEJN7QdVniA2tGpCdCupUltYqL8ZSkSaJx+1Rf0kQczZihUbQNhz3HYTQjBTGNr0Y7RAGmSUuPt9m4oPoX30STTP3UZBsOzitsV/ZNwDkwjYx0nGuUOiysF/PgX8rw5ZV3P48haes8C66LPMUWiFJunBNXnVoNtOem4CnfGtiZKjav63bPrVaSmHHrdGJz1VzihwjS6zu7AkI22cMuTkwDpfA+mn1LbceY0TMrvvgsOAtwq4oomkZdw35zYufn6FcyGC3O23HM2XCYelnCrCkD72qFDtD0JgGzEMaoUP5xHBKeMPfutq4KvjcdxKm08YBPDp/wldRSWYCAz393zT2E5SwZ+q6rIme0voZ1pAVAmrca8jeNiNX6dS0K7/MEWLYeEZa0GtYnWrkHrY/sJpP0uzAtJx507zq2pdwWZMt/8eijv8= 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)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 17:42:57.6140 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3a19366e-56dd-4793-a079-08dd365536d8 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: BL6PEPF0001AB71.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6882 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6D11340012 X-Stat-Signature: 9syow5hk93ejaequhpuonf8qbff79itp X-Rspam-User: X-HE-Tag: 1737049382-740642 X-HE-Meta: U2FsdGVkX1+CxH/9Z3inCP9aK3oekYACbhozzE6f543CV/a6/KOkgVjiq/QRoP95WWJS9+jOT8K+0YPziT5TuDrCgBcfQcE7KzlhPgiPyQX4Us8JjvF7+T+yatZku+8ROMIAjN8GSmGz7G7daKIM7ApFZND+MxCjac0eWW9irduH6HhL5+U92PNqiJKpIjiKEzLx+MUEZllertOzL9dAM/ES7KUHeTQuDtv1cB8X4tH2vkBhzh5/lrnJGQP+erHUZRBn4kwI46PWOAZ8OD6qXlX7ckulhHPf+LEZSEZPO5wDGJOrLTaADWAJf20oCzNpHced0VJyUuhvUPBRWey0Q2jXCOL8tdIfJYg96aLFl4Nb4Kq8S8vXKLqZpilA85qNTJI4NXeG7F+k/c7ptr7J4uN9R0Zmx/BM0hZ1UlSlmdXqGO1OLZvg86nKcjeKFOcT+KzL4KbelwQ9m3g7sqZ4NzyEHPM9QBrbAfrk8D7/wNu3EcVYv03ywC2LvyzvOpBQMAFw+6o/SftZD4g41MGRAJxG1wxZ/23fOC6rdi6WcGKUPqQQ099QCbP1k8dXlUSsJPm5UBSjsw/8HmctPyFYEwG9U20u+pULqCulzpFNlcH8pd+xmvicPN+nCVPZh855F8nj9257tPQjDFI5tPnSReMp8ygE1I9nm1a2ns7K1rgGp2Iar5Jl00VcrHPrA5/GuWsGPBN9hW88GU5Y6KGjSFkKUuUi+POhjwutp2WwHrntCrcAT2MJzFvKlU5IHN41H3mNF9wwwjkd90euM5EdTaDf3/loLgZa7EjH0vi+jn+IvlhL6rVyHdbMwDKVgbmPn6/3Zpm9YXfK787zF+CKZJX/bVuJtLaJdHN/L9lJnRq4FfoPkIlKQKSukRk838dNlu06jwXEoLhTUooj1n3eXhpz5h5QtsdcM1Cyw4W5fYVR/vObT+onBjZf6qv0mZ3JgzLrIidbOwjg4TGydcX V3pbHkhZ EqWC4ANG/NagGlrCmx5d6PgEcrtHUod2Zjn6ypyzfHH+L65lVMYsGXJGUqTjlK++8YL1Hq+f3btuVFgIo4+RkmvGBLRWkVCHnjDW8PnstEKG9gYt/OMcBSnvA9zGJUoivaKAseexzuENTRO9Fy4wr7WDZbh9SOhMukNmfEHsxzqU1Wbf1q/7qwVb4vWY5cx6RX9U8SAGAcI31TndI5wjffS7Oq4pD7pcFl+S+HdwjOkslRx5RhCXmWArX01CgaLWXyNhGIhaM3YpaPuf0uBsESyVI0DcgV2vBnEXZp1fWqBOADNfCHS/NCjGfZ23JNRBpX//KUgXFBbjZkYzidRj7N850ERFvk0yyc6bShwrMWvwdGaIfRUkEVNGumJngLA6vPg/XZ+WvrMwv1rFmHEAI1JvgEvy8FGRzA78ZIUYBhWiAPljGztCY31HeS1H0rELGxBWu3UkGeXZb9lfLCWKkP8tWLBV6Os13K2l83MJnUyabv3I= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Update handling of SOFT RESERVE iomem resources that intersect with CXL region resources to remove intersections from the SOFT RESERVE resources. The current approach of leaving SOFT RESERVE resources as is can cause failures during hotplug replace of CXL devices bercause the resource is not avaialable for reuse after teardown of the CXL device. The approach is to use the CONFIG_SOFT_RESERVED_MANAGED config option to have SOFT RESERVE resources set aside during boot. After the CXL drivers complete their probe and CXL regions are created any CXL region intersections with SOFT RESERVE resources are removed from the SOFT RESERVE resource. The remaining SOFT RESERVE resources, if any, are then added to the iomem resource tree. To accomplish this the cxl acpi driver creates a worker thread at the end of cxl_acpi_probe(). This worker thread first waits for the CXL PCI CXL mem drivers have loaded. The cxl core/suspend.c code is updated to add a pci_loaded variable, in addition to the mem_active variable, that is updated when the pci driver loads. A new cxl_wait_for_pci_mem() routine uses a waitqueue for both these driver to be loaded. The need to add this additional waitqueue is ensure the CXL PCI and CXL mem drivers have loaded before we wait for their probe, without it the cxl acpi probe worker thread calls wait_for_device_probe() before these drivers are loaded. After the CXL PCI and CXL mem drivers load the cxl acpi worker thread uses wait_for_device_probe() to ensure device probe routines have completed. After probe completes, find all cxl regions that have been created and remove any intersections with SOFT RESERVE resources and add remaining SOFT RESERRVES to the iomem resource tree. Signed-off-by: Nathan Fontenot --- drivers/cxl/Kconfig | 1 + drivers/cxl/acpi.c | 26 ++++++++++++++++++++++++ drivers/cxl/core/Makefile | 2 +- drivers/cxl/core/region.c | 25 ++++++++++++++++++++++- drivers/cxl/core/suspend.c | 41 ++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 3 +++ drivers/cxl/cxlmem.h | 9 --------- drivers/cxl/cxlpci.h | 2 ++ drivers/cxl/pci.c | 1 + 9 files changed, 99 insertions(+), 11 deletions(-) diff --git a/drivers/cxl/Kconfig b/drivers/cxl/Kconfig index 99b5c25be079..5d9dce2fb282 100644 --- a/drivers/cxl/Kconfig +++ b/drivers/cxl/Kconfig @@ -60,6 +60,7 @@ config CXL_ACPI default CXL_BUS select ACPI_TABLE_LIB select ACPI_HMAT + select SOFT_RESERVED_MANAGED help Enable support for host managed device memory (HDM) resources published by a platform's ACPI CXL memory layout description. See diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c index 82b78e331d8e..a95004230f85 100644 --- a/drivers/cxl/acpi.c +++ b/drivers/cxl/acpi.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include "cxlpci.h" #include "cxl.h" @@ -813,6 +815,27 @@ static int pair_cxl_resource(struct device *dev, void *data) return 0; } +static void cxl_srmem_work_fn(struct work_struct *work) +{ + /* Wait for CXL PCI and mem drivers to load */ + cxl_wait_for_pci_mem(); + + /* + * Once the CXL PCI and mem drivers have loaded wait + * for the driver probe routines to complete. + */ + wait_for_device_probe(); + + cxl_region_srmem_update(); +} + +DECLARE_WORK(cxl_sr_work, cxl_srmem_work_fn); + +static void cxl_srmem_update(void) +{ + schedule_work(&cxl_sr_work); +} + static int cxl_acpi_probe(struct platform_device *pdev) { int rc; @@ -887,6 +910,9 @@ static int cxl_acpi_probe(struct platform_device *pdev) /* In case PCI is scanned before ACPI re-trigger memdev attach */ cxl_bus_rescan(); + + /* Update SOFT RESERVED resources that intersect with CXL regions */ + cxl_srmem_update(); return 0; } diff --git a/drivers/cxl/core/Makefile b/drivers/cxl/core/Makefile index 9259bcc6773c..01587ba1dcdb 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_CXL_BUS) += cxl_core.o -obj-$(CONFIG_CXL_SUSPEND) += suspend.o +obj-y += suspend.o ccflags-y += -I$(srctree)/drivers/cxl CFLAGS_trace.o = -DTRACE_INCLUDE_PATH=. -I$(src) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 21ad5f242875..3f4a7cc4539b 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include "core.h" @@ -2294,7 +2295,7 @@ const struct device_type cxl_region_type = { bool is_cxl_region(struct device *dev) { - return dev->type == &cxl_region_type; + return dev && dev->type == &cxl_region_type; } EXPORT_SYMBOL_NS_GPL(is_cxl_region, CXL); @@ -3377,6 +3378,28 @@ int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled) } EXPORT_SYMBOL_NS_GPL(cxl_add_to_region, CXL); +int cxl_region_srmem_update(void) +{ + struct device *dev = NULL; + struct cxl_region *cxlr; + struct resource *res; + + do { + dev = bus_find_next_device(&cxl_bus_type, dev); + if (is_cxl_region(dev)) { + cxlr = to_cxl_region(dev); + res = cxlr->params.res; + release_srmem_region_adjustable(res->start, + resource_size(res)); + put_device(dev); + } + } while (dev); + + merge_srmem_resources(); + return 0; +} +EXPORT_SYMBOL_NS_GPL(cxl_region_srmem_update, CXL); + static int is_system_ram(struct resource *res, void *arg) { struct cxl_region *cxlr = arg; diff --git a/drivers/cxl/core/suspend.c b/drivers/cxl/core/suspend.c index a5984d96ea1d..589f7fc931ee 100644 --- a/drivers/cxl/core/suspend.c +++ b/drivers/cxl/core/suspend.c @@ -2,18 +2,27 @@ /* Copyright(c) 2022 Intel Corporation. All rights reserved. */ #include #include +#include #include "cxlmem.h" +#include "cxlpci.h" static atomic_t mem_active; +static DECLARE_WAIT_QUEUE_HEAD(cxl_wait_queue); + +static atomic_t pci_loaded; + +#ifdef CONFIG_CXL_SUSPEND bool cxl_mem_active(void) { return atomic_read(&mem_active) != 0; } +#endif void cxl_mem_active_inc(void) { atomic_inc(&mem_active); + wake_up(&cxl_wait_queue); } EXPORT_SYMBOL_NS_GPL(cxl_mem_active_inc, CXL); @@ -22,3 +31,35 @@ void cxl_mem_active_dec(void) atomic_dec(&mem_active); } EXPORT_SYMBOL_NS_GPL(cxl_mem_active_dec, CXL); + +void mark_cxl_pci_loaded(void) +{ + atomic_inc(&pci_loaded); + wake_up(&cxl_wait_queue); +} +EXPORT_SYMBOL_NS_GPL(mark_cxl_pci_loaded, CXL); + +static bool cxl_pci_loaded(void) +{ + if (IS_ENABLED(CONFIG_CXL_PCI)) + return atomic_read(&pci_loaded) != 0; + + return true; +} + +static bool cxl_mem_probed(void) +{ + if (IS_ENABLED(CONFIG_CXL_MEM)) + return atomic_read(&mem_active) != 0; + + return true; +} + +void cxl_wait_for_pci_mem(void) +{ + if (IS_ENABLED(CONFIG_CXL_PCI) || IS_ENABLED(CONFIG_CXL_MEM)) + wait_event_timeout(cxl_wait_queue, + cxl_pci_loaded() && cxl_mem_probed(), + 30 * HZ); +} +EXPORT_SYMBOL_NS_GPL(cxl_wait_for_pci_mem, CXL); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 9afb407d438f..65e425e72970 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -861,6 +861,7 @@ bool is_cxl_pmem_region(struct device *dev); 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); +int cxl_region_srmem_update(void); struct cxl_dax_region *to_cxl_dax_region(struct device *dev); #else static inline bool is_cxl_pmem_region(struct device *dev) @@ -898,6 +899,8 @@ void cxl_coordinates_combine(struct access_coordinate *out, bool cxl_endpoint_decoder_reset_detected(struct cxl_port *port); +void cxl_wait_for_pci_mem(void); + /* * Unit test builds overrides this to __weak, find the 'strong' version * of these symbols in tools/testing/cxl/. diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index afb53d058d62..df6bf7778321 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -838,17 +838,8 @@ int cxl_trigger_poison_list(struct cxl_memdev *cxlmd); int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa); int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa); -#ifdef CONFIG_CXL_SUSPEND void cxl_mem_active_inc(void); void cxl_mem_active_dec(void); -#else -static inline void cxl_mem_active_inc(void) -{ -} -static inline void cxl_mem_active_dec(void) -{ -} -#endif int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd); diff --git a/drivers/cxl/cxlpci.h b/drivers/cxl/cxlpci.h index 4da07727ab9c..42d9423ba4c0 100644 --- a/drivers/cxl/cxlpci.h +++ b/drivers/cxl/cxlpci.h @@ -129,4 +129,6 @@ void read_cdat_data(struct cxl_port *port); void cxl_cor_error_detected(struct pci_dev *pdev); pci_ers_result_t cxl_error_detected(struct pci_dev *pdev, pci_channel_state_t state); + +void mark_cxl_pci_loaded(void); #endif /* __CXL_PCI_H__ */ diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 4be35dc22202..d90505e3605c 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -1054,6 +1054,7 @@ static int __init cxl_pci_driver_init(void) if (rc) pci_unregister_driver(&cxl_pci_driver); + mark_cxl_pci_loaded(); return rc; } From patchwork Thu Jan 16 17:42:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Fontenot X-Patchwork-Id: 13942079 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF432C02183 for ; Thu, 16 Jan 2025 17:43:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F2DA6B008C; Thu, 16 Jan 2025 12:43:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A32C6B0092; Thu, 16 Jan 2025 12:43:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41D146B0093; Thu, 16 Jan 2025 12:43:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 231986B008C for ; Thu, 16 Jan 2025 12:43:25 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 95BD6AEE29 for ; Thu, 16 Jan 2025 17:43:24 +0000 (UTC) X-FDA: 83014036728.21.2721CC5 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2075.outbound.protection.outlook.com [40.107.93.75]) by imf03.hostedemail.com (Postfix) with ESMTP id A760B2000B for ; Thu, 16 Jan 2025 17:43:21 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=bi4Ji7v1; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf03.hostedemail.com: domain of Nathan.Fontenot@amd.com designates 40.107.93.75 as permitted sender) smtp.mailfrom=Nathan.Fontenot@amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1737049401; a=rsa-sha256; cv=pass; b=sBWJBVaEoOXbQ/c6yPi8Whd/7Ugk3XLLCcxcdvwFXZDKE4Nn73zwYTyGQOgkF+udTknmag +vGyDTLiAU1eI29Urfhh5xux5kJ9+DyTgVdb8MBVhF0N2Jiasgfbhe755nCW6PgFwCDaMZ 25ijT5Wh+ORtjnKm7BNCFEg7APLiZk4= ARC-Authentication-Results: i=2; imf03.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=bi4Ji7v1; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf03.hostedemail.com: domain of Nathan.Fontenot@amd.com designates 40.107.93.75 as permitted sender) smtp.mailfrom=Nathan.Fontenot@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737049401; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=j6wi+AkmrdVXhwbF9U8L/CrH+T4javGvPOhk9ojLIQ0=; b=VfSNYbaAb3sA6Y7HIWUwSC8c1KL+e0yNkTlPeMMqMxSxncaNxlJXB+7V01nqXwEBYQtFKk WarlOKjtkW2/n6Q8IZ4dbTkDkepwO5vEiZfGznbQ9Sk8HLElGkak0Hn8PcwJxh7OrqPVq/ oxVSHuQmkH3WtFIhYksQyEcEctSlmnU= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=p4CCnWCQiSqL5uec+63QhPpKzh6tlMJID5bPVnuwW1V9JasOMeEhpuKSrm/RGEs19lM6NyjJu84FqJGWuvGAS4ytCVGW7p7AmihjImHV9Q8I2Rwy6qrXGMBC/HZXjDY7VpPyLnVpM3b8fHQVrnLSrJ/Q/mpNgcHlq9GSSDYVgJeabHdCq8TAPNdDSrtP4NtISQ9jNiQycHRDyzVieD8qioW/bdI5ZXEbTumCIU8A6VU3SXFNmpC2y6KxgfTUldXSN5iPld6fn1Fse5ANfNfu6V0gG2dUp691qhvVi8NWdiUCVw9Kq72lWMCstQmtLj9L2g716t56XEsxHQ1/eHQFQA== 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=j6wi+AkmrdVXhwbF9U8L/CrH+T4javGvPOhk9ojLIQ0=; b=CWd0Ox7hlSHys1zyoovjO5KOLxQoPZhSAChIia/b0lIn7W6twshDhCrxeRQ8ygk2xpdwJVS2jUc6W/wQKkATr+obMGvb4qe7oPcZmmiCuJ1gzud2ICBvLmUSfHcc673luczONIx4ntc+ikwsdYaIw88eMmh4Emrdp8BU8dU6vLK0kH5kM6LIe3BOSg6mKy9TJYSVrXmxEvFJLZ1nrHyG6Q5dHM/jEyOWkVW8+wcWWbIdla3fPaOn5EvJaYMy6b2pPv3wvIebN+1QcJMzOJxwDV1a+v+VDdXoX8ZDaEoNM2sNFsZ0NXB3sVIiggygUbAPu/FIsJnJfjPRDS9l7S6GzA== 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=j6wi+AkmrdVXhwbF9U8L/CrH+T4javGvPOhk9ojLIQ0=; b=bi4Ji7v192stp9plebhMoGQkgLzzGe8V+Rrzw4Xjvcl0TI53dycJG+Il8of2iORhGNtP9M5/H3aUDgrq5zKN99fija2Xf+Ae5YVvU/DP6AUdfSVRZI5pY+YKJpK3F22xIX2ufYcYXuxUEdtXYOcc2kGC3H7VP76CS88vtahC9l0= Received: from BL0PR02CA0130.namprd02.prod.outlook.com (2603:10b6:208:35::35) by MW4PR12MB7285.namprd12.prod.outlook.com (2603:10b6:303:22e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.12; Thu, 16 Jan 2025 17:43:16 +0000 Received: from BL6PEPF0001AB73.namprd02.prod.outlook.com (2603:10b6:208:35:cafe::68) by BL0PR02CA0130.outlook.office365.com (2603:10b6:208:35::35) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.13 via Frontend Transport; Thu, 16 Jan 2025 17:43: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 BL6PEPF0001AB73.mail.protection.outlook.com (10.167.242.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8356.11 via Frontend Transport; Thu, 16 Jan 2025 17:43:15 +0000 Received: from AUSNAFONTEN1.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; Thu, 16 Jan 2025 11:43:13 -0600 From: Nathan Fontenot To: CC: , , , Subject: [PATCH v2 3/4] dax: Update hmem resource/device registration Date: Thu, 16 Jan 2025 11:42:07 -0600 Message-ID: <9a41f91ed487ea64e187d84fab3bd69a4a5862f9.1737046620.git.nathan.fontenot@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BL6PEPF0001AB73:EE_|MW4PR12MB7285:EE_ X-MS-Office365-Filtering-Correlation-Id: 890cf9a1-f885-41e3-11d3-08dd36554172 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014; X-Microsoft-Antispam-Message-Info: uwZUr1ajQAxfKgZEAfD2dE9/ZN08IuZyghe7qEBv8XVZrjUVoDQOY6SjDM3jnGQuqoQHukJCaKRJA5g63RwoIS8ZUP/W8by09/5Vdhq+Cf8SmuYfmjOuEWcgtEgBkAT3lfHZlX1gWd5zvUZ14Mz3B+DhdLL8qqmix4L++FJOONklSXTCAlC3ZKUOvJnwZO5fk3FRPdy5J36JjXo7Acrzbs6mPw3CK69GTl7ydHP/O50R72RU+8vOqysW/5HBu5VlRAUx187zhg5PLZAAle9U3mxp+f2KX9iYc30dq5vqpXO21vUmjc9vwdgR51ZoZpJ+JYe8OgeX0pQ35ul1iRspNsLQHDgXJ6naSawhVjEOezCPtud49KQbn+lt3A0uZy3huOMd1K9h1k+STlJmToPECkAbcEn6QmcfkJOBoM9D8gcnOOrds3vqDVTYZpuVUcDUDSTnvyB8MDTWwXBbO/TCpV6v6g2YvSseyExGhk4ZpiGajoT+XBgkWquRUiXqGH+Ts0sW9ahVm3a7a1UhfJLhDDJQt9e2EOZwVnyYPqELV/zdEQ4k1WM3G2G0pvt/l0eaYqhOOW5Flg/9mofrrj98mUs9VYOljSDYII/xg0nHUBc6A09/gQWCFhDqRCdnszIeIIocam4TJloTpPlju+LksZRps7tAk/GFARERAwVoFem1X+h4wG+6fJgw6y1kTdRGVyFK36ruqXPtjuKF8LwKdOwxE1d5Qgtvpw1oMt5b1INtRWfuy66oS5JYzXWScjiqFUNt4vvGKQnP+An6OOCDmSaIpZ4Bf2Ru/6QpVwltipOwhRu79jMuZV8//mkGffA5ml0eYmEKyJou6uboP2skii12cU2HcEUCSgxg9MFbz9T4UKLrXP+JBJDZ5dH0Ye55vMeK7c2J2zkdHiV3E/sOeS9AD9G6biA/Okme3hhJ057dvwSnBpPRkku3sPnFfNNcqCJ9kPhgt8KNeplVrvlQ7tPVA3zrDq65ThnKy1vb41aOSS2LfO2fBIf0qu8ZJs6jaOVPRxeITbNAY7cKSbmjqzpMokxtEA5EdUxgA6pG0dBBEZnEOEstZqkQGIrDp9Mnqnrxbsb8oo7Fdn9s+SMU3ixHMF8eJLIgBbD+eoP/+znuBCU9F6iYkwal/AXzNbO6V/iHZzQKX7lpL9dVkeTGpyYI+SLvmFxeVgAkuuKFTTiw3IYil8z8Fenx8GKi5ZpDiqIxWvV5kwMpgzserjRqBzltjlDOmKkHcwdpQTwShWrQGclVQVBk7FdY8rnrvJOYe9sHWbWjaNzSy2f23O52OJevd5esOf/cc6S25Ea5BwUyMULBsRTthy4Ni0vtnlv5GwDnkx5/wVeXRJKaV0dBL3FnWOLk4DXrZxQg7tDikHL9KDKuUs5TerMypxij4GKGQF6FkxpaFiF8vIDAVMsgMDDV6fsoQ8RJggzN52KlvBJeqdlEVrkw5Bn56HWipCZJj8qJjzA11sk3inj9vqx6ADAycabV4b6Le2OmBMFhMNY= 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)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 17:43:15.3811 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 890cf9a1-f885-41e3-11d3-08dd36554172 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: BL6PEPF0001AB73.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7285 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: A760B2000B X-Stat-Signature: uza86f4stjq7ry7ci6snoduqqpqy315t X-HE-Tag: 1737049401-900505 X-HE-Meta: U2FsdGVkX1+Bfbrer6MWzFBjMnyyJdhkSpYWIpHDwULxMf8cgDbHHT9qfK4CAquennKiR/QmPZLv+ehhhVrtfLtVTZ+YuMLqRrzw5TWM/F9xIxiLHnDVNux47/Q6LWn1Okxv74m5yBlJRgObC76N1HWO9ZbYhzACWe2Hf9riAlb8lPd/fDaMLpFliqr82UzcAJsu5lHy9Xh9JldFStEC5PodG0eV9e/ivqB99qpafoTteyI/jeeGOO/8i/o94cI1hglj3l8rcJtyBfjwlCsFS6N0TWyoCfwfC39dyCCd4QhdEjE/f0+ShIMp0ZvtVlhW9UAaNf4OJVTOLsY+Yp172u52hoVXP8wEx9D9BV2ACKo56nJpA8zzRr+p2yh4At0qxB0tO4y0w72+Byk/RFEdFG18vnoGs9te2nFmrhfQDSYJP0rc2F9daMfB6fM4jGDKez+3ZpC0wdfznXNNBTzJAnBBUMYNlJyVQ7zI/l7YihQ21fFxECfyA1XMg+L1YfrbjieRdmaWLDDj38qENoIqkrn5XjtqADcrD092+HXwLfyRdztOVnDAS9s5WoH0QYtn+gBa/zMKtIDyQeAmpX04u36IbIIyCc51DWQj4W19REzALmWRPZu5H3m4ZrERH212ONvUegf5Shp1C3MxEM+mLm1HokKUSOwhB9T2NcQZJyZGQAUM+B4PBrEU0cSZAYgyShiGeF4ZY5YYC/WymOdYnKMxJZocUk54QDdwLb9htJn4knqRmQzx7xRe/GBBwWRqP6+jxxA84Cz2CH7RN0C9OoJFXtQEh2FnQyUgwyLaSztdymQLFHEghdKUzeLYYhegmzcjv3YL2zeh1gIFZlZQSizYVEv4W4JK+fFTpgQ6Rmzw9RxYtdszr+NNKpz0CmLmRYvluiSr+U0QWJfrJ+eTnn4VfAcW57uGQzS428bqdxeCOnEX8Gxu71tKQqXBekLY9LiDvn0Xu634JrVTFZr NUziOBJ6 bJzlm7oCzGbA1k4wwV7qFZ4mOeG0j59Kl49oV0SALz3FLo2K7BM4fgAexDB3NUuE8fLOrw27P18cfYGmNBKfEu9atYkgm7UxOHOlf1KxvdCewQbMJYvn/AKAweyEKqbuSTbllispQOd6g5Sk8lSnzBuCUArrJMzw23kAhJ1sy82aW2XHpnEVS33mVu21WyfaCOvT1FdnRxS0ALNJXXIC8qNLAWKHIXdiX8++lWbpuOK0DXqZtyotEMt0EQvMvhurMyHr0cLjE2WhYfA1SeWJM2Y/TmXqOMTye1HQvw7MvuDO6+7eQrh1nOelTFMVMldItF3tRYojQVNkHMk0Kvwj7qEqFUBGU1frPgvhdk5z2D9tlPRANLTf9ww17zz3V7mpvn2MiS+JxXqyR4o+7ggdeqkDH2GTVF3S7m0dnxuTlxiqSkgi9BvyLoVKZUo8V8Nz2T3teNXmn+r44tuQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In order to handle registering hmem devices for SOFT RESERVE reources that are added late in boot update the hmem_register_resource(), hmem_register_device(), and walk_hmem_resources() interfaces. Remove the target_nid arg to hmem_register_resource(). The target nid value is calculated from the resource start address and not used until registering a device for the resource. Move the target nid calculation to hmem_register_device(). To allow for registering hmem devices outside of the hmem dax driver probe routine save the dax hmem platform driver during probe. The hmem_register_device() interface can then drop the host and target nid parameters. There should be no functional changes. Signed-off-by: Nathan Fontenot --- drivers/acpi/numa/hmat.c | 7 ++----- drivers/dax/hmem/device.c | 14 ++++++-------- drivers/dax/hmem/hmem.c | 12 ++++++++---- include/linux/dax.h | 9 ++++----- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c index 1a902a02390f..23d4b3ad6d88 100644 --- a/drivers/acpi/numa/hmat.c +++ b/drivers/acpi/numa/hmat.c @@ -857,11 +857,8 @@ static void hmat_register_target_devices(struct memory_target *target) if (!IS_ENABLED(CONFIG_DEV_DAX_HMEM)) return; - for (res = target->memregions.child; res; res = res->sibling) { - int target_nid = pxm_to_node(target->memory_pxm); - - hmem_register_resource(target_nid, res); - } + for (res = target->memregions.child; res; res = res->sibling) + hmem_register_resource(res); } static void hmat_register_target(struct memory_target *target) diff --git a/drivers/dax/hmem/device.c b/drivers/dax/hmem/device.c index f9e1a76a04a9..ae25e08a636f 100644 --- a/drivers/dax/hmem/device.c +++ b/drivers/dax/hmem/device.c @@ -17,14 +17,14 @@ static struct resource hmem_active = { .flags = IORESOURCE_MEM, }; -int walk_hmem_resources(struct device *host, walk_hmem_fn fn) +int walk_hmem_resources(walk_hmem_fn fn) { struct resource *res; int rc = 0; mutex_lock(&hmem_resource_lock); for (res = hmem_active.child; res; res = res->sibling) { - rc = fn(host, (int) res->desc, res); + rc = fn(res); if (rc) break; } @@ -33,7 +33,7 @@ int walk_hmem_resources(struct device *host, walk_hmem_fn fn) } EXPORT_SYMBOL_GPL(walk_hmem_resources); -static void __hmem_register_resource(int target_nid, struct resource *res) +static void __hmem_register_resource(struct resource *res) { struct platform_device *pdev; struct resource *new; @@ -46,8 +46,6 @@ static void __hmem_register_resource(int target_nid, struct resource *res) return; } - new->desc = target_nid; - if (platform_initialized) return; @@ -64,19 +62,19 @@ static void __hmem_register_resource(int target_nid, struct resource *res) platform_initialized = true; } -void hmem_register_resource(int target_nid, struct resource *res) +void hmem_register_resource(struct resource *res) { if (nohmem) return; mutex_lock(&hmem_resource_lock); - __hmem_register_resource(target_nid, res); + __hmem_register_resource(res); mutex_unlock(&hmem_resource_lock); } static __init int hmem_register_one(struct resource *res, void *data) { - hmem_register_resource(phys_to_target_node(res->start), res); + hmem_register_resource(res); return 0; } diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c index 5e7c53f18491..088f4060d4d5 100644 --- a/drivers/dax/hmem/hmem.c +++ b/drivers/dax/hmem/hmem.c @@ -9,6 +9,8 @@ static bool region_idle; module_param_named(region_idle, region_idle, bool, 0644); +static struct platform_device *dax_hmem_pdev; + static int dax_hmem_probe(struct platform_device *pdev) { unsigned long flags = IORESOURCE_DAX_KMEM; @@ -59,13 +61,13 @@ static void release_hmem(void *pdev) platform_device_unregister(pdev); } -static int hmem_register_device(struct device *host, int target_nid, - const struct resource *res) +static int hmem_register_device(const struct resource *res) { + struct device *host = &dax_hmem_pdev->dev; struct platform_device *pdev; struct memregion_info info; + int target_nid, rc; long id; - int rc; if (IS_ENABLED(CONFIG_CXL_REGION) && region_intersects(res->start, resource_size(res), IORESOURCE_MEM, @@ -94,6 +96,7 @@ static int hmem_register_device(struct device *host, int target_nid, return -ENOMEM; } + target_nid = phys_to_target_node(res->start); pdev->dev.numa_node = numa_map_to_online_node(target_nid); info = (struct memregion_info) { .target_node = target_nid, @@ -125,7 +128,8 @@ static int hmem_register_device(struct device *host, int target_nid, static int dax_hmem_platform_probe(struct platform_device *pdev) { - return walk_hmem_resources(&pdev->dev, hmem_register_device); + dax_hmem_pdev = pdev; + return walk_hmem_resources(hmem_register_device); } static struct platform_driver dax_hmem_platform_driver = { diff --git a/include/linux/dax.h b/include/linux/dax.h index 9d3e3327af4c..beaa4bcb515c 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -276,14 +276,13 @@ static inline int dax_mem2blk_err(int err) } #ifdef CONFIG_DEV_DAX_HMEM_DEVICES -void hmem_register_resource(int target_nid, struct resource *r); +void hmem_register_resource(struct resource *r); #else -static inline void hmem_register_resource(int target_nid, struct resource *r) +static inline void hmem_register_resource(struct resource *r) { } #endif -typedef int (*walk_hmem_fn)(struct device *dev, int target_nid, - const struct resource *res); -int walk_hmem_resources(struct device *dev, walk_hmem_fn fn); +typedef int (*walk_hmem_fn)(const struct resource *res); +int walk_hmem_resources(walk_hmem_fn fn); #endif From patchwork Thu Jan 16 17:42:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Fontenot X-Patchwork-Id: 13942080 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CE2CC02187 for ; Thu, 16 Jan 2025 17:43:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94E9F6B0093; Thu, 16 Jan 2025 12:43:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FEF36B0095; Thu, 16 Jan 2025 12:43:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A0226B0096; Thu, 16 Jan 2025 12:43:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5BE2D6B0093 for ; Thu, 16 Jan 2025 12:43:40 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0A45045858 for ; Thu, 16 Jan 2025 17:43:40 +0000 (UTC) X-FDA: 83014037400.02.B7AD941 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2046.outbound.protection.outlook.com [40.107.95.46]) by imf15.hostedemail.com (Postfix) with ESMTP id 0850CA0012 for ; Thu, 16 Jan 2025 17:43:36 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=rjZjqbHg; spf=pass (imf15.hostedemail.com: domain of Nathan.Fontenot@amd.com designates 40.107.95.46 as permitted sender) smtp.mailfrom=Nathan.Fontenot@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737049417; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ywFJp//eIGMl9pJ14Ejl6c1NL1m/qgp6gZ+lIbwIm+8=; b=erAzP/9scO9ZwcuOV5OAozxZiiRfPFIYdTNVaBpMVUssBD9iWvs0yV0cD2027jjYEsrdg+ uZd24FexYOB536yemNiz20zFpgfHnFEv6EAgB3V9hE4vHTBspLylXATDF3YHxGsPwe6qwb JBkGNPMz/6BkEBGsxsacsM6dcH4jxEg= ARC-Authentication-Results: i=2; imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=rjZjqbHg; spf=pass (imf15.hostedemail.com: domain of Nathan.Fontenot@amd.com designates 40.107.95.46 as permitted sender) smtp.mailfrom=Nathan.Fontenot@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1737049417; a=rsa-sha256; cv=pass; b=T0OEzkqHtVqTm/32A1rMgs1TvKSCR0EAva5Mx5VsOZPWTkIKlBlJfyCGIfE+LjnqQCQ8OX YpP814ILxFsS6kC4/jaAufdW8wZSy49tBmwY4TBsJ8Ct4DhQ7LooO5yIVG0euwT+RKXmjq nL/lI3UjfA83IwPH5krbfBJLpfEkvN0= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Sa+LOuafNG1Rpav0H1VCxwi+AXlQYRzeBzVrvR4CCdudrcTie+vQlZbXwhTAw/DQTbZsRAmO1Se6tLNC1ComuhIq+MbxLZWR2dBl0vY0pY8TwvxPYbEGCNjH3cUZWQCwciArB3qKKQRpXuh1JPzbggvBqlorgeZJAqtbZ8pDYpOKN6DpONvnGag+Ugw7vlj2gcolkp5zTWkJteAET203PHlNVpEVmTkaNC2aiQhgeRcIOAMksa62M7b+RFYysmD8E34CUsM4cdbxWveP2dvUHNiAAeKntHYLZF6wZWokEkOpxvsuxD5Bd8WDNNtGUgoGmvZmh5AIE2RlOC8ZFPpRmw== 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=ywFJp//eIGMl9pJ14Ejl6c1NL1m/qgp6gZ+lIbwIm+8=; b=q304VK/qs9SEPk9lKHrfTTY/62dhjPteJ0j5a0sG6hQSrMaKK067ANSlk+zreBS4D2bLzeetxV6dpH4zaiwOZC0E/bdZi8cX3r4qIvBc246zWQbDj093g3FZitMCowvmbgEy3aRumaPYMXHo9VubkZqfTRVXtH1NnCYL8X/QPluMMfDsr/CnCEQqFA7MNq7w1ER7/xskc9ulfk62wx8eFyYPqNMm728ozL2JEI5wEJcZkFCpJ+adTAc+cUEFY2eTFNLCYGTxIOqTFBBR+mD6378uccb9fxb0JkJWAyDLW4am117jF/dZ5XzLz710VoNiRVOzHQ8SGNXgvdXBhEJvCw== 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=ywFJp//eIGMl9pJ14Ejl6c1NL1m/qgp6gZ+lIbwIm+8=; b=rjZjqbHgBPo9Ch0xozD35W6l9fj378gg8h6M5Wc59E1YNd+1xeMyx12sVg8Y6vyFTiLMnYJoacPVR7ky7tngtm3S1n/w7EanFEavNEjvkiPElWwgngnKcxYCDBKa9FQkfrsOeYaF+rb/RHHGVN3/e/3rukuEEJ3l7w/1P2MPH3M= Received: from MN0P220CA0001.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:52e::29) by BN5PR12MB9509.namprd12.prod.outlook.com (2603:10b6:408:2a8::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.14; Thu, 16 Jan 2025 17:43:33 +0000 Received: from BL6PEPF0001AB78.namprd02.prod.outlook.com (2603:10b6:208:52e:cafe::bd) by MN0P220CA0001.outlook.office365.com (2603:10b6:208:52e::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.16 via Frontend Transport; Thu, 16 Jan 2025 17:43:32 +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 BL6PEPF0001AB78.mail.protection.outlook.com (10.167.242.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8356.11 via Frontend Transport; Thu, 16 Jan 2025 17:43:32 +0000 Received: from AUSNAFONTEN1.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; Thu, 16 Jan 2025 11:43:31 -0600 From: Nathan Fontenot To: CC: , , , Subject: [PATCH v2 4/4] Add SOFT RESERVE resource notification chain Date: Thu, 16 Jan 2025 11:42:08 -0600 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BL6PEPF0001AB78:EE_|BN5PR12MB9509:EE_ X-MS-Office365-Filtering-Correlation-Id: b5b6f673-5cfe-4466-4de4-08dd36554b71 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: 2iPu5JHYH2ksmVM359l7fEzsBvp+DPVGdkoar3vGSnf0Be+lDnxgQ8UOaUabiyzhH3V3Egb+hDP2C3rJa8AjVuQ/9XsoYlrVKMAbdi28+nv24pIpfy6TKmtY3BaMGut/EazueQJky3Fftd2h/iILZ4uxtoolGp5Ek+rLE+mxiKeR1XK908zS4CLRInQlC4u8eRCgyKUgWWNhB2D8aGlTGTPQtbIugJpF0d/tSU6CDvqeax+1EdOxpZQqb71LtTd60jnJQp8fyuGyMca8U+jpSAftgFRiiYEuoTTDQxyINc0lom3aCNdgHnGf5ucOusvnVuzbHq0sstrEcl70FmFr3aWzQXDmsNn1nQDboJ1S2yaldObtMl7uwhFeYWuBbr3jmy3n3orA1pasuHWglbeu88T7mdZTVD9bmrYz+7+6Hc8zJP7hphW+65jBQYUNsRC5Xo5RhC8gvNnOpX5X+34LtBe1gRG4MNLQpbYDpqoW78QHA7eORH3TFgcu+x83q2ez5/eEJY0Cpfi4WDS7WniX2ixBQMcswtDaq06fVXWz2RejQQZYjyVCNi/PlK1tl4t0F4mHbS7B4zXJxipl2jsgMXErw5QRIjPrkGS6ahodAM0mkfxIR5AjAgg2JBgPBVBJCh51ZpbaPH7ty/kiMKSx0l6wT69ttm8Rof4H77yqA+mBb1pJxLkNalKJoVDcObpePdfntXiUb2hcB+ycD7lhNhlhmZpvKOtpir2pac9N7qbp4m54dPers+y33XLQU+z2T1dxCrABdmGY/gT+3H1NB5LPNxUksZUYseiFecNdl5mLjl1C32Sz/9WSFcwNv3y4v2AxsH40U7XfrTzjcR3hD9/Nl/COnynNNgfnPz2HGJT2526Ci9A6hlzPJg/EHlSY09FH2zV3KHcaVABkAQs3MX2BFT/+2Ur6BUBo2HTcZ0mkf2qTvkzA3hcRwog9jrArR7/dbcUxi72FAbyEdMo+MB6DsF37EtUWbjeoiXMnUXLUPNlZ6nfujOvBvXxpTjaq0T/aMXqU7fNTkPggOlD112kX91BDjQBYc4oZFaAgV/hB59D68jMXjpTNFvaS3xEE/9gzmwGleQUqE+dagRk/+IauiMLakuQSzFWWoEM4mhtSgFsOrEzf4zVA4j121Zo4ie80WAKivCKSihQFQxmHEIQJHMeHw8Tli8Tka+ZT2cZ29Xenirvftb0U1Bh1TWj5FK96sC+iMKdKFQ+aM1aiGGkk2QE8gP2NLGV1Sd5BoMyioBqdmuN4UJtYvR7X263vsLSRK1S4N8JjDlO6ANOknnCRLXf+xzqIlElrco3QPCbbRV/6VJwOOR2h5U4VjJZYlB4F2xHyWMclq/VZCvTwK/VFb94lWbMNgyUkNLP5gJNkzxnIt6YTVRZmE1/Njk3DzLP4sf6lBLalgez4L3QLKKBFG5DwbiJ24VPKOm1NUrSCGyN86EuPSPlRH3IUeBrujn+dBZcfAFGr1dbZOWg0ZWNkJNj8P5hFVU8np/6YamI= 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)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 17:43:32.1533 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b5b6f673-5cfe-4466-4de4-08dd36554b71 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: BL6PEPF0001AB78.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN5PR12MB9509 X-Rspamd-Queue-Id: 0850CA0012 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 4tgdfx4su5uek9k9yyy1dcotqrdxbgz5 X-HE-Tag: 1737049416-284575 X-HE-Meta: U2FsdGVkX1+82fXklZ8IcEHAMOTJnWUnYnXNEDQpLckkOQvVOm+mfAytOIciLHIB+tE85qWdA4+BJcTAyb1IpV7mJPUUhR/SoM+2ypgmGhdQQODakcAPWvYsXyvJeGXYALd4IzMvqHsZQyAqvSF6skyrSZM1caio7KCVvbi1rtGEThyYfGqfPEFmiy7UgiKUzuDvioUBGv1jhFRzEmYOjV+JJ7JaKY310fUMo58WBbqBmuhbPqGnUkjBGJfvn7t3AifyCKCeVuH5tHd/6cPZcGd9u/duThKREtnKeqvv8iys/a+mtB3jHo/31DXEU3b5VevIfNa63p/gAMtjGVhR7Tz/cHss4OBi4pe+9YEVcknig3dDQvDht25uqWxNcMrcmOHeeoWPrRuTGu7Uhta7L6ebV1BR/Sa6BvWn5MbDE6RrO5y8mbPCpepc0VL5emRNXamYDP+A+S+hpw3tuHU6B7HlA8niuB9HzzzsXGH5MRXEIjtf8OTgMf5o7GsNqN3ethYvk0JCDdtd/sUaA7Qxtd5XrsDlRShJCElWnACDiBuMOquaVbGzbmFf6Zxklih45TrNY4Q+D+fnI2pwcJuwuyQ34y4nz/S3bPP68goleKXCCgE8VfhIbuz15lOiBBeZcAqdu4dDgWbnxllLBFiYCloWujcvVV3vOpN28rdsbm7H4g4dMDfIgP6F2VfVGY7049xNdL7Gk5Hwa5rC56qWfsZqFZ6799Uy1vScpKZ7cr7y1uJX3H/AD/GOQ94icMJiaEQnCX6lJCCffEsieHzDCrLp2PxEwq6Hkq9r3VxeTjOuudwiLUifULEpov5Lmglq+3rVievJD82Kzp5SBbpnvYHDxF25bKZrD5Lr+QfdBXLDQJta5w1fhYw6q7WQb6WjAxrhehMnt2qu/5O+L0NJWA8tn4ZihCsChYSblfpFrqDyoe/8rjMhCC50OqfmApnqUSiZD0yur+c0LsVme5t 4EpYOSZB Dg6LjvGwZ+wDvc0HhbLDdtGyYgerhRVESBqLpVF46zdTNsUNj7kKz3J7BXB/hgNpWkiXRD2XNaXgdVDlBO1oUtBjLAJSfDQh4wqD/QsNVMEWFaZEYQLdvUE4czKxMk0gzdaU3MX1nT6PnpLEL3rgstc8lcIkVUdRSyjU7rbB4x57UQ04T92YfBvhmIydsRrSfiFXLWwZjqzDETT7Mky8ddGy99+dp6m1RFZK2J0TF+JO3q3z+V7u9REAosR9v90bGbv1p1oyTm+9I6wjh2LroNSBLYcfT21q2IKbLTl8bq0K9I09nkNwufceREVMoz+KD9ouq0Veri75l7CR0s4Xrx+I1PXJd7wMexi9wTij+nksNRTtbmVUhexZ+IqEDxOXZH8swuQTpYXZb92wj7E2WquKMo4wm37QZLudP1J6k++WKDK2xTnU9yu6iUa1d1Jc8Wgv28umHk2WISKsFavd2xVecyeKM+PRLM+9jetrUbuB6mmo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a notification chain for SOFT RESERVE resources that are added to the iomem resource tree when the SOFT_RESERVE_MANAGED config option is specified. Update the dax driver to register a notification handler for SOFT RESERVE resources so that any late added SOFT RESERVES can be consumed by the driver. Signed-off-by: Nathan Fontenot --- drivers/dax/hmem/hmem.c | 24 +++++++++++++++++++++++- include/linux/ioport.h | 11 +++++++++++ kernel/resource.c | 21 +++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c index 088f4060d4d5..0e6b7558ca3d 100644 --- a/drivers/dax/hmem/hmem.c +++ b/drivers/dax/hmem/hmem.c @@ -126,14 +126,36 @@ static int hmem_register_device(const struct resource *res) return rc; } +static int dax_hmem_cb(struct notifier_block *nb, unsigned long action, + void *arg) +{ + return hmem_register_device((struct resource *)arg); +} + +static struct notifier_block dax_hmem_nb = { + .notifier_call = dax_hmem_cb, +}; + static int dax_hmem_platform_probe(struct platform_device *pdev) { + int rc; + dax_hmem_pdev = pdev; - return walk_hmem_resources(hmem_register_device); + rc = walk_hmem_resources(hmem_register_device); + + register_srmem_notifier(&dax_hmem_nb); + return rc; +} + +static void dax_hmem_platform_remove(struct platform_device *pdev) +{ + dax_hmem_pdev = NULL; + unregister_srmem_notifier(&dax_hmem_nb); } static struct platform_driver dax_hmem_platform_driver = { .probe = dax_hmem_platform_probe, + .remove = dax_hmem_platform_remove, .driver = { .name = "hmem_platform", }, diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 2c95cf0be45e..c173cdd5ab87 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -13,6 +13,7 @@ #include #include #include +#include #include /* * Resources are tree-like, allowing @@ -254,8 +255,18 @@ resource_size_t resource_alignment(struct resource *res); void merge_srmem_resources(void); extern void release_srmem_region_adjustable(resource_size_t start, resource_size_t size); +int register_srmem_notifier(struct notifier_block *nb); +int unregister_srmem_notifier(struct notifier_block *nb); #else static inline void merge_srmem_resources(void) { } +static int register_srmem_notifier(struct notifier_block *nb) +{ + return 0; +} +static int unregister_srmem_notifier(struct notifier_block *nb) +{ + return 0; +} #endif static inline resource_size_t resource_size(const struct resource *res) diff --git a/kernel/resource.c b/kernel/resource.c index 9db420078a3f..3e117e3ba2a5 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -1471,6 +1471,26 @@ static void release_region_adjustable(struct resource *parent, } #ifdef CONFIG_SOFT_RESERVED_MANAGED + +static RAW_NOTIFIER_HEAD(srmem_chain); + +int register_srmem_notifier(struct notifier_block *nb) +{ + return raw_notifier_chain_register(&srmem_chain, nb); +} +EXPORT_SYMBOL(register_srmem_notifier); + +int unregister_srmem_notifier(struct notifier_block *nb) +{ + return raw_notifier_chain_unregister(&srmem_chain, nb); +} +EXPORT_SYMBOL(unregister_srmem_notifier); + +static int srmem_notify(void *v) +{ + return raw_notifier_call_chain(&srmem_chain, 0, v); +} + /** * merge_srmem_resources - merge srmem resources into the iomem resource tree * @@ -1497,6 +1517,7 @@ void merge_srmem_resources(void) __insert_resource(&srmem_resource, res); write_unlock(&resource_lock); + srmem_notify(res); } } EXPORT_SYMBOL_GPL(merge_srmem_resources);