1. 19 Jun, 2023 11 commits
  2. 10 Jun, 2023 29 commits
    • Arnd Bergmann's avatar
      syscalls: add sys_ni_posix_timers prototype · a94181ec
      Arnd Bergmann authored
      The sys_ni_posix_timers() definition causes a warning when the declaration
      is missing, so this needs to be added along with the normal syscalls,
      outside of the #ifdef.
      
      kernel/time/posix-stubs.c:26:17: error: no previous prototype for 'sys_ni_posix_timers' [-Werror=missing-prototypes]
      
      Link: https://lkml.kernel.org/r/20230607142925.3126422-1-arnd@kernel.orgSigned-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      a94181ec
    • Kees Cook's avatar
      checkpatch: check for 0-length and 1-element arrays · f26799ff
      Kees Cook authored
      Fake flexible arrays have been deprecated since last millennium.  Proper
      C99 flexible arrays must be used throughout the kernel so
      CONFIG_FORTIFY_SOURCE and CONFIG_UBSAN_BOUNDS can provide proper array
      bounds checking.
      
      [joe@perches.com: various suggestions]
      Link: https://lkml.kernel.org/r/20230601160746.up.948-kees@kernel.org
      Link: https://lore.kernel.org/r/20230517204530.never.151-kees@kernel.orgSigned-off-by: default avatarKees Cook <keescook@chromium.org>
      Acked-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
      Acked-by: default avatarJoe Perches <joe@perches.com>
      Cc: Andy Whitcroft <apw@canonical.com>
      Cc: Dwaipayan Ray <dwaipayanray1@gmail.com>
      Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      f26799ff
    • Zhen Lei's avatar
      kexec: enable kexec_crash_size to support two crash kernel regions · 16c6006a
      Zhen Lei authored
      The crashk_low_res should be considered by /sys/kernel/kexec_crash_size
      to support two crash kernel regions shrinking if existing.
      
      While doing it, crashk_low_res will only be shrunk when the entire
      crashk_res is empty; and if the crashk_res is empty and crahk_low_res
      is not, change crashk_low_res to be crashk_res.
      
      [bhe@redhat.com: redo changelog]
      Link: https://lkml.kernel.org/r/20230527123439.772-7-thunder.leizhen@huawei.comSigned-off-by: default avatarZhen Lei <thunder.leizhen@huawei.com>
      Acked-by: default avatarBaoquan He <bhe@redhat.com>
      Cc: Cong Wang <amwang@redhat.com>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Michael Holzheu <holzheu@linux.vnet.ibm.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      16c6006a
    • Zhen Lei's avatar
      kexec: add helper __crash_shrink_memory() · 5b7bfb32
      Zhen Lei authored
      No functional change, in preparation for the next patch so that it is
      easier to review.
      
      [akpm@linux-foundation.org: make  __crash_shrink_memory() static]
        Link: https://lore.kernel.org/oe-kbuild-all/202305280717.Pw06aLkz-lkp@intel.com/
      Link: https://lkml.kernel.org/r/20230527123439.772-6-thunder.leizhen@huawei.comSigned-off-by: default avatarZhen Lei <thunder.leizhen@huawei.com>
      Acked-by: default avatarBaoquan He <bhe@redhat.com>
      Cc: Cong Wang <amwang@redhat.com>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Michael Holzheu <holzheu@linux.vnet.ibm.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      5b7bfb32
    • Zhen Lei's avatar
      kexec: improve the readability of crash_shrink_memory() · 8a7db779
      Zhen Lei authored
      The major adjustments are:
      1. end = start + new_size.
         The 'end' here is not an accurate representation, because it is not the
         new end of crashk_res, but the start of ram_res, difference 1. So
         eliminate it and replace it with ram_res->start.
      2. Use 'ram_res->start' and 'ram_res->end' as arguments to
         crash_free_reserved_phys_range() to indicate that the memory covered by
         'ram_res' is released from the crashk. And keep it close to
         insert_resource().
      3. Replace 'if (start == end)' with 'if (!new_size)', clear indication that
         all crashk memory will be shrunken.
      
      No functional change.
      
      Link: https://lkml.kernel.org/r/20230527123439.772-5-thunder.leizhen@huawei.comSigned-off-by: default avatarZhen Lei <thunder.leizhen@huawei.com>
      Acked-by: default avatarBaoquan He <bhe@redhat.com>
      Cc: Cong Wang <amwang@redhat.com>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Michael Holzheu <holzheu@linux.vnet.ibm.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      8a7db779
    • Zhen Lei's avatar
      kexec: clear crashk_res if all its memory has been released · f7f567b9
      Zhen Lei authored
      If the resource of crashk_res has been released, it is better to clear
      crashk_res.start and crashk_res.end.  Because 'end = start - 1' is not
      reasonable, and in some places the test is based on crashk_res.end, not
      resource_size(&crashk_res).
      
      Link: https://lkml.kernel.org/r/20230527123439.772-4-thunder.leizhen@huawei.comSigned-off-by: default avatarZhen Lei <thunder.leizhen@huawei.com>
      Acked-by: default avatarBaoquan He <bhe@redhat.com>
      Cc: Cong Wang <amwang@redhat.com>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Michael Holzheu <holzheu@linux.vnet.ibm.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      f7f567b9
    • Zhen Lei's avatar
      kexec: delete a useless check in crash_shrink_memory() · 6f22a744
      Zhen Lei authored
      The check '(crashk_res.parent != NULL)' is added by commit e05bd336
      ("kexec: fix Oops in crash_shrink_memory()"), but it's stale now.  Because
      if 'crashk_res' is not reserved, it will be zero in size and will be
      intercepted by the above 'if (new_size >= old_size)'.
      
      Ago:
      	if (new_size >= end - start + 1)
      
      Now:
      	old_size = (end == 0) ? 0 : end - start + 1;
      	if (new_size >= old_size)
      
      Link: https://lkml.kernel.org/r/20230527123439.772-3-thunder.leizhen@huawei.comSigned-off-by: default avatarZhen Lei <thunder.leizhen@huawei.com>
      Cc: Baoquan He <bhe@redhat.com>
      Cc: Cong Wang <amwang@redhat.com>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Michael Holzheu <holzheu@linux.vnet.ibm.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      6f22a744
    • Zhen Lei's avatar
      kexec: fix a memory leak in crash_shrink_memory() · 1cba6c43
      Zhen Lei authored
      Patch series "kexec: enable kexec_crash_size to support two crash kernel
      regions".
      
      When crashkernel=X fails to reserve region under 4G, it will fall back to
      reserve region above 4G and a region of the default size will also be
      reserved under 4G.  Unfortunately, /sys/kernel/kexec_crash_size only
      supports one crash kernel region now, the user cannot sense the low memory
      reserved by reading /sys/kernel/kexec_crash_size.  Also, low memory cannot
      be freed by writing this file.
      
      For example:
      resource_size(crashk_res) = 512M
      resource_size(crashk_low_res) = 256M
      
      The result of 'cat /sys/kernel/kexec_crash_size' is 512M, but it should be
      768M.  When we execute 'echo 0 > /sys/kernel/kexec_crash_size', the size
      of crashk_res becomes 0 and resource_size(crashk_low_res) is still 256 MB,
      which is incorrect.
      
      Since crashk_res manages the memory with high address and crashk_low_res
      manages the memory with low address, crashk_low_res is shrunken only when
      all crashk_res is shrunken.  And because when there is only one crash
      kernel region, crashk_res is always used.  Therefore, if all crashk_res is
      shrunken and crashk_low_res still exists, swap them.
      
      
      This patch (of 6):
      
      If the value of parameter 'new_size' is in the semi-open and semi-closed
      interval (crashk_res.end - KEXEC_CRASH_MEM_ALIGN + 1, crashk_res.end], the
      calculation result of ram_res is:
      
      	ram_res->start = crashk_res.end + 1
      	ram_res->end   = crashk_res.end
      
      The operation of insert_resource() fails, and ram_res is not added to
      iomem_resource.  As a result, the memory of the control block ram_res is
      leaked.
      
      In fact, on all architectures, the start address and size of crashk_res
      are already aligned by KEXEC_CRASH_MEM_ALIGN.  Therefore, we do not need
      to round up crashk_res.start again.  Instead, we should round up
      'new_size' in advance.
      
      Link: https://lkml.kernel.org/r/20230527123439.772-1-thunder.leizhen@huawei.com
      Link: https://lkml.kernel.org/r/20230527123439.772-2-thunder.leizhen@huawei.com
      Fixes: 6480e5a0 ("kdump: add missing RAM resource in crash_shrink_memory()")
      Fixes: 06a7f711 ("kexec: premit reduction of the reserved memory size")
      Signed-off-by: default avatarZhen Lei <thunder.leizhen@huawei.com>
      Acked-by: default avatarBaoquan He <bhe@redhat.com>
      Cc: Cong Wang <amwang@redhat.com>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Michael Holzheu <holzheu@linux.vnet.ibm.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      1cba6c43
    • Joseph Qi's avatar
      ocfs2: cleanup trace events · 69fe5c43
      Joseph Qi authored
      After commit 6dc8bc0f ("ocfs2: switch to iter_file_splice_write()"),
      ocfs2 has switched from ocfs2_file_splice_write() to
      iter_file_splice_write(), so cleanup the corresponding trace event as
      well.
      
      Link: https://lkml.kernel.org/r/20230528132033.217664-2-joseph.qi@linux.alibaba.comSigned-off-by: default avatarJoseph Qi <joseph.qi@linux.alibaba.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Mark Fasheh <mark@fasheh.com>
      Cc: Joel Becker <jlbec@evilplan.org>
      Cc: Junxiao Bi <junxiao.bi@oracle.com>
      Cc: Changwei Ge <gechangwei@live.cn>
      Cc: Gang He <ghe@suse.com>
      Cc: Jun Piao <piaojun@huawei.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      69fe5c43
    • Joseph Qi's avatar
      ocfs2: correct return value of ocfs2_local_free_info() · d32840ad
      Joseph Qi authored
      Now in ocfs2_local_free_info(), it returns 0 even if it actually fails. 
      Though it doesn't cause any real problem since the only caller
      dquot_disable() ignores the return value, we'd better return correct as it
      is.
      
      Link: https://lkml.kernel.org/r/20230528132033.217664-1-joseph.qi@linux.alibaba.comSigned-off-by: default avatarJoseph Qi <joseph.qi@linux.alibaba.com>
      Cc: Mark Fasheh <mark@fasheh.com>
      Cc: Joel Becker <jlbec@evilplan.org>
      Cc: Junxiao Bi <junxiao.bi@oracle.com>
      Cc: Joseph Qi <jiangqi903@gmail.com>
      Cc: Changwei Ge <gechangwei@live.cn>
      Cc: Gang He <ghe@suse.com>
      Cc: Jun Piao <piaojun@huawei.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      d32840ad
    • Simon Horman's avatar
      kexec: avoid calculating array size twice · 4df3504e
      Simon Horman authored
      Avoid calculating array size twice in kexec_purgatory_setup_sechdrs().
      Once using array_size(), and once open-coded.
      
      Flagged by Coccinelle:
      
        .../kexec_file.c:881:8-25: WARNING: array_size is already used (line 877) to compute the same size
      
      No functional change intended.
      Compile tested only.
      
      Link: https://lkml.kernel.org/r/20230525-kexec-array_size-v1-1-8b4bf4f7500a@kernel.orgSigned-off-by: default avatarSimon Horman <horms@kernel.org>
      Acked-by: default avatarBaoquan He <bhe@redhat.com>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Zhen Lei <thunder.leizhen@huawei.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      4df3504e
    • Alexey Dobriyan's avatar
      include/linux/math.h: fix mult_frac() multiple argument evaluation bug · 048a9883
      Alexey Dobriyan authored
      mult_frac() evaluates _all_ arguments multiple times in the body.
      
      Clarify comment while I'm at it.
      
      Link: https://lkml.kernel.org/r/f9f9fdbb-ec8e-4f5e-a998-2a58627a1a43@p183Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      048a9883
    • Douglas Anderson's avatar
      arm64: enable perf events based hard lockup detector · d7a0fe9e
      Douglas Anderson authored
      With the recent feature added to enable perf events to use pseudo NMIs as
      interrupts on platforms which support GICv3 or later, its now been
      possible to enable hard lockup detector (or NMI watchdog) on arm64
      platforms.  So enable corresponding support.
      
      One thing to note here is that normally lockup detector is initialized
      just after the early initcalls but PMU on arm64 comes up much later as
      device_initcall().  To cope with that, override
      arch_perf_nmi_is_available() to let the watchdog framework know PMU not
      ready, and inform the framework to re-initialize lockup detection once PMU
      has been initialized.
      
      [dianders@chromium.org: only HAVE_HARDLOCKUP_DETECTOR_PERF if the PMU config is enabled]
        Link: https://lkml.kernel.org/r/20230523073952.1.I60217a63acc35621e13f10be16c0cd7c363caf8c@changeid
      Link: https://lkml.kernel.org/r/20230519101840.v5.18.Ia44852044cdcb074f387e80df6b45e892965d4a1@changeidCo-developed-by: default avatarSumit Garg <sumit.garg@linaro.org>
      Signed-off-by: default avatarSumit Garg <sumit.garg@linaro.org>
      Co-developed-by: default avatarPingfan Liu <kernelfans@gmail.com>
      Signed-off-by: default avatarPingfan Liu <kernelfans@gmail.com>
      Signed-off-by: default avatarLecopzer Chen <lecopzer.chen@mediatek.com>
      Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      d7a0fe9e
    • Lecopzer Chen's avatar
      arm64: add hw_nmi_get_sample_period for preparation of lockup detector · 94946f9e
      Lecopzer Chen authored
      Set safe maximum CPU frequency to 5 GHz in case a particular platform
      doesn't implement cpufreq driver.  Although, architecture doesn't put any
      restrictions on maximum frequency but 5 GHz seems to be safe maximum given
      the available Arm CPUs in the market which are clocked much less than 5
      GHz.
      
      On the other hand, we can't make it much higher as it would lead to a
      large hard-lockup detection timeout on parts which are running slower (eg.
      1GHz on Developerbox) and doesn't possess a cpufreq driver.
      
      Link: https://lkml.kernel.org/r/20230519101840.v5.17.Ia9d02578e89c3f44d3cb12eec8b0176603c8ab2f@changeidCo-developed-by: default avatarSumit Garg <sumit.garg@linaro.org>
      Signed-off-by: default avatarSumit Garg <sumit.garg@linaro.org>
      Co-developed-by: default avatarPingfan Liu <kernelfans@gmail.com>
      Signed-off-by: default avatarPingfan Liu <kernelfans@gmail.com>
      Signed-off-by: default avatarLecopzer Chen <lecopzer.chen@mediatek.com>
      Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      94946f9e
    • Lecopzer Chen's avatar
      watchdog/perf: adapt the watchdog_perf interface for async model · 930d8f8d
      Lecopzer Chen authored
      When lockup_detector_init()->watchdog_hardlockup_probe(), PMU may be not
      ready yet.  E.g.  on arm64, PMU is not ready until
      device_initcall(armv8_pmu_driver_init).  And it is deeply integrated with
      the driver model and cpuhp.  Hence it is hard to push this initialization
      before smp_init().
      
      But it is easy to take an opposite approach and try to initialize the
      watchdog once again later.  The delayed probe is called using workqueues. 
      It need to allocate memory and must be proceed in a normal context.  The
      delayed probe is able to use if watchdog_hardlockup_probe() returns
      non-zero which means the return code returned when PMU is not ready yet.
      
      Provide an API - lockup_detector_retry_init() for anyone who needs to
      delayed init lockup detector if they had ever failed at
      lockup_detector_init().
      
      The original assumption is: nobody should use delayed probe after
      lockup_detector_check() which has __init attribute.  That is, anyone uses
      this API must call between lockup_detector_init() and
      lockup_detector_check(), and the caller must have __init attribute
      
      Link: https://lkml.kernel.org/r/20230519101840.v5.16.If4ad5dd5d09fb1309cebf8bcead4b6a5a7758ca7@changeidReviewed-by: default avatarPetr Mladek <pmladek@suse.com>
      Co-developed-by: default avatarPingfan Liu <kernelfans@gmail.com>
      Signed-off-by: default avatarPingfan Liu <kernelfans@gmail.com>
      Signed-off-by: default avatarLecopzer Chen <lecopzer.chen@mediatek.com>
      Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Suggested-by: default avatarPetr Mladek <pmladek@suse.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      930d8f8d
    • Douglas Anderson's avatar
      watchdog/perf: add a weak function for an arch to detect if perf can use NMIs · b17aa959
      Douglas Anderson authored
      On arm64, NMI support needs to be detected at runtime.  Add a weak
      function to the perf hardlockup detector so that an architecture can
      implement it to detect whether NMIs are available.
      
      Link: https://lkml.kernel.org/r/20230519101840.v5.15.Ic55cb6f90ef5967d8aaa2b503a4e67c753f64d3a@changeidSigned-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Lecopzer Chen <lecopzer.chen@mediatek.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Pingfan Liu <kernelfans@gmail.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      b17aa959
    • Douglas Anderson's avatar
      watchdog/hardlockup: detect hard lockups using secondary (buddy) CPUs · 1f423c90
      Douglas Anderson authored
      Implement a hardlockup detector that doesn't doesn't need any extra
      arch-specific support code to detect lockups.  Instead of using something
      arch-specific we will use the buddy system, where each CPU watches out for
      another one.  Specifically, each CPU will use its softlockup hrtimer to
      check that the next CPU is processing hrtimer interrupts by verifying that
      a counter is increasing.
      
      NOTE: unlike the other hard lockup detectors, the buddy one can't easily
      show what's happening on the CPU that locked up just by doing a simple
      backtrace.  It relies on some other mechanism in the system to get
      information about the locked up CPUs.  This could be support for NMI
      backtraces like [1], it could be a mechanism for printing the PC of locked
      CPUs at panic time like [2] / [3], or it could be something else.  Even
      though that means we still rely on arch-specific code, this arch-specific
      code seems to often be implemented even on architectures that don't have a
      hardlockup detector.
      
      This style of hardlockup detector originated in some downstream Android
      trees and has been rebased on / carried in ChromeOS trees for quite a long
      time for use on arm and arm64 boards.  Historically on these boards we've
      leveraged mechanism [2] / [3] to get information about hung CPUs, but we
      could move to [1].
      
      Although the original motivation for the buddy system was for use on
      systems without an arch-specific hardlockup detector, it can still be
      useful to use even on systems that _do_ have an arch-specific hardlockup
      detector.  On x86, for instance, there is a 24-part patch series [4] in
      progress switching the arch-specific hard lockup detector from a scarce
      perf counter to a less-scarce hardware resource.  Potentially the buddy
      system could be a simpler alternative to free up the perf counter but
      still get hard lockup detection.
      
      Overall, pros (+) and cons (-) of the buddy system compared to an
      arch-specific hardlockup detector (which might be implemented using
      perf):
      + The buddy system is usable on systems that don't have an
        arch-specific hardlockup detector, like arm32 and arm64 (though it's
        being worked on for arm64 [5]).
      + The buddy system may free up scarce hardware resources.
      + If a CPU totally goes out to lunch (can't process NMIs) the buddy
        system could still detect the problem (though it would be unlikely
        to be able to get a stack trace).
      + The buddy system uses the same timer function to pet the hardlockup
        detector on the running CPU as it uses to detect hardlockups on
        other CPUs. Compared to other hardlockup detectors, this means it
        generates fewer interrupts and thus is likely better able to let
        CPUs stay idle longer.
      - If all CPUs are hard locked up at the same time the buddy system
        can't detect it.
      - If we don't have SMP we can't use the buddy system.
      - The buddy system needs an arch-specific mechanism (possibly NMI
        backtrace) to get info about the locked up CPU.
      
      [1] https://lore.kernel.org/r/20230419225604.21204-1-dianders@chromium.org
      [2] https://issuetracker.google.com/172213129
      [3] https://docs.kernel.org/trace/coresight/coresight-cpu-debug.html
      [4] https://lore.kernel.org/lkml/20230301234753.28582-1-ricardo.neri-calderon@linux.intel.com/
      [5] https://lore.kernel.org/linux-arm-kernel/20220903093415.15850-1-lecopzer.chen@mediatek.com/
      
      Link: https://lkml.kernel.org/r/20230519101840.v5.14.I6bf789d21d0c3d75d382e7e51a804a7a51315f2c@changeidSigned-off-by: default avatarColin Cross <ccross@android.com>
      Signed-off-by: default avatarMatthias Kaehlcke <mka@chromium.org>
      Signed-off-by: default avatarGuenter Roeck <groeck@chromium.org>
      Signed-off-by: default avatarTzung-Bi Shih <tzungbi@chromium.org>
      Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Pingfan Liu <kernelfans@gmail.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      1f423c90
    • Douglas Anderson's avatar
      watchdog/hardlockup: have the perf hardlockup use __weak functions more cleanly · d9b3629a
      Douglas Anderson authored
      The fact that there watchdog_hardlockup_enable(),
      watchdog_hardlockup_disable(), and watchdog_hardlockup_probe() are
      declared __weak means that the configured hardlockup detector can define
      non-weak versions of those functions if it needs to.  Instead of doing
      this, the perf hardlockup detector hooked itself into the default __weak
      implementation, which was a bit awkward.  Clean this up.
      
      From comments, it looks as if the original design was done because the
      __weak function were expected to implemented by the architecture and not
      by the configured hardlockup detector.  This got awkward when we tried to
      add the buddy lockup detector which was not arch-specific but wanted to
      hook into those same functions.
      
      This is not expected to have any functional impact.
      
      Link: https://lkml.kernel.org/r/20230519101840.v5.13.I847d9ec852449350997ba00401d2462a9cb4302b@changeidSigned-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Lecopzer Chen <lecopzer.chen@mediatek.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Pingfan Liu <kernelfans@gmail.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      d9b3629a
    • Douglas Anderson's avatar
      watchdog/hardlockup: rename some "NMI watchdog" constants/function · df95d308
      Douglas Anderson authored
      Do a search and replace of:
      - NMI_WATCHDOG_ENABLED => WATCHDOG_HARDLOCKUP_ENABLED
      - SOFT_WATCHDOG_ENABLED => WATCHDOG_SOFTOCKUP_ENABLED
      - watchdog_nmi_ => watchdog_hardlockup_
      - nmi_watchdog_available => watchdog_hardlockup_available
      - nmi_watchdog_user_enabled => watchdog_hardlockup_user_enabled
      - soft_watchdog_user_enabled => watchdog_softlockup_user_enabled
      - NMI_WATCHDOG_DEFAULT => WATCHDOG_HARDLOCKUP_DEFAULT
      
      Then update a few comments near where names were changed.
      
      This is specifically to make it less confusing when we want to introduce
      the buddy hardlockup detector, which isn't using NMIs.  As part of this,
      we sanitized a few names for consistency.
      
      [trix@redhat.com: make variables static]
        Link: https://lkml.kernel.org/r/20230525162822.1.I0fb41d138d158c9230573eaa37dc56afa2fb14ee@changeid
      Link: https://lkml.kernel.org/r/20230519101840.v5.12.I91f7277bab4bf8c0cb238732ed92e7ce7bbd71a6@changeidSigned-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Reviewed-by: default avatarTom Rix <trix@redhat.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Lecopzer Chen <lecopzer.chen@mediatek.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Pingfan Liu <kernelfans@gmail.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      df95d308
    • Douglas Anderson's avatar
      watchdog/hardlockup: move perf hardlockup watchdog petting to watchdog.c · ed92e1ef
      Douglas Anderson authored
      In preparation for the buddy hardlockup detector, which wants the same
      petting logic as the current perf hardlockup detector, move the code to
      watchdog.c.  While doing this, rename the global variable to match others
      nearby.  As part of this change we have to change the code to account for
      the fact that the CPU we're running on might be different than the one
      we're checking.
      
      Currently the code in watchdog.c is guarded by
      CONFIG_HARDLOCKUP_DETECTOR_PERF, which makes this change seem silly. 
      However, a future patch will change this.
      
      Link: https://lkml.kernel.org/r/20230519101840.v5.11.I00dfd6386ee00da25bf26d140559a41339b53e57@changeidSigned-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Lecopzer Chen <lecopzer.chen@mediatek.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Pingfan Liu <kernelfans@gmail.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      ed92e1ef
    • Douglas Anderson's avatar
      watchdog/hardlockup: add a "cpu" param to watchdog_hardlockup_check() · 77c12fc9
      Douglas Anderson authored
      In preparation for the buddy hardlockup detector where the CPU checking
      for lockup might not be the currently running CPU, add a "cpu" parameter
      to watchdog_hardlockup_check().
      
      As part of this change, make hrtimer_interrupts an atomic_t since now the
      CPU incrementing the value and the CPU reading the value might be
      different.  Technially this could also be done with just READ_ONCE and
      WRITE_ONCE, but atomic_t feels a little cleaner in this case.
      
      While hrtimer_interrupts is made atomic_t, we change
      hrtimer_interrupts_saved from "unsigned long" to "int".  The "int" is
      needed to match the data type backing atomic_t for hrtimer_interrupts. 
      Even if this changes us from 64-bits to 32-bits (which I don't think is
      true for most compilers), it doesn't really matter.  All we ever do is
      increment it every few seconds and compare it to an old value so 32-bits
      is fine (even 16-bits would be).  The "signed" vs "unsigned" also doesn't
      matter for simple equality comparisons.
      
      hrtimer_interrupts_saved is _not_ switched to atomic_t nor even accessed
      with READ_ONCE / WRITE_ONCE.  The hrtimer_interrupts_saved is always
      consistently accessed with the same CPU.  NOTE: with the upcoming "buddy"
      detector there is one special case.  When a CPU goes offline/online then
      we can change which CPU is the one to consistently access a given instance
      of hrtimer_interrupts_saved.  We still can't end up with a partially
      updated hrtimer_interrupts_saved, however, because we end up petting all
      affected CPUs to make sure the new and old CPU can't end up somehow
      read/write hrtimer_interrupts_saved at the same time.
      
      Link: https://lkml.kernel.org/r/20230519101840.v5.10.I3a7d4dd8c23ac30ee0b607d77feb6646b64825c0@changeidSigned-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Lecopzer Chen <lecopzer.chen@mediatek.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Pingfan Liu <kernelfans@gmail.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      77c12fc9
    • Douglas Anderson's avatar
      watchdog/hardlockup: style changes to watchdog_hardlockup_check() / is_hardlockup() · 1610611a
      Douglas Anderson authored
      These are tiny style changes:
      - Add a blank line before a "return".
      - Renames two globals to use the "watchdog_hardlockup" prefix.
      - Store processor id in "unsigned int" rather than "int".
      - Minor comment rewording.
      - Use "else" rather than extra returns since it seemed more symmetric.
      
      Link: https://lkml.kernel.org/r/20230519101840.v5.9.I818492c326b632560b09f20d2608455ecf9d3650@changeidReviewed-by: default avatarPetr Mladek <pmladek@suse.com>
      Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Lecopzer Chen <lecopzer.chen@mediatek.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Pingfan Liu <kernelfans@gmail.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      1610611a
    • Douglas Anderson's avatar
      watchdog/hardlockup: move perf hardlockup checking/panic to common watchdog.c · 81972551
      Douglas Anderson authored
      The perf hardlockup detector works by looking at interrupt counts and
      seeing if they change from run to run.  The interrupt counts are managed
      by the common watchdog code via its watchdog_timer_fn().
      
      Currently the API between the perf detector and the common code is a
      function: is_hardlockup().  When the hard lockup detector sees that
      function return true then it handles printing out debug info and inducing
      a panic if necessary.
      
      Let's change the API a little bit in preparation for the buddy hardlockup
      detector.  The buddy hardlockup detector wants to print nearly the same
      debug info and have nearly the same panic behavior.  That means we want to
      move all that code to the common file.  For now, the code in the common
      file will only be there if the perf hardlockup detector is enabled, but
      eventually it will be selected by a common config.
      
      Right now, this _just_ moves the code from the perf detector file to the
      common file and changes the names.  It doesn't make the changes that the
      buddy hardlockup detector will need and doesn't do any style cleanups.  A
      future patch will do cleanup to make it more obvious what changed.
      
      With the above, we no longer have any callers of is_hardlockup() outside
      of the "watchdog.c" file, so we can remove it from the header, make it
      static, and move it to the same "#ifdef" block as our new
      watchdog_hardlockup_check().  While doing this, it can be noted that even
      if no hardlockup detectors were configured the existing code used to still
      have the code for counting/checking "hrtimer_interrupts" even if the perf
      hardlockup detector wasn't configured.  We didn't need to do that, so move
      all the "hrtimer_interrupts" counting to only be there if the perf
      hardlockup detector is configured as well.
      
      This change is expected to be a no-op.
      
      Link: https://lkml.kernel.org/r/20230519101840.v5.8.Id4133d3183e798122dc3b6205e7852601f289071@changeidSigned-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Lecopzer Chen <lecopzer.chen@mediatek.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Pingfan Liu <kernelfans@gmail.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      81972551
    • Douglas Anderson's avatar
      watchdog/perf: rename watchdog_hld.c to watchdog_perf.c · 6ea0d042
      Douglas Anderson authored
      The code currently in "watchdog_hld.c" is for detecting hardlockups using
      perf, as evidenced by the line in the Makefile that only compiles this
      file if CONFIG_HARDLOCKUP_DETECTOR_PERF is defined.  Rename the file to
      prepare for the buddy hardlockup detector, which doesn't use perf.
      
      It could be argued that the new name makes it less obvious that this is a
      hardlockup detector.  While true, it's not hard to remember that the
      "perf" detector is always a hardlockup detector and it's nice not to have
      names that are too convoluted.
      
      Link: https://lkml.kernel.org/r/20230519101840.v5.7.Ice803cb078d0e15fb2cbf49132f096ee2bd4199d@changeidSigned-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Acked-by: default avatarNicholas Piggin <npiggin@gmail.com>
      Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Lecopzer Chen <lecopzer.chen@mediatek.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Pingfan Liu <kernelfans@gmail.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      6ea0d042
    • Douglas Anderson's avatar
      watchdog/hardlockup: add comments to touch_nmi_watchdog() · 8b5c59a9
      Douglas Anderson authored
      In preparation for the buddy hardlockup detector, add comments to
      touch_nmi_watchdog() to make it obvious that it touches the configured
      hardlockup detector regardless of whether it's backed by an NMI.  Also
      note that arch_touch_nmi_watchdog() may not be architecture-specific.
      
      Ideally, we'd like to rename these functions but that is a fairly
      disruptive change touching a lot of drivers.  After discussion [1] the
      plan is to defer this until a good time.
      
      [1] https://lore.kernel.org/r/ZFy0TX1tfhlH8gxj@alley
      
      [akpm@linux-foundation.org: comment changes, per Petr]
        Link: https://lkml.kernel.org/r/ZGyONWPXpE1DcxA5@alley
      Link: https://lkml.kernel.org/r/20230519101840.v5.6.I4e47cbfa1bb2ebbcdb5ca16817aa2887f15dc82c@changeidSigned-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Lecopzer Chen <lecopzer.chen@mediatek.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Pingfan Liu <kernelfans@gmail.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      8b5c59a9
    • Pingfan Liu's avatar
      watchdog/perf: ensure CPU-bound context when creating hardlockup detector event · 1fafaa77
      Pingfan Liu authored
      hardlockup_detector_event_create() should create perf_event on the current
      CPU.  Preemption could not get disabled because
      perf_event_create_kernel_counter() allocates memory.  Instead, the CPU
      locality is achieved by processing the code in a per-CPU bound kthread.
      
      Add a check to prevent mistakes when calling the code in another code
      path.
      
      Link: https://lkml.kernel.org/r/20230519101840.v5.5.I654063e53782b11d53e736a8ad4897ffd207406a@changeidSigned-off-by: default avatarPingfan Liu <kernelfans@gmail.com>
      Co-developed-by: default avatarLecopzer Chen <lecopzer.chen@mediatek.com>
      Signed-off-by: default avatarLecopzer Chen <lecopzer.chen@mediatek.com>
      Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      1fafaa77
    • Lecopzer Chen's avatar
      watchdog/hardlockup: change watchdog_nmi_enable() to void · 73021118
      Lecopzer Chen authored
      Nobody cares about the return value of watchdog_nmi_enable(), changing its
      prototype to void.
      
      Link: https://lkml.kernel.org/r/20230519101840.v5.4.Ic3a19b592eb1ac4c6f6eade44ffd943e8637b6e5@changeidSigned-off-by: default avatarPingfan Liu <kernelfans@gmail.com>
      Signed-off-by: default avatarLecopzer Chen <lecopzer.chen@mediatek.com>
      Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
      Acked-by: default avatarNicholas Piggin <npiggin@gmail.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      73021118
    • Lecopzer Chen's avatar
      watchdog: remove WATCHDOG_DEFAULT · 810b560e
      Lecopzer Chen authored
      No reference to WATCHDOG_DEFAULT, remove it.
      
      Link: https://lkml.kernel.org/r/20230519101840.v5.3.I6a729209a1320e0ad212176e250ff945b8f91b2a@changeidSigned-off-by: default avatarPingfan Liu <kernelfans@gmail.com>
      Signed-off-by: default avatarLecopzer Chen <lecopzer.chen@mediatek.com>
      Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      810b560e
    • Douglas Anderson's avatar
      watchdog/perf: more properly prevent false positives with turbo modes · 4379e59f
      Douglas Anderson authored
      Currently, in the watchdog_overflow_callback() we first check to see if
      the watchdog had been touched and _then_ we handle the workaround for
      turbo mode.  This order should be reversed.
      
      Specifically, "touching" the hardlockup detector's watchdog should avoid
      lockups being detected for one period that should be roughly the same
      regardless of whether we're running turbo or not.  That means that we
      should do the extra accounting for turbo _before_ we look at (and clear)
      the global indicating that we've been touched.
      
      NOTE: this fix is made based on code inspection.  I am not aware of any
      reports where the old code would have generated false positives.  That
      being said, this order seems more correct and also makes it easier down
      the line to share code with the "buddy" hardlockup detector.
      
      Link: https://lkml.kernel.org/r/20230519101840.v5.2.I843b0d1de3e096ba111a179f3adb16d576bef5c7@changeid
      Fixes: 7edaeb68 ("kernel/watchdog: Prevent false positives with turbo modes")
      Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Colin Cross <ccross@android.com>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Guenter Roeck <groeck@chromium.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Lecopzer Chen <lecopzer.chen@mediatek.com>
      Cc: Marc Zyngier <maz@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
      Cc: Matthias Kaehlcke <mka@chromium.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nicholas Piggin <npiggin@gmail.com>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Pingfan Liu <kernelfans@gmail.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
      Cc: Ricardo Neri <ricardo.neri@intel.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Boyd <swboyd@chromium.org>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Cc: Tzung-Bi Shih <tzungbi@chromium.org>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      4379e59f