]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: arm64: Fix hyp_trace clock disabling
authorVincent Donnefort <vdonnefort@google.com>
Wed, 15 Jul 2026 10:51:00 +0000 (11:51 +0100)
committerMarc Zyngier <maz@kernel.org>
Thu, 23 Jul 2026 08:56:57 +0000 (09:56 +0100)
Fix the disable path in hyp_trace_clock_enable(), which fell through to
re-initialize and reschedule the clock after cancelling the work. Return
early instead.

While at it, cleanup hyp_trace_clock::lock which is unused and
hyp_trace_clock::running which is redundant: the trace_remote framework
already serializes calls to the callback enable_tracing.

Fixes: b22888917fa4 ("KVM: arm64: Sync boot clock with the nVHE/pKVM hyp")
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev> (✓ DKIM/linux.dev)
Link: https://patch.msgid.link/20260715105100.3178255-1-vdonnefort@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/hyp_trace.c

index 2411b4c32932cc8499e3fc89c682502473373b52..9bfa368dd84152bd93dd59efebc28af882379258 100644 (file)
@@ -37,8 +37,6 @@ static struct hyp_trace_clock {
        u32                     shift;
        struct delayed_work     work;
        struct completion       ready;
-       struct mutex            lock;
-       bool                    running;
 } hyp_clock;
 
 static void __hyp_clock_work(struct work_struct *work)
@@ -110,12 +108,9 @@ static void hyp_trace_clock_enable(struct hyp_trace_clock *hyp_clock, bool enabl
 {
        struct system_time_snapshot snap;
 
-       if (hyp_clock->running == enable)
-               return;
-
        if (!enable) {
                cancel_delayed_work_sync(&hyp_clock->work);
-               hyp_clock->running = false;
+               return;
        }
 
        ktime_get_snapshot_id(CLOCK_BOOTTIME, &snap);
@@ -128,7 +123,6 @@ static void hyp_trace_clock_enable(struct hyp_trace_clock *hyp_clock, bool enabl
        INIT_DELAYED_WORK(&hyp_clock->work, __hyp_clock_work);
        schedule_delayed_work(&hyp_clock->work, msecs_to_jiffies(CLOCK_INIT_MS));
        wait_for_completion(&hyp_clock->ready);
-       hyp_clock->running = true;
 }
 
 /* Access to this struct within the trace_remote_callbacks are protected by the trace_remote lock */
@@ -304,9 +298,15 @@ static void hyp_trace_unload(struct trace_buffer_desc *desc, void *priv)
 
 static int hyp_trace_enable_tracing(bool enable, void *priv)
 {
+       int ret;
+
        hyp_trace_clock_enable(&hyp_clock, enable);
 
-       return kvm_call_hyp_nvhe(__tracing_enable, enable);
+       ret = kvm_call_hyp_nvhe(__tracing_enable, enable);
+       if (ret)
+               hyp_trace_clock_enable(&hyp_clock, !enable);
+
+       return ret;
 }
 
 static int hyp_trace_swap_reader_page(unsigned int cpu, void *priv)