devices: vmwdt: Prevent spurious resets when the guest is scheduled out
devices: vmwdt: Prevent spurious resets when the guest is scheduled out

This patch modifies the way we program the watchdog internal counter to
prevent spurious resets when the guest is not scheduled to run.
The internal counter consists of a per-cpu POSIX timer and an associated
countdown register and is used to detect whether we missed periodic
heart-beat events from the guest. Add tests to verify the watchdog
expiration condition.

In this change we re-program the one-shot timer after we detected that
there are no events sent from the guest and the guest didn't run.
We detect that the guest is not running by looking
at the reported time from /proc/stat entry (guest_time).

We can enter in this state if the
guest is not scheduled to run, or is busy waiting for some MMIO
operation to finish. To detect a stall, we look for the value of the
guest_time field and if it changed between sub-sequent expiration events
then the guest is running, but it is not serving our watchdog.

Bug: 213422094
Change-Id: I0999f6ead350ac30a6ef6f600e57ec1805b40746
Signed-off-by: Sebastian Ene <d42dd67a4c1d4ac34d4fffddbcd72e048c0bab62@google.com>
Reported-by: Will Deacon <5530b815c0a5f57ff6d6caaef4a4600e5e15794d@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3872276
Reviewed-by: Will Deacon <5530b815c0a5f57ff6d6caaef4a4600e5e15794d@google.com>
Reviewed-by: Daniel Verkamp <72bc170b46ec491f7bdd4359a1c0bfed274de40c@chromium.org>

google/crosvm,google/crosvm,google/crosvm,google/crosvm