Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1296699pxb; Sat, 23 Apr 2022 02:40:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykRXHZlXPuFhdidqT+wZN5Px3v6F2NOrenM7UAyVNRcgq1yfaHOvtnoCOqRb50iE69jMXl X-Received: by 2002:a63:2b8f:0:b0:3aa:8453:d553 with SMTP id r137-20020a632b8f000000b003aa8453d553mr7234835pgr.265.1650706821973; Sat, 23 Apr 2022 02:40:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650706821; cv=none; d=google.com; s=arc-20160816; b=niZmbRq75hWTwE8Ga229MA4B8HBXW/NGf/tfJAc/1eFhgcc6cAqeuMjc+Or5oax2J6 P57O42KbDG9I2gnE+hzZzwEUy9Hx4n1py/NBPRtWb+IneBq0Er9IwixIO3C1GJNIyLIh tS7FbIi+x8jGgClVYy0leho5u7YwYttR6BVP/VzStjxvNlNReGQjVcBoY1BxNiQfmcPf tcSR6g8YngY242Li+MK8h/SI2XoWGBa23Mx8K65VXcqVplXINeuMjygwbj1v7w6HPLnt 984erea2y7dZZvvB2t3L46CfwF6AsUMrc87E9HVVCokH5cLcrZ8cBBpZs+SwgYulfwhj TZuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=5057RsOxbeAAL6nVOu+eGmk7nKlvpIbBUaATa+ucJ28=; b=DTrPbWUEz94Fa5GHBDyjj0f3zodrnRQjyBvsyyssd+KPF5qXfRyPNF7TJyQ5K4oZ2b IebJXz/Mzd0b/zP9p6riGB434QCCoPmvcdKcroG3Wk4vUxWi1eXJrsWPeUdkwtzc0rMp EAqR8I7aQQTeYzjVh7AzWQ/cjhhXnIO1Kkm76g4M8ppALIEj4cyb1qIiGrPSWAzgvKcT qe/1tFmfAkGVojQ3ECE00imF/dhAZbu8GABMUjcBJjEtPmZlG/NQ/LwGPXVNLwTFgDZm wh/d6PRxChtyW9jRFl0Jg5e0oo38Pf3N7aBEVB4eAcZM7X8884znSHsC+1fKRTavIpSF CR5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AXwHADvT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 193-20020a6302ca000000b003a9f9442c80si10719391pgc.508.2022.04.23.02.40.05; Sat, 23 Apr 2022 02:40:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AXwHADvT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233643AbiDWGxH (ORCPT + 99 others); Sat, 23 Apr 2022 02:53:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233589AbiDWGxG (ORCPT ); Sat, 23 Apr 2022 02:53:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DED87F20C; Fri, 22 Apr 2022 23:50:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0478F60B4D; Sat, 23 Apr 2022 06:50:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCCF8C385A5; Sat, 23 Apr 2022 06:50:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650696608; bh=N74KVf0Xg1tp9U6s88Q84deTqBztJDb0FzAXhMjhEW4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AXwHADvT9bmFHX0p2wyDgl0QCoHo4RZi3t+kVmn6d1P6Ky6rW4PALGL+H++PrHako j2WeC/kzVQ2RX2z4KJJ925UrIusHekMufSMTKJOAJecBywBcsJE+tWglxJHXWqk09Q PrKTaQJngGHIqMcsw90Gm7OiZyfq4nuObagEbcmA= Date: Sat, 23 Apr 2022 08:50:03 +0200 From: Greg Kroah-Hartman To: Sebastian Ene Cc: Rob Herring , Arnd Bergmann , Dragan Cvetic , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, maz@kernel.org, will@kernel.org, qperret@google.com Subject: Re: [PATCH v2 2/2] misc: Add a mechanism to detect stalls on guest vCPUs Message-ID: References: <20220422141949.3456505-1-sebastianene@google.com> <20220422141949.3456505-3-sebastianene@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220422141949.3456505-3-sebastianene@google.com> X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 22, 2022 at 02:19:50PM +0000, Sebastian Ene wrote: > 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 > --- > 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? > \ 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. > +// > +// 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. > + > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#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. 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. Again, why not have this in drivers/watchdog/ and use the apis there instead of creating a custom one for no reason? thanks, greg k-h