kfence: Avoid stalling work queue task without allocations 48/281548/1
authorMarco Elver <elver@google.com>
Tue, 10 Nov 2020 13:53:20 +0000 (14:53 +0100)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Tue, 20 Sep 2022 02:44:45 +0000 (11:44 +0900)
commit4850798f6e8f804dca444ba5ba400313167a1356
tree8fd61153168e4c79eef2cae1678588cfd178d08e
parent5c0118ae49bbd1b9e875cf10579f434637d542bd
kfence: Avoid stalling work queue task without allocations

To toggle the allocation gates, we set up a delayed work that calls
toggle_allocation_gate(). Here we use wait_event() to await an
allocation and subsequently disable the static branch again. However, if
the kernel has stopped doing allocations entirely, we'd wait
indefinitely, and stall the worker task. This may also result in the
appropriate warnings if CONFIG_DETECT_HUNG_TASK=y.

Therefore, introduce a 1 second timeout and use wait_event_timeout(). If
the timeout is reached, the static branch is disabled and a new delayed
work is scheduled to try setting up an allocation at a later time.

Note that, this scenario is very unlikely during normal workloads once
the kernel has booted and user space tasks are running. It can, however,
happen during early boot after KFENCE has been enabled, when e.g.
running tests that do not result in any allocations.

Link: https://lkml.kernel.org/r/CADYN=9J0DQhizAGB0-jz4HOBBh+05kMBXb4c0cXMS7Qi5NAJiw@mail.gmail.com
Reported-by: Anders Roxell <anders.roxell@linaro.org>
Signed-off-by: Marco Elver <elver@google.com>
[port kfence feature to rpi-5.10.95]
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Ia4e37404fce3497d6c9d32cae23ffa5d106055da
mm/kfence/core.c