]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: arm64: Initialise hyp_nr_cpus for nVHE hyp
authorVincent Donnefort <vdonnefort@google.com>
Mon, 9 Mar 2026 16:25:07 +0000 (16:25 +0000)
committerMarc Zyngier <maz@kernel.org>
Wed, 11 Mar 2026 08:51:16 +0000 (08:51 +0000)
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>
arch/arm64/include/asm/kvm_hyp.h
arch/arm64/kvm/arm.c
arch/arm64/kvm/hyp/include/nvhe/mem_protect.h
arch/arm64/kvm/hyp/nvhe/hyp-main.c
arch/arm64/kvm/hyp/nvhe/setup.c

index 76ce2b94bd97e3dfb90ac770583d814ff8125497..4bf63025061e524ec5578739482b6b6a8db3e1ee 100644 (file)
@@ -129,8 +129,7 @@ void __noreturn __hyp_do_panic(struct kvm_cpu_context *host_ctxt, u64 spsr,
 #ifdef __KVM_NVHE_HYPERVISOR__
 void __pkvm_init_switch_pgd(phys_addr_t pgd, unsigned long sp,
                void (*fn)(void));
-int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpus,
-               unsigned long *per_cpu_base, u32 hyp_va_bits);
+int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long *per_cpu_base, u32 hyp_va_bits);
 void __noreturn __host_enter(struct kvm_cpu_context *host_ctxt);
 #endif
 
@@ -147,5 +146,6 @@ extern u64 kvm_nvhe_sym(id_aa64smfr0_el1_sys_val);
 extern unsigned long kvm_nvhe_sym(__icache_flags);
 extern unsigned int kvm_nvhe_sym(kvm_arm_vmid_bits);
 extern unsigned int kvm_nvhe_sym(kvm_host_sve_max_vl);
+extern unsigned long kvm_nvhe_sym(hyp_nr_cpus);
 
 #endif /* __ARM64_KVM_HYP_H__ */
index 410ffd41fd73aadfbdedd8892dfb2f0534416605..1371f9b3ecea51031486a8a2cabea9b054e085df 100644 (file)
@@ -35,6 +35,7 @@
 #include <asm/kvm_arm.h>
 #include <asm/kvm_asm.h>
 #include <asm/kvm_emulate.h>
+#include <asm/kvm_hyp.h>
 #include <asm/kvm_mmu.h>
 #include <asm/kvm_nested.h>
 #include <asm/kvm_pkvm.h>
@@ -2465,7 +2466,7 @@ static int __init do_pkvm_init(u32 hyp_va_bits)
        preempt_disable();
        cpu_hyp_init_context();
        ret = kvm_call_hyp_nvhe(__pkvm_init, hyp_mem_base, hyp_mem_size,
-                               num_possible_cpus(), kern_hyp_va(per_cpu_base),
+                               kern_hyp_va(per_cpu_base),
                                hyp_va_bits);
        cpu_hyp_init_features();
 
@@ -2674,6 +2675,8 @@ static int __init init_hyp_mode(void)
                kvm_nvhe_sym(kvm_arm_hyp_percpu_base)[cpu] = (unsigned long)page_addr;
        }
 
+       kvm_nvhe_sym(hyp_nr_cpus) = num_possible_cpus();
+
        /*
         * Map the Hyp-code called directly from the host
         */
index 5f9d56754e39f5ce9378dfe76a53c84ab5583e08..f8a7b8c04c490fb0e0ed3718323f5e210eb65bb5 100644 (file)
@@ -30,8 +30,6 @@ enum pkvm_component_id {
        PKVM_ID_FFA,
 };
 
-extern unsigned long hyp_nr_cpus;
-
 int __pkvm_prot_finalize(void);
 int __pkvm_host_share_hyp(u64 pfn);
 int __pkvm_host_unshare_hyp(u64 pfn);
index e7790097db93a02bbd8101babf71348acee8448b..8ae3c348ed810e2b3fec243e5a2d79055eff6956 100644 (file)
@@ -486,17 +486,15 @@ static void handle___pkvm_init(struct kvm_cpu_context *host_ctxt)
 {
        DECLARE_REG(phys_addr_t, phys, host_ctxt, 1);
        DECLARE_REG(unsigned long, size, host_ctxt, 2);
-       DECLARE_REG(unsigned long, nr_cpus, host_ctxt, 3);
-       DECLARE_REG(unsigned long *, per_cpu_base, host_ctxt, 4);
-       DECLARE_REG(u32, hyp_va_bits, host_ctxt, 5);
+       DECLARE_REG(unsigned long *, per_cpu_base, host_ctxt, 3);
+       DECLARE_REG(u32, hyp_va_bits, host_ctxt, 4);
 
        /*
         * __pkvm_init() will return only if an error occurred, otherwise it
         * will tail-call in __pkvm_init_finalise() which will have to deal
         * with the host context directly.
         */
-       cpu_reg(host_ctxt, 1) = __pkvm_init(phys, size, nr_cpus, per_cpu_base,
-                                           hyp_va_bits);
+       cpu_reg(host_ctxt, 1) = __pkvm_init(phys, size, per_cpu_base, hyp_va_bits);
 }
 
 static void handle___pkvm_cpu_set_vector(struct kvm_cpu_context *host_ctxt)
index 90bd014e952fbc57a104444800cf78afe4400683..d8e5b563fd3d9f8c99e3baff57f6263cfb204097 100644 (file)
@@ -341,8 +341,7 @@ out:
        __host_enter(host_ctxt);
 }
 
-int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpus,
-               unsigned long *per_cpu_base, u32 hyp_va_bits)
+int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long *per_cpu_base, u32 hyp_va_bits)
 {
        struct kvm_nvhe_init_params *params;
        void *virt = hyp_phys_to_virt(phys);
@@ -355,7 +354,6 @@ int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpus,
                return -EINVAL;
 
        hyp_spin_lock_init(&pkvm_pgd_lock);
-       hyp_nr_cpus = nr_cpus;
 
        ret = divide_memory_pool(virt, size);
        if (ret)