From: SeongJae Park <sj@kernel.org>
To: Swaraj Gaikwad <swarajgaikwad1925@gmail.com>
Cc: SeongJae Park <sj@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
damon@lists.linux.dev (open list:DAMON),
linux-mm@kvack.org (open list:DAMON),
linux-kernel@vger.kernel.org (open list),
skhan@linuxfoundation.org, david.hunter.linux@gmail.com
Subject: Re: [PATCH] mm/damon/sysfs-schemes: Validate nid usage in nid_show()
Date: Mon, 20 Oct 2025 08:13:15 -0700 [thread overview]
Message-ID: <20251020151315.66260-1-sj@kernel.org> (raw)
In-Reply-To: <20251020112824.144391-1-swarajgaikwad1925@gmail.com>
Hello Swaraj,
On Mon, 20 Oct 2025 11:28:24 +0000 Swaraj Gaikwad <swarajgaikwad1925@gmail.com> wrote:
> The nid_show() function previously returned the node ID (nid) without
> verifying if the goal object of damos_sysfs_quota_goal was using a
> node-based metric. This could lead to incorrect reporting when the
> goal metric was unrelated to node memory.
>
> This patch introduces a validation step to ensure that nid_show() only
> returns the node ID for valid node-based metrics:
> - DAMOS_QUOTA_NODE_MEM_USED_BP
> - DAMOS_QUOTA_NODE_MEM_FREE_BP
>
> For other metrics, it returns -EINVAL to prevent misleading information.
>
> Tested with KUnit:
> - Built kernel with KUnit and DAMON sysfs tests enabled.
> - Executed KUnit tests:
> ./kunit.py run --kunitconfig ./mm/mm/damon/tests/.kunitconfig
> - All 25 tests passed, including damon_sysfs_test_add_targets.
So nice patch, thank you! I have a comment below, though.
>
> Based on commit 3a8660878839 ("Linux 6.18-rc1").
Maybe this is better to be put under the below comment section [1].
>
> Signed-off-by: Swaraj Gaikwad <swarajgaikwad1925@gmail.com>
> ---
> mm/damon/sysfs-schemes.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
> index 6536f16006c9..23a73b94fe53 100644
> --- a/mm/damon/sysfs-schemes.c
> +++ b/mm/damon/sysfs-schemes.c
> @@ -1112,7 +1112,16 @@ static ssize_t nid_show(struct kobject *kobj,
> struct damos_sysfs_quota_goal *goal = container_of(kobj, struct
> damos_sysfs_quota_goal, kobj);
>
> - /* todo: return error if the goal is not using nid */
> + switch (goal->metric) {
> + case DAMOS_QUOTA_USER_INPUT:
> + case DAMOS_QUOTA_SOME_MEM_PSI_US:
> + return -EINVAL;
> + case DAMOS_QUOTA_NODE_MEM_USED_BP:
> + case DAMOS_QUOTA_NODE_MEM_FREE_BP:
> + break;
> + default:
> + return -EINVAL;
> + }
>
> return sysfs_emit(buf, "%d\n", goal->nid);
> }
According to 'git bisect', I in the past actually added the todo comment. But,
I of now cannot remember why I in the past did think that's something to do. I
now think this function is better to be simply show the value the user has set
last time, since users could set the metrics after setting nid. Other similar
parameters also work in the way, to be wiring-order independent, so that simple
behavior would be better for consistency, too.
I'm sorry if the wrong todo comment was confusing you, Swaraj. Would you mind
sending a patch removing only the todo comment, without introducing any
behavior change?
[1] https://docs.kernel.org/process/submitting-patches.html#commentary
Thanks,
SJ
prev parent reply other threads:[~2025-10-20 15:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-20 11:28 [PATCH] mm/damon/sysfs-schemes: Validate nid usage in nid_show() Swaraj Gaikwad
2025-10-20 15:13 ` SeongJae Park [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=20251020151315.66260-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=david.hunter.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=skhan@linuxfoundation.org \
--cc=swarajgaikwad1925@gmail.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;
as well as URLs for NNTP newsgroup(s).