Skip to content

Commit 468c27a

Browse files
tlendackysean-jc
authored andcommitted
KVM: SVM: Add a mutex to dump_vmcb() to prevent concurrent output
If multiple VMRUN instructions fail, resulting in calls to dump_vmcb(), the output can become interleaved and it is impossible to identify which line of output belongs to which VMCB. Add a mutex to dump_vmcb() so that the output is serialized. Signed-off-by: Tom Lendacky <[email protected]> Acked-by: Borislav Petkov (AMD) <[email protected]> Tested-by: Kim Phillips <[email protected]> Link: https://lore.kernel.org/r/a880678afd9488e1dd6017445802712f7c02cc6d.1742477213.git.thomas.lendacky@amd.com Signed-off-by: Sean Christopherson <[email protected]>
1 parent 0e6b677 commit 468c27a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/cc_platform.h>
3030
#include <linux/smp.h>
3131
#include <linux/string_choices.h>
32+
#include <linux/mutex.h>
3233

3334
#include <asm/apic.h>
3435
#include <asm/perf_event.h>
@@ -249,6 +250,8 @@ static unsigned long iopm_base;
249250

250251
DEFINE_PER_CPU(struct svm_cpu_data, svm_data);
251252

253+
static DEFINE_MUTEX(vmcb_dump_mutex);
254+
252255
/*
253256
* Only MSR_TSC_AUX is switched via the user return hook. EFER is switched via
254257
* the VMCB, and the SYSCALL/SYSENTER MSRs are handled by VMLOAD/VMSAVE.
@@ -3404,6 +3407,8 @@ static void dump_vmcb(struct kvm_vcpu *vcpu)
34043407
return;
34053408
}
34063409

3410+
guard(mutex)(&vmcb_dump_mutex);
3411+
34073412
vm_type = sev_snp_guest(vcpu->kvm) ? "SEV-SNP" :
34083413
sev_es_guest(vcpu->kvm) ? "SEV-ES" :
34093414
sev_guest(vcpu->kvm) ? "SEV" : "SVM";

0 commit comments

Comments
 (0)