Skip to contentSkip to conversation

x86/traps: use only one stub function for l/cstar

PATCH Superseded Wei Liu 2 participants 2 messages Nov 8, 2018 – Nov 9, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH 1/1 x86/traps: use only one stub function for l/cstar

And place it into .text.cold.

---
 xen/arch/x86/x86_64/traps.c | 20 +++++++++-----------
 xen/include/xen/init.h      |  1 +
 2 files changed, 10 insertions(+), 11 deletions(-)
xen/arch/x86/x86_64/traps.c +9 -11
index 4d506e2c18..55d60fedcd 100644
@@ -298,19 +298,13 @@ static unsigned int write_stub_trampoline(
 }
 
 DEFINE_PER_CPU(struct stubs, stubs);
-
-#ifdef CONFIG_PV
 void lstar_enter(void);
 void cstar_enter(void);
-#else
-static inline void lstar_enter(void)
-{
-    panic("%s called\n", __func__);
-}
 
-static inline void cstar_enter(void)
+#ifndef CONFIG_PV
+static void __cold lcstar_enter(void)
 {
-    panic("%s called\n", __func__);
+    panic("lstar/cstar\n");
 }
 #endif /* CONFIG_PV */
 
@@ -334,7 +328,9 @@ void subarch_percpu_traps_init(void)
     wrmsrl(MSR_LSTAR, stub_va);
     offset = write_stub_trampoline(stub_page + (stub_va & ~PAGE_MASK),
                                    stub_va, stack_bottom,
-                                   (unsigned long)lstar_enter);
+                                   IS_ENABLED(CONFIG_PV) ?
+                                   (unsigned long)lstar_enter :
+                                   (unsigned long)lcstar_enter);
     stub_va += offset;
 
     if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL ||
@@ -352,7 +348,9 @@ void subarch_percpu_traps_init(void)
     wrmsrl(MSR_CSTAR, stub_va);
     offset += write_stub_trampoline(stub_page + (stub_va & ~PAGE_MASK),
                                     stub_va, stack_bottom,
-                                    (unsigned long)cstar_enter);
+                                   IS_ENABLED(CONFIG_PV) ?
+                                   (unsigned long)cstar_enter :
+                                   (unsigned long)lcstar_enter);
 
     /* Don't consume more than half of the stub space here. */
     ASSERT(offset <= STUB_BUF_SIZE / 2);
xen/include/xen/init.h +1 -0
index db06c76fdf..c6b453adfe 100644
@@ -9,6 +9,7 @@
  */
 #define __init            __text_section(".init.text")
 #define __exit            __text_section(".exit.text")
+#define __cold            __text_section(".text.cold")
 #define __initdata        __section(".init.data")
 #define __initconst       __section(".init.rodata")
 #define __initconstrel    __section(".init.rodata.rel")
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 08.11.18 at 18:08, <[email protected]> wrote:
xen/arch/x86/x86_64/traps.c +0 -6
@@ -298,19 +298,13 @@ static unsigned int write_stub_trampoline(
 }
 
 DEFINE_PER_CPU(struct stubs, stubs);
-
-#ifdef CONFIG_PV
 void lstar_enter(void);
 void cstar_enter(void);
-#else
-static inline void lstar_enter(void)
-{
-    panic("%s called\n", __func__);

xen/arch/x86/x86_64/traps.c static unsigned int write_stub_trampoline( · line 309

Quoted 10 lines
xen/arch/x86/x86_64/traps.c +3 -3
-}
 
-static inline void cstar_enter(void)
+#ifndef CONFIG_PV
+static void __cold lcstar_enter(void)
 {
-    panic("%s called\n", __func__);
+    panic("lstar/cstar\n");
 }
 #endif /* CONFIG_PV */

While I'd be fine with this, ...

Quoted 12 lines
xen/arch/x86/x86_64/traps.c +3 -1
@@ -334,7 +328,9 @@ void subarch_percpu_traps_init(void)
     wrmsrl(MSR_LSTAR, stub_va);
     offset = write_stub_trampoline(stub_page + (stub_va & ~PAGE_MASK),
                                    stub_va, stack_bottom,
-                                   (unsigned long)lstar_enter);
+                                   IS_ENABLED(CONFIG_PV) ?
+                                   (unsigned long)lstar_enter :
+                                   (unsigned long)lcstar_enter);
     stub_va += offset;
 
     if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL ||

xen/arch/x86/x86_64/traps.c void subarch_percpu_traps_init(void) · line 353

Quoted 7 lines
xen/arch/x86/x86_64/traps.c +3 -1
@@ -352,7 +348,9 @@ void subarch_percpu_traps_init(void)
     wrmsrl(MSR_CSTAR, stub_va);
     offset += write_stub_trampoline(stub_page + (stub_va & ~PAGE_MASK),
                                     stub_va, stack_bottom,
-                                    (unsigned long)cstar_enter);
+                                   IS_ENABLED(CONFIG_PV) ?
+                                   (unsigned long)cstar_enter :
+                                   (unsigned long)lcstar_enter);

... to be honest I dislike this. Why not have a single star_enter() function with lstar_enter and cstar_enter being #define-s to it?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel