Skip to content
/ linux Public

Commit e7e1fbb

Browse files
superm1Sasha Levin
authored andcommitted
crypto: ccp - Add an S4 restore flow
[ Upstream commit 0ba2035 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8bac2e8 commit e7e1fbb

File tree

6 files changed

+47
-1
lines changed

6 files changed

+47
-1
lines changed

drivers/crypto/ccp/psp-dev.c

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

241+
int psp_restore(struct sp_device *sp)
242+
{
243+
struct psp_device *psp = sp->psp_data;
244+
int ret = 0;
245+
246+
if (psp->tee_data)
247+
ret = tee_restore(psp);
248+
249+
return ret;
250+
}
251+
241252
void psp_pci_init(void)
242253
{
243254
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
@@ -229,6 +229,18 @@ int sp_resume(struct sp_device *sp)
229229
return 0;
230230
}
231231

232+
int sp_restore(struct sp_device *sp)
233+
{
234+
if (sp->psp_data) {
235+
int ret = psp_restore(sp);
236+
237+
if (ret)
238+
return ret;
239+
}
240+
241+
return sp_resume(sp);
242+
}
243+
232244
struct sp_device *sp_get_psp_master_device(void)
233245
{
234246
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
@@ -121,6 +121,7 @@ struct sp_device *sp_get_master(void);
121121

122122
int sp_suspend(struct sp_device *sp);
123123
int sp_resume(struct sp_device *sp);
124+
int sp_restore(struct sp_device *sp);
124125
int sp_request_ccp_irq(struct sp_device *sp, irq_handler_t handler,
125126
const char *name, void *data);
126127
void sp_free_ccp_irq(struct sp_device *sp, void *data);
@@ -154,13 +155,15 @@ int psp_dev_init(struct sp_device *sp);
154155
void psp_pci_init(void);
155156
void psp_dev_destroy(struct sp_device *sp);
156157
void psp_pci_exit(void);
158+
int psp_restore(struct sp_device *sp);
157159

158160
#else /* !CONFIG_CRYPTO_DEV_SP_PSP */
159161

160162
static inline int psp_dev_init(struct sp_device *sp) { return 0; }
161163
static inline void psp_pci_init(void) { }
162164
static inline void psp_dev_destroy(struct sp_device *sp) { }
163165
static inline void psp_pci_exit(void) { }
166+
static inline int psp_restore(struct sp_device *sp) { return 0; }
164167

165168
#endif /* CONFIG_CRYPTO_DEV_SP_PSP */
166169

drivers/crypto/ccp/sp-pci.c

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

346+
static int __maybe_unused sp_pci_restore(struct device *dev)
347+
{
348+
struct sp_device *sp = dev_get_drvdata(dev);
349+
350+
return sp_restore(sp);
351+
}
352+
346353
#ifdef CONFIG_CRYPTO_DEV_SP_PSP
347354
static const struct sev_vdata sevv1 = {
348355
.cmdresp_reg = 0x10580,
@@ -462,7 +469,14 @@ static const struct pci_device_id sp_pci_table[] = {
462469
};
463470
MODULE_DEVICE_TABLE(pci, sp_pci_table);
464471

465-
static SIMPLE_DEV_PM_OPS(sp_pci_pm_ops, sp_pci_suspend, sp_pci_resume);
472+
static const struct dev_pm_ops sp_pci_pm_ops = {
473+
.suspend = pm_sleep_ptr(sp_pci_suspend),
474+
.resume = pm_sleep_ptr(sp_pci_resume),
475+
.freeze = pm_sleep_ptr(sp_pci_suspend),
476+
.thaw = pm_sleep_ptr(sp_pci_resume),
477+
.poweroff = pm_sleep_ptr(sp_pci_suspend),
478+
.restore_early = pm_sleep_ptr(sp_pci_restore),
479+
};
466480

467481
static struct pci_driver sp_pci_driver = {
468482
.name = "ccp",

drivers/crypto/ccp/tee-dev.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,8 @@ int psp_check_tee_status(void)
394394
return 0;
395395
}
396396
EXPORT_SYMBOL(psp_check_tee_status);
397+
398+
int tee_restore(struct psp_device *psp)
399+
{
400+
return tee_init_ring(psp->tee_data);
401+
}

drivers/crypto/ccp/tee-dev.h

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

123123
int tee_dev_init(struct psp_device *psp);
124124
void tee_dev_destroy(struct psp_device *psp);
125+
int tee_restore(struct psp_device *psp);
125126

126127
#endif /* __TEE_DEV_H__ */

0 commit comments

Comments
 (0)