Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Sean Christopherson <seanjc@google.com>
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>
Message-ID: <15279ca0cad56a07cf12834ec544310f85ff5edc.1739226950.git.ashish.kalra@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Sean Christopherson and committed by
Paolo Bonzini
435b344a 3bb7dceb

+23
+14
drivers/crypto/ccp/sp-dev.c
··· 19 19 #include <linux/types.h> 20 20 #include <linux/ccp.h> 21 21 22 + #include "sev-dev.h" 22 23 #include "ccp-dev.h" 23 24 #include "sp-dev.h" 24 25 ··· 254 253 static int __init sp_mod_init(void) 255 254 { 256 255 #ifdef CONFIG_X86 256 + static bool initialized; 257 257 int ret; 258 + 259 + if (initialized) 260 + return 0; 258 261 259 262 ret = sp_pci_init(); 260 263 if (ret) ··· 267 262 #ifdef CONFIG_CRYPTO_DEV_SP_PSP 268 263 psp_pci_init(); 269 264 #endif 265 + 266 + initialized = true; 270 267 271 268 return 0; 272 269 #endif ··· 285 278 286 279 return -ENODEV; 287 280 } 281 + 282 + #if IS_BUILTIN(CONFIG_KVM_AMD) && IS_ENABLED(CONFIG_KVM_AMD_SEV) 283 + int __init sev_module_init(void) 284 + { 285 + return sp_mod_init(); 286 + } 287 + #endif 288 288 289 289 static void __exit sp_mod_exit(void) 290 290 {
+9
include/linux/psp-sev.h
··· 815 815 #ifdef CONFIG_CRYPTO_DEV_SP_PSP 816 816 817 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 + 826 + /** 818 827 * sev_platform_init - perform SEV INIT command 819 828 * 820 829 * @args: struct sev_platform_init_args to pass in arguments