bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v3 0/1] btf_dump fixes for s390
@ 2021-10-21 10:46 Ilya Leoshkevich
  2021-10-21 10:46 ` [PATCH bpf-next v3 1/1] libbpf: Fix ptr_is_aligned() usages Ilya Leoshkevich
  2021-10-21 23:00 ` [PATCH bpf-next v3 0/1] btf_dump fixes for s390 patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Ilya Leoshkevich @ 2021-10-21 10:46 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: bpf, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich

v2: https://lore.kernel.org/bpf/20211013160902.428340-1-iii@linux.ibm.com/
v2 -> v3:
- Drop committed patches.
- Handle potential division by zero when using btf__align_of(). Use
  btf__align_of() in btf_dump_ptr_data() instead of the direct ptr_sz
  access: although it's slightly slower, the result is the same and the
  resulting code is more uniform.

v1: https://lore.kernel.org/bpf/20211012023218.399568-1-iii@linux.ibm.com/
v1 -> v2:
- Remove redundant local variables, use t->size directly instead.
- Add btf__align_of() patch.

Ilya Leoshkevich (1):
  libbpf: Fix ptr_is_aligned() usages

 tools/lib/bpf/btf_dump.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH bpf-next v3 1/1] libbpf: Fix ptr_is_aligned() usages
  2021-10-21 10:46 [PATCH bpf-next v3 0/1] btf_dump fixes for s390 Ilya Leoshkevich
@ 2021-10-21 10:46 ` Ilya Leoshkevich
  2021-10-21 23:00 ` [PATCH bpf-next v3 0/1] btf_dump fixes for s390 patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Ilya Leoshkevich @ 2021-10-21 10:46 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: bpf, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich

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().

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 tools/lib/bpf/btf_dump.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index e98c201f29b5..e9e5801ece4c 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -1657,9 +1657,15 @@ 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 struct btf *btf, __u32 type_id,
+			   const void *data)
 {
-	return ((uintptr_t)data) % data_sz == 0;
+	int alignment = btf__align_of(btf, type_id);
+
+	if (alignment == 0)
+		return false;
+
+	return ((uintptr_t)data) % alignment == 0;
 }
 
 static int btf_dump_int_data(struct btf_dump *d,
@@ -1681,7 +1687,7 @@ static int btf_dump_int_data(struct btf_dump *d,
 	/* handle packed int data - accesses of integers not aligned on
 	 * int boundaries can cause problems on some platforms.
 	 */
-	if (!ptr_is_aligned(data, sz)) {
+	if (!ptr_is_aligned(d->btf, type_id, data)) {
 		memcpy(buf, data, sz);
 		data = buf;
 	}
@@ -1770,7 +1776,7 @@ static int btf_dump_float_data(struct btf_dump *d,
 	int sz = t->size;
 
 	/* handle unaligned data; copy to local union */
-	if (!ptr_is_aligned(data, sz)) {
+	if (!ptr_is_aligned(d->btf, type_id, data)) {
 		memcpy(&fl, data, sz);
 		flp = &fl;
 	}
@@ -1933,7 +1939,7 @@ static int btf_dump_ptr_data(struct btf_dump *d,
 			      __u32 id,
 			      const void *data)
 {
-	if (ptr_is_aligned(data, d->ptr_sz) && d->ptr_sz == sizeof(void *)) {
+	if (ptr_is_aligned(d->btf, id, data) && d->ptr_sz == sizeof(void *)) {
 		btf_dump_type_values(d, "%p", *(void **)data);
 	} else {
 		union ptr_data pt;
@@ -1953,10 +1959,8 @@ static int btf_dump_get_enum_value(struct btf_dump *d,
 				   __u32 id,
 				   __s64 *value)
 {
-	int sz = t->size;
-
 	/* handle unaligned enum value */
-	if (!ptr_is_aligned(data, sz)) {
+	if (!ptr_is_aligned(d->btf, id, data)) {
 		__u64 val;
 		int err;
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next v3 0/1] btf_dump fixes for s390
  2021-10-21 10:46 [PATCH bpf-next v3 0/1] btf_dump fixes for s390 Ilya Leoshkevich
  2021-10-21 10:46 ` [PATCH bpf-next v3 1/1] libbpf: Fix ptr_is_aligned() usages Ilya Leoshkevich
@ 2021-10-21 23:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-10-21 23:00 UTC (permalink / raw)
  To: Ilya Leoshkevich; +Cc: ast, daniel, andrii.nakryiko, bpf, hca, gor

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Thu, 21 Oct 2021 12:46:57 +0200 you wrote:
> v2: https://lore.kernel.org/bpf/20211013160902.428340-1-iii@linux.ibm.com/
> v2 -> v3:
> - Drop committed patches.
> - Handle potential division by zero when using btf__align_of(). Use
>   btf__align_of() in btf_dump_ptr_data() instead of the direct ptr_sz
>   access: although it's slightly slower, the result is the same and the
>   resulting code is more uniform.
> 
> [...]

Here is the summary with links:
  - [bpf-next,v3,1/1] libbpf: Fix ptr_is_aligned() usages
    https://git.kernel.org/bpf/bpf-next/c/632f96d2652e

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-21 23:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-21 10:46 [PATCH bpf-next v3 0/1] btf_dump fixes for s390 Ilya Leoshkevich
2021-10-21 10:46 ` [PATCH bpf-next v3 1/1] libbpf: Fix ptr_is_aligned() usages Ilya Leoshkevich
2021-10-21 23:00 ` [PATCH bpf-next v3 0/1] btf_dump fixes for s390 patchwork-bot+netdevbpf

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).