All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Vincent Donnefort <vdonnefort@google.com>
Cc: rostedt@goodmis.org, mhiramat@kernel.org,
	mathieu.desnoyers@efficios.com,
	linux-trace-kernel@vger.kernel.org, oliver.upton@linux.dev,
	joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com,
	kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	jstultz@google.com, qperret@google.com, will@kernel.org,
	aneesh.kumar@kernel.org, kernel-team@android.com,
	linux-kernel@vger.kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Stephen Boyd <sboyd@kernel.org>,
	"Christopher S. Hall" <christopher.s.hall@intel.com>,
	Richard Cochran <richardcochran@gmail.com>
Subject: Re: [PATCH v9 25/30] KVM: arm64: Sync boot clock with the nVHE/pKVM hyp
Date: Wed, 07 Jan 2026 14:23:16 +0000	[thread overview]
Message-ID: <86bjj5mrhn.wl-maz@kernel.org> (raw)
In-Reply-To: <20251202093623.2337860-26-vdonnefort@google.com>

On Tue, 02 Dec 2025 09:36:18 +0000,
Vincent Donnefort <vdonnefort@google.com> wrote:
> 
> Configure the hypervisor tracing clock with the kernel boot clock. For
> tracing purposes, the boot clock is interesting: it doesn't stop on
> suspend. However, it is corrected on a regular basis, which implies the
> need to re-evaluate it every once in a while.
> 
> Cc: John Stultz <jstultz@google.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Stephen Boyd <sboyd@kernel.org>
> Cc: Christopher S. Hall <christopher.s.hall@intel.com>
> Cc: Richard Cochran <richardcochran@gmail.com>
> Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
> 
> diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
> index f83650a7aad9..375607c67285 100644
> --- a/arch/arm64/include/asm/kvm_asm.h
> +++ b/arch/arm64/include/asm/kvm_asm.h
> @@ -93,6 +93,7 @@ enum __kvm_host_smccc_func {
>  	__KVM_HOST_SMCCC_FUNC___tracing_unload,
>  	__KVM_HOST_SMCCC_FUNC___tracing_enable,
>  	__KVM_HOST_SMCCC_FUNC___tracing_swap_reader,
> +	__KVM_HOST_SMCCC_FUNC___tracing_update_clock,
>  };
>  
>  #define DECLARE_KVM_VHE_SYM(sym)	extern char sym[]
> diff --git a/arch/arm64/kvm/hyp/include/nvhe/trace.h b/arch/arm64/kvm/hyp/include/nvhe/trace.h
> index 7da8788ce527..fd641e1b1c23 100644
> --- a/arch/arm64/kvm/hyp/include/nvhe/trace.h
> +++ b/arch/arm64/kvm/hyp/include/nvhe/trace.h
> @@ -11,6 +11,7 @@ int __tracing_load(unsigned long desc_va, size_t desc_size);
>  void __tracing_unload(void);
>  int __tracing_enable(bool enable);
>  int __tracing_swap_reader(unsigned int cpu);
> +void __tracing_update_clock(u32 mult, u32 shift, u64 epoch_ns, u64 epoch_cyc);
>  #else
>  static inline void *tracing_reserve_entry(unsigned long length) { return NULL; }
>  static inline void tracing_commit_entry(void) { }
> @@ -19,5 +20,6 @@ static inline int __tracing_load(unsigned long desc_va, size_t desc_size) { retu
>  static inline void __tracing_unload(void) { }
>  static inline int __tracing_enable(bool enable) { return -ENODEV; }
>  static inline int __tracing_swap_reader(unsigned int cpu) { return -ENODEV; }
> +static inline void __tracing_update_clock(u32 mult, u32 shift, u64 epoch_ns, u64 epoch_cyc) { }
>  #endif
>  #endif
> diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> index 8b78b29c2069..45b8f70828de 100644
> --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> @@ -613,6 +613,18 @@ static void handle___tracing_swap_reader(struct kvm_cpu_context *host_ctxt)
>  	cpu_reg(host_ctxt, 1) = __tracing_swap_reader(cpu);
>  }
>  
> +static void handle___tracing_update_clock(struct kvm_cpu_context *host_ctxt)
> +{
> +	DECLARE_REG(u32, mult, host_ctxt, 1);
> +	DECLARE_REG(u32, shift, host_ctxt, 2);
> +	DECLARE_REG(u64, epoch_ns, host_ctxt, 3);
> +	DECLARE_REG(u64, epoch_cyc, host_ctxt, 4);
> +
> +	__tracing_update_clock(mult, shift, epoch_ns, epoch_cyc);
> +
> +	cpu_reg(host_ctxt, 1) = 0;

What's the purpose of setting X1 to 0? This is a call returning void,
so I don't immediately see the need for this.

> +}
> +
>  typedef void (*hcall_t)(struct kvm_cpu_context *);
>  
>  #define HANDLE_FUNC(x)	[__KVM_HOST_SMCCC_FUNC_##x] = (hcall_t)handle_##x
> @@ -658,6 +670,7 @@ static const hcall_t host_hcall[] = {
>  	HANDLE_FUNC(__tracing_unload),
>  	HANDLE_FUNC(__tracing_enable),
>  	HANDLE_FUNC(__tracing_swap_reader),
> +	HANDLE_FUNC(__tracing_update_clock),
>  };
>  
>  static void handle_host_hcall(struct kvm_cpu_context *host_ctxt)
> diff --git a/arch/arm64/kvm/hyp/nvhe/trace.c b/arch/arm64/kvm/hyp/nvhe/trace.c
> index df9d66fcb3c9..97e9f6c1a52c 100644
> --- a/arch/arm64/kvm/hyp/nvhe/trace.c
> +++ b/arch/arm64/kvm/hyp/nvhe/trace.c
> @@ -271,3 +271,19 @@ int __tracing_swap_reader(unsigned int cpu)
>  
>  	return ret;
>  }
> +
> +void __tracing_update_clock(u32 mult, u32 shift, u64 epoch_ns, u64 epoch_cyc)
> +{
> +	int cpu;
> +
> +	/* After this loop, all CPUs are observing the new bank... */
> +	for (cpu = 0; cpu < hyp_nr_cpus; cpu++) {
> +		struct simple_rb_per_cpu *simple_rb = per_cpu_ptr(trace_buffer.simple_rbs, cpu);
> +
> +		while (READ_ONCE(simple_rb->status) == SIMPLE_RB_WRITING)
> +			;
> +	}
> +
> +	/* ...we can now override the old one and swap. */
> +	trace_clock_update(mult, shift, epoch_ns, epoch_cyc);
> +}
> diff --git a/arch/arm64/kvm/hyp_trace.c b/arch/arm64/kvm/hyp_trace.c
> index 2866effe28ec..1e5fc27f0e9d 100644
> --- a/arch/arm64/kvm/hyp_trace.c
> +++ b/arch/arm64/kvm/hyp_trace.c
> @@ -4,15 +4,133 @@
>   * Author: Vincent Donnefort <vdonnefort@google.com>
>   */
>  
> +#include <linux/cpumask.h>
>  #include <linux/trace_remote.h>
> +#include <linux/tracefs.h>
>  #include <linux/simple_ring_buffer.h>
>  
> +#include <asm/arch_timer.h>
>  #include <asm/kvm_host.h>
>  #include <asm/kvm_hyptrace.h>
>  #include <asm/kvm_mmu.h>
>  
>  #include "hyp_trace.h"
>  
> +/* Same 10min used by clocksource when width is more than 32-bits */
> +#define CLOCK_MAX_CONVERSION_S	600
> +/*
> + * Time to give for the clock init. Long enough to get a good mult/shift
> + * estimation. Short enough to not delay the tracing start too much.
> + */
> +#define CLOCK_INIT_MS		100
> +/*
> + * Time between clock checks. Must be small enough to catch clock deviation when
> + * it is still tiny.
> + */
> +#define CLOCK_UPDATE_MS		500

