lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241122-sysfs-const-bin_attr-bpf-v1-1-823aea399b53@weissschuh.net>
Date: Fri, 22 Nov 2024 13:56:41 +0100
From: Thomas Weißschuh <linux@...ssschuh.net>
To: Alexei Starovoitov <ast@...nel.org>, 
 Daniel Borkmann <daniel@...earbox.net>, Andrii Nakryiko <andrii@...nel.org>, 
 Martin KaFai Lau <martin.lau@...ux.dev>, 
 Eduard Zingerman <eddyz87@...il.com>, Song Liu <song@...nel.org>, 
 Yonghong Song <yonghong.song@...ux.dev>, 
 John Fastabend <john.fastabend@...il.com>, KP Singh <kpsingh@...nel.org>, 
 Stanislav Fomichev <sdf@...ichev.me>, Hao Luo <haoluo@...gle.com>, 
 Jiri Olsa <jolsa@...nel.org>
Cc: bpf@...r.kernel.org, linux-kernel@...r.kernel.org, 
 Thomas Weißschuh <linux@...ssschuh.net>
Subject: [PATCH] btf: Use BIN_ATTR_SIMPLE_RO() to define vmlinux attribute

The usage of the macro allows to remove the custom handler function,
saving some memory. Additionally the code is easier to read.

Signed-off-by: Thomas Weißschuh <linux@...ssschuh.net>
---
Something similar can be done to btf_module_read() in kernel/bpf/btf.c.
But doing it here and now would lead to some conflicts with some other
sysfs refactorings I'm doing. It will be part of a future series.
---
 kernel/bpf/sysfs_btf.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/kernel/bpf/sysfs_btf.c b/kernel/bpf/sysfs_btf.c
index fedb54c94cdb830a4890d33677dcc5a6e236c13f..a24381f933d0b80b11116d05463c35e9fa66acb1 100644
--- a/kernel/bpf/sysfs_btf.c
+++ b/kernel/bpf/sysfs_btf.c
@@ -12,34 +12,23 @@
 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,
-};
+static __ro_after_init BIN_ATTR_SIMPLE_RO(vmlinux);
 
 struct kobject *btf_kobj;
 
 static int __init btf_vmlinux_init(void)
 {
-	bin_attr_btf_vmlinux.size = __stop_BTF - __start_BTF;
+	bin_attr_vmlinux.private = __start_BTF;
+	bin_attr_vmlinux.size = __stop_BTF - __start_BTF;
 
-	if (bin_attr_btf_vmlinux.size == 0)
+	if (bin_attr_vmlinux.size == 0)
 		return 0;
 
 	btf_kobj = kobject_create_and_add("btf", kernel_kobj);
 	if (!btf_kobj)
 		return -ENOMEM;
 
-	return sysfs_create_bin_file(btf_kobj, &bin_attr_btf_vmlinux);
+	return sysfs_create_bin_file(btf_kobj, &bin_attr_vmlinux);
 }
 
 subsys_initcall(btf_vmlinux_init);

---
base-commit: 28eb75e178d389d325f1666e422bc13bbbb9804c
change-id: 20241122-sysfs-const-bin_attr-bpf-737286bb9f27

Best regards,
-- 
Thomas Weißschuh <linux@...ssschuh.net>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