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 <vdonnefort@google.com>
This commit is contained in:
Vincent Donnefort
2024-09-06 18:06:51 +01:00
parent c7596f093d
commit 822682e75d
3 changed files with 9 additions and 9 deletions

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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)