From: I Hsin Cheng <richard120310@gmail.com>
To: yury.norov@gmail.com
Cc: andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk,
linux-kernel@vger.kernel.org,
I Hsin Cheng <richard120310@gmail.com>
Subject: [PATCH] cpumask: Ensure the visibility of set_nr_cpu_ids
Date: Sun, 11 Aug 2024 17:25:01 +0800 [thread overview]
Message-ID: <20240811092501.87653-1-richard120310@gmail.com> (raw)
The variable "nr_cpu_ids" is a system-wide variable which should be seen
as consistent all the time. For example it's set in one of the kernel
setup procedure "prefill_possible_map", the operations here should
happens before all the code after setup, which means the operations here
should be visible to all the code after setup.
set_cpu_possible() ensure it's visibility because it eventually falls
into an atomic instruction, however the function "set_nr_cpu_ids()"
fails to make the guarantee since it only performs a normal write
operations.
Adding the macro "WRITE_ONCE()" will prevent the compiler from re-order
the instruction of the write operation for "nr_cpu_ids", so we can
guarantee the operation is visible to all the codes coming after it.
Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
---
include/linux/cpumask.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index f10fb87d4..3731f5e43 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -46,7 +46,7 @@ static inline void set_nr_cpu_ids(unsigned int nr)
#if (NR_CPUS == 1) || defined(CONFIG_FORCE_NR_CPUS)
WARN_ON(nr != nr_cpu_ids);
#else
- nr_cpu_ids = nr;
+ WRITE_ONCE(nr_cpu_ids, nr);
#endif
}
--
2.34.1
next reply other threads:[~2024-08-11 9:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-11 9:25 I Hsin Cheng [this message]
2024-08-11 15:18 ` [PATCH] cpumask: Ensure the visibility of set_nr_cpu_ids Yury Norov
2024-08-11 17:37 ` I Hsin Cheng
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=20240811092501.87653-1-richard120310@gmail.com \
--to=richard120310@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=yury.norov@gmail.com \
/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