* [PATCH] selftests/proc: proc-empty-vm: wait for child's SIGSEGV instead of sleep(1)
@ 2026-10-23 18:34 Drif Abdelmalek Mohamed Said
2026-11-01 12:57 ` Alexey Dobriyan
2026-11-02 4:31 ` Andrew Morton
0 siblings, 2 replies; 3+ messages in thread
From: Drif Abdelmalek Mohamed Said @ 2026-10-23 18:34 UTC (permalink / raw)
To: Alexey Dobriyan, Andrew Morton, Shuah Khan
Cc: linux-fsdevel, linux-kernel, Drif Abdelmalek Mohamed Said
The test had a TODO asking for a reliable way to know when the child's
munmap() has finished, and used sleep(1) in the meantime.
Unmapping the whole address space leaves the child with no code to run,
so it segfaults. Since it is traced, the SIGSEGV stop is reported to
the parent through waitpid(), which is exactly the signal the TODO
wanted. Wait for it there and drop the sleep and the TODO.
The stop is now consumed up front, so SIGKILL the child before the
final reap.
Fixes: 5bc73bb3451b ("proc: test how it holds up with mapping'less process")
Signed-off-by: Drif Abdelmalek Mohamed Said <drifabdelmalekmohamedsaid@gmail.com>
---
tools/testing/selftests/proc/proc-empty-vm.c | 24 ++++++++++++--------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/proc/proc-empty-vm.c b/tools/testing/selftests/proc/proc-empty-vm.c
index b3f898aab4ab..cf65313a25f5 100644
--- a/tools/testing/selftests/proc/proc-empty-vm.c
+++ b/tools/testing/selftests/proc/proc-empty-vm.c
@@ -41,6 +41,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
+#include <signal.h>
#ifdef __amd64__
#define TEST_VSYSCALL
@@ -500,13 +501,18 @@ int main(void)
#endif
return EXIT_FAILURE;
} else {
- /*
- * TODO find reliable way to signal parent that munmap(2) completed.
- * Child can't do it directly because it effectively doesn't exist
- * anymore. Looking at child's VM files isn't 100% reliable either:
- * due to a bug they may not become empty or empty-like.
- */
- sleep(1);
+ int wstatus;
+ pid_t p;
+
+ for (;;) {
+ p = waitpid(pid, &wstatus, 0);
+ if (p == -1 && errno == EINTR)
+ continue;
+ break;
+ }
+ assert(p == pid);
+ assert(WIFSTOPPED(wstatus));
+ assert(WSTOPSIG(wstatus) == SIGSEGV);
if (rv == EXIT_SUCCESS) {
rv = test_proc_pid_maps(pid);
@@ -525,10 +531,8 @@ int main(void)
}
/* Cut the rope. */
- int wstatus;
+ kill(pid, SIGKILL);
waitpid(pid, &wstatus, 0);
- assert(WIFSTOPPED(wstatus));
- assert(WSTOPSIG(wstatus) == SIGSEGV);
}
return rv;
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/proc: proc-empty-vm: wait for child's SIGSEGV instead of sleep(1)
2026-10-23 18:34 [PATCH] selftests/proc: proc-empty-vm: wait for child's SIGSEGV instead of sleep(1) Drif Abdelmalek Mohamed Said
@ 2026-11-01 12:57 ` Alexey Dobriyan
2026-11-02 4:31 ` Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: Alexey Dobriyan @ 2026-11-01 12:57 UTC (permalink / raw)
To: Drif Abdelmalek Mohamed Said
Cc: Andrew Morton, Shuah Khan, linux-fsdevel, linux-kernel
On Fri, Oct 23, 2026 at 07:34:33PM +0100, Drif Abdelmalek Mohamed Said wrote:
> The test had a TODO asking for a reliable way to know when the child's
> munmap() has finished, and used sleep(1) in the meantime.
>
> Unmapping the whole address space leaves the child with no code to run,
> so it segfaults. Since it is traced, the SIGSEGV stop is reported to
> the parent through waitpid(), which is exactly the signal the TODO
> wanted. Wait for it there and drop the sleep and the TODO.
>
> The stop is now consumed up front, so SIGKILL the child before the
> final reap.
OK I recall what's going on here.
The only thing to worry is child pid reuse but child is under ptrace
so it should be fine.
Reviewed-by: Alexey Dobriyan <adobriyan@gmail.com>
> + for (;;) {
> + p = waitpid(pid, &wstatus, 0);
> + if (p == -1 && errno == EINTR)
> + continue;
> + break;
> + }
do/while EINTR loops are shorter:
do {
rv = f();
} while (rv == -1 && errno == EINTR);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/proc: proc-empty-vm: wait for child's SIGSEGV instead of sleep(1)
2026-10-23 18:34 [PATCH] selftests/proc: proc-empty-vm: wait for child's SIGSEGV instead of sleep(1) Drif Abdelmalek Mohamed Said
2026-11-01 12:57 ` Alexey Dobriyan
@ 2026-11-02 4:31 ` Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2026-11-02 4:31 UTC (permalink / raw)
To: Drif Abdelmalek Mohamed Said
Cc: Alexey Dobriyan, Shuah Khan, linux-fsdevel, linux-kernel
On Fri, 23 Oct 2026 19:34:33 +0100 Drif Abdelmalek Mohamed Said <drifabdelmalekmohamedsaid@gmail.com> wrote:
> The test had a TODO asking for a reliable way to know when the child's
> munmap() has finished, and used sleep(1) in the meantime.
>
> Unmapping the whole address space leaves the child with no code to run,
> so it segfaults. Since it is traced, the SIGSEGV stop is reported to
> the parent through waitpid(), which is exactly the signal the TODO
> wanted. Wait for it there and drop the sleep and the TODO.
>
> The stop is now consumed up front, so SIGKILL the child before the
> final reap.
Thanks, checks out.
My review toy claims
: Separately, tools/testing/selftests/ptrace/vmaccess.c has similar
: sleep-based synchronization. A delayed child can make its attach test
: fail spuriously, or let its vmaccess test run before the intended
: blocked-exec state. That deserves a separate fix.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-02 4:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-23 18:34 [PATCH] selftests/proc: proc-empty-vm: wait for child's SIGSEGV instead of sleep(1) Drif Abdelmalek Mohamed Said
2026-11-01 12:57 ` Alexey Dobriyan
2026-11-02 4:31 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®