2019-07-18 04:55:36

by Like Xu

[permalink] [raw]
Subject: [PATCH] KVM: x86/vPMU: refine kvm_pmu err msg when event creation failed

If a perf_event creation fails due to any reason of the host perf
subsystem, it has no chance to log the corresponding event for guest
which may cause abnormal sampling data in guest result. In debug mode,
this message helps to understand the state of vPMC and we should not
limit the number of occurrences.

Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/pmu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index aa5a2597305a..259ada8d6db6 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -131,8 +131,8 @@ static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type,
intr ? kvm_perf_overflow_intr :
kvm_perf_overflow, pmc);
if (IS_ERR(event)) {
- printk_once("kvm_pmu: event creation failed %ld\n",
- PTR_ERR(event));
+ pr_debug("kvm_pmu: event creation failed %ld\n for pmc->idx = %d",
+ PTR_ERR(event), pmc->idx);
return;
}

--
2.21.0


2019-07-18 05:20:07

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] KVM: x86/vPMU: refine kvm_pmu err msg when event creation failed

On Thu, 2019-07-18 at 12:49 +0800, Like Xu wrote:
> If a perf_event creation fails due to any reason of the host perf
> subsystem, it has no chance to log the corresponding event for guest
> which may cause abnormal sampling data in guest result. In debug mode,
> this message helps to understand the state of vPMC and we should not
> limit the number of occurrences.
[]
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
[]
> @@ -131,8 +131,8 @@ static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type,
> intr ? kvm_perf_overflow_intr :
> kvm_perf_overflow, pmc);
> if (IS_ERR(event)) {
> - printk_once("kvm_pmu: event creation failed %ld\n",
> - PTR_ERR(event));
> + pr_debug("kvm_pmu: event creation failed %ld\n for pmc->idx = %d",
> + PTR_ERR(event), pmc->idx);

Perhaps this was written as printk_once to avoid
spamming the log with repeated messages.

Maybe this should use pr_debug_ratelimited.
(and it should also have a \n termination like:)

pr_debug_ratelimited("kvm_pmu: event creation failed %ld for pmc->idx = %d\n",
PTR_ERR(event), pmc->idx);

Perhaps Avi Kivity remembers why he wrote it this way.
https://lore.kernel.org/kvm/[email protected]/


2019-07-18 05:46:00

by Like Xu

[permalink] [raw]
Subject: Re: [PATCH] KVM: x86/vPMU: refine kvm_pmu err msg when event creation failed

Hi Joe,

On 2019/7/18 13:18, Joe Perches wrote:
> On Thu, 2019-07-18 at 12:49 +0800, Like Xu wrote:
>> If a perf_event creation fails due to any reason of the host perf
>> subsystem, it has no chance to log the corresponding event for guest
>> which may cause abnormal sampling data in guest result. In debug mode,
>> this message helps to understand the state of vPMC and we should not
>> limit the number of occurrences.
> []
>> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> []
>> @@ -131,8 +131,8 @@ static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type,
>> intr ? kvm_perf_overflow_intr :
>> kvm_perf_overflow, pmc);
>> if (IS_ERR(event)) {
>> - printk_once("kvm_pmu: event creation failed %ld\n",
>> - PTR_ERR(event));
>> + pr_debug("kvm_pmu: event creation failed %ld\n for pmc->idx = %d",
>> + PTR_ERR(event), pmc->idx);
>
> Perhaps this was written as printk_once to avoid
> spamming the log with repeated messages.

The spamming case in practice from this messages is very rare but it's
logically possible.

>
> Maybe this should use pr_debug_ratelimited.
> (and it should also have a \n termination like:)

Thanks and it's my mistake, agree on '\n' usage.

>
> pr_debug_ratelimited("kvm_pmu: event creation failed %ld for pmc->idx = %d\n",
> PTR_ERR(event), pmc->idx);
>
> Perhaps Avi Kivity remembers why he wrote it this way.
> https://lore.kernel.org/kvm/[email protected] >>
>