Skip to content

Commit beb7002

Browse files
author
Fuad Tabba
committed
KVM: arm64: Fix sparse __percpu warning
Force the cast to silence the warning. We don't have a proper way to dynamically allocate memory at EL2, and hence no proper way to dynamically allocate percpu fields. Instead, we rely on memory donated from the host and index it by hyp_smp_processor_id(). Reported-by: Todd Kjos <[email protected]> Change-Id: Ib8b0565ba9550b3f6d8932b24f8f9f69de9168d5 Signed-off-by: Fuad Tabba <[email protected]>
1 parent 19dcec1 commit beb7002

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

arch/arm64/kvm/hyp/nvhe/hyp-main.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ static void handle___pkvm_vcpu_load(struct kvm_cpu_context *host_ctxt)
622622
DECLARE_REG(unsigned int, vcpu_idx, host_ctxt, 2);
623623
DECLARE_REG(u64, hcr_el2, host_ctxt, 3);
624624
struct pkvm_hyp_vcpu *hyp_vcpu;
625+
int __percpu *last_vcpu_ran;
625626
int *last_ran;
626627

627628
if (!is_protected_kvm_enabled())
@@ -636,7 +637,8 @@ static void handle___pkvm_vcpu_load(struct kvm_cpu_context *host_ctxt)
636637
* vcpu from the same VM has previously run on the same physical CPU,
637638
* nuke the relevant contexts.
638639
*/
639-
last_ran = &hyp_vcpu->vcpu.arch.hw_mmu->last_vcpu_ran[hyp_smp_processor_id()];
640+
last_vcpu_ran = hyp_vcpu->vcpu.arch.hw_mmu->last_vcpu_ran;
641+
last_ran = (__force int *) &last_vcpu_ran[hyp_smp_processor_id()];
640642
if (*last_ran != hyp_vcpu->vcpu.vcpu_id) {
641643
__kvm_flush_cpu_context(hyp_vcpu->vcpu.arch.hw_mmu);
642644
*last_ran = hyp_vcpu->vcpu.vcpu_id;

arch/arm64/kvm/hyp/nvhe/pkvm.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ static void init_pkvm_hyp_vm(struct kvm *host_kvm, struct pkvm_hyp_vm *hyp_vm,
449449
hyp_vm->kvm.created_vcpus = nr_vcpus;
450450
hyp_vm->kvm.arch.vtcr = host_mmu.arch.vtcr;
451451
hyp_vm->kvm.arch.pkvm.enabled = READ_ONCE(host_kvm->arch.pkvm.enabled);
452-
hyp_vm->kvm.arch.mmu.last_vcpu_ran = last_ran;
453-
memset(hyp_vm->kvm.arch.mmu.last_vcpu_ran, -1, pkvm_get_last_ran_size());
452+
hyp_vm->kvm.arch.mmu.last_vcpu_ran = (int __percpu *)last_ran;
453+
memset(last_ran, -1, pkvm_get_last_ran_size());
454454
}
455455

456456
static int init_pkvm_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu,
@@ -646,7 +646,7 @@ int __pkvm_init_vm(struct kvm *host_kvm, unsigned long vm_hva,
646646
unsigned long pgd_hva, unsigned long last_ran_hva)
647647
{
648648
struct pkvm_hyp_vm *hyp_vm = NULL;
649-
void *last_ran = NULL;
649+
int *last_ran = NULL;
650650
size_t vm_size, pgd_size, last_ran_size;
651651
unsigned int nr_vcpus;
652652
void *pgd = NULL;
@@ -774,6 +774,7 @@ teardown_donated_memory(struct kvm_hyp_memcache *mc, void *addr, size_t size)
774774
int __pkvm_teardown_vm(pkvm_handle_t handle)
775775
{
776776
size_t vm_size, last_ran_size;
777+
int __percpu *last_vcpu_ran;
777778
struct kvm_hyp_memcache *mc;
778779
struct pkvm_hyp_vm *hyp_vm;
779780
struct kvm *host_kvm;
@@ -820,8 +821,9 @@ int __pkvm_teardown_vm(pkvm_handle_t handle)
820821
teardown_donated_memory(mc, hyp_vcpu, sizeof(*hyp_vcpu));
821822
}
822823

824+
last_vcpu_ran = hyp_vm->kvm.arch.mmu.last_vcpu_ran;
823825
last_ran_size = pkvm_get_last_ran_size();
824-
teardown_donated_memory(mc, hyp_vm->kvm.arch.mmu.last_vcpu_ran,
826+
teardown_donated_memory(mc, (__force void *)last_vcpu_ran,
825827
last_ran_size);
826828

827829
vm_size = pkvm_get_hyp_vm_size(hyp_vm->kvm.created_vcpus);

0 commit comments

Comments
 (0)