mm/damon/sysfs: check DAMOS regions update progress from before_terminate()
authorSeongJae Park <sj@kernel.org>
Sat, 7 Oct 2023 20:04:32 +0000 (20:04 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 18 Oct 2023 19:12:41 +0000 (12:12 -0700)
commit76b7069bcc89dec33f03eb08abee165d0306b754
treefca97c9e9f9146fe994d2222c5a8710614956ef5
parentc5155d4ef4b2ac03cb5838b4060ab2ceb7dbda09
mm/damon/sysfs: check DAMOS regions update progress from before_terminate()

DAMON_SYSFS can receive DAMOS tried regions update request while kdamond
is already out of the main loop and before_terminate callback
(damon_sysfs_before_terminate() in this case) is not yet called.  And
damon_sysfs_handle_cmd() can further be finished before the callback is
invoked.  Then, damon_sysfs_before_terminate() unlocks damon_sysfs_lock,
which is not locked by anyone.  This happens because the callback function
assumes damon_sysfs_cmd_request_callback() should be called before it.
Check if the assumption was true before doing the unlock, to avoid this
problem.

Link: https://lkml.kernel.org/r/20231007200432.3110-1-sj@kernel.org
Fixes: f1d13cacabe1 ("mm/damon/sysfs: implement DAMOS tried regions update command")
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: <stable@vger.kernel.org> [6.2.x]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/sysfs.c