From 822682e75de0bf86538a3427be150e2973b25c9d Mon Sep 17 00:00:00 2001 From: Vincent Donnefort Date: Fri, 6 Sep 2024 18:06:51 +0100 Subject: [PATCH] ANDROID: KVM: arm64: Fix cpu type for tracing HVCs CPU being an int, we need to check if it is negative to ensure no out-of-bounds access. Make it unsigned. Bug: 229972309 Change-Id: I987a66d83c7bf3143a6ba287e929cd52de549850 Signed-off-by: Vincent Donnefort --- arch/arm64/kvm/hyp/include/nvhe/trace.h | 8 ++++---- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 4 ++-- arch/arm64/kvm/hyp/nvhe/trace.c | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/trace.h b/arch/arm64/kvm/hyp/include/nvhe/trace.h index 2aec8f755f53..399147484f84 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/trace.h +++ b/arch/arm64/kvm/hyp/include/nvhe/trace.h @@ -58,8 +58,8 @@ void *rb_reserve_trace_entry(struct hyp_rb_per_cpu *cpu_buffer, unsigned long le int __pkvm_load_tracing(unsigned long pack_va, size_t pack_size); void __pkvm_teardown_tracing(void); int __pkvm_enable_tracing(bool enable); -int __pkvm_rb_swap_reader_page(int cpu); -int __pkvm_rb_update_footers(int cpu); +int __pkvm_rb_swap_reader_page(unsigned int cpu); +int __pkvm_rb_update_footers(unsigned int cpu); int __pkvm_enable_event(unsigned short id, bool enable); #define HYP_EVENT(__name, __proto, __struct, __assign, __printk) \ @@ -94,12 +94,12 @@ static inline void __pkvm_teardown_tracing(void) { } static inline int __pkvm_enable_tracing(bool enable) { return -ENODEV; } -static inline int __pkvm_rb_swap_reader_page(int cpu) +static inline int __pkvm_rb_swap_reader_page(unsigned int cpu) { return -ENODEV; } -static inline int __pkvm_rb_update_footers(int cpu) +static inline int __pkvm_rb_update_footers(unsigned int cpu) { return -ENODEV; } diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 87ca8cd735ea..eec014b1b4fa 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -1241,14 +1241,14 @@ static void handle___pkvm_enable_tracing(struct kvm_cpu_context *host_ctxt) static void handle___pkvm_rb_swap_reader_page(struct kvm_cpu_context *host_ctxt) { - DECLARE_REG(int, cpu, host_ctxt, 1); + DECLARE_REG(unsigned int, cpu, host_ctxt, 1); cpu_reg(host_ctxt, 1) = __pkvm_rb_swap_reader_page(cpu); } static void handle___pkvm_rb_update_footers(struct kvm_cpu_context *host_ctxt) { - DECLARE_REG(int, cpu, host_ctxt, 1); + DECLARE_REG(unsigned int, cpu, host_ctxt, 1); cpu_reg(host_ctxt, 1) = __pkvm_rb_update_footers(cpu); } diff --git a/arch/arm64/kvm/hyp/nvhe/trace.c b/arch/arm64/kvm/hyp/nvhe/trace.c index 6f796ec7b826..20e011a8785d 100644 --- a/arch/arm64/kvm/hyp/nvhe/trace.c +++ b/arch/arm64/kvm/hyp/nvhe/trace.c @@ -485,7 +485,7 @@ static void rb_teardown_bpage_backing(void) hyp_buffer_pages_backing.size = 0; } -int __pkvm_rb_update_footers(int cpu) +int __pkvm_rb_update_footers(unsigned int cpu) { struct hyp_rb_per_cpu *cpu_buffer; int ret = 0; @@ -508,9 +508,9 @@ int __pkvm_rb_update_footers(int cpu) return ret; } -int __pkvm_rb_swap_reader_page(int cpu) +int __pkvm_rb_swap_reader_page(unsigned int cpu) { - struct hyp_rb_per_cpu *cpu_buffer = per_cpu_ptr(&trace_rb, cpu); + struct hyp_rb_per_cpu *cpu_buffer; int ret = 0; if (cpu >= hyp_nr_cpus)