Skip to content

Commit 75bd50f

Browse files
Tian Taogregkh
authored andcommitted
drivers/base/node.c: use bin_attribute to break the size limitation of cpumap ABI
Reading /sys/devices/system/cpu/cpuX/nodeX/ returns cpumap and cpulist. 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 bb9ec13 commit 75bd50f

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

drivers/base/node.c

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,43 +26,47 @@ static struct bus_type node_subsys = {
2626
.dev_name = "node",
2727
};
2828

29-
30-
static ssize_t node_read_cpumap(struct device *dev, bool list, char *buf)
29+
static inline ssize_t cpumap_read(struct file *file, struct kobject *kobj,
30+
struct bin_attribute *attr, char *buf,
31+
loff_t off, size_t count)
3132
{
32-
ssize_t n;
33-
cpumask_var_t mask;
33+
struct device *dev = kobj_to_dev(kobj);
3434
struct node *node_dev = to_node(dev);
35-
36-
/* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */
37-
BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1));
35+
cpumask_var_t mask;
36+
ssize_t n;
3837

3938
if (!alloc_cpumask_var(&mask, GFP_KERNEL))
4039
return 0;
4140

4241
cpumask_and(mask, cpumask_of_node(node_dev->dev.id), cpu_online_mask);
43-
n = cpumap_print_to_pagebuf(list, buf, mask);
42+
n = cpumap_print_bitmask_to_buf(buf, mask, off, count);
4443
free_cpumask_var(mask);
4544

4645
return n;
4746
}
4847

49-
static inline ssize_t cpumap_show(struct device *dev,
50-
struct device_attribute *attr,
51-
char *buf)
48+
static BIN_ATTR_RO(cpumap, 0);
49+
50+
static inline ssize_t cpulist_read(struct file *file, struct kobject *kobj,
51+
struct bin_attribute *attr, char *buf,
52+
loff_t off, size_t count)
5253
{
53-
return node_read_cpumap(dev, false, buf);
54-
}
54+
struct device *dev = kobj_to_dev(kobj);
55+
struct node *node_dev = to_node(dev);
56+
cpumask_var_t mask;
57+
ssize_t n;
58+
59+
if (!alloc_cpumask_var(&mask, GFP_KERNEL))
60+
return 0;
5561

56-
static DEVICE_ATTR_RO(cpumap);
62+
cpumask_and(mask, cpumask_of_node(node_dev->dev.id), cpu_online_mask);
63+
n = cpumap_print_list_to_buf(buf, mask, off, count);
64+
free_cpumask_var(mask);
5765

58-
static inline ssize_t cpulist_show(struct device *dev,
59-
struct device_attribute *attr,
60-
char *buf)
61-
{
62-
return node_read_cpumap(dev, true, buf);
66+
return n;
6367
}
6468

65-
static DEVICE_ATTR_RO(cpulist);
69+
static BIN_ATTR_RO(cpulist, 0);
6670

6771
/**
6872
* struct node_access_nodes - Access class device to hold user visible
@@ -557,15 +561,28 @@ static ssize_t node_read_distance(struct device *dev,
557561
static DEVICE_ATTR(distance, 0444, node_read_distance, NULL);
558562

559563
static struct attribute *node_dev_attrs[] = {
560-
&dev_attr_cpumap.attr,
561-
&dev_attr_cpulist.attr,
562564
&dev_attr_meminfo.attr,
563565
&dev_attr_numastat.attr,
564566
&dev_attr_distance.attr,
565567
&dev_attr_vmstat.attr,
566568
NULL
567569
};
568-
ATTRIBUTE_GROUPS(node_dev);
570+
571+
static struct bin_attribute *node_dev_bin_attrs[] = {
572+
&bin_attr_cpumap,
573+
&bin_attr_cpulist,
574+
NULL
575+
};
576+
577+
static const struct attribute_group node_dev_group = {
578+
.attrs = node_dev_attrs,
579+
.bin_attrs = node_dev_bin_attrs
580+
};
581+
582+
static const struct attribute_group *node_dev_groups[] = {
583+
&node_dev_group,
584+
NULL
585+
};
569586

570587
#ifdef CONFIG_HUGETLBFS
571588
/*

0 commit comments

Comments
 (0)