From nobody Fri Oct 3 16:44:10 2025 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29BA82F99B3 for ; Wed, 27 Aug 2025 11:58:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756295923; cv=none; b=iGoSUPw4qxzBNPiHj+YP4ANXDd9hZFM9DSyP7aHgDouihduc2FLlUo47lhrASxwLiJ5Unh5lDdjIcbtft7ABkOSNXCJD0vuPayo4l5J40fwTqpSrbwP9j28wAB5udPO63xMT6VIL2eLgQ/do+0Ot4fNEM0z1ooU/se7hU16zfJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756295923; c=relaxed/simple; bh=TkIgPFBZrwHKn9HCQHkOWlhto+Sgm1X+3+iNhv1C41A=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pQ58W4hrgorfuXkwTqG+1VY2umq8OZTARXf4C8ej1UZkWW29ss2aAOVbDnIZc4x5TyAo/Qm8k0FjUifkBeZOpmdhdnglrS4vri2AvPmIjzw1+ATI3PBTZ5BEFtqY8mgX+FiDdcejsEPtlEAdCmb4r5LuAeXgMKYXNq4yGGOi1NQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4cBjdB5csMz13N0R; Wed, 27 Aug 2025 19:54:54 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 3852414011F; Wed, 27 Aug 2025 19:58:37 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 27 Aug 2025 19:58:36 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH 1/2] mm/damon/lru_sort: avoid divide-by-zero in damon_lru_sort_apply_parameters() Date: Wed, 27 Aug 2025 19:58:57 +0800 Message-ID: <20250827115858.1186261-2-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250827115858.1186261-1-yanquanmin1@huawei.com> References: <20250827115858.1186261-1-yanquanmin1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" During the calculation of 'hot_thres' and 'cold_thres', either 'sample_interval' or 'aggr_interval' is used as the divisor, which may lead to division-by-zero errors. Fix it by directly returning -EINVAL when such a case occurs. Additionally, since 'aggr_interval' is already required to be set no smaller than 'sample_interval' in damon_set_attrs(), only the case where 'sample_interval' is zero needs to be checked. Fixes: 40e983cca927 ("mm/damon: introduce DAMON-based LRU-lists Sorting") Cc: # 6.0.x Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park --- mm/damon/lru_sort.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 151a9de5ad8b..b5a5ed16a7a5 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -198,6 +198,11 @@ static int damon_lru_sort_apply_parameters(void) if (err) return err; =20 + if (!damon_lru_sort_mon_attrs.sample_interval) { + err =3D -EINVAL; + goto out; + } + err =3D damon_set_attrs(ctx, &damon_lru_sort_mon_attrs); if (err) goto out; --=20 2.43.0 From nobody Fri Oct 3 16:44:10 2025 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 025B229D297 for ; Wed, 27 Aug 2025 11:58:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756295923; cv=none; b=RagkkU6m5mGZcH/mofEmZztIp5N06ElnOT5ZR14q1po3qOjNA7mlYxuiLMIdHpUK3kKzG+fIgFX+sGYzqc/ZjqPfsf5BTC41s7SALehKMs9IxOh8dxU3PU5v2Z1pVggoP3WhKxTNU1/O2GQwb3iA5Ra3coE+qyLWWPybGybItV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756295923; c=relaxed/simple; bh=z9InhMwxlHrlpWLJoWGYpX26uQyPWRXLYtpQgRNMZog=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SpqBzdGSWVLP0xoBKbQBWcHzeob+hhKf0ucoiK61VdjoLvxMgXzPktOiVbkiNSHh1VTGYWnClXV3IU4E9S5Q/+kVJB75rNS1CLz//XIJ6DlDJL/15TEOwWBmxwmGN3mdJ7EGuVp2TYLYwZrl8xuIDOEAwgzNruJTaVNUS3Z/370= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4cBjf354Fyz2VRVq; Wed, 27 Aug 2025 19:55:39 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id D64011A016C; Wed, 27 Aug 2025 19:58:37 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 27 Aug 2025 19:58:37 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH 2/2] mm/damon/reclaim: avoid divide-by-zero in damon_reclaim_apply_parameters() Date: Wed, 27 Aug 2025 19:58:58 +0800 Message-ID: <20250827115858.1186261-3-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250827115858.1186261-1-yanquanmin1@huawei.com> References: <20250827115858.1186261-1-yanquanmin1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" 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") Cc: # 6.1.x Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park --- 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; =20 + if (!damon_reclaim_mon_attrs.aggr_interval) { + err =3D -EINVAL; + goto out; + } + err =3D damon_set_attrs(param_ctx, &damon_reclaim_mon_attrs); if (err) goto out; --=20 2.43.0