]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
s390/cpum_sf: Fix and protect memory allocation of SDBs with mutex
authorThomas Richter <tmricht@linux.ibm.com>
Wed, 30 Oct 2024 11:37:18 +0000 (12:37 +0100)
committerHeiko Carstens <hca@linux.ibm.com>
Thu, 31 Oct 2024 09:50:06 +0000 (10:50 +0100)
commitf55bd479d8663a4a4e403b3d308d3d1aa33d92df
tree20cf59076aefe8453f06d0e846c2d6af7b92085c
parenta5600f05d3d7a80be23a8905fdc128abd586c786
s390/cpum_sf: Fix and protect memory allocation of SDBs with mutex

Reservation of the PMU hardware is done at first event creation
and is protected by a pair of mutex_lock() and mutex_unlock().
After reservation of the PMU hardware the memory
required for the PMUs the event is to be installed on is
allocated by allocate_buffers() and alloc_sampling_buffer().
This done outside of the mutex protection.
Without mutex protection two or more concurrent invocations of
perf_event_init() may run in parallel.
This can lead to allocation of Sample Data Blocks (SDBs)
multiple times for the same PMU.
Prevent this and protect memory allocation of SDBs by
mutex.

Fixes: 8a6fe8f21ec4 ("s390/cpum_sf: Use refcount_t instead of atomic_t")
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/kernel/perf_cpum_sf.c