KVM: Cleanup the kvm_print functions and introduce pr_XX wrappers
PATCH 1/1 KVM: Cleanup the kvm_print functions and introduce pr_XX wrappers
From: Christoffer Dall <[email protected]>
Introduces a couple of print functions, which are essentially wrappers around standard printk functions, with a KVM: prefix.
Functions introduced or modified are:
- kvm_err(fmt, ...)
- kvm_info(fmt, ...)
- kvm_debug(fmt, ...)
- kvm_pr_unimpl(fmt, ...)
- pr_unimpl(vcpu, fmt, ...) -> vcpu_pr_unimpl(vcpu, fmt, ...)
--- arch/x86/kvm/svm.c | 4 ++-- arch/x86/kvm/vmx.c | 2 +- arch/x86/kvm/x86.c | 41 +++++++++++++++++++++-------------------- include/linux/kvm_host.h | 14 ++++++++------ 4 files changed, 32 insertions(+), 29 deletions(-)
arch/x86/kvm/svm.c +2 -2
@@ -3084,7 +3084,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)break ;case MSR_IA32_DEBUGCTLMSR :if (!boot_cpu_has (X86_FEATURE_LBRV )) { -pr_unimpl (vcpu,"%s: MSR_IA32_DEBUGCTL 0x%llx, nop\n" , +vcpu_pr_unimpl (vcpu,"%s: MSR_IA32_DEBUGCTL 0x%llx, nop\n" , __func__, data);break ; }
@@ -3104,7 +3104,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)case MSR_VM_CR :return svm_set_vm_cr (vcpu, data);case MSR_VM_IGNNE : -pr_unimpl (vcpu,"unimplemented wrmsr: 0x%x data 0x%llx\n" , ecx, data); +vcpu_pr_unimpl (vcpu,"unimplemented wrmsr: 0x%x data 0x%llx\n" , ecx, data);break ;default :return kvm_set_msr_common (vcpu, ecx, data);
arch/x86/kvm/vmx.c +1 -1
@@ -4457,7 +4457,7 @@ static int handle_cr(struct kvm_vcpu *vcpu)break ; } vcpu->run->exit_reason =0 ; -pr_unimpl (vcpu,"unhandled control register: op %d cr %d\n" , +vcpu_pr_unimpl (vcpu,"unhandled control register: op %d cr %d\n" , (int )(exit_qualification >>4 ) &3 , cr);return 0 ; }
arch/x86/kvm/x86.c +21 -20
136 lines not on this page · raw message
include/linux/kvm_host.h +8 -6
@@ -295,13 +295,15 @@ struct kvm {long tlbs_dirty; }; -/* The guest did something we don't support. */ -#define pr_unimpl (vcpu, fmt, ...) \ - pr_err_ratelimited("kvm: %i: cpu%i " fmt, \ - current->tgid, (vcpu)->vcpu_id , ## __VA_ARGS__) +#define kvm_err (fmt, ...) pr_err("kvm: " fmt, ## __VA_ARGS__) +#define kvm_info (fmt, ...) pr_info("kvm: " fmt, ## __VA_ARGS__) +#define kvm_debug (fmt, ...) pr_debug("kvm: " fmt, ## __VA_ARGS__) +#define kvm_pr_unimpl (fmt, ...) \ + pr_err_ratelimited("kvm: %i" fmt, current->tgid, ## __VA_ARGS__) -#define kvm_printf(kvm, fmt ...) printk(KERN_DEBUG fmt) -#define vcpu_printf(vcpu, fmt...) kvm_printf(vcpu->kvm, fmt) +/* The guest did something we don't support. */ +#define vcpu_pr_unimpl (vcpu, fmt, ...) \ + kvm_pr_unimpl("cpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__)static inline struct kvm_vcpu *kvm_get_vcpu (struct kvm *kvm,int i) {
Any comments on this one?
Quoted 236 lines · Christoffer Dall
From: Christoffer Dall <[email protected]>
Introduces a couple of print functions, which are essentially wrappers around standard printk functions, with a KVM: prefix.
Functions introduced or modified are:
-kvm_err(fmt, ...)
-kvm_info(fmt, ...)
-kvm_debug(fmt, ...)
-kvm_pr_unimpl(fmt, ...)
-pr_unimpl(vcpu, fmt, ...)->vcpu_pr_unimpl(vcpu, fmt, ...)Signed-off-by Christoffer Dall <[email protected]>---
arch/x86/kvm/svm.c | 4 ++-- arch/x86/kvm/vmx.c | 2 +- arch/x86/kvm/x86.c | 41 +++++++++++++++++++++-------------------- include/linux/kvm_host.h | 14 ++++++++------ 4 files changed, 32 insertions(+), 29 deletions(-)arch/x86/kvm/svm.c +0
-0@@ -3084,7 +3084,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data) break;case
MSR_IA32_DEBUGCTLMSR:
if (!boot_cpu_has(X86_FEATURE_LBRV)) {
- pr_unimpl(vcpu, "%s:MSR_IA32_DEBUGCTL0x%llx, nop\n",
+vcpu_pr_unimpl(vcpu, "%s: MSR_IA32_DEBUGCTL 0x%llx, nop\n", __func__, data);
break;
}arch/x86/kvm/svm.c +0
-0@@ -3104,7 +3104,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)case
MSR_VM_CR:
returnsvm_set_vm_cr(vcpu, data);
caseMSR_VM_IGNNE:
-pr_unimpl(vcpu, "unimplemented wrmsr: 0x%x data 0x%llx\n", ecx, data);
+vcpu_pr_unimpl(vcpu, "unimplemented wrmsr: 0x%x data 0x%llx\n", ecx, data); break;
default:
returnkvm_set_msr_common(vcpu, ecx, data);arch/x86/kvm/vmx.c +1
-1@@ -4457,7 +4457,7 @@ static int handle_cr(struct kvm_vcpu *vcpu) break; } vcpu->run->exit_reason = 0; - pr_unimpl(vcpu, "unhandled control register: op %d cr %d\n", + vcpu_pr_unimpl(vcpu, "unhandled control register: op %d cr %d\n", (int)(exit_qualification >> 4) & 3, cr); return 0; }arch/x86/kvm/x86.c +0
-0@@ -1391,7 +1391,7 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) break; }default:
- pr_unimpl(vcpu, "HYPER-V unimplemented wrmsr: 0x%x "
+vcpu_pr_unimpl(vcpu, "HYPER-V unimplemented wrmsr: 0x%x " "data 0x%llx\n", msr, data);
return 1;
}arch/x86/kvm/x86.c +0
-0@@ -1424,7 +1424,7 @@ static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data)case
HV_X64_MSR_TPR:
returnkvm_hv_vapic_msr_write(vcpu, APIC_TASKPRI, data); default:
- pr_unimpl(vcpu, "HYPER-V unimplemented wrmsr: 0x%x "
+vcpu_pr_unimpl(vcpu, "HYPER-V unimplemented wrmsr: 0x%x " "data 0x%llx\n", msr, data);
return 1;
}arch/x86/kvm/x86.c +0
-0@@ -1504,14 +1504,14 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)data &= ~(u64)0x40; /* ignore flush filter disable */ data &= ~(u64)0x100; /* ignore ignne emulation enable */ if (data != 0) {
- pr_unimpl(vcpu, "unimplemented HWCR wrmsr: 0x%llx\n",
+vcpu_pr_unimpl(vcpu, "unimplemented HWCR wrmsr: 0x%llx\n", data);
return 1;
}
break;
caseMSR_FAM10H_MMIO_CONF_BASE:
if (data != 0) {
- pr_unimpl(vcpu, "unimplementedMMIO_CONF_BASEwrmsr: "
+vcpu_pr_unimpl(vcpu, "unimplemented MMIO_CONF_BASE wrmsr: " "0x%llx\n", data);
return 1;
}arch/x86/kvm/x86.c +0
-0@@ -1527,7 +1527,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)thus reserved and should throw a #GP */ return 1;
}
- pr_unimpl(vcpu, "%s:MSR_IA32_DEBUGCTLMSR0x%llx, nop\n",
+vcpu_pr_unimpl(vcpu, "%s: MSR_IA32_DEBUGCTLMSR 0x%llx, nop\n", __func__, data);
break;
caseMSR_IA32_UCODE_REV:arch/x86/kvm/x86.c +0
-0@@ -1624,8 +1624,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)case
MSR_K7_EVNTSEL2:
caseMSR_K7_EVNTSEL3:
if (data != 0)
- pr_unimpl(vcpu, "unimplemented perfctr wrmsr: "
- "0x%x data 0x%llx\n", msr, data);
+ vcpu_pr_unimpl(vcpu, "unimplemented perfctr wrmsr: "
+ "0x%x data 0x%llx\n", msr, data); break;
/* at least RHEL 4 unconditionally writes to the perfctr registers,
* so we ignore writes to make it happy.arch/x86/kvm/x86.c +0
-0@@ -1634,8 +1634,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)case
MSR_K7_PERFCTR1:
caseMSR_K7_PERFCTR2:
caseMSR_K7_PERFCTR3:
- pr_unimpl(vcpu, "unimplemented perfctr wrmsr: "
- "0x%x data 0x%llx\n", msr, data);
+ vcpu_pr_unimpl(vcpu, "unimplemented perfctr wrmsr: "
+ "0x%x data 0x%llx\n", msr, data); break;
caseMSR_P6_PERFCTR0:
caseMSR_P6_PERFCTR1:arch/x86/kvm/x86.c +2
-2@@ -1646,8 +1646,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data) return kvm_pmu_set_msr(vcpu, msr, data); if (pr || data != 0) - pr_unimpl(vcpu, "disabled perfctr wrmsr: " - "0x%x data 0x%llx\n", msr, data); + vcpu_pr_unimpl(vcpu, "disabled perfctr wrmsr: " + "0x%x data 0x%llx\n", msr, data); break;case
MSR_K7_CLK_CTL:
/*arch/x86/kvm/x86.c +2
-1@@ -1673,7 +1673,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data) /* Drop writes to this legacy MSR -- see rdmsr * counterpart for further detail. */ - pr_unimpl(vcpu, "ignored wrmsr: 0x%x data %llx\n", msr, data); + vcpu_pr_unimpl(vcpu, "ignored wrmsr: 0x%x data %llx\n", + msr, data); break;default:
if (msr && (msr ==vcpu->kvm->arch.xen_hvm_config.msr))arch/x86/kvm/x86.c +2
-2@@ -1681,11 +1682,11 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data) if (kvm_pmu_msr(vcpu, msr)) return kvm_pmu_set_msr(vcpu, msr, data); if (!ignore_msrs) { - pr_unimpl(vcpu, "unhandled wrmsr: 0x%x data %llx\n", + vcpu_pr_unimpl(vcpu, "unhandled wrmsr: 0x%x data %llx\n", msr, data); return 1; } else { - pr_unimpl(vcpu, "ignored wrmsr: 0x%x data %llx\n", + vcpu_pr_unimpl(vcpu, "ignored wrmsr: 0x%x data %llx\n", msr, data); break; }@@ -1789,7 +1790,7 @@ static int get_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) data = kvm->arch.hv_hypercall; break;default:
-pr_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
+vcpu_pr_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr); return 1;
}arch/x86/kvm/x86.c +0
-0@@ -1820,7 +1821,7 @@ static int get_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) data = vcpu->arch.hv_vapic; break;default:
-pr_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
+vcpu_pr_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr); return 1;
}
*pdata = data;arch/x86/kvm/x86.c +2
-2@@ -1963,10 +1964,10 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) if (kvm_pmu_msr(vcpu, msr)) return kvm_pmu_get_msr(vcpu, msr, pdata); if (!ignore_msrs) { - pr_unimpl(vcpu, "unhandled rdmsr: 0x%x\n", msr); + vcpu_pr_unimpl(vcpu, "unhandled rdmsr: 0x%x\n", msr); return 1; } else { - pr_unimpl(vcpu, "ignored rdmsr: 0x%x\n", msr); + vcpu_pr_unimpl(vcpu, "ignored rdmsr: 0x%x\n", msr); data = 0; } break;@@ -4026,7 +4027,7 @@ static unsigned long emulator_get_cr(struct x86_emulate_ctxt *ctxt, int cr) value = kvm_get_cr8(vcpu); break;default:
-vcpu_printf(vcpu, "%s: unexpected cr %u\n", __func__, cr);
+kvm_err("%s: unexpected cr %u\n", __func__, cr); return 0;
}arch/x86/kvm/x86.c +0
-0@@ -4055,7 +4056,7 @@ static int emulator_set_cr(struct x86_emulate_ctxt *ctxt, int cr, ulong val) res = kvm_set_cr8(vcpu, val); break;default:
-vcpu_printf(vcpu, "%s: unexpected cr %u\n", __func__, cr);
+kvm_err("%s: unexpected cr %u\n", __func__, cr); res = -1;
}include/linux/kvm_host.h +8
-6@@ -295,13 +295,15 @@ struct kvm { long tlbs_dirty; }; -/* The guest did something we don't support. */ -#define pr_unimpl (vcpu, fmt, ...) \ - pr_err_ratelimited("kvm: %i: cpu%i " fmt, \ - current->tgid, (vcpu)->vcpu_id , ## __VA_ARGS__) +#define kvm_err (fmt, ...) pr_err("kvm: " fmt, ## __VA_ARGS__) +#define kvm_info (fmt, ...) pr_info("kvm: " fmt, ## __VA_ARGS__) +#define kvm_debug (fmt, ...) pr_debug("kvm: " fmt, ## __VA_ARGS__) +#define kvm_pr_unimpl (fmt, ...) \ + pr_err_ratelimited("kvm: %i" fmt, current->tgid, ## __VA_ARGS__) -#define kvm_printf(kvm, fmt ...) printk(KERN_DEBUG fmt) -#define vcpu_printf(vcpu, fmt...) kvm_printf(vcpu->kvm, fmt) +/* The guest did something we don't support. */ +#define vcpu_pr_unimpl (vcpu, fmt, ...) \ + kvm_pr_unimpl("cpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__) static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i) {
Quoted 1 line · Christoffer Dall
Any comments on this one?
While at it, how about you also add the PID? Otherwise it's pretty pointless to write information into the kernel log, as you still won't know which VM it origins from.
Also, I don't like the long function name. How about something like vcpu_unimpl()?
Alex
Quoted 7 lines · Alexander Graf
Quoted 1 line · Christoffer Dall
Any comments on this one?
While at it, how about you also add the PID? Otherwise it's pretty pointless to write information into the kernel log, as you still won't know which VM it origins from.
I don't know about pointless, but a PID would be helpful. I'll add that. And potentially also __func__ in kvm_debug.
Quoted 2 lines
Also, I don't like the long function name. How about something like
vcpu_unimpl()?
sure, I'll update accordingly.