Thread (178 messages) 178 messages, 11 authors, 2022-06-06

Re: [PATCH Part2 RFC v4 23/40] KVM: SVM: Add KVM_SEV_SNP_LAUNCH_START command

From: Peter Gonda <hidden>
Date: 2021-07-12 18:46:13
Also in: linux-coco, linux-crypto, linux-efi, linux-mm, lkml, platform-driver-x86

+static int snp_decommission_context(struct kvm *kvm)
+{
+       struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
+       struct sev_data_snp_decommission data = {};
+       int ret;
+
+       /* If context is not created then do nothing */
+       if (!sev->snp_context)
+               return 0;
+
+       data.gctx_paddr = __sme_pa(sev->snp_context);
+       ret = snp_guest_decommission(&data, NULL);
+       if (ret)
+               return ret;
Should we WARN or pr_err here? I see in the case of
snp_launch_start's e_free_context we do not warn the user they have
leaked a firmware page.
quoted hunk ↗ jump to hunk
+
+       /* free the context page now */
+       snp_free_firmware_page(sev->snp_context);
+       sev->snp_context = NULL;
+
+       return 0;
+}
+
 void sev_vm_destroy(struct kvm *kvm)
 {
        struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
@@ -1847,7 +1969,15 @@ void sev_vm_destroy(struct kvm *kvm)

        mutex_unlock(&kvm->lock);

-       sev_unbind_asid(kvm, sev->handle);
+       if (sev_snp_guest(kvm)) {
+               if (snp_decommission_context(kvm)) {
+                       pr_err("Failed to free SNP guest context, leaking asid!\n");
Should these errors be a WARN since we are leaking some state?

+                       return;
+               }
+       } else {
+               sev_unbind_asid(kvm, sev->handle);
+       }
+
        sev_asid_free(sev);
 }
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help