]>
Commit | Line | Data |
---|---|---|
b7ca0ba0 SL |
1 | From 15be35372524b63d964ac36f212f6b04f85977cb Mon Sep 17 00:00:00 2001 |
2 | From: Sasha Levin <sashal@kernel.org> | |
3 | Date: Tue, 12 Mar 2024 16:04:23 +0800 | |
4 | Subject: memtest: use {READ,WRITE}_ONCE in memory scanning | |
5 | ||
6 | From: Qiang Zhang <qiang4.zhang@intel.com> | |
7 | ||
8 | [ Upstream commit 82634d7e24271698e50a3ec811e5f50de790a65f ] | |
9 | ||
10 | memtest failed to find bad memory when compiled with clang. So use | |
11 | {WRITE,READ}_ONCE to access memory to avoid compiler over optimization. | |
12 | ||
13 | Link: https://lkml.kernel.org/r/20240312080422.691222-1-qiang4.zhang@intel.com | |
14 | Signed-off-by: Qiang Zhang <qiang4.zhang@intel.com> | |
15 | Cc: Bill Wendling <morbo@google.com> | |
16 | Cc: Justin Stitt <justinstitt@google.com> | |
17 | Cc: Nathan Chancellor <nathan@kernel.org> | |
18 | Cc: Nick Desaulniers <ndesaulniers@google.com> | |
19 | Cc: <stable@vger.kernel.org> | |
20 | Signed-off-by: Andrew Morton <akpm@linux-foundation.org> | |
21 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
22 | --- | |
23 | mm/memtest.c | 4 ++-- | |
24 | 1 file changed, 2 insertions(+), 2 deletions(-) | |
25 | ||
26 | diff --git a/mm/memtest.c b/mm/memtest.c | |
27 | index f53ace709ccd8..d407373f225b4 100644 | |
28 | --- a/mm/memtest.c | |
29 | +++ b/mm/memtest.c | |
30 | @@ -46,10 +46,10 @@ static void __init memtest(u64 pattern, phys_addr_t start_phys, phys_addr_t size | |
31 | last_bad = 0; | |
32 | ||
33 | for (p = start; p < end; p++) | |
34 | - *p = pattern; | |
35 | + WRITE_ONCE(*p, pattern); | |
36 | ||
37 | for (p = start; p < end; p++, start_phys_aligned += incr) { | |
38 | - if (*p == pattern) | |
39 | + if (READ_ONCE(*p) == pattern) | |
40 | continue; | |
41 | if (start_phys_aligned == last_bad + incr) { | |
42 | last_bad += incr; | |
43 | -- | |
44 | 2.43.0 | |
45 |