LKML Archive on lore.kernel.org help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, stable@vger.kernel.org, Martin Schwidefsky <schwidefsky@de.ibm.com>, Cornelia Huck <cohuck@redhat.com> Subject: [PATCH 4.9 34/74] s390: add options to change branch prediction behaviour for the kernel Date: Fri, 27 Apr 2018 15:58:24 +0200 [thread overview] Message-ID: <20180427135711.344105030@linuxfoundation.org> (raw) In-Reply-To: <20180427135709.899303463@linuxfoundation.org> 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Martin Schwidefsky <schwidefsky@de.ibm.com> [ Upstream commit d768bd892fc8f066cd3aa000eb1867bcf32db0ee ] Add the PPA instruction to the system entry and exit path to switch the kernel to a different branch prediction behaviour. The instructions are added via CPU alternatives and can be disabled with the "nospec" or the "nobp=0" kernel parameter. If the default behaviour selected with CONFIG_KERNEL_NOBP is set to "n" then the "nobp=1" parameter can be used to enable the changed kernel branch prediction. Acked-by: Cornelia Huck <cohuck@redhat.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> --- arch/s390/Kconfig | 17 +++++++++++++ arch/s390/include/asm/processor.h | 1 arch/s390/kernel/alternative.c | 23 ++++++++++++++++++ arch/s390/kernel/early.c | 2 + arch/s390/kernel/entry.S | 48 ++++++++++++++++++++++++++++++++++++++ arch/s390/kernel/ipl.c | 1 arch/s390/kernel/smp.c | 2 + 7 files changed, 94 insertions(+) --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -704,6 +704,23 @@ config SECCOMP If unsure, say Y. +config KERNEL_NOBP + def_bool n + prompt "Enable modified branch prediction for the kernel by default" + help + If this option is selected the kernel will switch to a modified + branch prediction mode if the firmware interface is available. + The modified branch prediction mode improves the behaviour in + regard to speculative execution. + + With the option enabled the kernel parameter "nobp=0" or "nospec" + can be used to run the kernel in the normal branch prediction mode. + + With the option disabled the modified branch prediction mode is + enabled with the "nobp=1" kernel parameter. + + If unsure, say N. + endmenu menu "Power Management" --- a/arch/s390/include/asm/processor.h +++ b/arch/s390/include/asm/processor.h @@ -84,6 +84,7 @@ void cpu_detect_mhz_feature(void); extern const struct seq_operations cpuinfo_op; extern int sysctl_ieee_emulation_warnings; extern void execve_tail(void); +extern void __bpon(void); /* * User space process size: 2GB for 31 bit, 4TB or 8PT for 64 bit. --- a/arch/s390/kernel/alternative.c +++ b/arch/s390/kernel/alternative.c @@ -14,6 +14,29 @@ static int __init disable_alternative_in early_param("noaltinstr", disable_alternative_instructions); +static int __init nobp_setup_early(char *str) +{ + bool enabled; + int rc; + + rc = kstrtobool(str, &enabled); + if (rc) + return rc; + if (enabled && test_facility(82)) + __set_facility(82, S390_lowcore.alt_stfle_fac_list); + else + __clear_facility(82, S390_lowcore.alt_stfle_fac_list); + return 0; +} +early_param("nobp", nobp_setup_early); + +static int __init nospec_setup_early(char *str) +{ + __clear_facility(82, S390_lowcore.alt_stfle_fac_list); + return 0; +} +early_param("nospec", nospec_setup_early); + struct brcl_insn { u16 opc; s32 disp; --- a/arch/s390/kernel/early.c +++ b/arch/s390/kernel/early.c @@ -302,6 +302,8 @@ static noinline __init void setup_facili memcpy(S390_lowcore.alt_stfle_fac_list, S390_lowcore.stfle_fac_list, sizeof(S390_lowcore.alt_stfle_fac_list)); + if (!IS_ENABLED(CONFIG_KERNEL_NOBP)) + __clear_facility(82, S390_lowcore.alt_stfle_fac_list); } static __init void detect_diag9c(void) --- a/arch/s390/kernel/entry.S +++ b/arch/s390/kernel/entry.S @@ -163,6 +163,34 @@ _PIF_WORK = (_PIF_PER_TRAP) tm off+\addr, \mask .endm + .macro BPOFF + .pushsection .altinstr_replacement, "ax" +660: .long 0xb2e8c000 + .popsection +661: .long 0x47000000 + .pushsection .altinstructions, "a" + .long 661b - . + .long 660b - . + .word 82 + .byte 4 + .byte 4 + .popsection + .endm + + .macro BPON + .pushsection .altinstr_replacement, "ax" +662: .long 0xb2e8d000 + .popsection +663: .long 0x47000000 + .pushsection .altinstructions, "a" + .long 663b - . + .long 662b - . + .word 82 + .byte 4 + .byte 4 + .popsection + .endm + .section .kprobes.text, "ax" .Ldummy: /* @@ -175,6 +203,11 @@ _PIF_WORK = (_PIF_PER_TRAP) */ nop 0 +ENTRY(__bpon) + .globl __bpon + BPON + br %r14 + /* * Scheduler resume function, called by switch_to * gpr2 = (task_struct *) prev @@ -234,7 +267,10 @@ ENTRY(sie64a) jnz .Lsie_skip TSTMSK __LC_CPU_FLAGS,_CIF_FPU jo .Lsie_skip # exit if fp/vx regs changed + BPON sie 0(%r14) +.Lsie_exit: + BPOFF .Lsie_skip: ni __SIE_PROG0C+3(%r14),0xfe # no longer in SIE lctlg %c1,%c1,__LC_USER_ASCE # load primary asce @@ -286,6 +322,7 @@ ENTRY(system_call) stpt __LC_SYNC_ENTER_TIMER .Lsysc_stmg: stmg %r8,%r15,__LC_SAVE_AREA_SYNC + BPOFF lg %r10,__LC_LAST_BREAK lg %r12,__LC_THREAD_INFO lghi %r14,_PIF_SYSCALL @@ -332,6 +369,7 @@ ENTRY(system_call) jnz .Lsysc_work # check for work TSTMSK __LC_CPU_FLAGS,_CIF_WORK jnz .Lsysc_work + BPON .Lsysc_restore: lg %r14,__LC_VDSO_PER_CPU lmg %r0,%r10,__PT_R0(%r11) @@ -492,6 +530,7 @@ ENTRY(kernel_thread_starter) ENTRY(pgm_check_handler) stpt __LC_SYNC_ENTER_TIMER + BPOFF stmg %r8,%r15,__LC_SAVE_AREA_SYNC lg %r10,__LC_LAST_BREAK lg %r12,__LC_THREAD_INFO @@ -590,6 +629,7 @@ ENTRY(pgm_check_handler) ENTRY(io_int_handler) STCK __LC_INT_CLOCK stpt __LC_ASYNC_ENTER_TIMER + BPOFF stmg %r8,%r15,__LC_SAVE_AREA_ASYNC lg %r10,__LC_LAST_BREAK lg %r12,__LC_THREAD_INFO @@ -641,9 +681,13 @@ ENTRY(io_int_handler) lg %r14,__LC_VDSO_PER_CPU lmg %r0,%r10,__PT_R0(%r11) mvc __LC_RETURN_PSW(16),__PT_PSW(%r11) + tm __PT_PSW+1(%r11),0x01 # returning to user ? + jno .Lio_exit_kernel + BPON .Lio_exit_timer: stpt __LC_EXIT_TIMER mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER +.Lio_exit_kernel: lmg %r11,%r15,__PT_R11(%r11) lpswe __LC_RETURN_PSW .Lio_done: @@ -775,6 +819,7 @@ ENTRY(io_int_handler) ENTRY(ext_int_handler) STCK __LC_INT_CLOCK stpt __LC_ASYNC_ENTER_TIMER + BPOFF stmg %r8,%r15,__LC_SAVE_AREA_ASYNC lg %r10,__LC_LAST_BREAK lg %r12,__LC_THREAD_INFO @@ -824,6 +869,7 @@ ENTRY(psw_idle) .Lpsw_idle_stcctm: #endif oi __LC_CPU_FLAGS+7,_CIF_ENABLED_WAIT + BPON STCK __CLOCK_IDLE_ENTER(%r2) stpt __TIMER_IDLE_ENTER(%r2) .Lpsw_idle_lpsw: @@ -931,6 +977,7 @@ load_fpu_regs: */ ENTRY(mcck_int_handler) STCK __LC_MCCK_CLOCK + BPOFF la %r1,4095 # revalidate r1 spt __LC_CPU_TIMER_SAVE_AREA-4095(%r1) # revalidate cpu timer lmg %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# revalidate gprs @@ -997,6 +1044,7 @@ ENTRY(mcck_int_handler) mvc __LC_RETURN_MCCK_PSW(16),__PT_PSW(%r11) # move return PSW tm __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ? jno 0f + BPON stpt __LC_EXIT_TIMER mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER 0: lmg %r11,%r15,__PT_R11(%r11) --- a/arch/s390/kernel/ipl.c +++ b/arch/s390/kernel/ipl.c @@ -563,6 +563,7 @@ static struct kset *ipl_kset; static void __ipl_run(void *unused) { + __bpon(); diag308(DIAG308_LOAD_CLEAR, NULL); if (MACHINE_IS_VM) __cpcmd("IPL", NULL, 0, NULL); --- a/arch/s390/kernel/smp.c +++ b/arch/s390/kernel/smp.c @@ -304,6 +304,7 @@ static void pcpu_delegate(struct pcpu *p mem_assign_absolute(lc->restart_fn, (unsigned long) func); mem_assign_absolute(lc->restart_data, (unsigned long) data); mem_assign_absolute(lc->restart_source, source_cpu); + __bpon(); asm volatile( "0: sigp 0,%0,%2 # sigp restart to target cpu\n" " brc 2,0b # busy, try again\n" @@ -877,6 +878,7 @@ void __cpu_die(unsigned int cpu) void __noreturn cpu_die(void) { idle_task_exit(); + __bpon(); pcpu_sigp_retry(pcpu_devices + smp_processor_id(), SIGP_STOP, 0); for (;;) ; }
next prev parent reply other threads:[~2018-04-27 15:14 UTC|newest] Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-04-27 13:57 [PATCH 4.9 00/74] 4.9.97-stable review Greg Kroah-Hartman 2018-04-27 13:57 ` [PATCH 4.9 01/74] cifs: do not allow creating sockets except with SMB1 posix exensions Greg Kroah-Hartman 2018-04-27 13:57 ` [PATCH 4.9 02/74] x86/tsc: Prevent 32bit truncation in calc_hpet_ref() Greg Kroah-Hartman 2018-04-27 13:57 ` [PATCH 4.9 03/74] drm/vc4: Fix memory leak during BO teardown Greg Kroah-Hartman 2018-04-27 13:57 ` [PATCH 4.9 04/74] drm/i915: Fix LSPCON TMDS output buffer enabling from low-power state Greg Kroah-Hartman 2018-04-27 13:57 ` [PATCH 4.9 05/74] i2c: i801: store and restore the SLVCMD register at load and unload Greg Kroah-Hartman 2018-04-27 13:57 ` [PATCH 4.9 06/74] i2c: i801: Save register SMBSLVCMD value only once Greg Kroah-Hartman 2018-04-27 13:57 ` [PATCH 4.9 07/74] i2c: i801: Restore configuration at shutdown Greg Kroah-Hartman 2018-04-27 13:57 ` [PATCH 4.9 08/74] usb: musb: fix enumeration after resume Greg Kroah-Hartman 2018-04-27 13:57 ` [PATCH 4.9 09/74] usb: musb: call pm_runtime_{get,put}_sync before reading vbus registers Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 10/74] usb: musb: Fix external abort in musb_remove on omap2430 Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 11/74] MIPS: Generic: Fix big endian CPUs on generic machine Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 12/74] Input: drv260x - fix initializing overdrive voltage Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 13/74] power: supply: bq2415x: check for NULL acpi_id to avoid null pointer dereference Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 14/74] [media] stk-webcam: fix an endian bug in stk_camera_read_reg() Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 15/74] OF: Prevent unaligned access in of_alias_scan() Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 16/74] ath9k_hw: check if the chip failed to wake up Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 17/74] jbd2: fix use after free in kjournald2() Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 18/74] Revert "perf tools: Decompress kernel module when reading DSO data" Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 19/74] perf: Fix sample_max_stack maximum check Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 20/74] perf: Return proper values for user stack errors Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 21/74] RDMA/mlx5: Fix NULL dereference while accessing XRC_TGT QPs Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 22/74] drm/i915/bxt, glk: Increase PCODE timeouts during CDCLK freq changing Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 23/74] mac80211_hwsim: fix use-after-free bug in hwsim_exit_net Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 24/74] r8152: add Linksys USB3GIGV1 id Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 25/74] Revert "pinctrl: intel: Initialize GPIO properly when used through irqchip" Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 26/74] Revert "ath10k: send (re)assoc peer command when NSS changed" Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 27/74] PCI: Wait up to 60 seconds for device to become ready after FLR Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 28/74] s390: introduce CPU alternatives Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 29/74] s390: enable CPU alternatives unconditionally Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 30/74] KVM: s390: wire up bpb feature Greg Kroah-Hartman 2018-04-27 15:43 ` Christian Borntraeger 2018-04-27 13:58 ` [PATCH 4.9 31/74] s390: scrub registers on kernel entry and KVM exit Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 32/74] s390: add optimized array_index_mask_nospec Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 33/74] s390/alternative: use a copy of the facility bit mask Greg Kroah-Hartman 2018-04-27 13:58 ` Greg Kroah-Hartman [this message] 2018-04-27 13:58 ` [PATCH 4.9 35/74] s390: run user space and KVM guests with modified branch prediction Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 36/74] s390: introduce execute-trampolines for branches Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 37/74] KVM: s390: force bp isolation for VSIE Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 38/74] s390: Replace IS_ENABLED(EXPOLINE_*) with IS_ENABLED(CONFIG_EXPOLINE_*) Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 39/74] s390: do not bypass BPENTER for interrupt system calls Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 40/74] s390/entry.S: fix spurious zeroing of r0 Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 41/74] s390: move nobp parameter functions to nospec-branch.c Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 42/74] s390: add automatic detection of the spectre defense Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 43/74] s390: report spectre mitigation via syslog Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 44/74] s390: add sysfs attributes for spectre Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 45/74] s390: correct nospec auto detection init order Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 46/74] s390: correct module section names for expoline code revert Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 47/74] bonding: do not set slave_dev npinfo before slave_enable_netpoll in bond_enslave Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 48/74] KEYS: DNS: limit the length of option strings Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 49/74] l2tp: check sockaddr length in pppol2tp_connect() Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 50/74] net: validate attribute sizes in neigh_dump_table() Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 51/74] llc: delete timers synchronously in llc_sk_free() Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 52/74] tcp: dont read out-of-bounds opsize Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 53/74] team: avoid adding twice the same option to the event list Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 54/74] team: fix netconsole setup over team Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 55/74] packet: fix bitfield update race Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 56/74] tipc: add policy for TIPC_NLA_NET_ADDR Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 57/74] pppoe: check sockaddr length in pppoe_connect() Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 58/74] vlan: Fix reading memory beyond skb->tail in skb_vlan_tagged_multi Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 59/74] sctp: do not check port in sctp_inet6_cmp_addr Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 60/74] net: sched: ife: signal not finding metaid Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 61/74] llc: hold llc_sap before release_sock() Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 62/74] llc: fix NULL pointer deref for SOCK_ZAPPED Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 63/74] net: ethernet: ti: cpsw: fix tx vlan priority mapping Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 64/74] net: fix deadlock while clearing neighbor proxy table Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 65/74] tcp: md5: reject TCP_MD5SIG or TCP_MD5SIG_EXT on established sockets Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 66/74] net: af_packet: fix race in PACKET_{R|T}X_RING Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 67/74] ipv6: add RTA_TABLE and RTA_PREFSRC to rtm_ipv6_policy Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 68/74] strparser: Fix incorrect strp->need_bytes value Greg Kroah-Hartman 2018-04-27 13:58 ` [PATCH 4.9 69/74] scsi: mptsas: Disable WRITE SAME Greg Kroah-Hartman 2018-04-27 13:59 ` [PATCH 4.9 70/74] cdrom: information leak in cdrom_ioctl_media_changed() Greg Kroah-Hartman 2018-04-27 13:59 ` [PATCH 4.9 71/74] s390/cio: update chpid descriptor after resource accessibility event Greg Kroah-Hartman 2018-04-27 13:59 ` [PATCH 4.9 72/74] s390/dasd: fix IO error for newly defined devices Greg Kroah-Hartman 2018-04-27 13:59 ` [PATCH 4.9 73/74] s390/uprobes: implement arch_uretprobe_is_alive() Greg Kroah-Hartman 2018-04-27 13:59 ` [PATCH 4.9 74/74] ACPI / video: Only default only_lcd to true on Win8-ready _desktops_ Greg Kroah-Hartman 2018-04-27 18:13 ` [PATCH 4.9 00/74] 4.9.97-stable review Shuah Khan 2018-04-27 20:33 ` Dan Rue 2018-04-27 20:44 ` kernelci.org bot 2018-04-28 14:26 ` Guenter Roeck
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180427135711.344105030@linuxfoundation.org \ --to=gregkh@linuxfoundation.org \ --cc=cohuck@redhat.com \ --cc=linux-kernel@vger.kernel.org \ --cc=schwidefsky@de.ibm.com \ --cc=stable@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).