[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240811092501.87653-1-richard120310@gmail.com>
Date: Sun, 11 Aug 2024 17:25:01 +0800
From: I Hsin Cheng <richard120310@...il.com>
To: yury.norov@...il.com
Cc: andriy.shevchenko@...ux.intel.com,
linux@...musvillemoes.dk,
linux-kernel@...r.kernel.org,
I Hsin Cheng <richard120310@...il.com>
Subject: [PATCH] cpumask: Ensure the visibility of set_nr_cpu_ids
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@...il.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
Powered by blists - more mailing lists