Re: [PATCH] x86: events: Do not return bogus capabilities if PMU is broken

From: Paolo Bonzini
Date: Wed Jun 01 2022 - 07:24:58 EST


On 6/1/22 13:07, Peter Zijlstra wrote:
On Wed, Jun 01, 2022 at 05:42:56AM -0400, Paolo Bonzini wrote:
From: Like Xu <likexu@xxxxxxxxxxx>

If the PMU is broken due to firmware issues, check_hw_exists() will return
false but perf_get_x86_pmu_capability() will still return data from x86_pmu.
Likewise if some of the hotplug callbacks cannot be installed the contents
of x86_pmu will not be reverted.

Handle the failure in both cases by clearing x86_pmu if init_hw_perf_events()
or reverts to software events only.

Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>

No SoB from Like,

And hardly any code from him either except for a single memset, :) but I'll add

Signed-off-by: Like Xu <likexu@xxxxxxxxxxx>
Co-developed-by: Like Xu <likexu@xxxxxxxxxxx>

(I have hooks that notice this when pushing, but they don't help with git-send-email...).


@@ -2982,6 +2985,11 @@ unsigned long perf_misc_flags(struct pt_regs *regs)
void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap)
{
+ if (!x86_pmu.name) {

We have x86_pmu_initialized(), the implementation is a bit daft, but
might as well use it here too, no?

Yes, thanks.

Paolo