* [PATCH v1 0/2] KVM: arm64: Fixes for hyp_trace
@ 2026-10-08 10:42 Vincent Donnefort
2026-10-08 10:42 ` [PATCH v1 1/2] KVM: arm64: Prevent 64-bit overflow when computing hyp clock rate Vincent Donnefort
2026-10-08 10:42 ` [PATCH v1 2/2] KVM: arm64: Fix bpages backing allocation size in hyp_trace Vincent Donnefort
0 siblings, 2 replies; 6+ messages in thread
From: Vincent Donnefort @ 2026-10-08 10:42 UTC (permalink / raw)
To: maz, oupton, kvmarm, linux-arm-kernel
Cc: joey.gouly, seiden, suzuki.poulose, yuzenghui, catalin.marinas,
will, kernel-team, fuad.tabba, qperret, Vincent Donnefort
Here's a couple of fixes for hyp_trace:
The first one fixes a potential 64 bits overflow in the hypervisor trace
clock.
The second may prevent tracing loading for certain buffer_size_kb
configuration. This one depends on the allocator, so I have based the
series on kvmarm/next.
Vincent Donnefort (2):
KVM: arm64: Prevent 64-bit overflow when computing hyp clock rate
KVM: arm64: Fix bpages backing allocation size in hyp_trace
arch/arm64/kvm/hyp_trace.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
base-commit: 8ed245078003cc5f61ca4c8f9920374086f2515c
--
2.56.0.360.g66cac248cb-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v1 1/2] KVM: arm64: Prevent 64-bit overflow when computing hyp clock rate
2026-10-08 10:42 [PATCH v1 0/2] KVM: arm64: Fixes for hyp_trace Vincent Donnefort
@ 2026-10-08 10:42 ` Vincent Donnefort
2026-10-08 19:12 ` Fuad Tabba
2026-10-08 10:42 ` [PATCH v1 2/2] KVM: arm64: Fix bpages backing allocation size in hyp_trace Vincent Donnefort
1 sibling, 1 reply; 6+ messages in thread
From: Vincent Donnefort @ 2026-10-08 10:42 UTC (permalink / raw)
To: maz, oupton, kvmarm, linux-arm-kernel
Cc: joey.gouly, seiden, suzuki.poulose, yuzenghui, catalin.marinas,
will, kernel-team, fuad.tabba, qperret, Vincent Donnefort, stable
The hypervisor clock rate is delta_cycles * NSEC_PER_SEC / delta_boot.
It is computed whenever a deviation occurs. If the delta between two
rate updates is big enough, delta_cycles * NSEC_PER_SEC will overflow.
Prevent overflow with mul_u64_u64_div_u64(). And as a bonus, simplify
the clock estimation with mul_u64_u32_shr().
Fixes: b22888917fa4 ("KVM: arm64: Sync boot clock with the nVHE/pKVM hyp")
Cc: stable@vger.kernel.org
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
---
arch/arm64/kvm/hyp_trace.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/arch/arm64/kvm/hyp_trace.c b/arch/arm64/kvm/hyp_trace.c
index 9241d5a325fb..26fc13c16458 100644
--- a/arch/arm64/kvm/hyp_trace.c
+++ b/arch/arm64/kvm/hyp_trace.c
@@ -60,14 +60,8 @@ static void __hyp_clock_work(struct work_struct *work)
if (hyp_clock->mult) {
u64 err, cur = delta_cycles;
- if (WARN_ON_ONCE(cur >= hyp_clock->cyc_overflow64)) {
- __uint128_t tmp = (__uint128_t)cur * hyp_clock->mult;
-
- cur = tmp >> hyp_clock->shift;
- } else {
- cur *= hyp_clock->mult;
- cur >>= hyp_clock->shift;
- }
+ WARN_ON_ONCE(cur >= hyp_clock->cyc_overflow64);
+ cur = mul_u64_u32_shr(cur, hyp_clock->mult, hyp_clock->shift);
cur += hyp_clock->boot;
err = abs_diff(cur, boot);
@@ -85,7 +79,7 @@ static void __hyp_clock_work(struct work_struct *work)
err / NSEC_PER_USEC);
}
- rate = div64_u64(delta_cycles * NSEC_PER_SEC, delta_boot);
+ rate = mul_u64_u64_div_u64(delta_cycles, NSEC_PER_SEC, delta_boot);
clocks_calc_mult_shift(&hyp_clock->mult, &hyp_clock->shift,
rate, NSEC_PER_SEC, CLOCK_MAX_CONVERSION_S);
--
2.56.0.360.g66cac248cb-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v1 2/2] KVM: arm64: Fix bpages backing allocation size in hyp_trace
2026-10-08 10:42 [PATCH v1 0/2] KVM: arm64: Fixes for hyp_trace Vincent Donnefort
2026-10-08 10:42 ` [PATCH v1 1/2] KVM: arm64: Prevent 64-bit overflow when computing hyp clock rate Vincent Donnefort
@ 2026-10-08 10:42 ` Vincent Donnefort
2026-10-08 19:13 ` Fuad Tabba
1 sibling, 1 reply; 6+ messages in thread
From: Vincent Donnefort @ 2026-10-08 10:42 UTC (permalink / raw)
To: maz, oupton, kvmarm, linux-arm-kernel
Cc: joey.gouly, seiden, suzuki.poulose, yuzenghui, catalin.marinas,
will, kernel-team, fuad.tabba, qperret, Vincent Donnefort
hyp_trace_buffer_alloc_bpages_backing() computes nr_bpages as
(PAGE_ALIGN(size) / PAGE_SIZE) + 1, whereas trace_remote_alloc_buffer()
takes into account the buffer page header.
Align the bpages backing allocation by using
__calc_nr_pages_ring_buffer_desc(). There's no need to validate
nr_bpages again, it has been before with trace_buffer_desc_size().
Fixes: 3aed038aac8d ("KVM: arm64: Add trace remote for the nVHE/pKVM hyp")
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
---
arch/arm64/kvm/hyp_trace.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kvm/hyp_trace.c b/arch/arm64/kvm/hyp_trace.c
index 26fc13c16458..b9404496f977 100644
--- a/arch/arm64/kvm/hyp_trace.c
+++ b/arch/arm64/kvm/hyp_trace.c
@@ -146,8 +146,8 @@ static void __unshare_page(unsigned long va)
static int hyp_trace_buffer_alloc_bpages_backing(struct hyp_trace_buffer *trace_buffer, size_t size)
{
+ unsigned long nr_bpages;
size_t backing_size;
- int nr_bpages;
void *start;
int ret;
@@ -157,7 +157,7 @@ static int hyp_trace_buffer_alloc_bpages_backing(struct hyp_trace_buffer *trace_
return 0;
}
- nr_bpages = (PAGE_ALIGN(size) / PAGE_SIZE) + 1;
+ nr_bpages = __calc_nr_pages_ring_buffer_desc(size);
backing_size = PAGE_ALIGN(sizeof(struct simple_buffer_page) * nr_bpages *
num_possible_cpus());
--
2.56.0.360.g66cac248cb-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v1 1/2] KVM: arm64: Prevent 64-bit overflow when computing hyp clock rate
2026-10-08 10:42 ` [PATCH v1 1/2] KVM: arm64: Prevent 64-bit overflow when computing hyp clock rate Vincent Donnefort
@ 2026-10-08 19:12 ` Fuad Tabba
0 siblings, 0 replies; 6+ messages in thread
From: Fuad Tabba @ 2026-10-08 19:12 UTC (permalink / raw)
To: Vincent Donnefort
Cc: maz, oupton, kvmarm, linux-arm-kernel, joey.gouly, seiden,
suzuki.poulose, yuzenghui, catalin.marinas, will, kernel-team,
qperret, stable
On Thu, 8 Oct 2026 at 11:42, 'Vincent Donnefort' via kernel-team
<kernel-team@android.com> wrote:
>
> The hypervisor clock rate is delta_cycles * NSEC_PER_SEC / delta_boot.
> It is computed whenever a deviation occurs. If the delta between two
> rate updates is big enough, delta_cycles * NSEC_PER_SEC will overflow.
>
> Prevent overflow with mul_u64_u64_div_u64(). And as a bonus, simplify
> the clock estimation with mul_u64_u32_shr().
>
> Fixes: b22888917fa4 ("KVM: arm64: Sync boot clock with the nVHE/pKVM hyp")
> Cc: stable@vger.kernel.org
> Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
Tested-by: Fuad Tabba <fuad.tabba@linux.dev>
Cheers,
/fuad
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1 2/2] KVM: arm64: Fix bpages backing allocation size in hyp_trace
2026-10-08 10:42 ` [PATCH v1 2/2] KVM: arm64: Fix bpages backing allocation size in hyp_trace Vincent Donnefort
@ 2026-10-08 19:13 ` Fuad Tabba
2026-10-09 8:39 ` Vincent Donnefort
0 siblings, 1 reply; 6+ messages in thread
From: Fuad Tabba @ 2026-10-08 19:13 UTC (permalink / raw)
To: Vincent Donnefort
Cc: maz, oupton, kvmarm, linux-arm-kernel, joey.gouly, seiden,
suzuki.poulose, yuzenghui, catalin.marinas, will, kernel-team,
qperret
On Thu, 8 Oct 2026 at 11:42, Vincent Donnefort <vdonnefort@google.com> wrote:
>
> hyp_trace_buffer_alloc_bpages_backing() computes nr_bpages as
> (PAGE_ALIGN(size) / PAGE_SIZE) + 1, whereas trace_remote_alloc_buffer()
> takes into account the buffer page header.
>
> Align the bpages backing allocation by using
> __calc_nr_pages_ring_buffer_desc(). There's no need to validate
> nr_bpages again, it has been before with trace_buffer_desc_size().
>
> Fixes: 3aed038aac8d ("KVM: arm64: Add trace remote for the nVHE/pKVM hyp")
Should this have Cc: stable too, like patch 1? The undercount is there
since 3aed038aac8d for small buffers, and 442ffa742daa6
("tracing/remotes: Account for ring buffer page header in size
calculation") makes it reachable at ordinary sizes.
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
Tested-by: Fuad Tabba <fuad.tabba@linux.dev>
Cheers,
/fuad
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1 2/2] KVM: arm64: Fix bpages backing allocation size in hyp_trace
2026-10-08 19:13 ` Fuad Tabba
@ 2026-10-09 8:39 ` Vincent Donnefort
0 siblings, 0 replies; 6+ messages in thread
From: Vincent Donnefort @ 2026-10-09 8:39 UTC (permalink / raw)
To: Fuad Tabba
Cc: maz, oupton, kvmarm, linux-arm-kernel, joey.gouly, seiden,
suzuki.poulose, yuzenghui, catalin.marinas, will, kernel-team,
qperret
On Thu, Oct 08, 2026 at 08:13:29PM +0100, Fuad Tabba wrote:
> On Thu, 8 Oct 2026 at 11:42, Vincent Donnefort <vdonnefort@google.com> wrote:
> >
> > hyp_trace_buffer_alloc_bpages_backing() computes nr_bpages as
> > (PAGE_ALIGN(size) / PAGE_SIZE) + 1, whereas trace_remote_alloc_buffer()
> > takes into account the buffer page header.
> >
> > Align the bpages backing allocation by using
> > __calc_nr_pages_ring_buffer_desc(). There's no need to validate
> > nr_bpages again, it has been before with trace_buffer_desc_size().
> >
> > Fixes: 3aed038aac8d ("KVM: arm64: Add trace remote for the nVHE/pKVM hyp")
>
> Should this have Cc: stable too, like patch 1? The undercount is there
> since 3aed038aac8d for small buffers, and 442ffa742daa6
> ("tracing/remotes: Account for ring buffer page header in size
> calculation") makes it reachable at ordinary sizes.
>
> Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
> Tested-by: Fuad Tabba <fuad.tabba@linux.dev>
>
> Cheers,
> /fuad
>
> To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com.
>
Yeah I wasn't sure, because __calc_nr_pages_ring_buffer_desc() was introduced
later.
But I can figure it out once the patch fails to apply and provide the
appropriate backport.
Thanks for the review.
--
Vincent
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-10-09 8:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-08 10:42 [PATCH v1 0/2] KVM: arm64: Fixes for hyp_trace Vincent Donnefort
2026-10-08 10:42 ` [PATCH v1 1/2] KVM: arm64: Prevent 64-bit overflow when computing hyp clock rate Vincent Donnefort
2026-10-08 19:12 ` Fuad Tabba
2026-10-08 10:42 ` [PATCH v1 2/2] KVM: arm64: Fix bpages backing allocation size in hyp_trace Vincent Donnefort
2026-10-08 19:13 ` Fuad Tabba
2026-10-09 8:39 ` Vincent Donnefort
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox