From: "Kalra, Ashish" <ashish.kalra@amd.com>
To: Tom Lendacky <thomas.lendacky@amd.com>,
seanjc@google.com, pbonzini@redhat.com, tglx@linutronix.de,
mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
x86@kernel.org, hpa@zytor.com, john.allen@amd.com,
herbert@gondor.apana.org.au, davem@davemloft.net,
joro@8bytes.org, suravee.suthikulpanit@amd.com, will@kernel.org,
robin.murphy@arm.com
Cc: michael.roth@amd.com, dionnaglaze@google.com, nikunj@amd.com,
ardb@kernel.org, kevinloughlin@google.com,
Neeraj.Upadhyay@amd.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
linux-coco@lists.linux.dev, iommu@lists.linux.dev
Subject: Re: [PATCH v3 1/3] crypto: ccp: Add external API interface for PSP module initialization
Date: Fri, 7 Feb 2025 22:52:50 -0600 [thread overview]
Message-ID: <30d6b5d6-d397-490a-afcf-0cae9d6d303c@amd.com> (raw)
In-Reply-To: <2794745e-c33a-68dc-f0e7-961e1631299e@amd.com>
Hello Tom,
On 2/7/2025 3:45 PM, Tom Lendacky wrote:
> On 2/3/25 15:56, Ashish Kalra wrote:
>> From: Sean Christopherson <seanjc@google.com>
>>
>> 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>
>> ---
>> drivers/crypto/ccp/sp-dev.c | 14 ++++++++++++++
>> include/linux/psp-sev.h | 9 +++++++++
>> 2 files changed, 23 insertions(+)
>>
>> diff --git a/drivers/crypto/ccp/sp-dev.c b/drivers/crypto/ccp/sp-dev.c
>> index 7eb3e4668286..3467f6db4f50 100644
>> --- a/drivers/crypto/ccp/sp-dev.c
>> +++ b/drivers/crypto/ccp/sp-dev.c
>> @@ -19,6 +19,7 @@
>> #include <linux/types.h>
>> #include <linux/ccp.h>
>>
>> +#include "sev-dev.h"
>> #include "ccp-dev.h"
>> #include "sp-dev.h"
>>
>> @@ -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;
>
> Do we need any kind of mutex protection here? Is the init process
> parallelized? We only have one caller today, so probably not a big deal.
>
Yes the booting will be parallelized, but the main reason we needed to
explicitly initialize the PSP driver from KVM module load time was that
for the built-in modules case, KVM module was being loaded before the PSP
driver, as per the order of compilation of modules.
So as kvm_amd module will be loading before CCP driver, therefore,
i don't believe kvm module load -> sev_module_init() -> sp_mod_init() can execute
concurrently with CCP module probe -> sp_mod_init().
Therefore i believe, the above code in sp_mod_init() should be safe.
And sev_module_init() is only called in case kvm_amd module is built-in.
Thanks,
Ashish
> If we don't need that:
>
> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
>
> Thanks,
> Tom
>
>> +
>> ret = sp_pci_init();
>> if (ret)
>> return ret;
>> @@ -263,6 +268,8 @@ static int __init sp_mod_init(void)
>> psp_pci_init();
>> #endif
>>
>> + initialized = true;
>> +
>> return 0;
>> #endif
>>
>> @@ -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
>> diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h
>> index 903ddfea8585..f3cad182d4ef 100644
>> --- a/include/linux/psp-sev.h
>> +++ b/include/linux/psp-sev.h
>> @@ -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
>> *
next prev parent reply other threads:[~2025-02-08 4:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-03 21:56 [PATCH v3 0/3] Fix broken SNP support with KVM module built-in Ashish Kalra
2025-02-03 21:56 ` [PATCH v3 1/3] crypto: ccp: Add external API interface for PSP module initialization Ashish Kalra
2025-02-07 21:45 ` Tom Lendacky
2025-02-08 4:52 ` Kalra, Ashish [this message]
2025-02-03 21:56 ` [PATCH v3 2/3] KVM: SVM: Ensure PSP module is initialized if KVM module is built-in Ashish Kalra
2025-02-07 21:46 ` Tom Lendacky
2025-02-03 21:56 ` [PATCH v3 3/3] x86/sev: Fix broken SNP support with KVM module built-in Ashish Kalra
2025-02-05 9:51 ` Vasant Hegde
2025-02-05 15:17 ` Sean Christopherson
2025-02-05 16:55 ` Vasant Hegde
2025-02-05 19:31 ` Sean Christopherson
2025-02-05 22:54 ` Kalra, Ashish
2025-02-07 15:52 ` Sean Christopherson
2025-02-07 21:45 ` Kalra, Ashish
2025-02-06 5:41 ` Vasant Hegde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=30d6b5d6-d397-490a-afcf-0cae9d6d303c@amd.com \
--to=ashish.kalra@amd.com \
--cc=Neeraj.Upadhyay@amd.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=davem@davemloft.net \
--cc=dionnaglaze@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=hpa@zytor.com \
--cc=iommu@lists.linux.dev \
--cc=john.allen@amd.com \
--cc=joro@8bytes.org \
--cc=kevinloughlin@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=mingo@redhat.com \
--cc=nikunj@amd.com \
--cc=pbonzini@redhat.com \
--cc=robin.murphy@arm.com \
--cc=seanjc@google.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=will@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®