1 // SPDX-License-Identifier: GPL-2.0 2 #include <linux/export.h> 3 #include <linux/types.h> 4 #include <linux/bits.h> 5 #include "probe.h" 6 7 static umode_t 8 not_visible(struct kobject *kobj, struct attribute *attr, int i) 9 { 10 return 0; 11 } 12 13 unsigned long 14 perf_msr_probe(struct perf_msr *msr, int cnt, bool zero, void *data) 15 { 16 unsigned long avail = 0; 17 unsigned int bit; 18 u64 val; 19 20 if (cnt >= BITS_PER_LONG) 21 return 0; 22 23 for (bit = 0; bit < cnt; bit++) { 24 if (!msr[bit].no_check) { 25 struct attribute_group *grp = msr[bit].grp; 26 27 grp->is_visible = not_visible; 28 29 if (msr[bit].test && !msr[bit].test(bit, data)) 30 continue; 31 /* Virt sucks; you cannot tell if a R/O MSR is present :/ */ 32 if (rdmsrl_safe(msr[bit].msr, &val)) 33 continue; 34 /* Disable zero counters if requested. */ 35 if (!zero && !val) 36 continue; 37 38 grp->is_visible = NULL; 39 } 40 avail |= BIT(bit); 41 } 42 43 return avail; 44 } 45 EXPORT_SYMBOL_GPL(perf_msr_probe); 46