lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAD=FV=Udm8M2HnMWzzY-cyr7UCVf-0O8uSe-yOAfJ+27YBOTdQ@mail.gmail.com>
Date: Fri, 2 May 2025 07:39:44 -0700
From: Doug Anderson <dianders@...omium.org>
To: Max Kellermann <max.kellermann@...os.com>
Cc: akpm@...ux-foundation.org, song@...nel.org, joel.granados@...nel.org, 
	cminyard@...sta.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] kernel/watchdog: add /sys/kernel/{hard,soft}lockup_count

Hi,

On Fri, May 2, 2025 at 3:39 AM Max Kellermann <max.kellermann@...os.com> wrote:
>
> There is /proc/sys/kernel/hung_task_detect_count,
> /sys/kernel/warn_count and /sys/kernel/oops_count but there is no
> userspace-accessible counter for hard/soft lockups.  Having this is
> useful for monitoring tools.

Hmmm. I suspect this has more to do with the fact that both hard and
soft lockups nearly always end up being fatal. ...but I guess
technically they could be recovered from and the kernel can be
configured not to panic, so I guess it would be OK to add something
like this.

It feels like there would be a better place for these to go than
straight in `/sys/kernel`, though I don't really know it. Maybe
someone else on this thread has opinions? Any chance they could go in
"debugfs"?


> Signed-off-by: Max Kellermann <max.kellermann@...os.com>
> ---
>  kernel/watchdog.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
>
> diff --git a/kernel/watchdog.c b/kernel/watchdog.c
> index 9fa2af9dbf2c..09994bfb47af 100644
> --- a/kernel/watchdog.c
> +++ b/kernel/watchdog.c
> @@ -63,6 +63,29 @@ int __read_mostly sysctl_hardlockup_all_cpu_backtrace;
>   */
>  unsigned int __read_mostly hardlockup_panic =
>                         IS_ENABLED(CONFIG_BOOTPARAM_HARDLOCKUP_PANIC);
> +
> +#ifdef CONFIG_SYSFS
> +
> +static unsigned int hardlockup_count;
> +
> +static ssize_t hardlockup_count_show(struct kobject *kobj, struct kobj_attribute *attr,
> +                                    char *page)
> +{
> +       return sysfs_emit(page, "%u\n", hardlockup_count);
> +}
> +
> +static struct kobj_attribute hardlockup_count_attr = __ATTR_RO(hardlockup_count);
> +
> +static __init int kernel_hardlockup_sysfs_init(void)
> +{
> +       sysfs_add_file_to_group(kernel_kobj, &hardlockup_count_attr.attr, NULL);
> +       return 0;
> +}
> +
> +late_initcall(kernel_hardlockup_sysfs_init);
> +
> +#endif // CONFIG_SYSFS
> +
>  /*
>   * We may not want to enable hard lockup detection by default in all cases,
>   * for example when running the kernel as a guest on a hypervisor. In these
> @@ -169,6 +192,10 @@ void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs)
>                 unsigned int this_cpu = smp_processor_id();
>                 unsigned long flags;
>
> +#ifdef CONFIG_SYSFS
> +               ++hardlockup_count;
> +#endif

Please no embedded ifdefs like this. I personally wouldn't hate it if
the "unsigned int" was simply always defined, but if we want to keep
it only defined for sysfs then please use a function to increment this
that's declared as a static inline noop in the case that sysfs is off.

-Doug

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