Skip to content

Commit fad133c

Browse files
tlendackybp3tk0v
authored andcommitted
crypto: ccp: Add the SNP_COMMIT command
The SNP_COMMIT command is used to commit the currently installed version of the SEV firmware. Once committed, the firmware cannot be replaced with a previous firmware version (cannot be rolled back). This command will also update the reported TCB to match that of the currently installed firmware. [ mdr: Note the reported TCB update in the documentation/commit. ] Signed-off-by: Tom Lendacky <[email protected]> Signed-off-by: Michael Roth <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f5db884 commit fad133c

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

Documentation/virt/coco/sev-guest.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ The SNP_PLATFORM_STATUS command is used to query the SNP platform status. The
151151
status includes API major, minor version and more. See the SEV-SNP
152152
specification for further details.
153153

154+
2.5 SNP_COMMIT
155+
--------------
156+
:Technology: sev-snp
157+
:Type: hypervisor ioctl cmd
158+
:Returns (out): 0 on success, -negative on error
159+
160+
SNP_COMMIT is used to commit the currently installed firmware using the
161+
SEV-SNP firmware SNP_COMMIT command. This prevents roll-back to a previously
162+
committed firmware version. This will also update the reported TCB to match
163+
that of the currently installed firmware.
164+
154165
3. SEV-SNP CPUID Enforcement
155166
============================
156167

drivers/crypto/ccp/sev-dev.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ static int sev_cmd_buffer_len(int cmd)
222222
case SEV_CMD_SNP_PLATFORM_STATUS: return sizeof(struct sev_data_snp_addr);
223223
case SEV_CMD_SNP_GUEST_REQUEST: return sizeof(struct sev_data_snp_guest_request);
224224
case SEV_CMD_SNP_CONFIG: return sizeof(struct sev_user_data_snp_config);
225+
case SEV_CMD_SNP_COMMIT: return sizeof(struct sev_data_snp_commit);
225226
default: return 0;
226227
}
227228

@@ -1990,6 +1991,19 @@ static int sev_ioctl_do_snp_platform_status(struct sev_issue_cmd *argp)
19901991
return ret;
19911992
}
19921993

1994+
static int sev_ioctl_do_snp_commit(struct sev_issue_cmd *argp)
1995+
{
1996+
struct sev_device *sev = psp_master->sev_data;
1997+
struct sev_data_snp_commit buf;
1998+
1999+
if (!sev->snp_initialized)
2000+
return -EINVAL;
2001+
2002+
buf.len = sizeof(buf);
2003+
2004+
return __sev_do_cmd_locked(SEV_CMD_SNP_COMMIT, &buf, &argp->error);
2005+
}
2006+
19932007
static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
19942008
{
19952009
void __user *argp = (void __user *)arg;
@@ -2044,6 +2058,9 @@ static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
20442058
case SNP_PLATFORM_STATUS:
20452059
ret = sev_ioctl_do_snp_platform_status(&input);
20462060
break;
2061+
case SNP_COMMIT:
2062+
ret = sev_ioctl_do_snp_commit(&input);
2063+
break;
20472064
default:
20482065
ret = -EINVAL;
20492066
goto out;

include/linux/psp-sev.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,15 @@ struct sev_platform_init_args {
801801
bool probe;
802802
};
803803

804+
/**
805+
* struct sev_data_snp_commit - SNP_COMMIT structure
806+
*
807+
* @len: length of the command buffer read by the PSP
808+
*/
809+
struct sev_data_snp_commit {
810+
u32 len;
811+
} __packed;
812+
804813
#ifdef CONFIG_CRYPTO_DEV_SP_PSP
805814

806815
/**

include/uapi/linux/psp-sev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum {
2929
SEV_GET_ID, /* This command is deprecated, use SEV_GET_ID2 */
3030
SEV_GET_ID2,
3131
SNP_PLATFORM_STATUS,
32+
SNP_COMMIT,
3233

3334
SEV_MAX,
3435
};

0 commit comments

Comments
 (0)