Skip to content

Commit ebd19fc

Browse files
samitolvanenPeter Zijlstra
authored andcommitted
perf/x86: fix sysfs type mismatches
This change switches rapl to use PMU_FORMAT_ATTR, and fixes two other macros to use device_attribute instead of kobj_attribute to avoid callback type mismatches that trip indirect call checking with Clang's Control-Flow Integrity (CFI). Reported-by: Sedat Dilek <[email protected]> Signed-off-by: Sami Tolvanen <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 1a8cfa2 commit ebd19fc

File tree

4 files changed

+12
-24
lines changed

4 files changed

+12
-24
lines changed

arch/x86/events/intel/cstate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@
107107
MODULE_LICENSE("GPL");
108108

109109
#define DEFINE_CSTATE_FORMAT_ATTR(_var, _name, _format) \
110-
static ssize_t __cstate_##_var##_show(struct kobject *kobj, \
111-
struct kobj_attribute *attr, \
110+
static ssize_t __cstate_##_var##_show(struct device *dev, \
111+
struct device_attribute *attr, \
112112
char *page) \
113113
{ \
114114
BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
115115
return sprintf(page, _format "\n"); \
116116
} \
117-
static struct kobj_attribute format_attr_##_var = \
117+
static struct device_attribute format_attr_##_var = \
118118
__ATTR(_name, 0444, __cstate_##_var##_show, NULL)
119119

120120
static ssize_t cstate_get_attr_cpumask(struct device *dev,

arch/x86/events/intel/uncore.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ struct pci2phy_map *__find_pci2phy_map(int segment)
9494
return map;
9595
}
9696

97-
ssize_t uncore_event_show(struct kobject *kobj,
98-
struct kobj_attribute *attr, char *buf)
97+
ssize_t uncore_event_show(struct device *dev,
98+
struct device_attribute *attr, char *buf)
9999
{
100100
struct uncore_event_desc *event =
101101
container_of(attr, struct uncore_event_desc, attr);

arch/x86/events/intel/uncore.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ struct intel_uncore_box {
157157
#define UNCORE_BOX_FLAG_CFL8_CBOX_MSR_OFFS 2
158158

159159
struct uncore_event_desc {
160-
struct kobj_attribute attr;
160+
struct device_attribute attr;
161161
const char *config;
162162
};
163163

@@ -179,8 +179,8 @@ struct pci2phy_map {
179179
struct pci2phy_map *__find_pci2phy_map(int segment);
180180
int uncore_pcibus_to_physid(struct pci_bus *bus);
181181

182-
ssize_t uncore_event_show(struct kobject *kobj,
183-
struct kobj_attribute *attr, char *buf);
182+
ssize_t uncore_event_show(struct device *dev,
183+
struct device_attribute *attr, char *buf);
184184

185185
static inline struct intel_uncore_pmu *dev_to_uncore_pmu(struct device *dev)
186186
{
@@ -201,14 +201,14 @@ extern int __uncore_max_dies;
201201
}
202202

203203
#define DEFINE_UNCORE_FORMAT_ATTR(_var, _name, _format) \
204-
static ssize_t __uncore_##_var##_show(struct kobject *kobj, \
205-
struct kobj_attribute *attr, \
204+
static ssize_t __uncore_##_var##_show(struct device *dev, \
205+
struct device_attribute *attr, \
206206
char *page) \
207207
{ \
208208
BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
209209
return sprintf(page, _format "\n"); \
210210
} \
211-
static struct kobj_attribute format_attr_##_var = \
211+
static struct device_attribute format_attr_##_var = \
212212
__ATTR(_name, 0444, __uncore_##_var##_show, NULL)
213213

214214
static inline bool uncore_pmc_fixed(int idx)

arch/x86/events/rapl.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,6 @@ static const char *const rapl_domain_names[NR_RAPL_DOMAINS] __initconst = {
9393
* any other bit is reserved
9494
*/
9595
#define RAPL_EVENT_MASK 0xFFULL
96-
97-
#define DEFINE_RAPL_FORMAT_ATTR(_var, _name, _format) \
98-
static ssize_t __rapl_##_var##_show(struct kobject *kobj, \
99-
struct kobj_attribute *attr, \
100-
char *page) \
101-
{ \
102-
BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
103-
return sprintf(page, _format "\n"); \
104-
} \
105-
static struct kobj_attribute format_attr_##_var = \
106-
__ATTR(_name, 0444, __rapl_##_var##_show, NULL)
107-
10896
#define RAPL_CNTR_WIDTH 32
10997

11098
#define RAPL_EVENT_ATTR_STR(_name, v, str) \
@@ -441,7 +429,7 @@ static struct attribute_group rapl_pmu_events_group = {
441429
.attrs = attrs_empty,
442430
};
443431

444-
DEFINE_RAPL_FORMAT_ATTR(event, event, "config:0-7");
432+
PMU_FORMAT_ATTR(event, "config:0-7");
445433
static struct attribute *rapl_formats_attr[] = {
446434
&format_attr_event.attr,
447435
NULL,

0 commit comments

Comments
 (0)