Skip to content

Commit

Permalink
crypto: ccp: Add external API interface for PSP module initialization
Browse files Browse the repository at this point in the history
KVM is dependent on the PSP SEV driver and PSP SEV driver needs to be
loaded before KVM module. In case of module loading any dependent
modules are automatically loaded but in case of built-in modules there
is no inherent mechanism available to specify dependencies between
modules and ensure that any dependent modules are loaded implicitly.

Add a new external API interface for PSP module initialization which
allows PSP SEV driver to be loaded explicitly if KVM is built-in.

Signed-off-by: Sean Christopherson <[email protected]>
Co-developed-by: Ashish Kalra <[email protected]>
Signed-off-by: Ashish Kalra <[email protected]>
Reviewed-by: Tom Lendacky <[email protected]>
Message-ID: <15279ca0cad56a07cf12834ec544310f85ff5edc.1739226950.git.ashish.kalra@amd.com>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
sean-jc authored and bonzini committed Feb 14, 2025
1 parent 3bb7dce commit 435b344
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions drivers/crypto/ccp/sp-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <linux/types.h>
#include <linux/ccp.h>

#include "sev-dev.h"
#include "ccp-dev.h"
#include "sp-dev.h"

Expand Down Expand Up @@ -253,8 +254,12 @@ struct sp_device *sp_get_psp_master_device(void)
static int __init sp_mod_init(void)
{
#ifdef CONFIG_X86
static bool initialized;
int ret;

if (initialized)
return 0;

ret = sp_pci_init();
if (ret)
return ret;
Expand All @@ -263,6 +268,8 @@ static int __init sp_mod_init(void)
psp_pci_init();
#endif

initialized = true;

return 0;
#endif

Expand All @@ -279,6 +286,13 @@ static int __init sp_mod_init(void)
return -ENODEV;
}

#if IS_BUILTIN(CONFIG_KVM_AMD) && IS_ENABLED(CONFIG_KVM_AMD_SEV)
int __init sev_module_init(void)
{
return sp_mod_init();
}
#endif

static void __exit sp_mod_exit(void)
{
#ifdef CONFIG_X86
Expand Down
9 changes: 9 additions & 0 deletions include/linux/psp-sev.h
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,15 @@ struct sev_data_snp_commit {

#ifdef CONFIG_CRYPTO_DEV_SP_PSP

/**
* sev_module_init - perform PSP SEV module initialization
*
* Returns:
* 0 if the PSP module is successfully initialized
* negative value if the PSP module initialization fails
*/
int sev_module_init(void);

/**
* sev_platform_init - perform SEV INIT command
*
Expand Down

0 comments on commit 435b344

Please sign in to comment.