public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
* [PATCH v2] mm/damon: validate min_region_size to be power of 2
@ 2026-04-02  5:37 Liew Rui Yan
  2026-04-02  7:08 ` (sashiko status) " Liew Rui Yan
  2026-04-02 14:03 ` SeongJae Park
  0 siblings, 2 replies; 7+ messages in thread
From: Liew Rui Yan @ 2026-04-02  5:37 UTC (permalink / raw)
  To: sj; +Cc: damon, linux-mm, Liew Rui Yan

Problem
=======
damon_commit_ctx() checks if 'min_region_sz' is a power of 2. But if it
is not, kdamond will terminate unexpectedly due to the user's invalid
input.

Solution
========
Add the same check to damon_{lru_sort, reclaim}_apply_parameters(), but
return -EINVAL immediately. This is to prevent user's invalid input
causing kdamond to terminate unexpectedly.

This patch is a follow-up to the discussion in [1], where we agreed that
the validation should be done on min_region_sz rather than addr_unit.

[1] https://lore.kernel.org/20260330233343.4083-1-sj@kernel.org

Signed-off-by: Liew Rui Yan <aethernet65535@gmail.com>
---
Changes from v1:
- Fix memory leak issue.
- Link to v1: https://lore.kernel.org/20260331073231.30060-1-aethernet65535@gmail.com

 mm/damon/lru_sort.c | 5 +++++
 mm/damon/reclaim.c  | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
index 554559d72976..3fd176ef9d9c 100644
--- a/mm/damon/lru_sort.c
+++ b/mm/damon/lru_sort.c
@@ -294,6 +294,11 @@ static int damon_lru_sort_apply_parameters(void)
 	param_ctx->addr_unit = addr_unit;
 	param_ctx->min_region_sz = max(DAMON_MIN_REGION_SZ / addr_unit, 1);
 
