Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp426522pxv; Fri, 9 Jul 2021 00:59:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAS5heoH+Z+k5z8yI5Q0Wx8fNIGMYBoIPfx/K5zI/BLZdpdOatWSKbusZfeB1NQnXKZAWK X-Received: by 2002:a17:906:a94:: with SMTP id y20mr12904975ejf.399.1625817548974; Fri, 09 Jul 2021 00:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625817548; cv=none; d=google.com; s=arc-20160816; b=D9E/XIlXc9xVT4QmtpcvfQnHn9vm3NdXXtv5RjwtWVxCSN8B12V8aqCHHeHhfcoWNh FxZ6NDTNXQSPGz/bLjh8pXutyHBiqSEkpRf6heGKBcLwzvnlovHdYOAUnOnNrIAhKVLK fRDtr5i6D8QCOvrwosGp2RKUWlHrOmSY1Iun0iSXFFGs1NIUewGysyTBEQrxZHaUruhi iNGnj3E2wsHeoS5gP4b38EaGMN/lYpDKpD69bEMU5bN6XQ3OX9l6BuNGpPlbStF7jAgn GpoHb8C39XXeupCggXF+sOayNkx7c4EWMyFHcWmcBmb8iYpcVoOzPv4zgsKeSq4+sJgY HKJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=MHz66aPQgnQKff016imbyNAeYAmk+0ALv2gqJtDdkOk=; b=NbYx2VIcH05yTK4FbdCKLj/G0ggjpvPdpRCxSxgfDn+TbvaoqxUnahKSKqdcEwi11o WgQDU9nP6tJYWzVg0h68M5JdVMKKsEJKKd+eD+p6c+u4s3IJ8VVcs3ImRuErs1EyJiIG LnMrc/oB5Zt8qWHNNj7OulHhtEzeKp6IgBsqebSI6j5ci69Vs6f7fJ6C6/mqnzHjIQt5 hu3TceFSzTgSXrdY++VdrhdhGtZoWGJf5157pRsg8G530HezEZ54HhbDajDo5X9/SO2V XNlGxLFUTmNG02Wnv7pJnTkvBX3J13A7Q4MMUR+xYzwPVzVrcA3xDYn6G/yD7ae0X/Oq 7/4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hisilicon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r18si6264269edp.19.2021.07.09.00.58.44; Fri, 09 Jul 2021 00:59:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hisilicon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231401AbhGIH71 (ORCPT + 99 others); Fri, 9 Jul 2021 03:59:27 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:6898 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231320AbhGIH70 (ORCPT ); Fri, 9 Jul 2021 03:59:26 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GLllC4XFzz79V3; Fri, 9 Jul 2021 15:53:11 +0800 (CST) Received: from dggemi761-chm.china.huawei.com (10.1.198.147) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Fri, 9 Jul 2021 15:56:35 +0800 Received: from SWX921481.china.huawei.com (10.126.202.219) by dggemi761-chm.china.huawei.com (10.1.198.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Fri, 9 Jul 2021 15:56:30 +0800 From: Barry Song To: , , , , CC: , , , , , , , , , , , , , , , , Tian Tao , Jonathan Cameron , Barry Song Subject: [PATCH v6 3/4] drivers/base/node.c: use bin_attribute to break the size limitation of cpumap ABI Date: Fri, 9 Jul 2021 19:55:43 +1200 Message-ID: <20210709075544.11412-4-song.bao.hua@hisilicon.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20210709075544.11412-1-song.bao.hua@hisilicon.com> References: <20210709075544.11412-1-song.bao.hua@hisilicon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.126.202.219] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggemi761-chm.china.huawei.com (10.1.198.147) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tian Tao 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. Signed-off-by: Tian Tao Reviewed-by: Jonathan Cameron Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Signed-off-by: Barry Song --- -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