linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] userfaultfd: selftests: infinite loop in faulting_process
@ 2022-06-13 23:33 Edward Liaw
  2022-06-14 18:31 ` Axel Rasmussen
  0 siblings, 1 reply; 2+ messages in thread
From: Edward Liaw @ 2022-06-13 23:33 UTC (permalink / raw)
  To: shuah
  Cc: axelrasmussen, akpm, linux-kernel, linux-kselftest, kernel-team,
	Edward Liaw

On Android this test is getting stuck in an infinite loop due to
indeterminate behavior:

The local variables steps and signalled were being reset to 1 and 0
respectively after every jump back to sigsetjmp by siglongjmp in the
signal handler. The test was incrementing them and expecting them to
retain their incremented values. The documentation for siglongjmp says:

All accessible objects have values as of the time sigsetjmp() was
called, except that the values of objects of automatic storage duration
which are local to the function containing the invocation of the
corresponding sigsetjmp() which do not have volatile-qualified type and
which are changed between the sigsetjmp() invocation and siglongjmp()
call are indeterminate.

Tagging steps and signalled with volatile enabled the test to pass.

Signed-off-by: Edward Liaw <edliaw@google.com>
---
 tools/testing/selftests/vm/userfaultfd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
index 0bdfc1955229..2b2a68722ae1 100644
--- a/tools/testing/selftests/vm/userfaultfd.c
+++ b/tools/testing/selftests/vm/userfaultfd.c
@@ -931,7 +931,7 @@ static int faulting_process(int signal_test)
 	unsigned long split_nr_pages;
 	unsigned long lastnr;
 	struct sigaction act;
-	unsigned long signalled = 0;
+	volatile unsigned long signalled = 0;
 
 	split_nr_pages = (nr_pages + 1) / 2;
 
@@ -946,7 +946,7 @@ static int faulting_process(int signal_test)
 	}
 
 	for (nr = 0; nr < split_nr_pages; nr++) {
-		int steps = 1;
+		volatile int steps = 1;
 		unsigned long offset = nr * page_size;
 
 		if (signal_test) {
-- 
2.36.1.476.g0c4daa206d-goog


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

* Re: [PATCH v1] userfaultfd: selftests: infinite loop in faulting_process
  2022-06-13 23:33 [PATCH v1] userfaultfd: selftests: infinite loop in faulting_process Edward Liaw
@ 2022-06-14 18:31 ` Axel Rasmussen
  0 siblings, 0 replies; 2+ messages in thread
From: Axel Rasmussen @ 2022-06-14 18:31 UTC (permalink / raw)
  To: Edward Liaw; +Cc: Shuah Khan, Andrew Morton, LKML, Linuxkselftest, kernel-team

Reviewed-by: Axel Rasmussen <axelrasmussen@google.com>

On Mon, Jun 13, 2022 at 4:33 PM Edward Liaw <edliaw@google.com> wrote:
>
> On Android this test is getting stuck in an infinite loop due to
> indeterminate behavior:
>
> The local variables steps and signalled were being reset to 1 and 0
> respectively after every jump back to sigsetjmp by siglongjmp in the
> signal handler. The test was incrementing them and expecting them to
> retain their incremented values. The documentation for siglongjmp says:
>
> All accessible objects have values as of the time sigsetjmp() was
> called, except that the values of objects of automatic storage duration
> which are local to the function containing the invocation of the
> corresponding sigsetjmp() which do not have volatile-qualified type and
> which are changed between the sigsetjmp() invocation and siglongjmp()
> call are indeterminate.
>
> Tagging steps and signalled with volatile enabled the test to pass.
>
> Signed-off-by: Edward Liaw <edliaw@google.com>
> ---
>  tools/testing/selftests/vm/userfaultfd.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
> index 0bdfc1955229..2b2a68722ae1 100644
> --- a/tools/testing/selftests/vm/userfaultfd.c
> +++ b/tools/testing/selftests/vm/userfaultfd.c
> @@ -931,7 +931,7 @@ static int faulting_process(int signal_test)
>         unsigned long split_nr_pages;
>         unsigned long lastnr;
>         struct sigaction act;
> -       unsigned long signalled = 0;
> +       volatile unsigned long signalled = 0;
>
>         split_nr_pages = (nr_pages + 1) / 2;
>
> @@ -946,7 +946,7 @@ static int faulting_process(int signal_test)
>         }
>
>         for (nr = 0; nr < split_nr_pages; nr++) {
> -               int steps = 1;
> +               volatile int steps = 1;
>                 unsigned long offset = nr * page_size;
>
>                 if (signal_test) {
> --
> 2.36.1.476.g0c4daa206d-goog
>

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

end of thread, other threads:[~2022-06-14 18:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-13 23:33 [PATCH v1] userfaultfd: selftests: infinite loop in faulting_process Edward Liaw
2022-06-14 18:31 ` Axel Rasmussen

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