Skip to content

Commit bb9ec13

Browse files
Tian Taogregkh
authored andcommitted
topology: use bin_attribute to break the size limitation of cpumap ABI
Reading /sys/devices/system/cpu/cpuX/topology/ returns cpu topology. However, the size of this file is limited to PAGE_SIZE because of the limitation for sysfs attribute. This patch moves to use bin_attribute to extend the ABI to be more than one page so that cpumap bitmask and list won't be potentially trimmed. Cc: Greg Kroah-Hartman <[email protected]> Cc: "Rafael J. Wysocki" <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Tian Tao <[email protected]> Signed-off-by: Barry Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 291f93c commit bb9ec13

File tree

1 file changed

+63
-52
lines changed

1 file changed

+63
-52
lines changed

drivers/base/topology.c

Lines changed: 63 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,27 @@ static ssize_t name##_show(struct device *dev, \
2121
return sysfs_emit(buf, "%d\n", topology_##name(dev->id)); \
2222
}
2323

24-
#define define_siblings_show_map(name, mask) \
25-
static ssize_t name##_show(struct device *dev, \
26-
struct device_attribute *attr, char *buf) \
27-
{ \
28-
return cpumap_print_to_pagebuf(false, buf, topology_##mask(dev->id));\
24+
#define define_siblings_read_func(name, mask) \
25+
static ssize_t name##_read(struct file *file, struct kobject *kobj, \
26+
struct bin_attribute *attr, char *buf, \
27+
loff_t off, size_t count) \
28+
{ \
29+
struct device *dev = kobj_to_dev(kobj); \
30+
\
31+
return cpumap_print_bitmask_to_buf(buf, topology_##mask(dev->id), \
32+
off, count); \
33+
} \
34+
\
35+
static ssize_t name##_list_read(struct file *file, struct kobject *kobj, \
36+
struct bin_attribute *attr, char *buf, \
37+
loff_t off, size_t count) \
38+
{ \
39+
struct device *dev = kobj_to_dev(kobj); \
40+
\
41+
return cpumap_print_list_to_buf(buf, topology_##mask(dev->id), \
42+
off, count); \
2943
}
3044

