]> xenbits.xensource.com Git - xen.git/commitdiff
xen/arch: Centralise __read_mostly and __ro_after_init
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 14 Jun 2024 12:05:40 +0000 (13:05 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 19 Jun 2024 12:00:06 +0000 (13:00 +0100)
These living in cache.h is inherited from Linux, but cache.h is not a terribly
appropriately location for them to live.

__read_mostly is an optimisation related to data placement in order to avoid
having shared data in cachelines that are likely to be written to, but it
really is just a section of the linked image separating data by usage
patterns; it has nothing to do with cache sizes or flushing logic.

Worse, __ro_after_init was only in xen/cache.h because __read_mostly was in
arch/cache.h, and has literally nothing whatsoever to do with caches.

Move the definitions into xen/sections.h, which in particular means that
RISC-V doesn't need to repeat the problematic pattern.  Take the opportunity
to provide a short descriptions of what these are used for.

For now, leave TODO comments next to the other identical definitions.  It
turns out that unpicking cache.h is more complicated than it appears because a
number of files use it for transitive dependencies.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Release-Acked-By: Oleksii Kurochko <oleksii.kurochko@gmail.com>
xen/arch/arm/include/asm/cache.h
xen/arch/ppc/include/asm/cache.h
xen/arch/x86/include/asm/cache.h
xen/include/xen/cache.h
xen/include/xen/sections.h

index 240b6ae0eaa389699f9d49d076b569b9fc89b99b..029b2896fb3e12a5c52978df6a7a60033fd91632 100644 (file)
@@ -6,6 +6,7 @@
 #define L1_CACHE_SHIFT  (CONFIG_ARM_L1_CACHE_SHIFT)
 #define L1_CACHE_BYTES  (1 << L1_CACHE_SHIFT)
 
+/* TODO: Phase out the use of this via cache.h */
 #define __read_mostly __section(".data.read_mostly")
 
 #endif
index 0d7323d7892fd2e40e02607ba96db99157aa287b..13c0bf3242c8d1176b52ade6a0ce432976869bbb 100644 (file)
@@ -3,6 +3,7 @@
 #ifndef _ASM_PPC_CACHE_H
 #define _ASM_PPC_CACHE_H
 
+/* TODO: Phase out the use of this via cache.h */
 #define __read_mostly __section(".data.read_mostly")
 
 #endif /* _ASM_PPC_CACHE_H */
index e4770efb22b9eeafafc7379941c38e5f46140a6e..956c05493e234e9fed4bbace7e2394cfedf4bfe5 100644 (file)
@@ -9,6 +9,7 @@
 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
 #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
 
+/* TODO: Phase out the use of this via cache.h */
 #define __read_mostly __section(".data.read_mostly")
 
 #ifndef __ASSEMBLY__
index f52a0aedf7680593fcaa724b6788b768b09f3594..55456823c543021243c7fea65fff6372ffb7d523 100644 (file)
@@ -15,6 +15,7 @@
 #define __cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
 #endif
 
+/* TODO: Phase out the use of this via cache.h */
 #define __ro_after_init __section(".data.ro_after_init")
 
 #endif /* __LINUX_CACHE_H */
index b6cb5604c2852835f135822fac418472e0eb4ae3..f2fac8d7fa29cf2f0d06c8a048a7490647af5cd3 100644 (file)
@@ -3,9 +3,30 @@
 #ifndef __XEN_SECTIONS_H__
 #define __XEN_SECTIONS_H__
 
+#include <xen/compiler.h>
+
 /* SAF-0-safe */
 extern char __init_begin[], __init_end[];
 
+/*
+ * Some data is expected to be written rarely (if at all).
+ *
+ * For performance reasons is it helpful to group such data in the build, to
+ * avoid the linker placing it adjacent to often-written data.
+ */
+#define __read_mostly __section(".data.read_mostly")
+
+/*
+ * Some data should be chosen during boot and be immutable thereafter.
+ *
+ * Variables annotated with __ro_after_init will become read-only after boot
+ * and suffer a runtime access fault if modified.
+ *
+ * For architectures/platforms which haven't implemented support, these
+ * variables will be treated as regular mutable data.
+ */
+#define __ro_after_init __section(".data.ro_after_init")
+
 #endif /* !__XEN_SECTIONS_H__ */
 /*
  * Local variables: