Skip to contentSkip to conversation

x86: arrange for ENDBR zapping from <vendor>_ctxt_switch_masking()

PATCH In review Jan Beulich 2 participants 3 messages Jan 16, 2024 – Feb 2, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: arrange for ENDBR zapping from <vendor>_ctxt_switch_masking()

While altcall is already used for them, the functions want announcing in .init.rodata.cf_clobber, even if the resulting static variables aren't otherwise used.

While doing this also move ctxt_switch_masking to .data.ro_after_init.

xen/arch/x86/cpu/amd.c +5 -0
@@ -258,6 +258,11 @@ static void cf_check amd_ctxt_switch_mas
 #undef LAZY
 }
 
+#ifdef CONFIG_XEN_IBT /* Announce the function to ENDBR clobbering logic. */
+static const typeof(ctxt_switch_masking) __initconst_cf_clobber __used csm =
+    amd_ctxt_switch_masking;
+#endif
+
 /*
  * Mask the features and extended features returned by CPUID.  Parameters are
  * set from the boot line via two methods:
xen/arch/x86/cpu/common.c +1 -1
@@ -119,7 +119,7 @@ static const struct cpu_dev __initconst_
 static const struct cpu_dev *this_cpu = &default_cpu;
 
 static DEFINE_PER_CPU(uint64_t, msr_misc_features);
-void (* __read_mostly ctxt_switch_masking)(const struct vcpu *next);
+void (* __ro_after_init ctxt_switch_masking)(const struct vcpu *next);
 
 bool __init probe_cpuid_faulting(void)
 {
xen/arch/x86/cpu/intel.c +5 -0
@@ -220,6 +220,11 @@ static void cf_check intel_ctxt_switch_m
 #undef LAZY
 }
 
+#ifdef CONFIG_XEN_IBT /* Announce the function to ENDBR clobbering logic. */
+static const typeof(ctxt_switch_masking) __initconst_cf_clobber __used csm =
+    intel_ctxt_switch_masking;
+#endif
+
 /*
  * opt_cpuid_mask_ecx/edx: cpuid.1[ecx, edx] feature mask.
  * For example, E8400[Intel Core 2 Duo Processor series] ecx = 0x0008E3FD,
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jan Beulich

While altcall is already used for them, the functions want announcing in .init.rodata.cf_clobber, even if the resulting static variables aren't otherwise used.

While doing this also move ctxt_switch_masking to .data.ro_after_init.

xen/arch/x86/cpu/amd.c static void cf_check amd_ctxt_switch_mas · line 264

Quoted 11 lines
xen/arch/x86/cpu/amd.c +4 -0
@@ -258,6 +258,11 @@ static void cf_check amd_ctxt_switch_mas
 #undef LAZY
 }
 
+#ifdef CONFIG_XEN_IBT /* Announce the function to ENDBR clobbering logic. */
+static const typeof(ctxt_switch_masking) __initconst_cf_clobber __used csm =
+    amd_ctxt_switch_masking;
+#endif

If we gain more of these, I suspect we'll want a wrapper for it.

Irritatingly you can't pass parameters into global asm, because the nice way to do this would be an _ASM_PTR in a pushsection.

~Andrew

#2 lore raw
Quoted 10 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich

While altcall is already used for them, the functions want announcing in .init.rodata.cf_clobber, even if the resulting static variables aren't otherwise used.

While doing this also move ctxt_switch_masking to .data.ro_after_init.

Thanks.

Quoted 13 lines

xen/arch/x86/cpu/amd.c static void cf_check amd_ctxt_switch_mas · line 264

Quoted 10 lines
xen/arch/x86/cpu/amd.c +4 -0
@@ -258,6 +258,11 @@ static void cf_check amd_ctxt_switch_mas
 #undef LAZY
 }
 
+#ifdef CONFIG_XEN_IBT /* Announce the function to ENDBR clobbering logic. */
+static const typeof(ctxt_switch_masking) __initconst_cf_clobber __used csm =
+    amd_ctxt_switch_masking;
+#endif

If we gain more of these, I suspect we'll want a wrapper for it.

Quoted 2 lines

Irritatingly you can't pass parameters into global asm, because the nice way to do this would be an _ASM_PTR in a pushsection.

While I'm not convinced resorting to asm() here would indeed be a good thing, for very many years I've been carrying a gcc change to permit exactly this. I don't even recall anymore why it wasn't liked upstream.

Jan