]> git.ipfire.org Git - people/arne_f/kernel.git/commitdiff
perf/x86: fix sysfs type mismatches
authorSami Tolvanen <samitolvanen@google.com>
Fri, 13 Nov 2020 18:31:26 +0000 (10:31 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 2 Dec 2020 07:34:42 +0000 (08:34 +0100)
[ Upstream commit ebd19fc372e3e78bf165f230e7c084e304441c08 ]

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 <sedat.dilek@gmail.com>
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lkml.kernel.org/r/20201113183126.1239404-1-samitolvanen@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/x86/events/intel/cstate.c
arch/x86/events/intel/rapl.c
arch/x86/events/intel/uncore.c
arch/x86/events/intel/uncore.h

index 59521c71c98a4206bd11cee3466e47c0315ec8a9..4ebeaa3c6710003cab5bdedc64a3e289c22c0adf 100644 (file)
 MODULE_LICENSE("GPL");
 
 #define DEFINE_CSTATE_FORMAT_ATTR(_var, _name, _format)                \
-static ssize_t __cstate_##_var##_show(struct kobject *kobj,    \
-                               struct kobj_attribute *attr,    \
+static ssize_t __cstate_##_var##_show(struct device *dev,      \
+                               struct device_attribute *attr,  \
                                char *page)                     \
 {                                                              \
        BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE);             \
        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)
 
 static ssize_t cstate_get_attr_cpumask(struct device *dev,
index d36a5fac6a18b3c17442f13ab607032c4b0ee410..7d3f861e31654d9d74775a5e79d30c313368a766 100644 (file)
@@ -115,18 +115,6 @@ static const char *const rapl_domain_names[NR_RAPL_DOMAINS] __initconst = {
  * any other bit is reserved
  */
 #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_EVENT_ATTR_STR(_name, v, str)                                     \
@@ -548,7 +536,7 @@ static struct attribute_group rapl_pmu_events_group = {
        .attrs = NULL, /* patched at runtime */
 };
 
-DEFINE_RAPL_FORMAT_ATTR(event, event, "config:0-7");
+PMU_FORMAT_ATTR(event, "config:0-7");
 static struct attribute *rapl_formats_attr[] = {
        &format_attr_event.attr,
        NULL,
index c56cb37b88e337dd34a46cd7ffc421062cdaddfd..4ad93871508cdf17169b2db1f1f9f5032fbb3da9 100644 (file)
@@ -90,8 +90,8 @@ end:
        return map;
 }
 
-ssize_t uncore_event_show(struct kobject *kobj,
-                         struct kobj_attribute *attr, char *buf)
+ssize_t uncore_event_show(struct device *dev,
+                         struct device_attribute *attr, char *buf)
 {
        struct uncore_event_desc *event =
                container_of(attr, struct uncore_event_desc, attr);
index 4364191e7c6b2904a443bf2a522ca4445b7f0a12..ae4ab89e16c7d9236679e11775e5e1e4979f4f37 100644 (file)
@@ -125,7 +125,7 @@ struct intel_uncore_box {
 #define UNCORE_BOX_FLAG_CTL_OFFS8      1 /* event config registers are 8-byte apart */
 
 struct uncore_event_desc {
-       struct kobj_attribute attr;
+       struct device_attribute attr;
        const char *config;
 };
 
@@ -137,8 +137,8 @@ struct pci2phy_map {
 
 struct pci2phy_map *__find_pci2phy_map(int segment);
 
-ssize_t uncore_event_show(struct kobject *kobj,
-                         struct kobj_attribute *attr, char *buf);
+ssize_t uncore_event_show(struct device *dev,
+                         struct device_attribute *attr, char *buf);
 
 #define INTEL_UNCORE_EVENT_DESC(_name, _config)                        \
 {                                                              \
@@ -147,14 +147,14 @@ ssize_t uncore_event_show(struct kobject *kobj,
 }
 
 #define DEFINE_UNCORE_FORMAT_ATTR(_var, _name, _format)                        \
-static ssize_t __uncore_##_var##_show(struct kobject *kobj,            \
-                               struct kobj_attribute *attr,            \
+static ssize_t __uncore_##_var##_show(struct device *dev,              \
+                               struct device_attribute *attr,          \
                                char *page)                             \
 {                                                                      \
        BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE);                     \
        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)
 
 static inline unsigned uncore_pci_box_ctl(struct intel_uncore_box *box)