+	if (!is_power_of_2(param_ctx->min_region_sz)) {
+		err = -EINVAL;
+		goto out;
+	}
+
 	if (!damon_lru_sort_mon_attrs.sample_interval) {
 		err = -EINVAL;
 		goto out;
diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
index 86da14778658..2747eef5919d 100644
--- a/mm/damon/reclaim.c
+++ b/mm/damon/reclaim.c
@@ -204,6 +204,11 @@ static int damon_reclaim_apply_parameters(void)
 	param_ctx->addr_unit = addr_unit;
 	param_ctx->min_region_sz = max(DAMON_MIN_REGION_SZ / addr_unit, 1);
 
+	if (!is_power_of_2(param_ctx->min_region_sz)) {
+		err = -EINVAL;
+		goto out;
+	}
+
 	if (!damon_reclaim_mon_attrs.aggr_interval) {
 		err = -EINVAL;
 		goto out;
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: (sashiko status) [PATCH v2] mm/damon: validate min_region_size to be power of 2
  2026-04-02  5:37 [PATCH v2] mm/damon: validate min_region_size to be power of 2 Liew Rui Yan
@ 2026-04-02  7:08 ` Liew Rui Yan
  2026-04-02 14:03 ` SeongJae Park
  1 sibling, 0 replies; 7+ messages in thread
From: Liew Rui Yan @ 2026-04-02  7:08 UTC (permalink / raw)
  To: aethernet65535, sj; +Cc: damon, linux-mm

- [PATCH v2] mm/damon: validate min_region_size to be power of 2
  - status: Reviewed
  - review: No issues found.

# hkml [1] generated a draft of this mail.  It can be regenerated
# using below command:
#
#     hkml patch sashiko_dev --thread_status --for_forwarding \
#             20260402053756.26606-1-aethernet65535@gmail.com
#
# [1] https://github.com/sjp38/hackermail


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] mm/damon: validate min_region_size to be power of 2
  2026-04-02  5:37 [PATCH v2] mm/damon: validate min_region_size to be power of 2 Liew Rui Yan
  2026-04-02  7:08 ` (sashiko status) " Liew Rui Yan
@ 2026-04-02 14:03 ` SeongJae Park
  2026-04-02 15:29   ` SeongJae Park
  2026-04-03  8:29   ` Liew Rui Yan
  1 sibling, 2 replies; 7+ messages in thread
From: SeongJae Park @ 2026-04-02 14:03 UTC (permalink / raw)
  To: Liew Rui Yan; +Cc: SeongJae Park, damon, linux-mm

On Thu,  2 Apr 2026 13:37:56 +0800 Liew Rui Yan <aethernet65535@gmail.com> wrote:

> Problem
> =======
> damon_commit_ctx() checks if 'min_region_sz' is a power of 2. But if it
> is not, kdamond will terminate unexpectedly due to the user's invalid
> input.

Could you please further elaborate visible user impact of the problem and
reproduction steps if available?

> 
> Solution
> ========
> Add the same check to damon_{lru_sort, reclaim}_apply_parameters(), but
> return -EINVAL immediately. This is to prevent user's invalid input
> causing kdamond to terminate unexpectedly.
> 
> This patch is a follow-up to the discussion in [1], where we agreed that
> the validation should be done on min_region_sz rather than addr_unit.
> 
> [1] https://lore.kernel.org/20260330233343.4083-1-sj@kernel.org
> 

Should we add Fixes: and Cc: stable@ ?

If we should Cc: stable@, and if the changes for DAMON_RECLAIM and
DAMON_LRU_SORT deserve different Fixes:, I think this patch is better to be
split into two patches, one for DAMON_RECLAIM, and the other for
DAMON_LRU_SORT.

> Signed-off-by: Liew Rui Yan <aethernet65535@gmail.com>
> ---
> Changes from v1:
> - Fix memory leak issue.
> - Link to v1: https://lore.kernel.org/20260331073231.30060-1-aethernet65535@gmail.com

Seems you forgot the patch [1] before renaming of the subject.

[...]

The code changes look good to me.

[1] https://lore.kernel.org/20260327062627.66426-1-aethernet65535@gmail.com


Thanks,
SJ


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] mm/damon: validate min_region_size to be power of 2
  2026-04-02 14:03 ` SeongJae Park
@ 2026-04-02 15:29   ` SeongJae Park
  2026-04-03  8:29   ` Liew Rui Yan
  1 sibling, 0 replies; 7+ messages in thread
From: SeongJae Park @ 2026-04-02 15:29 UTC (permalink / raw)
  To: SeongJae Park; +Cc: Liew Rui Yan, damon, linux-mm

On Thu,  2 Apr 2026 07:03:14 -0700 SeongJae Park <sj@kernel.org> wrote:

> On Thu,  2 Apr 2026 13:37:56 +0800 Liew Rui Yan <aethernet65535@gmail.com> wrote:
> 
> > Problem
> > =======
> > damon_commit_ctx() checks if 'min_region_sz' is a power of 2. But if it
> > is not, kdamond will terminate unexpectedly due to the user's invalid
> > input.
> 
> Could you please further elaborate visible user impact of the problem and
> reproduction steps if available?
> 
> > 
> > Solution
> > ========
> > Add the same check to damon_{lru_sort, reclaim}_apply_parameters(), but
> > return -EINVAL immediately. This is to prevent user's invalid input
> > causing kdamond to terminate unexpectedly.
> > 
> > This patch is a follow-up to the discussion in [1], where we agreed that
> > the validation should be done on min_region_sz rather than addr_unit.
> > 
> > [1] https://lore.kernel.org/20260330233343.4083-1-sj@kernel.org
> > 
> 
> Should we add Fixes: and Cc: stable@ ?
> 
> If we should Cc: stable@, and if the changes for DAMON_RECLAIM and
> DAMON_LRU_SORT deserve different Fixes:, I think this patch is better to be
> split into two patches, one for DAMON_RECLAIM, and the other for
> DAMON_LRU_SORT.
> 
> > Signed-off-by: Liew Rui Yan <aethernet65535@gmail.com>
> > ---
> > Changes from v1:
> > - Fix memory leak issue.
> > - Link to v1: https://lore.kernel.org/20260331073231.30060-1-aethernet65535@gmail.com
> 
> Seems you forgot the patch [1] before renaming of the subject.

Also, if you have posted RFCs or another different subject patches before,
please add full change log.

We are dealing with multiple patches in parallel, so I'm not fully following
entire contexts.  Please understand.

> 
> [...]
> 
> The code changes look good to me.
> 
> [1] https://lore.kernel.org/20260327062627.66426-1-aethernet65535@gmail.com


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] mm/damon: validate min_region_size to be power of 2
  2026-04-02 14:03 ` SeongJae Park
  2026-04-02 15:29   ` SeongJae Park
@ 2026-04-03  8:29   ` Liew Rui Yan
  2026-04-03 14:09     ` SeongJae Park
  1 sibling, 1 reply; 7+ messages in thread
From: Liew Rui Yan @ 2026-04-03  8:29 UTC (permalink / raw)
  To: sj; +Cc: aethernet65535, damon, linux-mm

Hi SeongJae,

Sorry for missing the discussion before sending out v3. I was too
focused on the code and missed the context of your questions.

On Thu,  2 Apr 2026 07:03:14 -0700 SeongJae Park <sj@kernel.org> wrote:

> On Thu,  2 Apr 2026 13:37:56 +0800 Liew Rui Yan <aethernet65535@gmail.com> wrote:
> [...]
> 
> Could you please further elaborate visible user impact of the problem and
> reproduction steps if available?

Yes, I have provided it in the cover letter of v3 [1].

> [...]
> 
> Should we add Fixes: and Cc: stable@ ?
> 
> If we should Cc: stable@, and if the changes for DAMON_RECLAIM and
> DAMON_LRU_SORT deserve different Fixes:, I think this patch is better to be
> split into two patches, one for DAMON_RECLAIM, and the other for
> DAMON_LRU_SORT.

Yes, I agree. I have split the changes into two separate patches in v3
[1]:
- Patch 1 Fixes: 
  2e0fe9245d6b ("mm/damon/lru_sort: support addr_unit for DAMON_LRU_SORT")
- Patch 2 Fixes:
  7db551fcfb2a ("mm/damon/reclaim: support addr_unit for DAMON_RECLAIM")

Both patches are now CC-ed to <stable@vger.kernel.org>.

> [...]
> 
> Seems you forgot the patch [1] before renaming of the subject.

Thank you again for reminding me, I have added the missing references
to the changelog in v3 [1].

> 
> [...]
> 
> The code changes look good to me.
> 
> [1] https://lore.kernel.org/20260327062627.66426-1-aethernet65535@gmail.com

Thank you for your review and patience.

[1] https://lore.kernel.org/20260403052837.58063-1-aethernet65535@gmail.com

Best regards,
Rui Yan


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] mm/damon: validate min_region_size to be power of 2
  2026-04-03  8:29   ` Liew Rui Yan
