From: Liew Rui Yan <aethernet65535@gmail.com>
To: sj@kernel.org
Cc: aethernet65535@gmail.com, damon@lists.linux.dev, linux-mm@kvack.org
Subject: Re: [PATCH] mm/damon: validate addr_unit to be power of 2
Date: Sun, 29 Mar 2026 01:44:09 +0800 [thread overview]
Message-ID: <20260328174409.6786-1-aethernet65535@gmail.com> (raw)
In-Reply-To: <20260328141323.10540-1-sj@kernel.org>
On Sat, 28 Mar 2026 07:13:23 -0700 SeongJae Park <sj@kernel.org> wrote:
> > On Sat, 28 Mar 2026 10:26:51 +0800 Liew Rui Yan <aethernet65535@gmail.com> wrote:
> >
> > > [...]
> > > - Would a lightweight fix be acceptable? For example, performing
> > > validation at the very beginning of damon_commit_ctx(), and returning
> > > -EINVAL before setting 'maybe_corrupted' to true. Since no
> > > modifications to 'dst' would have occurred, kdamond could safely
> > > continue with its old configuration.
> >
> > I suggested you to try something similar to what DAMON_SYSFS is doing. But I
> > didn't get your response to the idea yet. Could you please let me know what do
> > you think about the approach?
>
> I was thinking this one more time. So you want to ensure DAMON_RECLAIM and
> DAMON_LRU_SORT not passing wrong addr_unit to damon_commit_ctx(), right? And
> that's required because exisitng inputs validations of DAMON_RECLAIM and
> DAMON_LRU_SORT are not checking that. Why don't you add the just one more
> check there?
Apologize for the confusion in my previous explanation. To clarify, my
proposal was indeed focused on implementing a lightweight fix directly
within damon_commit_ctx(), rather than adding separate checks in
DAMON_RECLAIM and DAMON_LRU_SORT.
The goal is to safely handle the context state transition. Specifically,
I want to validate inputs before marking the context as potentially
corrupted. Here are two approaches to achieve this:
Option 1 - Using a label for cleanup:
damon_commit_ctx(...)
{
err = 0;
dst->maybe_corrupted = true;
if (...) {
err = -EINVAL;
goto out_reset;
}
... other code ...
out_reset:
dst->maybe_corrupted = false;
return err;
}
Option 2 - Deferring the 'maybe_corrupted' assignment:
damon_commit_ctx(...)
{
err = 0;
if (...)
return -EINVAL;
/*
* Only mark as pontentially corrupted once
* we start modifying dst.
*/
dst->maybe_corrupted = true;
... other code ...
}
I think Option 2 is cleaner as it avoids unnecessary state flipping.
>
> I remember I was saying this kind of change would be a kind of whack-a-mole and
> therefore prefer DAMON_SYSFS type damon_commit_ctx() based checking. But
> that's not a small change. Just adding yet another simple check on existing
> validation logic should be fine and small.
>
> [...]
Best regards,
Rui Yan
next prev parent reply other threads:[~2026-03-28 17:44 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-27 6:26 [PATCH] mm/damon: validate addr_unit to be power of 2 Liew Rui Yan
2026-03-27 6:45 ` Liew Rui Yan
2026-03-27 12:10 ` Liew Rui Yan
2026-03-27 8:11 ` (sashiko review) " Liew Rui Yan
2026-03-27 8:27 ` Liew Rui Yan
2026-03-27 14:14 ` SeongJae Park
2026-03-27 14:56 ` Liew Rui Yan
2026-03-28 0:14 ` SeongJae Park
2026-03-28 2:26 ` Liew Rui Yan
2026-03-28 13:29 ` SeongJae Park
2026-03-28 14:13 ` SeongJae Park
2026-03-28 17:44 ` Liew Rui Yan [this message]
2026-03-28 18:06 ` SeongJae Park
2026-03-28 18:43 ` Liew Rui Yan
2026-03-29 3:20 ` SeongJae Park
2026-03-29 7:51 ` Liew Rui Yan
2026-03-29 15:15 ` SeongJae Park
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=20260328174409.6786-1-aethernet65535@gmail.com \
--to=aethernet65535@gmail.com \
--cc=damon@lists.linux.dev \
--cc=linux-mm@kvack.org \
--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