From: sashiko-bot@kernel.org
To: gutierrez.asier@huawei-partners.com
Cc: damon@lists.linux.dev
Subject: Re: [RESEND PATCH v2 1/3] mm/damon: Introduce DAMOS_QUOTA_HUGEPAGE auto tuning
Date: Tue, 14 Jul 2026 15:15:07 +0000 [thread overview]
Message-ID: <20260714151507.9567D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260714150116.382521-2-gutierrez.asier@huawei-partners.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [High] Calculation of the huge page memory ratio in `damos_hugepage_mem_bp()` can trigger a divide-by-zero kernel panic if the calculated total memory evaluates to zero.
- [Medium] The new metric `DAMOS_QUOTA_HUGEPAGE_MEM_BP` is not exposed to the DAMON sysfs interface, making it unconfigurable from userspace.
Pre-existing issues:
- [High] Preexisting division by zero vulnerability in `damos_get_in_active_mem_bp()` when LRU memory is empty.
- [High] A user-controlled target_value of 0 will cause a divide-by-zero panic during quota scoring.
--
--- Patch [1]: [RESEND PATCH v2 1/3] mm/damon: Introduce DAMOS_QUOTA_HUGEPAGE auto tuning ---
commit bc154724e397943cbba0b2ca233b1c3995ce0802
Author: Asier Gutierrez <gutierrez.asier@huawei-partners.com>
mm/damon: Introduce DAMOS_QUOTA_HUGEPAGE auto tuning
Introduce DAMOS_QUOTA_HUGEPAGE_MEM_BP auto tuning. Add a new
DAMOS quota goal metric to measure the amount of huge page
consumption to total memory consumption ratio.
> diff --git a/include/linux/damon.h b/include/linux/damon.h
> index 02ac34537df9a..6f87ec40db8ca 100644
> --- a/include/linux/damon.h
> +++ b/include/linux/damon.h
> @@ -162,6 +162,7 @@ enum damos_action {
> * @DAMOS_QUOTA_INACTIVE_MEM_BP: Inactive to total LRU memory ratio.
> * @DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP: Scheme-eligible memory ratio of a
> * node in basis points (0-10000).
> + * @DAMOS_QUOTA_HUGEPAGE_MEM_BP: Huge page to total used memory ratio.
[Severity: Medium]
Will this new metric be configurable from userspace?
It looks like damos_sysfs_qgoal_metric_names[] in mm/damon/sysfs-schemes.c
was not updated, which might cause target_metric_store() to return -EINVAL
when trying to configure this metric via sysfs.
[ ... ]
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 7e4b9affc5b06..b001f80681b12 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -2795,6 +2795,17 @@ static unsigned int damos_get_in_active_mem_bp(bool active_ratio)
> return mult_frac(inactive, 10000, total);
> }
[Severity: High]
This isn't a bug introduced by this patch, but can total be zero here?
If the system has exactly 0 active and 0 inactive LRU pages (which could
happen if all memory is locked, used strictly by slab, or on tiny setups),
total would be 0. This might cause a divide-by-zero panic in mult_frac().
>
> +static unsigned int damos_hugepage_mem_bp(void)
> +{
> + unsigned long thp, total;
> +
> + thp = global_node_page_state(NR_ANON_THPS) +
> + global_node_page_state(NR_SHMEM_THPS) +
> + global_node_page_state(NR_FILE_THPS);
> + total = totalram_pages() - global_zone_page_state(NR_FREE_PAGES);
> + return mult_frac(thp, 10000, total);
[Severity: High]
Could total evaluate to zero here?
Due to per-CPU drift in the vm_stat counters (global_zone_page_state),
NR_FREE_PAGES could momentarily equal totalram_pages(). Passing total == 0
to mult_frac() will trigger a divide-by-zero kernel panic when the schema
is evaluated. Should we add a check for !total before calculating the
fraction?
[ ... ]
[Severity: High]
This is a pre-existing issue, but I noticed another potential
divide-by-zero related to these quota goals.
In mm/damon/sysfs-schemes.c:target_value_store(), user input is parsed via
kstrtoul() directly into goal->target_value without validating that it is
non-zero:
int err = kstrtoul(buf, 0, &goal->target_value);
return err ? err : count;
Later, when the DAMON thread evaluates the quota score,
mm/damon/core.c:damos_quota_score() does:
highest_score = max(highest_score,
mult_frac(goal->current_value, 10000,
goal->target_value));
Could a user writing 0 to the target_value sysfs file cause a predictable
and immediate system crash here?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260714150116.382521-1-gutierrez.asier@huawei-partners.com?part=1
next prev parent reply other threads:[~2026-07-14 15:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 15:01 [RESEND PATCH v2 0/3] mm/damon: Introduce a huge page collapsing mechanism using auto tuning gutierrez.asier
2026-07-14 15:01 ` [RESEND PATCH v2 1/3] mm/damon: Introduce DAMOS_QUOTA_HUGEPAGE " gutierrez.asier
2026-07-14 15:15 ` sashiko-bot [this message]
2026-07-14 15:01 ` [RESEND PATCH v2 2/3] mm/damon/sysfs: support hugepage_mem_bp quota goal metric gutierrez.asier
2026-07-14 15:01 ` [RESEND PATCH v2 3/3] Docs/mm/damon/design: Document hugepage_mem_bp target metric gutierrez.asier
2026-07-14 15:18 ` sashiko-bot
2026-07-15 0:18 ` [RESEND PATCH v2 0/3] mm/damon: Introduce a huge page collapsing mechanism using auto tuning SJ 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=20260714151507.9567D1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=damon@lists.linux.dev \
--cc=gutierrez.asier@huawei-partners.com \
--cc=sashiko-reviews@lists.linux.dev \
/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