]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: ccp - Cache SEV platform status and platform state
authorAshish Kalra <ashish.kalra@amd.com>
Mon, 21 Jul 2025 14:12:51 +0000 (14:12 +0000)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 16 Aug 2025 09:20:23 +0000 (17:20 +0800)
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 <thomas.lendacky@amd.com>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
Reviewed-by: Kim Phillips <kim.phillips@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/ccp/sev-dev.c
drivers/crypto/ccp/sev-dev.h

index e058ba0277929620c14618e43ba7e89e05f981d2..528013be1c0af9724161b06ed83e47c9fc54f134 100644 (file)
@@ -1286,7 +1286,7 @@ static int __sev_platform_init_locked(int *error)
 
        sev = psp_master->sev_data;
 
-       if (sev->state == SEV_STATE_INIT)
+       if (sev->sev_plat_status.state == SEV_STATE_INIT)
                return 0;
 
        __sev_platform_init_handle_tmr(sev);
@@ -1318,7 +1318,7 @@ static int __sev_platform_init_locked(int *error)
                return rc;
        }
 
-       sev->state = SEV_STATE_INIT;
+       sev->sev_plat_status.state = SEV_STATE_INIT;
 
        /* Prepare for first SEV guest launch after INIT */
        wbinvd_on_all_cpus();
@@ -1347,7 +1347,7 @@ static int _sev_platform_init_locked(struct sev_platform_init_args *args)
 
        sev = psp_master->sev_data;
 
-       if (sev->state == SEV_STATE_INIT)
+       if (sev->sev_plat_status.state == SEV_STATE_INIT)
                return 0;
 
        rc = __sev_snp_init_locked(&args->error);
@@ -1384,7 +1384,7 @@ static int __sev_platform_shutdown_locked(int *error)
 
        sev = psp->sev_data;
 
-       if (sev->state == SEV_STATE_UNINIT)
+       if (sev->sev_plat_status.state == SEV_STATE_UNINIT)
                return 0;
 
        ret = __sev_do_cmd_locked(SEV_CMD_SHUTDOWN, NULL, error);
@@ -1394,7 +1394,7 @@ static int __sev_platform_shutdown_locked(int *error)
                return ret;
        }
 
-       sev->state = SEV_STATE_UNINIT;
+       sev->sev_plat_status.state = SEV_STATE_UNINIT;
        dev_dbg(sev->dev, "SEV firmware shutdown\n");
 
        return ret;
@@ -1502,7 +1502,7 @@ static int sev_ioctl_do_pek_pdh_gen(int cmd, struct sev_issue_cmd *argp, bool wr
        if (!writable)
                return -EPERM;
 
-       if (sev->state == SEV_STATE_UNINIT) {
+       if (sev->sev_plat_status.state == SEV_STATE_UNINIT) {
                rc = sev_move_to_init_state(argp, &shutdown_required);
                if (rc)
                        return rc;
@@ -1551,7 +1551,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable)
        data.len = input.length;
 
 cmd:
-       if (sev->state == SEV_STATE_UNINIT) {
+       if (sev->sev_plat_status.state == SEV_STATE_UNINIT) {
                ret = sev_move_to_init_state(argp, &shutdown_required);
                if (ret)
                        goto e_free_blob;
@@ -1606,10 +1606,12 @@ static int sev_get_api_version(void)
                return 1;
        }
 
+       /* Cache SEV platform status */
+       sev->sev_plat_status = status;
+
        sev->api_major = status.api_major;
        sev->api_minor = status.api_minor;
        sev->build = status.build;
-       sev->state = status.state;
 
        return 0;
 }
@@ -1837,7 +1839,7 @@ static int sev_ioctl_do_pek_import(struct sev_issue_cmd *argp, bool writable)
        data.oca_cert_len = input.oca_cert_len;
 
        /* If platform is not in INIT state then transition it to INIT */
-       if (sev->state != SEV_STATE_INIT) {
+       if (sev->sev_plat_status.state != SEV_STATE_INIT) {
                ret = sev_move_to_init_state(argp, &shutdown_required);
                if (ret)
                        goto e_free_oca;
@@ -2008,7 +2010,7 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)
 
 cmd:
        /* If platform is not in INIT state then transition it to INIT. */
-       if (sev->state != SEV_STATE_INIT) {
+       if (sev->sev_plat_status.state != SEV_STATE_INIT) {
                if (!writable) {
                        ret = -EPERM;
                        goto e_free_cert;
index 3e4e5574e88a30278fa476543e0f423ee08480ac..24dd8ff8afaa15afa1700831de915860d64552b2 100644 (file)
@@ -42,7 +42,6 @@ struct sev_device {
 
        struct sev_vdata *vdata;
 
-       int state;
        unsigned int int_rcvd;
        wait_queue_head_t int_queue;
        struct sev_misc_dev *misc;
@@ -57,6 +56,8 @@ struct sev_device {
        bool cmd_buf_backup_active;
 
        bool snp_initialized;
+
+       struct sev_user_data_status sev_plat_status;
 };
 
 int sev_dev_init(struct psp_device *psp);