Skip to content

mm/damon: validate min_region_size to be power of 2

Liew Rui Yan damon linux-mm 5 versions – Applied

Status from this message: [merged mm-stable] mm-damon-reclaim-validate-min_region_size-to-be-power-of-2.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest2 patches 4 repliesApplied 2/2
  2. v42 patches 17 repliesSuperseded
  3. v32 patches 14 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v21 patch6 repliesSuperseded
v11 patch5 repliesSuperseded

Changes in v5 from the cover letter

(https://lore.kernel.org/[email protected])
- Clarify this is only a minor user experience improvement.
- Remove Fixes: and Cc: stable tags.

Patches in v5 All 2 applied

#Subject and filesSizeRepliesApplied
1/2mm/damon/lru_sort: validate min_region_size to be power of 2mm/damon/lru_sort.c+5 -02 repliesApplied
2/2mm/damon/reclaim: validate min_region_size to be power of 2mm/damon/reclaim.c+5 -01 replyApplied

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchSeongJae Park
1/2R-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v5 thread

Cover letter [PATCH v5 0/2] mm/damon: validate min_region_size to be power of 2

Problem
=======
When a user sets an invalid 'addr_unit' (e.g., 3) via DAMON_LRU_SORT or DAMON_RECLAIM, 'min_region_sz' becomes a non-power-of-2 value. While damon_commit_ctx() correctly detects this and returns -EINVAL, it sets the 'maybe_corrupted' flag during this process.

This flag causes the running kdamond to terminate. While the termination is a safety measure, it is suboptimal in this case because the error is just a simple invalid input from the user, which shouldn't neccessitate stopping the kdamond.

Solution
========
Add an early validation in damon_lru_sort_apply_parameters() and damon_reclaim_apply_parameters() to check 'min_region_sz' before any state change occurs. If it is non-power-of-2, return -EINVAL immediately, preventing 'maybe_corrupted' from being set.

Patch 1 fixes the issue for DAMON_LRU_SORT.
Patch 2 fixes the issue for DAMON_RECLAIM.

Changes from v4
(https://lore.kernel.org/[email protected])
- Clarify this is only a minor user experience improvement.
- Remove Fixes: and Cc: stable tags.
Changes from v3
(https://lore.kernel.org/[email protected])
- Improve commit message: clarify "unexpected termination".
- Add detailed User Impact with reason why kdamond cannot be restarted. Changes from v2
(https://lore.kernel.org/[email protected])
- Split the patch into two per-module patches.
- Add Fixes: and Cc: stable tags.
- Elaborate user impact and reproduction steps.
Changes from v1
(https://lore.kernel.org/[email protected])
- Fix memory leak issue.
Changes from first attempt
(https://lore.kernel.org/[email protected])
- Renamed the subject.
- Validate min_region_sz rather than addr_unit.

Liew Rui Yan (2):
mm/damon/lru_sort: validate min_region_size to be power of 2 mm/damon/reclaim: validate min_region_size to be power of 2

 mm/damon/lru_sort.c | 5 +++++
 mm/damon/reclaim.c  | 5 +++++
 2 files changed, 10 insertions(+)
Signature · 1 line
2.53.0