android_kernel_motorola_sm6375/mm
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Marco Elver 423c5febd4
FROMGIT: kfence: await for allocation using wait_event
Patch series "kfence: optimize timer scheduling", v2.

We have observed that mostly-idle systems with KFENCE enabled wake up
otherwise idle CPUs, preventing such to enter a lower power state.
Debugging revealed that KFENCE spends too much active time in
toggle_allocation_gate().

While the first version of KFENCE was using all the right bits to be
scheduling optimal, and thus power efficient, by simply using wait_event()
+ wake_up(), that code was unfortunately removed.

As KFENCE was exposed to various different configs and tests, the
scheduling optimal code slowly disappeared.  First because of hung task
warnings, and finally because of deadlocks when an allocation is made by
timer code with debug objects enabled.  Clearly, the "fixes" were not too
friendly for devices that want to be power efficient.

Therefore, let's try a little harder to fix the hung task and deadlock
problems that we have with wait_event() + wake_up(), while remaining as
scheduling friendly and power efficient as possible.

Crucially, we need to defer the wake_up() to an irq_work, avoiding any
potential for deadlock.

The result with this series is that on the devices where we observed a
power regression, power usage returns back to baseline levels.

This patch (of 3):

On mostly-idle systems, we have observed that toggle_allocation_gate() is
a cause of frequent wake-ups, preventing an otherwise idle CPU to go into
a lower power state.

A late change in KFENCE's development, due to a potential deadlock [1],
required changing the scheduling-friendly wait_event_timeout() and
wake_up() to an open-coded wait-loop using schedule_timeout().  [1]
https://lkml.kernel.org/r/000000000000c0645805b7f982e4@google.com

To avoid unnecessary wake-ups, switch to using wait_event_timeout().

Unfortunately, we still cannot use a version with direct wake_up() in
__kfence_alloc() due to the same potential for deadlock as in [1].
Instead, add a level of indirection via an irq_work that is scheduled if
we determine that the kfence_timer requires a wake_up().

Link: https://lkml.kernel.org/r/20210421105132.3965998-1-elver@google.com
Link: https://lkml.kernel.org/r/20210421105132.3965998-2-elver@google.com
Fixes: 0ce20dd84089 ("mm: add Kernel Electric-Fence infrastructure")
Signed-off-by: Marco Elver <elver@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Jann Horn <jannh@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Hillf Danton <hdanton@sina.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>

Bug: 172317151
Bug: 185280916
Test: power team confirmed there's no regression
(cherry picked from commit 0ac66fbbadde5547db190e9d87ff2e77d245f9a2
 https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git akpm)
