From: Balbir Singh <balbirs@nvidia.com>
To: Hongfu Li <lihongfu@kylinos.cn>,
jgg@ziepe.ca, leon@kernel.org, akpm@linux-foundation.org,
david@kernel.org, ljs@kernel.org, liam@infradead.org,
vbabka@kernel.org, rppt@kernel.org, surenb@google.com,
mhocko@suse.com, shuah@kernel.org
Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, hongfu.li@linux.dev,
SJ Park <sj@kernel.org>
Subject: Re: [PATCH v2] selftests/mm: Fix memleak in migration benchmark
Date: Tue, 14 Jul 2026 20:55:09 +1000 [thread overview]
Message-ID: <7f600e7a-e7b6-47a0-af54-05da2bea9cc7@nvidia.com> (raw)
In-Reply-To: <20260709081843.1451202-1-lihongfu@kylinos.cn>
On 7/9/26 6:18 PM, Hongfu Li wrote:
> Several early return paths in run_migration_benchmark() skip
> hmm_buffer_free(), leaking the buffer. Replace with a single cleanup
> label.
>
> Fixes: 271a7b2e3c13 ("selftests/mm/hmm-tests: new throughput tests including THP")
> Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
> Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
> Reviewed-by: SJ Park <sj@kernel.org>
> ---
> v2:
> - Set buffer->ptr to NULL on mmap failure to avoid passing MAP_FAILED
> to munmap() in hmm_buffer_free()
> - Drop the redundant "/* Cleanup */" comment
> - Add Fixes tag for the commit that introduced the leak
> - Collect Reviewed-by tags from David Hildenbrand and SJ Park
> ---
> tools/testing/selftests/mm/hmm-tests.c | 21 ++++++++++++---------
> 1 file changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
> index e4c49699f3f7..402c6f6f5f09 100644
> --- a/tools/testing/selftests/mm/hmm-tests.c
> +++ b/tools/testing/selftests/mm/hmm-tests.c
> @@ -2828,8 +2828,11 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
> buffer->ptr = mmap(NULL, buffer_size, PROT_READ | PROT_WRITE,
> MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>
> - if (buffer->ptr == MAP_FAILED)
> - return -1;
> + if (buffer->ptr == MAP_FAILED) {
> + buffer->ptr = NULL;
> + ret = -1;
> + goto cleanup;
> + }
>
> /* Apply THP hint if requested */
> if (use_thp)
> @@ -2838,7 +2841,7 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
> ret = madvise(buffer->ptr, buffer_size, MADV_NOHUGEPAGE);
>
> if (ret)
> - return ret;
> + goto cleanup;
>
> /* Initialize memory to make sure pages are allocated */
> ptr = (int *)buffer->ptr;
> @@ -2848,11 +2851,11 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
> /* Warmup iteration */
> ret = hmm_migrate_sys_to_dev(fd, buffer, npages);
> if (ret)
> - return ret;
> + goto cleanup;
>
> ret = hmm_migrate_dev_to_sys(fd, buffer, npages);
> if (ret)
> - return ret;
> + goto cleanup;
>
> /* Benchmark iterations */
> for (i = 0; i < iterations; i++) {
> @@ -2861,7 +2864,7 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
>
> ret = hmm_migrate_sys_to_dev(fd, buffer, npages);
> if (ret)
> - return ret;
> + goto cleanup;
>
> end = get_time_ms();
> s2d_total += (end - start);
> @@ -2871,7 +2874,7 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
>
> ret = hmm_migrate_dev_to_sys(fd, buffer, npages);
> if (ret)
> - return ret;
> + goto cleanup;
>
> end = get_time_ms();
> d2s_total += (end - start);
> @@ -2885,9 +2888,9 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
> results->throughput_d2s = (buffer_size / (1024.0 * 1024.0 * 1024.0)) /
> (results->dev_to_sys_time / 1000.0);
>
> - /* Cleanup */
> +cleanup:
> hmm_buffer_free(buffer);
> - return 0;
> + return ret;
> }
>
> /*
Thanks!
Reviewed-by: Balbir Singh <balbirs@nvidia.com>
prev parent reply other threads:[~2026-07-14 10:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 8:18 Hongfu Li
2026-07-13 1:35 ` Balbir Singh
2026-07-14 10:07 ` Lorenzo Stoakes (ARM)
2026-07-14 10:55 ` Balbir Singh [this message]
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=7f600e7a-e7b6-47a0-af54-05da2bea9cc7@nvidia.com \
--to=balbirs@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=hongfu.li@linux.dev \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=liam@infradead.org \
--cc=lihongfu@kylinos.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=sj@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
/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
Powered by JetHome