From nobody Sun Apr 5 13:13:07 2026 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F9B4344050 for ; Thu, 19 Feb 2026 15:03:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771513432; cv=none; b=Oi891txagSf0mi/QreT+mVAUH5UhUxNXvktMUD/2S8KpKUMZ0XZVLfF8mR/BYnyL+kfEFWOuxDMhb1lH6y360paUWlNRtejBEaGagrLuLkVSl4c+WEgGlQ/VOlAWoW0U+FcajnUdxHTavHEY/k9K1ug+9Lxwgt4ER4RH5Zx3yVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771513432; c=relaxed/simple; bh=YN0wy6xAljYaB8BEJlRUCEBXEfBuSP6aisvhLc0WpOo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PCue60v0Q+v4TsfmIfDfN1pH3U/44NRR6SkaneTyktphC7xI0t7quA0mSiOCUhu4dw5DFvxfIfTIn0myeN+LkKQ1UCgkIN3RgzW4crZd04wrxIxb3tTXhWQBY4U5IW2axjJMakJsvDTIo/MpQBoUkhY6ElimtmP9ZrTyAePOs9E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=T0selSk8; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="T0selSk8" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4836cf00787so20637285e9.1 for ; Thu, 19 Feb 2026 07:03:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771513428; x=1772118228; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oQnpLilO0aV7WO3HSwcQrAojYlDH2g+u5UVGrmlG8EY=; b=T0selSk8BDepn3vvnhQuMDipKs47SRTEWB7K/iKLC10sEu8KQ4iPnVnglos/j7IBIR 8LCmhIY1liqBCZy4ZRTU6CXhD0L/bUOGNyy95RAlXUSRw9FNYjRBZyB6PTFAdBRrB+vP 7IZ5u4l2hD8AICXJm1ILOZqYjfVaPu5/4uRJ/O093n/odPZl9VazfJSx4RNynD3AgVkU ggpamEfZJZG5HKULnP/ohFbpUwmbGvJDPLZ9inECsOR2MemMv0OvB08Cdl463Yovnsgu jKq5YD9OvGs0XyWia8Md3mMRUzJem5yp004I2TbP+0HkSfC9RZH4ZhxvdBxMHh3w7JQY /zuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771513428; x=1772118228; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oQnpLilO0aV7WO3HSwcQrAojYlDH2g+u5UVGrmlG8EY=; b=b9chSBVHYkK3stUUNQKFvIVjb6u4gjVSf86BB/PVic+9LDRN9PYTeDTJNuqhQSSep1 r34aVia7MXYOtE+vfXYUEFvk0lj+mzDDIGVoNH5dopbrt/yAlbDYpPPMDSs3PqQ4jxdb Krr9rvm7YVmo/30elk1THb9kP/F/XZpTL6TWXJZPikn9DOAPZZD0fPRw1RpxOa/XpMiP YjzeAo/9NNV12MSMOK4kwsoFWxWMGFzC7ctXUheZU93hn5Ax4cd9HABMo/Gv9pQEj8KE /KPX38/dYoJ5M9XAoRNw8wt/oTR1drPrGOmWlMUoqTv8TeOZ2MfIzVVHolhao/zTrC6e TsFA== X-Forwarded-Encrypted: i=1; AJvYcCW4V/6u1uvnpFXge2d9ANcQcgVlOm0fQpW1HbAETzwfrsLP6hamRZWcO/ooU5N3UF8RDhT0MkAOmfBv2kI=@vger.kernel.org X-Gm-Message-State: AOJu0YxaUgJL1zQe0RsHSWYEJdOzG7ayKknXnN5SdxVWVjBpFRe/EGNW mQ5fijTJEWMEZgXQOo0LGkiD4042Ovww+lJh3jnIvul4fCE/CVJQd2luEQXt8gt9dJN34IteaeK hDLsc0wKJfD80akDK37wzNw== X-Received: from wmga7.prod.google.com ([2002:a05:600c:2d47:b0:480:69a4:844d]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:c114:b0:47e:e97e:11aa with SMTP id 5b1f17b1804b1-4839fe8e843mr32525065e9.4.1771513427675; Thu, 19 Feb 2026 07:03:47 -0800 (PST) Date: Thu, 19 Feb 2026 15:02:58 +0000 In-Reply-To: <20260219150307.14538-1-vdonnefort@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260219150307.14538-1-vdonnefort@google.com> X-Mailer: git-send-email 2.53.0.335.g19a08e0c02-goog Message-ID: <20260219150307.14538-22-vdonnefort@google.com> Subject: [PATCH v12 21/30] KVM: arm64: Initialise hyp_nr_cpus for nVHE hyp From: Vincent Donnefort To: rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, linux-trace-kernel@vger.kernel.org, maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, jstultz@google.com, qperret@google.com, will@kernel.org, aneesh.kumar@kernel.org, kernel-team@android.com, linux-kernel@vger.kernel.org, Vincent Donnefort Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_= hyp.h index 76ce2b94bd97..4bf63025061e 100644 --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -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_cpu= s, - unsigned long *per_cpu_base, u32 hyp_va_bits); +int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long *per_c= pu_base, u32 hyp_va_bits); void __noreturn __host_enter(struct kvm_cpu_context *host_ctxt); #endif =20 @@ -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); =20 #endif /* __ARM64_KVM_HYP_H__ */ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 94d5b0b99fd1..6f9f3e8356b6 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -2466,7 +2467,7 @@ static int __init do_pkvm_init(u32 hyp_va_bits) preempt_disable(); cpu_hyp_init_context(); ret =3D 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(); =20 @@ -2675,6 +2676,8 @@ static int __init init_hyp_mode(void) kvm_nvhe_sym(kvm_arm_hyp_percpu_base)[cpu] =3D (unsigned long)page_addr; } =20 + kvm_nvhe_sym(hyp_nr_cpus) =3D num_possible_cpus(); + /* * Map the Hyp-code called directly from the host */ diff --git a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h b/arch/arm64/kvm= /hyp/include/nvhe/mem_protect.h index 5f9d56754e39..f8a7b8c04c49 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h @@ -30,8 +30,6 @@ enum pkvm_component_id { PKVM_ID_FFA, }; =20 -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); diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/h= yp-main.c index e7790097db93..8ae3c348ed81 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -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); =20 /* * __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) =3D __pkvm_init(phys, size, nr_cpus, per_cpu_base, - hyp_va_bits); + cpu_reg(host_ctxt, 1) =3D __pkvm_init(phys, size, per_cpu_base, hyp_va_bi= ts); } =20 static void handle___pkvm_cpu_set_vector(struct kvm_cpu_context *host_ctxt) diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setu= p.c index 90bd014e952f..d8e5b563fd3d 100644 --- a/arch/arm64/kvm/hyp/nvhe/setup.c +++ b/arch/arm64/kvm/hyp/nvhe/setup.c @@ -341,8 +341,7 @@ void __noreturn __pkvm_init_finalise(void) __host_enter(host_ctxt); } =20 -int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpu= s, - unsigned long *per_cpu_base, u32 hyp_va_bits) +int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long *per_c= pu_base, u32 hyp_va_bits) { struct kvm_nvhe_init_params *params; void *virt =3D hyp_phys_to_virt(phys); @@ -355,7 +354,6 @@ int __pkvm_init(phys_addr_t phys, unsigned long size, u= nsigned long nr_cpus, return -EINVAL; =20 hyp_spin_lock_init(&pkvm_pgd_lock); - hyp_nr_cpus =3D nr_cpus; =20 ret =3D divide_memory_pool(virt, size); if (ret) --=20 2.53.0.335.g19a08e0c02-goog