Skip to content

Commit 6f2f845

Browse files
committed
KVM: x86: do not spam dmesg with VMCS/VMCB dumps
Userspace can easily set up invalid processor state in such a way that dmesg will be filled with VMCS or VMCB dumps. Disable this by default using a module parameter. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 654f1f1 commit 6f2f845

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

arch/x86/kvm/svm.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ module_param(vgif, int, 0444);
379379
static int sev = IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT);
380380
module_param(sev, int, 0444);
381381

382+
static bool __read_mostly dump_invalid_vmcb = 0;
383+
module_param(dump_invalid_vmcb, bool, 0644);
384+
382385
static u8 rsm_ins_bytes[] = "\x0f\xaa";
383386

384387
static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);
@@ -4828,6 +4831,11 @@ static void dump_vmcb(struct kvm_vcpu *vcpu)
48284831
struct vmcb_control_area *control = &svm->vmcb->control;
48294832
struct vmcb_save_area *save = &svm->vmcb->save;
48304833

4834+
if (!dump_invalid_vmcb) {
4835+
pr_warn_ratelimited("set kvm_amd.dump_invalid_vmcb=1 to dump internal KVM state.\n");
4836+
return;
4837+
}
4838+
48314839
pr_err("VMCB Control Area:\n");
48324840
pr_err("%-20s%04x\n", "cr_read:", control->intercept_cr & 0xffff);
48334841
pr_err("%-20s%04x\n", "cr_write:", control->intercept_cr >> 16);
@@ -4986,7 +4994,6 @@ static int handle_exit(struct kvm_vcpu *vcpu)
49864994
kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
49874995
kvm_run->fail_entry.hardware_entry_failure_reason
49884996
= svm->vmcb->control.exit_code;
4989-
pr_err("KVM: FAILED VMRUN WITH VMCB:\n");
49904997
dump_vmcb(vcpu);
49914998
return 0;
49924999
}

arch/x86/kvm/vmx/vmx.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ static u64 __read_mostly host_xss;
114114
bool __read_mostly enable_pml = 1;
115115
module_param_named(pml, enable_pml, bool, S_IRUGO);
116116

117+
static bool __read_mostly dump_invalid_vmcs = 0;
118+
module_param(dump_invalid_vmcs, bool, 0644);
119+
117120
#define MSR_BITMAP_MODE_X2APIC 1
118121
#define MSR_BITMAP_MODE_X2APIC_APICV 2
119122

@@ -5607,15 +5610,24 @@ static void vmx_dump_dtsel(char *name, uint32_t limit)
56075610

56085611
void dump_vmcs(void)
56095612
{
5610-
u32 vmentry_ctl = vmcs_read32(VM_ENTRY_CONTROLS);
5611-
u32 vmexit_ctl = vmcs_read32(VM_EXIT_CONTROLS);
5612-
u32 cpu_based_exec_ctrl = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
5613-
u32 pin_based_exec_ctrl = vmcs_read32(PIN_BASED_VM_EXEC_CONTROL);
5614-
u32 secondary_exec_control = 0;
5615-
unsigned long cr4 = vmcs_readl(GUEST_CR4);
5616-
u64 efer = vmcs_read64(GUEST_IA32_EFER);
5613+
u32 vmentry_ctl, vmexit_ctl;
5614+
u32 cpu_based_exec_ctrl, pin_based_exec_ctrl, secondary_exec_control;
5615+
unsigned long cr4;
5616+
u64 efer;
56175617
int i, n;
56185618

5619+
if (!dump_invalid_vmcs) {
5620+
pr_warn_ratelimited("set kvm_intel.dump_invalid_vmcs=1 to dump internal KVM state.\n");
5621+
return;
5622+
}
5623+
5624+
vmentry_ctl = vmcs_read32(VM_ENTRY_CONTROLS);
5625+
vmexit_ctl = vmcs_read32(VM_EXIT_CONTROLS);
5626+
cpu_based_exec_ctrl = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
5627+
pin_based_exec_ctrl = vmcs_read32(PIN_BASED_VM_EXEC_CONTROL);
5628+
cr4 = vmcs_readl(GUEST_CR4);
5629+
efer = vmcs_read64(GUEST_IA32_EFER);
5630+
secondary_exec_control = 0;
56195631
if (cpu_has_secondary_exec_ctrls())
56205632
secondary_exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
56215633

0 commit comments

Comments
 (0)