public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf] selftests/bpf: Use -4095 as the bad address for bits iterator
@ 2024-11-05  4:30 Hou Tao
  2024-11-05 20:18 ` Ilya Leoshkevich
  2024-11-05 22:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Hou Tao @ 2024-11-05  4:30 UTC (permalink / raw)
  To: bpf
  Cc: Martin KaFai Lau, Alexei Starovoitov, Andrii Nakryiko,
	Eduard Zingerman, Song Liu, Hao Luo, Yonghong Song,
	Daniel Borkmann, KP Singh, Stanislav Fomichev, Jiri Olsa,
	John Fastabend, Ilya Leoshkevich, Byeonguk Jeong, Yafang Shao,
	houtao1, xukuohai

From: Hou Tao <houtao1@huawei.com>

As reported by Byeonguk, the bad_words test in verifier_bits_iter.c
occasionally fails on s390 host. Quoting Ilya's explanation:

  s390 kernel runs in a completely separate address space, there is no
  user/kernel split at TASK_SIZE. The same address may be valid in both
  the kernel and the user address spaces, there is no way to tell by
  looking at it. The config option related to this property is
  ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE.

  Also, unfortunately, 0 is a valid address in the s390 kernel address
  space.

Fix the issue by using -4096 as the bad address for bits iterator, as
suggested by Ilya. Verify that bpf_iter_bits_new() returns -EINVAL for
NULL address and -EFAULT for bad address.

Fixes: ebafc1e535db ("selftests/bpf: Add three test cases for bits_iter")
Reported-by: Byeonguk Jeong <jungbu2855@gmail.com>
Closes: https://lore.kernel.org/bpf/ZycSXwjH4UTvx-Cn@ub22/
Signed-off-by: Hou Tao <houtao1@huawei.com>
---
 .../selftests/bpf/progs/verifier_bits_iter.c  | 32 ++++++++++++++++---
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/progs/verifier_bits_iter.c b/tools/testing/selftests/bpf/progs/verifier_bits_iter.c
index 156cc278e2fc..7c881bca9af5 100644
--- a/tools/testing/selftests/bpf/progs/verifier_bits_iter.c
+++ b/tools/testing/selftests/bpf/progs/verifier_bits_iter.c
@@ -57,9 +57,15 @@ __description("null pointer")
 __success __retval(0)
 int null_pointer(void)
 {
-	int nr = 0;
+	struct bpf_iter_bits iter;
+	int err, nr = 0;
 	int *bit;
 
+	err = bpf_iter_bits_new(&iter, NULL, 1);
+	bpf_iter_bits_destroy(&iter);
+	if (err != -EINVAL)
+		return 1;
+
 	bpf_for_each(bits, bit, NULL, 1)
 		nr++;
 	return nr;
@@ -194,15 +200,33 @@ __description("bad words")
 __success __retval(0)
 int bad_words(void)
 {
-	void *bad_addr = (void *)(3UL << 30);
-	int nr = 0;
+	void *bad_addr = (void *)-4095;
+	struct bpf_iter_bits iter;
+	volatile int nr;
 	int *bit;
+	int err;
+
+	err = bpf_iter_bits_new(&iter, bad_addr, 1);
+	bpf_iter_bits_destroy(&iter);
+	if (err != -EFAULT)
+		return 1;
 
+	nr = 0;
 	bpf_for_each(bits, bit, bad_addr, 1)
 		nr++;
+	if (nr != 0)
+		return 2;
 
+	err = bpf_iter_bits_new(&iter, bad_addr, 4);
+	bpf_iter_bits_destroy(&iter);
+	if (err != -EFAULT)
+		return 3;
+
+	nr = 0;
 	bpf_for_each(bits, bit, bad_addr, 4)
 		nr++;
+	if (nr != 0)
+		return 4;
 
-	return nr;
+	return 0;
 }
-- 
2.29.2


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

* Re: [PATCH bpf] selftests/bpf: Use -4095 as the bad address for bits iterator
  2024-11-05  4:30 [PATCH bpf] selftests/bpf: Use -4095 as the bad address for bits iterator Hou Tao
@ 2024-11-05 20:18 ` Ilya Leoshkevich
  2024-11-05 22:04   ` Alexei Starovoitov
  2024-11-05 22:10 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Ilya Leoshkevich @ 2024-11-05 20:18 UTC (permalink / raw)
  To: Hou Tao, bpf
  Cc: Martin KaFai Lau, Alexei Starovoitov, Andrii Nakryiko,
	Eduard Zingerman, Song Liu, Hao Luo, Yonghong Song,
	Daniel Borkmann, KP Singh, Stanislav Fomichev, Jiri Olsa,
	John Fastabend, Byeonguk Jeong, Yafang Shao, houtao1, xukuohai

On Tue, 2024-11-05 at 12:30 +0800, Hou Tao wrote:
> From: Hou Tao <houtao1@huawei.com>
> 
> As reported by Byeonguk, the bad_words test in verifier_bits_iter.c
> occasionally fails on s390 host. Quoting Ilya's explanation:
> 
>   s390 kernel runs in a completely separate address space, there is
> no
>   user/kernel split at TASK_SIZE. The same address may be valid in
> both
>   the kernel and the user address spaces, there is no way to tell by
>   looking at it. The config option related to this property is
>   ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE.
> 
>   Also, unfortunately, 0 is a valid address in the s390 kernel
> address
>   space.
> 
> Fix the issue by using -4096 as the bad address for bits iterator, as
> suggested by Ilya. Verify that bpf_iter_bits_new() returns -EINVAL
> for
> NULL address and -EFAULT for bad address.

The code uses -4095, which I think is better, since it's the current
value of MAX_ERRNO, therefore, IS_ERR_VALUE() sees it as an error. It's
also not aligned, which may be an additional reason it may not be
dereferenceable on some CPUs.

Other than this discrepancy in the commit message:

Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>

> Fixes: ebafc1e535db ("selftests/bpf: Add three test cases for
> bits_iter")
> Reported-by: Byeonguk Jeong <jungbu2855@gmail.com>
> Closes: https://lore.kernel.org/bpf/ZycSXwjH4UTvx-Cn@ub22/
> Signed-off-by: Hou Tao <houtao1@huawei.com>
> ---
>  .../selftests/bpf/progs/verifier_bits_iter.c  | 32 ++++++++++++++++-
> --
>  1 file changed, 28 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/progs/verifier_bits_iter.c
> b/tools/testing/selftests/bpf/progs/verifier_bits_iter.c
> index 156cc278e2fc..7c881bca9af5 100644
> --- a/tools/testing/selftests/bpf/progs/verifier_bits_iter.c
> +++ b/tools/testing/selftests/bpf/progs/verifier_bits_iter.c
> @@ -57,9 +57,15 @@ __description("null pointer")
>  __success __retval(0)
>  int null_pointer(void)
>  {
> -	int nr = 0;
> +	struct bpf_iter_bits iter;
> +	int err, nr = 0;
>  	int *bit;
>  
> +	err = bpf_iter_bits_new(&iter, NULL, 1);
> +	bpf_iter_bits_destroy(&iter);
> +	if (err != -EINVAL)
> +		return 1;
> +
>  	bpf_for_each(bits, bit, NULL, 1)
>  		nr++;
>  	return nr;
> @@ -194,15 +200,33 @@ __description("bad words")
>  __success __retval(0)
>  int bad_words(void)
>  {
> -	void *bad_addr = (void *)(3UL << 30);
> -	int nr = 0;
> +	void *bad_addr = (void *)-4095;
> +	struct bpf_iter_bits iter;
> +	volatile int nr;
>  	int *bit;
> +	int err;
> +
> +	err = bpf_iter_bits_new(&iter, bad_addr, 1);
> +	bpf_iter_bits_destroy(&iter);
> +	if (err != -EFAULT)
> +		return 1;
>  
> +	nr = 0;
>  	bpf_for_each(bits, bit, bad_addr, 1)
>  		nr++;
> +	if (nr != 0)
> +		return 2;
>  
> +	err = bpf_iter_bits_new(&iter, bad_addr, 4);
> +	bpf_iter_bits_destroy(&iter);
> +	if (err != -EFAULT)
> +		return 3;
> +
> +	nr = 0;
>  	bpf_for_each(bits, bit, bad_addr, 4)
>  		nr++;
> +	if (nr != 0)
> +		return 4;
>  
> -	return nr;
> +	return 0;
>  }


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

* Re: [PATCH bpf] selftests/bpf: Use -4095 as the bad address for bits iterator
  2024-11-05 20:18 ` Ilya Leoshkevich
