Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.196.62 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796142570; b=zGs04synMlwHnG4xIvnYjgTyai2hkJnRZK1VS2ONzSddmYGxOoPqlYsGT30EGcVFQgMT OGQT1g3e2bbdyob0u1LWbsRdMaJlkDNBg7NjZcV9IXWAVdbjacNjpCcKsi9Byvfy1I3bO WZoDjop+jH/0pVVq8wFbY61qJt5GfdTk+Y3fxsrJJDxHLJpGkf2wwNrFEF2Gr+w0pn7hm MCCiX2lYKhpcmo/jXboNDZpBai+CmvHydN4KTWpeM8Dy/5L8ab09YucNKCizgCpukIj4S vVQWir6WgkwhXHdtIN8zEpiOqV6Z6Z1ahpbtg0xtZZuBBtT7m5HIyWVgNN57rOpY/yQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796142570; h=DMARC-Filter:DKIM-Signature:Received:Received:Message-ID:Date: User-Agent:Subject:Content-Language:To:Cc:References:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-ClientProxiedBy:MIME-Version: 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-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=KECaawtPNRlnlsMZfeYlVe3wsbAUtzA/Ovvt2VByiBs=; b=iOl1jMkisz+iARfNp8BVAdy67jQU/E/Ds53i1vB3VAHbisVVTkrROcqEml39R0VNMhu6 7jNOPPW/Mwcq1Zl3xcouufxOz+a6LzhzAxQK3pvALso6cnxaclN+s9p/btGPiNYsYpkPu wRJPL/aOrnVo/Z/5CYtsBlXhxk46NuyyEu4zkVExxgU4RI0Kh3z45l/zNrFFKIaal7zi/ ViDyhOs1ubyoH7vhJ5/aGtHv/mawVwlP5LXx/fmPYXj4VgvIHe4z4RUxCPui91F1XS7Ad w2kzbTU53VKYJGpJRW9JE+8a90kQiR9pCuUWkXm8PjpbGTJDEXEEjLTW6mZ18fLCwpw== 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=03OL9cb9; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.196.62 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013062.outbound.protection.outlook.com [40.93.196.62]) (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 744FF606A339; Tue, 1 Dec 2026 16:29:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 744FF606A339 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=03OL9cb9 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HSOyvhI3quqq8sllAtDiOLZrd6iwr+Wb2Rio97J8EZ5pedXwiY4FCLrj7EWtN5UsaOhUL13RQfgJgLTKJE0dVZDOPmLc9y+baLu02rFbdKCnboKkOD6yyeSi+oC61v/rnYs4jSrXqWBGhHivd/kNqChOtqb7rPeYippL01CWK/BnIu7Br+sb4ENllSOn1qwCcqoGKl/weX99n+LVKiw6/GMTmtoCsymUuFutgctrv2iYI4jUjLIzBRt+SYnEmTBdbCTxTC25X/uhC4Bsi8qiTnUM6bRlCvwx9/Ij0am5zy3+513b+9/JN7jy/RjQXwfscsRyEKMEjA5TD1zlNvzqnA== 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=KECaawtPNRlnlsMZfeYlVe3wsbAUtzA/Ovvt2VByiBs=; b=BgKGFQaXlNA9296jYZJ6fZIo6pLS39+PHysKt3fSHuuVBvIr2PabqOunRN+3ZlfMQyrfRCS/nnTmowGJ22telKsXSv9w5/9v9qPPDT/q1ROwB9lIkvHmngfc8ieQQXnLXjTenWV66DV9lbpu916+/mcmXPk8uMT8fy7kmbI9vLShQO3rAWFf5mf14JnXAVMiMF2BllvtnJi5MHMeyQfCLEAX7iasLDc+fGmmYGEkAEEkl+7ZQRRX0Tb4qBgkxgHUSphSHylMLg4fUN0PkzAuGfk2a/rKFM6w3XA2TPqt0Z92yRT5Hufc46T+YiguWq5FLAMT7XDoopKL06GY7NuApg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none 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=KECaawtPNRlnlsMZfeYlVe3wsbAUtzA/Ovvt2VByiBs=; b=03OL9cb9jmMqJ0ASFMZaAjpYM9iEzXIDlMoM6fJmENFqwEYsVAuODVqqc/Qq3auiO60UvJNmNg6KG5Ofvl5w593I+lnzPPnW6l0DE5hrHOpm/rQiCaYaU8GKxSXnVf4BlIElpiFeOTzqRyuQDTjxBoLzSJbBvIzFNV3qIM3PcVk= Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from PH7PR12MB9174.namprd12.prod.outlook.com (2603:10b6:510:2ed::9) by SA1PR12MB5614.namprd12.prod.outlook.com (2603:10b6:806:228::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.9; Tue, 1 Dec 2026 16:29:18 +0000 Received: from PH7PR12MB9174.namprd12.prod.outlook.com ([fe80::eaaa:b430:ba9:5dc]) by PH7PR12MB9174.namprd12.prod.outlook.com ([fe80::eaaa:b430:ba9:5dc%7]) with mapi id 15.21.0662.012; Tue, 1 Dec 2026 16:29:18 +0000 Message-ID: <5fb9bfb4-a36a-4403-9d1d-7687891ed2ce@amd.com> Date: Tue, 1 Dec 2026 10:29:15 -0600 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 2/2] platform/x86/amd/hsmp: Report raw SMU mailbox status via smu_response Content-Language: en-US To: Muralidhara M K , ilpo.jarvinen@linux.intel.com Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: <20261201161129.767731-1-muralidhara.mk@amd.com> <20261201161129.767731-3-muralidhara.mk@amd.com> From: Mario Limonciello In-Reply-To: <20261201161129.767731-3-muralidhara.mk@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: CH0PR03CA0071.namprd03.prod.outlook.com (2603:10b6:610:cc::16) To PH7PR12MB9174.namprd12.prod.outlook.com (2603:10b6:510:2ed::9) 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 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH7PR12MB9174:EE_|SA1PR12MB5614:EE_ X-MS-Office365-Filtering-Correlation-Id: d308ca2c-8a89-48a9-54c8-08df4fc83efb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|23010399003|1800799024|366016|4143699003|11063799006|5023799004|18002099003|261009223027099003|6133799003|22082099003|3023799007|261026140227099003|261028144727099003|10067099003|56012099006|261026135527099003|261102123227099003|261102130727099003|261026121527099003|261021130227099003|261021133027099003|261022075727099003|261022105027099003|261021123027099003|261026130827099003|261021135927099003|261021121427099003|261022115727099003|261022113327099003; X-Microsoft-Antispam-Message-Info: VKUnRIM4FSB3ErIAysJtlgjToiHbvSHPktI7YbqeBlz3oKLc6BzP1X2fmEfV65Dwt9VP5U+VwlBp4CRVQt1dIm96Ii1vUVKSdMOliJ1NMLXY/bWb4DNQjGPK1nnc5kbALGTygKjjV2OtIUIAwt/qdNwKy/zlDfWhVnmqyePSxMxjK9X3ggK6Kq59TcXOM4ayiqTjEEOvPUxmYUy/Vphlb6+p/7m5Yo9ml5czKbaOJkwCa83O4k02Fk8d7VZaZFv36fhV4xhAKATnW4KDHFv0dlkYsOP0A5QhDdery1ERwCgf449EpURklX8t88Y9zaYeveMpDbHTbJrCEHAvrC5LHzAbIzY8Ox7qEObmpRR2YYTm+bptTJRyurQLPmyYRg6+qmmBlywsJja5oIbIKlPQxqi6qFirH1lkTiBn4aadD2xMp9LvSUeKx9oz/8DXeHHbCJad/QQImVNNF1h4EzO0FOF5cXuPY4QphYjIWkbcoIHuCOxS6VhUjfdzJ2AQJi0Cw3cDCuS4N/XJPZChBpImkRnwomN6FGqXFmw9J005RpU3ps+Xz4wQC/uWv63iC2lRR+rnW1qhVnU/g/gsJCfnYkdxi/OwSdao2NRTNJJ436EUISb+XGuDTHLg8L8rdtfp X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH7PR12MB9174.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(23010399003)(1800799024)(366016)(4143699003)(11063799006)(5023799004)(18002099003)(261009223027099003)(6133799003)(22082099003)(3023799007)(261026140227099003)(261028144727099003)(10067099003)(56012099006)(261026135527099003)(261102123227099003)(261102130727099003)(261026121527099003)(261021130227099003)(261021133027099003)(261022075727099003)(261022105027099003)(261021123027099003)(261026130827099003)(261021135927099003)(261021121427099003)(261022115727099003)(261022113327099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?dVNYYk4rcXVpNzdkb0JQK1RQR3dtMnl4a2RKS2Vha2REYlJqcjdYTlNGaDVS?= =?utf-8?B?dGUrYU9Td1B6c3RqNkZ5WjhRNDVwSk1PSk9jcXRabU5qSWpNWWluNUlIK3pV?= =?utf-8?B?OGRnQzljc2lhMlFlT2dRbkhtZGk3Qm5selgvNm9uUmQ3aXJrZjhDQ05VcDIx?= =?utf-8?B?TnN2N3d4RTdKUzZ1azlpVGhJQlY1U1hLRjNLMWRTTU1LRW1qbitlU0ZUTVNp?= =?utf-8?B?eHZzbnFMMGtZTkFzYmN3anBMa1Z2aFVmMGhaRlc2TlVjd09jS1JPYVV3Zjd5?= =?utf-8?B?MndjanBJN21zbU9KVVdDdzA3eFBOcjRFR0xReWRiaEJibnhjSXduMHA1Y3JZ?= =?utf-8?B?b2dsQisyM3BybDVLRnBBallpUHM4UlRmY0h2cWxuQ09DaVRoZlJvSzljZ3FT?= =?utf-8?B?blRGak8vSkNBMmsrWFgyTGlNMVZMYkJ1NFBXMTJJR0E2ZG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WdoQjYxTXRNdjhodTFXSitENkF1N0NJUjZaV3UwQS9rQWc1?= =?utf-8?B?TGdyWUdrNjkycDlDVmhkMUNWa2c5UDdyU2R6QWNyY0swOHQ3UXNzZz09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d308ca2c-8a89-48a9-54c8-08df4fc83efb X-MS-Exchange-CrossTenant-AuthSource: PH7PR12MB9174.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 16:29:18.2291 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: P92UwZeJFoXpm2xxX2vj+wwVLAGLSB4wH0/YRJvPYWsb5eHs3pP8l/L/IKntdXOTEQsyYGEHKJw1TCYBEezInA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB5614 On 12/1/26 10:11, Muralidhara M K wrote: > 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 both ioctl command numbers unchanged. > > 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 | 19 ++++- > drivers/platform/x86/amd/hsmp/hsmp.c | 111 ++++++++++++++++----------- > 3 files changed, 103 insertions(+), 50 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..df91186a7a25 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; > }; Isn't this still breaking for userspace? It will send the wrong sized struct with the older struct hsmp_message. Why not instead map the SMU error codes and return the code to the caller? Then you don't need to change your interface at all. This is what we do in other code that talks to the ASP. Take a look here: https://github.com/torvalds/linux/blob/master/drivers/crypto/ccp/dbc.c#L30 I think you can do something pretty similar. > > 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; Given you only have 16 bits left do you really want to use the whole thing for the response? Aren't most responses only 8 bits? > }; > > /* Reset to default packing */ > 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"); >