From patchwork Thu Dec 5 17:35:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13895873 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73B03221465; Thu, 5 Dec 2024 17:35:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733420143; cv=none; b=V4swDCduwTPsWtUzWAhxooEQnT4OWXVdlPwEpimbobP9cs0rtu1sq6R2vYals+JW1vWap5DqXx82YF9cu8DyvqF1QcqOHNZGkVMjDmV9Atd1uS7gNzSq2aC6MDCq2ckVmyv6Hi+po4q0/WhfpNauhV4z8Wp0PM1i5snOqD/0ypA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733420143; c=relaxed/simple; bh=yFTZIDT/d9HKSr1VCybVUXBQPCUX/YWCdCVUCfZE2/M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pIszNQcjXEd/jvqq5t20u9ghwUgriFXjw3lWXuedNJ8HjC/e1ikq2SJcwiLRdx2+MUjx3h4OZBBD+z1uYLWeTbwg3V8rNW+cPSgHSWm1j33bFpem0BUd53/ic60OmTN17j92BS91m3ZggZmXOMCBN1QoAA9HMxqeJTs/KlfhjL8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=KG9tk7D3; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="KG9tk7D3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733420137; bh=yFTZIDT/d9HKSr1VCybVUXBQPCUX/YWCdCVUCfZE2/M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=KG9tk7D3L7Uf0IUGoE1XT5UumEfJAlsFAfz8UVuSvsNm0D3SC3/fIgoGLxau2ZERH mWMESJy6PDE+efZVb10E62JK6JebxXhDp9abmp90ylpbE6ROZkzRiglTfiN2Fx/5k+ W4pJX5dsjU6q3xn4Pjbdhsy3al2VGArAwS9ikGGY= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 05 Dec 2024 18:35:13 +0100 Subject: [PATCH 1/4] sysfs: constify bin_attribute argument of sysfs_bin_attr_simple_read() Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241205-sysfs-const-bin_attr-simple-v1-1-4a4e4ced71e3@weissschuh.net> References: <20241205-sysfs-const-bin_attr-simple-v1-0-4a4e4ced71e3@weissschuh.net> In-Reply-To: <20241205-sysfs-const-bin_attr-simple-v1-0-4a4e4ced71e3@weissschuh.net> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , Greg Kroah-Hartman , "Rafael J. Wysocki" , Luis Chamberlain , Petr Pavlu , Sami Tolvanen , Daniel Gomez , Armin Wolf , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, platform-driver-x86@vger.kernel.org, bpf@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733420137; l=3142; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=yFTZIDT/d9HKSr1VCybVUXBQPCUX/YWCdCVUCfZE2/M=; b=N6SLb2+eSyolUshM1oNp1SwAkyOJIwilUlfzAQ+W+1VNmN2Og70zO7PtWIR6lJLtiURIW0PKL lP9vrvVVQB8C6d3iPwEht3v7ttdLR6Ohcbgt+23W8yn/BbmOnet1+/p X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Most users use this function through the BIN_ATTR_SIMPLE* macros, they can handle the switch transparently. Also adapt the two non-macro users in the same change. Signed-off-by: Thomas Weißschuh --- arch/powerpc/platforms/powernv/opal.c | 2 +- fs/sysfs/file.c | 2 +- include/linux/sysfs.h | 4 ++-- kernel/module/sysfs.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c index 5d0f35bb917ebced8c741cd3af2c511949a1d2ef..013637e2b2a8e6a4ec6b93a520f8d5d9d3245467 100644 --- a/arch/powerpc/platforms/powernv/opal.c +++ b/arch/powerpc/platforms/powernv/opal.c @@ -818,7 +818,7 @@ static int opal_add_one_export(struct kobject *parent, const char *export_name, sysfs_bin_attr_init(attr); attr->attr.name = name; attr->attr.mode = 0400; - attr->read = sysfs_bin_attr_simple_read; + attr->read_new = sysfs_bin_attr_simple_read; attr->private = __va(vals[0]); attr->size = vals[1]; diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 785408861c01c89fc84c787848243a13c1338367..6931308876c4ac3b4c19878d5e1158ad8fe4f16f 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -817,7 +817,7 @@ EXPORT_SYMBOL_GPL(sysfs_emit_at); * Returns number of bytes written to @buf. */ ssize_t sysfs_bin_attr_simple_read(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, char *buf, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { memcpy(buf, attr->private + off, count); diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 0f2fcd244523f050c5286f19d4fe1846506f9214..2205561159afdb57d0a250bb0439b28c01d9010e 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -511,7 +511,7 @@ __printf(3, 4) int sysfs_emit_at(char *buf, int at, const char *fmt, ...); ssize_t sysfs_bin_attr_simple_read(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, char *buf, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count); #else /* CONFIG_SYSFS */ @@ -774,7 +774,7 @@ static inline int sysfs_emit_at(char *buf, int at, const char *fmt, ...) static inline ssize_t sysfs_bin_attr_simple_read(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { diff --git a/kernel/module/sysfs.c b/kernel/module/sysfs.c index 456358e1fdc43e6b5b24f383bbefa37812971174..254017b58b645d4afcf6876d29bcc2e2113a8dc4 100644 --- a/kernel/module/sysfs.c +++ b/kernel/module/sysfs.c @@ -196,7 +196,7 @@ static int add_notes_attrs(struct module *mod, const struct load_info *info) nattr->attr.mode = 0444; nattr->size = info->sechdrs[i].sh_size; nattr->private = (void *)info->sechdrs[i].sh_addr; - nattr->read = sysfs_bin_attr_simple_read; + nattr->read_new = sysfs_bin_attr_simple_read; ++nattr; } ++loaded; From patchwork Thu Dec 5 17:35:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13895872 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E619622576B; Thu, 5 Dec 2024 17:35:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733420142; cv=none; b=cAMYePGS4KflR7oG2rAA1EZSwxZ9uzxQcje1cbdmVl0HCNVF0T58Ck0dw3sw+59HJgBXW0lQjKr/u/uW12mx8TvhBN3oNJp4+Zl20D0pniBn0X8JTUyxdZJHaFlfbadKmpebCY7kjggvDJtPZU5TNGbJRwZeWXSDcwi1kEB2O8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733420142; c=relaxed/simple; bh=5LgMscy8fNMxkSnBk89bFZtOweO+ubs1BjcR/pPmVkk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Z7rM1xUWHSVsqX/iK4iqrbGpXolqDy4kJlKN7X2G5KCLhY0lgsqLrMZobya5cTpbvu5HS3b6GbUS25mxk/4zuDVTPPgunUmTfZe1T3v/kzte7bJEiAGUp7eTP44G+N0iwe4ESJL/oQv1FUjed5JQA7rpqUodLjKq8YC+HIq57qE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=N3aE/who; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="N3aE/who" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733420137; bh=5LgMscy8fNMxkSnBk89bFZtOweO+ubs1BjcR/pPmVkk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=N3aE/whoh0KniNiOdttnlBkPGxTSvIZRmCSS4tM8MAPBalxnpZjR3OoaUI3/xXTIo fNNtedHUR+sbdbMnShhmacrx6v0eWcsU3TYdFPa16wzAGR6XJ7jGXiDVl6/n1HjBz+ JSalKw3c9i0jJhAAfKdCvzOzYA+mk+CgGniZjEaI= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 05 Dec 2024 18:35:14 +0100 Subject: [PATCH 2/4] platform/x86: wmi-bmof: Switch to sysfs_bin_attr_simple_read() Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241205-sysfs-const-bin_attr-simple-v1-2-4a4e4ced71e3@weissschuh.net> References: <20241205-sysfs-const-bin_attr-simple-v1-0-4a4e4ced71e3@weissschuh.net> In-Reply-To: <20241205-sysfs-const-bin_attr-simple-v1-0-4a4e4ced71e3@weissschuh.net> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , Greg Kroah-Hartman , "Rafael J. Wysocki" , Luis Chamberlain , Petr Pavlu , Sami Tolvanen , Daniel Gomez , Armin Wolf , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, platform-driver-x86@vger.kernel.org, bpf@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733420137; l=1583; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=5LgMscy8fNMxkSnBk89bFZtOweO+ubs1BjcR/pPmVkk=; b=FFE0LC+lWyL41OWKcLih/cJP43TX/qUmNdEXnIWxYkdVLt0K7dsR35ynGht17m6UhezsKb9iC ql1zd1NvQ0BAvkF0dWD1XVGmm/v8XCf3L6eiabSOtHoMnaMvizVK/An X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The generic function from the sysfs core can replace the custom one. Signed-off-by: Thomas Weißschuh --- drivers/platform/x86/wmi-bmof.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/platform/x86/wmi-bmof.c b/drivers/platform/x86/wmi-bmof.c index df6f0ae6e6c7904f97c125297a21166f56d0b1f0..e6c217d70086a2896dc70cf8ac1c27dafb501a95 100644 --- a/drivers/platform/x86/wmi-bmof.c +++ b/drivers/platform/x86/wmi-bmof.c @@ -25,15 +25,6 @@ struct bmof_priv { struct bin_attribute bmof_bin_attr; }; -static ssize_t read_bmof(struct file *filp, struct kobject *kobj, struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - struct bmof_priv *priv = container_of(attr, struct bmof_priv, bmof_bin_attr); - - return memory_read_from_buffer(buf, count, &off, priv->bmofdata->buffer.pointer, - priv->bmofdata->buffer.length); -} - static int wmi_bmof_probe(struct wmi_device *wdev, const void *context) { struct bmof_priv *priv; @@ -60,7 +51,8 @@ static int wmi_bmof_probe(struct wmi_device *wdev, const void *context) sysfs_bin_attr_init(&priv->bmof_bin_attr); priv->bmof_bin_attr.attr.name = "bmof"; priv->bmof_bin_attr.attr.mode = 0400; - priv->bmof_bin_attr.read = read_bmof; + priv->bmof_bin_attr.read_new = sysfs_bin_attr_simple_read; + priv->bmof_bin_attr.private = priv->bmofdata->buffer.pointer; priv->bmof_bin_attr.size = priv->bmofdata->buffer.length; ret = device_create_bin_file(&wdev->dev, &priv->bmof_bin_attr); From patchwork Thu Dec 5 17:35:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13895874 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F69422579D; Thu, 5 Dec 2024 17:35:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733420143; cv=none; b=D3cLQcllqElOvPy1YIaKAo4CCeSd808+5o3qt6qwV3H/8W5LehiOrn+8D2m64QFKkd8WRvL8WwkU/BQZRnZ6ncUpijcd4OU719nEJak3OUjn54UcaHwTjSYOJzNM9hXCAw8C+aBZLMsjoa7caRtPyPCLdR2c+ZNflxjpnrXbIWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733420143; c=relaxed/simple; bh=v54jOXPBj86EmdoK8VRH/WJTe91je7IjzNhdTGxTAGM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Nai668EQ8mjtKJUKHobZ3eU72HFIs3XrfZipAm2iAjXxSDHDRGIBYm4KqySA+ZFTPlMNyDUH5QLxIL4GQqkrjeobEk5PBUTQVwAkCfztwLRhwiPP7MJfk3Tq/aFVQymzPSxSwjZA+zoKJOQ6BbBbOS3NsPvHbixpzrdlqPUZUpo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=K6bno3Pi; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="K6bno3Pi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733420137; bh=v54jOXPBj86EmdoK8VRH/WJTe91je7IjzNhdTGxTAGM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=K6bno3Pid1wQl8du0lNePJ95Kvvh7/8n5drvB2nGu7OHw9DcP/cBbyuGWw1foEg5Y zAU2a1oj/zgo72VtMRKRrCdb4KgzJ0Umw1lBEe2d076qaJC9xwZRrqMPO9OuBNxt/z Trex6yqGmkJCtKeeefG+X9DMpIdzov2ei2fbATzM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 05 Dec 2024 18:35:15 +0100 Subject: [PATCH 3/4] btf: Switch vmlinux BTF attribute to sysfs_bin_attr_simple_read() Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241205-sysfs-const-bin_attr-simple-v1-3-4a4e4ced71e3@weissschuh.net> References: <20241205-sysfs-const-bin_attr-simple-v1-0-4a4e4ced71e3@weissschuh.net> In-Reply-To: <20241205-sysfs-const-bin_attr-simple-v1-0-4a4e4ced71e3@weissschuh.net> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , Greg Kroah-Hartman , "Rafael J. Wysocki" , Luis Chamberlain , Petr Pavlu , Sami Tolvanen , Daniel Gomez , Armin Wolf , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, platform-driver-x86@vger.kernel.org, bpf@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733420137; l=1383; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=v54jOXPBj86EmdoK8VRH/WJTe91je7IjzNhdTGxTAGM=; b=z5q+mLaILrDgqDYwtsD48fkDkxpZ62jcajO3UKpxPz32mD8JI/2JI972ZU1lQwyNF3vSJQo0s 6sYjAwPi+IUDoUGqDySD1CsWmyWtBNVzTIiDOk4iNPc9R3Rd/cj/9nF X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The generic function from the sysfs core can replace the custom one. Signed-off-by: Thomas Weißschuh Acked-by: Andrii Nakryiko --- This is a replacement for [0], as Alexei was not happy about BIN_ATTR_SIMPLE_RO() [0] https://lore.kernel.org/lkml/20241122-sysfs-const-bin_attr-bpf-v1-1-823aea399b53@weissschuh.net/ --- kernel/bpf/sysfs_btf.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/kernel/bpf/sysfs_btf.c b/kernel/bpf/sysfs_btf.c index fedb54c94cdb830a4890d33677dcc5a6e236c13f..81d6cf90584a7157929c50f62a5c6862e7a3d081 100644 --- a/kernel/bpf/sysfs_btf.c +++ b/kernel/bpf/sysfs_btf.c @@ -12,24 +12,16 @@ extern char __start_BTF[]; extern char __stop_BTF[]; -static ssize_t -btf_vmlinux_read(struct file *file, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t len) -{ - memcpy(buf, __start_BTF + off, len); - return len; -} - static struct bin_attribute bin_attr_btf_vmlinux __ro_after_init = { .attr = { .name = "vmlinux", .mode = 0444, }, - .read = btf_vmlinux_read, + .read_new = sysfs_bin_attr_simple_read, }; struct kobject *btf_kobj; static int __init btf_vmlinux_init(void) { + bin_attr_btf_vmlinux.private = __start_BTF; bin_attr_btf_vmlinux.size = __stop_BTF - __start_BTF; if (bin_attr_btf_vmlinux.size == 0) From patchwork Thu Dec 5 17:35:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13895870 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1103224B0F; Thu, 5 Dec 2024 17:35:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733420142; cv=none; b=ozAyV6z+v97qpX0fugw+7/6mqbiTtGJRnqOM4xgrOhqlo98zo/LQyonMp8h7boXx6LXifo9oC58MveboIXZhK/26Nbl5+IeLvlEAPgWtSs5XF58jbjJfWv0U52yavtf1GMAKeSPRD2yrVhXwSQi6RfbsVV/1RiLAcEPG9pKQ+sM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733420142; c=relaxed/simple; bh=cfuC4VjJZbJslwembV87HLGJheNWpA6IXa9jHRZu/TI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sOlaQ3xoIpu3ZfrrvDlcTILqRASfAIi4MYpJkk653GtBuMni+FJL6Mar7Shi0YMlV5enjHhIGfAR6YG6Dg4kQVIJ3qFRMcUCzpzfzkFWhuHlIEvBo9CF7UZY0+dtuE5wOV3KGCDFYJ1PuX7JAu1j4ReA/K5zz/b3seEMmCLfcsk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=guoxc6ji; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="guoxc6ji" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733420137; bh=cfuC4VjJZbJslwembV87HLGJheNWpA6IXa9jHRZu/TI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=guoxc6jiRIqYEGgM6BDygebSsXZ13mk0XDHwVPTvCXJki6yuOI+VMVHt/REiIuCp3 5PH3S7I1rR5ECLEBN+pPHNQKosnLzkuyeTaP0HRnoKS91a4VeTxCdX7qXj6M8oBX9J pPlkZUr/1HRJkQYaW1Zp5F16MRkEAaHCkW1k8zbU= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 05 Dec 2024 18:35:16 +0100 Subject: [PATCH 4/4] btf: Switch module BTF attribute to sysfs_bin_attr_simple_read() Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241205-sysfs-const-bin_attr-simple-v1-4-4a4e4ced71e3@weissschuh.net> References: <20241205-sysfs-const-bin_attr-simple-v1-0-4a4e4ced71e3@weissschuh.net> In-Reply-To: <20241205-sysfs-const-bin_attr-simple-v1-0-4a4e4ced71e3@weissschuh.net> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , Greg Kroah-Hartman , "Rafael J. Wysocki" , Luis Chamberlain , Petr Pavlu , Sami Tolvanen , Daniel Gomez , Armin Wolf , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, platform-driver-x86@vger.kernel.org, bpf@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733420137; l=1356; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=cfuC4VjJZbJslwembV87HLGJheNWpA6IXa9jHRZu/TI=; b=e241/DoQXymqExeN+SMwvZ808XE79ecCrN8XFKqhJnW3U8HuphVENS4R6ai//luSj/YPr30lo NqTPg+Nmf9/Dvw7MuaG3SlMfMc+h0AAu8h+lEG2k3oNOjl5IwrAmm5N X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The generic function from the sysfs core can replace the custom one. Signed-off-by: Thomas Weißschuh Acked-by: Andrii Nakryiko --- kernel/bpf/btf.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index e7a59e6462a9331d0acb17a88a4ebf641509c050..69caa86ae6085dce17e95107c4497d2d8cf81544 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -7870,17 +7870,6 @@ struct btf_module { static LIST_HEAD(btf_modules); static DEFINE_MUTEX(btf_module_mutex); -static ssize_t -btf_module_read(struct file *file, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t len) -{ - const struct btf *btf = bin_attr->private; - - memcpy(buf, btf->data + off, len); - return len; -} - static void purge_cand_cache(struct btf *btf); static int btf_module_notify(struct notifier_block *nb, unsigned long op, @@ -7941,8 +7930,8 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op, attr->attr.name = btf->name; attr->attr.mode = 0444; attr->size = btf->data_size; - attr->private = btf; - attr->read = btf_module_read; + attr->private = btf->data; + attr->read_new = sysfs_bin_attr_simple_read; err = sysfs_create_bin_file(btf_kobj, attr); if (err) {