[RFC PATCH 2/2] mm/damon/reclaim: avoid divide-by-zero in damon_reclaim_apply_parameters()

Quanmin Yan posted 2 patches 1 month, 1 week ago
There is a newer version of this series
[RFC PATCH 2/2] mm/damon/reclaim: avoid divide-by-zero in damon_reclaim_apply_parameters()
Posted by Quanmin Yan 1 month, 1 week ago
When creating a new scheme of DAMON_RECLAIM, the calculation
of 'min_age_region' uses 'aggr_interval' as the divisor, which
may lead to division-by-zero errors. Fix it by directly returning
-EINVAL when such a case occurs.

Fixes: f5a79d7c0c87 ("mm/damon: introduce struct damos_access_pattern")
Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
---
 mm/damon/reclaim.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
index 3c71b4596676..fb7c982a0018 100644
--- a/mm/damon/reclaim.c
+++ b/mm/damon/reclaim.c
@@ -194,6 +194,11 @@ static int damon_reclaim_apply_parameters(void)
 	if (err)
 		return err;
 
+	if (!damon_reclaim_mon_attrs.aggr_interval) {
+		err = -EINVAL;
+		goto out;
+	}
+
 	err = damon_set_attrs(param_ctx, &damon_reclaim_mon_attrs);
 	if (err)
 		goto out;
-- 
2.43.0
Re: [RFC PATCH 2/2] mm/damon/reclaim: avoid divide-by-zero in damon_reclaim_apply_parameters()
Posted by SeongJae Park 1 month, 1 week ago
On Tue, 26 Aug 2025 11:36:53 +0800 Quanmin Yan <yanquanmin1@huawei.com> wrote:

> When creating a new scheme of DAMON_RECLAIM, the calculation
> of 'min_age_region' uses 'aggr_interval' as the divisor, which
> may lead to division-by-zero errors. Fix it by directly returning
> -EINVAL when such a case occurs.

Nice catch, thank you for this patch!

> 
> Fixes: f5a79d7c0c87 ("mm/damon: introduce struct damos_access_pattern")

Let's add Cc: stable@

> Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>

Reviewed-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

[...]