linux/arch/s390/mm
Gerald Schaefer 57834ce5a6 s390/mm: Prevent possible preempt_count overflow
The s390 implementation of ptep_modify_prot_start() currently does
preempt_disable(), and the preempt_enable() is done later in
ptep_modify_prot_commit(). This logic is not really required, because the
PTE lock must be held over the complete prot_start/commit transaction,
as described in the comment of the generic implementation of
ptep_modify_prot_start().

That comment also mentions that this interface should be batchable,
and modify_prot_start_ptes() might start a transaction over a batch of
PTEs, implemented as a simple loop over ptep_modify_prot_start().
In this case, the preempt_disable() in ptep_modify_prot_start() would
be called multiple times, before the corresponding preempt_enable()
calls happen, and this can lead to a preempt_count overflow.

To fix this, simply remove the preempt_disable/enable() calls in
ptep_modify_prot_start/commit(), and rely on the PTE lock being held.

Commit cac1db8c3a ("mm: optimize mprotect() by PTE batching") made use
of this PTE batching for the first time, and triggers warnings like this:

 DEBUG_LOCKS_WARN_ON((preempt_count() & PREEMPT_MASK) >= PREEMPT_MASK - 10)
 BUG: sleeping function called from invalid context at mm/mprotect.c:576

Hence, add a Fixes tag on that commit. Not because it is broken, but to
make sure that it won't get backported w/o also this fix for s390.

Fixes: cac1db8c3a ("mm: optimize mprotect() by PTE batching")
Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
History 2025-08-26 11:50:05 +02:00
..
cmm.c treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
dump_pagetables.c mm/ptdump: take the memory hotplug lock inside ptdump_walk_pgd() 2025-07-09 22:42:20 -07:00
extable.c s390/uaccess: Shorten raw_copy_from_user() / raw_copy_to_user() inline assemblies 2025-03-04 17:18:03 +01:00
extmem.c s390/extmem: Add workaround for DCSS unload diag 2025-05-17 10:55:00 +02:00
fault.c more s390 updates for 6.16 merge window 2025-06-06 18:02:37 -07:00
gmap.c s390: Explicitly include <linux/export.h> 2025-06-17 18:18:02 +02:00
gmap_helpers.c s390: Explicitly include <linux/export.h> 2025-06-17 18:18:02 +02:00
hugetlbpage.c s390 updates for 6.15 merge window 2025-03-29 11:59:43 -07:00
init.c s390: Handle KCOV __init vs inline mismatches 2025-07-21 21:44:01 -07:00
maccess.c s390: Remove __bootdata annotations from declarations 2024-12-15 16:19:04 +01:00
Makefile KVM: s390: Refactor and split some gmap helpers 2025-05-28 17:48:04 +02:00
mmap.c s390/mm: Simplify gap clamping in mmap_base() using clamp() 2025-03-04 17:18:08 +01:00
page-states.c s390/cmma: rework no-dat handling 2023-11-05 22:34:58 +01:00
pageattr.c s390/cpufeature: Convert MACHINE_HAS_IDTE to cpu_has_idte() 2025-03-04 17:18:05 +01:00
pfault.c s390/asm-offsets: Remove ASM_OFFSETS_C 2025-03-31 12:20:39 +02:00
pgalloc.c s390/mm: Remove possible false-positive warning in pte_free_defer() 2025-07-23 18:06:32 +02:00
pgtable.c s390/mm: Prevent possible preempt_count overflow 2025-08-26 11:50:05 +02:00
physaddr.c s390/mm: provide simple ARCH_HAS_DEBUG_VIRTUAL support 2024-03-13 09:23:49 +01:00
vmem.c s390/mm: Allocate page table with PAGE_SIZE granularity 2025-08-05 14:23:20 +02:00