]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: SVM: Add a mutex to dump_vmcb() to prevent concurrent output
authorTom Lendacky <thomas.lendacky@amd.com>
Thu, 20 Mar 2025 13:26:53 +0000 (08:26 -0500)
committerSean Christopherson <seanjc@google.com>
Fri, 25 Apr 2025 23:19:54 +0000 (16:19 -0700)
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 <thomas.lendacky@amd.com>
Acked-by: Borislav Petkov (AMD) <bp@alien8.de>
Tested-by: Kim Phillips <kim.phillips@amd.com>
Link: https://lore.kernel.org/r/a880678afd9488e1dd6017445802712f7c02cc6d.1742477213.git.thomas.lendacky@amd.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/svm.c

index 272ce4bdbf11103fc8ea5a88ef17582ca61da177..919f98479774b67094935dfa4b9a8de718ea827f 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/cc_platform.h>
 #include <linux/smp.h>
 #include <linux/string_choices.h>
+#include <linux/mutex.h>
 
 #include <asm/apic.h>
 #include <asm/perf_event.h>
@@ -249,6 +250,8 @@ static unsigned long iopm_base;
 
 DEFINE_PER_CPU(struct svm_cpu_data, svm_data);
 
+static DEFINE_MUTEX(vmcb_dump_mutex);
+
 /*
  * Only MSR_TSC_AUX is switched via the user return hook.  EFER is switched via
  * the VMCB, and the SYSCALL/SYSENTER MSRs are handled by VMLOAD/VMSAVE.
@@ -3404,6 +3407,8 @@ static void dump_vmcb(struct kvm_vcpu *vcpu)
                return;
        }
 
+       guard(mutex)(&vmcb_dump_mutex);
+
        vm_type = sev_snp_guest(vcpu->kvm) ? "SEV-SNP" :
                  sev_es_guest(vcpu->kvm) ? "SEV-ES" :
                  sev_guest(vcpu->kvm) ? "SEV" : "SVM";