Skip to contentSkip to conversation

x86/asm: Mark all top level asm statements as .text

PATCH In review Andi Kleen 4 participants 20 messages Mar 30, 2019 – May 8, 2019

Subsystems (6)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH v2 1/9 x86/asm: Mark all top level asm statements as .text

From: Andi Kleen <[email protected]>

With gcc toplevel assembler statements that do not mark themselves as .text may end up in other sections. I had LTO boot crashes because various assembler statements ended up in the middle of the initcall section. It's also a latent problem without LTO, although it's currently not known to cause any real problems.

According to the gcc team it's expected behavior.

Always mark all the top level assembler statements as text so that they switch to the right section.

---
 arch/x86/kernel/cpu/amd.c      | 3 ++-
 arch/x86/kernel/kprobes/core.c | 1 +
 arch/x86/lib/error-inject.c    | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/amd.c +2 -1
index 01004bfb1a1b..1bcb489e07e7 100644
@@ -83,7 +83,8 @@ static inline int wrmsrl_amd_safe(unsigned msr, unsigned long long val)
  */
 
 extern __visible void vide(void);
-__asm__(".globl vide\n"
+__asm__(".text\n"
+	".globl vide\n"
 	".type vide, @function\n"
 	".align 4\n"
 	"vide: ret\n");
arch/x86/kernel/kprobes/core.c +1 -0
index a034cb808e7e..31ab91c9c4e9 100644
@@ -715,6 +715,7 @@ NOKPROBE_SYMBOL(kprobe_int3_handler);
  * calls trampoline_handler() runs, which calls the kretprobe's handler.
  */
 asm(
+	".text\n"
 	".global kretprobe_trampoline\n"
 	".type kretprobe_trampoline, @function\n"
 	"kretprobe_trampoline:\n"
arch/x86/lib/error-inject.c +1 -0
index 3cdf06128d13..be5b5fb1598b 100644
@@ -6,6 +6,7 @@
 asmlinkage void just_return_func(void);
 
 asm(
+	".text\n"
 	".type just_return_func, @function\n"
 	".globl just_return_func\n"
 	"just_return_func:\n"
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH v2 2/9 x86/cpu/amd: Ifdef 32bit only assembler for 32bit

From: Andi Kleen <[email protected]>

The "vide" inline assembler is only needed on 32bit kernels for old 32bit only CPUs. Ifdef it to not include it into 64bit kernels.

---
 arch/x86/kernel/cpu/amd.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kernel/cpu/amd.c +2 -0
index 1bcb489e07e7..fb6a64bd765f 100644
@@ -82,12 +82,14 @@ static inline int wrmsrl_amd_safe(unsigned msr, unsigned long long val)
  *	performance at the same time..
  */
 
+#ifdef CONFIG_X86_32
 extern __visible void vide(void);
 __asm__(".text\n"
 	".globl vide\n"
 	".type vide, @function\n"
 	".align 4\n"
 	"vide: ret\n");
+#endif
 
 static void init_amd_k5(struct cpuinfo_x86 *c)
 {
Signature · 1 line
2.20.1
#2 lore raw

[tip:x86/asm] x86/cpu/amd: Exclude 32bit only assembler from 64bit build

x86/cpu/amd: Exclude 32bit only assembler from 64bit build
Commit-ID:  26b31f46f036ad89de20cbbb732b76289411eddb
Gitweb:     https://git.kernel.org/tip/26b31f46f036ad89de20cbbb732b76289411eddb
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 29 Mar 2019 17:47:36 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 19 Apr 2019 17:47:35 +0200

x86/cpu/amd: Exclude 32bit only assembler from 64bit build

The "vide" inline assembler is only needed on 32bit kernels for old 32bit only CPUs.

Guard it with an #ifdef so it's not included in 64bit builds.

---
 arch/x86/kernel/cpu/amd.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kernel/cpu/amd.c +2 -0
index 1bcb489e07e7..fb6a64bd765f 100644
@@ -82,12 +82,14 @@ static inline int wrmsrl_amd_safe(unsigned msr, unsigned long long val)
  *	performance at the same time..
  */
 
+#ifdef CONFIG_X86_32
 extern __visible void vide(void);
 __asm__(".text\n"
 	".globl vide\n"
 	".type vide, @function\n"
 	".align 4\n"
 	"vide: ret\n");
+#endif
 
 static void init_amd_k5(struct cpuinfo_x86 *c)
 {
author
#3 lore raw

PATCH v2 3/9 x86/paravirt: Replace paravirt patches with data

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

For LTO all top level assembler statements need to be global because LTO might put it into a different assembler file than the referencing C code.

To avoid making all the paravirt patch snippets global replace them with data containing the patch instructions. Since these are unlikely to change this shouldn't be a significant maintenance burden.

---
 arch/x86/include/asm/paravirt_types.h |  6 +---
 arch/x86/kernel/paravirt_patch_32.c   | 33 +++++++++++----------
 arch/x86/kernel/paravirt_patch_64.c   | 42 +++++++++++++++------------
 3 files changed, 42 insertions(+), 39 deletions(-)
arch/x86/include/asm/paravirt_types.h +1 -5
index 2474e434a6f7..bb13e79d4344 100644
@@ -367,12 +367,8 @@ extern struct paravirt_patch_template pv_ops;
 #define paravirt_alt(insn_string)					\
 	_paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
 
-/* Simple instruction patching code. */
-#define NATIVE_LABEL(a,x,b) "\n\t.globl " a #x "_" #b "\n" a #x "_" #b ":\n\t"
-
 #define DEF_NATIVE(ops, name, code)					\
-	__visible extern const char start_##ops##_##name[], end_##ops##_##name[];	\
-	asm(NATIVE_LABEL("start_", ops, name) code NATIVE_LABEL("end_", ops, name))
+	const char start_##ops##_##name[] = code
 
 unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len);
 unsigned paravirt_patch_default(u8 type, void *insnbuf,
arch/x86/kernel/paravirt_patch_32.c +18 -15
index de138d3912e4..9a649026d74c 100644
@@ -2,14 +2,14 @@
 #include <asm/paravirt.h>
 
 #ifdef CONFIG_PARAVIRT_XXL
-DEF_NATIVE(irq, irq_disable, "cli");
-DEF_NATIVE(irq, irq_enable, "sti");
-DEF_NATIVE(irq, restore_fl, "push %eax; popf");
-DEF_NATIVE(irq, save_fl, "pushf; pop %eax");
-DEF_NATIVE(cpu, iret, "iret");
-DEF_NATIVE(mmu, read_cr2, "mov %cr2, %eax");
-DEF_NATIVE(mmu, write_cr3, "mov %eax, %cr3");
-DEF_NATIVE(mmu, read_cr3, "mov %cr3, %eax");
+static const unsigned char patch_irq_irq_disable[] = { 0xfa }; 	  	/* cli */
+static const unsigned char patch_irq_irq_enable[] = { 0xfb };  	  	/* sti */
+static const unsigned char patch_irq_restore_fl[] =  { 0x50, 0x9d }; 	/* push %eax; popf */
+static const unsigned char patch_irq_save_fl[] = { 0x9c, 0x58 };  	/* pushf; pop %eax */
+static const unsigned char patch_cpu_iret[] = { 0xcf };		  	/* iret */
+static const unsigned char patch_mmu_read_cr2[] = { 0x0f, 0x20, 0xd0 }; /* mov %cr2, %eax */
+static const unsigned char patch_mmu_write_cr3[] = { 0x0f, 0x22, 0xd8 };/* mov %eax, %cr3 */
+static const unsigned char patch_mmu_read_cr3[] = { 0x0f, 0x20, 0xd8 }; /* mov %cr3, %eax */
 
 unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len)
 {
@@ -19,8 +19,8 @@ unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len)
 #endif
 
 #if defined(CONFIG_PARAVIRT_SPINLOCKS)
-DEF_NATIVE(lock, queued_spin_unlock, "movb $0, (%eax)");
-DEF_NATIVE(lock, vcpu_is_preempted, "xor %eax, %eax");
+static const unsigned char patch_lock_queued_spin_unlock[] = { 0xc6, 0x00, 0x00 }; /* movb $0, (%eax) */
+static const unsigned char patch_lock_vcpu_is_preempted[] =  { 0x31, 0xc0 }; 	 /* xor %eax, %eax */
 #endif
 
 extern bool pv_is_native_spin_unlock(void);
@@ -30,7 +30,8 @@ unsigned native_patch(u8 type, void *ibuf, unsigned long addr, unsigned len)
 {
 #define PATCH_SITE(ops, x)					\
 	case PARAVIRT_PATCH(ops.x):				\
-		return paravirt_patch_insns(ibuf, len, start_##ops##_##x, end_##ops##_##x)
+		return paravirt_patch_insns(ibuf, len, 		\
+				patch_##ops##_##x, patch_##ops##_##x+sizeof(patch_##ops##_x));
 
 	switch (type) {
 #ifdef CONFIG_PARAVIRT_XXL
@@ -47,15 +48,17 @@ unsigned native_patch(u8 type, void *ibuf, unsigned long addr, unsigned len)
 	case PARAVIRT_PATCH(lock.queued_spin_unlock):
 		if (pv_is_native_spin_unlock())
 			return paravirt_patch_insns(ibuf, len,
-						    start_lock_queued_spin_unlock,
-						    end_lock_queued_spin_unlock);
+						    patch_lock_queued_spin_unlock,
+						    patch_lock_queued_spin_unlock +
+						    sizeof(patch_lock_queued_spin_unlock));
 		break;
 
 	case PARAVIRT_PATCH(lock.vcpu_is_preempted):
 		if (pv_is_native_vcpu_is_preempted())
 			return paravirt_patch_insns(ibuf, len,
-						    start_lock_vcpu_is_preempted,
-						    end_lock_vcpu_is_preempted);
+						    patch_lock_vcpu_is_preempted,
+						    patch_lock_vcpu_is_preempted +
+						    sizeof(patch_lock_vcpu_is_preempted));
 		break;
 #endif
 
arch/x86/kernel/paravirt_patch_64.c +23 -19

74 lines not on this page · raw message

Signature · 1 line
2.20.1
#4 lore raw

Re: [PATCH v2 3/9] x86/paravirt: Replace paravirt patches with data

Quoted 7 lines · Andi Kleen

For LTO all top level assembler statements need to be global because LTO might put it into a different assembler file than the referencing C code.

To avoid making all the paravirt patch snippets global replace them with data containing the patch instructions. Since these are unlikely to change this shouldn't be a significant maintenance burden.

s/with data containing/with unparseable, inconsistent and broken mess/

Unparseable:
------------

arch/x86/kernel/paravirt_patch_32.c line 12

Quoted 5 lines
arch/x86/kernel/paravirt_patch_32.c +5 -0
+static const unsigned char patch_irq_save_fl[] = { 0x9c, 0x58 };  	/* pushf; pop %eax */
+static const unsigned char patch_cpu_iret[] = { 0xcf };		  	/* iret */
+static const unsigned char patch_mmu_read_cr2[] = { 0x0f, 0x20, 0xd0 }; /* mov %cr2, %eax */
+static const unsigned char patch_mmu_write_cr3[] = { 0x0f, 0x22, 0xd8 };/* mov %eax, %cr3 */
+static const unsigned char patch_mmu_read_cr3[] = { 0x0f, 0x20, 0xd8 }; /* mov %cr3, %eax */

Overlong lines, spaces and tabs mixed, no formatting which allows easy reading and review.

Inconsistent and unparseable:
-----------------------------

arch/x86/kernel/paravirt_patch_32.c unsigned native_patch(u8 type, void *ibuf, unsigned long addr, unsigned len) · line 34

Quoted 5 lines

#define PATCH_SITE(ops, x) \

arch/x86/kernel/paravirt_patch_32.c +2 -1
 	case PARAVIRT_PATCH(ops.x):				\
-		return paravirt_patch_insns(ibuf, len, start_##ops##_##x, end_##ops##_##x)
+		return paravirt_patch_insns(ibuf, len, 		\
+				patch_##ops##_##x, patch_##ops##_##x+sizeof(patch_##ops##_x));

vs.

arch/x86/kernel/paravirt_patch_64.c unsigned native_patch(u8 type, void *ibuf, unsigned long addr, unsigned len) · line 41

Quoted 2 lines
arch/x86/kernel/paravirt_patch_64.c +2 -0
+		return paravirt_patch_insns(ibuf, len, start_##ops##_##x, \
+				patch_##ops##_##x + sizeof(patch_##ops##_##x));

Broken:
-------

Quoted 1 line

+static const unsigned char patch_irq_restore_fl[] = { 0x50, 0x9d}; /* pushq %rdi; popfq */

Can you spot the fail?

That probably works because Intel CPUs are so good at executing crappy code, right? That's at least what you told me recently. If that's the proof then I should really stop reviewing patches.

Thanks,

tglx

author
#5 lore raw

PATCH v2 4/9 x86/timer: Don't inline __const_udelay

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

LTO will happily inline __const_udelay everywhere it is used. Forcing it noinline saves ~44k text in a LTO build.

13999560        1740864 1499136 17239560        1070e08 vmlinux-with-udelay-inline
13954764        1736768 1499136 17190668        1064f0c vmlinux-wo-udelay-inline

Even without LTO I believe marking it noinline documents it correctly.

---
 arch/x86/lib/delay.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/lib/delay.c +1 -1
index f5b7f1b3b6d7..b7375dc6898f 100644
@@ -162,7 +162,7 @@ void __delay(unsigned long loops)
 }
 EXPORT_SYMBOL(__delay);
 
-void __const_udelay(unsigned long xloops)
+noinline void __const_udelay(unsigned long xloops)
 {
 	unsigned long lpj = this_cpu_read(cpu_info.loops_per_jiffy) ? : loops_per_jiffy;
 	int d0;
Signature · 1 line
2.20.1
#6 lore raw

[tip:x86/timers] x86/timer: Don't inline __const_udelay()

x86/timer: Don't inline __const_udelay()
Commit-ID:  81423c37415fe45057d64196ae0ce8e17a9c7148
Gitweb:     https://git.kernel.org/tip/81423c37415fe45057d64196ae0ce8e17a9c7148
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 29 Mar 2019 17:47:38 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 19 Apr 2019 17:49:47 +0200

x86/timer: Don't inline __const_udelay()

LTO will happily inline __const_udelay() everywhere it is used. Forcing it noinline saves ~44k text in a LTO build.

13999560        1740864 1499136 17239560        1070e08 vmlinux-with-udelay-inline
13954764        1736768 1499136 17190668        1064f0c vmlinux-wo-udelay-inline

Even without LTO this function should never be inlined.

---
 arch/x86/lib/delay.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/lib/delay.c +1 -1
index f5b7f1b3b6d7..b7375dc6898f 100644
@@ -162,7 +162,7 @@ void __delay(unsigned long loops)
 }
 EXPORT_SYMBOL(__delay);
 
-void __const_udelay(unsigned long xloops)
+noinline void __const_udelay(unsigned long xloops)
 {
 	unsigned long lpj = this_cpu_read(cpu_info.loops_per_jiffy) ? : loops_per_jiffy;
 	int d0;
author
#7 lore raw

PATCH v2 5/9 x86/xen: Mark xen_vcpu_stolen as __visible

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

This function is referenced from assembler, so needs to be marked __visible for LTO.

---
 drivers/xen/time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/xen/time.c +1 -1
index 0968859c29d0..04b59dab30f5 100644
@@ -144,7 +144,7 @@ void xen_get_runstate_snapshot(struct vcpu_runstate_info *res)
 }
 
 /* return true when a vcpu could run but has no real cpu to run on */
-bool xen_vcpu_stolen(int vcpu)
+__visible bool xen_vcpu_stolen(int vcpu)
 {
 	return per_cpu(xen_runstate, vcpu).state == RUNSTATE_runnable;
 }
Signature · 1 line
2.20.1
author
#9 lore raw

PATCH v2 6/9 x86/hyperv: Make hv_vcpu_is_preempted visible

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

This function is referrenced from assembler, so need to be marked visible for LTO.

Fixes 3a025de64bf8 x86/hyperv: Enable PV qspinlock for Hyper-V
---
 arch/x86/hyperv/hv_spinlock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/hyperv/hv_spinlock.c +1 -1
index a861b0456b1a..07f21a06392f 100644
@@ -56,7 +56,7 @@ static void hv_qlock_wait(u8 *byte, u8 val)
 /*
  * Hyper-V does not support this so far.
  */
-bool hv_vcpu_is_preempted(int vcpu)
+__visible bool hv_vcpu_is_preempted(int vcpu)
 {
 	return false;
 }
Signature · 1 line
2.20.1
#10 lore raw

[tip:x86/hyperv] x86/hyperv: Make hv_vcpu_is_preempted() visible

x86/hyperv: Make hv_vcpu_is_preempted() visible
Commit-ID:  d3748c8533f576969837f11e69c39d3f080c0e2b
Gitweb:     https://git.kernel.org/tip/d3748c8533f576969837f11e69c39d3f080c0e2b
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 29 Mar 2019 17:47:40 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 19 Apr 2019 17:52:49 +0200

x86/hyperv: Make hv_vcpu_is_preempted() visible

This function is referrenced from assembler, so it needs to be marked visible for LTO.

---
 arch/x86/hyperv/hv_spinlock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/hyperv/hv_spinlock.c +1 -1
index a861b0456b1a..07f21a06392f 100644
@@ -56,7 +56,7 @@ static void hv_qlock_wait(u8 *byte, u8 val)
 /*
  * Hyper-V does not support this so far.
  */
-bool hv_vcpu_is_preempted(int vcpu)
+__visible bool hv_vcpu_is_preempted(int vcpu)
 {
 	return false;
 }
#11 lore raw

[tip:x86/platform] x86/hyperv: Make hv_vcpu_is_preempted() visible

In reply to Andi Kleen
x86/hyperv: Make hv_vcpu_is_preempted() visible
Commit-ID:  02143c2931c3c0faf088c5859a10de6c2b4f2d96
Gitweb:     https://git.kernel.org/tip/02143c2931c3c0faf088c5859a10de6c2b4f2d96
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 29 Mar 2019 17:47:40 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 19 Apr 2019 17:58:57 +0200

x86/hyperv: Make hv_vcpu_is_preempted() visible

This function is referrenced from assembler, so it needs to be marked visible for LTO.

---
 arch/x86/hyperv/hv_spinlock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/hyperv/hv_spinlock.c +1 -1
index a861b0456b1a..07f21a06392f 100644
@@ -56,7 +56,7 @@ static void hv_qlock_wait(u8 *byte, u8 val)
 /*
  * Hyper-V does not support this so far.
  */
-bool hv_vcpu_is_preempted(int vcpu)
+__visible bool hv_vcpu_is_preempted(int vcpu)
 {
 	return false;
 }
author
#12 lore raw

PATCH v2 7/9 x86/kprobes: Make trampoline_handler global and visible

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

This function is referenced from assembler, so in LTO it needs to be global and visible to not be optimized away.

---
 arch/x86/kernel/kprobes/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/kprobes/core.c +1 -1
index 31ab91c9c4e9..1309a4eb3119 100644
@@ -752,7 +752,7 @@ STACK_FRAME_NON_STANDARD(kretprobe_trampoline);
 /*
  * Called from kretprobe_trampoline
  */
-static __used void *trampoline_handler(struct pt_regs *regs)
+__used __visible void *trampoline_handler(struct pt_regs *regs)
 {
 	struct kretprobe_instance *ri = NULL;
 	struct hlist_head *head, empty_rp;
Signature · 1 line
2.20.1
#13 lore raw

[tip:x86/core] x86/kprobes: Make trampoline_handler() global and visible

x86/kprobes: Make trampoline_handler() global and visible
Commit-ID:  6ea26c21941cc313bc05f340019fe454900d21bd
Gitweb:     https://git.kernel.org/tip/6ea26c21941cc313bc05f340019fe454900d21bd
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 29 Mar 2019 17:47:41 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 19 Apr 2019 17:55:30 +0200

x86/kprobes: Make trampoline_handler() global and visible

This function is referenced from assembler, so in LTO it needs to be global and visible to not be optimized away.

---
 arch/x86/kernel/kprobes/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/kprobes/core.c +1 -1
index a034cb808e7e..a7b2a5c4d969 100644
@@ -751,7 +751,7 @@ STACK_FRAME_NON_STANDARD(kretprobe_trampoline);
 /*
  * Called from kretprobe_trampoline
  */
-static __used void *trampoline_handler(struct pt_regs *regs)
+__used __visible void *trampoline_handler(struct pt_regs *regs)
 {
 	struct kretprobe_instance *ri = NULL;
 	struct hlist_head *head, empty_rp;
#14 lore raw

[tip:x86/urgent] x86/kprobes: Make trampoline_handler() global and visible

In reply to Andi Kleen
x86/kprobes: Make trampoline_handler() global and visible
Commit-ID:  0e72499c3cc0cead32f88b94a02204d2b80768bf
Gitweb:     https://git.kernel.org/tip/0e72499c3cc0cead32f88b94a02204d2b80768bf
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 29 Mar 2019 17:47:41 -0700
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 8 May 2019 13:13:58 +0200

x86/kprobes: Make trampoline_handler() global and visible

This function is referenced from assembler, so in LTO it needs to be global and visible to not be optimized away.

---
 arch/x86/kernel/kprobes/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/kprobes/core.c +1 -1
index cf52ee0d8711..9e4fa2484d10 100644
@@ -768,7 +768,7 @@ static struct kprobe kretprobe_kprobe = {
 /*
  * Called from kretprobe_trampoline
  */
-static __used void *trampoline_handler(struct pt_regs *regs)
+__used __visible void *trampoline_handler(struct pt_regs *regs)
 {
 	struct kprobe_ctlblk *kcb;
 	struct kretprobe_instance *ri = NULL;
author
#15 lore raw

PATCH v2 8/9 x86/kvm: Make steal_time visible

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

This per cpu variable is accessed from assembler code, so needs to be visible.

---
 arch/x86/kernel/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/kvm.c +1 -1
index 5c93a65ee1e5..3f0cc828cc36 100644
@@ -67,7 +67,7 @@ static int __init parse_no_stealacc(char *arg)
 early_param("no-steal-acc", parse_no_stealacc);
 
 static DEFINE_PER_CPU_DECRYPTED(struct kvm_vcpu_pv_apf_data, apf_reason) __aligned(64);
-static DEFINE_PER_CPU_DECRYPTED(struct kvm_steal_time, steal_time) __aligned(64);
+DEFINE_PER_CPU_DECRYPTED(struct kvm_steal_time, steal_time) __aligned(64) __visible;
 static int has_steal_clock = 0;
 
 /*
Signature · 1 line
2.20.1
#16 lore raw

[tip:x86/platform] x86/kvm: Make steal_time visible

x86/kvm: Make steal_time visible
Commit-ID:  14e581c381b942ce5463a7e61326d8ce1c843be7
Gitweb:     https://git.kernel.org/tip/14e581c381b942ce5463a7e61326d8ce1c843be7
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 29 Mar 2019 17:47:42 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 19 Apr 2019 17:58:57 +0200

x86/kvm: Make steal_time visible

This per cpu variable is accessed from assembler code, so it needs to be visible for LTO.

---
 arch/x86/kernel/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/kvm.c +1 -1
index 5c93a65ee1e5..3f0cc828cc36 100644
@@ -67,7 +67,7 @@ static int __init parse_no_stealacc(char *arg)
 early_param("no-steal-acc", parse_no_stealacc);
 
 static DEFINE_PER_CPU_DECRYPTED(struct kvm_vcpu_pv_apf_data, apf_reason) __aligned(64);
-static DEFINE_PER_CPU_DECRYPTED(struct kvm_steal_time, steal_time) __aligned(64);
+DEFINE_PER_CPU_DECRYPTED(struct kvm_steal_time, steal_time) __aligned(64) __visible;
 static int has_steal_clock = 0;
 
 /*
author
#17 lore raw

PATCH v2 9/9 x86/cpu/bugs: Fix __initconst usage in bugs.c

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

Fix some of the recently added const tables to use __initconst for const data instead of __initdata which causes section attribute conflicts.

Fixes fa1202ef2243 ("x86/speculation: Add command line control")
---
 arch/x86/kernel/cpu/bugs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/bugs.c +3 -3
index 2da82eff0eb4..b91b3bfa5cfb 100644
@@ -275,7 +275,7 @@ static const struct {
 	const char			*option;
 	enum spectre_v2_user_cmd	cmd;
 	bool				secure;
-} v2_user_options[] __initdata = {
+} v2_user_options[] __initconst = {
 	{ "auto",		SPECTRE_V2_USER_CMD_AUTO,		false },
 	{ "off",		SPECTRE_V2_USER_CMD_NONE,		false },
 	{ "on",			SPECTRE_V2_USER_CMD_FORCE,		true  },
@@ -419,7 +419,7 @@ static const struct {
 	const char *option;
 	enum spectre_v2_mitigation_cmd cmd;
 	bool secure;
-} mitigation_options[] __initdata = {
+} mitigation_options[] __initconst = {
 	{ "off",		SPECTRE_V2_CMD_NONE,		  false },
 	{ "on",			SPECTRE_V2_CMD_FORCE,		  true  },
 	{ "retpoline",		SPECTRE_V2_CMD_RETPOLINE,	  false },
@@ -658,7 +658,7 @@ static const char * const ssb_strings[] = {
 static const struct {
 	const char *option;
 	enum ssb_mitigation_cmd cmd;
-} ssb_mitigation_options[]  __initdata = {
+} ssb_mitigation_options[]  __initconst = {
 	{ "auto",	SPEC_STORE_BYPASS_CMD_AUTO },    /* Platform decides */
 	{ "on",		SPEC_STORE_BYPASS_CMD_ON },      /* Disable Speculative Store Bypass */
 	{ "off",	SPEC_STORE_BYPASS_CMD_NONE },    /* Don't touch Speculative Store Bypass */
Signature · 1 line
2.20.1
#18 lore raw

[tip:x86/urgent] x86/cpu/bugs: Use __initconst for 'const' init data

x86/cpu/bugs: Use __initconst for 'const' init data
Commit-ID:  1de7edbb59c8f1b46071f66c5c97b8a59569eb51
Gitweb:     https://git.kernel.org/tip/1de7edbb59c8f1b46071f66c5c97b8a59569eb51
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 29 Mar 2019 17:47:43 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 19 Apr 2019 17:11:39 +0200

x86/cpu/bugs: Use __initconst for 'const' init data

Some of the recently added const tables use __initdata which causes section attribute conflicts.

Use __initconst instead.

Fixes fa1202ef2243 ("x86/speculation: Add command line control")
---
 arch/x86/kernel/cpu/bugs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/bugs.c +3 -3
index 2da82eff0eb4..b91b3bfa5cfb 100644
@@ -275,7 +275,7 @@ static const struct {
 	const char			*option;
 	enum spectre_v2_user_cmd	cmd;
 	bool				secure;
-} v2_user_options[] __initdata = {
+} v2_user_options[] __initconst = {
 	{ "auto",		SPECTRE_V2_USER_CMD_AUTO,		false },
 	{ "off",		SPECTRE_V2_USER_CMD_NONE,		false },
 	{ "on",			SPECTRE_V2_USER_CMD_FORCE,		true  },
@@ -419,7 +419,7 @@ static const struct {
 	const char *option;
 	enum spectre_v2_mitigation_cmd cmd;
 	bool secure;
-} mitigation_options[] __initdata = {
+} mitigation_options[] __initconst = {
 	{ "off",		SPECTRE_V2_CMD_NONE,		  false },
 	{ "on",			SPECTRE_V2_CMD_FORCE,		  true  },
 	{ "retpoline",		SPECTRE_V2_CMD_RETPOLINE,	  false },
@@ -658,7 +658,7 @@ static const char * const ssb_strings[] = {
 static const struct {
 	const char *option;
 	enum ssb_mitigation_cmd cmd;
-} ssb_mitigation_options[]  __initdata = {
+} ssb_mitigation_options[]  __initconst = {
 	{ "auto",	SPEC_STORE_BYPASS_CMD_AUTO },    /* Platform decides */
 	{ "on",		SPEC_STORE_BYPASS_CMD_ON },      /* Disable Speculative Store Bypass */
 	{ "off",	SPEC_STORE_BYPASS_CMD_NONE },    /* Don't touch Speculative Store Bypass */
#19 lore raw
In reply to Andi Kleen
x86/asm: Mark all top level asm statements as .text
Commit-ID:  c03e27506a564ec7db1b179e7464835901f49751
Gitweb:     https://git.kernel.org/tip/c03e27506a564ec7db1b179e7464835901f49751
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 29 Mar 2019 17:47:35 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 19 Apr 2019 17:46:55 +0200

x86/asm: Mark all top level asm statements as .text

With gcc toplevel assembler statements that do not mark themselves as .text may end up in other sections. This causes LTO boot crashes because various assembler statements ended up in the middle of the initcall section. It's also a latent problem without LTO, although it's currently not known to cause any real problems.

According to the gcc team it's expected behavior.

Always mark all the top level assembler statements as text so that they switch to the right section.

---
 arch/x86/kernel/cpu/amd.c      | 3 ++-
 arch/x86/kernel/kprobes/core.c | 1 +
 arch/x86/lib/error-inject.c    | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/amd.c +2 -1
index 01004bfb1a1b..1bcb489e07e7 100644
@@ -83,7 +83,8 @@ static inline int wrmsrl_amd_safe(unsigned msr, unsigned long long val)
  */
 
 extern __visible void vide(void);
-__asm__(".globl vide\n"
+__asm__(".text\n"
+	".globl vide\n"
 	".type vide, @function\n"
 	".align 4\n"
 	"vide: ret\n");
arch/x86/kernel/kprobes/core.c +1 -0
index a034cb808e7e..31ab91c9c4e9 100644
@@ -715,6 +715,7 @@ NOKPROBE_SYMBOL(kprobe_int3_handler);
  * calls trampoline_handler() runs, which calls the kretprobe's handler.
  */
 asm(
+	".text\n"
 	".global kretprobe_trampoline\n"
 	".type kretprobe_trampoline, @function\n"
 	"kretprobe_trampoline:\n"
arch/x86/lib/error-inject.c +1 -0
index 3cdf06128d13..be5b5fb1598b 100644
@@ -6,6 +6,7 @@
 asmlinkage void just_return_func(void);
 
 asm(
+	".text\n"
 	".type just_return_func, @function\n"
 	".globl just_return_func\n"
 	"just_return_func:\n"