Re: [PATCH v8 02/14] rv: Fix ha_monitor timer and invariant underflow

From: Karl Mehltretter

Date: Sun Nov 29 2026 - 23:36:03 EST


On Fri, 6 Nov 2026 01:49:02 +0800, Wen Yang wrote:
> Fixes: f5587d1b6ec9 ("rv: Add Hybrid Automata monitor type")
> Fixes: ab2900ae252b ("rv: Simplify hybrid automata monitors's clock variables")
[...]
> @@ -351,7 +351,11 @@ static inline void ha_reset_clk_ns(struct ha_monitor *ha_mon, enum envs env, u64
> static inline bool ha_check_invariant_ns(struct ha_monitor *ha_mon, enum envs env,
> u64 time_ns, u64 expire_ns)
> {
> - return READ_ONCE(ha_mon->env_store[env]) >= time_ns - expire_ns;
> + /*
> + * Compare as store + expire >= time to avoid underflow when the
> + * system uptime is still below expire_ns (early boot, large budget).
> + */
> + return READ_ONCE(ha_mon->env_store[env]) + expire_ns >= time_ns;
> }

This depends on patch 1 replacing ENV_INVALID_VALUE (U64_MAX) with an initial
reset. Without patch 1, an unset clock holds U64_MAX, so U64_MAX + expire_ns
wraps to expire_ns - 1 and reports a false violation once time_ns >= expire_ns.

Because patch 2 has Fixes: tags and patch 1 does not, stable could pick patch 2
alone.

Could we read the stored timestamp once, accept it if it's at or after the
current time, and check elapsed time otherwise?

That avoids wraparound and lets patch 2 go first so stable can backport it on
its own.

Thanks,
Karl