Skip to content

Commit 5fea0c6

Browse files
tlendackysean-jc
authored andcommitted
KVM: SVM: Update dump_ghcb() to use the GHCB snapshot fields
Commit 4e15a0d ("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: 4e15a0d ("KVM: SEV: snapshot the GHCB before accessing it") Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> Reviewed-by: Liam Merwick <liam.merwick@oracle.com> Link: https://lore.kernel.org/r/8f03878443681496008b1b37b7c4bf77a342b459.1745866531.git.thomas.lendacky@amd.com [sean: add comment and snapshot qualifier] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 20a6cff commit 5fea0c6

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

arch/x86/kvm/svm/sev.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3173,9 +3173,14 @@ void sev_free_vcpu(struct kvm_vcpu *vcpu)
31733173
kvfree(svm->sev_es.ghcb_sa);
31743174
}
31753175

3176+
static u64 kvm_ghcb_get_sw_exit_code(struct vmcb_control_area *control)
3177+
{
3178+
return (((u64)control->exit_code_hi) << 32) | control->exit_code;
3179+
}
3180+
31763181
static void dump_ghcb(struct vcpu_svm *svm)
31773182
{
3178-
struct ghcb *ghcb = svm->sev_es.ghcb;
3183+
struct vmcb_control_area *control = &svm->vmcb->control;
31793184
unsigned int nbits;
31803185

31813186
/* Re-use the dump_invalid_vmcb module parameter */
@@ -3184,18 +3189,24 @@ static void dump_ghcb(struct vcpu_svm *svm)
31843189
return;
31853190
}
31863191

3187-
nbits = sizeof(ghcb->save.valid_bitmap) * 8;
3192+
nbits = sizeof(svm->sev_es.valid_bitmap) * 8;
31883193

3189-
pr_err("GHCB (GPA=%016llx):\n", svm->vmcb->control.ghcb_gpa);
3194+
/*
3195+
* Print KVM's snapshot of the GHCB values that were (unsuccessfully)
3196+
* used to handle the exit. If the guest has since modified the GHCB
3197+
* itself, dumping the raw GHCB won't help debug why KVM was unable to
3198+
* handle the VMGEXIT that KVM observed.
3199+
*/
3200+
pr_err("GHCB (GPA=%016llx) snapshot:\n", svm->vmcb->control.ghcb_gpa);
31903201
pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_code",
3191-
ghcb->save.sw_exit_code, ghcb_sw_exit_code_is_valid(ghcb));
3202+
kvm_ghcb_get_sw_exit_code(control), kvm_ghcb_sw_exit_code_is_valid(svm));
31923203
pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_info_1",
3193-
ghcb->save.sw_exit_info_1, ghcb_sw_exit_info_1_is_valid(ghcb));
3204+
control->exit_info_1, kvm_ghcb_sw_exit_info_1_is_valid(svm));
31943205
pr_err("%-20s%016llx is_valid: %u\n", "sw_exit_info_2",
3195-
ghcb->save.sw_exit_info_2, ghcb_sw_exit_info_2_is_valid(ghcb));
3206+
control->exit_info_2, kvm_ghcb_sw_exit_info_2_is_valid(svm));
31963207
pr_err("%-20s%016llx is_valid: %u\n", "sw_scratch",
3197-
ghcb->save.sw_scratch, ghcb_sw_scratch_is_valid(ghcb));
3198-
pr_err("%-20s%*pb\n", "valid_bitmap", nbits, ghcb->save.valid_bitmap);
3208+
svm->sev_es.sw_scratch, kvm_ghcb_sw_scratch_is_valid(svm));
3209+
pr_err("%-20s%*pb\n", "valid_bitmap", nbits, svm->sev_es.valid_bitmap);
31993210
}
32003211

32013212
static void sev_es_sync_to_ghcb(struct vcpu_svm *svm)
@@ -3266,11 +3277,6 @@ static void sev_es_sync_from_ghcb(struct vcpu_svm *svm)
32663277
memset(ghcb->save.valid_bitmap, 0, sizeof(ghcb->save.valid_bitmap));
32673278
}
32683279

3269-
static u64 kvm_ghcb_get_sw_exit_code(struct vmcb_control_area *control)
3270-
{
3271-
return (((u64)control->exit_code_hi) << 32) | control->exit_code;
3272-
}
3273-
32743280
static int sev_es_validate_vmgexit(struct vcpu_svm *svm)
32753281
{
32763282
struct vmcb_control_area *control = &svm->vmcb->control;

0 commit comments

Comments
 (0)