Skip to contentSkip to conversation

x86/build: Move '-mindirect-branch-cs-prefix' out of GCC-only block

PATCH Superseded Nathan Chancellor 3 participants 8 messages Aug 17, 2022 – Oct 6, 2022 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/build: Move '-mindirect-branch-cs-prefix' out of GCC-only block

LLVM 16 will have support for this flag so move it out of the GCC-only block to allow LLVM builds to take advantage of it.

---

I was not sure if this information is relevant for the commit message but I can boot without any issues on my test machines (two Intel and one AMD).

 arch/x86/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/Makefile +1 -1
index 7854685c5f25..987da87c7778 100644
@@ -14,13 +14,13 @@ endif
 
 ifdef CONFIG_CC_IS_GCC
 RETPOLINE_CFLAGS	:= $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register)
-RETPOLINE_CFLAGS	+= $(call cc-option,-mindirect-branch-cs-prefix)
 RETPOLINE_VDSO_CFLAGS	:= $(call cc-option,-mindirect-branch=thunk-inline -mindirect-branch-register)
 endif
 ifdef CONFIG_CC_IS_CLANG
 RETPOLINE_CFLAGS	:= -mretpoline-external-thunk
 RETPOLINE_VDSO_CFLAGS	:= -mretpoline
 endif
+RETPOLINE_CFLAGS	+= $(call cc-option,-mindirect-branch-cs-prefix)
 
 ifdef CONFIG_RETHUNK
 RETHUNK_CFLAGS		:= -mfunction-return=thunk-extern

base-commit: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868

Signature · 1 line
2.37.2
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 7 lines · Nathan Chancellor

LLVM 16 will have support for this flag so move it out of the GCC-only block to allow LLVM builds to take advantage of it.

Thanks for the patch, I also boot tested this (in virtual guests for both 64b and 32b).

Peter, is there anything else special about these prefixes needed to make use of them?

Quoted 34 lines

---

I was not sure if this information is relevant for the commit message but I can boot without any issues on my test machines (two Intel and one AMD).

 arch/x86/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/Makefile +1 -1
index 7854685c5f25..987da87c7778 100644
@@ -14,13 +14,13 @@ endif
 
 ifdef CONFIG_CC_IS_GCC
 RETPOLINE_CFLAGS       := $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register)
-RETPOLINE_CFLAGS       += $(call cc-option,-mindirect-branch-cs-prefix)
 RETPOLINE_VDSO_CFLAGS  := $(call cc-option,-mindirect-branch=thunk-inline -mindirect-branch-register)
 endif
 ifdef CONFIG_CC_IS_CLANG
 RETPOLINE_CFLAGS       := -mretpoline-external-thunk
 RETPOLINE_VDSO_CFLAGS  := -mretpoline
 endif
+RETPOLINE_CFLAGS       += $(call cc-option,-mindirect-branch-cs-prefix)
 
 ifdef CONFIG_RETHUNK
 RETHUNK_CFLAGS         := -mfunction-return=thunk-extern

base-commit: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868 --
2.37.2

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw
Quoted 9 lines · Nick Desaulniers
Quoted 7 lines · Nathan Chancellor

LLVM 16 will have support for this flag so move it out of the GCC-only block to allow LLVM builds to take advantage of it.

Quoted 8 lines

Thanks for the patch, I also boot tested this (in virtual guests for both 64b and 32b).

Peter, is there anything else special about these prefixes needed to make use of them?

The thing to do is boot with (warning, *very* verbose):

"spectre_v2=retpoline,lfence debug-alternative"

and observe that the retpoline sites all replace:

	"cs call __x86_indirect_thunk_r11" (6 bytes)

with:

	"lfence; jmp *%r11" (6 bytes)

This being clang, you'll ofcourse still have a few weird:

	"Jcc.d32 __x86_indirect_thunk_r11"

sites that will not be able to be replaced, but there's nothing I can do about that other than to continue to encourage y'all to stop emitting them ;-)

#3 lore raw
Quoted 11 lines · Peter Zijlstra

The thing to do is boot with (warning, *very* verbose):

"spectre_v2=retpoline,lfence debug-alternative"

and observe that the retpoline sites all replace:

	"cs call __x86_indirect_thunk_r11" (6 bytes)

with:

	"lfence; jmp *%r11" (6 bytes)

^^ call, ofc, unless the original was jmp then jmp...

/me goes get more morning juice in an attempt to wake up.

Quoted 9 lines

This being clang, you'll ofcourse still have a few weird:

	"Jcc.d32 __x86_indirect_thunk_r11"

sites that will not be able to be replaced, but there's nothing I can do about that other than to continue to encourage y'all to stop emitting them ;-)

#4 lore raw
In reply to Peter Zijlstra
Quoted 8 lines · Peter Zijlstra

This being clang, you'll ofcourse still have a few weird:

        "Jcc.d32 __x86_indirect_thunk_r11"

sites that will not be able to be replaced, but there's nothing I can do about that other than to continue to encourage y'all to stop emitting them ;-)

