All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kurt Lin" <lylin1023@gmail.com>,
	"Andrew Morton" <akpm@linux-foundation.org>
Cc: "David Hildenbrand" <david@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Michal Hocko" <mhocko@suse.com>, "Shuah Khan" <shuah@kernel.org>,
	"Mina Almasry" <almasrymina@google.com>,
	"Sayali Patil" <sayalip@linux.ibm.com>, "Zi Yan" <ziy@nvidia.com>,
	"Song Hu" <husong@kylinos.cn>,
	linux-mm@kvack.org, "Li Wang" <li.wang@linux.dev>
Subject: Re: [PATCH 4/4] selftests/mm: fix and enable the multiple cgroups hugetlb tests
Date: Sat, 05 Dec 2026 17:33:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-251772@kernel.org> (raw)
In-Reply-To: <20261205-hugetlb-charge-multi-cgroup-v1-4-e88105afc12a@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] selftests/mm: run_multiple_cgroup_test() leaks writers on
  failure exit
- [Low] selftests/mm: cleanup_hugetlb_memory() wait loop races with
  umount and rmdir
--

commit c995fb54b97ee185014857c42d52be9482317eb8
Author: Kurt Lin <lylin1023@gmail.com>

selftests/mm: fix and enable the multiple cgroups hugetlb tests

This commit converts page counts to bytes in run_multiple_cgroup_test()
and its assertions, fixes its local path variable declarations, passes
both test cgroups to cleanup_hugetlb_memory(), and removes the continue
that skipped the multiple cgroups test.

> diff --git a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
> index e43b7bc1ad1b9..ca84c353e28fe 100755
> --- a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
> +++ b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
> @@ -283,14 +283,16 @@ function write_hugetlbfs_and_get_usage() {
>  
>  function cleanup_hugetlb_memory() {
>    set +e
> -  local cgroup="$1"
> +  local cgroup
>    if [[ "$(pgrep -f write_to_hugetlbfs)" != "" ]]; then
>      echo killing write_to_hugetlbfs
>      killall -2 write_to_hugetlbfs
>      while pgrep -f write_to_hugetlbfs > /dev/null; do
>        sleep 0.1
>      done
> -    wait_for_hugetlb_memory_to_get_depleted $cgroup
> +    for cgroup in "$@"; do
> +      wait_for_hugetlb_memory_to_get_depleted $cgroup
> +    done
>    fi
>    set -e

[Severity: Low]
Can the pgrep wait loop in cleanup_hugetlb_memory() exit before the
writer finishes closing files and detaching from its cgroup?

In do_exit(), exit_mm() clears tsk->mm and uncharges hugepages before
exit_files() closes /mnt/huge descriptors and before
do_cgroup_task_dead() removes the task from its cgroup:

cleanup_hugetlb_memory()            write_to_hugetlbfs (do_exit)
  killall -2 write_to_hugetlbfs
                                      exit_mm()
                                        clears tsk->mm; uncharges pages
  pgrep -f write_to_hugetlbfs -> 1
  wait_for_hugetlb_memory_... -> 0
  umount /mnt/huge  <-- EBUSY
                                      exit_files()
                                      exit_notify()
                                      do_cgroup_task_dead()

Once tsk->mm is cleared, /proc/<pid>/cmdline is empty and comm is
truncated to 15 characters, so pgrep -f write_to_hugetlbfs stops
matching.  umount /mnt/huge or rmdir in cleanup() can then fail with
EBUSY under set -e.

write_hugetlb_memory.sh also writes its own PID to cgroup.procs and
runs write_to_hugetlbfs without exec, so rmdir can hit EBUSY while the
wrapper shell is still exiting.  Waiting for the background PIDs or for
cgroup.procs to empty before unmounting would close both races.

[ ... ]

> @@ -418,7 +418,7 @@ function run_multiple_cgroup_test() {
>    expect_equal "$reservation_usage_before_second_write" \
>      "$(cat $cgroup1_reservation_usage)" "Reservation usage changed."
>  
> -  cleanup_hugetlb_memory
> +  cleanup_hugetlb_memory "hugetlb_cgroup_test1" "hugetlb_cgroup_test2"

[Severity: Low]
Does run_multiple_cgroup_test() leak background write_to_hugetlbfs
processes when expect_equal() fails?

On failure, expect_equal() calls cleanup() and exits before
cleanup_hugetlb_memory() stops the sleeping writers.  cleanup() does
not kill write_to_hugetlbfs, so umount /mnt/huge and rmdir fail with
EBUSY under set -e, leaking writers, hugepages, mounts, and cgroups.

The same leak happens if the second write_hugetlbfs_and_get_usage()
detects a dead writer and calls cleanup() while the first writer is
still alive.  Checking cgroup1 usage after cleanup_hugetlb_memory(), or
killing lingering writers in cleanup(), would avoid leaving them behind.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-hugetlb-charge-multi-cgroup-v1-0-e88105afc12a@gmail.com?part=4


  parent reply	other threads:[~2026-12-05 17:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 17:31 [PATCH 0/4] selftests/mm: run all hugetlb cgroup reservation tests Kurt Lin
2026-12-04 17:31 ` [PATCH 1/4] selftests/mm: don't wait for a hugetlb reservation that is expected to fail Kurt Lin
2026-12-05  8:35   ` + selftests-mm-dont-wait-for-a-hugetlb-reservation-that-is-expected-to-fail.patch added to mm-new branch Andrew Morton
2026-12-05 17:33   ` [PATCH 1/4] selftests/mm: don't wait for a hugetlb reservation that is expected to fail sashiko-bot
2026-12-04 17:31 ` [PATCH 2/4] selftests/mm: don't use killall --wait in charge_reserved_hugetlb.sh Kurt Lin
2026-12-05  8:35   ` + selftests-mm-dont-use-killall-wait-in-charge_reserved_hugetlbsh.patch added to mm-new branch Andrew Morton
2026-12-05 17:33   ` [PATCH 2/4] selftests/mm: don't use killall --wait in charge_reserved_hugetlb.sh sashiko-bot
2026-12-04 17:31 ` [PATCH 3/4] selftests/mm: restore hidden hugetlb reservation scenarios Kurt Lin
2026-12-05  8:35   ` + selftests-mm-restore-hidden-hugetlb-reservation-scenarios.patch added to mm-new branch Andrew Morton
2026-12-05 17:33   ` [PATCH 3/4] selftests/mm: restore hidden hugetlb reservation scenarios sashiko-bot
2026-12-04 17:32 ` [PATCH 4/4] selftests/mm: fix and enable the multiple cgroups hugetlb tests Kurt Lin
2026-12-05  8:35   ` + selftests-mm-fix-and-enable-the-multiple-cgroups-hugetlb-tests.patch added to mm-new branch Andrew Morton
2026-12-05 17:33   ` sashiko-bot [this message]
2026-12-05  8:33 ` [PATCH 0/4] selftests/mm: run all hugetlb cgroup reservation tests Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-251772@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=almasrymina@google.com \
    --cc=david@kernel.org \
    --cc=husong@kylinos.cn \
    --cc=li.wang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=lylin1023@gmail.com \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sayalip@linux.ibm.com \
    --cc=shuah@kernel.org \
    --cc=vbabka@kernel.org \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.