Skip to content

Commit 76b7069

Browse files
sjp38akpm00
authored andcommitted
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/[email protected] Fixes: f1d13ca ("mm/damon/sysfs: implement DAMOS tried regions update command") Signed-off-by: SeongJae Park <[email protected]> Cc: <[email protected]> [6.2.x] Signed-off-by: Andrew Morton <[email protected]>
1 parent c5155d4 commit 76b7069

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

mm/damon/sysfs.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,8 @@ static int damon_sysfs_set_targets(struct damon_ctx *ctx,
12081208
return 0;
12091209
}
12101210

1211+
static bool damon_sysfs_schemes_regions_updating;
1212+
12111213
static void damon_sysfs_before_terminate(struct damon_ctx *ctx)
12121214
{
12131215
struct damon_target *t, *next;
@@ -1219,8 +1221,10 @@ static void damon_sysfs_before_terminate(struct damon_ctx *ctx)
12191221
cmd = damon_sysfs_cmd_request.cmd;
12201222
if (kdamond && ctx == kdamond->damon_ctx &&
12211223
(cmd == DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS ||
1222-
cmd == DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES)) {
1224+
cmd == DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES) &&
1225+
damon_sysfs_schemes_regions_updating) {
12231226
damon_sysfs_schemes_update_regions_stop(ctx);
1227+
damon_sysfs_schemes_regions_updating = false;
12241228
mutex_unlock(&damon_sysfs_lock);
12251229
}
12261230

@@ -1340,7 +1344,6 @@ static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond)
13401344
static int damon_sysfs_cmd_request_callback(struct damon_ctx *c)
13411345
{
13421346
struct damon_sysfs_kdamond *kdamond;
1343-
static bool damon_sysfs_schemes_regions_updating;
13441347
bool total_bytes_only = false;
13451348
int err = 0;
13461349

0 commit comments

Comments
 (0)