linux/arch/s390/kernel
Heiko Carstens a400593eb3 s390/cpum_sf: add READ_ONCE() semantics to compare and swap loops
commit 82d3edb50a upstream.

The current cmpxchg_double() loops within the perf hw sampling code do not
have READ_ONCE() semantics to read the old value from memory. This allows
the compiler to generate code which reads the "old" value several times
from memory, which again allows for inconsistencies.

For example:

        /* Reset trailer (using compare-double-and-swap) */
        do {
                te_flags = te->flags & ~SDB_TE_BUFFER_FULL_MASK;
                te_flags |= SDB_TE_ALERT_REQ_MASK;
        } while (!cmpxchg_double(&te->flags, &te->overflow,
                 te->flags, te->overflow,
                 te_flags, 0ULL));

The compiler could generate code where te->flags used within the
cmpxchg_double() call may be refetched from memory and which is not
necessarily identical to the previous read version which was used to
generate te_flags. Which in turn means that an incorrect update could
happen.

Fix this by adding READ_ONCE() semantics to all cmpxchg_double()
loops. Given that READ_ONCE() cannot generate code on s390 which atomically
reads 16 bytes, use a private compare-and-swap-double implementation to
achieve that.

Also replace cmpxchg_double() with the private implementation to be able to
re-use the old value within the loops.

As a side effect this converts the whole code to only use bit fields
to read and modify bits within the hws trailer header.

