From nobody Wed Dec 17 08:05:15 2025 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 9081B313530 for ; Tue, 2 Dec 2025 09:36:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764668216; cv=none; b=LaCCWsHb9ntuVqvnZh4ZyzzPFek33jvHGDStkXR7oD0MXki4ngjVNA57XI0GKDOImLfLBkR8mvP39fj0+WRXdTgAuGte6Y3VmCe5iiatAWDr7a7WGxNQf9NZb4fCvvK2mKo0nOJJtVNZlR3INqUCjdzc641BR5NAf7yHuNKp1yA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764668216; c=relaxed/simple; bh=gN8DsTQ/1en0nSr/tnAaZZ6re/Ok8siNSIeUnIOv100=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BqFCgfIWYHQM5E9eA7HUYANH0kkSTLZ3R9W5WX3BC8IWFJEhbj/rb48+eWgsnIi2l0/A7LXD0qEauOpabKT8Lus+o5EdIYJHlFauDQQ0YvUTeRGUk5r0p1pCYUxWsERq0xE+S4twWr6A9RIEKjbGykq0YVIsAdyN3MeSFezwAkM= 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=QHYJip2a; arc=none smtp.client-ip=209.85.128.74 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="QHYJip2a" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4775d8428e8so44202045e9.0 for ; Tue, 02 Dec 2025 01:36:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764668212; x=1765273012; 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=+urX4bYsJY4uNvVnW0RPoXjdHSG5o+44VhSDvcUY5g8=; b=QHYJip2ax87qb7lUvCwMki65JspwWrjm+ZN8iTOJ2ViYFhCVarG1GKOagUQjymDujt Qq1Ke4uT/r8PskSJu5ioLJVPmb0zR/vJk5F82RxcLFu9ruZu/Teq9jz/XMkALk0eJ3OS V99KD0nUrPkWZ1Kil+iSFQPHDEq1pxBzWn9BlfPOENrPs9qO0O8wMXJrCgionm+egRg0 YHzczalWgH2gudK1Dlsnig7IJ0r07uHc7Z2aZ1FObDDM0hS4Vm9W7ad1fdoiucEaawGA Ev5rbS770dFqXQ2DJ2BWUrNxXritWopGXH9GwUUHekDnpSPgADI3E6/eULEKDb/Qx0YA 9FfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764668212; x=1765273012; 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=+urX4bYsJY4uNvVnW0RPoXjdHSG5o+44VhSDvcUY5g8=; b=TboxJ7nNNVsdR+bpW5U8/U6ta9aUjGz83Jxnfs14tcnnn9zDfOxcK2exOzo3B0T7BN 2n5m/AudSMQrzZQszN6qD8YbaXI7p04EgcmvSby6b3eLwv9nABh1XRFpVjQslcSFbd0c T57Anv62Bv2/2/pfBqXwAmaZXBxTxtA2cWU+Lptt5nOaXXQXP46bPft7+IxTgjq2N3H+ MvUj3lguQkirCd7Zr2/p1c9phwMTefRHVMskrgBAsDKndNfQK05iNHrvcEUFCm4CIcRW nWNJyHAn5NgXu6tCwmd2SVuD5AxyWuz6mmXkyJFxH6fUDyGBhP+1tR9oFe9GcsgzFi5q bnJg== X-Forwarded-Encrypted: i=1; AJvYcCVUy9uAtpXeNE7igaOBNE1OKnRnxCA9ewP/bNWRxs3WHVfSD/nNFb+N4QXmddyIkgt9kIy9mPTuhoD94gc=@vger.kernel.org X-Gm-Message-State: AOJu0YyHhqTT518NWi4KUKof3dJ2zFntjh+35kdxNkF6/q8zQEBJw3Bd sfyBwflL4D++NmIaEshD8yWhWMoCSomGPmTYClOSus0UeIW5S8GApvlu6mvDw6HdCVFcEROy4vE 1ZSwmd9zOFDF+ioJ4Euy3nA== X-Google-Smtp-Source: AGHT+IFgxxxf/V5F3C4Umac3vVzbQvZzBINLSdgbE5epwponp/6FMAwKjTUlKz+vvV7fNkbmaLpz3mFpw652zxYq X-Received: from wmcn18-n1.prod.google.com ([2002:a05:600c:c0d2:10b0:477:a0a1:eae8]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1909:b0:477:b642:9dc6 with SMTP id 5b1f17b1804b1-477c020137fmr430039125e9.34.1764668211970; Tue, 02 Dec 2025 01:36:51 -0800 (PST) Date: Tue, 2 Dec 2025 09:36:14 +0000 In-Reply-To: <20251202093623.2337860-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: <20251202093623.2337860-1-vdonnefort@google.com> X-Mailer: git-send-email 2.52.0.107.ga0afd4fd5b-goog Message-ID: <20251202093623.2337860-22-vdonnefort@google.com> Subject: [PATCH v9 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 e6be1f5d0967..b169d85458f9 100644 --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -128,8 +128,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 @@ -146,5 +145,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 052bf0d4d0b0..7ba427f9608c 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -2396,7 +2397,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 @@ -2605,6 +2606,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 29430c031095..34546dce57ff 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -482,17 +482,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.52.0.107.ga0afd4fd5b-goog