Re: [PATCH 1/5] KVM: SVM: Decrypt SEV VMSA in dump_vmcb() if debugging is enabled
From: Tom Lendacky
Date: Mon Apr 14 2025 - 12:13:12 EST
On 4/10/25 18:14, Sean Christopherson wrote:
> On Mon, Mar 24, 2025, Tom Lendacky wrote:
>> On 3/20/25 08:26, Tom Lendacky wrote:
>>> An SEV-ES/SEV-SNP VM save area (VMSA) can be decrypted if the guest
>>> policy allows debugging. Update the dump_vmcb() routine to output
>>> some of the SEV VMSA contents if possible. This can be useful for
>>> debug purposes.
>>>
>>> Signed-off-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
>>> ---
>>> arch/x86/kvm/svm/sev.c | 98 ++++++++++++++++++++++++++++++++++++++++++
>>> arch/x86/kvm/svm/svm.c | 13 ++++++
>>> arch/x86/kvm/svm/svm.h | 11 +++++
>>> 3 files changed, 122 insertions(+)
>>>
>>> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
>>> index 661108d65ee7..6e3f5042d9ce 100644
>>> --- a/arch/x86/kvm/svm/sev.c
>>> +++ b/arch/x86/kvm/svm/sev.c
>>
>>> +
>>> + if (sev_snp_guest(vcpu->kvm)) {
>>> + struct sev_data_snp_dbg dbg = {0};
>>> +
>>> + vmsa = snp_alloc_firmware_page(__GFP_ZERO);
>>> + if (!vmsa)
>>> + return NULL;
>>> +
>>> + dbg.gctx_paddr = __psp_pa(sev->snp_context);
>>> + dbg.src_addr = svm->vmcb->control.vmsa_pa;
>>> + dbg.dst_addr = __psp_pa(vmsa);
>>> +
>>> + ret = sev_issue_cmd(vcpu->kvm, SEV_CMD_SNP_DBG_DECRYPT, &dbg, &error);
>>
>> This can also be sev_do_cmd() where the file descriptor isn't checked.
>> Since it isn't really a user initiated call, that might be desirable since
>> this could also be useful for debugging during guest destruction (when the
>> file descriptor has already been closed) for VMSAs that haven't exited
>> with an INVALID exit code.
>>
>> Just an FYI, I can change this call and the one below to sev_do_cmd() if
>> agreed upon.
>
> Works for me. Want to provide a delta patch? I can fixup when applying.
Will do.
Thanks,
Tom