Reported-by: Alexander Gordeev <agordeev@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Acked-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Reviewed-by: Thomas Richter <tmricht@linux.ibm.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/linux-s390/Y71QJBhNTIatvxUT@osiris/T/#ma14e2a5f7aa8ed4b94b6f9576799b3ad9c60f333
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-01-18 11:48:49 +01:00
..
syscalls compat: remove some compat entry points 2021-09-08 15:32:35 -07:00
vdso32 s390 updates for 5.15 merge window 2021-08-30 13:07:15 -07:00
vdso64 s390/vdso: filter out -mstack-guard and -mstack-size 2021-11-25 09:48:45 +01:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
alternative.c s390/facilities: move stfl information from lowcore to global data 2021-06-07 17:06:58 +02:00
asm-offsets.c s390/dump: fix old lowcore virtual vs physical address confusion 2022-08-17 14:24:09 +02:00
audit.c
audit.h
base.S s390: remove unused s390_base_ext_handler 2020-11-09 11:20:58 +01:00
cache.c
compat_audit.c
compat_linux.c s390: use generic UID16 implementation 2019-01-18 09:33:18 +01:00
compat_linux.h
compat_ptrace.h
compat_signal.c s390/signal: switch to using vdso for sigreturn and syscall restart 2021-07-08 22:09:47 +02:00
cpcmd.c s390/cpcmd: use register pair instead of register asm 2021-06-18 16:41:22 +02:00
crash_dump.c s390/crashdump: fix TOD programmable field size 2022-12-02 17:41:07 +01:00
debug.c s390/sclp: add tracing of SCLP interactions 2021-08-25 11:03:35 +02:00
diag.c s390: rename dma section to amode31 2021-08-05 14:10:53 +02:00
dis.c s390/disassembler: add instructions 2021-07-27 09:39:19 +02:00
dumpstack.c s390/unwind: add machine check handler stack 2021-04-05 11:30:07 +02:00
early_printk.c s390/sclp: remove unused sclp_early_printk_forced 2020-09-21 08:08:44 +02:00
early.c s390: make PCI mio support a machine flag 2021-07-27 09:39:19 +02:00
ebcdic.c s390: ebcdic: convert comments to UTF-8 2018-08-23 18:48:43 -07:00
entry.h s390/boot: allocate amode31 section in decompressor 2022-07-12 16:34:56 +02:00
entry.S s390/mcck: isolate SIE instruction when setting CIF_MCCK_GUEST flag 2022-06-14 18:36:13 +02:00
fpu.c s390: convert to generic entry 2021-01-19 12:29:26 +01:00
ftrace.c s390/ftrace: remove incorrect __va usage 2021-09-08 14:23:31 +02:00
ftrace.h s390/ftrace: implement hotpatching 2021-08-03 14:31:40 +02:00
guarded_storage.c
head64.S s390/boot: move dma sections from decompressor to decompressed kernel 2021-07-27 09:39:17 +02:00
idle.c s390/time,idle: get rid of unsigned long long 2021-03-08 10:46:27 +01:00
ima_arch.c s390/kexec_file: Disable kexec_load when IPLed secure 2019-04-29 10:44:03 +02:00
ipl_vmparm.c s390/cio: remove unused include linux/spinlock.h from cio.h 2021-07-27 09:39:13 +02:00
ipl.c s390/maccess: rework absolute lowcore accessors 2022-08-17 14:24:13 +02:00
irq.c s390/entry: fix duplicate tracking of irq nesting level 2021-12-22 09:32:36 +01:00
jump_label.c s390/jump_label: print real address in a case of a jump label bug 2021-07-27 09:39:13 +02:00
kdebugfs.c s390: no need to check return value of debugfs_create functions 2019-01-28 15:58:55 +01:00
kexec_elf.c kexec: Fix file verification on S390 2019-09-10 13:27:51 +01:00
kexec_image.c kexec_file: split KEXEC_VERIFY_SIG into KEXEC_SIG and KEXEC_SIG_FORCE 2019-08-19 21:54:15 -07:00
kprobes_insn_page.S s390/kprobes: move insn_page to text segment 2020-10-09 23:45:30 +02:00
kprobes.c s390/kprobes: use is_kernel() helper 2021-07-05 12:44:23 +02:00
lgr.c s390: convert to msecs_to_jiffies() 2020-06-29 16:31:46 +02:00
machine_kexec_file.c s390/kexec: fix ipl report address for kdump 2023-01-18 11:48:48 +01:00
machine_kexec_reloc.c s390/kaslr: add support for R_390_JMP_SLOT relocation type 2020-05-20 10:13:27 +02:00
machine_kexec.c s390/maccess: rework absolute lowcore accessors 2022-08-17 14:24:13 +02:00
Makefile s390: rename dma section to amode31 2021-08-05 14:10:53 +02:00
mcount.S s390/ftrace: fix ftrace_update_ftrace_func implementation 2021-07-15 12:54:58 +02:00
module.c mm: defer kmemleak object creation of module_alloc() 2022-03-08 19:12:38 +01:00
nmi.c s390/boot: fix absolute zero lowcore corruption on boot 2022-09-15 11:30:07 +02:00
nospec-branch.c s390/speculation: Use statically initialized const for instructions 2021-06-28 11:18:28 +02:00
nospec-sysfs.c s390/facilities: move stfl information from lowcore to global data 2021-06-07 17:06:58 +02:00
numa.c s390/numa: move code to arch/s390/kernel 2020-08-11 18:16:55 +02:00
os_info.c s390/maccess: rework absolute lowcore accessors 2022-08-17 14:24:13 +02:00
perf_cpum_cf_common.c s390/cpumf: Allow concurrent access for CPU Measurement Counter Facility 2021-07-05 12:44:23 +02:00
perf_cpum_cf_events.c s390/cpum_cf,perf: change DFLT_CCERROR counter name 2020-07-21 13:53:56 +02:00
perf_cpum_cf.c s390/cpumf: Handle events cycles and instructions identical 2022-06-29 09:03:26 +02:00
perf_cpum_sf.c s390/cpum_sf: add READ_ONCE() semantics to compare and swap loops 2023-01-18 11:48:49 +01:00
perf_event.c s390/perf: obtain sie_block from the right address 2022-06-09 10:23:21 +02:00
perf_regs.c perf/arch: Remove perf_sample_data::regs_user_copy 2020-11-09 18:12:34 +01:00
process.c s390: fix double free of GS and RI CBs on fork() failure 2022-08-31 17:16:48 +02:00
processor.c s390: replace deprecated CPU-hotplug functions 2021-08-05 14:10:53 +02:00
ptrace.c s390/traps: add struct to access transactional diagnostic block 2021-06-07 17:06:58 +02:00
reipl.S s390: add missing ENDPROC statements to assembler functions 2019-05-02 13:54:11 +02:00
relocate_kernel.S s390: add missing ENDPROC statements to assembler functions 2019-05-02 13:54:11 +02:00
runtime_instr.c s390/runtime_instrumentation: fix storage key handling 2020-08-17 13:17:10 +02:00
setup.c s390/boot: fix absolute zero lowcore corruption on boot 2022-09-15 11:30:07 +02:00
signal.c s390: remove do_signal() prototype and do_notify_resume() function 2021-08-25 11:03:34 +02:00
smp.c s390/maccess: rework absolute lowcore accessors 2022-08-17 14:24:13 +02:00
stacktrace.c stacktrace: Move documentation for arch_stack_walk_reliable() to header 2021-03-10 15:52:31 +01:00
sthyi.c s390/sthyi: use register pair instead of register asm 2021-06-18 16:41:22 +02:00
syscall.c s390: rename PIF_SYSCALL_RESTART to PIF_EXECVE_PGSTE_RESTART 2021-07-08 22:12:17 +02:00
sysinfo.c s390/sysinfo: get rid of register asm 2021-06-18 16:41:23 +02:00
text_amode31.S s390/diag: make restart_part2 a local label 2021-08-25 11:03:34 +02:00
time.c s390/stp: clock_delta should be signed 2022-06-09 10:23:21 +02:00
topology.c s390/topology: fix topology information when calling cpu hotplug notifiers 2021-09-07 13:38:41 +02:00
trace.c s390/ftrace: fix potential crashes when switching tracers 2020-04-22 16:20:55 +02:00
traps.c s390/traps: improve panic message for translation-specification exception 2022-05-25 09:57:25 +02:00
unwind_bc.c s390/unwind: stop gracefully at user mode pt_regs in irq stack 2019-12-18 23:29:26 +01:00
uprobes.c s390: Fix fall-through warnings for Clang 2021-07-13 14:43:09 -05:00
uv.c s390/uv: fully validate the VMA before calling follow_page() 2021-11-18 19:16:40 +01:00
vdso.c s390/vdso: add minimal compat vdso 2021-07-08 15:37:28 +02:00
vmlinux.lds.S s390: fix nospec table alignments 2022-09-08 12:28:07 +02:00
vtime.c s390/vtime: fix increased steal time accounting 2021-03-15 19:09:25 +01:00