[PATCH v1 2/2] KVM: arm64: Fix bpages backing allocation size in hyp_trace

Vincent Donnefort vdonnefort at google.com
Thu Oct 8 03:42:12 PDT 2026


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 at 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




More information about the linux-arm-kernel mailing list