From: Sebastian Ene <sebastianene@google.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org,
Derek Kiernan <derek.kiernan@xilinx.com>,
Dragan Cvetic <dragan.cvetic@xilinx.com>,
Arnd Bergmann <arnd@arndb.de>, Rob Herring <robh+dt@kernel.org>,
devicetree@vger.kernel.org, qperret@google.com, will@kernel.org,
maz@kernel.org
Subject: Re: [PATCH v2 2/2] misc: Add a mechanism to detect stalls on guest vCPUs
Date: Sat, 23 Apr 2022 09:14:53 +0000 [thread overview]
Message-ID: <YmPDjWK5X1O3HQvk@google.com> (raw)
In-Reply-To: <YmOhmzmBL36rBO30@kroah.com>
On Sat, Apr 23, 2022 at 08:50:03AM +0200, Greg Kroah-Hartman wrote:
> On Fri, Apr 22, 2022 at 02:19:50PM +0000, Sebastian Ene wrote:
Hello Greg,
> > This patch adds support for a virtual watchdog which relies on the
> > per-cpu hrtimers to pet at regular intervals.
> >
> > Signed-off-by: Sebastian Ene <sebastianene@google.com>
> > ---
> > drivers/misc/Kconfig | 8 ++
> > drivers/misc/Makefile | 1 +
> > drivers/misc/vm-wdt.c | 215 ++++++++++++++++++++++++++++++++++++++++++
> > 3 files changed, 224 insertions(+)
> > create mode 100644 drivers/misc/vm-wdt.c
> >
> > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> > index 2b9572a6d114..0e710149ff95 100644
> > --- a/drivers/misc/Kconfig
> > +++ b/drivers/misc/Kconfig
> > @@ -493,6 +493,14 @@ config OPEN_DICE
> >
> > If unsure, say N.
> >
> > +config VM_WATCHDOG
> > + tristate "Virtual Machine Watchdog"
> > + select LOCKUP_DETECTOR
> > + help
> > + Detect CPU locks on the virtual machine.
> > + To compile this driver as a module, choose M here: the
> > + module will be called vm-wdt.
> > +
> > source "drivers/misc/c2port/Kconfig"
> > source "drivers/misc/eeprom/Kconfig"
> > source "drivers/misc/cb710/Kconfig"
> > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> > index 2ec634354cf5..868e28d01b75 100644
> > --- a/drivers/misc/Makefile
> > +++ b/drivers/misc/Makefile
> > @@ -59,3 +59,4 @@ obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o
> > obj-$(CONFIG_HISI_HIKEY_USB) += hisi_hikey_usb.o
> > obj-$(CONFIG_UID_SYS_STATS) += uid_sys_stats.o
> > obj-$(CONFIG_OPEN_DICE) += open-dice.o
> > +obj-$(CONFIG_VM_WATCHDOG) += vm-wdt.o
>
> No tab?
>
I will add one.
> > \ No newline at end of file
> > diff --git a/drivers/misc/vm-wdt.c b/drivers/misc/vm-wdt.c
> > new file mode 100644
> > index 000000000000..ea4351754645
> > --- /dev/null
> > +++ b/drivers/misc/vm-wdt.c
> > @@ -0,0 +1,215 @@
> > +// SPDX-License-Identifier: GPL-2.0+
>
> I have to ask, do you really mean "+" here as this is not the overall
> license of the kernel. It's not a normal license for your employer to
> pick, so as long as you have legal approval, it's fine, but if not, you
> need to get that.
>
Thanks for letting me know, I think this should be :
SPDX-License-Identifier: GPL-2.0 without "+".
> > +//
> > +// Virtual watchdog driver.
> > +// Copyright (C) Google, 2022
> > +
> > +#define pr_fmt(fmt) "vm-watchdog: " fmt
>
> It's a driver, you shouldn't need any pr_* calls.
>
I will remove those.
> > +
> > +#include <linux/cpu.h>
> > +#include <linux/init.h>
> > +#include <linux/io.h>
> > +#include <linux/kernel.h>
> > +
> > +#include <linux/device.h>
> > +#include <linux/interrupt.h>
> > +#include <linux/module.h>
> > +#include <linux/nmi.h>
> > +#include <linux/of.h>
> > +#include <linux/of_device.h>
> > +#include <linux/param.h>
> > +#include <linux/percpu.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/slab.h>
> > +
> > +#define DRV_NAME "vm_wdt"
>
> KBUILD_MODNAME?
>
> > +#define DRV_VERSION "1.0"
>
> "versions" mean nothing once the code is in the kernel, please drop
> this.
>
I will drop this.
> But why isn't this in the normal watchdog subdirectory? Why is this a
> special driver?
>
> > +
> > +#define VMWDT_REG_STATUS (0x00)
> > +#define VMWDT_REG_LOAD_CNT (0x04)
> > +#define VMWDT_REG_CURRENT_CNT (0x08)
> > +#define VMWDT_REG_CLOCK_FREQ_HZ (0x0C)
> > +#define VMWDT_REG_LEN (0x10)
> > +
> > +#define VMWDT_DEFAULT_CLOCK_HZ (10)
> > +#define VMWDT_DEFAULT_TIMEOT_SEC (8)
> > +
> > +struct vm_wdt_s {
> > + void __iomem *membase;
> > + u32 clock_freq;
> > + u32 expiration_sec;
> > + u32 ping_timeout_ms;
> > + struct hrtimer per_cpu_hrtimer;
> > + struct platform_device *dev;
> > +};
> > +
> > +#define vmwdt_reg_write(wdt, reg, value) \
> > + iowrite32((value), (wdt)->membase + (reg))
> > +#define vmwdt_reg_read(wdt, reg) \
> > + io32read((wdt)->membase + (reg))
> > +
> > +static struct platform_device *virt_dev;
> > +
> > +static enum hrtimer_restart vmwdt_timer_fn(struct hrtimer *hrtimer)
> > +{
> > + struct vm_wdt_s *cpu_wdt;
> > + u32 ticks;
> > +
> > + cpu_wdt = container_of(hrtimer, struct vm_wdt_s, per_cpu_hrtimer);
> > + ticks = cpu_wdt->clock_freq * cpu_wdt->expiration_sec;
> > + vmwdt_reg_write(cpu_wdt, VMWDT_REG_LOAD_CNT, ticks);
> > + hrtimer_forward_now(hrtimer, ms_to_ktime(cpu_wdt->ping_timeout_ms));
> > +
> > + return HRTIMER_RESTART;
> > +}
> > +
> > +static void vmwdt_start(void *arg)
> > +{
> > + u32 ticks;
> > + int cpu = smp_processor_id();
> > + struct vm_wdt_s *cpu_wdt = arg;
> > + struct hrtimer *hrtimer = &cpu_wdt->per_cpu_hrtimer;
> > +
> > + pr_info("cpu %u vmwdt start\n", cpu);
>
> When drivers work properly, they are quiet.
>
I will drop this.
> Again, why not have this in drivers/watchdog/ and use the apis there
> instead of creating a custom one for no reason?
>
I submitted this patch to the drivers/watchdog and I received some
feedback on it stating that this type of driver is not intended to be
used with watchdog core, because the drivers don't have a notion of
CPU. Moreover, we need to keep track of the elapsed time on a per-cpu
basis and the core watchdog framework doesn't provide this
functionality.
> thanks,
>
> greg k-h
Thanks,
Sebastian
next prev parent reply other threads:[~2022-04-23 9:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-22 14:19 [PATCH v2 0/2] Detect stalls on guest vCPUS Sebastian Ene
2022-04-22 14:19 ` [PATCH v2 1/2] dt-bindings: vm-wdt: Add qemu,vm-watchdog compatible Sebastian Ene
2022-04-22 21:10 ` Rob Herring
2022-04-22 14:19 ` [PATCH v2 2/2] misc: Add a mechanism to detect stalls on guest vCPUs Sebastian Ene
2022-04-23 6:50 ` Greg Kroah-Hartman
2022-04-23 9:14 ` Sebastian Ene [this message]
2022-04-23 9:22 ` Greg Kroah-Hartman
2022-04-23 6:51 ` [PATCH v2 0/2] Detect stalls on guest vCPUS Greg Kroah-Hartman
2022-04-23 9:02 ` Sebastian Ene
2022-04-23 9:36 ` Marc Zyngier
2022-04-23 11:12 ` Sebastian Ene
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YmPDjWK5X1O3HQvk@google.com \
--to=sebastianene@google.com \
--cc=arnd@arndb.de \
--cc=derek.kiernan@xilinx.com \
--cc=devicetree@vger.kernel.org \
--cc=dragan.cvetic@xilinx.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=qperret@google.com \
--cc=robh+dt@kernel.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).