forked from mirrors/linux
		
	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 <gregkh@linuxfoundation.org> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Tian Tao <tiantao6@hisilicon.com> Signed-off-by: Barry Song <song.bao.hua@hisilicon.com> Link: https://lore.kernel.org/r/20210806110251.560-5-song.bao.hua@hisilicon.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
		
							parent
							
								
									bb9ec13d15
								
							
						
					
					
						commit
						75bd50fa84
					
				
					 1 changed files with 42 additions and 25 deletions
				
			
		|  | @ -26,43 +26,47 @@ static struct bus_type node_subsys = { | ||||||
| 	.dev_name = "node", | 	.dev_name = "node", | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| 
 | static inline ssize_t cpumap_read(struct file *file, struct kobject *kobj, | ||||||
| static ssize_t node_read_cpumap(struct device *dev, bool list, char *buf) | 				  struct bin_attribute *attr, char *buf, | ||||||
|  | 				  loff_t off, size_t count) | ||||||
| { | { | ||||||
| 	ssize_t n; | 	struct device *dev = kobj_to_dev(kobj); | ||||||
| 	cpumask_var_t mask; |  | ||||||
| 	struct node *node_dev = to_node(dev); | 	struct node *node_dev = to_node(dev); | ||||||
| 
 | 	cpumask_var_t mask; | ||||||
| 	/* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */ | 	ssize_t n; | ||||||
| 	BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1)); |  | ||||||
| 
 | 
 | ||||||
| 	if (!alloc_cpumask_var(&mask, GFP_KERNEL)) | 	if (!alloc_cpumask_var(&mask, GFP_KERNEL)) | ||||||
| 		return 0; | 		return 0; | ||||||
| 
 | 
 | ||||||
| 	cpumask_and(mask, cpumask_of_node(node_dev->dev.id), cpu_online_mask); | 	cpumask_and(mask, cpumask_of_node(node_dev->dev.id), cpu_online_mask); | ||||||
| 	n = cpumap_print_to_pagebuf(list, buf, mask); | 	n = cpumap_print_bitmask_to_buf(buf, mask, off, count); | ||||||
| 	free_cpumask_var(mask); | 	free_cpumask_var(mask); | ||||||
| 
 | 
 | ||||||
| 	return n; | 	return n; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static inline ssize_t cpumap_show(struct device *dev, | static BIN_ATTR_RO(cpumap, 0); | ||||||
| 				  struct device_attribute *attr, | 
 | ||||||
| 				  char *buf) | static inline ssize_t cpulist_read(struct file *file, struct kobject *kobj, | ||||||
|  | 				   struct bin_attribute *attr, char *buf, | ||||||
|  | 				   loff_t off, size_t count) | ||||||
| { | { | ||||||
| 	return node_read_cpumap(dev, false, buf); | 	struct device *dev = kobj_to_dev(kobj); | ||||||
|  | 	struct node *node_dev = to_node(dev); | ||||||
|  | 	cpumask_var_t mask; | ||||||
|  | 	ssize_t n; | ||||||
|  | 
 | ||||||
|  | 	if (!alloc_cpumask_var(&mask, GFP_KERNEL)) | ||||||
|  | 		return 0; | ||||||
|  | 
 | ||||||
|  | 	cpumask_and(mask, cpumask_of_node(node_dev->dev.id), cpu_online_mask); | ||||||
|  | 	n = cpumap_print_list_to_buf(buf, mask, off, count); | ||||||
|  | 	free_cpumask_var(mask); | ||||||
|  | 
 | ||||||
|  | 	return n; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static DEVICE_ATTR_RO(cpumap); | static BIN_ATTR_RO(cpulist, 0); | ||||||
| 
 |  | ||||||
| static inline ssize_t cpulist_show(struct device *dev, |  | ||||||
| 				   struct device_attribute *attr, |  | ||||||
| 				   char *buf) |  | ||||||
| { |  | ||||||
| 	return node_read_cpumap(dev, true, buf); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static DEVICE_ATTR_RO(cpulist); |  | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * struct node_access_nodes - Access class device to hold user visible |  * struct node_access_nodes - Access class device to hold user visible | ||||||
|  | @ -557,15 +561,28 @@ static ssize_t node_read_distance(struct device *dev, | ||||||
| static DEVICE_ATTR(distance, 0444, node_read_distance, NULL); | static DEVICE_ATTR(distance, 0444, node_read_distance, NULL); | ||||||
| 
 | 
 | ||||||
| static struct attribute *node_dev_attrs[] = { | static struct attribute *node_dev_attrs[] = { | ||||||
| 	&dev_attr_cpumap.attr, |  | ||||||
| 	&dev_attr_cpulist.attr, |  | ||||||
| 	&dev_attr_meminfo.attr, | 	&dev_attr_meminfo.attr, | ||||||
| 	&dev_attr_numastat.attr, | 	&dev_attr_numastat.attr, | ||||||
| 	&dev_attr_distance.attr, | 	&dev_attr_distance.attr, | ||||||
| 	&dev_attr_vmstat.attr, | 	&dev_attr_vmstat.attr, | ||||||
| 	NULL | 	NULL | ||||||
| }; | }; | ||||||
| ATTRIBUTE_GROUPS(node_dev); | 
 | ||||||
|  | static struct bin_attribute *node_dev_bin_attrs[] = { | ||||||
|  | 	&bin_attr_cpumap, | ||||||
|  | 	&bin_attr_cpulist, | ||||||
|  | 	NULL | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | static const struct attribute_group node_dev_group = { | ||||||
|  | 	.attrs = node_dev_attrs, | ||||||
|  | 	.bin_attrs = node_dev_bin_attrs | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | static const struct attribute_group *node_dev_groups[] = { | ||||||
|  | 	&node_dev_group, | ||||||
|  | 	NULL | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
| #ifdef CONFIG_HUGETLBFS | #ifdef CONFIG_HUGETLBFS | ||||||
| /*
 | /*
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Tian Tao
						Tian Tao