Joao has a patch up for this:
https://reviews.llvm.org/D134915

Signature · 2 lines
Thanks,
~Nick Desaulniers
#5 lore raw
In reply to Peter Zijlstra
Quoted 17 lines · Peter Zijlstra
Quoted 15 lines · Nick Desaulniers
Quoted 7 lines · Nathan Chancellor

LLVM 16 will have support for this flag so move it out of the GCC-only block to allow LLVM builds to take advantage of it.

Thanks for the patch, I also boot tested this (in virtual guests for both 64b and 32b).

Quoted 6 lines
Quoted 2 lines

Peter, is there anything else special about these prefixes needed to make use of them?

The thing to do is boot with (warning, *very* verbose):

"spectre_v2=retpoline,lfence debug-alternative"

ah, debug-alternative also needs loglevel=8. Was wondering why I wasn't getting anything new in the output...

No kidding on the verbosity. For a defconfig, booting in QEMU and redirecting stdout to a file produced a 95257 line file.

$ grep "SMP alternatives: retpoline" /tmp/log.txt | wc -l
18623
$ du -h /tmp/log.txt
11M /tmp/log.txt
$ grep "SMP alternatives: retpoline" /tmp/log.txt | tr -s ' '
...
[ 56.736261] SMP alternatives: retpoline at:
pm_check_save_msr+0x30/0x80 (ffffffffaa34b320) len: 6 to:
__x86_indirect_thunk_r11+0x0/0x20
$ grep "SMP alternatives: retpoline" /tmp/log.txt | tr -s ' ' | cut -d
' ' -f 10 | sort -u
5
6
# Curious about the 5, looks like there's only 2 cases:
$ grep "SMP alternatives: retpoline" /tmp/log.txt | grep 'len: 5'
[    0.147261] SMP alternatives: retpoline at: ret_from_fork+0x1d/0x30
(ffffffffa9601dbd) len: 5 to: __x86_indirect_thunk_rbx+0x0/0x20
[    2.274261] SMP alternatives: retpoline at: __efi_call+0x23/0x30
(ffffffffa9671663) len: 5 to: __x86_indirect_thunk_rdi+0x0/0x20

Is there anything else I can do to help verify Nathan and Joao's patches? If not, would you mind Ack'ing this so the x86 maintainers can pick it up?

Quoted 10 lines

and observe that the retpoline sites all replace:

        "cs call __x86_indirect_thunk_r11" (6 bytes)

with:

        "lfence; jmp *%r11" (6 bytes)
Quoted 7 lines

This being clang, you'll ofcourse still have a few weird:

        "Jcc.d32 __x86_indirect_thunk_r11"

sites that will not be able to be replaced, but there's nothing I can do about that other than to continue to encourage y'all to stop emitting them ;-)

Noting that Joao's patch was applied in my tests.
https://reviews.llvm.org/D134915
I plan to land Joao's patch imminently.

Signature · 2 lines
Thanks,
~Nick Desaulniers

QEMU location: /usr/bin

QEMU version: QEMU emulator version 7.0.0 (Debian 1:7.0+dfsg-7) 

