kernel_samsung_a53x/arch
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
..
alpha
arc ARC: [plat-hsdk]: Remove misplaced interrupt-cells property 2024-11-19 11:32:36 +01:00
arm ARM: dts: cubieboard4: Fix DCDC5 regulator constraints 2024-12-17 13:24:03 +01:00
arm64 arm64: ptrace: fix partial SETREGSET for NT_ARM_TAGGED_ADDR_CTRL 2024-12-17 13:24:28 +01:00
c6x
csky csky, hexagon: fix broken sys_sync_file_range 2024-11-19 14:19:34 +01:00
h8300
hexagon hexagon: fix fadvise64_64 calling conventions 2024-11-19 14:19:34 +01:00
ia64 efi: ia64: move IA64-only declarations to new asm/efi.h header 2024-11-19 14:19:45 +01:00
m68k m68k: coldfire/device.c: only build FEC when HW macros are defined 2024-12-17 13:24:12 +01:00
microblaze Revert "microblaze: don't treat zero reserved memory regions as error" 2024-11-24 00:23:33 +01:00
mips clkdev: remove CONFIG_CLKDEV_LOOKUP 2024-12-17 13:24:00 +01:00
nds32
nios2
openrisc openrisc: Call setup_memory() earlier in the init sequence 2024-11-23 23:20:47 +01:00
parisc Revert "parisc: Fix itlb miss handler for 64-bit programs" 2024-11-24 00:23:05 +01:00
powerpc powerpc/kexec: Fix return of uninitialized variable 2024-12-17 13:24:09 +01:00
riscv Revert "riscv: Fix fp alignment bug in perf_callchain_user()" 2024-11-24 00:23:20 +01:00
s390 s390/cpum_sf: Handle CPU hotplug remove during sampling 2024-12-17 13:24:29 +01:00
sh sh: cpuinfo: Fix a warning for CONFIG_CPUMASK_OFFSTACK 2024-12-17 13:24:19 +01:00
sparc sparc64: Fix incorrect function signature and add prototype for prom_cif_init 2024-11-23 23:20:10 +01:00
um um: Always dump trace for specified task in show_stack 2024-12-17 13:24:21 +01:00
x86 crypto: x86/aegis128 - access 32-bit arguments as 32-bit 2024-12-17 13:24:17 +01:00
xtensa
Kconfig cpu: Re-enable CPU mitigations by default for !X86 architectures 2024-11-19 11:32:38 +01:00