Commit 2d99e804 authored by Kan Liang's avatar Kan Liang Committed by Yunying Sun
Browse files

perf/x86/intel: Hide Topdown metrics events if the feature is not enumerated

mainline inclusion
from mainline-v6.11-rc1
commit 556a7c039a52c21da33eaae9269984a1ef59189b
category: bugfix
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/IAIG7E
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=556a7c039a52c21da33eaae9269984a1ef59189b

-------------------------------------

The below error is observed on Ice Lake VM.

$ perf stat
Error:
The sys_perf_event_open() syscall returned with 22 (Invalid argument)
for event (slots).
/bin/dmesg | grep -i perf may provide additional information.

In a virtualization env, the Topdown metrics and the slots event haven't
been supported yet. The guest CPUID doesn't enumerate them. However, the
current kernel unconditionally exposes the slots event and the Topdown
metrics events to sysfs, which misleads the perf tool and triggers the
error.

Hide the perf-metrics topdown events and the slots event if the
perf-metrics feature is not enumerated.

The big core of a hybrid platform can also supports the perf-metrics
feature. Fix the hybrid platform as well.

Intel-SIG: commit 556a7c039a52 perf/x86/intel: Hide Topdown metrics events if the feature is not enumerated
Backport some core PMU bugfixes to kernel 5.10

Closes: https://lore.kernel.org/lkml/CAM9d7cj8z+ryyzUHR+P1Dcpot2jjW+Qcc4CPQpfafTXN=LEU0Q@mail.gmail.com/


Reported-by: default avatarDongli Zhang <dongli.zhang@oracle.com>
Signed-off-by: default avatarKan Liang <kan.liang@linux.intel.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: default avatarDongli Zhang <dongli.zhang@oracle.com>
Link: https://lkml.kernel.org/r/20240708193336.1192217-2-kan.liang@linux.intel.com


Signed-off-by: default avatarYunying Sun <yunying.sun@intel.com>
parent 13ac3d01
Loading
Loading
Loading
Loading
+32 −1
Original line number Diff line number Diff line
@@ -5525,8 +5525,22 @@ default_is_visible(struct kobject *kobj, struct attribute *attr, int i)
	return attr->mode;
}

static umode_t
td_is_visible(struct kobject *kobj, struct attribute *attr, int i)
{
	/*
	 * Hide the perf metrics topdown events
	 * if the feature is not enumerated.
	 */
	if (x86_pmu.num_topdown_events)
		return x86_pmu.intel_cap.perf_metrics ? attr->mode : 0;

	return attr->mode;
}

static struct attribute_group group_events_td  = {
	.name = "events",
	.is_visible = td_is_visible,
};

static struct attribute_group group_events_mem = {
@@ -5728,9 +5742,26 @@ static umode_t hybrid_format_is_visible(struct kobject *kobj,
	return (cpu >= 0) && (pmu->cpu_type & pmu_attr->pmu_type) ? attr->mode : 0;
}

static umode_t hybrid_td_is_visible(struct kobject *kobj,
				    struct attribute *attr, int i)
{
	struct device *dev = kobj_to_dev(kobj);
	struct x86_hybrid_pmu *pmu =
		 container_of(dev_get_drvdata(dev), struct x86_hybrid_pmu, pmu);

	if (!is_attr_for_this_pmu(kobj, attr))
		return 0;

	/* Only the big core supports perf metrics */
	if (pmu->cpu_type == hybrid_big)
		return pmu->intel_cap.perf_metrics ? attr->mode : 0;

	return attr->mode;
}

static struct attribute_group hybrid_group_events_td  = {
	.name		= "events",
	.is_visible	= hybrid_events_is_visible,
	.is_visible	= hybrid_td_is_visible,
};

static struct attribute_group hybrid_group_events_mem = {