From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>,
Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>,
bpf <bpf@vger.kernel.org>, LKML <linux-kernel@vger.kernel.org>,
Christian Brauner <brauner@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH] btf: Use BIN_ATTR_SIMPLE_RO() to define vmlinux attribute
Date: Wed, 27 Nov 2024 16:22:12 +0100 [thread overview]
Message-ID: <998be751-3e7d-46e7-896e-6fd089f5dfa5@t-8ch.de> (raw)
In-Reply-To: <CAADnVQLV=7Mt+DTX84u_4kP_pVNhbyHMvL29BPcFQjOj7RpM7A@mail.gmail.com>
On 2024-11-26 17:52:29-0800, Alexei Starovoitov wrote:
> On Fri, Nov 22, 2024 at 4:57 AM Thomas Weißschuh <linux@weissschuh.net> wrote:
> >
> > 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@weissschuh.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);
>
> To be honest I really don't like when code is hidden by macros like this.
> Looks like you guys already managed to sprinkle it in a few places.
>
> btf_vmlinux_read() can be replaced with sysfs_bin_attr_simple_read().
> This part is fine, but macro pls dont.
> It doesn't help readability.
> imo mode = 0444 vs mode = 0400 is easier to understand
> instead of _RO vs _ADMIN_RO suffix.
I'm fine with either solution.
My patch is motivated by my current effort to constify 'struct
bin_attribute' throughout the kernel.
With the macro I only have to touch this location once,
without it twice.
If we go with a plain sysfs_bin_attr_simple_read() please let me do the
patch in another series I have prepared, to be submitted after 6.13-rc1.
> __ro_after_init should be a part of it, at least.
I see where you are coming from, it would break the pattern with all the
other attribute macros however.
> I'd like to hear what other maintainers think about
> such obfuscation.
Ack.
prev parent reply other threads:[~2024-11-27 15:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-22 12:56 Thomas Weißschuh
2024-11-26 21:37 ` Andrii Nakryiko
2024-11-26 21:42 ` Thomas Weißschuh
2024-11-26 21:57 ` Andrii Nakryiko
2024-11-27 1:52 ` Alexei Starovoitov
2024-11-27 15:22 ` Thomas Weißschuh [this message]
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=998be751-3e7d-46e7-896e-6fd089f5dfa5@t-8ch.de \
--to=linux@weissschuh.net \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=yonghong.song@linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®