Fixes for PMF driver after S4
Subsystems (4)
cover Fixes for PMF driver after S4
Lars Francke reported that the PMF driver fails to work afer S4 with:
ccp 0000:c3:00.2: tee: command 0x5 timed out, disabling PSP
This is because there is a TA loaded to the TEE environment that is lost during S4. The TEE rings need to be reinitialized and the TA needs to be reloaded.
This series adds those flows.
Note:
I validated this on top of 6.18-rc6. I could reproduce Lars' original issue on a Strix laptop and then confirmed that after applying these two patches that PMF continues to work after resume. I ran a handful of S4 cycles, module unload tests and reboot tests.
Mario Limonciello (AMD) (1):
crypto: ccp - Add an S4 restore flow
Shyam Sundar S K (1):
platform/x86/amd/pmf: Prevent TEE errors after hibernate
drivers/crypto/ccp/sp-dev.c | 13 ++++++ drivers/crypto/ccp/sp-dev.h | 1 + drivers/crypto/ccp/sp-pci.c | 16 ++++++- drivers/crypto/ccp/tee-dev.c | 6 +++ drivers/crypto/ccp/tee-dev.h | 1 + drivers/platform/x86/amd/pmf/core.c | 62 ++++++++++++++++++++++++++- drivers/platform/x86/amd/pmf/pmf.h | 10 +++++ drivers/platform/x86/amd/pmf/tee-if.c | 12 ++---- 8 files changed, 110 insertions(+), 11 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 platform/x86/amd/pmf: Prevent TEE errors after hibernate
From: Shyam Sundar S K <[email protected]>
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
--- drivers/platform/x86/amd/pmf/core.c | 62 ++++++++++++++++++++++++++- drivers/platform/x86/amd/pmf/pmf.h | 10 +++++ drivers/platform/x86/amd/pmf/tee-if.c | 12 ++---- 3 files changed, 74 insertions(+), 10 deletions(-)
drivers/platform/x86/amd/pmf/core.c +61 -1
@@ -314,6 +314,61 @@ int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev)return 0 ; } +static int amd_pmf_reinit_ta (struct amd_pmf_dev *pdev) +{ +bool status; +int ret, i; + +for (i =0 ; i <ARRAY_SIZE (amd_pmf_ta_uuid); i++) { + ret =amd_pmf_tee_init (pdev, &amd_pmf_ta_uuid[i]); +if (ret) { +dev_err (pdev->dev,"TEE init failed for UUID[%d] ret: %d\n" , i, ret); +return ret; + } + + ret =amd_pmf_start_policy_engine (pdev); +dev_dbg (pdev->dev,"start policy engine ret: %d (UUID idx: %d)\n" , ret, i); + status = ret ==TA_PMF_TYPE_SUCCESS ; +if (status) +break ; +amd_pmf_tee_deinit (pdev); + } + +return 0 ; +} + +static int amd_pmf_restore_handler (struct device *dev) +{ +struct amd_pmf_dev *pdev =dev_get_drvdata (dev); +int ret; + +if (pdev->buf) { + ret =amd_pmf_set_dram_addr (pdev, false); +if (ret) +return ret; + } + +if (pdev->smart_pc_enabled) +amd_pmf_reinit_ta (pdev); + +return 0 ; +} + +static int amd_pmf_freeze_handler (struct device *dev) +{ +struct amd_pmf_dev *pdev =dev_get_drvdata (dev); + +if (!pdev->smart_pc_enabled) +return 0 ; + +cancel_delayed_work_sync (&pdev->pb_work); +/* Clear all TEE resources */ +amd_pmf_tee_deinit (pdev); + pdev->session_id =0 ; + +return 0 ; +} +static int amd_pmf_suspend_handler (struct device *dev) {struct amd_pmf_dev *pdev =dev_get_drvdata (dev);
@@ -347,7 +402,12 @@ static int amd_pmf_resume_handler(struct device *dev)return 0 ; } -static DEFINE_SIMPLE_DEV_PM_OPS(amd_pmf_pm, amd_pmf_suspend_handler, amd_pmf_resume_handler); +static const struct dev_pm_ops amd_pmf_pm = { + .suspend = amd_pmf_suspend_handler, + .resume = amd_pmf_resume_handler, + .freeze = amd_pmf_freeze_handler, + .restore = amd_pmf_restore_handler, +};static void amd_pmf_init_features (struct amd_pmf_dev *dev) {
drivers/platform/x86/amd/pmf/pmf.h +10 -0
@@ -122,6 +122,12 @@ struct cookie_header {typedef void (*apmf_event_handler_t )(acpi_handle handle,u32 event,void *data); +static const uuid_t amd_pmf_ta_uuid[]__used = {UUID_INIT (0xd9b39bf2 ,0x66bd ,0x4154 ,0xaf ,0xb8 , +0x8a ,0xcc ,0x2b ,0x2b ,0x60 ,0xd6 ), +UUID_INIT (0x6fd93b77 ,0x3fb8 ,0x524d ,0xb1 ,0x2d , +0xc5 ,0x29 ,0xb1 ,0x3d ,0x85 ,0x43 ), + }; +/* APTS PMF BIOS Interface */ struct amd_pmf_apts_output {u16 table_version;
@@ -888,4 +894,8 @@ void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_tabvoid amd_pmf_dump_ta_inputs (struct amd_pmf_dev *dev,struct ta_pmf_enact_table *in);int amd_pmf_invoke_cmd_enact (struct amd_pmf_dev *dev); +int amd_pmf_tee_init (struct amd_pmf_dev *dev,const uuid_t *uuid); +void amd_pmf_tee_deinit (struct amd_pmf_dev *dev); +int amd_pmf_start_policy_engine (struct amd_pmf_dev *dev); +#endif /* PMF_H */
drivers/platform/x86/amd/pmf/tee-if.c +3 -9
@@ -27,12 +27,6 @@ module_param(pb_side_load, bool, 0444);MODULE_PARM_DESC (pb_side_load,"Sideload policy binaries debug policy failures" );#endif -static const uuid_t amd_pmf_ta_uuid[] = {UUID_INIT (0xd9b39bf2 ,0x66bd ,0x4154 ,0xaf ,0xb8 ,0x8a , -0xcc ,0x2b ,0x2b ,0x60 ,0xd6 ), -UUID_INIT (0x6fd93b77 ,0x3fb8 ,0x524d ,0xb1 ,0x2d ,0xc5 , -0x29 ,0xb1 ,0x3d ,0x85 ,0x43 ), - }; -static const char *amd_pmf_uevent_as_str (unsigned int state) {switch (state) {
@@ -312,7 +306,7 @@ static void amd_pmf_invoke_cmd(struct work_struct *work)schedule_delayed_work (&dev->pb_work,msecs_to_jiffies (pb_actions_ms)); } -static int amd_pmf_start_policy_engine (struct amd_pmf_dev *dev) +int amd_pmf_start_policy_engine (struct amd_pmf_dev *dev) {struct cookie_header *header;int res;
@@ -468,7 +462,7 @@ static int amd_pmf_register_input_device(struct amd_pmf_dev *dev)return 0 ; } -static int amd_pmf_tee_init (struct amd_pmf_dev *dev,const uuid_t *uuid) +int amd_pmf_tee_init (struct amd_pmf_dev *dev,const uuid_t *uuid) {u32 size;int ret;
@@ -516,7 +510,7 @@ static int amd_pmf_tee_init(struct amd_pmf_dev *dev, const uuid_t *uuid)return ret; } -static void amd_pmf_tee_deinit (struct amd_pmf_dev *dev) +void amd_pmf_tee_deinit (struct amd_pmf_dev *dev) {if (!dev->tee_ctx)return ;
Signature · 1 line
2.43.0
PATCH 2/2 crypto: ccp - Add an S4 restore flow
In reply to Mario Limonciello (AMD)The system will have lost power during S4. The ring used for TEE communications needs to be initialized before use.
--- drivers/crypto/ccp/sp-dev.c | 13 +++++++++++++ drivers/crypto/ccp/sp-dev.h | 1 + drivers/crypto/ccp/sp-pci.c | 16 +++++++++++++++- drivers/crypto/ccp/tee-dev.c | 6 ++++++ drivers/crypto/ccp/tee-dev.h | 1 + 5 files changed, 36 insertions(+), 1 deletion(-)
drivers/crypto/ccp/sp-dev.c +13 -0
@@ -21,6 +21,7 @@#include "sev-dev.h" #include "ccp-dev.h" +#include "tee-dev.h" #include "sp-dev.h" MODULE_AUTHOR ("Tom Lendacky <[email protected]>" );
@@ -230,6 +231,18 @@ int sp_resume(struct sp_device *sp)return 0 ; } +int sp_restore (struct sp_device *sp) +{ +if (sp->dev_vdata->psp_vdata->tee) { +int r =tee_restore (sp->psp_data); + +if (r) +return r; + } + +return sp_resume (sp); +} +struct sp_device *sp_get_psp_master_device (void ) {struct sp_device *i, *ret =NULL ;
drivers/crypto/ccp/sp-dev.h +1 -0
@@ -141,6 +141,7 @@ void sp_destroy(struct sp_device *sp);int sp_suspend (struct sp_device *sp);int sp_resume (struct sp_device *sp); +int sp_restore (struct sp_device *sp);int sp_request_ccp_irq (struct sp_device *sp,irq_handler_t handler,const char *name,void *data);void sp_free_ccp_irq (struct sp_device *sp,void *data);
drivers/crypto/ccp/sp-pci.c +15 -1
@@ -353,6 +353,13 @@ static int __maybe_unused sp_pci_resume(struct device *dev)return sp_resume (sp); } +static int __maybe_unused sp_pci_restore (struct device *dev) +{ +struct sp_device *sp =dev_get_drvdata (dev); + +return sp_restore (sp); +} +#ifdef CONFIG_CRYPTO_DEV_SP_PSP static const struct sev_vdata sevv1 = { .cmdresp_reg = 0x10580, /* C2PMSG_32 */
@@ -544,7 +551,14 @@ static const struct pci_device_id sp_pci_table[] = { };MODULE_DEVICE_TABLE (pci, sp_pci_table); -static SIMPLE_DEV_PM_OPS(sp_pci_pm_ops, sp_pci_suspend, sp_pci_resume); +const struct dev_pm_ops sp_pci_pm_ops = { + .suspend =pm_sleep_ptr (sp_pci_suspend), + .resume =pm_sleep_ptr (sp_pci_resume), + .freeze =pm_sleep_ptr (sp_pci_suspend), + .thaw =pm_sleep_ptr (sp_pci_resume), + .poweroff =pm_sleep_ptr (sp_pci_suspend), + .restore =pm_sleep_ptr (sp_pci_restore), +};static struct pci_driver sp_pci_driver = { .name ="ccp" ,
drivers/crypto/ccp/tee-dev.c +6 -0
@@ -365,3 +365,9 @@ int psp_check_tee_status(void)return 0 ; }EXPORT_SYMBOL (psp_check_tee_status); + +int tee_restore (struct psp_device *psp) +{ +tee_free_ring (psp->tee_data); +return tee_init_ring (psp->tee_data); +}
drivers/crypto/ccp/tee-dev.h +1 -0
@@ -111,5 +111,6 @@ struct tee_ring_cmd {int tee_dev_init (struct psp_device *psp);void tee_dev_destroy (struct psp_device *psp); +int tee_restore (struct psp_device *psp);#endif /* __TEE_DEV_H__ */
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH 2/2] crypto: ccp - Add an S4 restore flow
kernel test robot noticed the following build warnings:
Hi Mario,
kernel test robot noticed the following build warnings:
[auto build test WARNING on herbert-cryptodev-2.6/master]
[also build test WARNING on herbert-crypto-2.6/master linus/master v6.18-rc6 next-20251120] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mario-Limonciello-AMD/platform-x86-amd-pmf-Prevent-TEE-errors-after-hibernate/20251120-050203 base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master patch link: https://lore.kernel.org/r/20251119205942.3411155-3-superm1%40kernel.org patch subject: [PATCH 2/2] crypto: ccp - Add an S4 restore flow config: i386-randconfig-r133-20251120 (https://download.01.org/0day-ci/archive/20251120/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251120/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> drivers/crypto/ccp/sp-pci.c:573:25: sparse: sparse: symbol 'sp_pci_pm_ops' was not declared. Should it be static?
vim +/sp_pci_pm_ops +573 drivers/crypto/ccp/sp-pci.c
572
> 573 const struct dev_pm_ops sp_pci_pm_ops = { 574 .suspend = pm_sleep_ptr(sp_pci_suspend),
575 .resume = pm_sleep_ptr(sp_pci_resume),
576 .freeze = pm_sleep_ptr(sp_pci_suspend),
577 .thaw = pm_sleep_ptr(sp_pci_resume),
578 .poweroff = pm_sleep_ptr(sp_pci_suspend),
579 .restore = pm_sleep_ptr(sp_pci_restore),
580 };
581
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH 2/2] crypto: ccp - Add an S4 restore flow
In reply to Mario Limonciello (AMD)kernel test robot noticed the following build errors:
Hi Mario,
kernel test robot noticed the following build errors:
[auto build test ERROR on herbert-cryptodev-2.6/master]
[also build test ERROR on herbert-crypto-2.6/master linus/master v6.18-rc7 next-20251121] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mario-Limonciello-AMD/platform-x86-amd-pmf-Prevent-TEE-errors-after-hibernate/20251120-050203 base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master patch link: https://lore.kernel.org/r/20251119205942.3411155-3-superm1%40kernel.org patch subject: [PATCH 2/2] crypto: ccp - Add an S4 restore flow config: i386-randconfig-004-20251124 (https://download.01.org/0day-ci/archive/20251124/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251124/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "tee_restore" [drivers/crypto/ccp/ccp.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH 2/2] crypto: ccp - Add an S4 restore flow
In reply to Mario Limonciello (AMD)kernel test robot noticed the following build errors:
Hi Mario,
kernel test robot noticed the following build errors:
[auto build test ERROR on herbert-cryptodev-2.6/master]
[also build test ERROR on herbert-crypto-2.6/master linus/master v6.18-rc7 next-20251121] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mario-Limonciello-AMD/platform-x86-amd-pmf-Prevent-TEE-errors-after-hibernate/20251120-050203 base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master patch link: https://lore.kernel.org/r/20251119205942.3411155-3-superm1%40kernel.org patch subject: [PATCH 2/2] crypto: ccp - Add an S4 restore flow config: i386-buildonly-randconfig-003-20251124 (https://download.01.org/0day-ci/archive/20251124/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251124/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
ld: drivers/crypto/ccp/sp-dev.o: in function `sp_restore':
>> drivers/crypto/ccp/sp-dev.c:237:(.text+0x28f): undefined reference to `tee_restore'
vim +237 drivers/crypto/ccp/sp-dev.c
233
234 int sp_restore(struct sp_device *sp)
235 {
236 if (sp->dev_vdata->psp_vdata->tee) {
> 237 int r = tee_restore(sp->psp_data);
238
239 if (r)
240 return r;
241 }
242
243 return sp_resume(sp);
244 }
245
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki