Skip to content

Commit f735425

Browse files
committed
crypto: ccp: Add external API interface for PSP module initialization
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. Co-developed-by: Ashish Kalra <ashish.kalra@amd.com> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Link: https://lore.kernel.org/r/15279ca0cad56a07cf12834ec544310f85ff5edc.1739226950.git.ashish.kalra@amd.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 8a01902 commit f735425

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

drivers/crypto/ccp/sp-dev.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/types.h>
2020
#include <linux/ccp.h>
2121

22+
#include "sev-dev.h"
2223
#include "ccp-dev.h"
2324
#include "sp-dev.h"
2425

@@ -253,8 +254,12 @@ struct sp_device *sp_get_psp_master_device(void)
253254
static int __init sp_mod_init(void)
254255
{
255256
#ifdef CONFIG_X86
257+
static bool initialized;
256258
int ret;
257259

260+
if (initialized)
261+
return 0;
262+
258263
ret = sp_pci_init();
259264
if (ret)
260265
return ret;
@@ -263,6 +268,8 @@ static int __init sp_mod_init(void)
263268
psp_pci_init();
264269
#endif
265270

271+
initialized = true;
272+
266273
return 0;
267274
#endif
268275

@@ -279,6 +286,13 @@ static int __init sp_mod_init(void)
279286
return -ENODEV;
280287
}
281288

289+
#if IS_BUILTIN(CONFIG_KVM_AMD) && IS_ENABLED(CONFIG_KVM_AMD_SEV)
290+
int __init sev_module_init(void)
291+
{
292+
return sp_mod_init();
293+
}
294+
#endif
295+
282296
static void __exit sp_mod_exit(void)
283297
{
284298
#ifdef CONFIG_X86

include/linux/psp-sev.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,15 @@ struct sev_data_snp_commit {
814814

815815
#ifdef CONFIG_CRYPTO_DEV_SP_PSP
816816

817+
/**
818+
* sev_module_init - perform PSP SEV module initialization
819+
*
820+
* Returns:
821+
* 0 if the PSP module is successfully initialized
822+
* negative value if the PSP module initialization fails
823+
*/
824+
int sev_module_init(void);
825+
817826
/**
818827
* sev_platform_init - perform SEV INIT command
819828
*

0 commit comments

Comments
 (0)