31-
#define define_siblings_show_list(name, mask) \
32-
static ssize_t name##_list_show(struct device *dev, \
33-
struct device_attribute *attr, \
34-
char *buf) \
35-
{ \
36-
return cpumap_print_to_pagebuf(true, buf, topology_##mask(dev->id));\
37-
}
38-
39-
#define define_siblings_show_func(name, mask) \
40-
define_siblings_show_map(name, mask); \
41-
define_siblings_show_list(name, mask)
42-
4345
define_id_show_func(physical_package_id);
4446
static DEVICE_ATTR_RO(physical_package_id);
4547

@@ -49,71 +51,80 @@ static DEVICE_ATTR_RO(die_id);
4951
define_id_show_func(core_id);
5052
static DEVICE_ATTR_RO(core_id);
5153

52-
define_siblings_show_func(thread_siblings, sibling_cpumask);
53-
static DEVICE_ATTR_RO(thread_siblings);
54-
static DEVICE_ATTR_RO(thread_siblings_list);
54+
define_siblings_read_func(thread_siblings, sibling_cpumask);
55+
static BIN_ATTR_RO(thread_siblings, 0);
56+
static BIN_ATTR_RO(thread_siblings_list, 0);
5557

56-
define_siblings_show_func(core_cpus, sibling_cpumask);
57-
static DEVICE_ATTR_RO(core_cpus);
58-
static DEVICE_ATTR_RO(core_cpus_list);
58+
define_siblings_read_func(core_cpus, sibling_cpumask);
59+
static BIN_ATTR_RO(core_cpus, 0);
60+
static BIN_ATTR_RO(core_cpus_list, 0);
5961

60-
define_siblings_show_func(core_siblings, core_cpumask);
61-
static DEVICE_ATTR_RO(core_siblings);
62-
static DEVICE_ATTR_RO(core_siblings_list);
62+
define_siblings_read_func(core_siblings, core_cpumask);
63+
static BIN_ATTR_RO(core_siblings, 0);
64+
static BIN_ATTR_RO(core_siblings_list, 0);
6365

64-
define_siblings_show_func(die_cpus, die_cpumask);
65-
static DEVICE_ATTR_RO(die_cpus);
66-
static DEVICE_ATTR_RO(die_cpus_list);
66+
define_siblings_read_func(die_cpus, die_cpumask);
67+
static BIN_ATTR_RO(die_cpus, 0);
68+
static BIN_ATTR_RO(die_cpus_list, 0);
6769

68-
define_siblings_show_func(package_cpus, core_cpumask);
69-
static DEVICE_ATTR_RO(package_cpus);
70-
static DEVICE_ATTR_RO(package_cpus_list);
70+
define_siblings_read_func(package_cpus, core_cpumask);
71+
static BIN_ATTR_RO(package_cpus, 0);
72+
static BIN_ATTR_RO(package_cpus_list, 0);
7173

7274
#ifdef CONFIG_SCHED_BOOK
7375
define_id_show_func(book_id);
7476
static DEVICE_ATTR_RO(book_id);
75-
define_siblings_show_func(book_siblings, book_cpumask);
76-
static DEVICE_ATTR_RO(book_siblings);
77-
static DEVICE_ATTR_RO(book_siblings_list);
77+
define_siblings_read_func(book_siblings, book_cpumask);
78+
static BIN_ATTR_RO(book_siblings, 0);
79+
static BIN_ATTR_RO(book_siblings_list, 0);
7880
#endif
7981

8082
#ifdef CONFIG_SCHED_DRAWER
8183
define_id_show_func(drawer_id);
8284
static DEVICE_ATTR_RO(drawer_id);
83-
define_siblings_show_func(drawer_siblings, drawer_cpumask);
84-
static DEVICE_ATTR_RO(drawer_siblings);
85-
static DEVICE_ATTR_RO(drawer_siblings_list);
85+
define_siblings_read_func(drawer_siblings, drawer_cpumask);
86+
static BIN_ATTR_RO(drawer_siblings, 0);
87+
static BIN_ATTR_RO(drawer_siblings_list, 0);
8688
#endif
8789

90+
static struct bin_attribute *bin_attrs[] = {
91+
&bin_attr_core_cpus,
92+
&bin_attr_core_cpus_list,
93+
&bin_attr_thread_siblings,
94+
&bin_attr_thread_siblings_list,
95+
&bin_attr_core_siblings,
96+
&bin_attr_core_siblings_list,
97+
&bin_attr_die_cpus,
98+
&bin_attr_die_cpus_list,
99+
&bin_attr_package_cpus,
100+
&bin_attr_package_cpus_list,
101+
#ifdef CONFIG_SCHED_BOOK
102+
&bin_attr_book_siblings,
103+
&bin_attr_book_siblings_list,
104+
#endif
105+
#ifdef CONFIG_SCHED_DRAWER
106+
&bin_attr_drawer_siblings,
107+
&bin_attr_drawer_siblings_list,
108+
#endif
109+
NULL
110+
};
111+
88112
static struct attribute *default_attrs[] = {
89113
&dev_attr_physical_package_id.attr,
90114
&dev_attr_die_id.attr,
91115
&dev_attr_core_id.attr,
92-
&dev_attr_thread_siblings.attr,
93-
&dev_attr_thread_siblings_list.attr,
94-
&dev_attr_core_cpus.attr,
95-
&dev_attr_core_cpus_list.attr,
96-
&dev_attr_core_siblings.attr,
97-
&dev_attr_core_siblings_list.attr,
98-
&dev_attr_die_cpus.attr,
99-
&dev_attr_die_cpus_list.attr,
100-
&dev_attr_package_cpus.attr,
101-
&dev_attr_package_cpus_list.attr,
102116
#ifdef CONFIG_SCHED_BOOK
103117
&dev_attr_book_id.attr,
104-
&dev_attr_book_siblings.attr,
105-
&dev_attr_book_siblings_list.attr,
106118
#endif
107119
#ifdef CONFIG_SCHED_DRAWER
108120
&dev_attr_drawer_id.attr,
109-
&dev_attr_drawer_siblings.attr,
110-
&dev_attr_drawer_siblings_list.attr,
111121
#endif
112122
NULL
113123
};
114124

115125
static const struct attribute_group topology_attr_group = {
116126
.attrs = default_attrs,
127+
.bin_attrs = bin_attrs,
117128
.name = "topology"
118129
};
119130

0 commit comments

Comments
 (0)