Commit ebd19fc3 authored by Sami Tolvanen's avatar Sami Tolvanen Committed by Peter Zijlstra

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: default avatarSedat Dilek <sedat.dilek@gmail.com>
Signed-off-by: default avatarSami Tolvanen <samitolvanen@google.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Link: https://lkml.kernel.org/r/20201113183126.1239404-1-samitolvanen@google.com
parent 1a8cfa24
...@@ -107,14 +107,14 @@ ...@@ -107,14 +107,14 @@
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
#define DEFINE_CSTATE_FORMAT_ATTR(_var, _name, _format) \ #define DEFINE_CSTATE_FORMAT_ATTR(_var, _name, _format) \
static ssize_t __cstate_##_var##_show(struct kobject *kobj, \ static ssize_t __cstate_##_var##_show(struct device *dev, \
struct kobj_attribute *attr, \ struct device_attribute *attr, \
char *page) \ char *page) \
{ \ { \
BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \ BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
return sprintf(page, _format "\n"); \ return sprintf(page, _format "\n"); \
} \ } \
static struct kobj_attribute format_attr_##_var = \ static struct device_attribute format_attr_##_var = \
__ATTR(_name, 0444, __cstate_##_var##_show, NULL) __ATTR(_name, 0444, __cstate_##_var##_show, NULL)
static ssize_t cstate_get_attr_cpumask(struct device *dev, static ssize_t cstate_get_attr_cpumask(struct device *dev,
......
...@@ -94,8 +94,8 @@ struct pci2phy_map *__find_pci2phy_map(int segment) ...@@ -94,8 +94,8 @@ struct pci2phy_map *__find_pci2phy_map(int segment)
return map; return map;
} }
ssize_t uncore_event_show(struct kobject *kobj, ssize_t uncore_event_show(struct device *dev,
struct kobj_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct uncore_event_desc *event = struct uncore_event_desc *event =
container_of(attr, struct uncore_event_desc, attr); container_of(attr, struct uncore_event_desc, attr);
......
...@@ -157,7 +157,7 @@ struct intel_uncore_box { ...@@ -157,7 +157,7 @@ struct intel_uncore_box {
#define UNCORE_BOX_FLAG_CFL8_CBOX_MSR_OFFS 2 #define UNCORE_BOX_FLAG_CFL8_CBOX_MSR_OFFS 2
struct uncore_event_desc { struct uncore_event_desc {
struct kobj_attribute attr; struct device_attribute attr;
const char *config; const char *config;
}; };
...@@ -179,8 +179,8 @@ struct pci2phy_map { ...@@ -179,8 +179,8 @@ struct pci2phy_map {
struct pci2phy_map *__find_pci2phy_map(int segment); struct pci2phy_map *__find_pci2phy_map(int segment);
int uncore_pcibus_to_physid(struct pci_bus *bus); int uncore_pcibus_to_physid(struct pci_bus *bus);
ssize_t uncore_event_show(struct kobject *kobj, ssize_t uncore_event_show(struct device *dev,
struct kobj_attribute *attr, char *buf); struct device_attribute *attr, char *buf);
static inline struct intel_uncore_pmu *dev_to_uncore_pmu(struct device *dev) static inline struct intel_uncore_pmu *dev_to_uncore_pmu(struct device *dev)
{ {
...@@ -201,14 +201,14 @@ extern int __uncore_max_dies; ...@@ -201,14 +201,14 @@ extern int __uncore_max_dies;
} }
#define DEFINE_UNCORE_FORMAT_ATTR(_var, _name, _format) \ #define DEFINE_UNCORE_FORMAT_ATTR(_var, _name, _format) \
static ssize_t __uncore_##_var##_show(struct kobject *kobj, \ static ssize_t __uncore_##_var##_show(struct device *dev, \
struct kobj_attribute *attr, \ struct device_attribute *attr, \
char *page) \ char *page) \
{ \ { \
BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \ BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
return sprintf(page, _format "\n"); \ return sprintf(page, _format "\n"); \
} \ } \
static struct kobj_attribute format_attr_##_var = \ static struct device_attribute format_attr_##_var = \
__ATTR(_name, 0444, __uncore_##_var##_show, NULL) __ATTR(_name, 0444, __uncore_##_var##_show, NULL)
static inline bool uncore_pmc_fixed(int idx) static inline bool uncore_pmc_fixed(int idx)
......
...@@ -93,18 +93,6 @@ static const char *const rapl_domain_names[NR_RAPL_DOMAINS] __initconst = { ...@@ -93,18 +93,6 @@ static const char *const rapl_domain_names[NR_RAPL_DOMAINS] __initconst = {
* any other bit is reserved * any other bit is reserved
*/ */
#define RAPL_EVENT_MASK 0xFFULL #define RAPL_EVENT_MASK 0xFFULL
#define DEFINE_RAPL_FORMAT_ATTR(_var, _name, _format) \
static ssize_t __rapl_##_var##_show(struct kobject *kobj, \
struct kobj_attribute *attr, \
char *page) \
{ \
BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
return sprintf(page, _format "\n"); \
} \
static struct kobj_attribute format_attr_##_var = \
__ATTR(_name, 0444, __rapl_##_var##_show, NULL)
#define RAPL_CNTR_WIDTH 32 #define RAPL_CNTR_WIDTH 32
#define RAPL_EVENT_ATTR_STR(_name, v, str) \ #define RAPL_EVENT_ATTR_STR(_name, v, str) \
...@@ -441,7 +429,7 @@ static struct attribute_group rapl_pmu_events_group = { ...@@ -441,7 +429,7 @@ static struct attribute_group rapl_pmu_events_group = {
.attrs = attrs_empty, .attrs = attrs_empty,
}; };
DEFINE_RAPL_FORMAT_ATTR(event, event, "config:0-7"); PMU_FORMAT_ATTR(event, "config:0-7");
static struct attribute *rapl_formats_attr[] = { static struct attribute *rapl_formats_attr[] = {
&format_attr_event.attr, &format_attr_event.attr,
NULL, NULL,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment