Skip to content

Commit 18085ac

Browse files
codomaniabp3tk0v
authored andcommitted
crypto: ccp: Provide an API to issue SEV and SNP commands
Export sev_do_cmd() as a generic API for the hypervisor to issue commands to manage an SEV or an SNP guest. The commands for SEV and SNP are defined in the SEV and SEV-SNP firmware specifications. Signed-off-by: Brijesh Singh <brijesh.singh@amd.com> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com> Signed-off-by: Michael Roth <michael.roth@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20240126041126.1927228-15-michael.roth@amd.com
1 parent 1ca5614 commit 18085ac

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

drivers/crypto/ccp/sev-dev.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret)
431431
return ret;
432432
}
433433

434-
static int sev_do_cmd(int cmd, void *data, int *psp_ret)
434+
int sev_do_cmd(int cmd, void *data, int *psp_ret)
435435
{
436436
int rc;
437437

@@ -441,6 +441,7 @@ static int sev_do_cmd(int cmd, void *data, int *psp_ret)
441441

442442
return rc;
443443
}
444+
EXPORT_SYMBOL_GPL(sev_do_cmd);
444445

445446
static int __sev_init_locked(int *error)
446447
{

include/linux/psp-sev.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,22 @@ int sev_guest_df_flush(int *error);
915915
*/
916916
int sev_guest_decommission(struct sev_data_decommission *data, int *error);
917917

918+
/**
919+
* sev_do_cmd - issue an SEV or an SEV-SNP command
920+
*
921+
* @cmd: SEV or SEV-SNP firmware command to issue
922+
* @data: arguments for firmware command
923+
* @psp_ret: SEV command return code
924+
*
925+
* Returns:
926+
* 0 if the SEV device successfully processed the command
927+
* -%ENODEV if the PSP device is not available
928+
* -%ENOTSUPP if PSP device does not support SEV
929+
* -%ETIMEDOUT if the SEV command timed out
930+
* -%EIO if PSP device returned a non-zero return code
931+
*/
932+
int sev_do_cmd(int cmd, void *data, int *psp_ret);
933+
918934
void *psp_copy_user_blob(u64 uaddr, u32 len);
919935

920936
#else /* !CONFIG_CRYPTO_DEV_SP_PSP */
@@ -930,6 +946,9 @@ sev_guest_deactivate(struct sev_data_deactivate *data, int *error) { return -ENO
930946
static inline int
931947
sev_guest_decommission(struct sev_data_decommission *data, int *error) { return -ENODEV; }
932948

949+
static inline int
950+
sev_do_cmd(int cmd, void *data, int *psp_ret) { return -ENODEV; }
951+
933952
static inline int
934953
sev_guest_activate(struct sev_data_activate *data, int *error) { return -ENODEV; }
935954

0 commit comments

Comments
 (0)