linux/mm/damon
SeongJae Park 4401e9d10a mm/damon/core: avoid overflow in damon_feed_loop_next_input()
damon_feed_loop_next_input() is inefficient and fragile to overflows. 
Specifically, 'score_goal_diff_bp' calculation can overflow when 'score'
is high.  The calculation is actually unnecessary at all because 'goal' is
a constant of value 10,000.  Calculation of 'compensation' is again
fragile to overflow.  Final calculation of return value for under-achiving
case is again fragile to overflow when the current score is
under-achieving the target.

Add two corner cases handling at the beginning of the function to make the
body easier to read, and rewrite the body of the function to avoid
overflows and the unnecessary bp value calcuation.

Link: https://lkml.kernel.org/r/20241031161203.47751-1-sj@kernel.org
Fixes: 9294a037c0 ("mm/damon/core: implement goal-oriented feedback-driven quota auto-tuning")
Signed-off-by: SeongJae Park <sj@kernel.org>
Reported-by: Guenter Roeck <linux@roeck-us.net>
Closes: https://lore.kernel.org/944f3d5b-9177-48e7-8ec9-7f1331a3fea3@roeck-us.net
Tested-by: Guenter Roeck <linux@roeck-us.net>
Cc: <stable@vger.kernel.org>	[6.8.x]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-11-07 14:14:59 -08:00
..
tests mm/damon/tests/sysfs-kunit.h: fix memory leak in damon_sysfs_test_add_targets() 2024-10-17 00:28:08 -07:00
core.c mm/damon/core: avoid overflow in damon_feed_loop_next_input() 2024-11-07 14:14:59 -08:00
dbgfs.c mm/damon: move kunit tests to tests/ subdirectory with _kunit suffix 2024-09-03 21:15:58 -07:00
Kconfig mm/damon/Kconfig: update DAMON doc URL 2024-09-26 14:01:44 -07:00
lru_sort.c Revert "mm/damon/lru_sort: adjust local variable to dynamic allocation" 2024-09-09 16:39:00 -07:00
Makefile
modules-common.c mm/damon: update email of SeongJae 2023-12-20 14:48:13 -08:00
modules-common.h
ops-common.c mm/damon/ops-common: avoid divide-by-zero during region hotness calculation 2023-10-25 16:47:15 -07:00
ops-common.h
paddr.c mm/damon/paddr: initialize nr_succeeded in __damon_pa_migrate_folio_list() 2024-07-04 18:05:50 -07:00
reclaim.c mm/damon/reclaim: remove unnecessary code for online tuning 2024-07-03 19:30:14 -07:00
sysfs-common.c
sysfs-common.h mm/damon/sysfs-schemes: rename *_set_{schemes,scheme_filters,quota_score,schemes}() 2024-07-03 19:30:14 -07:00
sysfs-schemes.c mm/damon/sysfs-schemes: rename *_set_{schemes,scheme_filters,quota_score,schemes}() 2024-07-03 19:30:14 -07:00
sysfs.c mm/damon: move kunit tests to tests/ subdirectory with _kunit suffix 2024-09-03 21:15:58 -07:00
vaddr.c ALong with the usual shower of singleton patches, notable patch series in 2024-09-21 07:29:05 -07:00