From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>, bpf <bpf@vger.kernel.org>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>
Subject: Re: [PATCH bpf-next v2 4/4] libbpf: Fix ptr_is_aligned() usages
Date: Thu, 21 Oct 2021 01:02:01 +0200 [thread overview]
Message-ID: <9c925536f10105414327ed70e7e50321061c9204.camel@linux.ibm.com> (raw)
In-Reply-To: <CAEf4BzbQcsz8Y1_MVhnyjCaYx-t-MWBD8xykF3x-UHE9a+X8HQ@mail.gmail.com>
On Wed, 2021-10-20 at 11:44 -0700, Andrii Nakryiko wrote:
> On Wed, Oct 13, 2021 at 9:09 AM Ilya Leoshkevich <iii@linux.ibm.com>
> wrote:
> >
> > Currently ptr_is_aligned() takes size, and not alignment, as a
> > parameter, which may be overly pessimistic e.g. for __i128 on s390,
> > which must be only 8-byte aligned. Fix by using btf__align_of()
> > where
> > possible - one notable exception is ptr_sz, for which there is no
> > corresponding type.
> >
> > Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> > ---
> > tools/lib/bpf/btf_dump.c | 12 +++++-------
> > 1 file changed, 5 insertions(+), 7 deletions(-)
> >
> > diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
> > index 25ce60828e8d..da345520892f 100644
> > --- a/tools/lib/bpf/btf_dump.c
> > +++ b/tools/lib/bpf/btf_dump.c
> > @@ -1657,9 +1657,9 @@ static int
> > btf_dump_base_type_check_zero(struct btf_dump *d,
> > return 0;
> > }
> >
> > -static bool ptr_is_aligned(const void *data, int data_sz)
> > +static bool ptr_is_aligned(const void *data, int alignment)
> > {
> > - return ((uintptr_t)data) % data_sz == 0;
> > + return ((uintptr_t)data) % alignment == 0;
>
> btf__align_of() can return 0 on error and this will be div by 0. I
> think the better approach would be for ptr_is_aligned to accept
> struct
> btf *btf and __u32 type_id, call btf__align_of() based on btf and
> type
> id, handle 0 case pessimistically (assume not aligned).
I thought about this, but it won't cover the ptr_sz case. Maybe we
just need two functions - I'll give it a try tomorrow.
next prev parent reply other threads:[~2021-10-20 23:05 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-13 16:08 [PATCH bpf-next v2 0/4] btf_dump fixes for s390 Ilya Leoshkevich
2021-10-13 16:08 ` [PATCH bpf-next v2 1/4] selftests/bpf: Use cpu_number only on arches that have it Ilya Leoshkevich
2021-10-13 16:09 ` [PATCH bpf-next v2 2/4] libbpf: Fix dumping big-endian bitfields Ilya Leoshkevich
2021-10-13 16:09 ` [PATCH bpf-next v2 3/4] libbpf: Fix dumping non-aligned __int128 Ilya Leoshkevich
2021-10-13 16:09 ` [PATCH bpf-next v2 4/4] libbpf: Fix ptr_is_aligned() usages Ilya Leoshkevich
2021-10-20 18:44 ` Andrii Nakryiko
2021-10-20 23:02 ` Ilya Leoshkevich [this message]
2021-10-20 23:10 ` Andrii Nakryiko
2021-10-21 10:29 ` Ilya Leoshkevich
2021-10-20 18:48 ` [PATCH bpf-next v2 0/4] btf_dump fixes for s390 Andrii Nakryiko
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=9c925536f10105414327ed70e7e50321061c9204.camel@linux.ibm.com \
--to=iii@linux.ibm.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).