All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] selftests/vm: fix errno handling in mrelease_test
@ 2022-07-04 17:33 Adam Sindelar
  2022-07-05 16:41 ` David Vernet
  0 siblings, 1 reply; 4+ messages in thread
From: Adam Sindelar @ 2022-07-04 17:33 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, Adam Sindelar, Adam Sindelar, David Vernet, kernel-team

mrelease_test should return KSFT_SKIP when process_mrelease is not
defined, but due to a perror call consuming the errno, it returns
KSFT_FAIL.

This patch decides the exit code before calling perror.

Signed-off-by: Adam Sindelar <adam@wowsignal.io>
---
v1->v2: Fixed second instance in the same file

 tools/testing/selftests/vm/mrelease_test.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/vm/mrelease_test.c b/tools/testing/selftests/vm/mrelease_test.c
index 96671c2f7d48..e8b17258579b 100644
--- a/tools/testing/selftests/vm/mrelease_test.c
+++ b/tools/testing/selftests/vm/mrelease_test.c
@@ -100,8 +100,10 @@ int main(void)
 
 	/* Test a wrong pidfd */
 	if (!syscall(__NR_process_mrelease, -1, 0) || errno != EBADF) {
+		/* perror overwrites errno, so this line must be first */
+		res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
 		perror("process_mrelease with wrong pidfd");
-		exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
+		exit(res);
 	}
 
 	/* Start the test with 1MB child memory allocation */
@@ -156,8 +158,9 @@ int main(void)
 	run_negative_tests(pidfd);
 
 	if (kill(pid, SIGKILL)) {
+		res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
 		perror("kill");
-		exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
+		exit(res);
 	}
 
 	success = (syscall(__NR_process_mrelease, pidfd, 0) == 0);
-- 
2.35.1



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

* Re: [PATCH v2] selftests/vm: fix errno handling in mrelease_test
  2022-07-04 17:33 [PATCH v2] selftests/vm: fix errno handling in mrelease_test Adam Sindelar
@ 2022-07-05 16:41 ` David Vernet
  2022-07-05 17:02   ` Suren Baghdasaryan
  0 siblings, 1 reply; 4+ messages in thread
From: David Vernet @ 2022-07-05 16:41 UTC (permalink / raw)
  To: Adam Sindelar; +Cc: Andrew Morton, linux-mm, Adam Sindelar, kernel-team, surenb

On Mon, Jul 04, 2022 at 07:33:51PM +0200, Adam Sindelar wrote:

Thanks for fixing this, Adam.

> mrelease_test should return KSFT_SKIP when process_mrelease is not
> defined, but due to a perror call consuming the errno, it returns
> KSFT_FAIL.
> 
> This patch decides the exit code before calling perror.
> 

We should probably also include a "Fixes" line here (see [0]):

Fixes: 33776141b812 ("selftests: vm: add process_mrelease tests")

[0]: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes

> Signed-off-by: Adam Sindelar <adam@wowsignal.io>
> ---
> v1->v2: Fixed second instance in the same file
> 
>  tools/testing/selftests/vm/mrelease_test.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/vm/mrelease_test.c b/tools/testing/selftests/vm/mrelease_test.c
> index 96671c2f7d48..e8b17258579b 100644
> --- a/tools/testing/selftests/vm/mrelease_test.c
> +++ b/tools/testing/selftests/vm/mrelease_test.c
> @@ -100,8 +100,10 @@ int main(void)
>  
>  	/* Test a wrong pidfd */
>  	if (!syscall(__NR_process_mrelease, -1, 0) || errno != EBADF) {
> +		/* perror overwrites errno, so this line must be first */
> +		res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
>  		perror("process_mrelease with wrong pidfd");
> -		exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
> +		exit(res);
>  	}
>  
>  	/* Start the test with 1MB child memory allocation */
> @@ -156,8 +158,9 @@ int main(void)
>  	run_negative_tests(pidfd);
>  
>  	if (kill(pid, SIGKILL)) {
> +		res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
>  		perror("kill");
> -		exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
> +		exit(res);
>  	}
>  
>  	success = (syscall(__NR_process_mrelease, pidfd, 0) == 0);
> -- 
> 2.35.1
> 

This looks good to me, but it looks like there are a couple of other places
where we're doing the wrong thing, i.e. in run_negative_tests() and after
calling waitpid(). Could you please fix those as well?

Also adding Suren to cc.

- David


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

* Re: [PATCH v2] selftests/vm: fix errno handling in mrelease_test
  2022-07-05 16:41 ` David Vernet
@ 2022-07-05 17:02   ` Suren Baghdasaryan
  2022-07-06  9:55     ` Adam Sindelar
  0 siblings, 1 reply; 4+ messages in thread
From: Suren Baghdasaryan @ 2022-07-05 17:02 UTC (permalink / raw)
  To: David Vernet
  Cc: Adam Sindelar, Andrew Morton, linux-mm, Adam Sindelar, kernel-team

