From nobody Sat Sep 26 08:37:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 A4538282F03; Thu, 3 Sep 2026 01:07:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788397650; cv=none; b=tGIAYe2Ty6T9GBGD5/48FqCcQFT0Vyr9rnPs8FhSdm1gGNC66tEUtHaDwukYY4vON8l/6SHw2XIJYiwBJeWlEMshtJIT4Gpd0j17viQbQDf7pYUn1RU6ZbQwPL6nsJG73wJPEpZViELII2Ln5sZhWEpBpfdiMgOssfu0GZ+jC04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788397650; c=relaxed/simple; bh=p2zMxKh68xFaCW7ziOQznGepGBTgaox7iBIqZjpl2U4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X71W8sS3/jMcyOUyHFCCtc2YXH0WAygek8bC3MPOSjHiz32j7DZZqi46uEeMK0EViQjpe7enEBe8NzMspWTug7aJQKNKvz9qhfh7QuAfobqUtTju8dU1S+CHvsocapIKY9WC9pW2GW6/yIc8F+6WauONyxq1IpgjzpfCGZdt8YM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=huWcm2b3; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="huWcm2b3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64AEF1F00A3A; Thu, 3 Sep 2026 01:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788397649; bh=a9IM/Ej4irsu0tekSCIZa7xad+wT2QHGn683VTr7Q88=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=huWcm2b3wYceGKjjjwjPQBzLv+hRL5m1+3L96P+Dy7mb8+EOVh0ZG7ka055pt4CQ4 O/yPRyz4jI002lrsN1mNDvJJirJXLV8WEwBh08RFyqVJsYYnyvJw5v1HEt/FDS1fIz wjex7RFagx+jP6A4+tQrp2zPlXnczIk2g3zd7bLlgSGjBqYt28/7NCEIJiyRn9zuUZ tPQxJvCPWAP8d2ZQld1rkG6FABZbFKrUp908uIUDKnioz7ozLp91G5QAwX1V3K3b76 kSWO/++MpfPUfEtHnDPJC1zA7KY/v7TqP3LOnZNX6FbcROeznspzN4wOoIGpnVsl/K HpKzS1nupRz2w== From: SJ Park To: Andrew Morton Cc: SJ Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/3] mm/damon/core: error damos_commit_quota_goal() for zero target_value Date: Wed, 2 Sep 2026 18:07:19 -0700 Message-ID: <20260903010722.94244-2-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260903010722.94244-1-sj@kernel.org> References: <20260903010722.94244-1-sj@kernel.org> 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 Content-Type: text/plain; charset="utf-8" If a DAMOS scheme has a damos_quota_goal of zero target_value, damos_quota_goal() could trigger division-by-zero error. Hence each DAMON API callers should do the zero target_value validation. It is easy to make mistakes. Actually such bugs in DAMON_LRU_SORT and DAMON_SAMPLE_MTIER were found and fixed [1]. It is better to handle the corner case only once in the core layer, instead of multiple places in all DAMON API callers. One straightforward option is using an alternative denominator for the corner case in the damos_quota_goal(). However, the zero target_value is meaningless. In this case, the quota goal is always evaluated as achieved or over-achieved. The quota will only keep being reduced. Simply avoid using zero target_value by adding a check in the core layer DAMOS quota goal parameters validation/commit path, damos_commit_quota_goal(). Update it to return an error in the case. Also update its caller to propagate the error. [1] https://lore.kernel.org/20260803134034.15217-1-sj@kernel.org Signed-off-by: SJ Park --- mm/damon/core.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 56ec6f616fa9a..89d1c77417450 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1212,14 +1212,17 @@ static void damos_commit_quota_goal_union( } } =20 -static void damos_commit_quota_goal( +static int damos_commit_quota_goal( struct damos_quota_goal *dst, struct damos_quota_goal *src) { + if (!src->target_value) + return -EINVAL; dst->metric =3D src->metric; dst->target_value =3D src->target_value; if (dst->metric =3D=3D DAMOS_QUOTA_USER_INPUT) dst->current_value =3D src->current_value; damos_commit_quota_goal_union(dst, src); + return 0; } =20 /** @@ -1237,14 +1240,17 @@ static void damos_commit_quota_goal( int damos_commit_quota_goals(struct damos_quota *dst, struct damos_quota *= src) { struct damos_quota_goal *dst_goal, *next, *src_goal, *new_goal; - int i =3D 0, j =3D 0; + int i =3D 0, j =3D 0, err; =20 damos_for_each_quota_goal_safe(dst_goal, next, dst) { src_goal =3D damos_nth_quota_goal(i++, src); - if (src_goal) - damos_commit_quota_goal(dst_goal, src_goal); - else + if (src_goal) { + err =3D damos_commit_quota_goal(dst_goal, src_goal); + if (err) + return err; + } else { damos_destroy_quota_goal(dst_goal); + } } damos_for_each_quota_goal_safe(src_goal, next, src) { if (j++ < i) @@ -1253,7 +1259,11 @@ int damos_commit_quota_goals(struct damos_quota *dst= , struct damos_quota *src) src_goal->metric, src_goal->target_value); if (!new_goal) return -ENOMEM; - damos_commit_quota_goal(new_goal, src_goal); + err =3D damos_commit_quota_goal(new_goal, src_goal); + if (err) { + damos_free_quota_goal(new_goal); + return err; + } damos_add_quota_goal(dst, new_goal); } return 0; --=20 2.47.3 From nobody Sat Sep 26 08:37:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 F0A3B2D949C; Thu, 3 Sep 2026 01:07:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788397651; cv=none; b=YwNTqxXTn8evFRSsEuih1qyRoVTEWyT3am39B8luO+PwCruBvaEZ7AHDuZjggVePWOObsVu19Q4tUO6etpBrATvYcpFpGi5pQke5aGq5fj/n5DhM0FyC0+ThXZo9duBddUtC5T0Nzax4wQIh7zPSwmArCKQOxDRrhxVhTdC2ReQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788397651; c=relaxed/simple; bh=axZTWAdNkaqbfw81b8HYeJVw703O5s5cDzE+KJ6R1x4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fUnkjh1MaWo4SMjkRaZ255YCJlpNbRcI6yC6bHYe0hG4pcxZKqEyfm673PmbpCq/QxaB7WMcMB2BTJ6sLxGwGvS6CcZtqVjs0un8QlURwks2AlmvmJ7vM3rWeSvHN0bdjMTqxDi89QYsquGGaXMFOB96f4YeP6Z9Q6wIn9RgXlw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SFpq7ydF; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SFpq7ydF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B24981F00A3D; Thu, 3 Sep 2026 01:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788397649; bh=3ydKZfv20XDA9Yk9OoF1itUqqkZNlBOcLwEjFDoPApk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SFpq7ydFn1Minqtp55XyMjj3pSEJhDIwAj7dFNpnIob9o750wJrG+nUBvaCfKCnfU 5PEXUWzW0VPiL+oNaRTPewGgzudX0SCkoWkyA2SO9E/Fhr5UM9qucdg0QhxlJ+0Q5K YHRSI4JdVUBeeu1rkiQ2c8+dCKR1YST6BwlZEg/1rpyAm0p8dJNnWH2nHorKbvfyEJ 5d8VBJmmH1njt2/hlqUWUGQVAKQ8YKWNZYL4Iqe1STd6rNL/O5jWv2cg6mZUnrRvK8 qr78Pk0qmA/vDx91IqIwpDEyytAZdI1O0KuOYo0e4FcBh9Z3q0NRxTSC6/uDB2D9Uk WhaOzAM2qvH6A== From: SJ Park To: Andrew Morton Cc: SJ Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/3] Revert "mm/damon/lru_sort: error out for >10000 active_mem_bp" Date: Wed, 2 Sep 2026 18:07:20 -0700 Message-ID: <20260903010722.94244-3-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260903010722.94244-1-sj@kernel.org> References: <20260903010722.94244-1-sj@kernel.org> 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 Content-Type: text/plain; charset="utf-8" This reverts commit 06befa61c427e74319781e6f35a364cfc32dbae8. The commit was made to avoid zero damos quota goal target value, because it can trigger division-by-zero. Now the core layer handles the corner case. It returns an error for any attempt setting the aero target_value. The corner case handling in DAMON_LRU_SORT is hence no more needed. Remove it. Note that this slightly changes the user behavior. It still disallows active_mem_bp of 10,002. But now it allows other >10,000 active_mem_bp values. Setting >10,000 active_mem_bp makes not much sense. But it doesn't cause critical problems such as memory leak or crash, either. Arguably that doesn't deserve additional code complexity. Just allow it. Signed-off-by: SJ Park --- mm/damon/lru_sort.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index f25ee7326e87c..ad8e86dd3a93e 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -233,8 +233,6 @@ static int damon_lru_sort_add_quota_goals(struct damos = *hot_scheme, =20 if (!active_mem_bp) return 0; - if (10000 < active_mem_bp) - return -EINVAL; goal =3D damos_new_quota_goal(DAMOS_QUOTA_ACTIVE_MEM_BP, active_mem_bp); if (!goal) return -ENOMEM; --=20 2.47.3 From nobody Sat Sep 26 08:37:11 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 795A52DFF3F; Thu, 3 Sep 2026 01:07:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788397651; cv=none; b=JJV0h3D370VKBASlULlGXbbySUzJtT/2oIx6CLXf2N7HKTsAgUAGWtcuhd37HXBlRzIvh5OhO8GqpdDmfJxufeEcPU0VkqtCmeq50yIwniqlDFb7/YqDS3zEdGBOQlB4n32vj5vZtnDmOerRz/0pnQqyRJIGlGWfCkU0puPq+Hc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788397651; c=relaxed/simple; bh=7BuePdqLsmCrpZcRRQjUY0RK2a5/39HdUmJOLbwdCNU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ic3XL0d5r4Jjc9IXlVcfCZnqqQHItdJKD2/rUAA3qNO6ot028kWtlUUw9ryfjX0TBnIGFupwTpc9IF+AjH7oaa0GfBhg4srYf4urIV57aRfZ9yjzctjfLo+vVhYmX9L2EAXxtIMbYny1t0W4uq2gjK9qboiCY25N5QN1r/kvpmg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iGh6AA0p; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iGh6AA0p" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B3831F00A3E; Thu, 3 Sep 2026 01:07:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788397650; bh=4SsJPfKsekeE5VptqHXgsGnvsq0lAUhbBGf4TqY9ku8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iGh6AA0pHU71NdvZh0YOA3rFuHLBh0+RJ6ntehGQFIdA3dHZJ2H3oD3+XPLYRSriF LTEFCe6UfMTb9+tEdnICcKKV5oB9MjFdPfkc1xS9T/xhVPd2xJlAV8J3cvUAfGUHlP vvzQXrli3zLDtSYA6HOZrUadW/uVdH2QHl6NDYA2l7J5zvF78Eav8fUXsYj5GAiBBP M2nr6zPaKt8NqM6sStlOOQ7O8Yp3uR+jY0Dj4txCzJnpZvv02TKy4bAuwHlD9dycAZ cGYn6aLuZt7I8CbZV1aH/y2OD4hqiDp1cZHaE3gm1EPsKpdluIyBeTOyCeU/606EU/ Zp9wmQVnjLgvw== From: SJ Park To: Andrew Morton Cc: SJ Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/3] Revert "samples/damon/mtier: error out for zero quota goal target values" Date: Wed, 2 Sep 2026 18:07:21 -0700 Message-ID: <20260903010722.94244-4-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260903010722.94244-1-sj@kernel.org> References: <20260903010722.94244-1-sj@kernel.org> 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 Content-Type: text/plain; charset="utf-8" This reverts commit a16fd3ad9d89b05475864da97327870464611736. The commit was made to avoid zero damos quota goal target value, because it can trigger division-by-zero. Now the core layer handles the corner case. It returns an error for any attempt setting the aero target_value. The corner case handling in DAMON_SAMPLE_MTIER is hence no more needed. Remove it. Signed-off-by: SJ Park --- samples/damon/mtier.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/samples/damon/mtier.c b/samples/damon/mtier.c index bea45c87cc9be..27dc88bdf7a0e 100644 --- a/samples/damon/mtier.c +++ b/samples/damon/mtier.c @@ -161,9 +161,6 @@ static struct damon_ctx *damon_sample_mtier_build_ctx(b= ool promote) if (!scheme) goto free_out; damon_set_schemes(ctx, &scheme, 1); - /* zero target value causes division by zero in damos_quota_store() */ - if (!node0_mem_used_bp || !node0_mem_free_bp) - goto free_out; quota_goal =3D damos_new_quota_goal( promote ? DAMOS_QUOTA_NODE_MEM_USED_BP : DAMOS_QUOTA_NODE_MEM_FREE_BP, --=20 2.47.3