From: Alexey Kardashevskiy <aik@amd.com>
To: Ashish Kalra <Ashish.Kalra@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, thomas.lendacky@amd.com,
john.allen@amd.com, herbert@gondor.apana.org.au,
davem@davemloft.net
Cc: michael.roth@amd.com, dionnaglaze@google.com,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-crypto@vger.kernel.org, linux-coco@lists.linux.dev
Subject: Re: [PATCH v2 8/9] KVM: SVM: Add support to initialize SEV/SNP functionality in KVM
Date: Fri, 27 Dec 2024 21:36:13 +1100 [thread overview]
Message-ID: <eaf008d6-87ec-45b4-9ace-6d499afd140a@amd.com> (raw)
In-Reply-To: <bc82a369d20b82177c3aac97fc5df0d9018c9fbc.1734392473.git.ashish.kalra@amd.com>
On 17/12/24 10:59, Ashish Kalra wrote:
> From: Ashish Kalra <ashish.kalra@amd.com>
>
> Remove platform initialization of SEV/SNP from PSP driver probe time and
> move it to KVM module load time so that KVM can do SEV/SNP platform
> initialization explicitly if it actually wants to use SEV/SNP
> functionality.
>
> With this patch, KVM will explicitly call into the PSP driver at load time
> to initialize SNP by default while SEV initialization is done on-demand
> when SEV/SEV-ES VMs are being launched.
>
> Additionally do SEV platform shutdown when all SEV/SEV-ES VMs have been
> destroyed to support SEV firmware hotloading and do full SEV and SNP
> platform shutdown during KVM module unload time.
>
> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
> ---
> arch/x86/kvm/svm/sev.c | 33 +++++++++++++++++++++++++++++----
> 1 file changed, 29 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 72674b8825c4..d55e281ac798 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -86,6 +86,7 @@ unsigned int max_sev_asid;
> static unsigned int min_sev_asid;
> static unsigned long sev_me_mask;
> static unsigned int nr_asids;
> +static unsigned int nr_sev_vms_active;
> static unsigned long *sev_asid_bitmap;
> static unsigned long *sev_reclaim_asid_bitmap;
>
> @@ -444,10 +445,16 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,
> if (ret)
> goto e_no_asid;
>
> - init_args.probe = false;
> - ret = sev_platform_init(&init_args);
> - if (ret)
> - goto e_free;
> + if ((vm_type == KVM_X86_SEV_VM) ||
> + (vm_type == KVM_X86_SEV_ES_VM)) {
> + down_write(&sev_deactivate_lock);
> + ret = sev_platform_init(&init_args);
> + if (!ret)
> + ++nr_sev_vms_active;
> + up_write(&sev_deactivate_lock);
> + if (ret)
> + goto e_free;
> + }
>
> /* This needs to happen after SEV/SNP firmware initialization. */
> if (vm_type == KVM_X86_SNP_VM) {
> @@ -2942,6 +2949,10 @@ void sev_vm_destroy(struct kvm *kvm)
> return;
> } else {
> sev_unbind_asid(kvm, sev->handle);
> + down_write(&sev_deactivate_lock);
> + if (--nr_sev_vms_active == 0)
> + sev_platform_shutdown();
> + up_write(&sev_deactivate_lock);
> }
>
> sev_asid_free(sev);
> @@ -2966,6 +2977,7 @@ void __init sev_set_cpu_caps(void)
> void __init sev_hardware_setup(void)
> {
> unsigned int eax, ebx, ecx, edx, sev_asid_count, sev_es_asid_count;
> + struct sev_platform_init_args init_args = {0};
{} (without '0') should do the trick too.
> bool sev_snp_supported = false;
> bool sev_es_supported = false;
> bool sev_supported = false;
> @@ -3082,6 +3094,16 @@ void __init sev_hardware_setup(void)
> sev_supported_vmsa_features = 0;
> if (sev_es_debug_swap_enabled)
> sev_supported_vmsa_features |= SVM_SEV_FEAT_DEBUG_SWAP;
> +
> + if (!sev_enabled)
> + return;
> +
> + /*
> + * NOTE: Always do SNP INIT regardless of sev_snp_supported
> + * as SNP INIT has to be done to launch legacy SEV/SEV-ES
> + * VMs in case SNP is enabled system-wide.
Out of curiosity - is not SNP INIT what "enables SNP system-wide"? What
is that thing which SNP INIT does to allow SEV VMs to run? Thanks,
> + */
> + sev_snp_platform_init(&init_args);
> }
>
> void sev_hardware_unsetup(void)
> @@ -3097,6 +3119,9 @@ void sev_hardware_unsetup(void)
>
> misc_cg_set_capacity(MISC_CG_RES_SEV, 0);
> misc_cg_set_capacity(MISC_CG_RES_SEV_ES, 0);
> +
> + /* Do SEV and SNP Shutdown */
> + sev_snp_platform_shutdown();
> }
>
> int sev_cpu_init(struct svm_cpu_data *sd)
--
Alexey
next prev parent reply other threads:[~2024-12-27 10:36 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-16 23:56 [PATCH v2 0/9] Move initializing SEV/SNP functionality to KVM Ashish Kalra
2024-12-16 23:57 ` [PATCH v2 1/9] crypto: ccp: Move dev_info/err messages for SEV/SNP initialization Ashish Kalra
2024-12-27 8:58 ` Alexey Kardashevskiy
2024-12-16 23:57 ` [PATCH v2 2/9] crypto: ccp: Fix implicit SEV/SNP init and shutdown in ioctls Ashish Kalra
2024-12-27 8:59 ` Alexey Kardashevskiy
2024-12-16 23:58 ` [PATCH v2 3/9] crypto: ccp: Reset TMR size at SNP Shutdown Ashish Kalra
2024-12-27 9:07 ` Alexey Kardashevskiy
2025-01-03 17:00 ` Tom Lendacky
2025-01-07 2:59 ` Alexey Kardashevskiy
2024-12-16 23:58 ` [PATCH v2 4/9] crypto: ccp: Register SNP panic notifier only if SNP is enabled Ashish Kalra
2024-12-17 22:51 ` Dionna Amalie Glaze
2024-12-27 9:13 ` Alexey Kardashevskiy
2024-12-16 23:58 ` [PATCH v2 5/9] crypto: ccp: Add new SEV platform shutdown API Ashish Kalra
2024-12-16 23:59 ` [PATCH v2 6/9] crypto: ccp: Add new SEV/SNP " Ashish Kalra
2024-12-16 23:59 ` [PATCH v2 7/9] crypto: ccp: Add new SEV/SNP platform initialization API Ashish Kalra
2024-12-27 10:25 ` Alexey Kardashevskiy
2024-12-16 23:59 ` [PATCH v2 8/9] KVM: SVM: Add support to initialize SEV/SNP functionality in KVM Ashish Kalra
2024-12-27 10:36 ` Alexey Kardashevskiy [this message]
2024-12-17 0:00 ` [PATCH v2 9/9] crypto: ccp: Move SEV/SNP Platform initialization to KVM Ashish Kalra
2024-12-27 10:29 ` Alexey Kardashevskiy
2024-12-17 16:00 ` [PATCH v2 0/9] Move initializing SEV/SNP functionality " Dionna Amalie Glaze
2024-12-17 21:16 ` Kalra, Ashish
2024-12-17 21:37 ` Sean Christopherson
2024-12-17 23:16 ` Kalra, Ashish
2024-12-18 18:11 ` Daniel P. Berrangé
2024-12-18 19:10 ` Sean Christopherson
2024-12-19 1:11 ` Kalra, Ashish
2024-12-19 22:04 ` Kalra, Ashish
2024-12-19 23:12 ` Dionna Amalie Glaze
2024-12-20 8:49 ` Daniel P. Berrangé
2024-12-20 16:25 ` Sean Christopherson
2024-12-20 19:52 ` Kalra, Ashish
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=eaf008d6-87ec-45b4-9ace-6d499afd140a@amd.com \
--to=aik@amd.com \
--cc=Ashish.Kalra@amd.com \
--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=john.allen@amd.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=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--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®