Detect stalls on guest vCPUS
Subsystems (2)
v7 cover Detect stalls on guest vCPUS
This adds a mechanism to detect stalls on the guest vCPUS by creating a per CPU hrtimer which periodically 'pets' the host backend driver. On a conventional watchdog-core driver, the userspace is responsible for delivering the 'pet' events by writing to the particular /dev/watchdogN node. In this case we require a strong thread affinity to be able to account for lost time on a per vCPU basis.
This device driver acts as a soft lockup detector by relying on the host backend driver to measure the elapesed time between subsequent 'pet' events. If the elapsed time doesn't match an expected value, the backend driver decides that the guest vCPU is locked and resets the guest. The host backend driver takes into account the time that the guest is not running. The communication with the backend driver is done through MMIO and the register layout of the virtual watchdog is described as part of the backend driver changes.
The host backend driver is implemented as part of:
https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3548817
Changelog v7:
- fix the dtschema warnings for 'timeout-sec' property
- rename vcpu_stall_detector.yaml to qemu,vcpu_stall_detector.yaml and place the file under misc
- improve the Kconfig description for the driver by making it KVM specific
Changelog v6:
- fix issues reported by lkp@intel robot:
building for ARCH=h8300 incorrect type in assignment (different address spaces)
Sebastian Ene (2):
dt-bindings: vcpu_stall_detector: Add qemu,vcpu-stall-detector
compatible
misc: Add a mechanism to detect stalls on guest vCPUs
.../misc/qemu,vcpu-stall-detector.yaml | 50 ++++ drivers/misc/Kconfig | 12 + drivers/misc/Makefile | 1 + drivers/misc/vcpu_stall_detector.c | 222 ++++++++++++++++++ 4 files changed, 285 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/qemu,vcpu-stall-detector.yaml create mode 100644 drivers/misc/vcpu_stall_detector.c
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
PATCH v7 1/2 dt-bindings: vcpu_stall_detector: Add qemu,vcpu-stall-detector compatible
The VCPU stall detection mechanism allows to configure the expiration duration and the internal counter clock frequency measured in Hz. Add these properties in the schema.
While this is a memory mapped virtual device, it is expected to be loaded when the DT contains the compatible: "qemu,vcpu-stall-detector" node. In a protected VM we trust the generated DT nodes and we don't rely on the host to present the hardware peripherals.
--- .../misc/qemu,vcpu-stall-detector.yaml | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/qemu,vcpu-stall-detector.yaml
Documentation/devicetree/bindings/misc/qemu,vcpu-stall-detector.yaml new file +50 -0
@@ -0,0 +1,50 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/misc/qemu,vcpu-stall-detector.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: VCPU stall detector + +description: + This binding describes a CPU stall detector mechanism for virtual CPUs + which is accessed through MMIO. + +maintainers: + - Sebastian Ene <[email protected]> + +properties: + compatible: + enum: + - qemu,vcpu-stall-detector + + clock-frequency: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + The internal clock of the stall detector peripheral measure in Hz used + to decrement its internal counter register on each tick. + Defaults to 10 if unset. + default: 10 + + timeout-sec: + description: | + The stall detector expiration timeout measured in seconds. + Defaults to 8 if unset. Please note that it also takes into account the + time spent while the VCPU is not running. + default: 8 + +required: + - compatible + +additionalProperties: false + +examples: + - | + vmwdt@9030000 { + compatible = "qemu,vcpu-stall-detector"; + clock-frequency = <10>; + timeout-sec = <8>; + reg = <0x0 0x9030000 0x0 0x10000>; + }; + +...
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
Rob Herring
maintainerRe: [PATCH v7 1/2] dt-bindings: vcpu_stall_detector: Add qemu,vcpu-stall-detector compatible
Quoted 9 lines · Sebastian Ene
The VCPU stall detection mechanism allows to configure the expiration duration and the internal counter clock frequency measured in Hz. Add these properties in the schema.
While this is a memory mapped virtual device, it is expected to be loaded when the DT contains the compatible: "qemu,vcpu-stall-detector" node. In a protected VM we trust the generated DT nodes and we don't rely on the host to present the hardware peripherals.
Quoted 6 lines
Signed-off-by Sebastian Ene <[email protected]>--- .../misc/qemu,vcpu-stall-detector.yaml | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/qemu,vcpu-stall-detector.yaml
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/misc/qemu,vcpu-stall-detector.example.dtb: vmwdt@9030000: 'reg' does not match any of the regexes: 'pinctrl-[0-9]+'
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/misc/qemu,vcpu-stall-detector.yaml
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/patch/
This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit.
PATCH v7 2/2 misc: Add a mechanism to detect stalls on guest vCPUs
In reply to Sebastian EneThis driver creates per-cpu hrtimers which are required to do the periodic 'pet' operation. On a conventional watchdog-core driver, the userspace is responsible for delivering the 'pet' events by writing to the particular /dev/watchdogN node. In this case we require a strong thread affinity to be able to account for lost time on a per vCPU.
This part of the driver is the 'frontend' which is reponsible for delivering the periodic 'pet' events, configuring the virtual peripheral and listening for cpu hotplug events. The other part of the driver handles the peripheral emulation and this part accounts for lost time by looking at the /proc/{}/task/{}/stat entries and is located here:
https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3548817
--- drivers/misc/Kconfig | 12 ++ drivers/misc/Makefile | 1 + drivers/misc/vcpu_stall_detector.c | 222 +++++++++++++++++++++++++++++ 3 files changed, 235 insertions(+) create mode 100644 drivers/misc/vcpu_stall_detector.c
drivers/misc/Kconfig +12 -0
@@ -483,6 +483,18 @@ config OPEN_DICE If unsure, say N. +config VCPU_STALL_DETECTOR + tristate "VCPU stall detector" + select LOCKUP_DETECTOR + help + Detect CPU locks on a kvm virtual machine. This driver relies on + the hrtimers which are CPU-binded to do the 'pet' operation. When a + vCPU has to do a 'pet', it exits the guest through MMIO write and + the backend driver takes into account the lost ticks for this + particular CPU. + To compile this driver as a module, choose M here: the + module will be called vcpu_stall_detector. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
@@ -60,3 +60,4 @@ obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o obj-$(CONFIG_HISI_HIKEY_USB) += hisi_hikey_usb.o obj-$(CONFIG_HI6421V600_IRQ) += hi6421v600-irq.o obj-$(CONFIG_OPEN_DICE) += open-dice.o +obj-$(CONFIG_VCPU_STALL_DETECTOR) += vcpu_stall_detector.o
drivers/misc/vcpu_stall_detector.c new file +222 -0
222 lines not on this page · raw message
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
Greg Kroah-Hartman
maintainerRe: [PATCH v7 2/2] misc: Add a mechanism to detect stalls on guest vCPUs
Quoted 30 lines · Sebastian Ene
This driver creates per-cpu hrtimers which are required to do the periodic 'pet' operation. On a conventional watchdog-core driver, the userspace is responsible for delivering the 'pet' events by writing to the particular
/dev/watchdogNnode. In this case we require a strong thread affinity to be able to account for lost time on a per vCPU.This part of the driver is the 'frontend' which is reponsible for delivering the periodic 'pet' events, configuring the virtual peripheral and listening for cpu hotplug events. The other part of the driver handles the peripheral emulation and this part accounts for lost time by looking at the
/proc/{}/task/{}/statentries and is located here:
https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3548817Signed-off-by Sebastian Ene <[email protected]>--- drivers/misc/Kconfig | 12 ++ drivers/misc/Makefile | 1 + drivers/misc/vcpu_stall_detector.c | 222 +++++++++++++++++++++++++++++ 3 files changed, 235 insertions(+) create mode 100644 drivers/misc/vcpu_stall_detector.cdrivers/misc/Kconfig +1
-0@@ -483,6 +483,18 @@ config OPEN_DICE If unsure, say N. +config VCPU_STALL_DETECTOR
drivers/misc/Kconfig config OPEN_DICE · line 496
Quoted 10 lines
drivers/misc/Kconfig +10
-0+ tristate "VCPU stall detector" + select LOCKUP_DETECTOR + help + Detect CPU locks on a kvm virtual machine. This driver relies on + the hrtimers which are CPU-binded to do the 'pet' operation. When a + vCPU has to do a 'pet', it exits the guest through MMIO write and + the backend driver takes into account the lost ticks for this + particular CPU. + To compile this driver as a module, choose M here: the + module will be called vcpu_stall_detector.
Should this depend on KVM_GUEST?
thanks,
greg k-h
Re: [PATCH v7 2/2] misc: Add a mechanism to detect stalls on guest vCPUs
Quoted 31 lines · Greg Kroah-Hartman
Quoted 30 lines · Sebastian Ene
This driver creates per-cpu hrtimers which are required to do the periodic 'pet' operation. On a conventional watchdog-core driver, the userspace is responsible for delivering the 'pet' events by writing to the particular
/dev/watchdogNnode. In this case we require a strong thread affinity to be able to account for lost time on a per vCPU.This part of the driver is the 'frontend' which is reponsible for delivering the periodic 'pet' events, configuring the virtual peripheral and listening for cpu hotplug events. The other part of the driver handles the peripheral emulation and this part accounts for lost time by looking at the
/proc/{}/task/{}/statentries and is located here:
https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3548817Signed-off-by Sebastian Ene <[email protected]>--- drivers/misc/Kconfig | 12 ++ drivers/misc/Makefile | 1 + drivers/misc/vcpu_stall_detector.c | 222 +++++++++++++++++++++++++++++ 3 files changed, 235 insertions(+) create mode 100644 drivers/misc/vcpu_stall_detector.cdrivers/misc/Kconfig +0
-0@@ -483,6 +483,18 @@ config OPEN_DICE If unsure, say N.
Quoted 14 lines
drivers/misc/Kconfig config OPEN_DICE · line 496
Quoted 12 lines
drivers/misc/Kconfig +6
-0+config VCPU_STALL_DETECTOR + tristate "VCPU stall detector" + select LOCKUP_DETECTOR + help + Detect CPU locks on a kvm virtual machine. This driver relies on + the hrtimers which are CPU-binded to do the 'pet' operation. Whena
drivers/misc/Kconfig +5
-0+ vCPU has to do a 'pet', it exits the guest through MMIO write and + the backend driver takes into account the lost ticks for this + particular CPU. + To compile this driver as a module, choose M here: the + module will be called vcpu_stall_detector.Should this depend on
KVM_GUEST?
Not all architectures have KVM_GUEST, and arm64 has no use for it.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Greg Kroah-Hartman
maintainerRe: [PATCH v7 2/2] misc: Add a mechanism to detect stalls on guest vCPUs
Quoted 49 lines · Marc Zyngier
Quoted 33 lines · Greg Kroah-Hartman
Quoted 32 lines · Sebastian Ene
This driver creates per-cpu hrtimers which are required to do the periodic 'pet' operation. On a conventional watchdog-core driver, the userspace is responsible for delivering the 'pet' events by writing to the particular
/dev/watchdogNnode. In this case we require a strong thread affinity to be able to account for lost time on a per vCPU.This part of the driver is the 'frontend' which is reponsible for delivering the periodic 'pet' events, configuring the virtual peripheral
and listening for cpu hotplug events. The other part of the driver handles the peripheral emulation and this part accounts for lost time by
looking at the/proc/{}/task/{}/statentries and is located here:
https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3548817Signed-off-by Sebastian Ene <[email protected]>--- drivers/misc/Kconfig | 12 ++ drivers/misc/Makefile | 1 + drivers/misc/vcpu_stall_detector.c | 222 +++++++++++++++++++++++++++++ 3 files changed, 235 insertions(+) create mode 100644 drivers/misc/vcpu_stall_detector.cdrivers/misc/Kconfig +0
-0@@ -483,6 +483,18 @@ config OPEN_DICE If unsure, say N.Quoted 14 lines
drivers/misc/Kconfig config OPEN_DICE · line 496
Quoted 12 lines
drivers/misc/Kconfig +6
-0+config VCPU_STALL_DETECTOR + tristate "VCPU stall detector" + select LOCKUP_DETECTOR + help + Detect CPU locks on a kvm virtual machine. This driver relies on + the hrtimers which are CPU-binded to do the 'pet' operation.When a
drivers/misc/Kconfig +5
-0+ vCPU has to do a 'pet', it exits the guest through MMIO write and + the backend driver takes into account the lost ticks for this + particular CPU. + To compile this driver as a module, choose M here: the + module will be called vcpu_stall_detector.Should this depend on
KVM_GUEST?
Quoted 1 line
Not all architectures have
KVM_GUEST, and arm64 has no use for it.
Ah, I thought this was a requirement (or created a better guest image) for use under KVM. Nevermind then...
thanks,
greg k-h
Re: [PATCH v7 2/2] misc: Add a mechanism to detect stalls on guest vCPUs
Quoted 51 lines · Greg Kroah-Hartman
Quoted 49 lines · Marc Zyngier
Quoted 47 lines · Greg Kroah-Hartman
Quoted 39 lines · Sebastian Ene
This driver creates per-cpu hrtimers which are required to do the periodic 'pet' operation. On a conventional watchdog-core driver, the userspace is responsible for delivering the 'pet' events by writing to the particular
/dev/watchdogNnode. In this case we require a strong thread affinity to be able to account for lost time on a per vCPU.This part of the driver is the 'frontend' which is reponsible for delivering the periodic 'pet' events, configuring the virtual peripheral
and listening for cpu hotplug events. The other part of the driver handles the peripheral emulation and this part accounts for lost time by
looking at the/proc/{}/task/{}/statentries and is located here:
https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3548817Signed-off-by Sebastian Ene <[email protected]>--- drivers/misc/Kconfig | 12 ++ drivers/misc/Makefile | 1 + drivers/misc/vcpu_stall_detector.c | 222 +++++++++++++++++++++++++++++ 3 files changed, 235 insertions(+) create mode 100644 drivers/misc/vcpu_stall_detector.cdrivers/misc/Kconfig +6
-0@@ -483,6 +483,18 @@ config OPEN_DICE If unsure, say N. +config VCPU_STALL_DETECTOR + tristate "VCPU stall detector" + select LOCKUP_DETECTOR + help + Detect CPU locks on a kvm virtual machine. This driver relies on + the hrtimers which are CPU-binded to do the 'pet' operation.When a
drivers/misc/Kconfig config OPEN_DICE · line 496
Quoted 5 lines
drivers/misc/Kconfig +5
-0+ vCPU has to do a 'pet', it exits the guest through MMIO write and + the backend driver takes into account the lost ticks for this + particular CPU. + To compile this driver as a module, choose M here: the + module will be called vcpu_stall_detector.Should this depend on
KVM_GUEST?
Quoted 4 lines
Quoted 1 line
Not all architectures have
KVM_GUEST, and arm64 has no use for it.Ah, I thought this was a requirement (or created a better guest image) for use under KVM. Nevermind then...
It really depends whether an architecture relies on non-architectural extensions to support KVM guests. PPC does most of the time, x86 certainly works better with the knowledge that this is a KVM guest.
KVM on arm64 implements the architecture itself, and hardly anything else (if something sucks in virt, it also likely sucks bare metal). The couple of KVM-specific options we support are definitely not worth a KVM_GUEST, as they only cover pretty esoteric stuff that nobody enables, such as PTP_1588_CLOCK_KVM.
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.