mm/damon: validate min_region_size to be power of 2
Subsystems (2)
PATCH v2 1/1 mm/damon: validate min_region_size to be power of 2
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/[email protected]
---
Changes from v1:
- Fix memory leak issue.
- Link to v1: https://lore.kernel.org/[email protected]
mm/damon/lru_sort.c | 5 +++++ mm/damon/reclaim.c | 5 +++++ 2 files changed, 10 insertions(+)
mm/damon/lru_sort.c +5 -0
@@ -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;
mm/damon/reclaim.c +5 -0
@@ -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;
Signature · 1 line
2.53.0
Re: (sashiko status) [PATCH v2] mm/damon: validate min_region_size to be power of 2
- [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 \ # [email protected] # # [1] https://github.com/sjp38/hackermail
SeongJae Park
maintainerQuoted 5 lines · On Thu, 2 Apr 2026 13:37:56 +0800 Liew Rui Yan <[email protected]>…
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?
Quoted 7 lines
Solution
========
Add the same check to damon_{lru_sort, reclaim}_apply_parameters(), but return-EINVALimmediately. This is to prevent user's invalid input causing kdamond to terminate unexpectedly.
Quoted 5 lines
This patch is a follow-up to the discussion in [1], where we agreed that the validation should be done on
min_region_szrather thanaddr_unit.
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.
Quoted 5 lines
Signed-off-by Liew Rui Yan <[email protected]>---
Changes from v1:
- Fix memory leak issue.
- Link to v1: https://lore.kernel.org/[email protected]
Seems you forgot the patch [1] before renaming of the subject.
[...]
The code changes look good to me.
[1] https://lore.kernel.org/[email protected]
Thanks,
SJ
SeongJae Park
maintainerQuoted 31 lines · On Thu, 2 Apr 2026 07:03:14 -0700 SeongJae Park <[email protected]> wrote:
Quoted 5 lines · On Thu, 2 Apr 2026 13:37:56 +0800 Liew Rui Yan <[email protected]>…
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?
Quoted 7 lines
Solution
========
Add the same check to damon_{lru_sort, reclaim}_apply_parameters(), but return-EINVALimmediately. This is to prevent user's invalid input causing kdamond to terminate unexpectedly.Quoted 5 lines
This patch is a follow-up to the discussion in [1], where we agreed that the validation should be done on
min_region_szrather thanaddr_unit.Should we add Fixes: and Cc: stable@ ?
If we should Cc: stable@, and if the changes for
DAMON_RECLAIMandDAMON_LRU_SORTdeserve different Fixes:, I think this patch is better to be split into two patches, one forDAMON_RECLAIM, and the other forDAMON_LRU_SORT.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Liew Rui Yan <[email protected]>---
Changes from v1:
- Fix memory leak issue.
- Link to v1: https://lore.kernel.org/[email protected]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.
Quoted 6 lines
[...]
The code changes look good to me.
Thanks,
SJ
[...]
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.
Quoted 5 lines · On Thu, 2 Apr 2026 07:03:14 -0700 SeongJae Park <[email protected]> wrote:
On Thu, 2 Apr 2026 13:37:56 +0800 Liew Rui Yan <[email protected]> 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].
Quoted 8 lines
[...]
Should we add Fixes: and Cc: stable@ ?
If we should Cc: stable@, and if the changes for
DAMON_RECLAIMandDAMON_LRU_SORTdeserve different Fixes:, I think this patch is better to be split into two patches, one forDAMON_RECLAIM, and the other forDAMON_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 <[email protected]>.
Quoted 3 lines
[...]
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].
Quoted 6 lines
[...]
The code changes look good to me.
Thank you for your review and patience.
[1] https://lore.kernel.org/[email protected]
Best regards,
Rui Yan
SeongJae Park
maintainerQuoted 4 lines · On Fri, 3 Apr 2026 16:29:10 +0800 Liew Rui Yan <[email protected]>…
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.
Quoted 9 lines
Quoted 7 lines
[...]
The code changes look good to me.
Thank you for your review and patience.
You are always welcome.
Quoted 2 lines
Thanks,
SJ
[...]
SeongJae Park
maintainerQuoted 10 lines · On Fri, 3 Apr 2026 07:09:41 -0700 SeongJae Park <[email protected]> wrote:
Quoted 4 lines · On Fri, 3 Apr 2026 16:29:10 +0800 Liew Rui Yan <[email protected]>…
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
Quoted 18 lines
[...]
Thank you for all your answers to my questions and requests. That all make sense to me.
Quoted 9 lines
Quoted 7 lines
[...]
The code changes look good to me.
Thank you for your review and patience.
You are always welcome.
Quoted 1 line
Quoted 8 lines
Quoted 1 line
Thanks,
SJ[...]
Sent using hkml (https://github.com/sjp38/hackermail)