All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] pids.sh: Wait for killed tasks to leave the cgroup
@ 2026-11-16  9:36 Avinesh Kumar via ltp
  2026-11-16 12:08 ` [LTP] " linuxtestproject.agent
  2026-11-16 16:24 ` [LTP] [PATCH] " Cyril Hrubis
  0 siblings, 2 replies; 3+ messages in thread
From: Avinesh Kumar via ltp @ 2026-11-16  9:36 UTC (permalink / raw)
  To: ltp

From: Avinesh Kumar <avinesh.kumar@suse.com>

pids_task1 leaves an orphaned child in the cgroup, so "wait" in
stop_pids_tasks_path() can't wait for it, and kill -9 only queues the
signal. The rmdir that follows can fail with EBUSY (unchecked), leaving
the child cgroup behind and breaking the cgroup cleanup:

    rmdir: failed to remove '.../test-3200/child1': Device or resource busy
    tst_cgroup.c:1052: TBROK: unlinkat(..., 'test-3200', AT_REMOVEDIR): EBUSY

Wait for the cgroup to become empty at the end of
stop_pids_tasks_path() and in cleanup() before the test cgroup is removed.

Fixes: dd2b901a9 ("controllers: Update pids.sh to use newer cgroup lib")
Signed-off-by: Avinesh Kumar <avinesh.kumar@suse.com>
---
 testcases/kernel/controllers/pids/pids.sh | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/testcases/kernel/controllers/pids/pids.sh b/testcases/kernel/controllers/pids/pids.sh
index dd27b5616f0c..32434ab0dba0 100755
--- a/testcases/kernel/controllers/pids/pids.sh
+++ b/testcases/kernel/controllers/pids/pids.sh
@@ -32,11 +32,28 @@ OPTIONS
 EOF
 }
 
+wait_cgroup_empty()
+{
+	local delay=1000
+
+	while [ -n "$(cat "$1/$task_list" 2>/dev/null)" ]; do
+		if [ $delay -gt 4000000 ]; then
+			# tst_brk() only warns in cleanup(), so return after it
+			tst_brk TBROK "cgroup $1 is not empty"
+			return
+		fi
+		tst_sleep ${delay}us
+		delay=$((delay * 2))
+	done
+}
+
 cleanup()
 {
 	killall -9 pids_task2 >/dev/null 2>&1
 	killall -9 pids_task1 >/dev/null 2>&1
 
+	[ -n "$testpath" ] && wait_cgroup_empty "$testpath"
+
 	cgroup_cleanup
 }
 
@@ -83,6 +100,10 @@ stop_pids_tasks_path()
 		kill -9 $i 2>/dev/null
 		wait $i 2>/dev/null
 	done
+
+	# wait can't reap the orphaned pids_task1 children, so wait for them
+	# to leave the cgroup instead
+	wait_cgroup_empty "$path"
 }
 
 case1()
-- 
2.56.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] pids.sh: Wait for killed tasks to leave the cgroup
  2026-11-16  9:36 [LTP] [PATCH] pids.sh: Wait for killed tasks to leave the cgroup Avinesh Kumar via ltp
@ 2026-11-16 12:08 ` linuxtestproject.agent
  2026-11-16 16:24 ` [LTP] [PATCH] " Cyril Hrubis
  1 sibling, 0 replies; 3+ messages in thread
From: linuxtestproject.agent @ 2026-11-16 12:08 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi Avinesh,

On Mon Nov 16 10:36:58 2026 +0100, Avinesh Kumar <avinesh.kumar@suse.com> wrote:
> pids.sh: Wait for killed tasks to leave the cgroup

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH] pids.sh: Wait for killed tasks to leave the cgroup
  2026-11-16  9:36 [LTP] [PATCH] pids.sh: Wait for killed tasks to leave the cgroup Avinesh Kumar via ltp
  2026-11-16 12:08 ` [LTP] " linuxtestproject.agent
@ 2026-11-16 16:24 ` Cyril Hrubis
  1 sibling, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2026-11-16 16:24 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi!
> pids_task1 leaves an orphaned child in the cgroup, so "wait" in
> stop_pids_tasks_path() can't wait for it, and kill -9 only queues the
> signal. The rmdir that follows can fail with EBUSY (unchecked), leaving
> the child cgroup behind and breaking the cgroup cleanup:
> 
>     rmdir: failed to remove '.../test-3200/child1': Device or resource busy
>     tst_cgroup.c:1052: TBROK: unlinkat(..., 'test-3200', AT_REMOVEDIR): EBUSY
> 
> Wait for the cgroup to become empty at the end of
> stop_pids_tasks_path() and in cleanup() before the test cgroup is removed.
> 
> Fixes: dd2b901a9 ("controllers: Update pids.sh to use newer cgroup lib")
> Signed-off-by: Avinesh Kumar <avinesh.kumar@suse.com>
> ---
>  testcases/kernel/controllers/pids/pids.sh | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/testcases/kernel/controllers/pids/pids.sh b/testcases/kernel/controllers/pids/pids.sh
> index dd27b5616f0c..32434ab0dba0 100755
> --- a/testcases/kernel/controllers/pids/pids.sh
> +++ b/testcases/kernel/controllers/pids/pids.sh
> @@ -32,11 +32,28 @@ OPTIONS
>  EOF
>  }
>  
> +wait_cgroup_empty()
> +{
> +	local delay=1000
> +
> +	while [ -n "$(cat "$1/$task_list" 2>/dev/null)" ]; do
> +		if [ $delay -gt 4000000 ]; then
> +			# tst_brk() only warns in cleanup(), so return after it
> +			tst_brk TBROK "cgroup $1 is not empty"
> +			return
> +		fi
> +		tst_sleep ${delay}us
> +		delay=$((delay * 2))
> +	done
> +}
> +
>  cleanup()
>  {
>  	killall -9 pids_task2 >/dev/null 2>&1
>  	killall -9 pids_task1 >/dev/null 2>&1
>  
> +	[ -n "$testpath" ] && wait_cgroup_empty "$testpath"
> +
>  	cgroup_cleanup
>  }
>  
> @@ -83,6 +100,10 @@ stop_pids_tasks_path()
>  		kill -9 $i 2>/dev/null
>  		wait $i 2>/dev/null
>  	done
> +
> +	# wait can't reap the orphaned pids_task1 children, so wait for them
> +	# to leave the cgroup instead
> +	wait_cgroup_empty "$path"
>  }

This is working around the real problem. The tst_cg_cleanup() function
in lib/tst_cgroup.c that is eventually called from cgroup_cleanup
(testcases/lib/tst_cgctl.c) makes sure there are no processes left
before unlinking the cgroups.

The ugly part of the shell cgroup library is that it dumps the cgroup
library state into a file and then re-loads it in each command. So my
guess is that there is a bug somewhere in that code.

And I also suppose that it would be easier to rewrite the test into C so
that we can use the library natively than trying to find the problem.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

end of thread, other threads:[~2026-11-16 16:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16  9:36 [LTP] [PATCH] pids.sh: Wait for killed tasks to leave the cgroup Avinesh Kumar via ltp
2026-11-16 12:08 ` [LTP] " linuxtestproject.agent
2026-11-16 16:24 ` [LTP] [PATCH] " Cyril Hrubis

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.