DAMON development mailing list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH 6.12.y] mm/damon/core: always put unsuccessfully committed target pids
Date: Tue, 21 Jul 2026 05:33:00 +0000	[thread overview]
Message-ID: <20260721053301.0B6731F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260721052238.163760-1-sj@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Medium] PID references are leaked when damon_start() or late stages of context building fail in damon_sysfs_turn_damon_on().
--

--- Patch [1]: [PATCH 6.12.y] mm/damon/core: always put unsuccessfully committed target pids ---
commit d053b994cdbf8e3fe384c68bbdb8f593cb5a45e5
Author: SeongJae Park <sj@kernel.org>

mm/damon/core: always put unsuccessfully committed target pids

This commit fixes a PID leak by explicitly putting the PIDs of targets in
the commit operation when damon_commit_target() fails.

Link: https://lore.kernel.org/20260605013849.83750-1-sj@kernel.org
Link: https://lore.kernel.org/20260603112306.58490-1-akinobu.mita@gmail.com [1]
Link: https://lore.kernel.org/20260320020056.835-1-sj@kernel.org [2]

> The source context will do the put operations using the above explained
> routine.  However, let's suppose the destination context was not
> originally using [f]vaddr operation set and the commit failed before the
> ops of the source context is committed.  The destination does not have the
> cleanup_target() ops callback, so it cannot put the pids via the
> damon_destroy_ctx().
> 
> As a result, the pids are leaked.

[Severity: Medium]
This is a pre-existing issue, but does a similar PID leak happen in
mm/damon/sysfs.c when context building or starting fails?

For example, in damon_sysfs_build_ctx():

mm/damon/sysfs.c:damon_sysfs_build_ctx() {
	...
	err = damon_sysfs_apply_inputs(ctx, sys_ctx);
	if (err) {
		damon_destroy_ctx(ctx);
		return ERR_PTR(err);
	}
	...
}

If damon_sysfs_apply_inputs() fails during scheme addition (after targets
were successfully added and PIDs referenced), damon_destroy_ctx(ctx) is
called and the PIDs are leaked.

Similarly, in damon_sysfs_turn_damon_on():

mm/damon/sysfs.c:damon_sysfs_turn_damon_on() {
	...
	err = damon_start(&ctx, 1, false);
	if (err) {
		damon_destroy_ctx(ctx);
		return err;
	}
	...
}

If damon_start() fails (e.g., due to ENOMEM), the error path directly calls
damon_destroy_ctx(ctx). For vaddr operations, ctx->ops.cleanup is NULL,
and PID references are normally released by damon_sysfs_before_terminate().

However, since the thread is never started or the context is aborted early,
the termination callback is not called and the PIDs are never put.

Is this something that needs a similar fix to ensure these PIDs are
released?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260721052238.163760-1-sj@kernel.org?part=1

      reply	other threads:[~2026-07-21  5:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2026072031-shingle-buddy-1bbb@gregkh>
2026-07-21  5:22 ` [PATCH 6.12.y] mm/damon/core: always put unsuccessfully committed target pids SJ Park
2026-07-21  5:33   ` sashiko-bot [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=20260721053301.0B6731F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sj@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