]> www.infradead.org Git - users/hch/configfs.git/commit
mm/damon/core: avoid overflow in damon_feed_loop_next_input()
authorSeongJae Park <sj@kernel.org>
Thu, 31 Oct 2024 16:12:03 +0000 (09:12 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 7 Nov 2024 22:14:59 +0000 (14:14 -0800)
commit4401e9d10ab0281a520b9f8c220f30f60b5c248f
tree9d36e1c84b3c714531be43b8c4ff0c04a67c1ddc
parent8e7bde615f634a82a44b1f3d293c049fd3ef9ca9
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: 9294a037c015 ("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>
mm/damon/core.c