If these definitions are common, can't we reuse the existing ones?
Specially given that this isn't EL2 code.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

  reply	other threads:[~2026-01-07 14:23 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-02  9:35 [PATCH v9 00/30] Tracefs support for pKVM Vincent Donnefort
2025-12-02  9:35 ` [PATCH v9 01/30] ring-buffer: Add page statistics to the meta-page Vincent Donnefort
2025-12-02  9:35 ` [PATCH v9 02/30] ring-buffer: Store bpage pointers into subbuf_ids Vincent Donnefort
2025-12-02  9:35 ` [PATCH v9 03/30] ring-buffer: Introduce ring-buffer remotes Vincent Donnefort
2025-12-02  9:35 ` [PATCH v9 04/30] ring-buffer: Add non-consuming read for " Vincent Donnefort
2025-12-02  9:35 ` [PATCH v9 05/30] tracing: Introduce trace remotes Vincent Donnefort
2025-12-02  9:35 ` [PATCH v9 06/30] tracing: Add reset to " Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 07/30] tracing: Add non-consuming read " Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 08/30] tracing: Add init callback " Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 09/30] tracing: Add events " Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 10/30] tracing: Add events/ root files " Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 11/30] tracing: Add helpers to create trace remote events Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 12/30] ring-buffer: Export buffer_data_page and macros Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 13/30] tracing: Introduce simple_ring_buffer Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 14/30] tracing: Add a trace remote module for testing Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 15/30] tracing: selftests: Add trace remote tests Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 16/30] Documentation: tracing: Add tracing remotes Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 17/30] tracing: load/unload page callbacks for simple_ring_buffer Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 18/30] tracing: Check for undefined symbols in simple_ring_buffer Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 19/30] KVM: arm64: Add PKVM_DISABLE_STAGE2_ON_PANIC Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 20/30] KVM: arm64: Add clock support to nVHE/pKVM hyp Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 21/30] KVM: arm64: Initialise hyp_nr_cpus for nVHE hyp Vincent Donnefort
2026-01-07 13:45   ` Marc Zyngier
2025-12-02  9:36 ` [PATCH v9 22/30] KVM: arm64: Support unaligned fixmap in the pKVM hyp Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 23/30] KVM: arm64: Add tracing capability for the nVHE/pKVM hyp Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 24/30] KVM: arm64: Add trace remote " Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 25/30] KVM: arm64: Sync boot clock with " Vincent Donnefort
2026-01-07 14:23   ` Marc Zyngier [this message]
2026-01-23 12:12     ` Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 26/30] KVM: arm64: Add trace reset to " Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 27/30] KVM: arm64: Add event support to the nVHE/pKVM hyp and trace remote Vincent Donnefort
2025-12-02  9:36 ` [PATCH v9 28/30] KVM: arm64: Add hyp_enter/hyp_exit events to nVHE/pKVM hyp Vincent Donnefort
2026-01-07 14:37   ` Marc Zyngier
2026-01-07 16:36     ` Steven Rostedt
2025-12-02  9:36 ` [PATCH v9 29/30] KVM: arm64: Add selftest event support " Vincent Donnefort
2026-01-07 15:40   ` Marc Zyngier
2026-01-23 12:14     ` Vincent Donnefort
2026-01-23 12:21       ` Vincent Donnefort
2026-01-23 12:47         ` Marc Zyngier
2026-01-23 12:47       ` Marc Zyngier
2025-12-02  9:36 ` [PATCH v9 30/30] tracing: selftests: Add hypervisor trace remote tests Vincent Donnefort
2026-01-07 16:00 ` [PATCH v9 00/30] Tracefs support for pKVM Marc Zyngier
2026-01-07 16:59   ` Steven Rostedt
2026-01-16 10:08     ` Marc Zyngier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86bjj5mrhn.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=aneesh.kumar@kernel.org \
    --cc=christopher.s.hall@intel.com \
    --cc=joey.gouly@arm.com \
    --cc=jstultz@google.com \
    --cc=kernel-team@android.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=qperret@google.com \
    --cc=richardcochran@gmail.com \
    --cc=rostedt@goodmis.org \
    --cc=sboyd@kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=tglx@linutronix.de \
    --cc=vdonnefort@google.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.