Linux-mm Archive on 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 2/4] selftests/mm: don't use killall --wait in charge_reserved_hugetlb.sh
Date: Sat, 05 Dec 2026 17:33:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-251770@kernel.org> (raw)
In-Reply-To: <20261205-hugetlb-charge-multi-cgroup-v1-2-e88105afc12a@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] selftests/mm: pgrep -f in cleanup_hugetlb_memory() races with
  exit teardown
- [Medium] selftests/mm: unbounded pgrep -f loop in
  cleanup_hugetlb_memory() can hang
--

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

selftests/mm: don't use killall --wait in charge_reserved_hugetlb.sh

This commit replaces killall -2 --wait with killall -2 followed by a
0.1-second pgrep -f polling loop in cleanup_hugetlb_memory() to reduce the
runtime of charge_reserved_hugetlb.sh.

> diff --git a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
> index 043cc1b1eb5ff..92d6a66e6a846 100755
> --- a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
> +++ b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
> @@ -286,7 +286,10 @@ function cleanup_hugetlb_memory() {
>    local cgroup="$1"
>    if [[ "$(pgrep -f write_to_hugetlbfs)" != "" ]]; then
>      echo killing write_to_hugetlbfs
> -    killall -2 --wait 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
>    fi
>    set -e

[Severity: Medium]
Can polling with pgrep -f return before write_to_hugetlbfs finishes
tearing down, reintroducing the umount EBUSY race fixed by c41a701d18ef
("selftests/mm: fix charge_reserved_hugetlb.sh test")?

pgrep -f reads /proc/<pid>/cmdline, which returns 0 bytes in
get_task_cmdline() as soon as exit_mm() clears current->mm.  Because
write_to_hugetlbfs is longer than the 15-character TASK_COMM_LEN limit,
even falling back to /proc/<pid>/comm (write_to_hugetl) will not match:

CPU0 (write_to_hugetlbfs)           CPU1 (charge_reserved_hugetlb.sh)
do_exit()
  exit_mm()
    current->mm = NULL;
                                    pgrep -f write_to_hugetlbfs
                                      get_task_cmdline() -> 0 bytes
                                    wait_for_hugetlb_memory_to_get_depleted
                                    umount /mnt/huge  <-- EBUSY
  exit_files()
  exit_task_work()
  cgroup_task_exit()

exit_files(), deferred fput()/mntput() in exit_task_work(), and
cgroup_task_exit() all run after exit_mm().  When rsvd.current is
already 0 (e.g. MAP_NORESERVE without populate), umount /mnt/huge or
rmdir of the test cgroup can fail with EBUSY under set -e.

Capturing the target pids before signaling and polling with kill -0
would preserve killall --wait semantics without the 1-second delay.

[Severity: Medium]
Could this unbounded pgrep -f loop hang cleanup_hugetlb_memory() if an
unrelated process matches the command-line pattern?

killall -2 matches only by process name, whereas pgrep -f matches any
command line containing write_to_hugetlbfs (such as an editor open on
write_to_hugetlbfs.c).  Previously, killall --wait only waited on pids
it signaled, so unrelated matches returned immediately.

Without a retry limit like wait_for_file_value() uses, either an
unrelated match or a write_to_hugetlbfs process that does not exit on
SIGINT will spin forever.

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


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

Thread overview: 10+ 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 17:33   ` 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 17:33   ` sashiko-bot [this message]
2026-12-04 17:31 ` [PATCH 3/4] selftests/mm: restore hidden hugetlb reservation scenarios Kurt Lin
2026-12-05 17:33   ` 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 17:33   ` sashiko-bot
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-251770@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox