Skip to content

Commit 48d229c

Browse files
Shyam Sundar S Kij-intel
authored andcommitted
platform/x86/amd/pmf: Prevent TEE errors after hibernate
After resuming from hibernate, TEE commands can time out and cause PSP disables. Fix this by reinitializing the Trusted Application (TA) and cancelling the pb workqueue in the hibernate callbacks to avoid these errors. ccp 0000:c4:00.2: tee: command 0x5 timed out, disabling PSP amd-pmf AMDI0107:00: TEE enact cmd failed. err: ffff000e, ret:0 amd-pmf AMDI0107:00: TEE enact cmd failed. err: ffff000e, ret:0 amd-pmf AMDI0107:00: TEE enact cmd failed. err: ffff000e, ret:0 Fixes: ae82cef ("platform/x86/amd/pmf: Add support for PMF-TA interaction") Reported-by: Lars Francke <lars.francke@gmail.com> Closes: https://lore.kernel.org/platform-driver-x86/CAD-Ua_gfJnQSo8ucS_7ZwzuhoBRJ14zXP7s8b-zX3ZcxcyWePw@mail.gmail.com/ Tested-by: Yijun Shen <Yijun.Shen@Dell.com> Co-developed-by: Patil Rajesh Reddy <Patil.Reddy@amd.com> Signed-off-by: Patil Rajesh Reddy <Patil.Reddy@amd.com> Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> [ML: Add more tags] Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org> Link: https://patch.msgid.link/20260116041132.153674-2-superm1@kernel.org Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
1 parent 51ed342 commit 48d229c

3 files changed

Lines changed: 74 additions & 10 deletions

File tree

drivers/platform/x86/amd/pmf/core.c

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,61 @@ int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev)
315315
return 0;
316316
}
317317

318+
static int amd_pmf_reinit_ta(struct amd_pmf_dev *pdev)
319+
{
320+
bool status;
321+
int ret, i;
322+
323+
for (i = 0; i < ARRAY_SIZE(amd_pmf_ta_uuid); i++) {
324+
ret = amd_pmf_tee_init(pdev, &amd_pmf_ta_uuid[i]);
325+
if (ret) {
326+
dev_err(pdev->dev, "TEE init failed for UUID[%d] ret: %d\n", i, ret);
327+
return ret;
328+
}
329+
330+
ret = amd_pmf_start_policy_engine(pdev);
331+
dev_dbg(pdev->dev, "start policy engine ret: %d (UUID idx: %d)\n", ret, i);
332+
status = ret == TA_PMF_TYPE_SUCCESS;
333+
if (status)
334+
break;
335+
amd_pmf_tee_deinit(pdev);
336+
}
337+
338+
return 0;
339+
}
340+
341+
static int amd_pmf_restore_handler(struct device *dev)
342+
{
343+
struct amd_pmf_dev *pdev = dev_get_drvdata(dev);
344+
int ret;
345+
346+
if (pdev->buf) {
347+
ret = amd_pmf_set_dram_addr(pdev, false);
348+
if (ret)
349+
return ret;
350+
}
351+
352+
if (pdev->smart_pc_enabled)
353+
amd_pmf_reinit_ta(pdev);
354+
355+
return 0;
356+
}
357+
358+
static int amd_pmf_freeze_handler(struct device *dev)
359+
{
360+
struct amd_pmf_dev *pdev = dev_get_drvdata(dev);
361+
362+
if (!pdev->smart_pc_enabled)
363+
return 0;
364+
365+
cancel_delayed_work_sync(&pdev->pb_work);
366+
/* Clear all TEE resources */
367+
amd_pmf_tee_deinit(pdev);
368+
pdev->session_id = 0;
369+
370+
return 0;
371+
}
372+
318373
static int amd_pmf_suspend_handler(struct device *dev)
319374
{
320375
struct amd_pmf_dev *pdev = dev_get_drvdata(dev);
@@ -348,7 +403,12 @@ static int amd_pmf_resume_handler(struct device *dev)
348403
return 0;
349404
}
350405

