All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Barry Song <song.bao.hua@hisilicon.com>
Cc: gregkh@linuxfoundation.org, akpm@linux-foundation.org,
	yury.norov@gmail.com, linux-kernel@vger.kernel.org,
	dave.hansen@intel.com, linux@rasmusvillemoes.dk,
	rafael@kernel.org, rdunlap@infradead.org, agordeev@linux.ibm.com,
	sbrivio@redhat.com, jianpeng.ma@intel.com,
	valentin.schneider@arm.com, peterz@infradead.org,
	bristot@redhat.com, guodong.xu@linaro.org,
	tangchengchang@huawei.com, prime.zeng@hisilicon.com,
	yangyicong@huawei.com, tim.c.chen@linux.intel.com,
	linuxarm@huawei.com, Tian Tao <tiantao6@hisilicon.com>,
	Jonathan Cameron <jonathan.cameron@huawei.com>
Subject: Re: [PATCH v6 3/4] drivers/base/node.c: use bin_attribute to break the size limitation of cpumap ABI
Date: Fri, 9 Jul 2021 14:25:38 +0300	[thread overview]
Message-ID: <YOgyMuwwS74mgclU@smile.fi.intel.com> (raw)
In-Reply-To: <20210709075544.11412-4-song.bao.hua@hisilicon.com>

On Fri, Jul 09, 2021 at 07:55:43PM +1200, Barry Song wrote:
> From: Tian Tao <tiantao6@hisilicon.com>
> 
> Reading sys/devices/system/cpu/cpuX/nodeX/ returns cpumap and cpulist.

/sys

> 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.
> 
> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Signed-off-by: Barry Song <song.bao.hua@hisilicon.com>
> ---
>  -v6: remove an extra blank line according to Andy Shevchenko's comment;
> 
>  drivers/base/node.c | 51 +++++++++++++++++++++++++++++----------------
>  1 file changed, 33 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/base/node.c b/drivers/base/node.c
> index 4a4ae868ad9f..89a72aba72a3 100644
> --- a/drivers/base/node.c
> +++ b/drivers/base/node.c
> @@ -27,42 +27,44 @@ static struct bus_type node_subsys = {
>  };
>  
>  
> -static ssize_t node_read_cpumap(struct device *dev, bool list, char *buf)
> +static ssize_t node_read_cpumap(struct device *dev, bool list, char *buf,
> +				loff_t off, size_t count)
>  {
>  	ssize_t n;
>  	cpumask_var_t mask;
>  	struct node *node_dev = to_node(dev);
>  
> -	/* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */
> -	BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1));
> -
>  	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_to_pagebuf(list, buf, mask);
> +	n = cpumap_print_to_buf(list, buf, mask, off, count);
>  	free_cpumask_var(mask);
>  
>  	return n;
>  }
>  
> -static inline ssize_t cpumap_show(struct device *dev,
> -				  struct device_attribute *attr,
> -				  char *buf)
> +static inline ssize_t cpumap_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);
> +
> +	return node_read_cpumap(dev, false, buf, off, count);
>  }
>  
> -static DEVICE_ATTR_RO(cpumap);
> +static BIN_ATTR_RO(cpumap, 0);
>  
> -static inline ssize_t cpulist_show(struct device *dev,
> -				   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, true, buf);
> +	struct device *dev = kobj_to_dev(kobj);
> +
> +	return node_read_cpumap(dev, true, buf, off, count);
>  }
>  
> -static DEVICE_ATTR_RO(cpulist);
> +static BIN_ATTR_RO(cpulist, 0);
>  
>  /**
>   * struct node_access_nodes - Access class device to hold user visible
> @@ -557,15 +559,28 @@ static ssize_t node_read_distance(struct device *dev,
>  static DEVICE_ATTR(distance, 0444, node_read_distance, NULL);
>  
>  static struct attribute *node_dev_attrs[] = {
> -	&dev_attr_cpumap.attr,
> -	&dev_attr_cpulist.attr,
>  	&dev_attr_meminfo.attr,
>  	&dev_attr_numastat.attr,
>  	&dev_attr_distance.attr,
>  	&dev_attr_vmstat.attr,
>  	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
>  /*
> -- 
> 2.25.1
> 

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2021-07-09 11:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-09  7:55 [PATCH v6 0/4] use bin_attribute to break the size limitation of cpumap ABI Barry Song
2021-07-09  7:55 ` [PATCH v6 1/4] cpumask: introduce cpumap_print_to_buf to support large bitmask and list Barry Song
2021-07-09 11:23   ` Andy Shevchenko
2021-07-09  7:55 ` [PATCH v6 2/4] topology: use bin_attribute to break the size limitation of cpumap ABI Barry Song
2021-07-09  7:55 ` [PATCH v6 3/4] drivers/base/node.c: " Barry Song
2021-07-09 11:25   ` Andy Shevchenko [this message]
2021-07-09  7:55 ` [PATCH v6 4/4] lib: test_bitmap: add bitmap_print_to_buf test cases Barry Song
2021-07-09 11:30   ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YOgyMuwwS74mgclU@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=agordeev@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=bristot@redhat.com \
    --cc=dave.hansen@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=guodong.xu@linaro.org \
    --cc=jianpeng.ma@intel.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=linuxarm@huawei.com \
    --cc=peterz@infradead.org \
    --cc=prime.zeng@hisilicon.com \
    --cc=rafael@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=sbrivio@redhat.com \
    --cc=song.bao.hua@hisilicon.com \
    --cc=tangchengchang@huawei.com \
    --cc=tiantao6@hisilicon.com \
    --cc=tim.c.chen@linux.intel.com \
    --cc=valentin.schneider@arm.com \
    --cc=yangyicong@huawei.com \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.