Skip to content

Commit 4c953f8

Browse files
Stephane EranianIngo Molnar
authored andcommitted
perf/x86/rapl: Make perf_probe_msr() more robust and flexible
This patch modifies perf_probe_msr() by allowing passing of struct perf_msr array where some entries are not populated, i.e., they have either an msr address of 0 or no attribute_group pointer. This helps with certain call paths, e.g., RAPL. In case the grp is NULL, the default sysfs visibility rule applies which is to make the group visible. Without the patch, you would get a kernel crash with a NULL group. Signed-off-by: Stephane Eranian <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2a3e3f7 commit 4c953f8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

arch/x86/events/probe.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ not_visible(struct kobject *kobj, struct attribute *attr, int i)
1010
return 0;
1111
}
1212

13+
/*
14+
* Accepts msr[] array with non populated entries as long as either
15+
* msr[i].msr is 0 or msr[i].grp is NULL. Note that the default sysfs
16+
* visibility is visible when group->is_visible callback is set.
17+
*/
1318
unsigned long
1419
perf_msr_probe(struct perf_msr *msr, int cnt, bool zero, void *data)
1520
{
@@ -24,8 +29,16 @@ perf_msr_probe(struct perf_msr *msr, int cnt, bool zero, void *data)
2429
if (!msr[bit].no_check) {
2530
struct attribute_group *grp = msr[bit].grp;
2631

32+
/* skip entry with no group */
33+
if (!grp)
34+
continue;
35+
2736
grp->is_visible = not_visible;
2837

38+
/* skip unpopulated entry */
39+
if (!msr[bit].msr)
40+
continue;
41+
2942
if (msr[bit].test && !msr[bit].test(bit, data))
3043
continue;
3144
/* Virt sucks; you cannot tell if a R/O MSR is present :/ */

0 commit comments

Comments
 (0)