The patch titled Subject: mm/kmemleak: use READ_ONCE() for accessing jiffies_scan_wait has been added to the -mm tree. Its filename is mm-kmemleak-use-read_once-for-accessing-jiffies_scan_wait.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/mm-kmemleak-use-read_once-for-accessing-jiffies_scan_wait.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/mm-kmemleak-use-read_once-for-accessing-jiffies_scan_wait.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Yanfei Xu <yanfei.xu@xxxxxxxxxxxxx> Subject: mm/kmemleak: use READ_ONCE() for accessing jiffies_scan_wait The stop_scan_thread() and start_scan_thread() cannot really solve the problem of concurrent accessing the global jiffies_scan_wait. kmemleak_write kmemleak_scan_thread while (!kthread_should_stop()) stop_scan_thread jiffies_scan_wait = xxx timeout = jiffies_scan_wait start_scan_thread We could replace these with a READ_ONCE() when reading jiffies_scan_wait. It also can prevent compiler from reordering the jiffies_scan_wait which is in while loop. Link: https://lkml.kernel.org/r/20210609155657.26972-1-yanfei.xu@xxxxxxxxxxxxx Signed-off-by: Yanfei Xu <yanfei.xu@xxxxxxxxxxxxx> Cc: Catalin Marinas <catalin.marinas@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/kmemleak.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) --- a/mm/kmemleak.c~mm-kmemleak-use-read_once-for-accessing-jiffies_scan_wait +++ a/mm/kmemleak.c @@ -1567,7 +1567,7 @@ static int kmemleak_scan_thread(void *ar } while (!kthread_should_stop()) { - signed long timeout = jiffies_scan_wait; + signed long timeout = READ_ONCE(jiffies_scan_wait); mutex_lock(&scan_mutex); kmemleak_scan(); @@ -1812,11 +1812,8 @@ static ssize_t kmemleak_write(struct fil ret = kstrtoul(buf + 5, 0, &secs); if (ret < 0) goto out; - stop_scan_thread(); - if (secs) { + if (secs) jiffies_scan_wait = msecs_to_jiffies(secs * 1000); - start_scan_thread(); - } } else if (strncmp(buf, "scan", 4) == 0) kmemleak_scan(); else if (strncmp(buf, "dump=", 5) == 0) _ Patches currently in -mm which might be from yanfei.xu@xxxxxxxxxxxxx are mm-kmemleak-use-read_once-for-accessing-jiffies_scan_wait.patch