$ timeout --foreground 3m stdbuf -oL -eL qemu-system-x86_64 -d unimp,guest_errors -kernel /android0/kernel-all/arch/x86_64/boot/bzImage -append "console=ttyS0 earlycon=uart8250,io,0x3f8 spectre_v2=retpoline,lfence debug-alternative" -cpu host -enable-kvm -smp 64 -display none -initrd /android1/boot-utils/images/x86_64/rootfs.cpio -m 512m -nodefaults -no-reboot -serial mon:stdio
[    0.000000] Linux version 6.0.0-rc7-00182-g3801f027b5b5 ([email protected]) (Nick Desaulniers clang version 16.0.0 ([email protected]:llvm/llvm-project.git 4b104c2ec016b3722190cdd67d23de6adc552f9e), LLD 16.0.0) #2 SMP PREEMPT_DYNAMIC Tue Oct 4 14:05:52 PDT 2022
[    0.000000] Command line: console=ttyS0 earlycon=uart8250,io,0x3f8 spectre_v2=retpoline,lfence debug-alternative
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
[    0.000000] signal: max sigframe size: 1776
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[    0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000001ffdffff] usable
[    0.000000] BIOS-e820: [mem 0x000000001ffe0000-0x000000001fffffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
[    0.000000] earlycon: uart8250 at I/O port 0x3f8 (options '')
[    0.000000] printk: bootconsole [uart8250] enabled
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] SMBIOS 2.8 present.
[    0.000000] DMI: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.0-debian-1.16.0-4 04/01/2014
[    0.000000] Hypervisor detected: KVM
[    0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00
[    0.000000] kvm-clock: using sched offset of 212626233 cycles
[    0.000586] clocksource: kvm-clock: mask: 0xffffffffffffffff max_cycles: 0x1cd42e4dffb, max_idle_ns: 881590591483 ns
[    0.002414] tsc: Detected 2694.936 MHz processor
[    0.003227] last_pfn = 0x1ffe0 max_arch_pfn = 0x400000000
[    0.003877] x86/PAT: Configuration [0-7]: WB  WC  UC- UC  WB  WP  UC- WT  
[    0.006441] found SMP MP-table at [mem 0x000f5ba0-0x000f5baf]
[    0.007108] Using GB pages for direct mapping
[    0.007713] RAMDISK: [mem 0x1fb0d000-0x1ffdffff]
[    0.008275] ACPI: Early table checksum verification disabled
[    0.008923] ACPI: RSDP 0x00000000000F59D0 000014 (v00 BOCHS )
[    0.009572] ACPI: RSDT 0x000000001FFE2FBE 000034 (v01 BOCHS  BXPC     00000001 BXPC 00000001)
[    0.010533] ACPI: FACP 0x000000001FFE2C7A 000074 (v01 BOCHS  BXPC     00000001 BXPC 00000001)
[    0.011491] ACPI: DSDT 0x000000001FFE0040 002C3A (v01 BOCHS  BXPC     00000001 BXPC 00000001)
[    0.012445] ACPI: FACS 0x000000001FFE0000 000040
[    0.012976] ACPI: APIC 0x000000001FFE2CEE 000270 (v01 BOCHS  BXPC     00000001 BXPC 00000001)
[    0.013929] ACPI: HPET 0x000000001FFE2F5E 000038 (v01 BOCHS  BXPC     00000001 BXPC 00000001)
[    0.014880] ACPI: WAET 0x000000001FFE2F96 000028 (v01 BOCHS  BXPC     00000001 BXPC 00000001)
[    0.015830] ACPI: Reserving FACP table memory at [mem 0x1ffe2c7a-0x1ffe2ced]
[    0.016615] ACPI: Reserving DSDT table memory at [mem 0x1ffe0040-0x1ffe2c79]
[    0.017439] ACPI: Reserving FACS table memory at [mem 0x1ffe0000-0x1ffe003f]
[    0.018229] ACPI: Reserving APIC table memory at [mem 0x1ffe2cee-0x1ffe2f5d]
[    0.019019] ACPI: Reserving HPET table memory at [mem 0x1ffe2f5e-0x1ffe2f95]
[    0.019822] ACPI: Reserving WAET table memory at [mem 0x1ffe2f96-0x1ffe2fbd]
[    0.020814] No NUMA configuration found
[    0.021245] Faking a node at [mem 0x0000000000000000-0x000000001ffdffff]
[    0.021995] NODE_DATA(0) allocated [mem 0x1fb09000-0x1fb0cfff]
[    0.022657] Zone ranges:
[    0.022940]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.023632]   DMA32    [mem 0x0000000001000000-0x000000001ffdffff]
[    0.024324]   Normal   empty
[    0.024647] Movable zone start for each node
[    0.025136] Early memory node ranges
[    0.025534]   node   0: [mem 0x0000000000001000-0x000000000009efff]
[    0.026238]   node   0: [mem 0x0000000000100000-0x000000001ffdffff]
[    0.026946] Initmem setup node 0 [mem 0x0000000000001000-0x000000001ffdffff]
[    0.027893] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.027911] On node 0, zone DMA: 97 pages in unavailable ranges
[    0.029539] On node 0, zone DMA32: 32 pages in unavailable ranges
[    0.030423] ACPI: PM-Timer IO Port: 0x608
[    0.031561] ACPI: LAPIC_NMI (acpi_id[0xff] dfl dfl lint[0x1])
[    0.032226] IOAPIC[0]: apic_id 0, version 17, address 0xfec00000, GSI 0-23
[    0.033012] ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_irq 2 dfl dfl)
[    0.033722] ACPI: INT_SRC_OVR (bus 0 bus_irq 5 global_irq 5 high level)
[    0.034462] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[    0.035201] ACPI: INT_SRC_OVR (bus 0 bus_irq 10 global_irq 10 high level)
[    0.035960] ACPI: INT_SRC_OVR (bus 0 bus_irq 11 global_irq 11 high level)
[    0.036719] ACPI: Using ACPI (MADT) for SMP configuration information
[    0.037453] ACPI: HPET id: 0x8086a201 base: 0xfed00000
[    0.038033] TSC deadline timer available
[    0.038475] smpboot: Allowing 64 CPUs, 0 hotplug CPUs
[    0.039060] kvm-guest: KVM setup pv remote TLB flush
[    0.039623] kvm-guest: setup PV sched yield
[    0.040097] PM: hibernation: Registered nosave memory: [mem 0x00000000-0x00000fff]
[    0.040951] PM: hibernation: Registered nosave memory: [mem 0x0009f000-0x0009ffff]
[    0.041797] PM: hibernation: Registered nosave memory: [mem 0x000a0000-0x000effff]
[    0.042645] PM: hibernation: Registered nosave memory: [mem 0x000f0000-0x000fffff]
[    0.043492] [mem 0x20000000-0xfeffbfff] available for PCI devices
[    0.044172] Booting paravirtualized kernel on KVM
[    0.044695] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1910969940391419 ns
[    0.050262] setup_percpu: NR_CPUS:64 nr_cpumask_bits:64 nr_cpu_ids:64 nr_node_ids:1
[    0.053360] percpu: Embedded 52 pages/cpu s175464 r8192 d29336 u262144
[    0.054187] Fallback order for Node 0: 0 
[    0.054661] Built 1 zonelists, mobility grouping on.  Total pages: 128736
[    0.055446] Policy zone: DMA32
[    0.055804] Kernel command line: console=ttyS0 earlycon=uart8250,io,0x3f8 spectre_v2=retpoline,lfence debug-alternative
[    0.057090] Unknown kernel command line parameters "spectre_v2=retpoline,lfence", will be passed to user space.
[    0.058248] printk: log_buf_len individual max cpu contribution: 4096 bytes
[    0.059047] printk: log_buf_len total cpu_extra contributions: 258048 bytes
[    0.059844] printk: log_buf_len min size: 262144 bytes
[    0.060767] printk: log_buf_len: 524288 bytes
[    0.061271] printk: early log buf free: 255272(97%)
[    0.061849] Dentry cache hash table entries: 65536 (order: 7, 524288 bytes, linear)
[    0.062887] Inode-cache hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.063892] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.065541] Memory: 458384K/523768K available (16396K kernel code, 2538K rwdata, 5072K rodata, 1540K init, 1272K bss, 65124K reserved, 0K cma-reserved)
[    0.067269] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=64, Nodes=1
[    0.068933] Dynamic Preempt: voluntary
[    0.069602] rcu: Preemptible hierarchical RCU implementation.
[    0.070269] rcu: 	RCU event tracing is enabled.
[    0.070796] 	Trampoline variant of Tasks RCU enabled.
[    0.071389] rcu: RCU calculated value of scheduler-enlistment delay is 100 jiffies.
[    0.073182] NR_IRQS: 4352, nr_irqs: 936, preallocated irqs: 16
[    0.074075] rcu: srcu_init: Setting srcu_struct sizes based on contention.
[    0.074900] random: crng init done
[    0.075396] Console: colour *CGA 80x25
[    0.075853] printk: console [ttyS0] enabled
[    0.075853] printk: console [ttyS0] enabled
[    0.076831] printk: bootconsole [uart8250] disabled
[    0.076831] printk: bootconsole [uart8250] disabled
[    0.077979] ACPI: Core revision 20220331
[    0.078546] clocksource: hpet: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604467 ns
[    0.079687] APIC: Switch to symmetric I/O mode setup
[    0.080295] Switched APIC routing to physical flat.
[    0.080898] kvm-guest: setup PV IPIs
[    0.082251] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1
[    0.083376] tsc: Marking TSC unstable due to TSCs unsynchronized
[    0.084480] Calibrating delay loop (skipped) preset value.. 5389.87 BogoMIPS (lpj=2694936)
[    0.085479] pid_max: default: 65536 minimum: 512
[    0.086517] LSM: Security Framework initializing
[    0.087490] SELinux:  Initializing.
[    0.088155] Mount-cache hash table entries: 1024 (order: 1, 8192 bytes, linear)
[    0.088480] Mountpoint-cache hash table entries: 1024 (order: 1, 8192 bytes, linear)
[    0.089791] x86/cpu: User Mode Instruction Prevention (UMIP) activated
[    0.091557] Last level iTLB entries: 4KB 512, 2MB 255, 4MB 127
[    0.092479] Last level dTLB entries: 4KB 512, 2MB 255, 4MB 127, 1GB 0
[    0.093482] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[    0.094480] Spectre V2 : retpoline,lfence selected on command line.
[    0.095479] Spectre V2 : WARNING: LFENCE mitigation is not recommended for this CPU, data leaks possible!
[    0.096479] Spectre V2 : Mitigation: LFENCE
[    0.097479] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch
[    0.098480] Spectre V2 : Spectre v2 / SpectreRSB : Filling RSB on VMEXIT
[    0.099479] Spectre V2 : Enabling Speculation Barrier for firmware calls
[    0.100479] RETBleed: Mitigation: untrained return thunk
[    0.101481] Spectre V2 : mitigation: Enabling conditional Indirect Branch Prediction Barrier
[    0.102480] Speculative Store Bypass: Mitigation: Speculative Store Bypass disabled via prctl
[    0.370312] Freeing SMP alternatives memory: 52K
[    0.370575] smpboot: CPU0: AMD Ryzen Threadripper PRO 3995WX 64-Cores (family: 0x17, model: 0x31, stepping: 0x0)
[    0.371575] cblist_init_generic: Setting adjustable number of callback queues.
[    0.372481] cblist_init_generic: Setting shift to 6 and lim to 1.
[    0.373491] Performance Events: Fam17h+ core perfctr, AMD PMU driver.
[    0.374483] ... version:                0
[    0.375194] ... bit width:              48
[    0.375481] ... generic registers:      6
[    0.376189] ... value mask:             0000ffffffffffff
[    0.376481] ... max period:             00007fffffffffff
[    0.377425] ... fixed-purpose events:   0
[    0.377481] ... event mask:             000000000000003f
[    0.378512] rcu: Hierarchical SRCU implementation.
[    0.379360] rcu: 	Max phase no-delay instances is 400.
[    0.379998] smp: Bringing up secondary CPUs ...
[    0.380540] x86: Booting SMP configuration:
[    0.381287] .... node  #0, CPUs:        #1  #2  #3  #4  #5  #6  #7  #8  #9 #10 #11 #12 #13 #14 #15 #16 #17 #18 #19 #20 #21 #22 #23 #24 #25 #26 #27 #28 #29 #30 #31 #32 #33 #34 #35 #36 #37 #38 #39 #40 #41 #42 #43 #44 #45 #46 #47 #48 #49 #50 #51 #52 #53 #54 #55 #56 #57 #58 #59 #60 #61 #62 #63
[    0.437796] smp: Brought up 1 node, 64 CPUs
[    0.439238] smpboot: Max logical packages: 1
[    0.439483] smpboot: Total of 64 processors activated (344951.80 BogoMIPS)
[    0.442193] devtmpfs: initialized
[    0.442626] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275000 ns
[    0.443489] futex hash table entries: 16384 (order: 8, 1048576 bytes, linear)
[    0.444781] PM: RTC time: 21:07:22, date: 2022-10-04
[    0.445700] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.446532] audit: initializing netlink subsys (disabled)
[    0.447532] audit: type=2000 audit(1664917642.765:1): state=initialized audit_enabled=0 res=1
[    0.447547] thermal_sys: Registered thermal governor 'step_wise'
[    0.448482] thermal_sys: Registered thermal governor 'user_space'
[    0.449517] cpuidle: using governor menu
[    0.453738] PCI: Using configuration type 1 for base access
[    0.454482] PCI: Using configuration type 1 for extended access
[    0.459162] kprobes: kprobe jump-optimization is enabled. All kprobes are optimized if possible.
[    0.459558] HugeTLB: registered 2.00 MiB page size, pre-allocated 0 pages
[    0.460485] HugeTLB: 28 KiB vmemmap can be freed for a 2.00 MiB page
[    0.461637] ACPI: Added _OSI(Module Device)
[    0.462506] ACPI: Added _OSI(Processor Device)
[    0.463484] ACPI: Added _OSI(3.0 _SCP Extensions)
[    0.464483] ACPI: Added _OSI(Processor Aggregator Device)
[    0.465482] ACPI: Added _OSI(Linux-Dell-Video)
[    0.466305] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
[    0.466500] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)
[    0.468166] ACPI: 1 ACPI AML tables successfully acquired and loaded
[    0.469092] ACPI: Interpreter enabled
[    0.469492] ACPI: PM: (supports S0 S3 S4 S5)
[    0.470264] ACPI: Using IOAPIC for interrupt routing
[    0.470495] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
[    0.471481] PCI: Using E820 reservations for host bridge windows
[    0.472598] ACPI: Enabled 2 GPEs in block 00 to 0F
[    0.476492] ACPI: PCI Root Bridge [PCI0] (domain 0000 [bus 00-ff])
[    0.477483] acpi PNP0A03:00: _OSC: OS supports [ExtendedConfig ASPM ClockPM Segments MSI HPX-Type3]
[    0.478560] PCI host bridge to bus 0000:00
[    0.479321] pci_bus 0000:00: root bus resource [io  0x0000-0x0cf7 window]
[    0.479481] pci_bus 0000:00: root bus resource [io  0x0d00-0xffff window]
[    0.480481] pci_bus 0000:00: root bus resource [mem 0x000a0000-0x000bffff window]
[    0.481481] pci_bus 0000:00: root bus resource [mem 0x20000000-0xfebfffff window]
[    0.482481] pci_bus 0000:00: root bus resource [mem 0x100000000-0x17fffffff window]
[    0.483481] pci_bus 0000:00: root bus resource [bus 00-ff]
[    0.484582] pci 0000:00:00.0: [8086:1237] type 00 class 0x060000
[    0.486001] pci 0000:00:01.0: [8086:7000] type 00 class 0x060100
[    0.486932] pci 0000:00:01.1: [8086:7010] type 00 class 0x010180
[    0.488615] pci 0000:00:01.1: reg 0x20: [io  0xc000-0xc00f]
[    0.489974] pci 0000:00:01.1: legacy IDE quirk: reg 0x10: [io  0x01f0-0x01f7]
[    0.490481] pci 0000:00:01.1: legacy IDE quirk: reg 0x14: [io  0x03f6]
[    0.491481] pci 0000:00:01.1: legacy IDE quirk: reg 0x18: [io  0x0170-0x0177]
[    0.492481] pci 0000:00:01.1: legacy IDE quirk: reg 0x1c: [io  0x0376]
[    0.493580] pci 0000:00:01.3: [8086:7113] type 00 class 0x068000
[    0.494835] pci 0000:00:01.3: quirk: [io  0x0600-0x063f] claimed by PIIX4 ACPI
[    0.495487] pci 0000:00:01.3: quirk: [io  0x0700-0x070f] claimed by PIIX4 SMB
[    0.496895] ACPI: PCI: Interrupt link LNKA configured for IRQ 10
[    0.497616] ACPI: PCI: Interrupt link LNKB configured for IRQ 10
[    0.498599] ACPI: PCI: Interrupt link LNKC configured for IRQ 11
[    0.499594] ACPI: PCI: Interrupt link LNKD configured for IRQ 11
[    0.500566] ACPI: PCI: Interrupt link LNKS configured for IRQ 9
[    0.502967] iommu: Default domain type: Translated 
[    0.503481] iommu: DMA domain TLB invalidation policy: lazy mode 
[    0.504518] SCSI subsystem initialized
[    0.505260] ACPI: bus type USB registered
[    0.505492] usbcore: registered new interface driver usbfs
[    0.506486] usbcore: registered new interface driver hub
[    0.507487] usbcore: registered new device driver usb
[    0.508420] pps_core: LinuxPPS API ver. 1 registered
[    0.508481] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <[email protected]>
[    0.509483] PTP clock support registered
[    0.510203] Advanced Linux Sound Architecture Driver Initialized.
[    0.510566] NetLabel: Initializing
[    0.511174] NetLabel:  domain hash size = 128
[    0.511481] NetLabel:  protocols = UNLABELED CIPSOv4 CALIPSO
[    0.512489] NetLabel:  unlabeled traffic allowed by default
[    0.513508] PCI: Using ACPI for IRQ routing
[    0.514318] vgaarb: loaded
[    0.514540] hpet0: at MMIO 0xfed00000, IRQs 2, 8, 0
[    0.515427] hpet0: 3 comparators, 64-bit 100.000000 MHz counter
[    0.518952] clocksource: Switched to clocksource kvm-clock
[    0.519645] VFS: Disk quotas dquot_6.6.0
[    0.520417] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.521743] pnp: PnP ACPI init
[    0.522474] pnp: PnP ACPI: found 5 devices
[    0.531089] clocksource: acpi_pm: mask: 0xffffff max_cycles: 0xffffff, max_idle_ns: 2085701024 ns
[    0.532688] NET: Registered PF_INET protocol family
[    0.533583] IP idents hash table entries: 8192 (order: 4, 65536 bytes, linear)
[    0.535014] tcp_listen_portaddr_hash hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.536505] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.537891] TCP established hash table entries: 4096 (order: 3, 32768 bytes, linear)
[    0.539284] TCP bind hash table entries: 4096 (order: 4, 65536 bytes, linear)
[    0.540572] TCP: Hash tables configured (established 4096 bind 4096)
[    0.541772] UDP hash table entries: 256 (order: 1, 8192 bytes, linear)
[    0.542952] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes, linear)
[    0.544256] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.545564] RPC: Registered named UNIX socket transport module.
[    0.546640] RPC: Registered udp transport module.
[    0.547496] RPC: Registered tcp transport module.
[    0.548339] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.549850] pci_bus 0000:00: resource 4 [io  0x0000-0x0cf7 window]
[    0.550977] pci_bus 0000:00: resource 5 [io  0x0d00-0xffff window]
[    0.552093] pci_bus 0000:00: resource 6 [mem 0x000a0000-0x000bffff window]
[    0.553326] pci_bus 0000:00: resource 7 [mem 0x20000000-0xfebfffff window]
[    0.554566] pci_bus 0000:00: resource 8 [mem 0x100000000-0x17fffffff window]
[    0.555851] pci 0000:00:01.0: PIIX3: Enabling Passive Release
[    0.556904] pci 0000:00:00.0: Limiting direct PCI/PCI transfers
[    0.558003] PCI: CLS 0 bytes, default 64
[    0.558783] Unpacking initramfs...
[    0.562846] Freeing initrd memory: 4940K
[    0.576849] Initialise system trusted keyrings
[    0.577801] workingset: timestamp_bits=56 max_order=17 bucket_order=0
[    0.579938] NFS: Registering the id_resolver key type
[    0.580868] Key type id_resolver registered
[    0.581636] Key type id_legacy registered
[    0.582408] 9p: Installing v9fs 9p2000 file system support
[    0.586897] Key type asymmetric registered
[    0.587663] Asymmetric key parser 'x509' registered
[    0.588554] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251)
[    0.589904] io scheduler mq-deadline registered
[    0.590730] io scheduler kyber registered
[    0.595421] input: Power Button as /devices/LNXSYSTM:00/LNXPWRBN:00/input/input0
[    0.596814] ACPI: button: Power Button [PWRF]
[    0.598997] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    0.600262] 00:03: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[    0.602055] Non-volatile memory driver v1.3
[    0.602829] Linux agpgart interface v0.103
[    0.603604] ACPI: bus type drm_connector registered
[    0.616441] loop: module loaded
[    0.617699] scsi host0: ata_piix
[    0.618552] scsi host1: ata_piix
[    0.619151] ata1: PATA max MWDMA2 cmd 0x1f0 ctl 0x3f6 bmdma 0xc000 irq 14
[    0.620367] ata2: PATA max MWDMA2 cmd 0x170 ctl 0x376 bmdma 0xc008 irq 15
[    0.621703] e100: Intel(R) PRO/100 Network Driver
[    0.622763] e100: Copyright(c) 1999-2006 Intel Corporation
[    0.623904] e1000: Intel(R) PRO/1000 Network Driver
[    0.624798] e1000: Copyright (c) 1999-2006 Intel Corporation.
[    0.625848] e1000e: Intel(R) PRO/1000 Network Driver
[    0.626746] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
[    0.627816] sky2: driver version 1.30
[    0.628581] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    0.629773] ehci-pci: EHCI PCI platform driver
[    0.630584] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    0.631701] ohci-pci: OHCI PCI platform driver
[    0.632512] uhci_hcd: USB Universal Host Controller Interface driver
[    0.633687] usbcore: registered new interface driver usblp
[    0.634686] usbcore: registered new interface driver usb-storage
[    0.635788] i8042: PNP: PS/2 Controller [PNP0303:KBD,PNP0f13:MOU] at 0x60,0x64 irq 1,12
[    0.638026] serio: i8042 KBD port at 0x60,0x64 irq 1
[    0.638941] serio: i8042 AUX port at 0x60,0x64 irq 12
[    0.640153] rtc_cmos 00:04: RTC can wake from S4
[    0.641733] input: AT Translated Set 2 keyboard as /devices/platform/i8042/serio0/input/input1
[    0.642559] rtc_cmos 00:04: registered as rtc0
[    0.645921] rtc_cmos 00:04: alarms up to one day, y3k, 242 bytes nvram, hpet irqs
[    0.649860] device-mapper: ioctl: 4.47.0-ioctl (2022-07-28) initialised: [email protected]
[    0.652752] hid: raw HID events driver (C) Jiri Kosina
[    0.654526] usbcore: registered new interface driver usbhid
[    0.655539] usbhid: USB HID core driver
[    0.656561] Initializing XFRM netlink socket
[    0.657532] NET: Registered PF_INET6 protocol family
[    0.658846] Segment Routing with IPv6
[    0.659538] In-situ OAM (IOAM) with IPv6
[    0.660272] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    0.661440] NET: Registered PF_PACKET protocol family
[    0.662395] 9pnet: Installing 9P2000 support
[    0.663196] Key type dns_resolver registered
[    0.670887] IPI shorthand broadcast: enabled
[    0.671720] sched_clock: Marking stable (665092110, 6605125)->(723079606, -51382371)
[    0.673571] registered taskstats version 1
[    0.674338] Loading compiled-in X.509 certificates
[    0.675423] cryptomgr_test (366) used greatest stack depth: 15728 bytes left
[    0.677936] cryptomgr_test (380) used greatest stack depth: 15568 bytes left
[    0.680677] PM:   Magic number: 10:617:145
[    0.681475] ata_port ata2: hash matches
[    0.682187]  ata2: hash matches
[    0.682816] acpi device:16: hash matches
[    0.683554] printk: console [netcon0] enabled
[    0.684341] netconsole: network logging started
[    0.685826] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[    0.687907] modprobe (389) used greatest stack depth: 14272 bytes left
[    0.688964] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[    0.691434] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
[    0.693029] cfg80211: failed to load regulatory.db
[    0.693937] ALSA device list:
[    0.694496]   No soundcards found.
[    0.777773] Freeing unused kernel image (initmem) memory: 1540K
[    0.779535] Write protecting the kernel read-only data: 24576k
[    0.782175] Freeing unused kernel image (text/rodata gap) memory: 2032K
[    0.784549] Freeing unused kernel image (rodata/data gap) memory: 1072K
[    0.786428] Run /init as init process
Starting syslogd: [    0.797052] start-stop-daem (408) used greatest stack depth: 14184 bytes left
OK
Starting klogd: OK
Running sysctl: [    0.803599] S02sysctl (416) used greatest stack depth: 14048 bytes left
OK
Saving random seed: OK
Starting network: [    0.812740] ip (433) used greatest stack depth: 12920 bytes left
OK
Linux version 6.0.0-rc7-00182-g3801f027b5b5 ([email protected]) (Nick Desaulniers clang version 16.0.0 ([email protected]:llvm/llvm-project.git 4b104c2ec016b3722190cdd67d23de6adc552f9e), LLD 16.0.0) #2 SMP PREEMPT_DYNAMIC Tue Oct 4 14:05:52 PDT 2022
Stopping network: OK
Saving random seed: OK
Stopping klogd: OK
Stopping syslogd: OK
umount: devtmpfs busy - remounted read-only
umount: can't unmount /: Invalid argument

