From nobody Fri Jul 24 21:53:11 2026 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010051.outbound.protection.outlook.com [52.101.56.51]) (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 AED41346ACE; Thu, 23 Jul 2026 09:47:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.56.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784800041; cv=fail; b=Cd+iEbV16VD9x5vh6BoqaRKnjlSRsD9h++nPB/E4v3YyJp23tNQwlJcoiOYLgiLJpwEtRD9hNdZy8z4mjFvw3NQpJHdJnJzv9Zh13CN3esAVs6sM4c25fd/9626ngkgPnZ4dAIJ4tt7Jmu9ffk4ceqJM1oyFqRxWqlbZlJwVojM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784800041; c=relaxed/simple; bh=0NXPWYua/Ovcc7dRZXcUwc9utJaJXIEE/Tc4VLgbXWY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=C2Wu/cGYgz3Z9QTmYQ6yFEDEdyY/DyKpQxN+KT0wmKFcLXrxeHlXCmG4EL7v23YJYpW8qGUK8exSxqyAHodx+fmw9xDgCVUCZ3oDSwqLHGfP1Z+3HqxEVubDA64AwxfSuplBOWs5SG4oUroUwyNuNygTDhIohq/cs2q+FAu6jwA= 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=uPd1eklG; arc=fail smtp.client-ip=52.101.56.51 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="uPd1eklG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JSUnPAEBJNpvfp8Fo/VV3Z1pUCQx4l/PM+PmD/dq4z0Wz70q4vkPYlKWuBJrupthOkzOWjKUOpg2WN3firc75H51z2lYB7oWWmqsBzWoqpgDqJwQmo8fBUon7qXdLugxUYZ1hUWQ5oBb0X/vnOPVbhgI0jP4c78gFywbetzKl1UQeNJDQcQ0iJ8gmOlBelrt469tcS+StRl6ztBAE3iYaHi3njJOERbaHkhlMGcraDssuu1dBeL0YrXVRhmngCxiTFTMRb/SvDTXZzPC9lf9Pn7xXuY1CnbI/31NIXa1rVKxqv1Hx31MpH+C1fv0GnJlYPkHGpnuWHNr6g6DMRtFBA== 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=su0fIOSQl1Jg5BSbfiAbCFUrkr0w/SPg8rkCPKxWD0U=; b=xLkrN1o1vrHCQFefOBY90P2MdWjxtqVQYz5SBkYVSefqQSPblkRGRCpFHDYqSijxys89Rcz7h/sAhh0D5vimPNwW/QkurLmTugOSrnyxJpY87JbLVGnBULF0iQmrAYGjhSwZz5T5aRYcojoT7CdMiSkZTON1/OolDiZi+OTwr70bdxJe+ewCYATlfcq4RsD8qNko6efsjxA2H5/Q08z5EIMCpCoj+zdZB7nPIG59pI9o1FPH66uRjMOk5SDM3cxxBWKbKr+gQHgATjLW0TT7/UCSJPbBsU7OwBkoKYr8oiAj/Mr5XSbq5LG7pY36NN7StiaF2fMTHoQaQhdblwHtUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=su0fIOSQl1Jg5BSbfiAbCFUrkr0w/SPg8rkCPKxWD0U=; b=uPd1eklGgZD+zwVdxpDcMvLnGjMVbSRo5WKUe9WC9kFpKpFdTIAbff8PL/Z7b3Yr6p0Wnb4O5faiP0JCCQmehVr0+KF5lt1CiIclUM1FZxb1Hyq6YvrWQhhPpjui6FioLEDacPVX3ZhevzKyp78VZZ3P4JsL5LSPtLsR86hsMBQ= Received: from SA1PR04CA0018.namprd04.prod.outlook.com (2603:10b6:806:2ce::23) by PH0PR12MB8031.namprd12.prod.outlook.com (2603:10b6:510:28e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.10; Thu, 23 Jul 2026 09:47:15 +0000 Received: from SN1PEPF00036F3D.namprd05.prod.outlook.com (2603:10b6:806:2ce:cafe::ab) by SA1PR04CA0018.outlook.office365.com (2603:10b6:806:2ce::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.245.11 via Frontend Transport; Thu, 23 Jul 2026 09:47: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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SN1PEPF00036F3D.mail.protection.outlook.com (10.167.248.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Thu, 23 Jul 2026 09:47:15 +0000 Received: from dcsm-trdripper1.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Thu, 23 Jul 2026 04:47:13 -0500 From: Muralidhara M K To: CC: , , , Muralidhara M K Subject: [PATCH v7 1/6] platform/x86/amd/hsmp: Serialize ACPI HSMP probe and remove with an rwsem Date: Thu, 23 Jul 2026 15:16:51 +0530 Message-ID: <20260723094656.3806028-2-muralidhara.mk@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260723094656.3806028-1-muralidhara.mk@amd.com> References: <20260723094656.3806028-1-muralidhara.mk@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F3D:EE_|PH0PR12MB8031:EE_ X-MS-Office365-Filtering-Correlation-Id: d3ba1d4b-88c8-46cf-77bf-08dee89f60ca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|376014|1800799024|82310400026|23010399003|10067099003|11063799006|56012099006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: vHxF6kn3y1A6Ry8MevzsIPcYKGvNPhshyuP7NwzrwPtn7TPg4nelJrwCibbDqNV4fawLoZjTuFRaMCJ+RoVMj3ajuk4Pu+4TOb8TCbNz5t3Eez8j0MlCUb4Akz74Z27P4k0Bo0FoDUiuzrgqD+CVJfq3VlwSj6CtmesFo1hrKGCMxk2E03XDOagJ/msPysqQIUOheFrR4VAXozoVdWVxxSeBz44A2acSYoaGpgYVuZXprEc5NllVa6XP3uuTSPKnK06Wb/rdX6oP993BwFcynkwluB5QARx0RcUmrgOHZC6OdLPBKO9yh4D5T2Qay0DZyC8IL9CGIFpJvJCphLXdNcTxRBXMRzuEhxXSfuBTZNe93OU4tfNWg7pWbFm0oO2gylCzX2A2BaEJHEN2hLqWDiRvvXq1RRAlmGbUJSvr2IqRzJyvj3RgYL0sXU/xa2GD/uhpMkB6eNFbGUeeHPyZeR9IBQ/wMchhkqFSgq3vaXHC8tmeYjdV1TFmBGZYoFJqx0c81fyk6oB1MuozHm8EbiPlLvDGzLDlpatcoLgQNSXvyQOR6rSk4wyBciQhLsG0oHhGVPfruDPd11yOLGF6JL0HzTZaoSpADLh8qR1/lvOwKz061UAyqKg/3A7/Hwhfw9CZVq0PApcnQhNAFo3bY/3Tg2Z8tC+NmLQLZDRfcRBo8HhYFUhlT/x4tFqDANcU X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(376014)(1800799024)(82310400026)(23010399003)(10067099003)(11063799006)(56012099006)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0jYBbfKpMVBBqL2+R5B8PFMIhKuqK8wieu0gFKWv+CJUCz5XChI1vfXy1bGmVpGJrMrFrxnZ4vt6ecSZ+7yNpXVGrgr9PMcE97zBzXF7N7vW5XXivn/Qi4LopGMhKYA2gg3MS5Ee7czKI7ZxHKOjSol/hicqv12hsQhzFmw4c+4rNBc950StL6lwLAj9e/0AjgDlLY1IHjlD/RO7pFqZt9FNQBJ1bd49eoZlhUBlM78ASrHiMR3Vps5Kxz+4MqCSVjE6ZKrdh2hQAXPb0MmykpJDVgSdg0ZFdCCPOiewy1e8fKhjx0kVxRBzXZONdUOpdvshC0C64PneVwiTvmJNSQMaWO0BmiyyEi2g2HWc8c/LKepPgL0ZVQupaUPL2SJlPsmisEDcuTyrvqWOdnhI2hzRxdliFXlx3253fPV0cbFqKMLeArmv0BOw9my2FJi4 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jul 2026 09:47:15.3909 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d3ba1d4b-88c8-46cf-77bf-08dee89f60ca X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F3D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8031 Content-Type: text/plain; charset="utf-8" Add hsmp_sock_rwsem and export it, then hold it for write across ACPI probe, remove and init_acpi() so concurrent per-socket platform probes cannot race the is_probed handshake or the one-time socket-array allocation. Use lockdep_assert_held_write() in init_acpi() to catch incorrect locking under lockdep. An rw_semaphore is used rather than a plain mutex because an upcoming change adds a read side so data-plane messages run concurrently with each other while probe/remove hold it for write to drain in-flight messages. Introducing it as an rwsem now keeps the lock type stable across that change. Signed-off-by: Muralidhara M K --- drivers/platform/x86/amd/hsmp/acpi.c | 22 ++++++++++++++++++++++ drivers/platform/x86/amd/hsmp/hsmp.c | 9 +++++++++ drivers/platform/x86/amd/hsmp/hsmp.h | 7 +++++++ 3 files changed, 38 insertions(+) diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/am= d/hsmp/acpi.c index 72f68cef1297..a23797bd1dd5 100644 --- a/drivers/platform/x86/amd/hsmp/acpi.c +++ b/drivers/platform/x86/amd/hsmp/acpi.c @@ -15,12 +15,15 @@ #include #include #include +#include #include #include #include #include +#include #include #include +#include #include #include #include @@ -482,11 +485,20 @@ static ssize_t hsmp_freq_limit_source_show(struct dev= ice *dev, struct device_att return len; } =20 +/* + * Bring up one ACPI HSMP socket: parse its ACPI table, run the mailbox + * handshake and register its sysfs/hwmon interfaces. + * + * Called with hsmp_sock_rwsem held for write by hsmp_acpi_probe(), so the + * per-socket bring-up cannot race a concurrent probe or remove. + */ static int init_acpi(struct device *dev) { u16 sock_ind; int ret; =20 + lockdep_assert_held_write(&hsmp_sock_rwsem); + ret =3D hsmp_get_uid(dev, &sock_ind); if (ret) return ret; @@ -607,6 +619,14 @@ static int hsmp_acpi_probe(struct platform_device *pde= v) if (!hsmp_pdev) return -ENOMEM; =20 + /* + * Multiple ACPI socket devices probe in parallel, but the is_probed + * handshake and the one-time socket-array allocation below must run + * exactly once. Serialize the whole bring-up against concurrent + * probe/remove by holding the socket rwsem for write. + */ + guard(rwsem_write)(&hsmp_sock_rwsem); + if (!hsmp_pdev->is_probed) { hsmp_pdev->num_sockets =3D topology_max_packages(); if (!hsmp_pdev->num_sockets) { @@ -642,6 +662,8 @@ static int hsmp_acpi_probe(struct platform_device *pdev) =20 static void hsmp_acpi_remove(struct platform_device *pdev) { + guard(rwsem_write)(&hsmp_sock_rwsem); + /* * We register only one misc_device even on multi-socket system. * So, deregister should happen only once. diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/am= d/hsmp/hsmp.c index 1a87931136fd..e9c17698983c 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.c +++ b/drivers/platform/x86/amd/hsmp/hsmp.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include =20 @@ -40,6 +41,14 @@ =20 static struct hsmp_plat_device hsmp_pdev; =20 +/* + * Serializes AMD HSMP socket bring-up and teardown: ACPI probe and remove= take + * it for write so concurrent per-socket probes cannot race the is_probed + * handshake or the one-time socket-array allocation. + */ +DECLARE_RWSEM(hsmp_sock_rwsem); +EXPORT_SYMBOL_NS_GPL(hsmp_sock_rwsem, "AMD_HSMP"); + /* * Send a message to the HSMP port via PCI-e config space registers * or by writing to MMIO space. diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/am= d/hsmp/hsmp.h index 0509a442eaae..129200d0cf81 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.h +++ b/drivers/platform/x86/amd/hsmp/hsmp.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include =20 @@ -71,4 +72,10 @@ int hsmp_create_sensor(struct device *dev, u16 sock_ind); static inline int hsmp_create_sensor(struct device *dev, u16 sock_ind) { r= eturn 0; } #endif int hsmp_msg_get_nargs(u16 sock_ind, u32 msg_id, u32 *data, u8 num_args); + +/* + * Serializes HSMP socket bring-up and teardown. ACPI probe and remove tak= e it + * for write. + */ +extern struct rw_semaphore hsmp_sock_rwsem; #endif /* HSMP_H */ --=20 2.34.1 From nobody Fri Jul 24 21:53:11 2026 Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010023.outbound.protection.outlook.com [52.101.193.23]) (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 ACCE535C6B7; Thu, 23 Jul 2026 09:47:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.193.23 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784800044; cv=fail; b=I8mt1oDAzIW8DNvoi3D/S1BDgoCfwzW6T4cThD7EAJJMPHugzF/f95tZ1EKXglHsK9e0ameJb9RijFeWxFnDaA/i3H2TnvDXG/6ZeTYiEV5tf5Mgl6SJjauEGocwGY8ZUKLIizc4m0P+OVtdAWB9FJTaeTbvVSz8qAwxTUit3/U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784800044; c=relaxed/simple; bh=XitKQOIx8UmTWhOV/W9LPUVmUm38q8G/PXkZ0MWlw48=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lkpfDp53QAHWUqhVz/X1lvmM3Yky75LdM13XuZVosjboDRlvUnZC+Xxfq9n0xra8hasroO19rjv91INLO+EINuNgFfoHD2jHSOeRMrT/2jSUeOXuOeCiWf7FMwpCbZ/r7mpNTJZKQ6TK70/hdhYeWtPmLRLaDa0VkJvbmAq83Po= 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=G98dEgzJ; arc=fail smtp.client-ip=52.101.193.23 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="G98dEgzJ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=snf1jV8YkN3T/L3yFiq1DFIkECdHXENbCMDxNDMsugdRPk0v9rUS/2SExyjDdLyiouET/sIR2xj0D/iEINCUhPzSI1VzQnRuuBczYw8wuio5xXFOvA/Y+p7UCkv8O3DHaZ6UyZd1xMhmkkFlrIkGRrJeYvVpuQBmb/EDX4jcx94jH4XOXRT54FOl9YxQIyRRTn+OrF/fs7t+8t+ywV47Xf7nd7ft0/IXnqFf1SeKkW/53RChD+uZ3jmJMhy/75/PMj6Ooz+rifWYvdcZudRkY/siDVw8ATSRKsAV2bKK0P79JHrJJLNEFS7nHAErXcfylU4/pTGDMO1ex00DkAxpXA== 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=p3XZeIuQn/pJE53Mejk9HVsw1h7wIkwrG1Rx7VMe+q4=; b=RN6embKFf7wDtQU5rnLnR2SRcD3YXxYut1NdAJgMh173IXZVeVSPQPWsXNAjXn7NV5z/Bfr22tgU6IEvDOyZK0CHT1Xtny0TV+a4H8aIFbxl1ZeLpRbvDEv1xFXawI9VEjTRKz3DPI0P72CcR/j+cTFcPd/m5JRXAbR/51gfWK961PvH/W6pOhaCvhBARJGaPszvwRRtaQ0bPSFi/W9zJ0deu+0KIv1ATo50QwLOcR0qRmkHcKnN+TLr3T0SjdjJZIZk6rxLRWwLhhtaF/gSRDaVdVjJQMhfWFilvVpD7lcA39kTYzTyr/E+ibEyhqTwTeNwhtlUnhdlcVmJTkO5Cg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p3XZeIuQn/pJE53Mejk9HVsw1h7wIkwrG1Rx7VMe+q4=; b=G98dEgzJ5pMG30qydlkl5809ibP7F/bNmbX4wn0DIBBm0qMKVZQlzZQbySeTU2yaEVq8YhVuQn1TRIdCZ2FKBJkQ7joNS0gbx/IHizXvmRqQrplUo6/ROIZomsY3a1d0GLicd5mIx1RvTppYvBLIjKXpHT3LW1bR5P0Fl/9ZIQ0= Received: from SA1PR04CA0012.namprd04.prod.outlook.com (2603:10b6:806:2ce::15) by PH7PR12MB5879.namprd12.prod.outlook.com (2603:10b6:510:1d7::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.10; Thu, 23 Jul 2026 09:47:17 +0000 Received: from SN1PEPF00036F3D.namprd05.prod.outlook.com (2603:10b6:806:2ce:cafe::a8) by SA1PR04CA0012.outlook.office365.com (2603:10b6:806:2ce::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.245.11 via Frontend Transport; Thu, 23 Jul 2026 09:47:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SN1PEPF00036F3D.mail.protection.outlook.com (10.167.248.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Thu, 23 Jul 2026 09:47:17 +0000 Received: from dcsm-trdripper1.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Thu, 23 Jul 2026 04:47:15 -0500 From: Muralidhara M K To: CC: , , , Muralidhara M K Subject: [PATCH v7 2/6] platform/x86/amd/hsmp: Map the metric table with ioremap() and unmap it explicitly Date: Thu, 23 Jul 2026 15:16:52 +0530 Message-ID: <20260723094656.3806028-3-muralidhara.mk@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260723094656.3806028-1-muralidhara.mk@amd.com> References: <20260723094656.3806028-1-muralidhara.mk@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F3D:EE_|PH7PR12MB5879:EE_ X-MS-Office365-Filtering-Correlation-Id: f2fae844-d968-4045-4119-08dee89f6217 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|36860700016|376014|82310400026|1800799024|11063799006|10067099003|56012099006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: 0R4gREA6qUycjF0P2IypHnW6bmHa+SC5+45ZeNZwrQin+gK43T8MXFpYckwHClKDI8UcaVWabgzaIKf+653X7SoXphMNijM7kaVjb8+Sszn+Y6BL2K//+DV0GVsvSGknh41u7Wj3ZL3Znlm7YHzVw8xkaQExD49blYcWBcp+bCCtAgq3FCt/AX14gwYDyiblbrO/6YoC6SFfZBLDz16xhEmioKR2KaqcelWEEOHRgQjm43TCpXtCAh3JJUgwEl+dHZRtXpjPvJQo9lV8aGFiAT/yVIWJIZiAAJg1Ux1M/vBMsIvz+X+3QThuCIyiJuHHZ5i1jTAMJZ1gQ1SHzgo23IrM/w+8gz9RuoQbc35CqejtOy4/BAv/aB7e4sH5rcBMUAGcpzJpIgtekb+9HeiGvz0GcG/ndTKnSC+k/e0L6NLEgA9H0dcVCz9yNSLqOV+F/BbfHEf9BMweIX0BW1S7lF0oY2mMF3KQOXwt9/pJR3l+nG1DOUyLpmcRd/TIRFU8iOmOFOD0rPay/xa7aa+WNsGdmGAWSscIhA8usJyxkdEsG6SoH5EDiYl89Tg4f0k/L8+Ua4YtOnmAJ84jdGAeZ1fku06wiSH5XN8enpCq2mqIXSBgXZYvy+Mwt4ctYx5WGYK6cmqa+qfqTMwAUfZBwnA6BgPA4VRqWgjLgCqqaeEbusKCI4DuTK11gS5SftHrBRJkjCAW3dLaE1LmW89aew== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(36860700016)(376014)(82310400026)(1800799024)(11063799006)(10067099003)(56012099006)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: l7ZnggpnkaALzFlAOzlDdzqzHMf1n6Tcb69/y0TwTunUG6BUiJ3jlBGxayhkmNPcuIBnbOp8fpvB5nGZVLv69rT/eGDb1UDmoa3oMWba8HULcnZnHeWrR1FxobLCzPcey94Vao9kAgaOXldNUEjEgNGt0jn/AFcYqP6/xM9oWbSPDtTFxJNLeUPS1EtoU9QdgEPYv3QZuCFAbelH3aDj4CSzSDWk2v6kL2j8fZHlhXW8DXDBbCc2DNIHnwUum2GXzw0xax6A3fWbiOJoBASgYW1M9D1R5wWHN3AzlO+XbSf+P4nVbCdx8ciprYjWLg7O6fYbfAmYKhc1AFQ4iIuD0oud0ulSBXuFIYXT8kFdqBrcvUSMgGVsZAxFAtG5d0rFRFgBw8RtvNlYmrbSx0TbddHlVKd2OQoHjsmXv78/LM3L+A5DbboyITw9nbLlwtKa X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jul 2026 09:47:17.5707 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f2fae844-d968-4045-4119-08dee89f6217 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F3D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5879 Content-Type: text/plain; charset="utf-8" The metric-table DRAM region is mapped with devm_ioremap(), which ties the mapping to the socket device's devres scope. An upcoming change lets the ACPI front-end share the socket array across sockets and run its own coordinated teardown, so the mapping can no longer be pinned to a single per-socket devres scope. Map it with plain ioremap() instead and add hsmp_unmap_metric_tbls(), which drops every socket's metric_tbl_addr mapping. The platform driver registers that helper with devm_add_action_or_reset() so the mappings are released on both remove and probe failure, while the socket array itself stays devm-managed. Signed-off-by: Muralidhara M K --- drivers/platform/x86/amd/hsmp/hsmp.c | 19 +++++++++++++++++-- drivers/platform/x86/amd/hsmp/hsmp.h | 1 + drivers/platform/x86/amd/hsmp/plat.c | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/am= d/hsmp/hsmp.c index e9c17698983c..008f3c0b2ad7 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.c +++ b/drivers/platform/x86/amd/hsmp/hsmp.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -423,6 +424,21 @@ ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock,= char *buf, size_t size) } EXPORT_SYMBOL_NS_GPL(hsmp_metric_tbl_read, "AMD_HSMP"); =20 +void hsmp_unmap_metric_tbls(struct hsmp_plat_device *pdev) +{ + struct hsmp_socket *sock; + u16 i; + + for (i =3D 0; i < pdev->num_sockets; i++) { + sock =3D &pdev->sock[i]; + if (sock->metric_tbl_addr) { + iounmap(sock->metric_tbl_addr); + sock->metric_tbl_addr =3D NULL; + } + } +} +EXPORT_SYMBOL_NS_GPL(hsmp_unmap_metric_tbls, "AMD_HSMP"); + int hsmp_get_tbl_dram_base(u16 sock_ind) { struct hsmp_socket *sock =3D &hsmp_pdev.sock[sock_ind]; @@ -447,8 +463,7 @@ int hsmp_get_tbl_dram_base(u16 sock_ind) dev_err(sock->dev, "Invalid DRAM address for metric table\n"); return -ENOMEM; } - sock->metric_tbl_addr =3D devm_ioremap(sock->dev, dram_addr, - sizeof(struct hsmp_metric_table)); + sock->metric_tbl_addr =3D ioremap(dram_addr, sizeof(struct hsmp_metric_ta= ble)); if (!sock->metric_tbl_addr) { dev_err(sock->dev, "Failed to ioremap metric table addr\n"); return -ENOMEM; diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/am= d/hsmp/hsmp.h index 129200d0cf81..b0d67b93363d 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.h +++ b/drivers/platform/x86/amd/hsmp/hsmp.h @@ -64,6 +64,7 @@ long hsmp_ioctl(struct file *fp, unsigned int cmd, unsign= ed long arg); void hsmp_misc_deregister(void); int hsmp_misc_register(struct device *dev); int hsmp_get_tbl_dram_base(u16 sock_ind); +void hsmp_unmap_metric_tbls(struct hsmp_plat_device *pdev); ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock, char *buf, size_t s= ize); struct hsmp_plat_device *get_hsmp_pdev(void); #if IS_ENABLED(CONFIG_HWMON) diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/am= d/hsmp/plat.c index e07f68575055..b5f2120765c8 100644 --- a/drivers/platform/x86/amd/hsmp/plat.c +++ b/drivers/platform/x86/amd/hsmp/plat.c @@ -201,6 +201,19 @@ static int init_platform_device(struct device *dev) return 0; } =20 +/* + * The socket array is devm-managed and freed by the driver core, but the + * metric-table DRAM regions are mapped with plain ioremap() during probe = and + * are therefore not covered by devres. + * + * Drop those mappings from a devres action so both remove and probe failu= re + * unmap them exactly once, before the socket array they refer to is freed. + */ +static void hsmp_pltdrv_release(void *data) +{ + hsmp_unmap_metric_tbls(hsmp_pdev); +} + static int hsmp_pltdrv_probe(struct platform_device *pdev) { int ret; @@ -211,6 +224,10 @@ static int hsmp_pltdrv_probe(struct platform_device *p= dev) if (!hsmp_pdev->sock) return -ENOMEM; =20 + ret =3D devm_add_action_or_reset(&pdev->dev, hsmp_pltdrv_release, NULL); + if (ret) + return ret; + ret =3D init_platform_device(&pdev->dev); if (ret) { dev_err(&pdev->dev, "Failed to init HSMP mailbox\n"); --=20 2.34.1 From nobody Fri Jul 24 21:53:11 2026 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013033.outbound.protection.outlook.com [40.93.196.33]) (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 A330F42EEC9; Thu, 23 Jul 2026 09:47:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.33 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784800047; cv=fail; b=M+qi9l/jxG6C1xwK3J8YA8BavOYFJ4UCUEMOIBI17wy+RKlLkfKxogcFL+qAE38DQ8R6lfhlLefoFvjcdl0qfAoGs8rQQ0n0wD0M/ZmUTHpRYJy0UCuxQkmnNFRX/35vbkwSmy0BlHEsYWvsPG3pck7G2xgLr6Se/LPubgD/J98= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784800047; c=relaxed/simple; bh=t6pcNxzgxUnlbOibqB4NYzZYzG/BqEyfso1F39C2H7A=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fo/ep1wTLliPHpvQP4Q5rxpolMVgXDfI/FUQyeyyyU5c8rzMiT+eTUG/L6hXY67x5CdH330CngirCObsHCjrmaJD7awCdvf6jDaQBYMY0kueKmS/spplWC5dwXmJ1uFYd9q/Du4A9MTc8z0pY7glIf04McXQdjKBZw32geM3Ylc= 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=KnKMC18u; arc=fail smtp.client-ip=40.93.196.33 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="KnKMC18u" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=y6df3rRv346Brck7WY2L6LfQngGaTDH2+nHG+JWIDHziPIfLRO3x+di6huiIYMxM5LOKCHFP6k1LAIkoe/x2HCwwnxbIvoY2bT7gGj3kEq/2dTjrdjXU0VmQXqaiuziGXsu5x+p5jAXoyb1u53hL5489Y38bikdaeBOTB/2j+3VXI8BLl3m3g3T9TTrcjXzm34jI2f3Lvrj533IoYUkvEILRlk6gw18FO2ZvrId2c3HU2fwxRDw+1wrMdKy0ue5KbFtQ24iouTWUMhiKxDxy8K054XyFbuablcE+Vxe/5VF6Y1pmpf2furk8g8gs1KEtynnXv3EeWjevlUb5AYX3xQ== 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=PTQqoRjCR1NTLftlLud0dF1a5y0lq6my/fM6coKXjdo=; b=ZqkmIWxpS2GPs46fxOGutTsaI6Tg5TFc8dzRSpp4MpQoB5HXFx2AsynOrfZuBvER1UtcphN1Q1SJNUHUwho5NswnF/8IicH6SYnGmFqlhHm1AGjBNrC4qv2TOhKqcsnKpxSeKwRFffwE4x6ZKCpSlBjdzG3wyvTEryuhynOzuk1xGPWEUsNWEK2pczQ0hIfvuyCRo4CuoPeyttEoTj28TTcGcsBfg5YkF5HsS45ECte14kYbD0gPltNG9XqTM9XTVVXWSJv9kw03UNC1hg5+FbKjU+MvBZocdZZ/TNlAsS6el2tVXTSnmaEj6De8hyeAeB8P/3/q/YPymMN+5AnNVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PTQqoRjCR1NTLftlLud0dF1a5y0lq6my/fM6coKXjdo=; b=KnKMC18uZjqalO4/WiMonyGTQGZDflnYyZTfcKZxUZovUMLBOGMCjIjAYWPhik6am3BqX31EHwlzVQyA9IT1h6owo96ER596acemmanIo8xq+xIzW70mO6NPLTMAxDSrHlv2JraQjKo0sgbNRRAVabrakaVp9/uEWShTD5Nqclo= Received: from SA1PR04CA0020.namprd04.prod.outlook.com (2603:10b6:806:2ce::29) by DM4PR12MB8449.namprd12.prod.outlook.com (2603:10b6:8:17f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.223.18; Thu, 23 Jul 2026 09:47:21 +0000 Received: from SN1PEPF00036F3D.namprd05.prod.outlook.com (2603:10b6:806:2ce:cafe::56) by SA1PR04CA0020.outlook.office365.com (2603:10b6:806:2ce::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.245.11 via Frontend Transport; Thu, 23 Jul 2026 09:47:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SN1PEPF00036F3D.mail.protection.outlook.com (10.167.248.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Thu, 23 Jul 2026 09:47:19 +0000 Received: from dcsm-trdripper1.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Thu, 23 Jul 2026 04:47:17 -0500 From: Muralidhara M K To: CC: , , , Muralidhara M K Subject: [PATCH v7 3/6] platform/x86/amd/hsmp: Serialize per-socket metric table reads with a mutex Date: Thu, 23 Jul 2026 15:16:53 +0530 Message-ID: <20260723094656.3806028-4-muralidhara.mk@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260723094656.3806028-1-muralidhara.mk@amd.com> References: <20260723094656.3806028-1-muralidhara.mk@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F3D:EE_|DM4PR12MB8449:EE_ X-MS-Office365-Filtering-Correlation-Id: 9fc71289-0754-4df0-1602-08dee89f62fb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|36860700016|376014|1800799024|82310400026|10067099003|11063799006|56012099006|6133799003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: gXNxmA65dnUrnls2Pid+jR2STwfiDaGCSFFSjeW3u0KqMtwo01hnaAl7P4RzfHHcLhqGGWav/sSGcvmTm/GrcEqk2YQuNjYS25VtmU5/gi6TCMYKfrHm+GfSB5eaTlWjEch+i9nq8D2FTTq8yRmCX0aYLnMEkkHIR84gGhIl2XwYEmC+3MBwy5XY8E9jSNBWWBT1yEuPnLm8X0CvzzeRb0sCl6BiJuS3ClTF7WfU+P/cMryQqU/zfBlusAUZcDiuXfJhlxsfxy9ixitd/etM1UF9+qhmoWxJd9zMWZMtfXjFvrR/GacRaDQzB6XXlmQm0a/U3DhJYapOAYXy5z25MSvBo7drcS8l7iY+Uc1WMuNw1INJE/m1aedDjXfK9/2eYY39P/PuRRxMffNC0EJ8MY3WmEVuDdw5Av+QrE1ErgJPGrskreT4/0048MxDsFbcMmDsCDRd1q/Y1uqhDrfur+cXR9d2LSvMYH9nZ6gxbOD15pqwJ6rmb/jJRIk4exWZGD+20RB4Q45F3VCwSiB5HU1sTvahyKy3NxVXSYMiAdVcM2WNpSKIslAw74/mG1+mtBaTGwFFhpNQluyEWXSeUqYAtwqzyAlW5Lxk4Laq3/Kk8+3X3eN6yvyLSnM1pvNLLUtefRktQZJdO7Hx1w5/DdhwBwLhY26s6wbjf4qPJCeIJh0SpaQwD/fzED1bLnpkGVLOj9jEh6xqtCPGne7oHw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(36860700016)(376014)(1800799024)(82310400026)(10067099003)(11063799006)(56012099006)(6133799003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: E1qA2rZVUKNrYxlncg3aA3LkmYuWovvzhJMtP0eo78R4AgwOeGrEiLRKWlnVEkiJS12wFTJDlIeFo1DN9TktfIMfQGyQ89Kx7nVMjmogmn1j6Y8kSu3C/eCiFSYB4nxiNTOcyZMA5CMui38oA73jHYUk0jRdcukt5g1uFanKW3dIHr5kUeDJIlv3pxPkT3QZM5368u88pC7CYDTaODLMnLmQ/nGaRKMB8w3a4km76pabORY7vVvftbWyzwUo1m9GV5AFjR4tQCrgraKLtsXdsFsTCyziPijb40UDl4inOBfRlYlhyq5JgLCDTbz06wViEDmGB9w/DbmPeAMQtg3LAS62x/DwVg0b0jzbyfY9vu0Py+VExf1FzvyAhhQ231EU4WFbr3PVoENY5wNjEnsroDQJcDX90GJih1yBGln2yl9QBsjl4UffFW0pnpF1TknY X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jul 2026 09:47:19.0913 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9fc71289-0754-4df0-1602-08dee89f62fb X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F3D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB8449 Content-Type: text/plain; charset="utf-8" HSMP_GET_METRIC_TABLE makes the firmware refill a shared per-socket metric DRAM region, which hsmp_metric_tbl_read() then copies out with memcpy_fromio(). Two concurrent readers of the metrics_bin sysfs attribute on the same socket can race: one can trigger a fresh fill while the other is mid-copy and return a torn snapshot. (The hwmon path does not touch this region; it only issues power messages via hsmp_send_message().) Embed a struct mutex metric_read_lock in each hsmp_socket and hold it across the fill-and-copy in hsmp_metric_tbl_read(). Add hsmp_init_metric_read_locks() and hsmp_destroy_metric_read_locks(), which take only struct hsmp_plat_device and iterate pdev->sock[] over pdev->num_sockets so the caller cannot pass a count that disagrees with the array. Wire them into both front-ends' probe and teardown paths so the mutex is always initialized before metrics_bin is exposed: the platform driver and the ACPI driver both drive hsmp_metric_tbl_read() through the same 0444 metrics_bin attribute. Doing this in one patch avoids a bisection point where an ACPI read would lock an uninitialized mutex. Signed-off-by: Muralidhara M K --- drivers/platform/x86/amd/hsmp/acpi.c | 3 +++ drivers/platform/x86/amd/hsmp/hsmp.c | 28 ++++++++++++++++++++++++++++ drivers/platform/x86/amd/hsmp/hsmp.h | 5 +++++ drivers/platform/x86/amd/hsmp/plat.c | 3 +++ 4 files changed, 39 insertions(+) diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/am= d/hsmp/acpi.c index a23797bd1dd5..a092d7589bcb 100644 --- a/drivers/platform/x86/amd/hsmp/acpi.c +++ b/drivers/platform/x86/amd/hsmp/acpi.c @@ -639,6 +639,8 @@ static int hsmp_acpi_probe(struct platform_device *pdev) GFP_KERNEL); if (!hsmp_pdev->sock) return -ENOMEM; + + hsmp_init_metric_read_locks(hsmp_pdev); } =20 ret =3D init_acpi(&pdev->dev); @@ -670,6 +672,7 @@ static void hsmp_acpi_remove(struct platform_device *pd= ev) */ if (hsmp_pdev->is_probed) { hsmp_misc_deregister(); + hsmp_destroy_metric_read_locks(hsmp_pdev); hsmp_pdev->is_probed =3D false; } } diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/am= d/hsmp/hsmp.c index 008f3c0b2ad7..fd36c8f142c0 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.c +++ b/drivers/platform/x86/amd/hsmp/hsmp.c @@ -10,9 +10,11 @@ #include =20 #include +#include #include #include #include +#include #include #include #include @@ -415,6 +417,14 @@ ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock,= char *buf, size_t size) msg.msg_id =3D HSMP_GET_METRIC_TABLE; msg.sock_ind =3D sock->sock_ind; =20 + /* + * HSMP_GET_METRIC_TABLE makes firmware refill this socket's shared + * metric DRAM region, which is then copied out below. Hold the + * per-socket lock across the fill-and-copy so concurrent readers of the + * same socket cannot return a torn snapshot. + */ + guard(mutex)(&sock->metric_read_lock); + ret =3D hsmp_send_message(&msg); if (ret) return ret; @@ -424,6 +434,24 @@ ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock,= char *buf, size_t size) } EXPORT_SYMBOL_NS_GPL(hsmp_metric_tbl_read, "AMD_HSMP"); =20 +void hsmp_init_metric_read_locks(struct hsmp_plat_device *pdev) +{ + u16 i; + + for (i =3D 0; i < pdev->num_sockets; i++) + mutex_init(&pdev->sock[i].metric_read_lock); +} +EXPORT_SYMBOL_NS_GPL(hsmp_init_metric_read_locks, "AMD_HSMP"); + +void hsmp_destroy_metric_read_locks(struct hsmp_plat_device *pdev) +{ + u16 i; + + for (i =3D 0; i < pdev->num_sockets; i++) + mutex_destroy(&pdev->sock[i].metric_read_lock); +} +EXPORT_SYMBOL_NS_GPL(hsmp_destroy_metric_read_locks, "AMD_HSMP"); + void hsmp_unmap_metric_tbls(struct hsmp_plat_device *pdev) { struct hsmp_socket *sock; diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/am= d/hsmp/hsmp.h index b0d67b93363d..ec92c2a429bb 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.h +++ b/drivers/platform/x86/amd/hsmp/hsmp.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,8 @@ struct hsmp_socket { void __iomem *metric_tbl_addr; void __iomem *virt_base_addr; struct semaphore hsmp_sem; + /* Serializes HSMP_GET_METRIC_TABLE fill-and-copy for this socket */ + struct mutex metric_read_lock; char name[HSMP_ATTR_GRP_NAME_SIZE]; struct device *dev; u16 sock_ind; @@ -65,6 +68,8 @@ void hsmp_misc_deregister(void); int hsmp_misc_register(struct device *dev); int hsmp_get_tbl_dram_base(u16 sock_ind); void hsmp_unmap_metric_tbls(struct hsmp_plat_device *pdev); +void hsmp_init_metric_read_locks(struct hsmp_plat_device *pdev); +void hsmp_destroy_metric_read_locks(struct hsmp_plat_device *pdev); ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock, char *buf, size_t s= ize); struct hsmp_plat_device *get_hsmp_pdev(void); #if IS_ENABLED(CONFIG_HWMON) diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/am= d/hsmp/plat.c index b5f2120765c8..7a16d1ab463b 100644 --- a/drivers/platform/x86/amd/hsmp/plat.c +++ b/drivers/platform/x86/amd/hsmp/plat.c @@ -212,6 +212,7 @@ static int init_platform_device(struct device *dev) static void hsmp_pltdrv_release(void *data) { hsmp_unmap_metric_tbls(hsmp_pdev); + hsmp_destroy_metric_read_locks(hsmp_pdev); } =20 static int hsmp_pltdrv_probe(struct platform_device *pdev) @@ -224,6 +225,8 @@ static int hsmp_pltdrv_probe(struct platform_device *pd= ev) if (!hsmp_pdev->sock) return -ENOMEM; =20 + hsmp_init_metric_read_locks(hsmp_pdev); + ret =3D devm_add_action_or_reset(&pdev->dev, hsmp_pltdrv_release, NULL); if (ret) return ret; --=20 2.34.1 From nobody Fri Jul 24 21:53:11 2026 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013052.outbound.protection.outlook.com [40.93.196.52]) (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 DC62142FCCC; Thu, 23 Jul 2026 09:47:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784800047; cv=fail; b=o2KDva4iNf1p3tVgxnzuX3FhVFvyN6iGWt464EZFwwZqjHjO1wZoSj3t5JOXBtnffb7/ukX+UER1jSheo9qDzLrO5JTg+33nz5GnQ4PtdfAeS66JT+8SOVe+1IECGhnmNaFG9dRMHIi3+ewUscHp71XEkKFAr6UTUyFbTQAoEWE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784800047; c=relaxed/simple; bh=9KWKZzZGuWBWH/h+cSYBAWf9dJ/sAcuRy03LTHEJMqk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tlxNVUOCkHSIV2wTqu42vLnKWLQCDr1mAXvIdKpJjP8m3HD8QIOF5mVeAqskPhOGOgsPnMW+d73QD7cJLb1FfmKXw4tNEdIQcMxQqD3cEAoZ5ywmyXxyBhC2SIYyAVb56NcKUCpcjrMuh3DHRUa+aozSeuluTfH9myKXpCCYHFw= 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=5D8jr7Pb; arc=fail smtp.client-ip=40.93.196.52 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="5D8jr7Pb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fy5U7EzsV6M99Sz3eHa9NsMO5ZoNnZTsoWOQgCx/jlLA+cr5oBxsPPMXdO0m1NhKdiG5lVl0bvb5O+lcOW9aL6aq0CQFbBsN5oGGxFEqR3ISp+K+hdHsUY44MHxCEMwFJh5XUM2ICkmjFWf6vIJ/I0fOFw0FZItje/DMHY1ZcnggY13ipfULad6cOGnQhw4c6r8snjrw7XWha8p4XKmPdeMINJrEAYDkEFvMauUZ68qnkvWQNeqjhopv16TFWRT7CfW8Siv9lGC2pbNxWd5woiuT4P6vc7LbljDMDr5ZHmh7Nb6zelLyhZx/PpTUv5KyfBNnORMy3xpqSef2PgMoDA== 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=FyWGPWrrB9mFsyaDZ9ijrgy5YkVtj1mSwJzz5noEpz4=; b=JomvhGZ/W573E0PgNNhHWoOQKtNb5Iwyz6hquX9dvejjQun/CJWAvCwVbM5UroDvbfGYxSUXNc16kXREyscISh1o9LvPpm3/8afCKHeDGU3n3xCfzqF8cwp+u89PMQv9QHW0dT45Xn8FntdGlGT5UnxEyvRhTAlq4aj3F39IfFW3zLquIyALeE3NuY/OBGMd1wdjcam3XFbs/+yQDHZ+LoXbRXXKLyZvYqLJ6ReeJenj8bFL/wxbLHmTGIw6DEzFykZpDKkX5oxQJ5+i+hiE0odyVN+UOzbt+A/oJzcx0BgIzFTMzcK1yPyVoLQdezo25wn+bJgqn0zork1TW55uKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FyWGPWrrB9mFsyaDZ9ijrgy5YkVtj1mSwJzz5noEpz4=; b=5D8jr7PbIwLEP5W8vs4UHp7WzoGRRc8NdVu8QNnko1jWSNuqIfaDNUymTw9TeGWXEDfrgs3+2N+Xrrpw6CYaTClWK62rTsGprBbagF1gRUbeVDrQ+RmRAjDCtXXQe2A8QuibYpQy3f2T7L1Ss8mOnwU89vIBlhuEyyJ/7M3nJHg= Received: from SA1PR04CA0013.namprd04.prod.outlook.com (2603:10b6:806:2ce::19) by IA1PR12MB8468.namprd12.prod.outlook.com (2603:10b6:208:445::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.223.18; Thu, 23 Jul 2026 09:47:22 +0000 Received: from SN1PEPF00036F3D.namprd05.prod.outlook.com (2603:10b6:806:2ce:cafe::3) by SA1PR04CA0013.outlook.office365.com (2603:10b6:806:2ce::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.245.11 via Frontend Transport; Thu, 23 Jul 2026 09:47:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SN1PEPF00036F3D.mail.protection.outlook.com (10.167.248.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Thu, 23 Jul 2026 09:47:22 +0000 Received: from dcsm-trdripper1.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Thu, 23 Jul 2026 04:47:19 -0500 From: Muralidhara M K To: CC: , , , Muralidhara M K Subject: [PATCH v7 4/6] platform/x86/amd/hsmp: Clear mdev.this_device on deregister Date: Thu, 23 Jul 2026 15:16:54 +0530 Message-ID: <20260723094656.3806028-5-muralidhara.mk@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260723094656.3806028-1-muralidhara.mk@amd.com> References: <20260723094656.3806028-1-muralidhara.mk@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F3D:EE_|IA1PR12MB8468:EE_ X-MS-Office365-Filtering-Correlation-Id: a8cd03a8-7b2a-4e7d-e0b6-08dee89f64b8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|376014|82310400026|36860700016|1800799024|11063799006|56012099006|10067099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: 68oU41SoWd2PlfinRGzLgMp98mgbmS/XvXoIQbn5x7Skpv3NmVblffFFJ4zWhjmcLgSBkUm8D+Jr6VMAOKfRDAsWefKvEuoqnHfBsFcLZBYueIE6PEHbuO+UmJFoxb/y+bzutPENrXPQxzQizG1iNXiVq9iUQylMzjDA84fXsJPnkRu61QtYRNI7Xv4Ovst09p2di01uRyuOAheZliXQtmm5GGnGgtOur5KGPcnah4BWYms1EVB5GCNc7pb1FkMEmrMrtx3JddB/qgTlyJ+cx8OtND3oI3CJ2mFHmMsw11DZUYPYMLMOG42Zz223Y9FmLkI+7/7kSY3j0OehI8zdPEaFdI+AgPz6tmGfL0D8a7e2eFHCucBMqxZq+lUkoSgNyX1L4BQW1CsbHPlPH6Dzo4qieXBcXGrlJkfpJryvthDcVPsBPJ+UQAgH/xPrU6mXrsBtHIMRhkakmT307U1tRvqAa/7/nhAmr9lmTBVBkAawvfo7JvWDfwJuMhMpfwAkjI3q+NeFwhBTKGuMCaRxlHTDRbZkqvbyNQlq4mOMCJHNnKVWjpRvQZ5rUSkYtnB5BrvdzRMmSTbAXqPSgred0ush8V4iczV/pMi9vWEB+/0WXkYF7+XjehVUVO9eDzyz8lLqn13peZuWB7Xx/W1YRwAjVj1FkjG2lvVPvpVEnTNgDQn7X+tjCv4+U8hzdaPf5BBL3ZtTc/kj9BAhK+j2eQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(376014)(82310400026)(36860700016)(1800799024)(11063799006)(56012099006)(10067099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0c7Igq3ecRj9YzYKtzqEHDBvXnFR/HInvH73SvNdgvMbDJHeQ688ynFegjMwFvrjNonBcSDwQXNqqmY4D3Z19EpoKDJrK55ogpvo86O9QLmwyDqa+0cQ7Qf53BPsYMUgC/6y5li9VNJf6KEDCK3AVUYMz63sXtCo4ch3eAdmxEv9S0nAi2ADZYGlR11Ne0Fu6mZldoTM/QW9AuR4N2UstAUeePEFp87ldRt2Ft2qIKcZGtb4YloHbpDnqLlm+qS0KAd7l9my+biKkIQSD13htcRYPpwJLCaz8mSpeItB5wuAyH3kpd5cj4ZrjMa5UtAv72CnlGyUYQstm+tqWt5W0vqKQt3tfj0c9ljgnIzG2J5ZJiLx3QGerFbVDN0EivdrARV+iUu883RdlHIG2pgW3T5jp2n+oIh47BNh1RGZhDe6VMmw2CgVFDGMqO7tjo+L X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jul 2026 09:47:22.0133 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a8cd03a8-7b2a-4e7d-e0b6-08dee89f64b8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F3D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8468 Content-Type: text/plain; charset="utf-8" misc_deregister() destroys the device but leaves miscdevice.this_device pointing at the freed struct device. Clear it so any later check of this_device, and a subsequent re-register, does not observe a stale pointer. An upcoming change uses this_device to track whether /dev/hsmp is registered across the shared ACPI sockets and relies on it being NULL after deregister. Signed-off-by: Muralidhara M K --- drivers/platform/x86/amd/hsmp/hsmp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/am= d/hsmp/hsmp.c index fd36c8f142c0..584fd9b1d31f 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.c +++ b/drivers/platform/x86/amd/hsmp/hsmp.c @@ -539,6 +539,7 @@ EXPORT_SYMBOL_NS_GPL(hsmp_misc_register, "AMD_HSMP"); void hsmp_misc_deregister(void) { misc_deregister(&hsmp_pdev.mdev); + hsmp_pdev.mdev.this_device =3D NULL; } EXPORT_SYMBOL_NS_GPL(hsmp_misc_deregister, "AMD_HSMP"); =20 --=20 2.34.1 From nobody Fri Jul 24 21:53:11 2026 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012004.outbound.protection.outlook.com [40.93.195.4]) (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 D2951431E4B; Thu, 23 Jul 2026 09:47:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.195.4 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784800050; cv=fail; b=SQ7MvTV0xVbF0Sf8hNy9TIYg9CSkh8lrw8PhWYyLGhjdnEKWah+0jxsYDK4Ae4KLi6aTgPsswMKy+Ww46NQ37womJJnIFBxQh5tSUwupzOOYZoPrnWrQohp9iNoQu+RkwN+DSsM1GefODmFllTofjSpE5OqSsOQfzMa6WiLC3zk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784800050; c=relaxed/simple; bh=gUTHi3e/VcKLsB6QcWsNGl+dQab7fcn3JU0uAHJU4Bs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bAJ+PRqDecy/dIw9e3w2Oi8Vps6HC1zCYfmvW/T//blK4/iDKg5S/dRrcd7CYrg30RLTjw6/OEEGlqydc9eJhXFKyffKUBEX2SndnIrAAFG/GV+ZktKWJov0KKmGi4gVsoq0QbefCNVkkkUvrDqQDubPi/osEH4XWOGX/+I/Hho= 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=Uax7YkdY; arc=fail smtp.client-ip=40.93.195.4 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="Uax7YkdY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wf+xVA2j0gFDUEvHxk5OcHEESOaHxDUIHfyBJAqn4dVYFkJlY7VhTBndVp6Arjf594/fhkenmHQdGTefW8cTN9vHbvx5mDlDV1Uj5Z7YkBXYE6modn2vbsil2X3/GLASGhQZcpzH1j4Q5YwqLA+fyARXRMbv4m3QgKQlS+cNlfM/ruFrMVekssJg0c39ypXUyu0EaSNj7xrJhzNnWJUvWBmxFJle6zYOodbwLqf3tyRs5n8VDbbiyJHR5IQ1KH9P4JHFrf8FYXdVW3xvCpdLCEkKI0L0VmB1PPBfQU15cURYul/BZySbjQMBc3m/SdblpaRwwOGOaDA4AX0DAwE0sg== 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=FsH+h3PKL1f/+YVQcPzLjAXsqNDRDMIdYtvuyBVmkQo=; b=pKRvxReyGuoZBCMagInuBs446bVSmay8yJZ2JsL2h7YAS43foC0jVWva7ashv69Rjzb9Mujw4U3jqqIdMMlzX5NAZJvcsheycfz63UNAEgzhs2dt1kM3Hr/CX/ai1o22OSx2YYxiB6rqo50LwAmCcy8uvMQiI8ji0JXkDw8Tv0VcpEOpQhazfcUpSXu3q2NOsHFBuAOZhf7XrC9I+XZBgfGTCT+4BHhTUPx9/0IgxM2/1o8kLljA77YHn2g9G6ZG6lD2l69BPKRq4XD0TguDWZ8lZ0HH8WyTapY+EYzv2H9n1vZerv1vvuN3yNZ17aEaxJr7ZgYeZUzB5TRRSPVfdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FsH+h3PKL1f/+YVQcPzLjAXsqNDRDMIdYtvuyBVmkQo=; b=Uax7YkdYBk5g0xl8LQpOyooEFlFKfOJqyQhWfBG4wkvTjou6OVeXwGz6n26fkvJipWiJJ6jEQZLlmAt1+cUTWmphKiWjJCGMLU4EuvDgwbByNRFYQUKVwEyBCwOkz+8KBUrKPiGg0gt8rLasQ+5nwVFUYPsWEhymapJ0D/p3sXQ= Received: from PH8P221CA0004.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:2d8::9) by DS4PR12MB9745.namprd12.prod.outlook.com (2603:10b6:8:2a9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.10; Thu, 23 Jul 2026 09:47:24 +0000 Received: from SN1PEPF00036F3E.namprd05.prod.outlook.com (2603:10b6:510:2d8:cafe::97) by PH8P221CA0004.outlook.office365.com (2603:10b6:510:2d8::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.245.11 via Frontend Transport; Thu, 23 Jul 2026 09:47:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SN1PEPF00036F3E.mail.protection.outlook.com (10.167.248.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Thu, 23 Jul 2026 09:47:23 +0000 Received: from dcsm-trdripper1.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Thu, 23 Jul 2026 04:47:21 -0500 From: Muralidhara M K To: CC: , , , Muralidhara M K Subject: [PATCH v7 5/6] platform/x86/amd/hsmp: ACPI HSMP refcounted sockets and coordinated release Date: Thu, 23 Jul 2026 15:16:55 +0530 Message-ID: <20260723094656.3806028-6-muralidhara.mk@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260723094656.3806028-1-muralidhara.mk@amd.com> References: <20260723094656.3806028-1-muralidhara.mk@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F3E:EE_|DS4PR12MB9745:EE_ X-MS-Office365-Filtering-Correlation-Id: 24aee42a-fb63-47ba-b4f9-08dee89f6592 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|376014|36860700016|82310400026|1800799024|6133799003|56012099006|11063799006|10067099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: g6I9qQq60wmqAmB6rIE3vjjmsXr9uafkX83aE3+4SKuqxuckgau0SriPlOwn/nvTr3iWfwkC93B28Le8lzOedpnl1dSRjHM79vktm+Tm0RQ0XiLc9RvE/GWQ+cSmkRagX5vFH9oVSRtdh+peynWJVA4oBCsjz77q8/3walLig7umEKfN9zOI24fiasYMOUYf4mwoikUeHwryS5UWz6YRSNWOnhoWuGmY/d0/cd/7RkXSlmjB+dv8KMW0lesKmxJPKIZTje3mntvUoRErgi9izyU9wBWwEp/nBsBFJOT97viqKxoMhfHdhsEPAOe6r5Rl+rcTE02SXACuuzybwyPmIa1qwzoXu6tD50FAVJXjq6hUWmQpJu0NYGtyoQbhHL/QYjaH1a3Pfrx5cwzqpsY7q7E0L0Zhw3iSd7M/zNpL0eeyHdTt4q/SZOMcP5JMUJWCDpbdiTO3NRcMT6HcgG6iq0Ca/D/ZJzGbZHRpHLLnFixpvZnzWa9ygUMgH+8wO6A8lIDI1k2a/HV4cjNs4paiy0Y4CUWlMBKjURa58iLTzf5Zobp4jsOiEUVSsC6ysBxMQJafyaYIfitlqmZWpcFkI2epYCOvoOHUMIy/+lu0b1oFyJqFmxQcyr/gVUd0paAOGfUHa+Q/2DgdfBv9ZMVO8HkLIDQxJXnvXrJJ/9S57lBPVpn34e5JHXjN+agz9ngJpAVeVznJKOtU6SmI3Q7Fbg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(376014)(36860700016)(82310400026)(1800799024)(6133799003)(56012099006)(11063799006)(10067099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: x/RYZunmM19eL8oG5VyKoPek+Qctj9Rmd6bjvJkRGJap4oL96i2Ky+/HGvLO0He3Jn/HGxRAzTY4szPriFb+WNu+iM3tJ1rV+zx+4wHb8yVSP7/PjlBl/9Gz/2kALWqdsdMDaWbBhTZXFmf30Pv91tZstnW5nmzZAEgp41zxVKEu5OWBbUJJV9Dh0t8aHyni4QuSfAuH+bAXzF+YBtFTDLkOJ629m3Fn+0j0VV0TlQwxPdOXmPVQxCqBtlUFymd25ZPJrByUd3DXqoxgBDZY/lQae4A2oc24F+nD3PM57Yrx1CEsdW5NwT7idGiMhpvD2BIFJs3pZ8tUsB4aM58KuId3xJW1pvAYi71ScaDUKAZIH36OI0TNiEbo6HM6rGH5AFvkwT67/wpiQHlHRipEXTDiAoIU125oVi5JpwvcEhMdqFWQRaY4sNAJze6hS3Dw X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jul 2026 09:47:23.4120 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 24aee42a-fb63-47ba-b4f9-08dee89f6592 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F3E.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS4PR12MB9745 Content-Type: text/plain; charset="utf-8" The ACPI driver binds one platform device per socket but shares a single socket array and a single /dev/hsmp misc device across them. Replace the is_probed flag with state that tracks this shared ownership: - miscdevice.this_device tells whether /dev/hsmp is registered, so the misc device is registered on the first socket and torn down last. A preceding change clears mdev.this_device on deregister so this gate stays reliable across a re-probe. - a kref tracks the sockets that share the array. The first probe initializes it, each further probe takes a reference and every remove (or probe failure) drops one; the last put runs the release callback. All get/put happen under hsmp_sock_rwsem held for write, so the counting is already serialized and kref's atomic is not strictly needed, but kref gives the clearer get/put interface and a release callback. The shared socket array is allocated with kcalloc() on the first probe and freed by the release callback once the last reference is dropped. hsmp_acpi_sock_release() is the single teardown helper, run from kref_put(): it deregisters /dev/hsmp if registered, unmaps any metric-table DRAM, destroys the per-socket mutexes and frees the array. The remove path and the probe-failure path both reach it through the last put, so the teardown lives in one place. Both paths also clear this socket's dev, so a message issued after a non-final unbind (or to a socket that failed to probe on a multi-socket system, whose array stays alive and whose remove() is never called) cannot reach the mailbox that devres is about to unmap. Two lifetime fixes fall out of the array persisting across a non-final unbind: - hsmp_get_tbl_dram_base() iounmap()s any stale metric_tbl_addr before remapping, so a rebind does not leak one mapping per cycle. It runs during (re)probe before the metric sysfs attribute is exposed, so no reader can be using the old mapping. - The ACPI path registers /dev/hsmp unparented by passing NULL to hsmp_misc_register(). Its per-socket devices can be unbound individually and out of order and the misc device outlives all but the last of them, so parenting it to one socket's device would leave a dangling parent. hsmp_misc_register() now takes the parent from its caller, so the platform driver keeps parenting /dev/hsmp to its single device. hsmp_sock_rwsem is held for write across probe and remove, so the release and probe-failure cleanup run with it already held; an upcoming change adds its read side so the same lock also drains the data plane. Signed-off-by: Muralidhara M K --- drivers/platform/x86/amd/hsmp/acpi.c | 131 +++++++++++++++++++++++---- drivers/platform/x86/amd/hsmp/hsmp.c | 20 ++++ drivers/platform/x86/amd/hsmp/hsmp.h | 1 - 3 files changed, 132 insertions(+), 20 deletions(-) diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/am= d/hsmp/acpi.c index a092d7589bcb..24f54dc7254f 100644 --- a/drivers/platform/x86/amd/hsmp/acpi.c +++ b/drivers/platform/x86/amd/hsmp/acpi.c @@ -19,11 +19,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -42,6 +44,17 @@ =20 static struct hsmp_plat_device *hsmp_pdev; =20 +/* + * Tracks the ACPI socket platform devices that share the socket array and= the + * /dev/hsmp misc device. The first probe initializes it, each further pro= be + * takes a reference and every remove (or probe failure) drops one; the la= st + * put frees the shared state via hsmp_acpi_sock_release(). All get/put run + * under hsmp_sock_rwsem held for write, so the counting is already serial= ized + * and the atomic in kref is not strictly needed; kref is used for the cle= arer + * get/put interface and its release callback. + */ +static struct kref hsmp_acpi_sock_kref; + struct hsmp_sys_attr { struct device_attribute dattr; u32 msg_id; @@ -611,6 +624,60 @@ static const struct acpi_device_id amd_hsmp_acpi_ids[]= =3D { }; MODULE_DEVICE_TABLE(acpi, amd_hsmp_acpi_ids); =20 +/* + * kref release: tear down the shared ACPI socket state once the last sock= et + * drops its reference. Deregister /dev/hsmp if it was registered, unmap a= ny + * metric-table DRAM, destroy the per-socket mutexes and free the socket a= rray. + * + * Runs from kref_put() with hsmp_sock_rwsem held for write, since the rem= ove + * and probe-failure paths both drop their reference under that lock. The = write + * lock has drained any in-flight hsmp_send_message(), so unmapping the ma= ilbox + * and freeing the array cannot race the data plane. + */ +static void hsmp_acpi_sock_release(struct kref *kref) +{ + lockdep_assert_held_write(&hsmp_sock_rwsem); + + if (!IS_ERR_OR_NULL(hsmp_pdev->mdev.this_device)) + hsmp_misc_deregister(); + hsmp_unmap_metric_tbls(hsmp_pdev); + hsmp_destroy_metric_read_locks(hsmp_pdev); + kfree(hsmp_pdev->sock); + hsmp_pdev->sock =3D NULL; + hsmp_pdev->num_sockets =3D 0; + hsmp_pdev->proto_ver =3D 0; +} + +/** + * hsmp_acpi_probe_failure_cleanup() - Undo a failed ACPI socket probe. + * @dev: ACPI companion device whose probe failed. + * + * This device already took a reference on entry to hsmp_acpi_probe(), so = clear + * its sock->dev and drop that reference; the shared state is released if = it was + * the last one. + * + * Clearing sock->dev matters on multi-socket systems: when a non-first so= cket + * fails, the array stays alive (owned by an already-probed socket) and + * remove() is never called for this device, yet devres unmaps its mailbox= once + * probe() returns. Without clearing dev, a later message to this index wo= uld + * pass every gate in hsmp_send_message() and reach the unmapped mailbox. + * + * sock is NULL if probe failed before hsmp_parse_acpi_table() set the drv= data. + * + * Called from hsmp_acpi_probe(), which already holds hsmp_sock_rwsem for = write. + */ +static void hsmp_acpi_probe_failure_cleanup(struct device *dev) +{ + struct hsmp_socket *sock =3D dev_get_drvdata(dev); + + lockdep_assert_held_write(&hsmp_sock_rwsem); + + if (sock) + sock->dev =3D NULL; + + kref_put(&hsmp_acpi_sock_kref, hsmp_acpi_sock_release); +} + static int hsmp_acpi_probe(struct platform_device *pdev) { int ret; @@ -620,43 +687,60 @@ static int hsmp_acpi_probe(struct platform_device *pd= ev) return -ENOMEM; =20 /* - * Multiple ACPI socket devices probe in parallel, but the is_probed - * handshake and the one-time socket-array allocation below must run - * exactly once. Serialize the whole bring-up against concurrent - * probe/remove by holding the socket rwsem for write. + * Multiple ACPI socket devices probe in parallel, but the one-time + * socket-array allocation and /dev/hsmp registration below must run + * exactly once. Hold the socket rwsem for write across the whole + * bring-up so it cannot race a concurrent probe or remove, and so the + * probe-failure teardown drains the data plane. */ guard(rwsem_write)(&hsmp_sock_rwsem); =20 - if (!hsmp_pdev->is_probed) { + if (!hsmp_pdev->sock) { hsmp_pdev->num_sockets =3D topology_max_packages(); if (!hsmp_pdev->num_sockets) { dev_err(&pdev->dev, "No CPU sockets detected\n"); return -ENODEV; } =20 - hsmp_pdev->sock =3D devm_kcalloc(&pdev->dev, hsmp_pdev->num_sockets, - sizeof(*hsmp_pdev->sock), - GFP_KERNEL); + hsmp_pdev->sock =3D kcalloc(hsmp_pdev->num_sockets, + sizeof(*hsmp_pdev->sock), + GFP_KERNEL); if (!hsmp_pdev->sock) return -ENOMEM; =20 hsmp_init_metric_read_locks(hsmp_pdev); + kref_init(&hsmp_acpi_sock_kref); + } else { + kref_get(&hsmp_acpi_sock_kref); } =20 + /* + * This socket now holds a reference (kref_init on the first socket, + * kref_get afterwards). Every failure path below drops it via + * hsmp_acpi_probe_failure_cleanup(), and a successful probe hands it to + * hsmp_acpi_remove(). + */ ret =3D init_acpi(&pdev->dev); if (ret) { dev_err(&pdev->dev, "Failed to initialize HSMP interface.\n"); + hsmp_acpi_probe_failure_cleanup(&pdev->dev); return ret; } =20 - if (!hsmp_pdev->is_probed) { - ret =3D hsmp_misc_register(&pdev->dev); + if (IS_ERR_OR_NULL(hsmp_pdev->mdev.this_device)) { + /* + * Register /dev/hsmp unparented. It is a singleton shared by all + * ACPI sockets and outlives all but the last of them, so + * parenting it to this socket's device would leave a dangling + * parent once that socket is unbound. + */ + ret =3D hsmp_misc_register(NULL); if (ret) { dev_err(&pdev->dev, "Failed to register misc device\n"); + hsmp_acpi_probe_failure_cleanup(&pdev->dev); return ret; } - hsmp_pdev->is_probed =3D true; - dev_dbg(&pdev->dev, "AMD HSMP ACPI is probed successfully\n"); + dev_dbg(&pdev->dev, "AMD HSMP ACPI misc device registered\n"); } =20 return 0; @@ -664,17 +748,26 @@ static int hsmp_acpi_probe(struct platform_device *pd= ev) =20 static void hsmp_acpi_remove(struct platform_device *pdev) { + struct hsmp_socket *sock =3D dev_get_drvdata(&pdev->dev); + + /* + * Serialize the kref_put() and any release it triggers against a + * concurrent probe, and drain the data plane for the whole + * teardown: this covers the per-socket unbind, whose mailbox devres + * unmaps once we return, and the last unbind that frees the socket + * array in hsmp_acpi_sock_release(). + */ guard(rwsem_write)(&hsmp_sock_rwsem); =20 /* - * We register only one misc_device even on multi-socket system. - * So, deregister should happen only once. + * Clear this socket's dev so hsmp_send_message() rejects it before + * devres unmaps the mailbox. On a non-final unbind the socket array + * stays alive, so without this a later message to this index would + * reach an unmapped iomem region. */ - if (hsmp_pdev->is_probed) { - hsmp_misc_deregister(); - hsmp_destroy_metric_read_locks(hsmp_pdev); - hsmp_pdev->is_probed =3D false; - } + sock->dev =3D NULL; + + kref_put(&hsmp_acpi_sock_kref, hsmp_acpi_sock_release); } =20 static struct platform_driver amd_hsmp_driver =3D { diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/am= d/hsmp/hsmp.c index 584fd9b1d31f..967307abe641 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.c +++ b/drivers/platform/x86/amd/hsmp/hsmp.c @@ -491,6 +491,18 @@ int hsmp_get_tbl_dram_base(u16 sock_ind) dev_err(sock->dev, "Invalid DRAM address for metric table\n"); return -ENOMEM; } + /* + * The ACPI socket array is shared across sockets and outlives a + * per-socket unbind, so metric_tbl_addr may hold a mapping from an + * earlier bind of this socket. Unmap it before remapping so an + * unbind/rebind cycle does not leak a metric-table mapping. This runs + * during probe before the metric sysfs attribute is exposed, so no + * reader can be using it. + */ + if (sock->metric_tbl_addr) { + iounmap(sock->metric_tbl_addr); + sock->metric_tbl_addr =3D NULL; + } sock->metric_tbl_addr =3D ioremap(dram_addr, sizeof(struct hsmp_metric_ta= ble)); if (!sock->metric_tbl_addr) { dev_err(sock->dev, "Failed to ioremap metric table addr\n"); @@ -528,6 +540,14 @@ int hsmp_misc_register(struct device *dev) hsmp_pdev.mdev.name =3D HSMP_CDEV_NAME; hsmp_pdev.mdev.minor =3D MISC_DYNAMIC_MINOR; hsmp_pdev.mdev.fops =3D &hsmp_fops; + /* + * The caller chooses the parent. The platform driver has a single + * device whose lifetime matches /dev/hsmp and parents it there. The + * ACPI driver passes NULL: its /dev/hsmp is a singleton shared by + * per-socket devices that can be unbound individually and out of order, + * so parenting it to one would leave it attached to an already-removed + * device. + */ hsmp_pdev.mdev.parent =3D dev; hsmp_pdev.mdev.nodename =3D HSMP_DEVNODE_NAME; hsmp_pdev.mdev.mode =3D 0644; diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/am= d/hsmp/hsmp.h index ec92c2a429bb..45dab9253c13 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.h +++ b/drivers/platform/x86/amd/hsmp/hsmp.h @@ -58,7 +58,6 @@ struct hsmp_plat_device { struct hsmp_socket *sock; u32 proto_ver; u16 num_sockets; - bool is_probed; }; =20 int hsmp_cache_proto_ver(u16 sock_ind); --=20 2.34.1 From nobody Fri Jul 24 21:53:11 2026 Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010032.outbound.protection.outlook.com [52.101.193.32]) (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 BB816432BD6; Thu, 23 Jul 2026 09:47:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.193.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784800054; cv=fail; b=Wyvf1wd/kL0QsA4TOeWfjFhRPYZqxR0NAXAw0D25kN62F6yT2obWImOVDT0GGBsXJz835gjrBjTnT6Q5qccGv/8bT7+dMJc/MGoLwkerUhILuwpd0NVzhL2FwojEImP4jiO2CTYAnzfybG4DJeO0uMtFL4hqRkWufKlLm4siIm0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784800054; c=relaxed/simple; bh=WB9orJ7o28uPSqNu9CE5feUdfv0mroTsZhVrzPpCGZA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s6DSJpWfd9B1hWBwMTWYfWn4om7QMGfPh4CJ4IRn+NDjpYY/C6tCzBqz7wrb5coRCou413RE0L07gbMFFTKTYFi2ZLHzuQrJqIgGuARXx6I8oQxNdo1QWM7/pnlJGb9bfbSJ9UfUYPStmdWd+qJm+6yqHy6hG6N7TkxvdaiaUek= 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=wBoFNf4q; arc=fail smtp.client-ip=52.101.193.32 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="wBoFNf4q" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DXnqJwAOO/VbMENSZ/UrA8u1aZ/QVolD7eIpSZlc9mn8G6A6KxWaBPo00OwI19Qxi2arKPrUtH11DXia8VIaEoblUTaQazEU68zyHi4TlkZC//73euR8hMKh+yQjDVAB8yoUWhxcjxpGwno7+sA6EVgZSLIUg4ODaCtz+XJprI6zRxnSBxZQ7RyLUtblQNkWk/MgtLW4o1yF9HlhGPcEWUvf1rm3cWXPqoV2SUEI89yCrKMx4n/XcWDQW/KFHEs7aOeHvWT4Rl1w38DbLB+RS9tAvqryjARhfiaqvvKKdSP9eiJBO5I6a5vyj4UN1YvBhm/rwjsVEqpr+yLxYE1MhQ== 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=71yqArRKSUu4XQ6cGz+RPYr55A2eFv2P/zNoEWybxKw=; b=vOqo4Kr2QuuSfeN4/Zbe7ry87q1ZdWuGbSD1qTBf6pT+6cC9vpnF19rARFvfjzqvQ+CkezVxVR4W1eo8DwENiPgvYjSy0mit2JWnEblkia/dvDm4+OwXXHSVkDPkMKjiNvSQ4IaJLjd7EhTALBKguo5Sxg2iqk2HTRZnpi5DvHLhlFVOZdV1A2VRNUChG+odXAL+0BwffD751qEEDUN7OUl2ixQ3vJeDaiJK4j+0N+/KFgha6YTpdx1r9rWBts72VBDFW7uJt1NEdilVB3k058MCBUWiWxkflw8cWEp0idzl692rsrOr5zCGDOFRZj8ViqwVTzJU/S7BlXSnhJmllQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=71yqArRKSUu4XQ6cGz+RPYr55A2eFv2P/zNoEWybxKw=; b=wBoFNf4qq0PzPd9S9+6Go/JAdKyW/mVRrRjgn6F9OwHDUprP57m2ZL5jrCX6lbJMly/TM/63uVfDV1rf82K+skNvYC3sUxWAolU4SjX+CyZgvHDlQEFHrsnfZPEmnmJUmot0d30rDwVXMTakybZ4aa7jL33//RB9FZlnswOvfQo= Received: from SA1P222CA0016.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:22c::8) by DSWPR12MB999130.namprd12.prod.outlook.com (2603:10b6:8:36d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.10; Thu, 23 Jul 2026 09:47:26 +0000 Received: from SN1PEPF00036F42.namprd05.prod.outlook.com (2603:10b6:806:22c:cafe::14) by SA1P222CA0016.outlook.office365.com (2603:10b6:806:22c::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.245.10 via Frontend Transport; Thu, 23 Jul 2026 09:47:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SN1PEPF00036F42.mail.protection.outlook.com (10.167.248.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.5 via Frontend Transport; Thu, 23 Jul 2026 09:47:25 +0000 Received: from dcsm-trdripper1.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Thu, 23 Jul 2026 04:47:23 -0500 From: Muralidhara M K To: CC: , , , Muralidhara M K Subject: [PATCH v7 6/6] platform/x86/amd/hsmp: Serialize the data plane against socket teardown Date: Thu, 23 Jul 2026 15:16:56 +0530 Message-ID: <20260723094656.3806028-7-muralidhara.mk@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260723094656.3806028-1-muralidhara.mk@amd.com> References: <20260723094656.3806028-1-muralidhara.mk@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F42:EE_|DSWPR12MB999130:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e6caa13-9fc1-476b-c075-08dee89f66e3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|23010399003|1800799024|376014|36860700016|56012099006|10067099003|5023799004|11063799006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: /KTtzslQIrcpQZu8tCVBaU5EL0B6qU5itqjP9zeec34Mrz1znskdqP/wZ9i+ejD7JCKFAHXYk5ieB+PJsDsjtZEqnbDcSxsEgRDJxZS3Km7r5WAp+yvaM4Da/PZcvqpEBnSz+5PqfMur7hLiZnm4eZVSEwplpbpedrh9PcOUVc4ZyJNSXwZjgx1D1Fo7r9eFRve3shb1zoeVfpU101Tc/sBEpUvLGRq/JWwlUjNMgEFCq6P67/WCH5Im6AyD3pgCxPWrtkeAgInfILei5jER+jwxKzR/A2b2CbBEY13LbQSDxFyKaVqwZDvfeJg0LscaoRQy/dfdw3OdTaZYSgqfqMUj0FIcP6h35AM/llAiN5M5xq7jDHCLDY/aZ4IiHb3FPr5lXWHi2LWZ30MjIiSlZnrdW+BD+p9MPW3V2UVaE2O6cXS9fJTvSyb+bEeph2OX0Z0dsB1LXZ8ap+Ywo5J97WE9DprufR46XsFoAKHgw5f10/qOh6WikwRJqWiz4okmgI7ZA8OwpGrVnqTd/bXf8g435tof7FAEeIbnEntGSfKwKuEzPg78GVr2fGkZVXYCKU/elszeExuBdAnwhyIwn9pPjXDyjA8g5c9r+24mPaEQAI5PbBLlapD/0iWYH9MQBN7nkFKFxhCKgumJvx/lCUJIUBwNlkQ7OoCO6R3gijA6SzhSTpF7lQNMfsmZQwGZ/WH4Nqe+BL2dh0Nrzq4Y9A== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(23010399003)(1800799024)(376014)(36860700016)(56012099006)(10067099003)(5023799004)(11063799006)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kGpKFsHDiTlVsmkIPiVZUqygMAMSFCdKkx2nPJaehxA5ogf6AkyC9R/rhD7yD+FvIV7zhYR0DWDP4jW7vFGRPi+cZuupnarB4bSW6EGuh2zocYuBQRETQT8jhSei1qlgJKTI2KA42vlCD3MxByO1yTPUDnvGJNasnONauW6v03z+WPewif59p1ZH3qog+MT/WTWRHfAdi+z+Ok5Ool/tkcIKAOojmRtL3ScMvAZWCUeHIDu+D/ZwKcMg228EaGgRw0rLyb5+FnzOMkOgQdwH6f2iPF5nEGgH0EQbqou7etlh09+DVpJMsVeYL/ABSEWAznSwPaPYi20ITpS0h0h2XLf8JmNZHnN/6tC8Ncp/yvxraKH9TzZCR2M9VeLwyqqvEgJFzLjXw6q0Sd9XRJ0SWYndVyQOZTZxcvrLfWnT3CGzXe7k06oprAyutxWqd5he X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jul 2026 09:47:25.6193 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3e6caa13-9fc1-476b-c075-08dee89f66e3 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F42.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DSWPR12MB999130 Content-Type: text/plain; charset="utf-8" Before this change the HSMP data plane runs without any coordination with driver teardown: open /dev/hsmp fds and hwmon sysfs reads call hsmp_send_message() while probe and remove bring sockets up and down. misc_deregister() does not drain already-open fds, so an in-flight message can race a concurrent unbind and touch a freed socket array or an unmapped mailbox. Add the read side of hsmp_sock_rwsem to the data plane. Split the message send into hsmp_send_message_locked(), which does the bounds check and MMIO access and asserts the rwsem is held, and hsmp_send_message(), which wraps it in guard(rwsem_read). Probe and remove hold the rwsem for write, so they drain in-flight messages and keep new ones out while they tear a socket down. The probe-time senders run under the probe write lock and so must not take the rwsem again: route hsmp_test(), hsmp_cache_proto_ver() and hsmp_get_tbl_dram_base() through hsmp_send_message_locked() to avoid recursive locking. A single rwsem therefore covers both the data plane and the probe/remove handshake, with no separate probe lock: - acpi.c already holds it for write across probe for the socket-array and misc-registration handshake, so the mailbox handshake now nests under that same lock. - plat.c takes it for write around init_platform_device(). It is not held across devm_add_action_or_reset() so the release action, which also takes it for write, cannot deadlock if that registration fails. Signed-off-by: Muralidhara M K --- drivers/platform/x86/amd/hsmp/hsmp.c | 41 ++++++++++++++++++++++------ drivers/platform/x86/amd/hsmp/hsmp.h | 4 +-- drivers/platform/x86/amd/hsmp/plat.c | 24 +++++++++++++--- 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/am= d/hsmp/hsmp.c index 967307abe641..a457831c9c6b 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.c +++ b/drivers/platform/x86/amd/hsmp/hsmp.c @@ -45,9 +45,12 @@ static struct hsmp_plat_device hsmp_pdev; =20 /* - * Serializes AMD HSMP socket bring-up and teardown: ACPI probe and remove= take - * it for write so concurrent per-socket probes cannot race the is_probed - * handshake or the one-time socket-array allocation. + * Gates the AMD HSMP data plane against socket bring-up and teardown. + * + * hsmp_send_message() takes it for read, so open /dev/hsmp fds and hwmon = reads + * run concurrently. Probe and remove take it for write: probe brings sock= ets + * up (running the mailbox handshake via hsmp_send_message_locked()) and r= emove + * tears them down, both excluding and draining the data plane. */ DECLARE_RWSEM(hsmp_sock_rwsem); EXPORT_SYMBOL_NS_GPL(hsmp_sock_rwsem, "AMD_HSMP"); @@ -211,12 +214,20 @@ static int validate_message(struct hsmp_message *msg) return 0; } =20 -int hsmp_send_message(struct hsmp_message *msg) +/* + * Core message send. The caller must hold hsmp_sock_rwsem: the data plane + * takes it for read so many messages run concurrently, while the probe-ti= me + * senders run under the write lock taken by probe. Holding it here serial= izes + * every message against socket teardown, which also holds it for write. + */ +static int hsmp_send_message_locked(struct hsmp_message *msg) { struct hsmp_socket *sock; unsigned int sock_ind; int ret; =20 + lockdep_assert_held(&hsmp_sock_rwsem); + if (!msg) return -EINVAL; ret =3D validate_message(msg); @@ -243,7 +254,8 @@ int hsmp_send_message(struct hsmp_message *msg) * non-NULL dev also guarantees virt_base_addr, the mailbox offsets and * the semaphore are visible. * - * Pairs with smp_store_release(&sock->dev) in hsmp_parse_acpi_table(). + * Held under hsmp_sock_rwsem; pairs with smp_store_release(&sock->dev) + * in hsmp_parse_acpi_table(). */ if (!smp_load_acquire(&sock->dev)) return -ENODEV; @@ -258,6 +270,19 @@ int hsmp_send_message(struct hsmp_message *msg) =20 return ret; } + +int hsmp_send_message(struct hsmp_message *msg) +{ + /* + * Data-plane entry point: open /dev/hsmp fds and hwmon sysfs reads issue + * messages from here. Take hsmp_sock_rwsem for read so messages run + * concurrently with each other but are drained and kept out while + * probe/remove hold it for write to tear a socket down. + */ + guard(rwsem_read)(&hsmp_sock_rwsem); + + return hsmp_send_message_locked(msg); +} EXPORT_SYMBOL_NS_GPL(hsmp_send_message, "AMD_HSMP"); =20 int hsmp_msg_get_nargs(u16 sock_ind, u32 msg_id, u32 *data, u8 num_args) @@ -298,7 +323,7 @@ int hsmp_test(u16 sock_ind, u32 value) msg.args[0] =3D value; msg.sock_ind =3D sock_ind; =20 - ret =3D hsmp_send_message(&msg); + ret =3D hsmp_send_message_locked(&msg); if (ret) return ret; =20 @@ -478,7 +503,7 @@ int hsmp_get_tbl_dram_base(u16 sock_ind) msg.response_sz =3D hsmp_msg_desc_table[HSMP_GET_METRIC_TABLE_DRAM_ADDR].= response_sz; msg.msg_id =3D HSMP_GET_METRIC_TABLE_DRAM_ADDR; =20 - ret =3D hsmp_send_message(&msg); + ret =3D hsmp_send_message_locked(&msg); if (ret) return ret; =20 @@ -521,7 +546,7 @@ int hsmp_cache_proto_ver(u16 sock_ind) msg.sock_ind =3D sock_ind; msg.response_sz =3D hsmp_msg_desc_table[HSMP_GET_PROTO_VER].response_sz; =20 - ret =3D hsmp_send_message(&msg); + ret =3D hsmp_send_message_locked(&msg); if (!ret) hsmp_pdev.proto_ver =3D msg.args[0]; =20 diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/am= d/hsmp/hsmp.h index 45dab9253c13..cfd1a8cbd459 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.h +++ b/drivers/platform/x86/amd/hsmp/hsmp.h @@ -79,8 +79,8 @@ static inline int hsmp_create_sensor(struct device *dev, = u16 sock_ind) { return int hsmp_msg_get_nargs(u16 sock_ind, u32 msg_id, u32 *data, u8 num_args); =20 /* - * Serializes HSMP socket bring-up and teardown. ACPI probe and remove tak= e it - * for write. + * Gates the HSMP data plane: hsmp_send_message() takes it for read; probe= and + * remove take it for write to bring sockets up and tear them down. */ extern struct rw_semaphore hsmp_sock_rwsem; #endif /* HSMP_H */ diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/am= d/hsmp/plat.c index 7a16d1ab463b..e9b2b809c0f5 100644 --- a/drivers/platform/x86/amd/hsmp/plat.c +++ b/drivers/platform/x86/amd/hsmp/plat.c @@ -13,12 +13,14 @@ =20 #include #include +#include #include #include #include #include #include #include +#include #include =20 #include @@ -204,15 +206,20 @@ static int init_platform_device(struct device *dev) /* * The socket array is devm-managed and freed by the driver core, but the * metric-table DRAM regions are mapped with plain ioremap() during probe = and - * are therefore not covered by devres. + * the per-socket mutexes need an explicit mutex_destroy(), neither of whi= ch + * devres covers. * - * Drop those mappings from a devres action so both remove and probe failu= re - * unmap them exactly once, before the socket array they refer to is freed. + * Take the data-plane rwsem for write to drain any in-flight + * hsmp_send_message(), unmap the metric tables, destroy the mutexes and d= rop + * the global socket pointer, all before devres frees the array. Registere= d as + * a devres action so it runs on both remove and probe failure. */ static void hsmp_pltdrv_release(void *data) { + guard(rwsem_write)(&hsmp_sock_rwsem); hsmp_unmap_metric_tbls(hsmp_pdev); hsmp_destroy_metric_read_locks(hsmp_pdev); + hsmp_pdev->sock =3D NULL; } =20 static int hsmp_pltdrv_probe(struct platform_device *pdev) @@ -231,7 +238,16 @@ static int hsmp_pltdrv_probe(struct platform_device *p= dev) if (ret) return ret; =20 - ret =3D init_platform_device(&pdev->dev); + /* + * init_platform_device() runs the mailbox handshake via the probe-only + * senders, which issue messages through hsmp_send_message_locked() and + * so require hsmp_sock_rwsem held. Hold it for write, matching probe's + * role as a socket bring-up path. The lock is not held across + * devm_add_action_or_reset() above so the release action, which also + * takes it for write, does not deadlock if that registration fails. + */ + scoped_guard(rwsem_write, &hsmp_sock_rwsem) + ret =3D init_platform_device(&pdev->dev); if (ret) { dev_err(&pdev->dev, "Failed to init HSMP mailbox\n"); return ret; --=20 2.34.1