[RFC PATCH 37/47] mm: asi: ASI annotation support for static variables.

Junaid Shahid
2022-02-23T05:28:07Z

From: Ofir Weisse <oweisse@google.com>

Added the following annotations:

__asi_not_sensitive: for static variables which are considered not
sensitive.

__asi_not_sensitive_readmostly: similar to __read_mostly, for
non-sensitive static variables.

Signed-off-by: Ofir Weisse <oweisse@google.com>

---
arch/x86/include/asm/asi.h | 12 ++++++++++++
include/asm-generic/asi.h | 6 ++++++
include/asm-generic/vmlinux.lds.h | 18 +++++++++++++++++-
3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/asi.h b/arch/x86/include/asm/asi.h
index bdb2f70d4f85..6dd9c7c8a2b8 100644
--- a/arch/x86/include/asm/asi.h
+++ b/arch/x86/include/asm/asi.h
@@ -177,6 +177,18 @@ static inline pgd_t *asi_pgd(struct asi *asi)
return asi->pgd;
}

+/* IMPORTANT: Any modification to the name here should also be applied to
+ * include/asm-generic/vmlinux.lds.h */
+#define ASI_NON_SENSITIVE_SECTION_NAME ".data..asi_non_sensitive"
+#define ASI_NON_SENSITIVE_READ_MOSTLY_SECTION_NAME \
+ ".data..asi_non_sensitive_readmostly"
+
+#define __asi_not_sensitive \
+ __section(ASI_NON_SENSITIVE_SECTION_NAME)
+
+#define __asi_not_sensitive_readmostly \
+ __section(ASI_NON_SENSITIVE_READ_MOSTLY_SECTION_NAME)
+
#else /* CONFIG_ADDRESS_SPACE_ISOLATION */

static inline void asi_intr_enter(void) { }
diff --git a/include/asm-generic/asi.h b/include/asm-generic/asi.h
index fffb323d2a00..d9082267a5dd 100644
--- a/include/asm-generic/asi.h
+++ b/include/asm-generic/asi.h
@@ -121,6 +121,12 @@ void asi_flush_tlb_range(struct asi *asi, void *addr, size_t len) { }
#define static_asi_enabled() false

+/* IMPORTANT: Any modification to the name here should also be applied to
+ * include/asm-generic/vmlinux.lds.h */
+
+#define __asi_not_sensitive
+#define __asi_not_sensitive_readmostly
+
#endif /* !_ASSEMBLY_ */

#endif /* !CONFIG_ADDRESS_SPACE_ISOLATION */
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 42f3866bca69..c769d939c15f 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -374,10 +374,26 @@
. = ALIGN(PAGE_SIZE); \
__nosave_end = .;

+#ifdef CONFIG_ADDRESS_SPACE_ISOLATION
+#define ASI_NOT_SENSITIVE_DATA(page_align) \
+ . = ALIGN(page_align); \
+ __start_asi_nonsensitive = .; \
+ *(.data..asi_non_sensitive) \
+ . = ALIGN(page_align); \
+ __end_asi_nonsensitive = .; \
+ __start_asi_nonsensitive_readmostly = .; \
+ *(.data..asi_non_sensitive_readmostly) \
+ . = ALIGN(page_align); \
+ __end_asi_nonsensitive_readmostly = .;
+#else
+#define ASI_NOT_SENSITIVE_DATA
+#endif
+
#define PAGE_ALIGNED_DATA(page_align) \
. = ALIGN(page_align); \
*(.data..page_aligned) \
- . = ALIGN(page_align);
+ . = ALIGN(page_align); \
+ ASI_NOT_SENSITIVE_DATA(page_align)

#define READ_MOSTLY_DATA(align) \
. = ALIGN(align); \
--
2.35.1.473.g83b2b277ed-goog