The system is going down NOW!

Sent SIGTERM to all processes
[    1.275742] input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input3

Sent SIGKILL to all processes

Requesting system poweroff
[    2.851951] ACPI: PM: Preparing to enter system sleep state S5
[    2.853012] reboot: Power down
#6 lore raw
Quoted 43 lines · Nick Desaulniers
Quoted 17 lines · Peter Zijlstra
Quoted 15 lines · Nick Desaulniers
Quoted 7 lines · Nathan Chancellor

LLVM 16 will have support for this flag so move it out of the GCC-only block to allow LLVM builds to take advantage of it.

Thanks for the patch, I also boot tested this (in virtual guests for both 64b and 32b).

Quoted 6 lines
Quoted 2 lines

Peter, is there anything else special about these prefixes needed to make use of them?

The thing to do is boot with (warning, *very* verbose):

"spectre_v2=retpoline,lfence debug-alternative"

ah, debug-alternative also needs loglevel=8. Was wondering why I wasn't getting anything new in the output...

No kidding on the verbosity. For a defconfig, booting in QEMU and redirecting stdout to a file produced a 95257 line file.

$ grep "SMP alternatives: retpoline" /tmp/log.txt | wc -l
18623
$ du -h /tmp/log.txt
11M /tmp/log.txt
$ grep "SMP alternatives: retpoline" /tmp/log.txt | tr -s ' '
...
[ 56.736261] SMP alternatives: retpoline at:
pm_check_save_msr+0x30/0x80 (ffffffffaa34b320) len: 6 to:
__x86_indirect_thunk_r11+0x0/0x20
$ grep "SMP alternatives: retpoline" /tmp/log.txt | tr -s ' ' | cut -d
' ' -f 10 | sort -u
Quoted 8 lines
5
6
# Curious about the 5, looks like there's only 2 cases:
$ grep "SMP alternatives: retpoline" /tmp/log.txt | grep 'len: 5'
[    0.147261] SMP alternatives: retpoline at: ret_from_fork+0x1d/0x30
(ffffffffa9601dbd) len: 5 to: __x86_indirect_thunk_rbx+0x0/0x20
[    2.274261] SMP alternatives: retpoline at: __efi_call+0x23/0x30
(ffffffffa9671663) len: 5 to: __x86_indirect_thunk_rdi+0x0/0x20