Signed-off-by: Alexander Potapenko <glider@google.com>
Change-Id: Idba39683f0b76eb3f70df1113e43d94845fab5bf
2026-05-07 17:24:08 +03:00
..
kasan BACKPORT: kasan: use error_report_end tracepoint 2026-05-07 17:24:06 +03:00
kfence FROMGIT: kfence: await for allocation using wait_event 2026-05-07 17:24:08 +03:00
backing-dev.c
balloon_compaction.c
cleancache.c
cma.c Merge android11-5.4.265+ (a34cc1d) into msm-5.4 2024-02-29 15:10:56 +05:30
cma.h
cma_debug.c
compaction.c BACKPORT: sysctl: pass kernel pointers to ->proc_handler 2025-12-23 13:36:15 -08:00
debug.c
debug_page_ref.c
dmapool.c
early_ioremap.c
fadvise.c
failslab.c
filemap.c Merge tag 'ASB-2025-10-06_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina 2025-10-08 15:17:54 +03:00
frame_vector.c v4l2: don't fall back to follow_pfn() if pin_user_pages_fast() fails 2022-12-08 11:23:06 +01:00
frontswap.c treewide: Remove uninitialized_var() usage 2023-06-09 10:29:01 +02:00
gup.c BACKPORT: mm/gup: Remove enfornced COW mechanism 2025-05-18 08:08:42 +00:00
gup_benchmark.c
highmem.c
hmm.c mm/hmm: move pmd_to_hmm_pfn_flags() to the respective #ifdeffery 2025-08-28 16:21:34 +02:00
huge_memory.c Merge tag 'ASB-2025-08-05_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina 2025-09-01 13:17:46 +03:00
hugetlb.c BACKPORT: sysctl: pass kernel pointers to ->proc_handler 2025-12-23 13:36:15 -08:00
hugetlb_cgroup.c
hwpoison-inject.c
init-mm.c Revert "mm: protect mm_rb tree with a rwlock" 2025-05-24 05:44:05 +00:00
internal.h Revert "mm: protect mm_rb tree with a rwlock" 2025-05-24 05:44:05 +00:00
interval_tree.c
Kconfig Revert "mm: introduce CONFIG_SPECULATIVE_PAGE_FAULT" 2025-05-24 05:44:57 +00:00
Kconfig.debug
khugepaged.c mm/khugepaged: fix the address passed to notifier on testing young 2025-10-02 13:34:28 +02:00
kmemleak-test.c
kmemleak.c UPSTREAM: kfence: make compatible with kmemleak 2026-05-07 17:24:07 +03:00
ksm.c Merge android11-5.4.249+ (d57e792) into msm-5.4 2023-09-28 16:45:28 +05:30
list_lru.c
maccess.c BACKPORT: maccess: rename probe_user_{read,write} to copy_{from,to}_user_nofault 2026-01-14 18:13:22 -08:00
madvise.c Merge tag 'ASB-2025-10-06_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina 2025-10-08 15:17:54 +03:00
Makefile BACKPORT: mm: add Kernel Electric-Fence infrastructure 2026-05-07 17:24:01 +03:00
memblock.c This is the 5.4.232 stable release 2023-02-22 12:30:48 +00:00
memcontrol.c UPSTREAM: mm: memcontrol: recursive memory.low protection 2026-01-14 18:13:12 -08:00
memfd.c
memory-failure.c Merge branch 'android11-5.4-lts' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina 2025-10-08 15:23:13 +03:00
memory.c BACKPORT: mm/memory.c: Add memory read privilege on page fault handling 2026-01-14 18:13:19 -08:00
memory_hotplug.c
mempolicy.c Revert "mm: protect VMA modifications using VMA sequence count" 2025-05-24 05:44:09 +00:00
mempool.c
memremap.c
memtest.c memtest: use {READ,WRITE}_ONCE in memory scanning 2024-04-13 12:51:27 +02:00
migrate.c Merge branch 'android11-5.4-lts' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina 2025-10-08 15:23:13 +03:00
mincore.c
mlock.c Revert "mm: protect VMA modifications using VMA sequence count" 2025-05-24 05:44:09 +00:00
mm_init.c
mmap.c This is the 5.4.297 stable release 2025-09-02 10:52:40 +00:00
mmu_context.c
mmu_gather.c mm/khugepaged: fix GUP-fast interaction by sending IPI 2022-12-14 11:30:42 +01:00
mmu_notifier.c
mmzone.c
mprotect.c Revert "mm: protect VMA modifications using VMA sequence count" 2025-05-24 05:44:09 +00:00
mremap.c Revert "mm: protect mremap() against SPF hanlder" 2025-05-24 05:44:08 +00:00
msync.c
nommu.c BACKPORT: mm: remove the pgprot argument to __vmalloc 2026-01-14 17:48:09 -08:00
oom_kill.c Merge tag 'ASB-2025-05-05_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina 2025-05-18 08:00:20 +00:00
OWNERS
page-writeback.c BACKPORT: sysctl: pass kernel pointers to ->proc_handler 2025-12-23 13:36:15 -08:00
page_alloc.c BACKPORT: mm: remove the pgprot argument to __vmalloc 2026-01-14 17:48:09 -08:00
page_counter.c
page_ext.c
page_idle.c BACKPORT: mm: don't be stuck to rmap lock on reclaim path 2023-01-13 08:56:32 +00:00
page_io.c
page_isolation.c
page_owner.c mm: page_owner: Fix -Wstrlcpy-strlcat-size 2025-04-26 21:17:21 +03:00
page_poison.c
page_vma_mapped.c
pagewalk.c mm: pagewalk: Fix race between unmap and page walker 2022-10-15 07:54:36 +02:00
percpu-internal.h
percpu-km.c
percpu-stats.c
percpu-vm.c
percpu.c BACKPORT: mm: remove the pgprot argument to __vmalloc 2026-01-14 17:48:09 -08:00
pgsize_migration.c ANDROID: 16K: Allocate pad vma on the stack 2025-08-22 07:07:13 -07:00
pgtable-generic.c
process_vm_access.c
readahead.c vfs: fix readahead(2) on block devices 2023-11-20 10:30:08 +01:00
rmap.c Revert "mm: introduce __page_add_new_anon_rmap()" 2025-05-24 05:44:06 +00:00
rodata_test.c BACKPORT: maccess: rename probe_kernel_{read,write} to copy_{from,to}_kernel_nofault 2026-01-14 18:13:21 -08:00
shmem.c UPSTREAM: kernfs: Add removed_size out param for simple_xattr_set 2026-01-14 18:13:12 -08:00
showmem.c
shuffle.c
shuffle.h
slab.c BACKPORT: mm, kfence: insert KFENCE hooks for SLAB 2026-05-07 17:24:04 +03:00
slab.h
slab_common.c BACKPORT: mm, kfence: insert KFENCE hooks for SLAB 2026-05-07 17:24:04 +03:00
slob.c
slub.c BACKPORT: mm, kfence: insert KFENCE hooks for SLUB 2026-05-07 17:24:04 +03:00
sparse-vmemmap.c
sparse.c
swap.c Revert "mm: introduce __lru_cache_add_active_or_unevictable" 2025-05-24 05:44:06 +00:00
swap_cgroup.c
swap_slots.c
swap_state.c Revert "mm: protect VMA modifications using VMA sequence count" 2025-05-24 05:44:09 +00:00
swapfile.c This is the 5.4.285 stable release 2024-11-09 11:29:17 +00:00
truncate.c
usercopy.c
userfaultfd.c UPSTREAM: mm/shmem: use page_mapping() to detect page cache for uffd continue 2025-05-18 08:08:42 +00:00
util.c BACKPORT: sysctl: pass kernel pointers to ->proc_handler 2025-12-23 13:36:15 -08:00
vmacache.c
vmalloc.c BACKPORT: mm: remove the pgprot argument to __vmalloc 2026-01-14 17:48:09 -08:00
vmpressure.c
vmscan.c Merge tag 'ASB-2025-06-05_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina 2025-06-30 10:49:17 +03:00
vmstat.c BACKPORT: sysctl: pass kernel pointers to ->proc_handler 2025-12-23 13:36:15 -08:00
workingset.c
z3fold.c
zbud.c
zpool.c
zsmalloc.c Merge tag 'ASB-2025-10-06_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina 2025-10-08 15:17:54 +03:00
zswap.c