351-
static DEFINE_SIMPLE_DEV_PM_OPS(amd_pmf_pm, amd_pmf_suspend_handler, amd_pmf_resume_handler);
406+
static const struct dev_pm_ops amd_pmf_pm = {
407+
.suspend = amd_pmf_suspend_handler,
408+
.resume = amd_pmf_resume_handler,
409+
.freeze = amd_pmf_freeze_handler,
410+
.restore = amd_pmf_restore_handler,
411+
};
352412

353413
static void amd_pmf_init_features(struct amd_pmf_dev *dev)
354414
{

drivers/platform/x86/amd/pmf/pmf.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ struct cookie_header {
132132

133133
typedef void (*apmf_event_handler_t)(acpi_handle handle, u32 event, void *data);
134134

135+
static const uuid_t amd_pmf_ta_uuid[] __used = { UUID_INIT(0xd9b39bf2, 0x66bd, 0x4154, 0xaf, 0xb8,
136+
0x8a, 0xcc, 0x2b, 0x2b, 0x60, 0xd6),
137+
UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d, 0xb1, 0x2d,
138+
0xc5, 0x29, 0xb1, 0x3d, 0x85, 0x43),
139+
};
140+
135141
/* APTS PMF BIOS Interface */
136142
struct amd_pmf_apts_output {
137143
u16 table_version;
@@ -916,4 +922,8 @@ void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_tab
916922
void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in);
917923
int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev);
918924

925+
int amd_pmf_tee_init(struct amd_pmf_dev *dev, const uuid_t *uuid);
926+
void amd_pmf_tee_deinit(struct amd_pmf_dev *dev);
927+
int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev);
928+
919929
#endif /* PMF_H */

drivers/platform/x86/amd/pmf/tee-if.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ module_param(pb_side_load, bool, 0444);
2727
MODULE_PARM_DESC(pb_side_load, "Sideload policy binaries debug policy failures");
2828
#endif
2929

30-
static const uuid_t amd_pmf_ta_uuid[] = { UUID_INIT(0xd9b39bf2, 0x66bd, 0x4154, 0xaf, 0xb8, 0x8a,
31-
0xcc, 0x2b, 0x2b, 0x60, 0xd6),
32-
UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d, 0xb1, 0x2d, 0xc5,
33-
0x29, 0xb1, 0x3d, 0x85, 0x43),
34-
};
35-
3630
static const char *amd_pmf_uevent_as_str(unsigned int state)
3731
{
3832
switch (state) {
@@ -324,7 +318,7 @@ static void amd_pmf_invoke_cmd(struct work_struct *work)
324318
schedule_delayed_work(&dev->pb_work, msecs_to_jiffies(pb_actions_ms));
325319
}
326320

327-
static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev)
321+
int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev)
328322
{
329323
struct cookie_header *header;
330324
int res;
@@ -480,7 +474,7 @@ static int amd_pmf_register_input_device(struct amd_pmf_dev *dev)
480474
return 0;
481475
}
482476

483-
static int amd_pmf_tee_init(struct amd_pmf_dev *dev, const uuid_t *uuid)
477+
int amd_pmf_tee_init(struct amd_pmf_dev *dev, const uuid_t *uuid)
484478
{
485479
u32 size;
486480
int ret;
@@ -528,7 +522,7 @@ static int amd_pmf_tee_init(struct amd_pmf_dev *dev, const uuid_t *uuid)
528522
return ret;
529523
}
530524

531-
static void amd_pmf_tee_deinit(struct amd_pmf_dev *dev)
525+
void amd_pmf_tee_deinit(struct amd_pmf_dev *dev)
532526
{
533527
if (!dev->tee_ctx)
534528
return;

0 commit comments

Comments
 (0)