For the typical len 6 case:

[    0.710345] SMP alternatives: ffffffffa2b6d1f2: orig: 2e e8 88 5f 09 ff
[    0.711345] SMP alternatives: ffffffffa2b6d1f2: repl: 0f ae e8 41 ff d3
[    0.712345] SMP alternatives: retpoline at: setup_arch+0x4b0/0x58c

(ffffffffa2b6d2ef) len: 6 to: __x86_indirect_thunk_r11+0x0/0x20

2e is the cs prefix, so it looks like this is working.

https://github.com/llvm/llvm-project/issues/58201
:^)

Quoted 3 lines

Is there anything else I can do to help verify Nathan and Joao's patches? If not, would you mind Ack'ing this so the x86 maintainers can pick it up?

I see it's already been Acked, so NVM. This is good to go.

Quoted 3 lines

Noting that Joao's patch was applied in my tests.
https://reviews.llvm.org/D134915
I plan to land Joao's patch imminently.

Merging.

Signature · 2 lines
Thanks,
~Nick Desaulniers
Acked-by on v1 1/1
#7 lore raw
In reply to Nathan Chancellor
Quoted 6 lines · Nathan Chancellor

LLVM 16 will have support for this flag so move it out of the GCC-only block to allow LLVM builds to take advantage of it.

Quoted 15 lines

---

I was not sure if this information is relevant for the commit message but I can boot without any issues on my test machines (two Intel and one AMD).

 arch/x86/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/Makefile +0 -0
index 7854685c5f25..987da87c7778 100644
@@ -14,13 +14,13 @@ endif
 

arch/x86/Makefile endif · line 23

Quoted 10 lines
arch/x86/Makefile +1 -1
 ifdef CONFIG_CC_IS_GCC
 RETPOLINE_CFLAGS	:= $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register)
-RETPOLINE_CFLAGS	+= $(call cc-option,-mindirect-branch-cs-prefix)
 RETPOLINE_VDSO_CFLAGS	:= $(call cc-option,-mindirect-branch=thunk-inline -mindirect-branch-register)
 endif
 ifdef CONFIG_CC_IS_CLANG
 RETPOLINE_CFLAGS	:= -mretpoline-external-thunk
 RETPOLINE_VDSO_CFLAGS	:= -mretpoline
 endif
+RETPOLINE_CFLAGS	+= $(call cc-option,-mindirect-branch-cs-prefix)

Thanks for using the same option!