From: Masami Hiramatsu (Google) <[email protected]>

Commit c5c413534d40 ("selftests/tracing: Have trigger-hist-poll.tc use
sched_process_exit") changed the target event from sched_process_free to
sched_process_exit to avoid timeouts under CONFIG_RCU_LAZY.

However, sched_process_exit fires inside do_exit() before the exiting task
completes teardown and before the parent shell reaps it. When poll unblocks
upon sched_process_exit, checking whether /proc/${BGPID} exists immediately
after poll returns causes a race condition between poll exiting and the
parent shell reaping the child process.

Fix this by waiting for the background sleep process (wait ${BGPID}) and
removing the fragile /proc/${BGPID} check. Checking whether the event was
logged in the trace buffer already verifies that poll did not exit before
the event occurred.

Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/oe-lkp/[email protected]
Fixes: c5c413534d40 ("selftests/tracing: Have trigger-hist-poll.tc use 
sched_process_exit")
Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
---
 .../ftrace/test.d/trigger/trigger-hist-poll.tc     |   14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-poll.tc 
b/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-poll.tc
index 04eb8546fc07..d54d54f9ec77 100644
--- a/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-poll.tc
+++ b/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-poll.tc
@@ -38,11 +38,7 @@ BGPID=$!
 ${POLL} -I -t 4000 ${EVENT}/hist
 echo 0 > tracing_on
 
-if [ -d /proc/${BGPID} ]; then
-  echo "poll exits too soon"
-  kill -KILL ${BGPID} ||:
-  exit_fail
-fi
+wait ${BGPID} 2>/dev/null ||:
 
 if ! grep -qw "sleep" trace; then
   echo "poll exits before event happens"
@@ -60,11 +56,7 @@ BGPID=$!
 ${POLL} -P -t 4000 ${EVENT}/hist
 echo 0 > tracing_on
 
-if [ -d /proc/${BGPID} ]; then
-  echo "poll exits too soon"
-  kill -KILL ${BGPID} ||:
-  exit_fail
-fi
+wait ${BGPID} 2>/dev/null ||:
 
 if ! grep -qw "sleep" trace; then
   echo "poll exits before event happens"
@@ -72,3 +64,5 @@ if ! grep -qw "sleep" trace; then
 fi
 
 exit_pass
+
+


Reply via email to