]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: x86: do not spam dmesg with VMCS/VMCB dumps
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 20 May 2019 13:34:35 +0000 (15:34 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 24 May 2019 19:27:12 +0000 (21:27 +0200)
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 <pbonzini@redhat.com>
arch/x86/kvm/svm.c
arch/x86/kvm/vmx/vmx.c

index a9e553a1317f9f3acdf319a56ef39f6f0b8746f7..735b8c01895e15ad03edbea3b8d6f1dcd261e74b 100644 (file)
@@ -379,6 +379,9 @@ module_param(vgif, int, 0444);
 static int sev = IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT);
 module_param(sev, int, 0444);
 
+static bool __read_mostly dump_invalid_vmcb = 0;
+module_param(dump_invalid_vmcb, bool, 0644);
+
 static u8 rsm_ins_bytes[] = "\x0f\xaa";
 
 static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);
@@ -4828,6 +4831,11 @@ static void dump_vmcb(struct kvm_vcpu *vcpu)
        struct vmcb_control_area *control = &svm->vmcb->control;
        struct vmcb_save_area *save = &svm->vmcb->save;
 
+       if (!dump_invalid_vmcb) {
+               pr_warn_ratelimited("set kvm_amd.dump_invalid_vmcb=1 to dump internal KVM state.\n");
+               return;
+       }
+
        pr_err("VMCB Control Area:\n");
        pr_err("%-20s%04x\n", "cr_read:", control->intercept_cr & 0xffff);
        pr_err("%-20s%04x\n", "cr_write:", control->intercept_cr >> 16);
@@ -4986,7 +4994,6 @@ static int handle_exit(struct kvm_vcpu *vcpu)
                kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
                kvm_run->fail_entry.hardware_entry_failure_reason
                        = svm->vmcb->control.exit_code;
-               pr_err("KVM: FAILED VMRUN WITH VMCB:\n");
                dump_vmcb(vcpu);
                return 0;
        }
index 1ac167614032a317d324a9d43adc4aa1b16a3c59..b93e36ddee5e470b88609b2523189653472300d8 100644 (file)
@@ -114,6 +114,9 @@ static u64 __read_mostly host_xss;
 bool __read_mostly enable_pml = 1;
 module_param_named(pml, enable_pml, bool, S_IRUGO);
 
+static bool __read_mostly dump_invalid_vmcs = 0;
+module_param(dump_invalid_vmcs, bool, 0644);
+
 #define MSR_BITMAP_MODE_X2APIC         1
 #define MSR_BITMAP_MODE_X2APIC_APICV   2
 
@@ -5607,15 +5610,24 @@ static void vmx_dump_dtsel(char *name, uint32_t limit)
 
 void dump_vmcs(void)
 {
-       u32 vmentry_ctl = vmcs_read32(VM_ENTRY_CONTROLS);
-       u32 vmexit_ctl = vmcs_read32(VM_EXIT_CONTROLS);
-       u32 cpu_based_exec_ctrl = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
-       u32 pin_based_exec_ctrl = vmcs_read32(PIN_BASED_VM_EXEC_CONTROL);
-       u32 secondary_exec_control = 0;
-       unsigned long cr4 = vmcs_readl(GUEST_CR4);
-       u64 efer = vmcs_read64(GUEST_IA32_EFER);
+       u32 vmentry_ctl, vmexit_ctl;
+       u32 cpu_based_exec_ctrl, pin_based_exec_ctrl, secondary_exec_control;
+       unsigned long cr4;
+       u64 efer;
        int i, n;
 
+       if (!dump_invalid_vmcs) {
+               pr_warn_ratelimited("set kvm_intel.dump_invalid_vmcs=1 to dump internal KVM state.\n");
+               return;
+       }
+
+       vmentry_ctl = vmcs_read32(VM_ENTRY_CONTROLS);
+       vmexit_ctl = vmcs_read32(VM_EXIT_CONTROLS);
+       cpu_based_exec_ctrl = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
+       pin_based_exec_ctrl = vmcs_read32(PIN_BASED_VM_EXEC_CONTROL);
+       cr4 = vmcs_readl(GUEST_CR4);
+       efer = vmcs_read64(GUEST_IA32_EFER);
+       secondary_exec_control = 0;
        if (cpu_has_secondary_exec_ctrls())
                secondary_exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);