Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.201.21 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796121092; b=h5l6eZD4HslgWvFmqRP1FNPUOM2o4Y1RBOaxieKlyjJrIXA/fxsOohv4R+NJUpN32fKO jIZCm+kKhA3JaGc8J6ze8TVi65Y5fvAeXn52QHwmYf3RUEe5TNa04xJd1ZsFtAKZnFLmb ZSYQHRnDcEByHq/l/TjjBUjwxNuslmLQSV8+py8qVkfyXc89MwfRXzcZ7zjogHRK0ik+W NvMzWJmesz9wfyzkeVOMoup7erR7gbT99hlKXJLedutEvzVcjBiQzbz70VnIdz4vi9Yj9 XFMyD+FBgHzLJdTZ8C8/bJOzYo4TxYNxNzWzhFaVTIVO4rV6fU5PUtQXF6jqTZ3B8ZA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796121092; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy:X-EOPAttributedMessage:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=Z+ZX/hmzfQJVwIKlFvZWJAEeLwUBKrpkQ62MaU6Ev1g=; b=VZ0u481XCuxd0bX0o1uA/ssFCI4pU7yq182VsOrDXR0wP9fSxE0UsrnF4Vkqh/JCYmW4 cRrmnc9GgQRC7TILzUrQfONrE+q/w/cx7XAL+LJq8CYc74HTpJxlJZvxoja/cI/ZShzzf zTXog26Bh84iwGVv3yRUCt9QbbYwe6/k6USjR8/fKWbluhR7Ev+yqYphLrCIXZu2K6lEp vM73RueNmVZbbfPJNdrKDcm/IcKWo9DA9T0kWxuAppfFUFpPdVYWiBoI04ZLPiGqL/7mA Fl0cug1x46Eq5HG9cFGASgftktWYBJiM9ss74QBQGJSKr2R4BPraqOvG6+KaWpsUPcg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=YXAmH10p; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.201.21 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013021.outbound.protection.outlook.com [40.93.201.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9974A606A320; Tue, 1 Dec 2026 10:31:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9974A606A320 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, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=YXAmH10p ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AWR26ULWY9uXGbxA7JhgHnFb4JpjEmD3leectBdDdWHXS1jRtTO9uJrk1Xcpt+woPOYa9jFTt2y9E3CFgR9q0RA/uf4nJt60xSktHtAdBfrTf25pxcTAnNZOHos0smpQa/38QD379YMocuQLHXs6rOENoC2ffJBNj0irec3+j8XF3VqaNG439praBXHwOwiEKDY8mnMlJ3Tw1Hl0TYzvf5z+smraztZpbuEkFVjfvz//8yJNJpWIpfwiViO6n0YjCtO/Yw3H4xJ9wO7pfNTbazSH4Y4oJv2Y7slqy/UaHin4SjFWyMA5oykTArqtN+qQOxHiaF031YKQhw0/WULarg== 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=Z+ZX/hmzfQJVwIKlFvZWJAEeLwUBKrpkQ62MaU6Ev1g=; b=MuXuztc3fBQVr89bzEEWV9QVZzynZVoo6l5YrwLB+ZsOruhsNxMceZFkmVdbINFaJ+fbFej7M3/tqPCCnXDD5BRiaAaUA7n7O0cEmebqutqm0ipVvxdn16NOclumsDoAc6mSjXQhWxWRpDNx45QXmEkOe86Q6WVxT+00bPwedQFQt0xdi4W1w/HbhOyD4hd4SpzpaKcH0+f7Ix0lqIvmUbLZAfpLtP65sUBth1iHeTOzFtT4bIcPoLkgIw0mErdNLMvGujthOXIcznbYC9Y0hjHJ4sOZMh3F/++8zcdG7nbHZ+H2PZsZfTbA77S3EVQFYFeHQu1uS/Acfcbl35gmbA== 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=Z+ZX/hmzfQJVwIKlFvZWJAEeLwUBKrpkQ62MaU6Ev1g=; b=YXAmH10ph2R/r30uEW10mQXhofLSWv+jMjyL9gJtbOm4wEcnuLAUeAeGcTcgVRFrEr21FJ9HvnynCxALvzm5gFSQjbfN3Eh84/EwKGj0VRnqXOKzlHFO0h1SyDtjxC6J9l7d1esSc3atHuf13qqQbiu76v+0EAruJZ3WTVthE9o= Received: from MN2PR16CA0053.namprd16.prod.outlook.com (2603:10b6:208:234::22) by BL1PR12MB5922.namprd12.prod.outlook.com (2603:10b6:208:399::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Tue, 1 Dec 2026 10:31:26 +0000 Received: from IA0PEPF00000041.namprd04.prod.outlook.com (2603:10b6:208:234:cafe::4) by MN2PR16CA0053.outlook.office365.com (2603:10b6:208:234::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Tue, 1 Dec 2026 10:31:26 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; 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 IA0PEPF00000041.mail.protection.outlook.com (10.167.249.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Tue, 1 Dec 2026 10:31:26 +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.57; Tue, 1 Dec 2026 04:31:24 -0600 From: Muralidhara M K To: CC: , , , Muralidhara M K Subject: [PATCH v3 2/2] platform/x86/amd/hsmp: Report raw SMU mailbox status via smu_response Date: Tue, 1 Dec 2026 16:01:02 +0530 Message-ID: <20261201103102.601993-3-muralidhara.mk@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261201103102.601993-1-muralidhara.mk@amd.com> References: <20261201103102.601993-1-muralidhara.mk@amd.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA0PEPF00000041:EE_|BL1PR12MB5922:EE_ X-MS-Office365-Filtering-Correlation-Id: 26c4ca1e-3168-4406-7a66-08df4f9640eb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|23010399003|1800799024|82310400026|376014|22082099003|18002099003|10067099003|56012099006|261026121527099003|261026135527099003|261026140227099003|261026130827099003|261028144727099003|261022075727099003|261022115727099003|261021123027099003|261022113327099003|261022105027099003|261021121427099003|261021130227099003|261021133027099003|261021135927099003|261102123227099003|261102130727099003|261009223027099003|5023799004|11063799006|6133799003|3023799007; X-Microsoft-Antispam-Message-Info: WTO+9C52msjbxwVPRGWYCI0G9x1Q80buVMUDfjdAJBiNWhFKAtaS1LiwIk9kr57uFDJtGd2v1f56f/FW9HXNdr1SpnDKBsxrwCoLB3Wpzirz8qSTjwWaz3GobZ8o7GKnxDBy3qjanB4WYPfh0muO8+m5XDfYcnLyo2YFo0lIXVahB2YOvl3MVDmXdxgO4uajf4C/kprwiu7qg2nupzPcw43lPavKan0UFlEY88S2WWMxG91lti2hji4d8KtJo6dWqz4wqVa9WFgGxu8jQQa00Uc8YAHOyTIpPXAnBIne3hHhJnRhHqdUye6tZysFqUWkkK3C9REcpP1+XNbxmKreKQl5s0fEUkYno/aZfwt5bx2bDFjcLcVfeN/znhtnFjzTXNlFUq7DBdjUExbXKWjp8X5UjqGDFngsiJz9aZTicGoNXiw++8PhDcHVAkPCAEff7gT7FnAMJFPyBE6G+fKMlzjLdlewSqqcROkfNJl32lApR2ZrauothcmjwENkqRhPH1isfkwqKtopvhfR07T8pl7LIbHvTafyofS41YLXw5OlOINABN19OF0YqIAJcj6rMP80r3u8ypBQpgOOiMDS96kpjkA9AkRQJPuU7HwlmmMSGb2jbVjbQf7WqpFtlimM+bUpmwQ5rIpJeYyuz7Dh0xTeuxdJ8V1R9SO8Ell6LMAyzC0Azz4k5o5E55XL/6Inhq6s0n5WM8abPDU6tWpf1A== 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)(23010399003)(1800799024)(82310400026)(376014)(22082099003)(18002099003)(10067099003)(56012099006)(261026121527099003)(261026135527099003)(261026140227099003)(261026130827099003)(261028144727099003)(261022075727099003)(261022115727099003)(261021123027099003)(261022113327099003)(261022105027099003)(261021121427099003)(261021130227099003)(261021133027099003)(261021135927099003)(261102123227099003)(261102130727099003)(261009223027099003)(5023799004)(11063799006)(6133799003)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SEKJtT/xC+q1Fmcc3H0uOpyYV745rWyLTV6806Rt6DgP30jhQruRuUvjQUsZ7D6qJ639hqzI1DM0I0ubyy/3bCpIpmfoSxgRpOimv3z+Gw/6VaVooocrxRgdTXgP/DGddnD6gBwemz/jOcYycLCCNfAO49qZ8bH31UbeEOQ95m1KTzvPqAUlPN33b2Wdj7Fbh2JDyXDPvwHBPp0jAFBvnXmrYUHtm3W9qd+CPbJQ2J4RnXyZEUeLnfy/98MMARD88YjgwG0xJHOF+aJ29qbBZFGO+m1gy5tFxNmHjl7QFwDZEsvU6baS8EFQxA33d5sK25+CaU92qkFvhGGpuOCvCcl3bsSwRwVXAOpqVLLBhNCR89itJVa+rB9qAxRL2MTBCp+6gwavaytRgxCw0H6P0ldvhjeXTpLX6WxvzvcLqxeU8qsTBT0YmrHE+e0m3+Or X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 10:31:26.2421 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 26c4ca1e-3168-4406-7a66-08df4f9640eb 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: IA0PEPF00000041.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5922 Add smu_response to struct hsmp_message and struct hsmp_telemetry_data, set from the polled SMU mailbox status register and surfaced to userspace on every HSMP_IOCTL_CMD and HSMP_IOCTL_GET_TELEMETRY_DATA call. Both fields fit in existing spare bytes, keeping sizeof() and the HSMP_IOCTL_CMD command number unchanged. HSMP_IOCTL_GET_TELEMETRY_DATA is now _IOWR, since the kernel writes smu_response back into the request struct. Update Documentation/arch/x86/amd_hsmp.rst to match. Signed-off-by: Muralidhara M K --- Documentation/arch/x86/amd_hsmp.rst | 23 +++++- arch/x86/include/uapi/asm/amd_hsmp.h | 25 ++++-- drivers/platform/x86/amd/hsmp/hsmp.c | 111 ++++++++++++++++----------- 3 files changed, 106 insertions(+), 53 deletions(-) diff --git a/Documentation/arch/x86/amd_hsmp.rst b/Documentation/arch/x86/amd_hsmp.rst index c483c68dcfad..081082b9c523 100644 --- a/Documentation/arch/x86/amd_hsmp.rst +++ b/Documentation/arch/x86/amd_hsmp.rst @@ -193,8 +193,20 @@ The following IOCTLs are defined: __u16 response_sz; /* Number of expected output/response words */ __u32 args[HSMP_MAX_MSG_LEN]; /* argument/response buffer */ __u16 sock_ind; /* socket number */ + __u16 smu_response; /* Output: raw SMU mailbox status */ }; + ``msg`` is copied back to userspace after every call, regardless of + whether the ioctl succeeds or fails, so ``smu_response`` is always + visible: 1 means the SMU accepted the message, and any other + nonzero value is an SMU-specific error code. 0 (HSMP_STATUS_NOT_READY) + is overloaded: it means either the message was rejected before + dispatch (e.g. an invalid msg_id or argument count, or an unprobed + socket) and never reached the SMU at all, or it was written to the + mailbox but the SMU never responded before the driver's internal + timeout (reported as ``-ETIMEDOUT``). Callers cannot tell these two + 0 cases apart from ``smu_response`` alone. + ``ioctl(file, HSMP_IOCTL_GET_TELEMETRY_DATA, struct hsmp_telemetry_data *req)`` Atomically fetch the firmware metric (telemetry) table for a socket. The ioctl copies the table in one shot, so unlike the metrics_bin @@ -206,14 +218,19 @@ The following IOCTLs are defined: __u64 buf; /* User pointer to destination buffer */ __u32 size; /* Size of @buf in bytes */ __u16 sock_ind; /* Socket index */ - __u16 reserved; /* Reserved, must be zero */ + __u16 smu_response; /* Output: raw SMU mailbox status */ }; ``size`` must be non-zero and no larger than the table size firmware reports for that socket; a larger value is rejected with ``-EINVAL`` rather than short-written, and a smaller one returns the leading - ``size`` bytes of the snapshot. A non-zero ``reserved`` is also - rejected with ``-EINVAL``. + ``size`` bytes of the snapshot. ``req`` is copied back to userspace + with ``smu_response`` filled in, using the same values as ``msg``'s + ``smu_response`` above, on every call that reaches the point of + reading ``req`` from userspace, including failures from there on. + The one exception is a request on an fd not opened for reading, + which is rejected with ``-EPERM`` before ``req`` is read at all, so + there is nothing to copy back. The table layout depends on the protocol version, which userspace reads from the ``protocol_version`` sysfs attribute. On version 6 diff --git a/arch/x86/include/uapi/asm/amd_hsmp.h b/arch/x86/include/uapi/asm/amd_hsmp.h index dcbe89dc4d2b..9f94aa0ee62b 100644 --- a/arch/x86/include/uapi/asm/amd_hsmp.h +++ b/arch/x86/include/uapi/asm/amd_hsmp.h @@ -88,6 +88,13 @@ struct hsmp_message { __u16 response_sz; /* Number of expected output/response words */ __u32 args[HSMP_MAX_MSG_LEN]; /* argument/response buffer */ __u16 sock_ind; /* socket number */ + /* + * Output: raw SMU mailbox status. 1 = accepted; any other nonzero + * value is an SMU-specific error code. 0 means either the message + * never reached the SMU, or it did and the SMU never responded + * (-ETIMEDOUT); the two are not distinguishable from this field. + */ + __u16 smu_response; }; enum hsmp_msg_type { @@ -644,9 +651,13 @@ struct hsmp_metric_table { * short-written. A smaller value returns the leading @size bytes * of the snapshot. 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. + * @smu_response: Output. Raw SMU mailbox status from the HSMP_GET_METRIC_TABLE + * message that refilled the table. 1 = success; any other + * nonzero value is an SMU-specific error code. 0 means + * either the message never reached the SMU, or it did and + * the SMU never responded; the two are not distinguishable + * from this field. Callers should set this to zero on + * input; the kernel overwrites it before returning. * * 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 @@ -662,7 +673,7 @@ struct hsmp_telemetry_data { __u64 buf; __u32 size; __u16 sock_ind; - __u16 reserved; + __u16 smu_response; }; /* Reset to default packing */ @@ -678,11 +689,11 @@ struct hsmp_telemetry_data { * sysfs binary attribute path for tables larger than one page (such as the * ~13 KB table used by HSMP protocol version 7). * - * The direction is _IOW because the kernel only reads the request struct; - * the table itself is written to the buffer that @buf points at. + * _IOWR: the kernel reads the request struct and writes smu_response + * back into it; the table itself goes through @buf. */ #define HSMP_IOCTL_GET_TELEMETRY_DATA \ - _IOW(HSMP_BASE_IOCTL_NR, 1, struct hsmp_telemetry_data) + _IOWR(HSMP_BASE_IOCTL_NR, 1, struct hsmp_telemetry_data) /** * enum hsmp_client_message_ids - Ryzen Master SMC (RMSMC) message IDs diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c index 635e6d5723ac..2b83bd334499 100644 --- a/drivers/platform/x86/amd/hsmp/hsmp.c +++ b/drivers/platform/x86/amd/hsmp/hsmp.c @@ -173,6 +173,9 @@ static int __hsmp_send_message(struct hsmp_socket *sock, struct hsmp_message *ms mbinfo = &sock->mbinfo; + /* Default to "not sent" until the mailbox status is actually polled */ + msg->smu_response = HSMP_STATUS_NOT_READY; + /* Clear the status register */ mbox_status = HSMP_STATUS_NOT_READY; ret = sock->amd_hsmp_rdwr(sock, mbinfo->msg_resp_off, &mbox_status, HSMP_WR); @@ -229,6 +232,9 @@ static int __hsmp_send_message(struct hsmp_socket *sock, struct hsmp_message *ms usleep_range(1000, 2000); } + /* Report the raw mailbox status regardless of outcome */ + msg->smu_response = mbox_status; + if (unlikely(mbox_status == HSMP_STATUS_NOT_READY)) { dev_err(sock->dev, "Message ID 0x%X failure : SMU timeout (status = 0x%X)\n", msg->msg_id, mbox_status); @@ -340,6 +346,10 @@ static int hsmp_send_message_locked(struct hsmp_message *msg) if (!msg) return -EINVAL; + + /* Default to "not sent" until __hsmp_send_message() runs */ + msg->smu_response = HSMP_STATUS_NOT_READY; + ret = validate_message(msg); if (ret) return ret; @@ -471,6 +481,9 @@ static long hsmp_ioctl_msg(struct file *fp, unsigned long arg) if (copy_struct_from_user(&msg, sizeof(msg), arguser, sizeof(struct hsmp_message))) return -EFAULT; + /* Default to "not sent" until hsmp_send_message() runs */ + msg.smu_response = HSMP_STATUS_NOT_READY; + /* * The client message set has no per-message descriptor table to * bounds-check msg_id against or index into, and no per-message @@ -482,8 +495,10 @@ static long hsmp_ioctl_msg(struct file *fp, unsigned long arg) if (plat_desc->msg_desc) { /* Rejects out-of-range and reserved msg_ids */ desc = get_msg_desc(msg.msg_id); - if (!desc) - return -ENOMSG; + if (!desc) { + ret = -ENOMSG; + goto out; + } /* * is_get_msg() below reads msg.args[0] for HSMP_SET_GET @@ -492,8 +507,10 @@ static long hsmp_ioctl_msg(struct file *fp, unsigned long arg) * the fd-mode gate read an argument slot the request does * not actually carry. */ - if (msg.num_args != desc->num_args) - return -EINVAL; + if (msg.num_args != desc->num_args) { + ret = -EINVAL; + goto out; + } switch (fp->f_mode & (FMODE_WRITE | FMODE_READ)) { case FMODE_WRITE: @@ -501,16 +518,20 @@ static long hsmp_ioctl_msg(struct file *fp, unsigned long arg) * Device is opened in O_WRONLY mode * Execute only set/configure commands. */ - if (is_get_msg(desc, &msg)) - return -EPERM; + if (is_get_msg(desc, &msg)) { + ret = -EPERM; + goto out; + } break; case FMODE_READ: /* * Device is opened in O_RDONLY mode * Execute only get/monitor commands. */ - if (!is_get_msg(desc, &msg)) - return -EPERM; + if (!is_get_msg(desc, &msg)) { + ret = -EPERM; + goto out; + } break; case FMODE_READ | FMODE_WRITE: /* @@ -519,30 +540,23 @@ static long hsmp_ioctl_msg(struct file *fp, unsigned long arg) */ break; default: - return -EPERM; + ret = -EPERM; + goto out; } } ret = hsmp_send_message(&msg); - if (ret) - return ret; - /* - * The client message set has no per-message response_sz to check - * here (desc is NULL); validate_message() already bounded - * msg.response_sz. - */ - if ((desc ? desc->response_sz : msg.response_sz) > 0) { - /* Copy results back to user for get/monitor commands */ - if (copy_to_user(arguser, &msg, sizeof(struct hsmp_message))) - return -EFAULT; - } +out: + /* Copy back even on failure, so smu_response is always visible */ + if (copy_to_user(arguser, &msg, sizeof(struct hsmp_message))) + return -EFAULT; - return 0; + return ret; } static ssize_t hsmp_metric_tbl_read_locked(struct hsmp_socket *sock, char *buf, - size_t size); + size_t size, u16 *smu_response); /* * Fetch the firmware metric (telemetry) table for the requested socket and @@ -558,6 +572,7 @@ static long hsmp_ioctl_get_telemetry(struct file *fp, unsigned long arg) void *kbuf __free(kvfree) = NULL; void __user *arguser = (void __user *)arg; struct hsmp_telemetry_data req; + u16 smu_response = HSMP_STATUS_NOT_READY; struct hsmp_socket *sock; void __user *user_buf; size_t tbl_size; @@ -571,13 +586,6 @@ static long hsmp_ioctl_get_telemetry(struct file *fp, unsigned long arg) 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; - user_buf = u64_to_user_ptr(req.buf); /* @@ -594,8 +602,10 @@ static long hsmp_ioctl_get_telemetry(struct file *fp, unsigned long arg) * which would leave a socket unbind waiting for the write lock. */ scoped_guard(rwsem_read, &hsmp_sock_rwsem) { - if (!hsmp_pdev.sock || req.sock_ind >= hsmp_pdev.num_sockets) - return -ENODEV; + if (!hsmp_pdev.sock || req.sock_ind >= hsmp_pdev.num_sockets) { + ret = -ENODEV; + break; + } /* * Sanitize the user-controlled socket index against speculative @@ -609,12 +619,16 @@ static long hsmp_ioctl_get_telemetry(struct file *fp, unsigned long arg) */ sock_ind = array_index_nospec(req.sock_ind, hsmp_pdev.num_sockets); sock = &hsmp_pdev.sock[sock_ind]; - if (!sock->metric_tbl_addr) - return -ENODEV; + if (!sock->metric_tbl_addr) { + ret = -ENODEV; + break; + } tbl_size = sock->metric_tbl_size; - if (!tbl_size) - return -ENODEV; + if (!tbl_size) { + ret = -ENODEV; + break; + } /* * A request shorter than the firmware table is served with the @@ -624,8 +638,10 @@ static long hsmp_ioctl_get_telemetry(struct file *fp, unsigned long arg) * rejected rather than short-written, so a caller can never * mistake a partial copy for a full one. */ - if (!req.size || req.size > tbl_size) - return -EINVAL; + if (!req.size || req.size > tbl_size) { + ret = -EINVAL; + break; + } /* * The bounce buffer is overwritten in full by memcpy_fromio() @@ -634,12 +650,19 @@ static long hsmp_ioctl_get_telemetry(struct file *fp, unsigned long arg) * on every ioctl call. */ kbuf = kvmalloc(tbl_size, GFP_KERNEL); - if (!kbuf) - return -ENOMEM; + if (!kbuf) { + ret = -ENOMEM; + break; + } - ret = hsmp_metric_tbl_read_locked(sock, kbuf, tbl_size); + ret = hsmp_metric_tbl_read_locked(sock, kbuf, tbl_size, &smu_response); } + /* Report the raw SMU mailbox status back to userspace */ + req.smu_response = smu_response; + if (copy_to_user(arguser, &req, sizeof(req)) && ret >= 0) + ret = -EFAULT; + if (ret < 0) return ret; @@ -667,7 +690,7 @@ long hsmp_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) * write while they bring sockets up and tear them down. */ static ssize_t hsmp_metric_tbl_read_locked(struct hsmp_socket *sock, char *buf, - size_t size) + size_t size, u16 *smu_response) { struct hsmp_message msg = { 0 }; int ret; @@ -699,6 +722,8 @@ static ssize_t hsmp_metric_tbl_read_locked(struct hsmp_socket *sock, char *buf, guard(mutex)(&sock->metric_read_lock); ret = hsmp_send_message_locked(&msg); + if (smu_response) + *smu_response = msg.smu_response; if (ret) return ret; memcpy_fromio(buf, sock->metric_tbl_addr, size); @@ -710,7 +735,7 @@ ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock, char *buf, size_t size) { guard(rwsem_read)(&hsmp_sock_rwsem); - return hsmp_metric_tbl_read_locked(sock, buf, size); + return hsmp_metric_tbl_read_locked(sock, buf, size, NULL); } EXPORT_SYMBOL_NS_GPL(hsmp_metric_tbl_read, "AMD_HSMP"); -- 2.34.1