Skip to content

Commit 0ba2035

Browse files
superm1ij-intel
authored andcommitted
crypto: ccp - Add an S4 restore flow
The system will have lost power during S4. The ring used for TEE communications needs to be initialized before use. Fixes: f892a21 ("crypto: ccp - use generic power management") 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> Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org> Reviewed-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Link: https://patch.msgid.link/20260116041132.153674-4-superm1@kernel.org Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
1 parent 5e599d7 commit 0ba2035

6 files changed

Lines changed: 47 additions & 1 deletion

File tree

drivers/crypto/ccp/psp-dev.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,17 @@ struct psp_device *psp_get_master_device(void)
351351
return sp ? sp->psp_data : NULL;
352352
}
353353

354+
int psp_restore(struct sp_device *sp)
355+
{
356+
struct psp_device *psp = sp->psp_data;
357+
int ret = 0;
358+
359+
if (psp->tee_data)
360+
ret = tee_restore(psp);
361+
362+
return ret;
363+
}
364+
354365
void psp_pci_init(void)
355366
{
356367
psp_master = psp_get_master_device();

drivers/crypto/ccp/sp-dev.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,18 @@ int sp_resume(struct sp_device *sp)
230230
return 0;
231231
}
232232

233+
int sp_restore(struct sp_device *sp)
234+
{
235+
if (sp->psp_data) {
236+
int ret = psp_restore(sp);
237+
238+
if (ret)
239+
return ret;
240+
}
241+
242+
return sp_resume(sp);
243+
}
244+
233245
struct sp_device *sp_get_psp_master_device(void)
234246
{
235247
struct sp_device *i, *ret = NULL;

drivers/crypto/ccp/sp-dev.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ void sp_destroy(struct sp_device *sp);
141141

142142
int sp_suspend(struct sp_device *sp);
143143
int sp_resume(struct sp_device *sp);
144+
int sp_restore(struct sp_device *sp);
144145
int sp_request_ccp_irq(struct sp_device *sp, irq_handler_t handler,
145146
const char *name, void *data);
146147
void sp_free_ccp_irq(struct sp_device *sp, void *data);
@@ -174,13 +175,15 @@ int psp_dev_init(struct sp_device *sp);
174175
void psp_pci_init(void);
175176
void psp_dev_destroy(struct sp_device *sp);
176177
void psp_pci_exit(void);
178+
int psp_restore(struct sp_device *sp);
177179

178180
#else /* !CONFIG_CRYPTO_DEV_SP_PSP */
179181

180182
static inline int psp_dev_init(struct sp_device *sp) { return 0; }
181183
static inline void psp_pci_init(void) { }
182184
static inline void psp_dev_destroy(struct sp_device *sp) { }
183185
static inline void psp_pci_exit(void) { }
186+
static inline int psp_restore(struct sp_device *sp) { return 0; }
184187

185188
#endif /* CONFIG_CRYPTO_DEV_SP_PSP */
186189

drivers/crypto/ccp/sp-pci.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ static int __maybe_unused sp_pci_resume(struct device *dev)
353353
return sp_resume(sp);
354354
}
355355

356+
static int __maybe_unused sp_pci_restore(struct device *dev)
357+
{
358+
struct sp_device *sp = dev_get_drvdata(dev);
359+
360+
return sp_restore(sp);
361+
}
362+
356363
#ifdef CONFIG_CRYPTO_DEV_SP_PSP
357364
static const struct sev_vdata sevv1 = {
358365
.cmdresp_reg = 0x10580, /* C2PMSG_32 */
@@ -563,7 +570,14 @@ static const struct pci_device_id sp_pci_table[] = {
563570
};
564571
MODULE_DEVICE_TABLE(pci, sp_pci_table);
565572

566-
static SIMPLE_DEV_PM_OPS(sp_pci_pm_ops, sp_pci_suspend, sp_pci_resume);
573+
static 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_early = pm_sleep_ptr(sp_pci_restore),
580+
};
567581

568582
static struct pci_driver sp_pci_driver = {
569583
.name = "ccp",

drivers/crypto/ccp/tee-dev.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,8 @@ int psp_check_tee_status(void)
366366
return 0;
367367
}
368368
EXPORT_SYMBOL(psp_check_tee_status);
369+
370+
int tee_restore(struct psp_device *psp)
371+
{
372+
return tee_init_ring(psp->tee_data);
373+
}

drivers/crypto/ccp/tee-dev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,6 @@ struct tee_ring_cmd {
111111

112112
int tee_dev_init(struct psp_device *psp);
113113
void tee_dev_destroy(struct psp_device *psp);
114+
int tee_restore(struct psp_device *psp);
114115

115116
#endif /* __TEE_DEV_H__ */

0 commit comments

Comments
 (0)