From: Yanfei Xu <yanfei.xu@windriver.com>
To: catalin.marinas@arm.com, akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH] mm/kmemleak: use READ_ONCE() for accessing jiffies_scan_wait
Date: Wed, 9 Jun 2021 23:56:57 +0800 [thread overview]
Message-ID: <20210609155657.26972-1-yanfei.xu@windriver.com> (raw)
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.
Signed-off-by: Yanfei Xu <yanfei.xu@windriver.com>
---
mm/kmemleak.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 92a2d4885808..5ccf3969b7fe 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1567,7 +1567,7 @@ static int kmemleak_scan_thread(void *arg)
}
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 file *file, const char __user *user_buf,
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)
--
2.27.0
next reply other threads:[~2021-06-09 15:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-09 15:56 Yanfei Xu [this message]
[not found] ` <20210611085913.GA8132@arm.com>
[not found] ` <833a5523-3e49-2554-178d-cba7cbe71b7a@windriver.com>
2021-06-13 17:49 ` [PATCH] mm/kmemleak: use READ_ONCE() for accessing jiffies_scan_wait Xu, Yanfei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210609155657.26972-1-yanfei.xu@windriver.com \
--to=yanfei.xu@windriver.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).