* [PATCH] KVM: SVM: Update dump_ghcb() to use the GHCB snapshot fields
@ 2025-04-28 18:55 Tom Lendacky
2025-04-29 15:22 ` Sean Christopherson
2025-05-02 21:50 ` Sean Christopherson
0 siblings, 2 replies; 8+ messages in thread
From: Tom Lendacky @ 2025-04-28 18:55 UTC (permalink / raw)
To: kvm, linux-kernel, x86
Cc: Paolo Bonzini, Sean Christopherson, Borislav Petkov, Dave Hansen,
Ingo Molnar, Thomas Gleixner, Michael Roth
Commit 4e15a0ddc3ff ("KVM: SEV: snapshot the GHCB before accessing it")
updated the SEV code to take a snapshot of the GHCB before using it. But
the dump_ghcb() function wasn't updated to use the snapshot locations.
This results in incorrect output from dump_ghcb() for the "is_valid" and
"valid_bitmap" fields.
Update dump_ghcb() to use the proper locations.
Fixes: 4e15a0ddc3ff ("KVM: SEV: snapshot the GHCB before accessing it")
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
arch/x86/kvm/svm/sev.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 0bc708ee2788..91e514d07f8a 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -3173,9 +3173,14 @@ void sev_free_vcpu(struct kvm_vcpu *vcpu)
kvfree(svm->sev_es.ghcb_sa);
}
+static u64 kvm_ghcb_get_sw_exit_code(struct vmcb_control_area *control)
+{
+ return (((u64)control->exit_code_hi) << 32) | control->exit_code;
+}
+
static void dump_ghcb(struct vcpu_svm *svm)
{
- struct ghcb *ghcb = svm->sev_es.ghcb;
+ struct vmcb_control_area *control = &svm->vmcb->control;
unsigned int nbits;
/* Re-use the dump_invalid_vmcb module parameter */
@@ -3184,18 +3189,18 @@ static void dump_ghcb(struct vcpu_svm *svm)
return;
}
- nbits = sizeof(ghcb->save.valid_bitmap) * 8;
+ nbits = sizeof(svm->sev_es.valid_bitmap) * 8;
pr_err("GHCB (GPA=%016llx):\n", svm->vmcb->control.ghcb_gpa);
pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_code",
- ghcb->save.sw_exit_code, ghcb_sw_exit_code_is_valid(ghcb));
+ kvm_ghcb_get_sw_exit_code(control), kvm_ghcb_sw_exit_code_is_valid(svm));
pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_info_1",
- ghcb->save.sw_exit_info_1, ghcb_sw_exit_info_1_is_valid(ghcb));
+ control->exit_info_1, kvm_ghcb_sw_exit_info_1_is_valid(svm));
pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_info_2",
- ghcb->save.sw_exit_info_2, ghcb_sw_exit_info_2_is_valid(ghcb));
+ control->exit_info_2, kvm_ghcb_sw_exit_info_2_is_valid(svm));
pr_err("%-20s%016llx is_valid: %u\n", "sw_scratch",
- ghcb->save.sw_scratch, ghcb_sw_scratch_is_valid(ghcb));
- pr_err("%-20s%*pb\n", "valid_bitmap", nbits, ghcb->save.valid_bitmap);
+ svm->sev_es.sw_scratch, kvm_ghcb_sw_scratch_is_valid(svm));
+ pr_err("%-20s%*pb\n", "valid_bitmap", nbits, svm->sev_es.valid_bitmap);
}
static void sev_es_sync_to_ghcb(struct vcpu_svm *svm)
@@ -3266,11 +3271,6 @@ static void sev_es_sync_from_ghcb(struct vcpu_svm *svm)
memset(ghcb->save.valid_bitmap, 0, sizeof(ghcb->save.valid_bitmap));
}
-static u64 kvm_ghcb_get_sw_exit_code(struct vmcb_control_area *control)
-{
- return (((u64)control->exit_code_hi) << 32) | control->exit_code;
-}
-
static int sev_es_validate_vmgexit(struct vcpu_svm *svm)
{
struct vmcb_control_area *control = &svm->vmcb->control;
base-commit: 2d7124941a273c7233849a7a2bbfbeb7e28f1caa
--
2.46.2
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH] KVM: SVM: Update dump_ghcb() to use the GHCB snapshot fields
2025-04-28 18:55 [PATCH] KVM: SVM: Update dump_ghcb() to use the GHCB snapshot fields Tom Lendacky
@ 2025-04-29 15:22 ` Sean Christopherson
2025-04-29 16:31 ` Liam Merwick
2025-04-29 17:03 ` Tom Lendacky
2025-05-02 21:50 ` Sean Christopherson
1 sibling, 2 replies; 8+ messages in thread
From: Sean Christopherson @ 2025-04-29 15:22 UTC (permalink / raw)
To: Tom Lendacky
Cc: kvm, linux-kernel, x86, Paolo Bonzini, Borislav Petkov,
Dave Hansen, Ingo Molnar, Thomas Gleixner, Michael Roth
On Mon, Apr 28, 2025, Tom Lendacky wrote:
> @@ -3184,18 +3189,18 @@ static void dump_ghcb(struct vcpu_svm *svm)
> return;
> }
>
> - nbits = sizeof(ghcb->save.valid_bitmap) * 8;
> + nbits = sizeof(svm->sev_es.valid_bitmap) * 8;
I'm planning on adding this comment to explain the use of KVM's snapshot. Please
holler if it's wrong/misleading in any way.
/*
* Print KVM's snapshot of the GHCB that was (unsuccessfully) used to
* handle the exit. If the guest has since modified the GHCB itself,
* dumping the raw GHCB won't help debug why KVM was unable to handle
* the VMGEXIT that KVM observed.
*/
> pr_err("GHCB (GPA=%016llx):\n", svm->vmcb->control.ghcb_gpa);
> pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_code",
> - ghcb->save.sw_exit_code, ghcb_sw_exit_code_is_valid(ghcb));
> + kvm_ghcb_get_sw_exit_code(control), kvm_ghcb_sw_exit_code_is_valid(svm));
> pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_info_1",
> - ghcb->save.sw_exit_info_1, ghcb_sw_exit_info_1_is_valid(ghcb));
> + control->exit_info_1, kvm_ghcb_sw_exit_info_1_is_valid(svm));
> pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_info_2",
> - ghcb->save.sw_exit_info_2, ghcb_sw_exit_info_2_is_valid(ghcb));
> + control->exit_info_2, kvm_ghcb_sw_exit_info_2_is_valid(svm));
> pr_err("%-20s%016llx is_valid: %u\n", "sw_scratch",
> - ghcb->save.sw_scratch, ghcb_sw_scratch_is_valid(ghcb));
> - pr_err("%-20s%*pb\n", "valid_bitmap", nbits, ghcb->save.valid_bitmap);
> + svm->sev_es.sw_scratch, kvm_ghcb_sw_scratch_is_valid(svm));
> + pr_err("%-20s%*pb\n", "valid_bitmap", nbits, svm->sev_es.valid_bitmap);
> }
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] KVM: SVM: Update dump_ghcb() to use the GHCB snapshot fields
2025-04-29 15:22 ` Sean Christopherson
@ 2025-04-29 16:31 ` Liam Merwick
2025-04-29 17:33 ` Tom Lendacky
2025-04-29 17:03 ` Tom Lendacky
1 sibling, 1 reply; 8+ messages in thread
From: Liam Merwick @ 2025-04-29 16:31 UTC (permalink / raw)
To: Sean Christopherson, Tom Lendacky
Cc: kvm, linux-kernel, x86, Paolo Bonzini, Borislav Petkov,
Dave Hansen, Ingo Molnar, Thomas Gleixner, Michael Roth,
liam.merwick
On 29/04/2025 16:22, Sean Christopherson wrote:
> On Mon, Apr 28, 2025, Tom Lendacky wrote:
>> @@ -3184,18 +3189,18 @@ static void dump_ghcb(struct vcpu_svm *svm)
>> return;
>> }
>>
>> - nbits = sizeof(ghcb->save.valid_bitmap) * 8;
>> + nbits = sizeof(svm->sev_es.valid_bitmap) * 8;
>
> I'm planning on adding this comment to explain the use of KVM's snapshot. Please
> holler if it's wrong/misleading in any way.
>
> /*
> * Print KVM's snapshot of the GHCB that was (unsuccessfully) used to
> * handle the exit. If the guest has since modified the GHCB itself,
> * dumping the raw GHCB won't help debug why KVM was unable to handle
> * the VMGEXIT that KVM observed.
> */
>
>> pr_err("GHCB (GPA=%016llx):\n", svm->vmcb->control.ghcb_gpa);
Would printing "GHCB snapshot (GPA= ...." here instead of just "GHCB
(GPA= ..."
help gently remind people just looking at the debug output of this too?
Either way, for patch:
Reviewed-by: Liam Merwick <liam.merwick@oracle.com>
>> pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_code",
>> - ghcb->save.sw_exit_code, ghcb_sw_exit_code_is_valid(ghcb));
>> + kvm_ghcb_get_sw_exit_code(control), kvm_ghcb_sw_exit_code_is_valid(svm));
>> pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_info_1",
>> - ghcb->save.sw_exit_info_1, ghcb_sw_exit_info_1_is_valid(ghcb));
>> + control->exit_info_1, kvm_ghcb_sw_exit_info_1_is_valid(svm));
>> pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_info_2",
>> - ghcb->save.sw_exit_info_2, ghcb_sw_exit_info_2_is_valid(ghcb));
>> + control->exit_info_2, kvm_ghcb_sw_exit_info_2_is_valid(svm));
>> pr_err("%-20s%016llx is_valid: %u\n", "sw_scratch",
>> - ghcb->save.sw_scratch, ghcb_sw_scratch_is_valid(ghcb));
>> - pr_err("%-20s%*pb\n", "valid_bitmap", nbits, ghcb->save.valid_bitmap);
>> + svm->sev_es.sw_scratch, kvm_ghcb_sw_scratch_is_valid(svm));
>> + pr_err("%-20s%*pb\n", "valid_bitmap", nbits, svm->sev_es.valid_bitmap);
>> }
>
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] KVM: SVM: Update dump_ghcb() to use the GHCB snapshot fields
2025-04-29 16:31 ` Liam Merwick
@ 2025-04-29 17:33 ` Tom Lendacky
2025-04-29 17:56 ` Sean Christopherson
0 siblings, 1 reply; 8+ messages in thread
From: Tom Lendacky @ 2025-04-29 17:33 UTC (permalink / raw)
To: Liam Merwick, Sean Christopherson
Cc: kvm, linux-kernel, x86, Paolo Bonzini, Borislav Petkov,
Dave Hansen, Ingo Molnar, Thomas Gleixner, Michael Roth
On 4/29/25 11:31, Liam Merwick wrote:
> On 29/04/2025 16:22, Sean Christopherson wrote:
>> On Mon, Apr 28, 2025, Tom Lendacky wrote:
>>> @@ -3184,18 +3189,18 @@ static void dump_ghcb(struct vcpu_svm *svm)
>>> return;
>>> }
>>> - nbits = sizeof(ghcb->save.valid_bitmap) * 8;
>>> + nbits = sizeof(svm->sev_es.valid_bitmap) * 8;
>>
>> I'm planning on adding this comment to explain the use of KVM's
>> snapshot. Please
>> holler if it's wrong/misleading in any way.
>>
>> /*
>> * Print KVM's snapshot of the GHCB that was (unsuccessfully) used to
>> * handle the exit. If the guest has since modified the GHCB itself,
>> * dumping the raw GHCB won't help debug why KVM was unable to handle
>> * the VMGEXIT that KVM observed.
>> */
>>
>>> pr_err("GHCB (GPA=%016llx):\n", svm->vmcb->control.ghcb_gpa);
>
> Would printing "GHCB snapshot (GPA= ...." here instead of just "GHCB (GPA=
> ..."
> help gently remind people just looking at the debug output of this too?
Except the GPA is that of the actual GHCB. And the values being printed
are the actual values sent by the guest and being used by KVM at the time
the GHCB was read. So I'm not sure if that would clear things up at all.
Thanks,
Tom
>
> Either way, for patch:
> Reviewed-by: Liam Merwick <liam.merwick@oracle.com>
>
>
>>> pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_code",
>>> - ghcb->save.sw_exit_code, ghcb_sw_exit_code_is_valid(ghcb));
>>> + kvm_ghcb_get_sw_exit_code(control),
>>> kvm_ghcb_sw_exit_code_is_valid(svm));
>>> pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_info_1",
>>> - ghcb->save.sw_exit_info_1,
>>> ghcb_sw_exit_info_1_is_valid(ghcb));
>>> + control->exit_info_1, kvm_ghcb_sw_exit_info_1_is_valid(svm));
>>> pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_info_2",
>>> - ghcb->save.sw_exit_info_2,
>>> ghcb_sw_exit_info_2_is_valid(ghcb));
>>> + control->exit_info_2, kvm_ghcb_sw_exit_info_2_is_valid(svm));
>>> pr_err("%-20s%016llx is_valid: %u\n", "sw_scratch",
>>> - ghcb->save.sw_scratch, ghcb_sw_scratch_is_valid(ghcb));
>>> - pr_err("%-20s%*pb\n", "valid_bitmap", nbits,
>>> ghcb->save.valid_bitmap);
>>> + svm->sev_es.sw_scratch, kvm_ghcb_sw_scratch_is_valid(svm));
>>> + pr_err("%-20s%*pb\n", "valid_bitmap", nbits,
>>> svm->sev_es.valid_bitmap);
>>> }
>>
>
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] KVM: SVM: Update dump_ghcb() to use the GHCB snapshot fields
2025-04-29 17:33 ` Tom Lendacky
@ 2025-04-29 17:56 ` Sean Christopherson
0 siblings, 0 replies; 8+ messages in thread
From: Sean Christopherson @ 2025-04-29 17:56 UTC (permalink / raw)
To: Tom Lendacky
Cc: Liam Merwick, kvm, linux-kernel, x86, Paolo Bonzini,
Borislav Petkov, Dave Hansen, Ingo Molnar, Thomas Gleixner,
Michael Roth
On Tue, Apr 29, 2025, Tom Lendacky wrote:
> On 4/29/25 11:31, Liam Merwick wrote:
> > On 29/04/2025 16:22, Sean Christopherson wrote:
> >> On Mon, Apr 28, 2025, Tom Lendacky wrote:
> >>> @@ -3184,18 +3189,18 @@ static void dump_ghcb(struct vcpu_svm *svm)
> >>> return;
> >>> }
> >>> - nbits = sizeof(ghcb->save.valid_bitmap) * 8;
> >>> + nbits = sizeof(svm->sev_es.valid_bitmap) * 8;
> >>
> >> I'm planning on adding this comment to explain the use of KVM's
> >> snapshot. Please
> >> holler if it's wrong/misleading in any way.
> >>
> >> /*
> >> * Print KVM's snapshot of the GHCB that was (unsuccessfully) used to
> >> * handle the exit. If the guest has since modified the GHCB itself,
> >> * dumping the raw GHCB won't help debug why KVM was unable to handle
> >> * the VMGEXIT that KVM observed.
> >> */
> >>
> >>> pr_err("GHCB (GPA=%016llx):\n", svm->vmcb->control.ghcb_gpa);
> >
> > Would printing "GHCB snapshot (GPA= ...." here instead of just "GHCB (GPA=
> > ..."
> > help gently remind people just looking at the debug output of this too?
>
> Except the GPA is that of the actual GHCB. And the values being printed
> are the actual values sent by the guest and being used by KVM at the time
> the GHCB was read. So I'm not sure if that would clear things up at all.
I personally like the "snapshot" addendum. Yes, the GPA is the GPA of the GHCB,
but it also the GPA from which the snapshot was obtained. Ditto for the values.
For folks that aren't aware that KVM operates on a snapshot of the GHCB, they
could end up really confused if they somehow have access to the raw GHCB, e.g.
from the guest side or something.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] KVM: SVM: Update dump_ghcb() to use the GHCB snapshot fields
2025-04-29 15:22 ` Sean Christopherson
2025-04-29 16:31 ` Liam Merwick
@ 2025-04-29 17:03 ` Tom Lendacky
1 sibling, 0 replies; 8+ messages in thread
From: Tom Lendacky @ 2025-04-29 17:03 UTC (permalink / raw)
To: Sean Christopherson
Cc: kvm, linux-kernel, x86, Paolo Bonzini, Borislav Petkov,
Dave Hansen, Ingo Molnar, Thomas Gleixner, Michael Roth
On 4/29/25 10:22, Sean Christopherson wrote:
> On Mon, Apr 28, 2025, Tom Lendacky wrote:
>> @@ -3184,18 +3189,18 @@ static void dump_ghcb(struct vcpu_svm *svm)
>> return;
>> }
>>
>> - nbits = sizeof(ghcb->save.valid_bitmap) * 8;
>> + nbits = sizeof(svm->sev_es.valid_bitmap) * 8;
>
> I'm planning on adding this comment to explain the use of KVM's snapshot. Please
> holler if it's wrong/misleading in any way.
>
> /*
> * Print KVM's snapshot of the GHCB that was (unsuccessfully) used to
s/snapshot/snapshot values/ ?
> * handle the exit. If the guest has since modified the GHCB itself,
> * dumping the raw GHCB won't help debug why KVM was unable to handle
> * the VMGEXIT that KVM observed.
> */
Otherwise, looks good to me.
Thanks,
Tom
>
>> pr_err("GHCB (GPA=%016llx):\n", svm->vmcb->control.ghcb_gpa);
>> pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_code",
>> - ghcb->save.sw_exit_code, ghcb_sw_exit_code_is_valid(ghcb));
>> + kvm_ghcb_get_sw_exit_code(control), kvm_ghcb_sw_exit_code_is_valid(svm));
>> pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_info_1",
>> - ghcb->save.sw_exit_info_1, ghcb_sw_exit_info_1_is_valid(ghcb));
>> + control->exit_info_1, kvm_ghcb_sw_exit_info_1_is_valid(svm));
>> pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_info_2",
>> - ghcb->save.sw_exit_info_2, ghcb_sw_exit_info_2_is_valid(ghcb));
>> + control->exit_info_2, kvm_ghcb_sw_exit_info_2_is_valid(svm));
>> pr_err("%-20s%016llx is_valid: %u\n", "sw_scratch",
>> - ghcb->save.sw_scratch, ghcb_sw_scratch_is_valid(ghcb));
>> - pr_err("%-20s%*pb\n", "valid_bitmap", nbits, ghcb->save.valid_bitmap);
>> + svm->sev_es.sw_scratch, kvm_ghcb_sw_scratch_is_valid(svm));
>> + pr_err("%-20s%*pb\n", "valid_bitmap", nbits, svm->sev_es.valid_bitmap);
>> }
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] KVM: SVM: Update dump_ghcb() to use the GHCB snapshot fields
2025-04-28 18:55 [PATCH] KVM: SVM: Update dump_ghcb() to use the GHCB snapshot fields Tom Lendacky
2025-04-29 15:22 ` Sean Christopherson
@ 2025-05-02 21:50 ` Sean Christopherson
2025-05-02 21:54 ` Tom Lendacky
1 sibling, 1 reply; 8+ messages in thread
From: Sean Christopherson @ 2025-05-02 21:50 UTC (permalink / raw)
To: Sean Christopherson, kvm, linux-kernel, x86, Tom Lendacky
Cc: Paolo Bonzini, Borislav Petkov, Dave Hansen, Ingo Molnar,
Thomas Gleixner, Michael Roth
On Mon, 28 Apr 2025 13:55:31 -0500, Tom Lendacky wrote:
> Commit 4e15a0ddc3ff ("KVM: SEV: snapshot the GHCB before accessing it")
> updated the SEV code to take a snapshot of the GHCB before using it. But
> the dump_ghcb() function wasn't updated to use the snapshot locations.
> This results in incorrect output from dump_ghcb() for the "is_valid" and
> "valid_bitmap" fields.
>
> Update dump_ghcb() to use the proper locations.
>
> [...]
Applied to kvm-x86 fixes.
Tom, I tried to find a middle ground between capturing the "snapshot" behavior
and not making it seem like the reported GPA is the GPA of the snapshot. Holler
if you don't like the end result.
[1/1] KVM: SVM: Update dump_ghcb() to use the GHCB snapshot fields
https://github.com/kvm-x86/linux/commit/5fea0c6c0ebe
--
https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] KVM: SVM: Update dump_ghcb() to use the GHCB snapshot fields
2025-05-02 21:50 ` Sean Christopherson
@ 2025-05-02 21:54 ` Tom Lendacky
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lendacky @ 2025-05-02 21:54 UTC (permalink / raw)
To: Sean Christopherson, kvm, linux-kernel, x86
Cc: Paolo Bonzini, Borislav Petkov, Dave Hansen, Ingo Molnar,
Thomas Gleixner, Michael Roth
On 5/2/25 16:50, Sean Christopherson wrote:
> On Mon, 28 Apr 2025 13:55:31 -0500, Tom Lendacky wrote:
>> Commit 4e15a0ddc3ff ("KVM: SEV: snapshot the GHCB before accessing it")
>> updated the SEV code to take a snapshot of the GHCB before using it. But
>> the dump_ghcb() function wasn't updated to use the snapshot locations.
>> This results in incorrect output from dump_ghcb() for the "is_valid" and
>> "valid_bitmap" fields.
>>
>> Update dump_ghcb() to use the proper locations.
>>
>> [...]
>
> Applied to kvm-x86 fixes.
>
> Tom, I tried to find a middle ground between capturing the "snapshot" behavior
> and not making it seem like the reported GPA is the GPA of the snapshot. Holler
> if you don't like the end result.
No hollerin' here. Looks good, Sean.
Thanks,
Tom
>
> [1/1] KVM: SVM: Update dump_ghcb() to use the GHCB snapshot fields
> https://github.com/kvm-x86/linux/commit/5fea0c6c0ebe
>
> --
> https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-05-02 21:54 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-28 18:55 [PATCH] KVM: SVM: Update dump_ghcb() to use the GHCB snapshot fields Tom Lendacky
2025-04-29 15:22 ` Sean Christopherson
2025-04-29 16:31 ` Liam Merwick
2025-04-29 17:33 ` Tom Lendacky
2025-04-29 17:56 ` Sean Christopherson
2025-04-29 17:03 ` Tom Lendacky
2025-05-02 21:50 ` Sean Christopherson
2025-05-02 21:54 ` Tom Lendacky
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.