Skip to content
  1. May 07, 2021
  2. May 06, 2021
    • Marco Elver's avatar
      kfence: use power-efficient work queue to run delayed work · 36f0b35d
      Marco Elver authored
      
      
      Use the power-efficient work queue, to avoid the pathological case where
      we keep pinning ourselves on the same possibly idle CPU on systems that
      want to be power-efficient (https://lwn.net/Articles/731052/).
      
      Link: https://lkml.kernel.org/r/20210421105132.3965998-4-elver@google.com
      Signed-off-by: default avatarMarco Elver <elver@google.com>
      Cc: Alexander Potapenko <glider@google.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Hillf Danton <hdanton@sina.com>
      Cc: Jann Horn <jannh@google.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      36f0b35d
    • Marco Elver's avatar
      kfence: maximize allocation wait timeout duration · 37c9284f
      Marco Elver authored
      
      
      The allocation wait timeout was initially added because of warnings due to
      CONFIG_DETECT_HUNG_TASK=y [1].  While the 1 sec timeout is sufficient to
      resolve the warnings (given the hung task timeout must be 1 sec or larger)
      it may cause unnecessary wake-ups if the system is idle:
      
        https://lkml.kernel.org/r/CADYN=9J0DQhizAGB0-jz4HOBBh+05kMBXb4c0cXMS7Qi5NAJiw@mail.gmail.com
      
      Fix it by computing the timeout duration in terms of the current
      sysctl_hung_task_timeout_secs value.
      
      Link: https://lkml.kernel.org/r/20210421105132.3965998-3-elver@google.com
      Signed-off-by: default avatarMarco Elver <elver@google.com>
      Cc: Alexander Potapenko <glider@google.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Hillf Danton <hdanton@sina.com>
      Cc: Jann Horn <jannh@google.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      37c9284f
    • Marco Elver's avatar
      kfence: await for allocation using wait_event · 407f1d8c
      Marco Elver authored
      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: 0ce20dd8
      
       ("mm: add Kernel Electric-Fence infrastructure")
      Signed-off-by: default avatarMarco 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: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      407f1d8c
    • Marco Elver's avatar
      kfence: zero guard page after out-of-bounds access · 94868a1e
      Marco Elver authored
      
      
      After an out-of-bounds accesses, zero the guard page before re-protecting
      in kfence_guarded_free().  On one hand this helps make the failure mode of
      subsequent out-of-bounds accesses more deterministic, but could also
      prevent certain information leaks.
      
      Link: https://lkml.kernel.org/r/20210312121653.348518-1-elver@google.com
      Signed-off-by: default avatarMarco Elver <elver@google.com>
      Acked-by: default avatarAlexander Potapenko <glider@google.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Andrey Konovalov <andreyknvl@google.com>
      Cc: Jann Horn <jannh@google.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      94868a1e
    • Zhang Yunkai's avatar
      mm/process_vm_access.c: remove duplicate include · 0c4ff27a
      Zhang Yunkai authored
      
      
      'linux/compat.h' included in 'process_vm_access.c' is duplicated.
      
      Link: https://lkml.kernel.org/r/20210306132122.220431-1-zhang.yunkai@zte.com.cn
      Signed-off-by: default avatarZhang Yunkai <zhang.yunkai@zte.com.cn>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      0c4ff27a