@ 2024-11-05 22:04   ` Alexei Starovoitov
  0 siblings, 0 replies; 4+ messages in thread
From: Alexei Starovoitov @ 2024-11-05 22:04 UTC (permalink / raw)
  To: Ilya Leoshkevich
  Cc: Hou Tao, bpf, Martin KaFai Lau, Andrii Nakryiko, Eduard Zingerman,
	Song Liu, Hao Luo, Yonghong Song, Daniel Borkmann, KP Singh,
	Stanislav Fomichev, Jiri Olsa, John Fastabend, Byeonguk Jeong,
	Yafang Shao, Hou Tao, Xu Kuohai

On Tue, Nov 5, 2024 at 12:18 PM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>
> On Tue, 2024-11-05 at 12:30 +0800, Hou Tao wrote:
> > From: Hou Tao <houtao1@huawei.com>
> >
> > As reported by Byeonguk, the bad_words test in verifier_bits_iter.c
> > occasionally fails on s390 host. Quoting Ilya's explanation:
> >
> >   s390 kernel runs in a completely separate address space, there is
> > no
> >   user/kernel split at TASK_SIZE. The same address may be valid in
> > both
> >   the kernel and the user address spaces, there is no way to tell by
> >   looking at it. The config option related to this property is
> >   ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE.
> >
> >   Also, unfortunately, 0 is a valid address in the s390 kernel
> > address
> >   space.
> >
> > Fix the issue by using -4096 as the bad address for bits iterator, as
> > suggested by Ilya. Verify that bpf_iter_bits_new() returns -EINVAL
> > for
> > NULL address and -EFAULT for bad address.
>
> The code uses -4095, which I think is better, since it's the current
> value of MAX_ERRNO, therefore, IS_ERR_VALUE() sees it as an error. It's
> also not aligned, which may be an additional reason it may not be
> dereferenceable on some CPUs.
>
> Other than this discrepancy in the commit message:
>
> Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>

Fixed it up while applying.

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

* Re: [PATCH bpf] selftests/bpf: Use -4095 as the bad address for bits iterator
  2024-11-05  4:30 [PATCH bpf] selftests/bpf: Use -4095 as the bad address for bits iterator Hou Tao
  2024-11-05 20:18 ` Ilya Leoshkevich