@ 2026-04-03 14:09     ` SeongJae Park
  2026-04-03 14:12       ` SeongJae Park
  0 siblings, 1 reply; 7+ messages in thread
From: SeongJae Park @ 2026-04-03 14:09 UTC (permalink / raw)
  To: Liew Rui Yan; +Cc: SeongJae Park, damon, linux-mm

On Fri,  3 Apr 2026 16:29:10 +0800 Liew Rui Yan <aethernet65535@gmail.com> wrote:

> Hi SeongJae,
> 
> Sorry for missing the discussion before sending out v3. I was too
> focused on the code and missed the context of your questions.

No worries.  From next time, please ensure discussions on the last version is
ended, by replying to questions and waiting about one day for giving others to
chime in, before sending the next version.
[...]

Thank you for all your answers to my questions and requests.  That all make
sense to me.

> 
> > 
> > [...]
> > 
> > The code changes look good to me.
> > 
> > [1] https://lore.kernel.org/20260327062627.66426-1-aethernet65535@gmail.com
> 
> Thank you for your review and patience.

You are always welcome.

> 
> [1] https://lore.kernel.org/20260403052837.58063-1-aethernet65535@gmail.com


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] mm/damon: validate min_region_size to be power of 2
  2026-04-03 14:09     ` SeongJae Park
@ 2026-04-03 14:12       ` SeongJae Park
  0 siblings, 0 replies; 7+ messages in thread
From: SeongJae Park @ 2026-04-03 14:12 UTC (permalink / raw)
  To: SeongJae Park; +Cc: Liew Rui Yan, damon, linux-mm

On Fri,  3 Apr 2026 07:09:41 -0700 SeongJae Park <sj@kernel.org> wrote:

> On Fri,  3 Apr 2026 16:29:10 +0800 Liew Rui Yan <aethernet65535@gmail.com> wrote:
> 
> > Hi SeongJae,
> > 
> > Sorry for missing the discussion before sending out v3. I was too
> > focused on the code and missed the context of your questions.
> 
> No worries.  From next time, please ensure discussions on the last version is
> ended, by replying to questions and waiting about one day for giving others to
> chime in, before sending the next version.

Also, please don't rush.  Let's take enough time for both writing and reviewing
of the code.


Thanks,
SJ

> [...]
> 
> Thank you for all your answers to my questions and requests.  That all make
> sense to me.
> 
> > 
> > > 
> > > [...]
> > > 
> > > The code changes look good to me.
> > > 
> > > [1] https://lore.kernel.org/20260327062627.66426-1-aethernet65535@gmail.com
> > 
> > Thank you for your review and patience.
> 
> You are always welcome.
> 
> > 
> > [1] https://lore.kernel.org/20260403052837.58063-1-aethernet65535@gmail.com
> 
> 
> Thanks,
> SJ
> 
> [...]
> 

Sent using hkml (https://github.com/sjp38/hackermail)


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-04-03 14:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-02  5:37 [PATCH v2] mm/damon: validate min_region_size to be power of 2 Liew Rui Yan
2026-04-02  7:08 ` (sashiko status) " Liew Rui Yan
2026-04-02 14:03 ` SeongJae Park
2026-04-02 15:29   ` SeongJae Park
2026-04-03  8:29   ` Liew Rui Yan
2026-04-03 14:09     ` SeongJae Park
2026-04-03 14:12       ` SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox