Re: [PATCH v6 4/9] rv: Fix ha_invariant_passed_ns silent bypass of invariant check
From: Gabriele Monaco
Date: Fri Aug 28 2026 - 07:15:35 EST
On Fri, 2026-08-21 at 00:45 +0800, wen.yang@xxxxxxxxx wrote:
> From: Wen Yang <wen.yang@xxxxxxxxx>
>
> 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().
>
> This is a stopgap: once the RV framework reworks the per-env clock
> guard, this first-invocation reset should be subsumed.
>
> Signed-off-by: Wen Yang <wen.yang@xxxxxxxxx>
> ---
I would like to solve this a bit differently. I have this patch hanging around
to reset() when the monitor starts, which makes the whole invalid thing
obsolete.
I was planning on sending it together with other changes when I have time to
test them, but it seems the patch works fine on this series as well.
I reverted your fix, applied that and added the ha_reset_env() which you were
not defining:
diff --git a/kernel/trace/rv/monitors/tlob/tlob.c
b/kernel/trace/rv/monitors/tlob/tlob.c
index 18150cbf57a5..934eea34021a 100644
--- a/kernel/trace/rv/monitors/tlob/tlob.c
+++ b/kernel/trace/rv/monitors/tlob/tlob.c
@@ -175,6 +175,12 @@ static u64 ha_get_env(struct ha_monitor *ha_mon, enum
envs_tlob env,
return ENV_INVALID_VALUE;
}
+static void ha_reset_env(struct ha_monitor *ha_mon, enum envs_tlob env, u64
time_ns)
+{
+ if (env == clk_elapsed_tlob)
+ ha_reset_clk_ns(ha_mon, env, time_ns);
+}
+
/*
* Invariant: clk_elapsed < BUDGET_NS in running/waiting/sleeping. "stopped"
* is exempt: the parked period must not be measured against the old window's
---
Applying the appended patch too and running the selftests seems to work fine on
my setup.
If you want, you can add this patch to your series for now as it doesn't have
dependencies, I can sort the rest out.
Thanks,
Gabriele
---