From nobody Mon Jun 8 15:38:03 2026 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011037.outbound.protection.outlook.com [52.101.52.37]) (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 86AC93AFCEF; Thu, 28 May 2026 09:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.37 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779961228; cv=fail; b=bg3py+l590GCadAGU/0RfVOK5z6US7kVzUWiIo1ACUMNSX8UUXSBUPJTS350HXFXedvBj6LY/Gq+3owbSH++fBpSox1XjqBFFgVR/yCQJ4pqqzHCsAOzOi0CE0Z6o2X13NFZGYuMMmyvVgYGGckDa865Z7IG3PcEhHgiYTKO5Rw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779961228; c=relaxed/simple; bh=QLCoUOeoO4IOfsxpuppmcylEdQUn+rL1J5MIzFs1Irs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pX+2sYWI627dHHQc6cXQX2HF75e3QRNYLCu0PzXH3Z2/UxMtfRu/IQyfeo9ltk2scb/MrOD5GWJBYCTN5PTr8jXkZxCKTPU2qB2c0v+Xads4+zF6XsoV3qmd5CII46nBC1tDnUBY9eT74j3Ka8rkHj9LY53jGEdhV1ftvy9/9dU= 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=QA1u1ysX; arc=fail smtp.client-ip=52.101.52.37 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="QA1u1ysX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MWdGL/pSnHuLN+i+osB06MhK37EXVitZ2PIROXY298Gq00HEqZjO2PydKVmwzuWC+//Os6ur1jPss9MCB332KNKijdWuB/BD9BVSCgZsd0ixhbgHlLForzT+SBBuRn7+vt9ut5Y/Qi8Ner9ThYIe1c3N9NmEPpE5B5VTQCmq0RRn0YtSGnT8RY+UhgAuQhNlclpD0PL1aOVYQyKxu/JzHL+gl2TZpzH0sVFFi6TFD2wb3SuH4Dwu1xHmz5Xzz9TP7iE2mNR7iLl/L77Ktwnaz98SXTeyKFzj2hKY/VlGIspv/thxJbgICIhanY4cMp8q7PunXTgssgJkfYJwhXXH/w== 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=onbJ7V2tHOpfrmP1pdceaQ1tKe3JtGbJuC2RTmRybG0=; b=LttcJOieKRYb3/56XmvBMtV9Z5sDCsDnAKN/krZfBL0sGwlx1Nxc9bQKWkKYnVPBmRd3oNaxFJA6gC+HZ0D2XGQD4ZTX7iNjjmxDNV3SLAzQNVtg1gcVsBMnnHO0fVyObsCgcF3COi6jU/c8KI5RVy+dhnkE3NcwuzQmW6w7R+nrbyD+ukr90SLbN/7c8Kig6cKQiS3niQLj4SCz85PYRYHM5tnu4NIspzvMqpcHxM+gCof7wtSrBd9j65Fvm7tT/u/DrNyHAJ56F7ryEkOpoQ4sMQ31kW0K/RTWNLQLV7F/1hsXur6C2k2oIx5ZUz93wjMt8O8H0citEReBcHisYw== 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=onbJ7V2tHOpfrmP1pdceaQ1tKe3JtGbJuC2RTmRybG0=; b=QA1u1ysXum4ouiuq7PdaFFo1P8pQh+emY3FQSBMFfzjHitItX7EiDpNtsU6DPrZCNMw8TBCEc6svqGoPAmEisctLMdZy9juZA8Pw5FEbZwgPkaDhC1uH0juJOAqucYVbZC4Qt61kPaf0Bw0T9Ol6vVdoPsVCLuK2n4BaYBtyidw= Received: from CH0PR03CA0268.namprd03.prod.outlook.com (2603:10b6:610:e5::33) by DM4PR12MB6253.namprd12.prod.outlook.com (2603:10b6:8:a6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.13; Thu, 28 May 2026 09:40:18 +0000 Received: from CH1PEPF0000AD83.namprd04.prod.outlook.com (2603:10b6:610:e5:cafe::94) by CH0PR03CA0268.outlook.office365.com (2603:10b6:610:e5::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.71.13 via Frontend Transport; Thu, 28 May 2026 09:40:18 +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 CH1PEPF0000AD83.mail.protection.outlook.com (10.167.244.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Thu, 28 May 2026 09:40: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, 28 May 2026 04:40:15 -0500 From: Muralidhara M K To: CC: , , Suma Hegde , Muthusamy Ramalingam , Muralidhara M K Subject: [PATCH v4 1/7] platform/x86/amd/hsmp: Add new HSMP messages for Family 1Ah, Model 50h-5Fh Date: Thu, 28 May 2026 15:09:48 +0530 Message-ID: <20260528093954.2461272-2-muralidhara.mk@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260528093954.2461272-1-muralidhara.mk@amd.com> References: <20260528093954.2461272-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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD83:EE_|DM4PR12MB6253:EE_ X-MS-Office365-Filtering-Correlation-Id: 5312a634-3803-4e74-0bb9-08debc9d2086 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700016|1800799024|22082099003|18002099003|6133799003|56012099006|3023799007|11063799006; X-Microsoft-Antispam-Message-Info: DOUDeFiUo/rA4qDcimJkDmAI0fOGsUQJIsB6/ISbeqO+Du7Yc1WulF6jzMAROHmfZdawhUSEdEGIay5Kp5vrO0Di1pquQ1NuIEQXNa6efeF/Ji0H9Vaa2wP6yJsVzu8uJ822URCYpQC/gYZA7nXr01f5IXfZ5HRZvXfHM+CA7ithVGDmjLRbMEUxkt32fo5MDZJOsyDSuIO3PZnO276ps3nMGzQdmg9kEp9ZYLN0uru6nfQavd9ShfQpzsOGJq38FwLbY5MpfRVvxs9/eVDQmLDhNLr9FfLPvQt+BPWqIFbIPW+HTbvgQ4iXweWyismR9HDzgeXqT7tkIOOGvYL2R5/FsYB0AaauYyB2ZRgdvTdQjjLvN1wZ/bzKoOroFfU8CW/idt7GFifimdPuz7Q2/JN9ud9Dn2qfOR9TOn+CJpearTSH4CO5iTvpRfGYb59nn3GGrmvRIc5OiiUsKY9oPPy0RY7lYd84Tv2KS0AHWSadxWIpmyMZVdsR2NRgwgW71KRvOTAWZyJhRdKFj/KFGEuLgivTqXrc0ewTpaUBJiHlPz2LCh3N6V0tOYpsrX+1gQ+fY0u60YOwnCABoKYGJP7QiYv+c1ux/w52vWZAh+SyeLZ3J+0x9qmL9ri2nZJsBXJZFoigBnLOOELcD3MZgnwkOMSkksPaF777cGqZzeEP6JLLpsYISLIaj4amNYg2KciA/Jr8welWm2kAOXk8A7FvgkZNtnwmY/a06ujUxqo= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(82310400026)(36860700016)(1800799024)(22082099003)(18002099003)(6133799003)(56012099006)(3023799007)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gxaAXGGJtu856cxeFcWgk5Ug5aoSr3stSWl1eZy04mhGe6tOmxLkpHtbW4WCKE1zWguVANfTAP7bB/pun8AgNNj4999xWDsZpgGFHvJfuXYwTQcWDAvxO6d0I8eWds9U/6uAjetp0BOEszb9NfAVXTiHqSBVcoZv0Ed6NMTyCLqD0BkF+7ucRoPicuqqH4JSamwMOqVZt+u026kHExoT3GQ78Lmk6p4aUeW2cQNTVqerB7XA35mtNRNntm51o/POlJrSO6/OMye0E/sGnsDHaszqhsLtAFD2oWIYcEpVYhQ4DFDysZqz6pVMYQX9jg0GaVDqE51XHjt2o1yWcJIuen53RFjIei2e2ocw2HPCPkNr2nqNVaRv2rG21deE941C1kWTEa9WoLGT/663yrTQ5ql8JsX6ApqrjrEPaMUjuuqO7FFuOuRc0EB/k5hExHe1 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2026 09:40:17.4401 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5312a634-3803-4e74-0bb9-08debc9d2086 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: CH1PEPF0000AD83.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6253 Content-Type: text/plain; charset="utf-8" From: Suma Hegde Family 1Ah Model 50h-5Fh firmware exposes new HSMP messages (0x29-0x2A, 0x33-0x3A) for PC6/CC6 control, CCD power/thermal monitoring, DIMM sideband access, floor- and SDPS-limit control, and command-enable discovery. The driver currently marks those IDs as HSMP_RSVD and validate_message() rejects them with -ENOMSG, so userspace has no way to reach the new functionality. The same firmware also extends three existing SET-only messages (HSMP_SET_XGMI_LINK_WIDTH 0x0C, HSMP_SET_DF_PSTATE 0x0D, HSMP_SET_PSTATE_MAX_MIN 0x22) with a read-back path selected by bit[31] of args[0] (0 =3D set, 1 =3D get). Without converting these entries to HSMP_SET_GET, userspace cannot query the currently programmed value even though firmware now supports it. Add the new IDs, convert the three messages to HSMP_SET_GET, and bump the driver version to 2.6. Backward compatibility is preserved on prior platforms: - The new IDs previously occupied HSMP_RSVD slots and were rejected with -ENOMSG, so no existing caller could have been issuing them. - Existing userspace that leaves bit[31] =3D 0 continues to take a pure SET path (is_get_msg() returns false); the lax upper-bound validation already used for HSMP_SET_GET accepts the historical response_sz =3D 0 callers unchanged. - A new-userspace build that issues a GET against older firmware fails cleanly with a firmware error, because that firmware rejects the non-zero Reserved bit it now sees in bit[31]. Reviewed-by: Suma Hegde Co-developed-by: Muthusamy Ramalingam Signed-off-by: Muthusamy Ramalingam Signed-off-by: Muralidhara M K --- arch/x86/include/uapi/asm/amd_hsmp.h | 153 ++++++++++++++++++++++++--- drivers/platform/x86/amd/hsmp/hsmp.h | 2 +- 2 files changed, 140 insertions(+), 15 deletions(-) diff --git a/arch/x86/include/uapi/asm/amd_hsmp.h b/arch/x86/include/uapi/a= sm/amd_hsmp.h index 92d8f256d096..52e53ec5877f 100644 --- a/arch/x86/include/uapi/asm/amd_hsmp.h +++ b/arch/x86/include/uapi/asm/amd_hsmp.h @@ -53,9 +53,19 @@ enum hsmp_message_ids { HSMP_SET_XGMI_PSTATE_RANGE, /* 26h Set xGMI P-state range */ HSMP_CPU_RAIL_ISO_FREQ_POLICY, /* 27h Get/Set Cpu Iso frequency policy */ HSMP_DFC_ENABLE_CTRL, /* 28h Enable/Disable DF C-state */ + HSMP_PC6_ENABLE, /* 29h Get/Set PC6 enable/disable status */ + HSMP_CC6_ENABLE, /* 2Ah Get/Set CC6 enable/disable status */ HSMP_GET_RAPL_UNITS =3D 0x30, /* 30h Get scaling factor for energy */ HSMP_GET_RAPL_CORE_COUNTER, /* 31h Get core energy counter value */ HSMP_GET_RAPL_PACKAGE_COUNTER, /* 32h Get package energy counter value */ + HSMP_DIMM_SB_RD, /* 33h Get DIMM sideband data */ + HSMP_READ_CCD_POWER, /* 34h Get average CCD power */ + HSMP_READ_TDELTA, /* 35h Get thermal behaviour */ + HSMP_GET_SVI3_VR_CTRL_TEMP, /* 36h Get SVI3 VR controller rail temp */ + HSMP_GET_ENABLED_HSMP_CMDS, /* 37h Get supported HSMP commands */ + HSMP_SET_GET_FLOOR_LIMIT, /* 38h Get/Set core floor frequency limit */ + HSMP_DIMM_SB_WR, /* 39h Set DIMM sideband data */ + HSMP_SDPS_LIMIT, /* 3Ah Get/Set SDPS limit */ HSMP_MSG_ID_MAX, }; =20 @@ -170,16 +180,27 @@ static const struct hsmp_msg_desc hsmp_msg_desc_table= [] {0, 1, HSMP_GET}, =20 /* - * HSMP_SET_XGMI_LINK_WIDTH, num_args =3D 1, response_sz =3D 0 - * input: args[0] =3D min link width[15:8] + max link width[7:0] + * HSMP_SET_XGMI_LINK_WIDTH, num_args =3D 1, response_sz =3D 0/1 + * input: args[0] =3D set/get XGMI Link width[31] (0 =3D set, 1 =3D get) + + * min link width[15:8] + max link width[7:0] + * Link width encoding: 0 =3D x4, 1 =3D x8, 2 =3D x16. + * On SET, max must be >=3D min. On GET, [15:0] are reserved. + * output: args[0] =3D reserved[31:16] + min link width[15:8] + + * max link width[7:0] */ - {1, 0, HSMP_SET}, + {1, 1, HSMP_SET_GET}, =20 /* - * HSMP_SET_DF_PSTATE, num_args =3D 1, response_sz =3D 0 - * input: args[0] =3D df pstate[7:0] + * HSMP_SET_DF_PSTATE (APBDisable), num_args =3D 1, response_sz =3D 0/1 + * input: args[0] =3D set APB_DISABLE / get APB state[31] + * (0 =3D set & lock DF P-state, 1 =3D get) + + * reserved[30:8] + + * DF P-state[7:0] (0..2; reserved on GET) + * output: args[0] =3D reserved[31:9] + + * APB state[8] (1 =3D disabled, 0 =3D enabled) + + * locked DF P-state[7:0] if [8] =3D 1, else reserved */ - {1, 0, HSMP_SET}, + {1, 1, HSMP_SET_GET}, =20 /* HSMP_SET_AUTO_DF_PSTATE, num_args =3D 0, response_sz =3D 0 */ {0, 0, HSMP_SET}, @@ -305,16 +326,32 @@ static const struct hsmp_msg_desc hsmp_msg_desc_table= [] {1, 1, HSMP_SET}, =20 /* - * HSMP_SET_POWER_MODE, num_args =3D 1, response_sz =3D 0 - * input: args[0] =3D power efficiency mode[2:0] + * HSMP_SET_POWER_MODE (PwrEfficiencyModeSelection), + * num_args =3D 1, response_sz =3D 1 + * input: args[0] =3D set/get policy[31] (0 =3D set, 1 =3D get) + + * high util point[30:24] + + * low util point[23:17] + + * PPT limit[16:5] + + * reserved[4:3] + mode selection[2:0] + * [30:5] are valid only when [2:0] is a balanced core mode + * (4 or 5). [2:0] is reserved when getting (bit[31] =3D 1). + * output: args[0] same layout, [31] reserved, [2:0] =3D arbitrated + * current efficiency mode. */ {1, 1, HSMP_SET_GET}, =20 /* - * HSMP_SET_PSTATE_MAX_MIN, num_args =3D 1, response_sz =3D 0 - * input: args[0] =3D min df pstate[15:8] + max df pstate[7:0] + * HSMP_SET_PSTATE_MAX_MIN (DfPstateRange), num_args =3D 1, response_sz = =3D 0/1 + * input: args[0] =3D set/get DF P-state range[31] (0 =3D set, 1 =3D get)= + + * reserved[30:16] + + * min DF P-state[15:8] + max DF P-state[7:0] + * DF P-state encoding: 0 =3D DFP0 (high performance), + * 1 =3D DFP1, 2 =3D DFP2 (low performance). + * [15:0] are reserved when getting (args[0] bit[31] =3D 1). + * output: args[0] =3D reserved[31:16] + min DF P-state[15:8] + + * max DF P-state[7:0] */ - {1, 0, HSMP_SET}, + {1, 1, HSMP_SET_GET}, =20 /* * HSMP_GET_METRIC_TABLE_VER, num_args =3D 0, response_sz =3D 1 @@ -355,9 +392,31 @@ static const struct hsmp_msg_desc hsmp_msg_desc_table[] */ {1, 1, HSMP_SET_GET}, =20 - /* RESERVED(0x29-0x2f) */ - {0, 0, HSMP_RSVD}, - {0, 0, HSMP_RSVD}, + /* + * HSMP_PC6_ENABLE (Pc6Enable), num_args =3D 1, response_sz =3D 0/1 + * input: args[0] =3D set/get PC6 control[31] (0 =3D set, 1 =3D get) + + * reserved[30:1] + + * enable PC6[0] (0 =3D disable, 1 =3D enable; + * reserved on GET) + * output: args[0] =3D reserved[31:1] + current PC6 control[0] + * (last value configured via HSMP or APML) + */ + {1, 1, HSMP_SET_GET}, + + /* + * HSMP_CC6_ENABLE (CC6Enable), num_args =3D 1, response_sz =3D 0/1 + * Configures CC6 enable for all cores; changing the setting does + * not by itself transition cores in or out of CC6. + * input: args[0] =3D set/get CC6 control[31] (0 =3D set, 1 =3D get) + + * reserved[30:1] + + * enable CC6[0] (0 =3D disable, 1 =3D enable; + * reserved on GET) + * output: args[0] =3D reserved[31:1] + current CC6 control[0] + * (last value configured via HSMP or APML) + */ + {1, 1, HSMP_SET_GET}, + + /* RESERVED(0x2B-0x2F) */ {0, 0, HSMP_RSVD}, {0, 0, HSMP_RSVD}, {0, 0, HSMP_RSVD}, @@ -385,6 +444,72 @@ static const struct hsmp_msg_desc hsmp_msg_desc_table[] */ {0, 2, HSMP_GET}, =20 + /* + * HSMP_DIMM_SB_RD, num_args =3D 1, response_sz =3D 1 + * input: args[0] =3D reg space[23] + reg offset[22:12] + + * device LID[11:8] + DIMM address[7:0] + * output: args[0] =3D read data byte[3:0] + */ + {1, 1, HSMP_GET}, + + /* + * HSMP_READ_CCD_POWER, num_args =3D 1, response_sz =3D 1 + * input: args[0] =3D apic id of core[15:0] + * output: args[0] =3D CCD power(mWatts)[31:0] + */ + {1, 1, HSMP_GET}, + + /* + * HSMP_READ_TDELTA, num_args =3D 0, response_sz =3D 1 + * output: args[0] =3D thermal behaviour[31:0] + */ + {0, 1, HSMP_GET}, + + /* + * HSMP_GET_SVI3_VR_CTRL_TEMP, num_args =3D 1, response_sz =3D 1 + * input: args[0] =3D SVI3 rail index[3:1] + read temperature[0] + * output: args[0] =3D SVI3 rail index[30:28] + + * rail temperature in degree C[27:0] + */ + {1, 1, HSMP_GET}, + + /* + * HSMP_GET_ENABLED_HSMP_CMDS, num_args =3D 1, response_sz =3D 3 + * input: args[0] =3D HSMP command mask[0] + * output: status of HSMP command =3D args[0], args[1], args[2] + */ + {1, 3, HSMP_GET}, + + /* + * HSMP_SET_GET_FLOOR_LIMIT, num_args =3D 1, response_sz =3D 1 + * input: args[0] =3D op[31:30] + reserved[29:28] + + * apic id[27:16] + floor frequency MHz[15:0] + * op encoding: 00 =3D set per-core floor, + * 01 =3D set all-cores floor (apic id reserved), + * 10 =3D get per-core floor, + * 11 =3D get per-core effective floor. + * Floor frequency field is reserved on GET (bit[31] =3D 1). + * output: args[0] =3D floor frequency MHz[15:0] + * (effective for op 11, configured for op 10; + * reserved on SET) + */ + {1, 1, HSMP_SET_GET}, + + /* + * HSMP_DIMM_SB_WR, num_args =3D 1, response_sz =3D 0 + * input: args[0] =3D write data[31:24] + reg space[23] + + * reg offset[22:12] + device LID[11:8] + + * DIMM address[7:0] + */ + {1, 0, HSMP_SET}, + + /* + * HSMP_SDPS_LIMIT, num_args =3D 1, response_sz =3D 1 + * input: args[0] =3D Set/Get[31] + SDPS Limit[30:0] + * output: args[0] =3D SDPS Limit[30:0] + */ + {1, 1, HSMP_SET_GET}, + }; =20 /* Metrics table (supported only with proto version 6) */ diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/am= d/hsmp/hsmp.h index 0509a442eaae..b153527e0a0d 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.h +++ b/drivers/platform/x86/amd/hsmp/hsmp.h @@ -27,7 +27,7 @@ #define HSMP_DEVNODE_NAME "hsmp" #define ACPI_HSMP_DEVICE_HID "AMDI0097" =20 -#define DRIVER_VERSION "2.5" +#define DRIVER_VERSION "2.6" =20 struct hsmp_mbaddr_info { u32 base_addr; --=20 2.34.1 From nobody Mon Jun 8 15:38:03 2026 Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11010036.outbound.protection.outlook.com [40.93.198.36]) (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 161183AF66F; Thu, 28 May 2026 09:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.198.36 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779961230; cv=fail; b=nIXCkIBBYUKB+5I52sjphbuXB3jpGYBLoHCSzaZtlbsu5N9nmcFhVMlTwgs1/va0ygCDObTFmxw8TJr32chmspmrgmoNm5QYR30DcspC5EeIBeftitwwi0C/VPPxaPK7WUaITEi7BRswZF9IrinLkbcEzVPtaZJ3ibhF457Yj+I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779961230; c=relaxed/simple; bh=0f1eWmFvJNzqzXC92VolsCXHqSACPZq0Z1kqA1i2Zpo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kTXmF1CqfhFpgICi/nIldRwaChiWhLOFq1DNWt6TwZo0buWmzsfcS3fWYUayBI18mgGgBiJ1rjK9/JFCaiR7YBFDQA34IqoBlApVPfU7cX/jVqX9OX5xqQjAZTEJGHCc0R8jAtdu9R7zR8Q2fGRp6WBj7Mift17LWF6NoOFdals= 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=H9ADyWWI; arc=fail smtp.client-ip=40.93.198.36 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="H9ADyWWI" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oz0ZDS/uZqAYgTBaNajHJWvBKaMnqSjk/CCEobLxN/jYr865GZtE4n2qwQ+h1PHfIPqKs21gPFY8VSH1mMxZa8Jui3VtjuSbKH55I8gZU9inSpOUXQCtg+dgm0jpY4Oft9MG/CLMtOCu4PB0CAiV9hV5wJ5ZLMRpUMwMiyOsM9jG7ae5rdwAlsTPuHGbsPq6J2Qm1yuXo1duUaNsruUdhsvjVIUuYwKN1occ0iIBIOTmwSgOhSJtWclmumlcgftdZy2UrBMWrXfYr0y9CZgYZjwFrqo/yjLlKZKTjjpQoA0zo9wqjV2YczrPInG/Izp9REdpNBRvEenVDIDVjqahwQ== 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=9sE2WV9tkhN2aiycQIkQAh9a9xrvgDAZIdVJzDJVM3M=; b=wqNSRdrcHPZp9j/Qkd7g0x557aMdfAo3AiEO+1zdOOc8iEeHbHxKAJ+gg1oQAxMaEkesp/zgqSGgK7zIjE9YihYaudZOGwYRwprrzVilykA/TPtHvNBxWhGowTTLsBiDAidlh9gCqhjtf6lRsidYSfANBePBi96cyFv8/CPrJYpB5FGeiyM+WSdCnBc4+fantGfESWLgGjB6SmoT+xc+TrQVVsxgMXoKQMI0GGm7kYO8pKRIIEXqyQGhggBAVGNQ3he9c8Fl+tnJPEfM3+GBcWaL2zhH8vy/vyJIPENBZHFiThnaLfnUEWjMWPJ2hmvb7cSMiIj8D6G7Kqrd7ttb+g== 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=9sE2WV9tkhN2aiycQIkQAh9a9xrvgDAZIdVJzDJVM3M=; b=H9ADyWWIdKPNyhGRTDgRIsxm9/OrjyCqyhGXkT80Y7foIlxHtRdOnS3XoakU6eOYjAmatfwzVg3dA9JoUxLxITLgVVMa+Hh2eM1cJDr2M+PKkcWFzV3N3k8kMcRA22dYOe9y7seTLcB9hziFmTCqNWNk2kY9ge74n9BaoR3K+9M= Received: from CY5PR22CA0065.namprd22.prod.outlook.com (2603:10b6:930:80::10) by BN5PR12MB9511.namprd12.prod.outlook.com (2603:10b6:408:2a9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.12; Thu, 28 May 2026 09:40:22 +0000 Received: from CH1PEPF0000AD80.namprd04.prod.outlook.com (2603:10b6:930:80:cafe::9f) by CY5PR22CA0065.outlook.office365.com (2603:10b6:930:80::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.71.13 via Frontend Transport; Thu, 28 May 2026 09:40: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 CH1PEPF0000AD80.mail.protection.outlook.com (10.167.244.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Thu, 28 May 2026 09:40:21 +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, 28 May 2026 04:40:17 -0500 From: Muralidhara M K To: CC: , , Muralidhara M K , Suma Hegde , Muthusamy Ramalingam Subject: [PATCH v4 2/7] platform/x86/amd/hsmp: Add UAPI structures for Family 1Ah Model 50h-5Fh metrics table Date: Thu, 28 May 2026 15:09:49 +0530 Message-ID: <20260528093954.2461272-3-muralidhara.mk@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260528093954.2461272-1-muralidhara.mk@amd.com> References: <20260528093954.2461272-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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD80:EE_|BN5PR12MB9511:EE_ X-MS-Office365-Filtering-Correlation-Id: e16cb33c-e9c6-4578-88c5-08debc9d2332 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|82310400026|376014|1800799024|56012099006|3023799007|22082099003|11063799006|18002099003; X-Microsoft-Antispam-Message-Info: EwdNw70XuqFAOd48YjkAeFLcJRsgiLvqEdmRsORyg5m08f8PnwTlkdCNaAfJApC1wkNGcgAKELMMOKn5/8XGMOArgVVgm34E0mCGU1KwNbEQzdSNSVMgHDZjbypKPFhwwVigj9BWcvBHaHYNvetjtiW+tgKUjgdcgQPjIYgG7Fr4q0PCftq6AH3BpMThELn4jQhyuwUIXp5bR/UGUXeLan6t+y0bHo8IssuaUAk3siDf4BHXfiOQDdhHv59eHsFjdssmZyD7ZzWNBNKD/fzE0BJJhKvYrWWNoj4+x+s77KGSfPqKBvP3YniRoM7jOTB+6Av5iaRKxskptNHAPVWxoUKRVMED2CFtTCHYxuugc3VP1mbhlZE1qcJtNYDEp0EXqWPWHI7z2v84jjfPu1Zz//QGyFxWgiqhNCUZVgBPi71fMZqtbH5laM66g3SqZN7GMscf50o3vrByqQf0nnh6gHA/EMnF/uMMX5ah9GJNH0X+9aq38ZtA8c0W2xSo/eVcWaOWgPCCF6qyglKCnhvcoO4WuTXl0lQOZxKnZpwxviRMMyeCjvInpgLxE/y2CdpPRkLEdxPtEpJrSB/SkcFt/B5gd8gsvpjBrWRdIFyyXADyANTwrxT29dxFL3iyjo2eDUTGI7+6l33JDtZbs78t2XShjrrwqiUdUb8Oe/Cg3m0lo5IliwhmJXPtQo1TQDlJYPyQmiRssVozf/Al7l5N30WBYpxCzGjbe9cGwwbUBfM= 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)(82310400026)(376014)(1800799024)(56012099006)(3023799007)(22082099003)(11063799006)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IT6b3RLXYdUKEu5YJMsZoT6B+NLxyNHDIiqBvN+hS4n8CmTIaWZfp/0988/zKIL/vYedCnDtSeuGuSFidxu5c7vtw8k8P1k/B8/Zp/duLLO5X1fqj/w4A+DNRZmu/O4YjJGB1U7pnzSiMzYUAI7Isb3+E6OvIhoiGuxiEgcdqPqFtN/weHMJfmm/zI0dS09zVqQnnVWQKTz/mZmFunDCGosBG5+JKHxL2e70JEocnNwvD3gxeSfnxyAma73pRxnU9wimuct7KRs7+t/eCxUxXQC8jjRPi7GbGkLofdCzot4uRwUTsoNkcke2fWjNMMN29j9s71TFoi8L3h7VSDprY9XtIIHKcABpfVMJy9E6JQ0PYQKm4FUXlPZtyMYfvBhAL1EkTNz5+taMRAX5vJhnz1KsYiYRgqm/Q5ufJB/RG2bPKITkIrKui22mzbeBn8cJ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2026 09:40:21.9041 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e16cb33c-e9c6-4578-88c5-08debc9d2332 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: CH1PEPF0000AD80.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN5PR12MB9511 Content-Type: text/plain; charset="utf-8" HSMP protocol version 7 on Family 1Ah Model 50h-5Fh delivers a new per-IOD/per-CCD metric-table layout that is not compatible with the existing hsmp_metric_table. Userspace tooling needs a stable UAPI description of this layout to interpret the firmware blob carried by the HSMP character device. Add hsmp_metric_table_zen6_iod, hsmp_metric_table_zen6_ccd and the top-level hsmp_metric_table_zen6 that mirror the firmware-defined binary layout 1:1. The ccd[] array is sized to the hardware maximum (HSMP_F1A_M50_M5F_MAX_CCDS =3D 8) to keep that mirror exact; userspace iterates ccd[0 .. iod.num_active_ccds - 1] and ignores the rest. num_active_ccds lives in the IOD block because the IOD die is the aggregator that reports the CCD population, and keeping it there preserves the 1:1 mapping with the firmware layout. Driver enablement for protocol version 7 is added in a follow-up patch. Reviewed-by: Suma Hegde Co-developed-by: Muthusamy Ramalingam Signed-off-by: Muthusamy Ramalingam Signed-off-by: Muralidhara M K --- arch/x86/include/uapi/asm/amd_hsmp.h | 93 ++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/arch/x86/include/uapi/asm/amd_hsmp.h b/arch/x86/include/uapi/a= sm/amd_hsmp.h index 52e53ec5877f..fce271282348 100644 --- a/arch/x86/include/uapi/asm/amd_hsmp.h +++ b/arch/x86/include/uapi/asm/amd_hsmp.h @@ -592,6 +592,99 @@ struct hsmp_metric_table { __u32 gfxclk_frequency[8]; }; =20 +#define HSMP_F1A_M50_M5F_MAX_CORES_PER_CCD 32 +#define HSMP_F1A_M50_M5F_MAX_FREQ_TABLE_SIZE 4 +#define HSMP_F1A_M50_M5F_MAX_XGMI_LINKS 8 +#define HSMP_F1A_M50_M5F_MAX_PCIE_LINKS 8 +#define HSMP_F1A_M50_M5F_MAX_CCDS 8 + +/* Metrics table (supported only with proto version 7) */ +struct hsmp_metric_table_zen6_iod { + __u32 num_active_ccds; /* Number of valid entries in the sibling ccd[] ar= ray */ + __u32 accumulation_counter; + + /* TEMPERATURE */ + __u64 max_socket_temperature_acc; + + /* POWER */ + __u32 socket_power_limit; + __u32 max_socket_power_limit; + __u64 socket_power_acc; + __u64 core_power_acc; + __u64 uncore_power_acc; + + /* ENERGY */ + __u64 timestamp; + __u64 socket_energy_acc; + __u64 core_energy_acc; + __u64 uncore_energy_acc; + + /* FREQUENCY */ + __u64 fclk_frequency_acc; + __u64 uclk_frequency_acc; + __u64 ddr_rate_acc; + __u64 lclk_frequency_acc[HSMP_F1A_M50_M5F_MAX_FREQ_TABLE_SIZE]; + + /* FREQUENCY RANGE */ + __u32 fclk_frequency_table[HSMP_F1A_M50_M5F_MAX_FREQ_TABLE_SIZE]; + __u32 uclk_frequency_table[HSMP_F1A_M50_M5F_MAX_FREQ_TABLE_SIZE]; + __u32 ddr_rate_table[HSMP_F1A_M50_M5F_MAX_FREQ_TABLE_SIZE]; + __u32 max_df_pstate_range; + __u32 min_df_pstate_range; + __u32 lclk_frequency_table[HSMP_F1A_M50_M5F_MAX_FREQ_TABLE_SIZE]; + __u32 max_lclk_dpm_range; + __u32 min_lclk_dpm_range; + + /* XGMI */ + __u64 xgmi_bit_rate[HSMP_F1A_M50_M5F_MAX_XGMI_LINKS]; + __u64 xgmi_read_bandwidth[HSMP_F1A_M50_M5F_MAX_XGMI_LINKS]; + __u64 xgmi_write_bandwidth[HSMP_F1A_M50_M5F_MAX_XGMI_LINKS]; + + /* ACTIVITY */ + __u64 socket_c0_residency_acc; + __u64 socket_df_cstate_residency_acc; + __u64 dram_read_bandwidth_acc; + __u64 dram_write_bandwidth_acc; + __u32 max_dram_bandwidth; + __u64 pcie_bandwidth_acc[HSMP_F1A_M50_M5F_MAX_PCIE_LINKS]; + + /* THROTTLERS */ + __u32 prochot_residency_acc; + __u32 ppt_residency_acc; + __u32 thm_residency_acc; + __u32 vrhot_residency_acc; + __u32 cpu_tdc_residency_acc; + __u32 soc_tdc_residency_acc; + __u32 io_mem_tdc_residency_acc; + __u32 fit_residency_acc; +}; + +struct hsmp_metric_table_zen6_ccd { + __u32 core_apicid_of_thread0[HSMP_F1A_M50_M5F_MAX_CORES_PER_CCD]; + __u64 core_c0[HSMP_F1A_M50_M5F_MAX_CORES_PER_CCD]; + __u64 core_cc1[HSMP_F1A_M50_M5F_MAX_CORES_PER_CCD]; + __u64 core_cc6[HSMP_F1A_M50_M5F_MAX_CORES_PER_CCD]; + __u64 core_frequency[HSMP_F1A_M50_M5F_MAX_CORES_PER_CCD]; + __u64 core_frequency_effective[HSMP_F1A_M50_M5F_MAX_CORES_PER_CCD]; + __u64 core_power[HSMP_F1A_M50_M5F_MAX_CORES_PER_CCD]; +}; + +/* + * Metrics table for Family 0x1A, Models 0x50 to 0x5F, table version 0x007= 00000. + * + * The layout mirrors the SMU's binary metric table verbatim: one IOD block + * followed by HSMP_F1A_M50_M5F_MAX_CCDS fixed-size CCD blocks. Only the f= irst + * iod.num_active_ccds entries in ccd[] carry meaningful data; the remaini= ng + * entries are firmware padding and must be ignored by userspace. + * + * Future processors within the same family and model may support a + * variable number of CCDs and cores. + */ +struct hsmp_metric_table_zen6 { + struct hsmp_metric_table_zen6_iod iod; + struct hsmp_metric_table_zen6_ccd ccd[HSMP_F1A_M50_M5F_MAX_CCDS]; +}; + /* Reset to default packing */ #pragma pack() =20 --=20 2.34.1 From nobody Mon Jun 8 15:38:03 2026 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011002.outbound.protection.outlook.com [52.101.52.2]) (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 D2F923AFD0A; Thu, 28 May 2026 09:40:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.2 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779961229; cv=fail; b=lOvTmMauTY4v0HxGqe5Xbzc30OdSUO03uOjJB8S3UIOZEXV/dUd4Xxvio6fAF767YariOPg+eEGWYJb6MUk9neZdlhky5x/w9r/qgEg201Wt5JejfhfCtY5g+WbwtYZkcOiipJh+PWT8z5ofHj43p/nMS4eM1SeBpwWvW5quLIs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779961229; c=relaxed/simple; bh=EkM1/WsRLDcDUNeiKE/UWpjiKLuGO1nDztRsvuCjOqU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZvnDz5vPXZliFvTEYZA2muTeruz5unaQns5H54Cgixrhh8xBs0AL0F5jZrBYghq/ZzoSMi8OSoafHOPB5ijPfxv9hkbn6JfZTnwTSQ3dQZqUoFmedQz2LnqQy/Nui64+6F+/KRu+K9+G6CD7RVG7KfaPm27EnRHcKwqUX2OgRIo= 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=4ifbG+NZ; arc=fail smtp.client-ip=52.101.52.2 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="4ifbG+NZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Mp4zjhx4PfqrZd/ghJvlWytaMrAHkJC/ikz0FHpm0UKqdIdWJ89n0ff0I6aHRKfR2lrBTJUDM4LGhH+A3wWSxbvb1PvuEieSBIwpbnLhhtsiGZRpAmHLIWYDBm2z0v1HoX/cqHWf28qwKQUvq9muGQifX4yZaL1eFfXAPRaDvQ4eu2LWn9QD8Z1sUvwwpIBcdzddoIztXYWxj6gx91qVYjX+5HBvwJfu6wzKKsDYNinNxQI32NZCfLjI6uW/e0iXW9J426jgaLvCR4fW+Z9Bki69lUS9XRkYvMqEn09KG7ZnCTdxdiSIeuvLc9wbslvlayz/8yIbEwoyPIpEzWoP5A== 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=Uh7lXLeIC/hMkgGP5ij4RghWFHbq/ACrn93GwB++Nzk=; b=WEHjugE7GZjo9DzWbdcfU6y/L3pjsMDQQlg+Hc/KFyMZOZ0+K+Mt4FQg/pWhuHn2bajtM2DmmsQNYHPYuZWP1vlAVqSKmIW6i8VQilQC15jSPbbFoFP5R5X0a+ipzZrZQvMUlVGkw6oMVC7abkZPJvX72vUmW/w5wojZZYgIpXaNeLdMBwIC6htNWNQclHl/wH7NKSE8vILGJAtXoYVC8Zw+BFMKsdZQyG+Zz+ZD/Dv6VXhsDUrIWS+s1XGhRRqxjMwFqrOP6FlrO7VyhTaE0ExnwGDZbSercUH2aiGuUlB3hdjyW0xFlS5vuH2yqvet+lmNnor8BEtSejOn6oiK8w== 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=Uh7lXLeIC/hMkgGP5ij4RghWFHbq/ACrn93GwB++Nzk=; b=4ifbG+NZVUUhNOkJjAn7dN5eW/ZKfdOHq6ph4d+cNsjfY9ecXJgTOYgzVUeyS25xVDKNFknzzJWp885Z7HouCatckX7Q9/6GZ+kHWHJXZUbRo3Q7GJqghk73bOUQf+JJ5gRA38YmG2kRE9UIaA9bbci1IsjSbjxhSYfITBgWxSA= Received: from CY5PR22CA0078.namprd22.prod.outlook.com (2603:10b6:930:80::25) by CYYPR12MB8872.namprd12.prod.outlook.com (2603:10b6:930:c8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.11; Thu, 28 May 2026 09:40:23 +0000 Received: from CH1PEPF0000AD80.namprd04.prod.outlook.com (2603:10b6:930:80:cafe::30) by CY5PR22CA0078.outlook.office365.com (2603:10b6:930:80::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.71.13 via Frontend Transport; Thu, 28 May 2026 09:40:23 +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 CH1PEPF0000AD80.mail.protection.outlook.com (10.167.244.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Thu, 28 May 2026 09:40: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, 28 May 2026 04:40:19 -0500 From: Muralidhara M K To: CC: , , Muralidhara M K , Suma Hegde , Muthusamy Ramalingam Subject: [PATCH v4 3/7] platform/x86/amd/hsmp: Unify response_sz validation to an upper-bound check Date: Thu, 28 May 2026 15:09:50 +0530 Message-ID: <20260528093954.2461272-4-muralidhara.mk@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260528093954.2461272-1-muralidhara.mk@amd.com> References: <20260528093954.2461272-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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD80:EE_|CYYPR12MB8872:EE_ X-MS-Office365-Filtering-Correlation-Id: 3b6ae609-b029-4961-92ef-08debc9d23d8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700016|376014|22082099003|3023799007|18002099003|11063799006|56012099006; X-Microsoft-Antispam-Message-Info: PPPyajCPK5RL9PMemCVTjcUZ2aBx37kbQNxRunJhetVhGn700rlF8qvjiksPo5vgI787L/sDB4b6dgUSmhaEyBUSCAFbz9wJha0j5UebAmZhSAflGpbWZ25zBS0fwjy3cSQfKFOKiQnv1PeH5xINlKGZJqVor/ERKDGNYEFYFqdzvoe5e1L5Rtk6t0Ni4Dmof6TynYiJR4epd4DsVk3nJcVu4Z9qbHp90y+yTjUILZF/+jA5kEvTxZ9pIvvF1YNftD2NVBmTOTf+25vsJKfWdheT1QakwyaHFZoIGTnQIvUleQIaX0adCJSqGqUGXsS3PiORE8YMhuhIayB9Ezw1Kw7RrTXZftaYgL5+HLPUHXPjXCicdP60kbBPjDIVz1hJevz2FD0tGcyN89d824OAE5iUNBaWaI3H9jOEJY9rukRWkLUEWXWFwIKxFaLAPyN16l3LSI1tLyEQT8DXFoqGVIMQLw6Q+aORrEwClxj4dX6KdER1vOeHllJfqku2NTIC0cmypOebf6h5RMYqepZtb0AzEi2231VHLVVbny5dnPdxH1wAF+iYS7kGiup19cWi6kTFYmkfuI3G69jr3m7YtV/jaibjjue4XmlNeya2+szG7Z0LWOADUGeyKQ8jjce6cf9w6/th6D5KP0/vtmFxk3UBFguPkLPdqRIYUK2K+kZGUVGLntwLBgRLW9JujuigfPGjMp/S/6vNhb0Z8wvuJlzEZ82Cy5fr/r8YlEEk0wY= 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)(1800799024)(82310400026)(36860700016)(376014)(22082099003)(3023799007)(18002099003)(11063799006)(56012099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eJTAPLjoWdWn/yzNDUgO7vPq/Mt0+b74+Ku9E66Y9SrmTd+Om/DGj8FtojWU2BaFhmeLZ8+i1Frr5JUxdwIgIEIpnDoTAjraCLKdnVKrUZW1f9wZ/vQH6/dfUKpTSBAXDAUd0GAdutf8sg2rbrlOOiyRtJlvCfVI1I0wD5aStn7D9UmQ+iITip028HsZCeXOAQptfvki1PL01upRkhthryBSIKXXZrBXqPQp0CysuysSH1mX0u/mZwhoe16o7p0EZGgkAwNKLl5vabSkuhzFhdmysoV3KtMWlvHR/7AyG5JwNfG/F2wNg+P4/w+0er41tfXTlE0b9yKrzXjTZB5Wr4QviMUYTusR/gfM0NyhTY8EXlDBQOAM+OFn+6oD/I0ZZjZsR/G5sNeNPWeGMmUWg2wrrE9i8ZICfUk08zSN1iNxwMOg6dLjFlxPV3+80BPA X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2026 09:40:22.9924 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3b6ae609-b029-4961-92ef-08debc9d23d8 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: CH1PEPF0000AD80.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8872 Content-Type: text/plain; charset="utf-8" As HSMP protocol versions evolve, existing message IDs sometimes gain additional response words on newer firmware. validate_message() currently enforces a strict equality (response_sz =3D=3D table value) for HSMP_SET and HSMP_GET, so userspace compiled against an earlier descriptor table is rejected with -EINVAL when it asks for fewer response words than the in-kernel table now declares - even though that caller has no interest in the additional words. Only HSMP_SET_GET already used a relaxed upper-bound check. Replace the per-type branching with a single upper-bound check for all message types. Userspace can now request fewer response words than hardware provides, while requests that exceed the descriptor table (and therefore the hardware capability) are still rejected. Reviewed-by: Suma Hegde Co-developed-by: Muthusamy Ramalingam Signed-off-by: Muthusamy Ramalingam Signed-off-by: Muralidhara M K --- drivers/platform/x86/amd/hsmp/hsmp.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/am= d/hsmp/hsmp.c index 631ffc0978d1..9bad58fef304 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.c +++ b/drivers/platform/x86/amd/hsmp/hsmp.c @@ -182,20 +182,15 @@ static int validate_message(struct hsmp_message *msg) return -EINVAL; =20 /* - * Some older HSMP SET messages are updated to add GET in the same messag= e. - * In these messages, GET returns the current value and SET also returns - * the successfully set value. To support this GET and SET in same message - * while maintaining backward compatibility for the HSMP users, - * hsmp_msg_desc_table[] indicates only maximum allowed response_sz. + * As the HSMP protocol evolves, newer platforms may define more + * response arguments for existing messages. Use an upper-bound + * check so that older userspace callers requesting fewer response + * words than what the current hsmp_msg_desc_table[] defines are + * still accepted, while rejecting requests that exceed the + * hardware capability. */ - if (hsmp_msg_desc_table[msg->msg_id].type =3D=3D HSMP_SET_GET) { - if (msg->response_sz > hsmp_msg_desc_table[msg->msg_id].response_sz) - return -EINVAL; - } else { - /* only HSMP_SET or HSMP_GET messages go through this strict check */ - if (msg->response_sz !=3D hsmp_msg_desc_table[msg->msg_id].response_sz) - return -EINVAL; - } + if (msg->response_sz > hsmp_msg_desc_table[msg->msg_id].response_sz) + return -EINVAL; return 0; } =20 --=20 2.34.1 From nobody Mon Jun 8 15:38:03 2026 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013069.outbound.protection.outlook.com [40.93.201.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DF393B0AC6; Thu, 28 May 2026 09:40:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.201.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779961231; cv=fail; b=VswGSq/Fc2KpQWzKD0AkgIXZ14ddz0chRRp8RvqVDOWV6nnf3n5ZVG4Y9EAHfW7H/+602A2fpaEHNmCtPw2O1vJTPydvX+01VFl9BUp8lKnhGRn6g7oFUIU+v2+BWOm+Inrh94iYVXpATERYNjaOg8/Wi/T/I7MrjH1prwdXjYg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779961231; c=relaxed/simple; bh=MLAjFuaM/SkxUEtH0R2VGYs6BHUwEZgU+i2EcQFjATs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=olNOYPsTkBXmzxHtuxZv+bx5H7f81UfoUGDeJEdFWMio+JMPz3GpldkCqAM14bPowU4mtDtJwobJfk3TFBPmnRQ7d2XBBvP4nFyjLechqkathpqtWPHyQcZzFPkpuR6e/DGoVBXc5Zs+7Nv82UO2C84NCHAyM7MMxChiR4HJScc= 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=gSI6pL17; arc=fail smtp.client-ip=40.93.201.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="gSI6pL17" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vgXG0ZFGsgbQuDhscKzkzdznRWze9F0kvHI4SpGfTUHxwl4qNthWIJ08AXYviMeahqzs8lCvm9v06ryXm4BLzpsjIdnOfDq8FAmK6LxLbyKuiU2gbKTbYMqtVFXEIW44Nl1AWV2ofHtgYPel9b9+vo6RFUZVM8EtxTEa1YkMuAatxK4tCNf3xluqggk9ejBSJ7fHXKOi9mt2gBIkoAQKc568C2gdRyITaJ/o9tBYP62c1WwA0GOep+5uUIdyzLPp069yLDwJIPQ3x9h5xefIIG1dr3f4BEOKjc1NrvxDtk/o4u6tPGdBWkiw4zg/n95bR6ty400i42JMs3h7EgHkPA== 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=+udk7GCMxUlEQihZUamLzFS5wxkGB3A/fyJa/nwnrCw=; b=T8TINP+llSzdan2e7vPz2WVifaFMWn0xlCgumwiQLNnhCYHgopRn1bRhAYeKSWWr6khxoqVE5KeT56R534fdOjK2ebH7y9ZkJiu9L99aM9uM5Jz/3SNPn3ZekdG7RWef9N+UWEY2Xj3EeG1ALhoZS6kw45cAVxlKIPytJGhqdJvy3cjmRMMEEwvhkmIgJYvtSrLBZrC5zdyzRdHNATbCd2YhYY+NNOh6BvLFQKtsH8e5Z0mCYgbAAAXXFJz2A6lmpCCOO8P1WqwiX+HHUY6kaiAZvFklyzBeohQqWplt/FQMmOlIxPzeW5wRlHuZ2TdKOoI6TctdzKrD89r7FC9chQ== 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=+udk7GCMxUlEQihZUamLzFS5wxkGB3A/fyJa/nwnrCw=; b=gSI6pL17OP1fVnMeEWNYuEtMHWSxXL+0z5UkZJbUCJ3EClZCfysEMOR0Vf2n6RDoScJvnV1YOQii6tf2U8ynX9eHZP3yOduXGm5beKIfg6lxGOvgXqZECeZMAJGKTOZu3DxjmBFZE3Rv3PWOFDlKN0Bp9wLfHzqYDjvbD7V45kY= Received: from CH0PR03CA0268.namprd03.prod.outlook.com (2603:10b6:610:e5::33) by DS7PR12MB8347.namprd12.prod.outlook.com (2603:10b6:8:e5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.13; Thu, 28 May 2026 09:40:23 +0000 Received: from CH1PEPF0000AD83.namprd04.prod.outlook.com (2603:10b6:610:e5:cafe::a7) by CH0PR03CA0268.outlook.office365.com (2603:10b6:610:e5::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.71.13 via Frontend Transport; Thu, 28 May 2026 09:40:23 +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 CH1PEPF0000AD83.mail.protection.outlook.com (10.167.244.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Thu, 28 May 2026 09:40: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, 28 May 2026 04:40:21 -0500 From: Muralidhara M K To: CC: , , Muralidhara M K , Muthusamy Ramalingam Subject: [PATCH v4 4/7] platform/x86/amd/hsmp: Source metric-table size from firmware Date: Thu, 28 May 2026 15:09:51 +0530 Message-ID: <20260528093954.2461272-5-muralidhara.mk@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260528093954.2461272-1-muralidhara.mk@amd.com> References: <20260528093954.2461272-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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD83:EE_|DS7PR12MB8347:EE_ X-MS-Office365-Filtering-Correlation-Id: 0040e223-c758-4e1d-b68f-08debc9d2436 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700016|376014|82310400026|3023799007|11063799006|6133799003|22082099003|56012099006|18002099003; X-Microsoft-Antispam-Message-Info: fklZnYRwe9VLNQEirQX99VS/RhWR8b4aFN6sBzbEFqOqC4GUpDS5zVAOb0Ji3PBe4S/nepksSup55ZI/GxqUlmV9QRTY7U7BCppKrjhAxOgEB4IeFJcSUlAOum8Ags1NWN5+YOynH2tqHdK7AGVTiBhBLb7dR/R/bueuJEKPpbtNTp3DwQWmxazPn4+bCPh/xRzrbchAh8aRI7hhlLCH54Qjdq1oHUHx3Dgv9aZtoHP6xMZEDplq9Un5bQVelfkqFGjvU9MRpaJLIC5+sd9aSc3sQ2Zmb/spJe+u/1zGQATF8o6ZOP2SGxMZ05jlYOfmEhzrXI0/bzrurPcFoJkoK43j0VPdW/6ZJrcqE00KZn8DgXaHHdYxBsAHSw3uzef93nvP63RRkuS01rxHSrDLgfENEDz19Qf7I3ZXKf3tzXqzdGYaWrCq4FPzK9BBGeMURwLhJCAeYMgUKZNjNRhCY0zoZDSFI+aLZ9sxqYH77HiajS1JuGaoYu8w+fX+qvVWO3O6fe2d8oG50al9d8eAtEyyd3x+PCBn+joCw4tI+vP2Lmi+bOnj8QlePpQvqho9p5PiTKDcE1RfEsEU4Nrh3y6AuyGpYRskHCDmb1pZ4svsSmpDT447XdeVZTUxNbv9J9w3Cshf2VI4l/J8puSuIaHjDmleLrvu1feYwJfpV9hvcUCxRz7goK7UJX31i7VxdtwjLlOhPkkAEEG5LPngCY1cqMM+CsyHudmc+BuBxts= 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)(1800799024)(36860700016)(376014)(82310400026)(3023799007)(11063799006)(6133799003)(22082099003)(56012099006)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RGwxFgMP1MOnp1tf8mz7PelRRLdHFtrPcVtX5oB/nT/5PeW8nKFsnhP7IEPZKmuAJX0MyxV45VN0fu1P8TIl5JRlNgcfLHxuc1VnhrF2rbVZfdNIYW6E/1bMO1spn9XUgo0eIBHyQhUss5DVqeL8Qye35EiZyuCJ1L38oRhwn6jiC8PeEbvv07xdLsjWUAJqVTnv1P479mWLC9LPY4DjRzDFEJOsbxUkOXAmsAGnQWWfzc4nBO0XlFKT+aqB6y/rh3SB0dpzfyBwgyKj3hpWpwgEk5oWJQjgoA4fODDjLcTWhCV36hu9ryJGSqVTxS1AY2EUCDa7LEK9pJzaWOCj64qGfZ0Kb32ptr+/TyOtTxv6QTpYGn2a1LVAaInE8CmqGJBeBCWg4eRs21XcNyHWndmu2Y4viXB+ViuAQw73JuLaXYkJENrGVaq5h6nDBXdf X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2026 09:40:23.6228 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0040e223-c758-4e1d-b68f-08debc9d2436 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: CH1PEPF0000AD83.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8347 Content-Type: text/plain; charset="utf-8" The driver hard-codes the metric-table region size to sizeof(struct hsmp_metric_table). That is correct for HSMP protocol version 6 but mis-sizes the ioremap of the SMU DRAM region on newer platforms: Family 1Ah Model 50h-5Fh exposes a ~13 KB hsmp_metric_table_zen6, and the table is expected to keep growing on future firmware. The same hard-coded value also forces hsmp_metric_tbl_read() to reject any read that follows the actual firmware layout. Pick up the table size from firmware instead. SMU on Family 1Ah Model 50h and later populates HSMP_GET_METRIC_TABLE_DRAM_ADDR's args[2] with the DRAM region size in bytes; older firmware leaves it 0. Bump the descriptor's response_sz to 3 so the field is read, store the value in hsmp_pdev.hsmp_table_size at probe time, and fall back to sizeof(struct hsmp_metric_table) when firmware reports 0. Use hsmp_table_size both for the devm_ioremap() of the region and as the upper bound for hsmp_metric_tbl_read(). Behaviour on existing protocol-version-6 hardware is unchanged: firmware returns 0, the fallback yields the same value as the previous hard-coded one, and both the ioremap and the size check produce the same result as before. The ioctl interface added later in this series uses the same hsmp_table_size to validate the userspace request and to copy out the full firmware-reported region. Co-developed-by: Muthusamy Ramalingam Signed-off-by: Muthusamy Ramalingam Signed-off-by: Muralidhara M K --- arch/x86/include/uapi/asm/amd_hsmp.h | 5 +++-- drivers/platform/x86/amd/hsmp/hsmp.c | 11 ++++++++--- drivers/platform/x86/amd/hsmp/hsmp.h | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/uapi/asm/amd_hsmp.h b/arch/x86/include/uapi/a= sm/amd_hsmp.h index fce271282348..438ac38d0dc8 100644 --- a/arch/x86/include/uapi/asm/amd_hsmp.h +++ b/arch/x86/include/uapi/asm/amd_hsmp.h @@ -365,11 +365,12 @@ static const struct hsmp_msg_desc hsmp_msg_desc_table= [] {0, 0, HSMP_GET}, =20 /* - * HSMP_GET_METRIC_TABLE_DRAM_ADDR, num_args =3D 0, response_sz =3D 2 + * HSMP_GET_METRIC_TABLE_DRAM_ADDR, num_args =3D 0, response_sz =3D 3 * output: args[0] =3D lower 32 bits of the address * output: args[1] =3D upper 32 bits of the address + * output: args[2] =3D DRAM region size in bytes */ - {0, 2, HSMP_GET}, + {0, 3, HSMP_GET}, =20 /* * HSMP_SET_XGMI_PSTATE_RANGE, num_args =3D 1, response_sz =3D 0 diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/am= d/hsmp/hsmp.c index 9bad58fef304..cf9392f99298 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.c +++ b/drivers/platform/x86/amd/hsmp/hsmp.c @@ -356,8 +356,7 @@ ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock, = char *buf, size_t size) return -ENOMEM; } =20 - /* Do not support lseek(), also don't allow more than the size of metric = table */ - if (size !=3D sizeof(struct hsmp_metric_table)) { + if (size !=3D hsmp_pdev.hsmp_table_size) { dev_err(sock->dev, "Wrong buffer size\n"); return -EINVAL; } @@ -398,8 +397,14 @@ int hsmp_get_tbl_dram_base(u16 sock_ind) dev_err(sock->dev, "Invalid DRAM address for metric table\n"); return -ENOMEM; } + /* SMU returns table size from Family 1Ah Model 50h and forward */ + if (msg.args[2]) + hsmp_pdev.hsmp_table_size =3D msg.args[2]; + else + hsmp_pdev.hsmp_table_size =3D sizeof(struct hsmp_metric_table); + sock->metric_tbl_addr =3D devm_ioremap(sock->dev, dram_addr, - sizeof(struct hsmp_metric_table)); + hsmp_pdev.hsmp_table_size); 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 b153527e0a0d..e7f051475728 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.h +++ b/drivers/platform/x86/amd/hsmp/hsmp.h @@ -55,6 +55,7 @@ struct hsmp_plat_device { u32 proto_ver; u16 num_sockets; bool is_probed; + size_t hsmp_table_size; }; =20 int hsmp_cache_proto_ver(u16 sock_ind); --=20 2.34.1 From nobody Mon Jun 8 15:38:03 2026 Received: from MW6PR02CU001.outbound.protection.outlook.com (mail-westus2azon11012007.outbound.protection.outlook.com [52.101.48.7]) (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 88B2A3B2D17; Thu, 28 May 2026 09:40:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.48.7 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779961236; cv=fail; b=r99ekNPTDvB/AEYVmwiPMrvaJRh8yFcQ9qIlEY75rs686d5KMDK0Xx0ac0LtNU0Yh/mP3SWR9Zd5A3aerEWktixKB2853kn+SOtRyi0Ag3/wv2v8qncl0AX0lgjsOKuWIul+6QwAJll1fqSK8LnL9XpyxV7+cOf8jZ0aNHermaA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779961236; c=relaxed/simple; bh=Ub86zaE0NFGI4NYxmhWE5ex+wj8JaD+cFPqUmCxVW9Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CfRDCkQK18jsKkGr4U2YYZLmvZ4rWMy6q0AC6eqTsYgN17Rup6Wtb2eg465zN6QPT+cgf5Px2xDyrHKiQcEEWVp6NkOM/ma4wlN2OLoiuy98Ze9EVz248Sv4+VV2Mz5WRXJFfImA+syN9bi7rvmul52tCFW3DThSZ8Vs7JKS9uU= 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=HB0Hff0D; arc=fail smtp.client-ip=52.101.48.7 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="HB0Hff0D" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=C/bhZhaH5Mj7ieDuHTMTXpdwijYDlQbn7qJPDsE3BxJ1Y5Y0kzkcj6WFZ1Iahv+g6zPCl4HSSraKehqQh8/wfULJWF8WlhULdDMstx6LAVuaKhM2fVjjfD0akIHAeIPJki1/357ElKIGlW0EgcnEOOSolXgz6CVRwn6YFvxPJo5iXKZeSovFcu2yl9wQkzqhCM88EcdkH9DyrkAhTDBO7pT7Sk6z4mLA7mwgRCrxqOSzYlOOuW/9dLxXRBzhe9lE7rmHNTXT0lD2yO6JVHrSIHwIdvv0SwemvJHIRrrTNmiv4YekcPiEx66uyDGAaYkZFfvo6PQijr3k5+6UUsL25Q== 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=IPpJDzYsr7krO3CA6+YSO757xAX4dStPZ+oFQPvPWuI=; b=CU8McQy/wD3AN3zgkvcR0+lzxZBBN0fk12A5/Hr40UdZ149f5q+Io19e1rXXXHUoZzwx52jN/hhHLHpBnUKxN7hprQT/atY8gVgf3x8glp8yaVVl2TomzpgDeGj9wJwL0uTmZqEhL56IGZWMa0NbHoQFC8x9xmopRNVCHXFQiBE1yaoa0oqLQG1ZpPg2nws3XVnCoKZ8vDrn8K/F6tiVj5riC7vnbepmnwUn5yf4sZQFue47lGUxNIpLY9lLzpTpoRzntTtKivCGUxRT/KYEzSl9RUxKJs26FvoXznlSx7rd8NuK+3KQdgrghr/xZH4si+K5WB5xSl1wCM/jVDgGug== 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=IPpJDzYsr7krO3CA6+YSO757xAX4dStPZ+oFQPvPWuI=; b=HB0Hff0DQaC0ThNzSZKE3BjJyigU12SYddiKS+4p2TBacQ2dEVMTXJxBs61hkVcmejAUoAUA2e5mo3XEj01jD72lTRy5gwkk2TUw89/4bQ8XdAO9I1f/r/mlWujbzmx0QduYoZQjjL6/EZm0L6opikG5zRkduSvmlJCnzarCDhk= Received: from CY5PR22CA0074.namprd22.prod.outlook.com (2603:10b6:930:80::22) by SJ5PPFC41ACEE7B.namprd12.prod.outlook.com (2603:10b6:a0f:fc02::9a0) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.12; Thu, 28 May 2026 09:40:26 +0000 Received: from CH1PEPF0000AD80.namprd04.prod.outlook.com (2603:10b6:930:80:cafe::80) by CY5PR22CA0074.outlook.office365.com (2603:10b6:930:80::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.71.14 via Frontend Transport; Thu, 28 May 2026 09:40: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 CH1PEPF0000AD80.mail.protection.outlook.com (10.167.244.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Thu, 28 May 2026 09:40: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, 28 May 2026 04:40:23 -0500 From: Muralidhara M K To: CC: , , Muralidhara M K , Muthusamy Ramalingam Subject: [PATCH v4 5/7] platform/x86/amd/hsmp: Add IOCTL_GET_TELEMETRY_DATA for metric table reads Date: Thu, 28 May 2026 15:09:52 +0530 Message-ID: <20260528093954.2461272-6-muralidhara.mk@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260528093954.2461272-1-muralidhara.mk@amd.com> References: <20260528093954.2461272-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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD80:EE_|SJ5PPFC41ACEE7B:EE_ X-MS-Office365-Filtering-Correlation-Id: f2b588e6-1d52-4f2b-d43b-08debc9d2590 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|82310400026|36860700016|22082099003|18002099003|3023799007|5023799004|11063799006|6133799003|56012099006; X-Microsoft-Antispam-Message-Info: OD5i5g4VS+owa800wZLNA4NyVI+jDn850UWRSsD3K14/3o5mOk12H5XcuzjDHZBVT7AJKsjVl4Muyn7lLUy/cztdOVqPBvsmSDqAIMMk1/0DjNX80w+wJIpS226+OXWtYWeN5PzmhF3OjwT13DBpL7fVTo0G8k1zuF6+OSn1yeeVP2c8czIl5CMa9CO5SDMkoT33nFx8C2Bw9xtyKRpQxt0eQB+Pbn8uO3SdfYM7Z0EeVER7P1uf1QmEn8xuu4fkpBdyycL9ATvPB742/XLiEHR8tMzBuXkxWFgUwnlkr3lsPMv0VApejy2Hir8nskAwU2NUqhpmFxI9Zj1PMZ11KFaGmSJ8vUApXs2KzulPNUpECapZVekZLIHXsBOYqabK6348BhPFtM5jjDYqAj98fSpN/YeG9k+lGmvmPlNvKtlSX3GGCyN5UEvfXBVo+YugAliBmcK5kMch8OGvtOsEZj4LTG35+HUm8YP6ghJBmH6NCRsZhgQ39Ehk0CXSM/Cg8EaaSn6R+T/8s3IGHl3ikc6F984oVK6PcpzzMjjYqArHDzUSmxjdasnJMT0EgA/doL30ASr4aypFiPb+brNja9UTTc12r+NGziaVh+reC2uBnJiGrpWa9AbIGwa1mOrLtEDalSAjq8jyVEOoGd3FOCxhpPoEhAE3p1eFLUSXM+24W8EEQCunHo7XqM/f9cOd45uxrLR3iYCh8mgvo75ouumPOPvo0H3mO85NbZoW7Eg= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(1800799024)(82310400026)(36860700016)(22082099003)(18002099003)(3023799007)(5023799004)(11063799006)(6133799003)(56012099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2bHeBq+3kWpVuri0B7OoWxFzzGl+QBPPQOR2nEwcvyEQ3d8N3AJAFvE0G/FSbjr9S0LpUJcM+lonGcJ6Ql7PvVI4KIWCAMpF5OMvSqt0gr2OnQMm3/sRFJhwqXp+UTlgjqNfetqmwb8bgIEIoXKQeXadi9pClXv9U691ghLomlI1gY9vIXkkCKU4zcQk6t02gtvXy9B7EknTA4MAa6Olk8R3JHRnaE1VxvhFzskiD1oMIgCk+gLNpcHpUetgkgH2AVT/ZoIyeiwFBhSA9vACNvWdnYYu4l2Iyo5h+ZKHVaVJLtYSUFWtich5RdIhweby188rVUdJYieiyILqB/3AtW10ks2qQU0LScnhFIL5ywpppULRbATbHl2cWtY5cHrcmSk4d7mdq4tXPpajCUqAaz7t3yzHmDmQJHeYBSdlJQxlNgxcUcclxL5uQ2CwizsJ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2026 09:40:25.8780 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f2b588e6-1d52-4f2b-d43b-08debc9d2590 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: CH1PEPF0000AD80.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ5PPFC41ACEE7B Content-Type: text/plain; charset="utf-8" The metric table needs to be delivered to userspace as a single atomic snapshot, but the current sysfs metrics_bin path is a file read: userspace can read it in chunks and observe a torn snapshot if an SMU refresh happens between read() calls. The same path is also bounded by PAGE_SIZE, so the ~13 KB hsmp_metric_table_zen6 used on Family 1Ah Model 50h-5Fh cannot be returned at all, regardless of how userspace reads it. Rather than extend sysfs to lift both restrictions, expose the metric table through the existing HSMP character device using a new ioctl that always copies the full table in one shot. Add struct hsmp_telemetry_data and HSMP_IOCTL_GET_TELEMETRY_DATA to the UAPI header. Under the surrounding #pragma pack(4), placing the __u64 user pointer first gives a tight 16-byte layout that is identical for 32- and 64-bit callers, and the trailing __u16 reserved field is rejected with -EINVAL if non-zero so future kernels can repurpose it without breaking already-deployed userspace. Userspace sizes its buffer using the matching UAPI metric-table struct for the running platform; sizes that disagree with the firmware-reported table size are rejected so a short copy can never silently truncate the snapshot. Dispatch hsmp_ioctl() on the ioctl command: the existing message handler is factored out as hsmp_ioctl_msg() for HSMP_IOCTL_CMD, and HSMP_IOCTL_GET_TELEMETRY_DATA goes to a new hsmp_ioctl_get_telemetry() helper. The user-controlled indices reaching kernel arrays via these ioctl paths are clamped with array_index_nospec() to mitigate Spectre v1 (CVE-2017-5753): req.sock_ind before indexing hsmp_pdev.sock[], and msg.msg_id once at the entry to hsmp_ioctl_msg() so all six downstream hsmp_msg_desc_table[] dereferences inherit the clamp from a single mask. Co-developed-by: Muthusamy Ramalingam Signed-off-by: Muthusamy Ramalingam Signed-off-by: Muralidhara M K --- Documentation/arch/x86/amd_hsmp.rst | 30 ++++++- arch/x86/include/uapi/asm/amd_hsmp.h | 43 ++++++++++ drivers/platform/x86/amd/hsmp/hsmp.c | 117 ++++++++++++++++++++++++++- 3 files changed, 188 insertions(+), 2 deletions(-) diff --git a/Documentation/arch/x86/amd_hsmp.rst b/Documentation/arch/x86/a= md_hsmp.rst index 8bb411f0d70d..74c259507888 100644 --- a/Documentation/arch/x86/amd_hsmp.rst +++ b/Documentation/arch/x86/amd_hsmp.rst @@ -68,6 +68,14 @@ under per socket sysfs directory created at =20 Note: lseek() is not supported as entire metrics table is read. =20 +The sysfs metrics_bin path supports only HSMP protocol version 6 and, +because it is a file read, can return a torn snapshot if userspace +reads in pieces. Protocol version 7 metric tables +(``struct hsmp_metric_table_zen6``, ~13 KB) also exceed PAGE_SIZE, so +a read returns ``-EOPNOTSUPP``. For atomic reads on any protocol +version, use the ``HSMP_IOCTL_GET_TELEMETRY_DATA`` ioctl on /dev/hsmp +(see below). + Metrics table definitions will be documented as part of Public PPR. The same is defined in the amd_hsmp.h header. =20 @@ -167,7 +175,7 @@ Next thing, open the device file, as follows:: exit(1); } =20 -The following IOCTL is defined: +The following IOCTLs are defined: =20 ``ioctl(file, HSMP_IOCTL_CMD, struct hsmp_message *msg)`` The argument is a pointer to a:: @@ -180,6 +188,26 @@ The following IOCTL is defined: __u16 sock_ind; /* socket number */ }; =20 +``ioctl(file, HSMP_IOCTL_GET_TELEMETRY_DATA, struct hsmp_telemetry_data *r= eq)`` + Atomically fetch the firmware metric (telemetry) table for a socket. + The ioctl copies the table in one shot, so unlike the metrics_bin + sysfs path it cannot return a torn snapshot and is not bounded by + PAGE_SIZE. Required for HSMP protocol version 7+ (e.g. Family 1Ah + Model 50h-5Fh, ~13 KB ``struct hsmp_metric_table_zen6``). Argument:: + + struct hsmp_telemetry_data { + __u64 buf; /* User pointer to destination buffer */ + __u32 size; /* Size of @buf, must equal firmware-reported table size = */ + __u16 sock_ind; /* Socket index */ + __u16 reserved; /* Reserved, must be zero */ + }; + + Userspace picks the layout matching the running protocol version + (``struct hsmp_metric_table`` for v6, ``struct hsmp_metric_table_zen6`` + for v7, queried via the ``protocol_version`` sysfs attribute) and + uses ``sizeof()`` of that struct for ``size``. The kernel rejects + a mismatched ``size`` or non-zero ``reserved`` with ``-EINVAL``. + The ioctl would return a non-zero on failure; you can read errno to see what happened. The transaction returns 0 on success. =20 diff --git a/arch/x86/include/uapi/asm/amd_hsmp.h b/arch/x86/include/uapi/a= sm/amd_hsmp.h index 438ac38d0dc8..50b28ccc7597 100644 --- a/arch/x86/include/uapi/asm/amd_hsmp.h +++ b/arch/x86/include/uapi/asm/amd_hsmp.h @@ -686,6 +686,40 @@ struct hsmp_metric_table_zen6 { struct hsmp_metric_table_zen6_ccd ccd[HSMP_F1A_M50_M5F_MAX_CCDS]; }; =20 +/** + * struct hsmp_telemetry_data - Request descriptor for HSMP telemetry IOCTL + * @buf: Input. Userspace pointer (encoded as __u64 to keep the layo= ut + * stable between 32-bit and 64-bit callers) to the destination + * buffer that receives the metric table. + * @size: Input. Size in bytes of the buffer pointed to by @buf. Must + * match the firmware-reported metric table size for the runni= ng + * HSMP protocol version (see below); any other value results = in + * -EINVAL. The kernel does not write this field back. + * @sock_ind: Input. Socket index from which the metric table is read. + * @reserved: Reserved for future use. Callers should set this to zero; + * future kernels may begin interpreting the field, so passing + * a non-zero value today is not forwards compatible. + * + * Placing @buf first lets all fields fall on their natural alignment under + * the surrounding #pragma pack(4), so the struct is a tight 16 bytes with + * the same wire layout on 32-bit and 64-bit userspace. + * + * The exact metric table layout depends on the HSMP protocol version repo= rted + * by the firmware: + * - Protocol version 6 -> struct hsmp_metric_table + * - Protocol version 7 -> struct hsmp_metric_table_zen6 + * + * Userspace queries the protocol version (e.g. via the protocol_version s= ysfs + * attribute) and uses sizeof() on the matching UAPI structure for both @s= ize + * and the allocation backing @buf. + */ +struct hsmp_telemetry_data { + __u64 buf; + __u32 size; + __u16 sock_ind; + __u16 reserved; +}; + /* Reset to default packing */ #pragma pack() =20 @@ -693,4 +727,13 @@ struct hsmp_metric_table_zen6 { #define HSMP_BASE_IOCTL_NR 0xF8 #define HSMP_IOCTL_CMD _IOWR(HSMP_BASE_IOCTL_NR, 0, struct hsmp_message) =20 +/* + * Fetch the firmware metric (telemetry) table for a given socket via the + * HSMP character device. This avoids the PAGE_SIZE limitation of the + * sysfs binary attribute path for tables larger than one page (such as the + * ~13 KB hsmp_metric_table_zen6 used on Family 1Ah Model 50h-5Fh). + */ +#define HSMP_IOCTL_GET_TELEMETRY_DATA \ + _IOWR(HSMP_BASE_IOCTL_NR, 1, struct hsmp_telemetry_data) + #endif /*_ASM_X86_AMD_HSMP_H_*/ diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/am= d/hsmp/hsmp.c index cf9392f99298..67f0074bb532 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.c +++ b/drivers/platform/x86/amd/hsmp/hsmp.c @@ -12,8 +12,11 @@ #include #include #include +#include #include +#include #include +#include =20 #include "hsmp.h" =20 @@ -287,7 +290,7 @@ static bool is_get_msg(struct hsmp_message *msg) return false; } =20 -long hsmp_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) +static long hsmp_ioctl_msg(struct file *fp, unsigned long arg) { int __user *arguser =3D (int __user *)arg; struct hsmp_message msg =3D { 0 }; @@ -303,6 +306,19 @@ long hsmp_ioctl(struct file *fp, unsigned int cmd, uns= igned long arg) if (msg.msg_id < HSMP_TEST || msg.msg_id >=3D HSMP_MSG_ID_MAX) return -ENOMSG; =20 + /* + * Sanitize the user-controlled msg_id against speculative + * execution. The bounds check above retires the out-of-range + * case with -ENOMSG, but a mispredicted branch can still let the + * CPU speculatively use msg_id as an index into + * hsmp_msg_desc_table[] (here and in validate_message() / + * is_get_msg() called downstream via hsmp_send_message()), and + * pull arbitrary kernel memory into the cache (Spectre v1, + * CVE-2017-5753). Clamp once into msg.msg_id so every downstream + * dereference sees the sanitized value. + */ + msg.msg_id =3D array_index_nospec(msg.msg_id, HSMP_MSG_ID_MAX); + switch (fp->f_mode & (FMODE_WRITE | FMODE_READ)) { case FMODE_WRITE: /* @@ -343,6 +359,105 @@ long hsmp_ioctl(struct file *fp, unsigned int cmd, un= signed long arg) return 0; } =20 +/* + * Fetch the firmware metric (telemetry) table for the requested socket and + * copy it to the userspace buffer described by the request. + * + * The metric table size is variable across HSMP protocol versions and on + * Family 1Ah Model 50h-5Fh exceeds PAGE_SIZE. Userspace must therefore + * supply a buffer at least the firmware-reported size in bytes. + */ +static long hsmp_ioctl_get_telemetry(struct file *fp, unsigned long arg) +{ + void __user *arguser =3D (void __user *)arg; + struct hsmp_telemetry_data req; + struct hsmp_socket *sock; + void __user *user_buf; + size_t tbl_size; + unsigned int sock_ind; + void *kbuf; + int ret; + + /* Telemetry data is read-only; require read access on the fd. */ + if (!(fp->f_mode & FMODE_READ)) + return -EPERM; + + if (copy_from_user(&req, arguser, sizeof(req))) + return -EFAULT; + + /* + * Reserved fields must be zero so future kernels can safely + * repurpose them without breaking already-deployed userspace. + */ + if (req.reserved) + return -EINVAL; + + if (!hsmp_pdev.sock || req.sock_ind >=3D hsmp_pdev.num_sockets) + return -ENODEV; + + tbl_size =3D hsmp_pdev.hsmp_table_size; + if (!tbl_size) + return -ENODEV; + + /* + * Userspace must size its buffer using the appropriate UAPI metric + * table struct for the running protocol version. Reject mismatched + * sizes so we never silently truncate or short-write. + */ + if (req.size !=3D tbl_size) + return -EINVAL; + + /* + * Sanitize the user-controlled socket index against speculative + * execution. The bounds check above retires the out-of-range case + * with -ENODEV, but a mispredicted branch can still let the CPU + * speculatively use sock_ind as an index into hsmp_pdev.sock[] and + * pull arbitrary kernel memory into the cache (Spectre v1, CVE-2017- + * 5753). array_index_nospec() turns the bounds check into a + * data-flow clamp so the speculative load is in-range too. + */ + sock_ind =3D array_index_nospec(req.sock_ind, hsmp_pdev.num_sockets); + sock =3D &hsmp_pdev.sock[sock_ind]; + if (!sock->metric_tbl_addr) + return -ENODEV; + + user_buf =3D u64_to_user_ptr(req.buf); + + /* + * The bounce buffer is overwritten in full by memcpy_fromio() inside + * hsmp_metric_tbl_read(); use kvmalloc() to avoid the zeroing cost of + * kvzalloc() on the ~13 KB allocation done on every ioctl call. + */ + kbuf =3D kvmalloc(tbl_size, GFP_KERNEL); + if (!kbuf) + return -ENOMEM; + + ret =3D hsmp_metric_tbl_read(sock, kbuf, tbl_size); + if (ret < 0) + goto out; + + if (copy_to_user(user_buf, kbuf, tbl_size)) + ret =3D -EFAULT; + else + ret =3D 0; + +out: + kvfree(kbuf); + return ret; +} + +long hsmp_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) +{ + switch (cmd) { + case HSMP_IOCTL_CMD: + return hsmp_ioctl_msg(fp, arg); + case HSMP_IOCTL_GET_TELEMETRY_DATA: + return hsmp_ioctl_get_telemetry(fp, arg); + default: + return -ENOTTY; + } +} + ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock, char *buf, size_t s= ize) { struct hsmp_message msg =3D { 0 }; --=20 2.34.1 From nobody Mon Jun 8 15:38:03 2026 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012011.outbound.protection.outlook.com [40.93.195.11]) (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 76DE83AFCE4; Thu, 28 May 2026 09:40:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.195.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779961233; cv=fail; b=kxdnX/uZiD3nFAkAnWwc3ORN7RJNkr1v1WZI43aZ/QmYBbC7Hp+qkrBPFN02cqpmbEAifuYP2wh0AZaTXp75Sgpf3+LgkStfL2TvKWuqXsEYDJTJxN59TpE2jILRjQ/Q3jCB6XSVMNKe2Gxnlp5lwNs0PNoJ0WME3P0MCQMhgzI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779961233; c=relaxed/simple; bh=r3YAuXP1aKDHdedEAIQ+a98JdvlsaEoBxt5U5KN3VUk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qxJuMvc3NB16h+JbZTZYSMbaX6VaaaXFArq4p0t5Ok4DWz1D0PACkQcIxkiP3dhwoCmOXUeSf/48eK22rw9CAYVYr5GYQQIXXDSKQcakDBUd8Q72G7iSwftMjSPwurUjqOE63QdKrib0AQZfkjQYWNSIatcHBhmNQVzQIO3gCXs= 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=YjYlZsZ0; arc=fail smtp.client-ip=40.93.195.11 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="YjYlZsZ0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NxPfa76gqpLdHfs7M458phzPShri1wUbyqDCy4gY+QqqJnpg2t0hFGy0YA0WvD8qSaDyEyXj7TPU1cC/KXAMa1FP02ZLtMqBBkm/nCnf9HIJxX2oWuf8hndhlnDZBJu/6NjzODbaKFFiwz0y0DA4nHA4OhLUoeWzdrIpagDO/coG/CCJq5CQWzJ4szu6Hm4Np9CH/8UVat8oEFwU47LS7zvnU46O4zA1HJoFyNO42eCsNtEIiFnzgfCDfpdJsnESRfKJ8Rp4M0QLjyDT6b+1zR00R011qMH3hUmL/FOLW1TAi11WQlrwTfnX6oCHKBWn2h+Pfyr3hEKxgJHZ5eTM8w== 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=RHXeXFWn+60PXIyf0oFx+yEmGUdUD7N+PeBrTvHoujw=; b=kCrfBUsAVXvOWTICSUsjR68VoU2cLxcQFjxpybJAvn2a6Q0efjhCXxaCqOKErUn28Xn+j59ljGwdRk5Dkn28TJV9OSWRBLlbA05bFYqsWWMlaAQ46W74RoEeC+1XsgikJNSeMMTraEOw9u29MO0sWYYHJ/QvHSX8tSCJu1RJXsDlg0v9v5JXA/DV7Uq1XAhy5+FeOFSUOWydRyF9GoLPvKG8Bzowj6GKiOfwKp2FmdGxE08hlruJhgOidDnxQ2vuLT5XvFiZ6vqo5YK3n1We5nB/fXTMKDP0jRFD5fBHwiFqcGfqwsZWAmUz+WegytTE/EKWJpRcxYSmJFomErPztw== 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=RHXeXFWn+60PXIyf0oFx+yEmGUdUD7N+PeBrTvHoujw=; b=YjYlZsZ0j/4rEOb+LNzd6xehqkdFN/THWmdMl3t5fYSFUqHCxd61kdBYJsqgPtBbbZ4seCUJF+moC2c3RVv9arfhWn43aGsGZbMoapqrAWml4I7bU3f2QJsqsA9sNOkLYCkCXQKQFKguOsvIWxTClgUn6N/Jgr11kSUR9XMDHKQ= Received: from CY5PR22CA0084.namprd22.prod.outlook.com (2603:10b6:930:80::28) by IA0PR12MB8907.namprd12.prod.outlook.com (2603:10b6:208:492::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.12; Thu, 28 May 2026 09:40:27 +0000 Received: from CH1PEPF0000AD80.namprd04.prod.outlook.com (2603:10b6:930:80:cafe::2c) by CY5PR22CA0084.outlook.office365.com (2603:10b6:930:80::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.71.13 via Frontend Transport; Thu, 28 May 2026 09:40:27 +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 CH1PEPF0000AD80.mail.protection.outlook.com (10.167.244.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Thu, 28 May 2026 09:40:27 +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, 28 May 2026 04:40:25 -0500 From: Muralidhara M K To: CC: , , Muralidhara M K , Muthusamy Ramalingam Subject: [PATCH v4 6/7] platform/x86/amd/hsmp: Enable HSMP_PROTO_VER7 metric tables on the ACPI driver via the IOCTL Date: Thu, 28 May 2026 15:09:53 +0530 Message-ID: <20260528093954.2461272-7-muralidhara.mk@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260528093954.2461272-1-muralidhara.mk@amd.com> References: <20260528093954.2461272-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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD80:EE_|IA0PR12MB8907:EE_ X-MS-Office365-Filtering-Correlation-Id: fc21b4e6-0fe9-4d94-cfcc-08debc9d268d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700016|376014|56012099006|18002099003|22082099003|11063799006|5023799004|3023799007; X-Microsoft-Antispam-Message-Info: Lo+VVLfPV4DBHdmvJRRLI5vc14AI6YyWkTSOmxItShOIBF56QZis8wnSmjraSvkK7gbywKJQQyhHXHLWwKTYKq9Gvv3mP3Vhsy96fwKvgYjWCbMrMICWrmOjKy8SGSluCpBUjqyUdGmYA37epEi7TUgAbT3lsjjVrRrzYyy7XXxqVY9jruYrrYM3ie1Rn9QKVYChQ3QY1Rc95JrKFwhn/Cdm+O6Ax2OCPJ5Gk1Qch7gV7AxpJJ01lMqoJO/uKs64kfrgFE4hwJSprMm80o7JplJqH1egEEtupDT38+YbkAEEcVhgQ+Bd3crnPBGTBzetMFKC006+kQxKyJs1YnWrAhVrsYTTqK6YkyCiP14kRIlOVwjzOPevAArHCBLGVJHJfLKfugESwQoS3zv2Hn8fbT3etTlwFMVGeHUTVHt/wi3koEgVSW0Z7XkrqU1zgJS2TmlXkAd7fBYDJawPa3quzsSW0yWMvJ2+GYzi80jSpz7T6Qlga4KDWKX9SAz93RIT0AJI6QtG1BTAt2ZO0NqbsXnwZ37hHeUuKjRRCzfNxhTY4923uU8EOwq8Q0+yP6aqGn6p/3bCjVwtLOnf36/2NsFekrQfmSgrrHR665S25kFeoHURtHXLMoAvPuHC24/QnSWM5n0Ic8mrgw4ClA8CWR/2yLQjalaz5yPhLr1SqyKXUzoPbTB0qrSIwu9rAE9wgTrULTVYjSb1lnSVgIs5/DPi0Rqj3Bjpso6P2BoDZFg= 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)(1800799024)(82310400026)(36860700016)(376014)(56012099006)(18002099003)(22082099003)(11063799006)(5023799004)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LIgWRM0F8OQWAjNwirw9amY+o/G4ZFTxfg0h1+SNsfnm6/cXKig38VZUkASsvMNFpNvqIVihiJ+Cjdqu7UvflY4o9V0/+a3ZOeYTso5G9YFHFnAwokZa3e27vE7T/DRWt0pqbqv/N+KBQoxYRvWapMPCCykGOkQ31uwD4ZOTGgp7M4Rw2XTTkiB+Bq6MCGzyh5sWWFL9Rh/ehUeo/68ECt1zEJqvuYzJAINUXQxeojE9J+lK7LgRK9kTgz09krLP8g2myPqXfL+GZwNC2haV9XYDvFg4W3pCs/UfMKQUz+cF3RvvjiDNEytZ231Y4kHrRR2v40J4iBCX8RdO/MUsSRJyc24hRjpIyjsBoXXIRas56XCaQwdJN+OIz9W25viIOeLAarn984tg6VoKL6ZaiiVAtrzbnATq04Zmg/9DFTEHbaP4h0UWuCRlF4WtyB/q X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2026 09:40:27.5574 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fc21b4e6-0fe9-4d94-cfcc-08debc9d268d 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: CH1PEPF0000AD80.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8907 Content-Type: text/plain; charset="utf-8" The ACPI driver currently prepares the per-socket metric table only on HSMP_PROTO_VER6. With protocol version 7 in use on Family 1Ah Model 50h-5Fh, userspace cannot reach the new ~13 KB hsmp_metric_table_zen6: hsmp_get_tbl_dram_base() is skipped, sock->metric_tbl_addr stays NULL, and the ioctl added earlier in this series has nothing to read. Widen the proto_ver gate in init_acpi() from '=3D=3D HSMP_PROTO_VER6' to '>=3D HSMP_PROTO_VER6' so the DRAM region is mapped and hsmp_pdev.hsmp_table_size is populated on protocol version 7 (and any future compatible version), making the ioctl path functional. hsmp_metric_tbl_acpi_read() now returns -EOPNOTSUPP whenever the running protocol version is not VER6. v7 userspace gets a clear, actionable error and a documented pointer to HSMP_IOCTL_GET_TELEMETRY_DATA; v6 userspace sees no change. The non-ACPI plat.c path is intentionally left untouched: it covers Family 1Ah Model 0h-Fh hardware fixed at protocol version 6, where the existing metrics_bin remains the supported interface. Co-developed-by: Muthusamy Ramalingam Signed-off-by: Muthusamy Ramalingam Signed-off-by: Muralidhara M K --- drivers/platform/x86/amd/hsmp/acpi.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/am= d/hsmp/acpi.c index 97ed71593bdf..8dc6b4a8bd27 100644 --- a/drivers/platform/x86/amd/hsmp/acpi.c +++ b/drivers/platform/x86/amd/hsmp/acpi.c @@ -238,13 +238,32 @@ static ssize_t hsmp_metric_tbl_acpi_read(struct file = *filp, struct kobject *kobj struct device *dev =3D container_of(kobj, struct device, kobj); struct hsmp_socket *sock =3D dev_get_drvdata(dev); =20 + /* + * metrics_bin is a sysfs binary attribute and is capped at PAGE_SIZE. + * It can therefore only carry the protocol version 6 metric table + * (struct hsmp_metric_table). Larger tables (HSMP_PROTO_VER7+, e.g. + * struct hsmp_metric_table_zen6 at ~13 KB used on Family 1Ah Model + * 50h-5Fh) do not fit; userspace on those systems must read the + * snapshot through HSMP_IOCTL_GET_TELEMETRY_DATA on /dev/hsmp. + * Surface the unsupported case here as -EOPNOTSUPP rather than + * silently truncating the snapshot. + */ + if (hsmp_pdev->proto_ver !=3D HSMP_PROTO_VER6) + return -EOPNOTSUPP; + return hsmp_metric_tbl_read(sock, buf, count); } =20 static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj, const struct bin_attribute *battr, int id) { - if (hsmp_pdev->proto_ver =3D=3D HSMP_PROTO_VER6) + /* + * Keep metrics_bin visible for HSMP_PROTO_VER7+ as well, so that + * userspace which expects the file to exist gets a clear + * -EOPNOTSUPP from the read handler instead of -ENOENT, and is + * pointed at HSMP_IOCTL_GET_TELEMETRY_DATA as the supported path. + */ + if (hsmp_pdev->proto_ver >=3D HSMP_PROTO_VER6) return battr->attr.mode; =20 return 0; @@ -491,7 +510,7 @@ static int init_acpi(struct device *dev) return ret; } =20 - if (hsmp_pdev->proto_ver =3D=3D HSMP_PROTO_VER6) { + if (hsmp_pdev->proto_ver >=3D HSMP_PROTO_VER6) { ret =3D hsmp_get_tbl_dram_base(sock_ind); if (ret) dev_info(dev, "Failed to init metric table\n"); --=20 2.34.1 From nobody Mon Jun 8 15:38:03 2026 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010050.outbound.protection.outlook.com [52.101.61.50]) (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 82DEB3AFB19; Thu, 28 May 2026 09:40:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.61.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779961235; cv=fail; b=oY1UZSVxxujlpnWA7xoZJX8fh/ZjgjOnp3K3/crICQNEXqi6WzWzWQLt4rEMOHHNmhC7h0nWaNKys/97JLSfOFFKF9ftrg0gItu1wm1qbpYlzXfclCMqEzZMtA5Kh1chVkoOxAdCWrEYIJyS+4KTrvtA4JWBNHtU++UXws85Dws= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779961235; c=relaxed/simple; bh=cFXmahLI4UDy1tmCkfjWYX/d2VVHJ3IcqiaJ3yNi8f4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FYTVZxbX/hk8fBnNO3cGEjorV2gG6Gve3E4ce17S8cFmMMC8LsuzGANnEd+CdVr2RZRvQwl9PRfA63T4XTlbQEUJLYFzjrPCZ/06G11MvEa/1a2ncPDsNY9V+mLxND0XjWWgAF1DSMtQv7tTdpeltbzU4EMfTsf1rppXNS1aBNM= 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=075f5/su; arc=fail smtp.client-ip=52.101.61.50 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="075f5/su" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LOO1aO1JiM4ZyNzRNnhypgyREkQrqG08TDYELjbjy6h+iuQEtyr3Uqgg61R1M1d/vxEhkJcbv+debvcFdO9MsrxwveBMwEgng+CyF5tIdBJEjp7zN9Pak2YecB7GAoG/ZsetfKBsK4OFjjA1fGXX5PUjrtac2fSXSaznRQzEXcYGKeAMbDiYpBQ0xpuQQBiVGvlLgWB+EauMRunslfGAASNlnPahngsXC4PYgT5r8fv/9It9hGULyPyrX1kExx7nKBh8IVv12Yz9/jlIn/TD25C/JPFg2aj+yLFrHV34j0HvPVm99AtmyRSc4Dbf9fN4P8Et3/CFqUpfPIcf4pU+7w== 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=vmQcyZIFV7yxsbWlMxnNVeD4jFcj7d7GGDwYbryuLy0=; b=fS2tbvPFBABVHsTnSp/20/b9PccVaNKQeMhpCBv+LR92IzL/p8RyF3LzZDNB5L2BZeKP3cV8ptAf7PcTRwwAakADSgrHe/gmW6ZeXHOlGd4kDFuKOlgzyE6qXaPUQzvtBB5wNo/OQfZrAbTu6DH9//ujPcDg+XTaeAbelWQR87RTYb2jpzoPfpGI6yph6n4zALUDju4DyTGPxd8eJTu45jrRNHcBX6X44Pf/7pamzRe8FP46cWK35bdePmo4IuaNoIvyA+IUiSKpGJ4L3ZhGgT4uXi+pETRrNJpGAA+F1kjDul43/CcyYDqJH9InJ0Vp0Hh4ZcerPVH85e+l7bICjA== 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=vmQcyZIFV7yxsbWlMxnNVeD4jFcj7d7GGDwYbryuLy0=; b=075f5/su96PLmgtvZDgIj/h3OAkIDZE4OqbRSKJsWEyHiYGM6FOs2Lb48jePH0hghX6InhfW9F9PxWn/cjuhTok0MFnWnkjKkjq/R+pmrNS5KsQItqDojIn7V4p/lfWXq/fNZipEoXO/MljMa4jAglx98jPymTHR7dGwmpurCGQ= Received: from CH2PR02CA0001.namprd02.prod.outlook.com (2603:10b6:610:4e::11) by CH8PR12MB9839.namprd12.prod.outlook.com (2603:10b6:610:274::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.13; Thu, 28 May 2026 09:40:30 +0000 Received: from CH1PEPF0000AD7E.namprd04.prod.outlook.com (2603:10b6:610:4e:cafe::68) by CH2PR02CA0001.outlook.office365.com (2603:10b6:610:4e::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.71.13 via Frontend Transport; Thu, 28 May 2026 09:40:30 +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 CH1PEPF0000AD7E.mail.protection.outlook.com (10.167.244.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Thu, 28 May 2026 09:40:29 +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, 28 May 2026 04:40:27 -0500 From: Muralidhara M K To: CC: , , Muralidhara M K , Muthusamy Ramalingam Subject: [PATCH v4 7/7] platform/x86/amd/hsmp: Make metric table read locking use guard(mutex) Date: Thu, 28 May 2026 15:09:54 +0530 Message-ID: <20260528093954.2461272-8-muralidhara.mk@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260528093954.2461272-1-muralidhara.mk@amd.com> References: <20260528093954.2461272-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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD7E:EE_|CH8PR12MB9839:EE_ X-MS-Office365-Filtering-Correlation-Id: 561121fb-1518-405c-381b-08debc9d27bb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700016|376014|56012099006|18002099003|11063799006|22082099003; X-Microsoft-Antispam-Message-Info: p58XISyTHHwrN7xbl1rYnj4KQWN71gqLpyXxF7U+IQuSboI8kDarV33PknOO810kPv760gr1C7aWtL1eoc/TghwbvYcRtrmVtiR1oZ7dQaQWFLbRZPmT+Ps0TNoyAK+KSRUgobMvhOZYErRx7Tkip9Ms9skZPXUkyFgsCICWH0bR8x01g7zLtYifi8puHLtQI0yseYYzkjaSt/m26mcnC1oSvEaDMqernESsH+oYqVaS1gNDCHxOTOBPNyL2wiPnlIGaEMTjgNgUjXGm+VD2QCwByzSNv0tee9AEyDjzxz6OrO/FyH/AOXd4YbHyZJ8DSPksQQ/VZcYRoYDYqAbARvnHDzyXYdDHdMddJwoivZ7LdB/85NKb9CJvL82EHWa1NmC9EZNvkfI5svQE3nqq1P2XkY8S62mqyXA+MnRPUL7p0gLSMC7CvwiQGGOj1SAUHirMwYBE7l1Dxkv00wBvj/92BYTPo162mUuh/mX7OkC9lUJUseokk397Ve5w8pWAzpMMlTVGJ5c8onV/a8ncizB7SwKlZgqEKADGIsdlA5bp+g+AXIMktCG5IJnplAlaydjo6CVwNqNBKx1L31FtMCV5PxI/DDjTCoR9ZxmvdLZucKdia+GJZWhIvwbihULp+ZKDTMt7GrWBS6xuBUoqt1M5TFPfpH7+8hFeVKaY2CFbVnNbXfcKaH5zdMJQsmzP0blkZZxx3y56uA+S0R48iVinun3yDtW9qvV14aOHWXA= 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)(1800799024)(82310400026)(36860700016)(376014)(56012099006)(18002099003)(11063799006)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NaQq6WRlIjf5JBhFDvHw6OYg4CBrCiKA7akRg3ByI9ztOTkLKwhXIl8r9QKZL8Ad0Jv3ugClpQO5W7h5+C4tuR01HEIK9giyq10j/U5qpQPNiBKCofwf9t+rnufHOx4DHERiHNYqkP6ruZYKvgJpXREiMv+ULpuXYKG0IximeBnpdENxufOC9E5y5Uzfbzh+0QO0c0z0Q3S2ehRushZWlTLckyC7FPKTs7/XIaRanOh3cwHWArH7U0OwzB4dZA+neoFYHT2kHupQSRxBpmu9CW7cZN4fsrtrO0VrxKYhZpAnhhKdcFgzXXdbHbvRlhMghv+AvsuknLn59ZhpOZK+1kwNlX4PKMUc6Zge1YQfam4l9QH/2rDkhesI4caNNIgi9lKLlkT2GbDwTD5G/ejL11QM+I12JEmdr1QHGUB7Q/awvO/UM+ErOBXNpPsKp2zx X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2026 09:40:29.5117 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 561121fb-1518-405c-381b-08debc9d27bb 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: CH1PEPF0000AD7E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH8PR12MB9839 Content-Type: text/plain; charset="utf-8" hsmp_metric_tbl_read() refreshes the SMU-side metric table and then memcpy_fromio()'s the result. Without serialization, two parallel readers can interleave the refresh and the copy and the caller observes a torn (mixed old/new) snapshot. Add a per-socket metric_tbl_lock so the refresh-and-copy sequence is atomic from userspace's point of view. Use scoped guard(mutex) so the lock is released on every return path without hand-written goto chains, and initialize the mutex with devm_mutex_init() so no explicit mutex_destroy() cleanup is required. Initialize the mutex before devm_ioremap() so the invariant "sock->metric_tbl_addr !=3D NULL implies metric_tbl_lock is usable" holds on every error exit. Both callers of hsmp_get_tbl_dram_base() (init_acpi() and init_platform_device()) intentionally only log a failure and continue probing, so initializing the mutex after a successful ioremap would leave sock->metric_tbl_addr populated with an uninitialized lock, and the next hsmp_metric_tbl_read() would take guard(mutex)() on garbage memory. With the order swapped, a devm_mutex_init() failure returns early before metric_tbl_addr is ever set, and the existing NULL check in hsmp_metric_tbl_read() keeps rejecting the read with -ENOMEM as before. Co-developed-by: Muthusamy Ramalingam Signed-off-by: Muthusamy Ramalingam Signed-off-by: Muralidhara M K --- drivers/platform/x86/amd/hsmp/hsmp.c | 20 ++++++++++++++++++++ drivers/platform/x86/amd/hsmp/hsmp.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/am= d/hsmp/hsmp.c index 67f0074bb532..fda57225939c 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.c +++ b/drivers/platform/x86/amd/hsmp/hsmp.c @@ -479,6 +479,7 @@ 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 + guard(mutex)(&sock->metric_tbl_lock); ret =3D hsmp_send_message(&msg); if (ret) return ret; @@ -495,6 +496,24 @@ int hsmp_get_tbl_dram_base(u16 sock_ind) phys_addr_t dram_addr; int ret; =20 + /* + * Initialize the per-socket lock before anything that can set + * sock->metric_tbl_addr to a non-NULL value. hsmp_metric_tbl_read() + * gates on sock->metric_tbl_addr being non-NULL and then takes + * metric_tbl_lock unconditionally; both callers of this function + * (init_acpi() and init_platform_device()) intentionally only log + * a failure here and continue probing, so an init order that left + * metric_tbl_addr populated while devm_mutex_init() failed would + * leave the read path locking an uninitialized mutex. Doing the + * mutex init first preserves the invariant "metric_tbl_addr !=3D + * NULL implies the lock is usable" on every error exit. + */ + ret =3D devm_mutex_init(sock->dev, &sock->metric_tbl_lock); + if (ret) { + dev_err(sock->dev, "Failed to initialize metric table lock\n"); + return ret; + } + msg.sock_ind =3D 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; @@ -524,6 +543,7 @@ int hsmp_get_tbl_dram_base(u16 sock_ind) dev_err(sock->dev, "Failed to ioremap metric table addr\n"); return -ENOMEM; } + return 0; } EXPORT_SYMBOL_NS_GPL(hsmp_get_tbl_dram_base, "AMD_HSMP"); diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/am= d/hsmp/hsmp.h index e7f051475728..f7b1cbf19932 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 @@ -41,6 +42,8 @@ struct hsmp_socket { struct bin_attribute hsmp_attr; struct hsmp_mbaddr_info mbinfo; void __iomem *metric_tbl_addr; + /* Serializes concurrent metric table refreshes from the sysfs path */ + struct mutex metric_tbl_lock; void __iomem *virt_base_addr; struct semaphore hsmp_sem; char name[HSMP_ATTR_GRP_NAME_SIZE]; --=20 2.34.1