提交 c91859b6 编写于 作者: Z ZhangPeng 提交者: Jialin Zhang

mm: slince possible data races about pgdat->kswapd

maillist inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I6PKGM

Reference: https://lore.kernel.org/linux-mm/20220824071909.192535-1-wangkefeng.wang@huawei.com/

--------------------------------

The pgdat->kswapd could be accessed concurrently by kswapd_run() and
kcompactd(), it don't be protected by any lock, which could leads to
data races, adding READ/WRITE_ONCE() to slince it.
Signed-off-by: NKefeng Wang <wangkefeng.wang@huawei.com>

Conflicts:
	mm/compaction.c
	mm/vmscan.c
Signed-off-by: NZhangPeng <zhangpeng362@huawei.com>
Reviewed-by: NKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
上级 d569f7f9
......@@ -1926,7 +1926,9 @@ static inline bool is_via_compact_memory(int order)
static bool kswapd_is_running(pg_data_t *pgdat)
{
return pgdat->kswapd && (pgdat->kswapd->state == TASK_RUNNING);
struct task_struct *t = READ_ONCE(pgdat->kswapd);
return t && (t->state == TASK_RUNNING);
}
/*
......
......@@ -4331,7 +4331,7 @@ int kswapd_run(int nid)
int ret = 0;
struct task_struct *t;
if (pgdat->kswapd)
if (READ_ONCE(pgdat->kswapd))
return 0;
t = kthread_run(kswapd, pgdat, "kswapd%d", nid);
......@@ -4341,7 +4341,7 @@ int kswapd_run(int nid)
pr_err("Failed to start kswapd on node %d\n", nid);
ret = PTR_ERR(t);
} else {
pgdat->kswapd = t;
WRITE_ONCE(pgdat->kswapd, t);
}
return ret;
}
......@@ -4352,11 +4352,11 @@ int kswapd_run(int nid)
*/
void kswapd_stop(int nid)
{
struct task_struct *kswapd = NODE_DATA(nid)->kswapd;
struct task_struct *kswapd = READ_ONCE(NODE_DATA(nid)->kswapd);
if (kswapd) {
kthread_stop(kswapd);
NODE_DATA(nid)->kswapd = NULL;
WRITE_ONCE(NODE_DATA(nid)->kswapd, NULL);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册