kernel_samsung_a53x/arch/s390/kernel
Thomas Richter 098a3b309b s390/cpum_sf: Handle CPU hotplug remove during sampling
[ Upstream commit a0bd7dacbd51c632b8e2c0500b479af564afadf3 ]

CPU hotplug remove handling triggers the following function
call sequence:

   CPUHP_AP_PERF_S390_SF_ONLINE  --> s390_pmu_sf_offline_cpu()
   ...
   CPUHP_AP_PERF_ONLINE          --> perf_event_exit_cpu()

The s390 CPUMF sampling CPU hotplug handler invokes:

 s390_pmu_sf_offline_cpu()
 +-->  cpusf_pmu_setup()
       +--> setup_pmc_cpu()
            +--> deallocate_buffers()

This function de-allocates all sampling data buffers (SDBs) allocated
for that CPU at event initialization. It also clears the
PMU_F_RESERVED bit. The CPU is gone and can not be sampled.

With the event still being active on the removed CPU, the CPU event
hotplug support in kernel performance subsystem triggers the
following function calls on the removed CPU:

  perf_event_exit_cpu()
  +--> perf_event_exit_cpu_context()
       +--> __perf_event_exit_context()
	    +--> __perf_remove_from_context()
	         +--> event_sched_out()
	              +--> cpumsf_pmu_del()
	                   +--> cpumsf_pmu_stop()
                                +--> hw_perf_event_update()

to stop and remove the event. During removal of the event, the
sampling device driver tries to read out the remaining samples from
the sample data buffers (SDBs). But they have already been freed
(and may have been re-assigned). This may lead to a use after free
situation in which case the samples are most likely invalid. In the
best case the memory has not been reassigned and still contains
valid data.

Remedy this situation and check if the CPU is still in reserved
state (bit PMU_F_RESERVED set). In this case the SDBs have not been
released an contain valid data. This is always the case when
the event is removed (and no CPU hotplug off occured).
If the PMU_F_RESERVED bit is not set, the SDB buffers are gone.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-12-17 13:24:29 +01:00
..
syscalls s390/syscalls: Avoid creation of arch/arch/ directory 2024-12-17 13:23:59 +01:00
vdso64 s390/vdso: Add CFI for RA register to asm macro vdso_func 2024-11-19 11:32:42 +01:00
alternative.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
asm-offsets.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
audit.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
audit.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
base.S Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cache.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
compat_audit.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
compat_linux.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
compat_linux.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
compat_ptrace.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
compat_signal.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cpcmd.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
crash_dump.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
debug.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
diag.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dis.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dumpstack.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
early.c s390/smp,mcck: fix early IPI handling 2024-11-23 23:20:44 +01:00
early_printk.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ebcdic.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
entry.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
entry.S s390/entry: align system call table on 8 bytes 2024-11-19 09:23:10 +01:00
fpu.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ftrace.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
guarded_storage.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
head64.S Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
idle.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ima_arch.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ipl.c s390/ipl: Fix incorrect initialization of nvme dump block 2024-11-19 12:27:05 +01:00
ipl_vmparm.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
irq.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
jump_label.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
kdebugfs.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
kexec_elf.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
kexec_image.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
kprobes.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
kprobes_insn_page.S Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lgr.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
machine_kexec.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
machine_kexec_file.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
machine_kexec_reloc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Makefile Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mcount.S Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
module.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nmi.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nospec-branch.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nospec-sysfs.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
numa.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
os_info.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
perf_cpum_cf.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
perf_cpum_cf_common.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
perf_cpum_cf_diag.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
perf_cpum_cf_events.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
perf_cpum_sf.c s390/cpum_sf: Handle CPU hotplug remove during sampling 2024-12-17 13:24:29 +01:00
perf_event.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
perf_regs.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pgm_check.S Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
process.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
processor.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ptrace.c s390/ptrace: handle setting of fpc register correctly 2024-11-18 12:13:10 +01:00
reipl.S Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
relocate_kernel.S Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
runtime_instr.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
setup.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
signal.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
smp.c s390/smp,mcck: fix early IPI handling 2024-11-23 23:20:44 +01:00
stacktrace.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sthyi.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sys_s390.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sysinfo.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
time.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
topology.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
trace.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
traps.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
unwind_bc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
uprobes.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
uv.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vdso.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vmlinux.lds.S Revert "s390/vmlinux.lds.S: Move ro_after_init section behind rodata section" 2024-11-24 00:23:39 +01:00
vtime.c s390/vtime: fix average steal time calculation 2024-11-19 08:44:59 +01:00