Re: [PATCH v3 6/7] KVM: SVM: Add support to initialize SEV/SNP functionality in KVM

From: Dionna Amalie Glaze
Date: Fri Jan 10 2025 - 19:42:18 EST


On Fri, Jan 10, 2025 at 4:40 PM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
>
> On Fri, Jan 10, 2025, Ashish Kalra wrote:
> > It looks like i have hit a serious blocker issue with this approach of moving
> > SEV/SNP initialization to KVM module load time.
> >
> > While testing with kvm_amd and PSP driver built-in, it looks like kvm_amd
> > driver is being loaded/initialized before PSP driver is loaded, and that
> > causes sev_platform_init() call from sev_hardware_setup(kvm_amd) to fail:
> >
> > [ 10.717898] kvm_amd: TSC scaling supported
> > [ 10.722470] kvm_amd: Nested Virtualization enabled
> > [ 10.727816] kvm_amd: Nested Paging enabled
> > [ 10.732388] kvm_amd: LBR virtualization supported
> > [ 10.737639] kvm_amd: SEV enabled (ASIDs 100 - 509)
> > [ 10.742985] kvm_amd: SEV-ES enabled (ASIDs 1 - 99)
> > [ 10.748333] kvm_amd: SEV-SNP enabled (ASIDs 1 - 99)
> > [ 10.753768] PSP driver not init <<<---- sev_platform_init() returns failure as PSP driver is still not initialized
> > [ 10.757563] kvm_amd: Virtual VMLOAD VMSAVE supported
> > [ 10.763124] kvm_amd: Virtual GIF supported
> > ...
> > ...
> > [ 12.514857] ccp 0000:23:00.1: enabling device (0000 -> 0002)
> > [ 12.521691] ccp 0000:23:00.1: no command queues available
> > [ 12.527991] ccp 0000:23:00.1: sev enabled
> > [ 12.532592] ccp 0000:23:00.1: psp enabled
> > [ 12.537382] ccp 0000:a2:00.1: enabling device (0000 -> 0002)
> > [ 12.544389] ccp 0000:a2:00.1: no command queues available
> > [ 12.550627] ccp 0000:a2:00.1: psp enabled
> >
> > depmod -> modules.builtin show kernel/arch/x86/kvm/kvm_amd.ko higher on the list and before kernel/drivers/crypto/ccp/ccp.ko
> >
> > modules.builtin:
> > kernel/arch/x86/kvm/kvm.ko
> > kernel/arch/x86/kvm/kvm-amd.ko
> > ...
> > ...
> > kernel/drivers/crypto/ccp/ccp.ko
> >
> > I believe that the modules which are compiled first get called first and it
> > looks like that the only way to change the order for builtin modules is by
> > changing which makefiles get compiled first ?
> >
> > Is there a way to change the load order of built-in modules and/or change
> > dependency of built-in modules ?
>
> The least awful option I know of would be to have the PSP use a higher priority
> initcall type so that it runs before the standard initcalls. When compiled as
> a module, all initcall types are #defined to module_init.
>
> E.g. this should work, /cross fingers
>
> diff --git a/drivers/crypto/ccp/sp-dev.c b/drivers/crypto/ccp/sp-dev.c
> index 7eb3e4668286..02c49fbf6198 100644
> --- a/drivers/crypto/ccp/sp-dev.c
> +++ b/drivers/crypto/ccp/sp-dev.c
> @@ -295,5 +295,6 @@ static void __exit sp_mod_exit(void)
> #endif
> }
>
> -module_init(sp_mod_init);
> +/* The PSP needs to be initialized before dependent modules, e.g. before KVM. */
> +subsys_initcall(sp_mod_init);

I was 2 seconds from clicking send with this exact suggestion. There
are examples in 'drivers/' that use subsys_initcall / module_exit
pairs.

> module_exit(sp_mod_exit);



--
-Dionna Glaze, PhD, CISSP, CCSP (she/her)