Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

KVM: arm64: Initialise hyp_nr_cpus for nVHE hyp

Knowing the number of CPUs is necessary for determining the boundaries
of per-cpu variables, which will be used for upcoming hypervisor
tracing. hyp_nr_cpus which stores this value, is only initialised for
the pKVM hypervisor. Make it accessible for the nVHE hypervisor as well.

With the kernel now responsible for initialising hyp_nr_cpus, the
nr_cpus parameter is no longer needed in __pkvm_init.

Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Link: https://patch.msgid.link/20260309162516.2623589-22-vdonnefort@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>

authored by

Vincent Donnefort and committed by
Marc Zyngier
8bbeb4d1 405df5b5

+10 -13
+2 -2
arch/arm64/include/asm/kvm_hyp.h
··· 129 129 #ifdef __KVM_NVHE_HYPERVISOR__ 130 130 void __pkvm_init_switch_pgd(phys_addr_t pgd, unsigned long sp, 131 131 void (*fn)(void)); 132 - int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpus, 133 - unsigned long *per_cpu_base, u32 hyp_va_bits); 132 + int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long *per_cpu_base, u32 hyp_va_bits); 134 133 void __noreturn __host_enter(struct kvm_cpu_context *host_ctxt); 135 134 #endif 136 135 ··· 146 147 extern unsigned long kvm_nvhe_sym(__icache_flags); 147 148 extern unsigned int kvm_nvhe_sym(kvm_arm_vmid_bits); 148 149 extern unsigned int kvm_nvhe_sym(kvm_host_sve_max_vl); 150 + extern unsigned long kvm_nvhe_sym(hyp_nr_cpus); 149 151 150 152 #endif /* __ARM64_KVM_HYP_H__ */
+4 -1
arch/arm64/kvm/arm.c
··· 35 35 #include <asm/kvm_arm.h> 36 36 #include <asm/kvm_asm.h> 37 37 #include <asm/kvm_emulate.h> 38 + #include <asm/kvm_hyp.h> 38 39 #include <asm/kvm_mmu.h> 39 40 #include <asm/kvm_nested.h> 40 41 #include <asm/kvm_pkvm.h> ··· 2466 2465 preempt_disable(); 2467 2466 cpu_hyp_init_context(); 2468 2467 ret = kvm_call_hyp_nvhe(__pkvm_init, hyp_mem_base, hyp_mem_size, 2469 - num_possible_cpus(), kern_hyp_va(per_cpu_base), 2468 + kern_hyp_va(per_cpu_base), 2470 2469 hyp_va_bits); 2471 2470 cpu_hyp_init_features(); 2472 2471 ··· 2674 2673 memcpy(page_addr, CHOOSE_NVHE_SYM(__per_cpu_start), nvhe_percpu_size()); 2675 2674 kvm_nvhe_sym(kvm_arm_hyp_percpu_base)[cpu] = (unsigned long)page_addr; 2676 2675 } 2676 + 2677 + kvm_nvhe_sym(hyp_nr_cpus) = num_possible_cpus(); 2677 2678 2678 2679 /* 2679 2680 * Map the Hyp-code called directly from the host
-2
arch/arm64/kvm/hyp/include/nvhe/mem_protect.h
··· 30 30 PKVM_ID_FFA, 31 31 }; 32 32 33 - extern unsigned long hyp_nr_cpus; 34 - 35 33 int __pkvm_prot_finalize(void); 36 34 int __pkvm_host_share_hyp(u64 pfn); 37 35 int __pkvm_host_unshare_hyp(u64 pfn);
+3 -5
arch/arm64/kvm/hyp/nvhe/hyp-main.c
··· 486 486 { 487 487 DECLARE_REG(phys_addr_t, phys, host_ctxt, 1); 488 488 DECLARE_REG(unsigned long, size, host_ctxt, 2); 489 - DECLARE_REG(unsigned long, nr_cpus, host_ctxt, 3); 490 - DECLARE_REG(unsigned long *, per_cpu_base, host_ctxt, 4); 491 - DECLARE_REG(u32, hyp_va_bits, host_ctxt, 5); 489 + DECLARE_REG(unsigned long *, per_cpu_base, host_ctxt, 3); 490 + DECLARE_REG(u32, hyp_va_bits, host_ctxt, 4); 492 491 493 492 /* 494 493 * __pkvm_init() will return only if an error occurred, otherwise it 495 494 * will tail-call in __pkvm_init_finalise() which will have to deal 496 495 * with the host context directly. 497 496 */ 498 - cpu_reg(host_ctxt, 1) = __pkvm_init(phys, size, nr_cpus, per_cpu_base, 499 - hyp_va_bits); 497 + cpu_reg(host_ctxt, 1) = __pkvm_init(phys, size, per_cpu_base, hyp_va_bits); 500 498 } 501 499 502 500 static void handle___pkvm_cpu_set_vector(struct kvm_cpu_context *host_ctxt)
+1 -3
arch/arm64/kvm/hyp/nvhe/setup.c
··· 341 341 __host_enter(host_ctxt); 342 342 } 343 343 344 - int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpus, 345 - unsigned long *per_cpu_base, u32 hyp_va_bits) 344 + int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long *per_cpu_base, u32 hyp_va_bits) 346 345 { 347 346 struct kvm_nvhe_init_params *params; 348 347 void *virt = hyp_phys_to_virt(phys); ··· 354 355 return -EINVAL; 355 356 356 357 hyp_spin_lock_init(&pkvm_pgd_lock); 357 - hyp_nr_cpus = nr_cpus; 358 358 359 359 ret = divide_memory_pool(virt, size); 360 360 if (ret)