On Tue, Jul 5, 2022 at 9:41 AM David Vernet <void@manifault.com> wrote:
>
> On Mon, Jul 04, 2022 at 07:33:51PM +0200, Adam Sindelar wrote:
>
> Thanks for fixing this, Adam.
>
> > mrelease_test should return KSFT_SKIP when process_mrelease is not
> > defined, but due to a perror call consuming the errno, it returns
> > KSFT_FAIL.
> >
> > This patch decides the exit code before calling perror.
> >
>
> We should probably also include a "Fixes" line here (see [0]):
>
> Fixes: 33776141b812 ("selftests: vm: add process_mrelease tests")
>
> [0]: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
>
> > Signed-off-by: Adam Sindelar <adam@wowsignal.io>
> > ---
> > v1->v2: Fixed second instance in the same file
> >
> >  tools/testing/selftests/vm/mrelease_test.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/testing/selftests/vm/mrelease_test.c b/tools/testing/selftests/vm/mrelease_test.c
> > index 96671c2f7d48..e8b17258579b 100644
> > --- a/tools/testing/selftests/vm/mrelease_test.c
> > +++ b/tools/testing/selftests/vm/mrelease_test.c
> > @@ -100,8 +100,10 @@ int main(void)
> >
> >       /* Test a wrong pidfd */
> >       if (!syscall(__NR_process_mrelease, -1, 0) || errno != EBADF) {
> > +             /* perror overwrites errno, so this line must be first */
> > +             res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
> >               perror("process_mrelease with wrong pidfd");
> > -             exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
> > +             exit(res);
> >       }
> >
> >       /* Start the test with 1MB child memory allocation */
> > @@ -156,8 +158,9 @@ int main(void)
> >       run_negative_tests(pidfd);
> >
> >       if (kill(pid, SIGKILL)) {
> > +             res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
> >               perror("kill");
> > -             exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
> > +             exit(res);
> >       }
> >
> >       success = (syscall(__NR_process_mrelease, pidfd, 0) == 0);
> > --
> > 2.35.1
> >
>
> This looks good to me, but it looks like there are a couple of other places
> where we're doing the wrong thing, i.e. in run_negative_tests() and after
> calling waitpid(). Could you please fix those as well?
>
> Also adding Suren to cc.

Thanks for adding me, David!

The fixes look good but there are 5 places in all this fix is needed:
https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L68
https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L76
https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L103
https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L159
https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L175
Thanks for catching this, Adam!
Suren.

>
> - David


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

* Re: [PATCH v2] selftests/vm: fix errno handling in mrelease_test
  2022-07-05 17:02   ` Suren Baghdasaryan
@ 2022-07-06  9:55     ` Adam Sindelar
  0 siblings, 0 replies; 4+ messages in thread
From: Adam Sindelar @ 2022-07-06  9:55 UTC (permalink / raw)
  To: Suren Baghdasaryan
  Cc: David Vernet, Andrew Morton, linux-mm, Adam Sindelar, kernel-team

On Tue, Jul 05, 2022 at 10:02:08AM -0700, Suren Baghdasaryan wrote:
> On Tue, Jul 5, 2022 at 9:41 AM David Vernet <void@manifault.com> wrote:
> >
> > On Mon, Jul 04, 2022 at 07:33:51PM +0200, Adam Sindelar wrote:
> >
> > Thanks for fixing this, Adam.
> >
> > > mrelease_test should return KSFT_SKIP when process_mrelease is not
> > > defined, but due to a perror call consuming the errno, it returns
> > > KSFT_FAIL.
> > >
> > > This patch decides the exit code before calling perror.
> > >
> >
> > We should probably also include a "Fixes" line here (see [0]):
> >
> > Fixes: 33776141b812 ("selftests: vm: add process_mrelease tests")
> >
> > [0]: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
> >
> > > Signed-off-by: Adam Sindelar <adam@wowsignal.io>
> > > ---
> > > v1->v2: Fixed second instance in the same file
> > >
> > >  tools/testing/selftests/vm/mrelease_test.c | 7 +++++--
> > >  1 file changed, 5 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/tools/testing/selftests/vm/mrelease_test.c b/tools/testing/selftests/vm/mrelease_test.c
> > > index 96671c2f7d48..e8b17258579b 100644
> > > --- a/tools/testing/selftests/vm/mrelease_test.c
> > > +++ b/tools/testing/selftests/vm/mrelease_test.c
> > > @@ -100,8 +100,10 @@ int main(void)
> > >
> > >       /* Test a wrong pidfd */
> > >       if (!syscall(__NR_process_mrelease, -1, 0) || errno != EBADF) {
> > > +             /* perror overwrites errno, so this line must be first */
> > > +             res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
> > >               perror("process_mrelease with wrong pidfd");
> > > -             exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
> > > +             exit(res);
> > >       }
> > >
> > >       /* Start the test with 1MB child memory allocation */
> > > @@ -156,8 +158,9 @@ int main(void)
> > >       run_negative_tests(pidfd);
> > >
> > >       if (kill(pid, SIGKILL)) {
> > > +             res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
> > >               perror("kill");
> > > -             exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
> > > +             exit(res);
> > >       }
> > >
> > >       success = (syscall(__NR_process_mrelease, pidfd, 0) == 0);
> > > --
> > > 2.35.1
> > >
> >
> > This looks good to me, but it looks like there are a couple of other places
> > where we're doing the wrong thing, i.e. in run_negative_tests() and after
> > calling waitpid(). Could you please fix those as well?
> >
> > Also adding Suren to cc.
> 
> Thanks for adding me, David!
> 
> The fixes look good but there are 5 places in all this fix is needed:
> https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L68
> https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L76
> https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L103
> https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L159
> https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L175
> Thanks for catching this, Adam!
> Suren.
> 
> >
> > - David

Ah, well spotted. I've fixed the remaining instances in v3.

-Adam



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

end of thread, other threads:[~2022-07-06  9:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-04 17:33 [PATCH v2] selftests/vm: fix errno handling in mrelease_test Adam Sindelar
2022-07-05 16:41 ` David Vernet
2022-07-05 17:02   ` Suren Baghdasaryan
2022-07-06  9:55     ` Adam Sindelar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.