Skip to content

Commit 459daec

Browse files
ashkalraherbertx
authored andcommitted
crypto: ccp - Cache SEV platform status and platform state
Cache the SEV platform status into sev_device structure and use this cached SEV platform status for api_major/minor/build. The platform state is unique between SEV and SNP and hence needs to be tracked independently. Remove the state field from sev_device structure and instead track SEV state from the cached SEV platform status. Suggested-by: Tom Lendacky <[email protected]> Reviewed-by: Tom Lendacky <[email protected]> Signed-off-by: Ashish Kalra <[email protected]> Reviewed-by: Kim Phillips <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 450bbe4 commit 459daec

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

drivers/crypto/ccp/sev-dev.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ static int __sev_platform_init_locked(int *error)
12861286

12871287
sev = psp_master->sev_data;
12881288

1289-
if (sev->state == SEV_STATE_INIT)
1289+
if (sev->sev_plat_status.state == SEV_STATE_INIT)
12901290
return 0;
12911291

12921292
__sev_platform_init_handle_tmr(sev);
@@ -1318,7 +1318,7 @@ static int __sev_platform_init_locked(int *error)
13181318
return rc;
13191319
}
13201320

1321-
sev->state = SEV_STATE_INIT;
1321+
sev->sev_plat_status.state = SEV_STATE_INIT;
13221322

13231323
/* Prepare for first SEV guest launch after INIT */
13241324
wbinvd_on_all_cpus();
@@ -1347,7 +1347,7 @@ static int _sev_platform_init_locked(struct sev_platform_init_args *args)
13471347

13481348
sev = psp_master->sev_data;
13491349

1350-
if (sev->state == SEV_STATE_INIT)
1350+
if (sev->sev_plat_status.state == SEV_STATE_INIT)
13511351
return 0;
13521352

13531353
rc = __sev_snp_init_locked(&args->error);
@@ -1384,7 +1384,7 @@ static int __sev_platform_shutdown_locked(int *error)
13841384

13851385
sev = psp->sev_data;
13861386

1387-
if (sev->state == SEV_STATE_UNINIT)
1387+
if (sev->sev_plat_status.state == SEV_STATE_UNINIT)
13881388
return 0;
13891389

13901390
ret = __sev_do_cmd_locked(SEV_CMD_SHUTDOWN, NULL, error);
@@ -1394,7 +1394,7 @@ static int __sev_platform_shutdown_locked(int *error)
13941394
return ret;
13951395
}
13961396

1397-
sev->state = SEV_STATE_UNINIT;
1397+
sev->sev_plat_status.state = SEV_STATE_UNINIT;
13981398
dev_dbg(sev->dev, "SEV firmware shutdown\n");
13991399

14001400
return ret;
@@ -1502,7 +1502,7 @@ static int sev_ioctl_do_pek_pdh_gen(int cmd, struct sev_issue_cmd *argp, bool wr
15021502
if (!writable)
15031503
return -EPERM;
15041504

1505-
if (sev->state == SEV_STATE_UNINIT) {
1505+
if (sev->sev_plat_status.state == SEV_STATE_UNINIT) {
15061506
rc = sev_move_to_init_state(argp, &shutdown_required);
15071507
if (rc)
15081508
return rc;
@@ -1551,7 +1551,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable)
15511551
data.len = input.length;
15521552

15531553
cmd:
1554-
if (sev->state == SEV_STATE_UNINIT) {
1554+
if (sev->sev_plat_status.state == SEV_STATE_UNINIT) {
15551555
ret = sev_move_to_init_state(argp, &shutdown_required);
15561556
if (ret)
15571557
goto e_free_blob;
@@ -1606,10 +1606,12 @@ static int sev_get_api_version(void)
16061606
return 1;
16071607
}
16081608

1609+
/* Cache SEV platform status */
1610+
sev->sev_plat_status = status;
1611+
16091612
sev->api_major = status.api_major;
16101613
sev->api_minor = status.api_minor;
16111614
sev->build = status.build;
1612-
sev->state = status.state;
16131615

16141616
return 0;
16151617
}
@@ -1837,7 +1839,7 @@ static int sev_ioctl_do_pek_import(struct sev_issue_cmd *argp, bool writable)
18371839
data.oca_cert_len = input.oca_cert_len;
18381840

18391841
/* If platform is not in INIT state then transition it to INIT */
1840-
if (sev->state != SEV_STATE_INIT) {
1842+
if (sev->sev_plat_status.state != SEV_STATE_INIT) {
18411843
ret = sev_move_to_init_state(argp, &shutdown_required);
18421844
if (ret)
18431845
goto e_free_oca;
@@ -2008,7 +2010,7 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)
20082010

20092011
cmd:
20102012
/* If platform is not in INIT state then transition it to INIT. */
2011-
if (sev->state != SEV_STATE_INIT) {
2013+
if (sev->sev_plat_status.state != SEV_STATE_INIT) {
20122014
if (!writable) {
20132015
ret = -EPERM;
20142016
goto e_free_cert;

drivers/crypto/ccp/sev-dev.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ struct sev_device {
4242

4343
struct sev_vdata *vdata;
4444

45-
int state;
4645
unsigned int int_rcvd;
4746
wait_queue_head_t int_queue;
4847
struct sev_misc_dev *misc;
@@ -57,6 +56,8 @@ struct sev_device {
5756
bool cmd_buf_backup_active;
5857

5958
bool snp_initialized;
59+
60+
struct sev_user_data_status sev_plat_status;
6061
};
6162

6263
int sev_dev_init(struct psp_device *psp);

0 commit comments

Comments
 (0)