From: Wen Yang <[email protected]>

When env_store is U64_MAX (its initial sentinel value),
ha_invariant_passed_ns() returns 0 immediately without initializing
env_store to the current clock.  Subsequent calls to
ha_check_invariant_ns() then find env_store still at U64_MAX, causing
the elapsed comparison to wrap and always report the invariant as
satisfied, silently masking any violations.

Fix by calling ha_reset_clk_ns() to establish the guard on the first
invocation instead of returning early.  Apply the same fix to
ha_invariant_passed_jiffy().

Signed-off-by: Wen Yang <[email protected]>
---
 include/rv/ha_monitor.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/rv/ha_monitor.h b/include/rv/ha_monitor.h
index 83199f90afe8..dddf5694bcc8 100644
--- a/include/rv/ha_monitor.h
+++ b/include/rv/ha_monitor.h
@@ -375,12 +375,12 @@ static inline bool ha_check_invariant_ns(struct 
ha_monitor *ha_mon,
 static inline u64 ha_invariant_passed_ns(struct ha_monitor *ha_mon, enum envs 
env,
                                   u64 expire, u64 time_ns)
 {
-       u64 passed = 0;
+       u64 passed;
 
        if (env < 0 || env >= ENV_MAX_STORED)
                return 0;
        if (ha_monitor_env_invalid(ha_mon, env))
-               return 0;
+               ha_reset_clk_ns(ha_mon, env, time_ns);
        passed = ha_get_env(ha_mon, env, time_ns);
        ha_set_invariant_ns(ha_mon, env, expire - passed, time_ns);
        return passed;
@@ -414,12 +414,12 @@ static inline bool ha_check_invariant_jiffy(struct 
ha_monitor *ha_mon,
 static inline u64 ha_invariant_passed_jiffy(struct ha_monitor *ha_mon, enum 
envs env,
                                      u64 expire, u64 time_ns)
 {
-       u64 passed = 0;
+       u64 passed;
 
        if (env < 0 || env >= ENV_MAX_STORED)
                return 0;
        if (ha_monitor_env_invalid(ha_mon, env))
-               return 0;
+               ha_reset_clk_jiffy(ha_mon, env);
        passed = ha_get_env(ha_mon, env, time_ns);
        ha_set_invariant_jiffy(ha_mon, env, expire - passed);
        return passed;
-- 
2.25.1


Reply via email to