@ 2024-11-05 22:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-11-05 22:10 UTC (permalink / raw)
  To: Hou Tao
  Cc: bpf, martin.lau, alexei.starovoitov, andrii, eddyz87, song,
	haoluo, yonghong.song, daniel, kpsingh, sdf, jolsa,
	john.fastabend, iii, jungbu2855, laoar.shao, houtao1, xukuohai

Hello:

This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Tue,  5 Nov 2024 12:30:57 +0800 you wrote:
> From: Hou Tao <houtao1@huawei.com>
> 
> As reported by Byeonguk, the bad_words test in verifier_bits_iter.c
> occasionally fails on s390 host. Quoting Ilya's explanation:
> 
>   s390 kernel runs in a completely separate address space, there is no
>   user/kernel split at TASK_SIZE. The same address may be valid in both
>   the kernel and the user address spaces, there is no way to tell by
>   looking at it. The config option related to this property is
>   ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE.
> 
> [...]

Here is the summary with links:
  - [bpf] selftests/bpf: Use -4095 as the bad address for bits iterator
    https://git.kernel.org/bpf/bpf/c/6801cf7890f2

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] 4+ messages in thread

end of thread, other threads:[~2024-11-05 22:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-05  4:30 [PATCH bpf] selftests/bpf: Use -4095 as the bad address for bits iterator Hou Tao
2024-11-05 20:18 ` Ilya Leoshkevich
2024-11-05 22:04   ` Alexei Starovoitov
2024-11-05 22:10 ` 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