From mboxrd@z Thu Jan 1 00:00:00 1970 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 65C813EF0DC for ; Mon, 9 Mar 2026 16:26:23 +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=1773073585; cv=none; b=Fjl1zTF5afASkrp8LDlHL5s0QC9tG0X6dM2g1o+ZSQZ+UQ+Av4o9C8PnYMX63pXPO7aKaxA8PE9IQaqPvGG6TctrIaIG35B7XqQiHwIBhl6piylvDPiExtgwAv5wyUTBgTjCR6rPGNtJ2LeY+vopMzeXvMK0Vt3bttqlQuxKz4k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773073585; c=relaxed/simple; bh=Qjw69/BBWT9BSPH1lQiEuT1/lOOedls+e1TJNd0iMvs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=m+KMyYLwh2UKRDDCPyhqJy/yAYCOOp3XHe+TEKISAtUvwilQBVhYQMviifZD/rexiv9w/uOK+e8E2RDgdxP1U7knBqVthM6rjpVW5obPgnJ1xE4WWvk6Yz5aMN9+/R6Mv7xjv926CRVzkG4hn9C7SCmhgb5HYUwygfEydAId8Uk= 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=YXOe/+W4; 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="YXOe/+W4" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4853efceaddso6557685e9.3 for ; Mon, 09 Mar 2026 09:26:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773073582; x=1773678382; 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=2KM8z/si7HcTp05zjHIB0T7h5Dhh3bTdr1CGW99HQcs=; b=YXOe/+W4udbt4jWSyJOuGkGKW29HGAYlu4AIc8sKQXV2AapXP/IadrzrLAEhFfWgE+ 5lrUJp4ySq1UYWgvNIgFbCsPEPjjtIGc7hbINIA69FFisKADSioiQZVUFe391RnnKZqB No028EA/iP/cWw33XPozogdwAQMnF5OUwoi2KKApqT1JB6m5utknlbpnFK5oWgroZdXM s1qpj7GSC+sptcHNCy0T3r0vbaqaw6LOSY9XSKbVzzYxp2/1q6S76xStAT12nQd5q7r9 HuXJn6VbVXzp8YqKkMxwgXepbWKi1XPmq0coUaSQSZ6Uc3BrWOFzyVtb89qhE8D27Nwf q+pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773073582; x=1773678382; 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=2KM8z/si7HcTp05zjHIB0T7h5Dhh3bTdr1CGW99HQcs=; b=fFehKLB8j0nqtV5moNvLHZHkZU7kI767SY0FuUGohI5oO8J4afxkiGGMsxKv/ZgFzB IwN61fiJSNtuulj0EkeQlOWBxYXHcfucba2dSipDdEly/Yj+mGkeNC5OftPjCF8ZFamA /hX8VgVixWn6Q3Rt6XxfDywMrlE+l9JqgY9YiTwm4SDJmD6JX4WR5Yi4wlQwrFwUqfE9 /oPT4P4HQGyq7DbtQzswkJmPHd9rjn53lStnWWDkBPGtD4oCnLUuhn5PwURYZn9+cdk9 UYZiwRA0H51kiSUNGv5z4fyPz/W98VV+HvsusgMNMk5tC9UqqQqE37Ze73/R+672Gnuv uVCA== X-Forwarded-Encrypted: i=1; AJvYcCXL2DsGCQvBw9n4LAFy13CN0HvR16jzzrM8E0k4j6pbs1S7A/TyJ+oiGuwqmXTpm8rZ3aKnP7fqKZ14XTmFOr4BY40=@vger.kernel.org X-Gm-Message-State: AOJu0YzZ1pAYnKk333pDBOsWhuR9yKiAqy7PbfYjYR4kPuKxWsAg84IL xp5Caw1v9+msfod9lkNG5bttqyBepWyhilc9saPM7VqnEAXLb8VZ+JSg9FlxuCN7Dt3lb0FKOV/ VHq/dWhQKFa1Xtmetix0lyw== X-Received: from wmv11.prod.google.com ([2002:a05:600c:26cb:b0:485:3539:bc05]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:138a:b0:47e:e2eb:bc22 with SMTP id 5b1f17b1804b1-4852691c5bamr216470615e9.5.1773073581753; Mon, 09 Mar 2026 09:26:21 -0700 (PDT) Date: Mon, 9 Mar 2026 16:25:07 +0000 In-Reply-To: <20260309162516.2623589-1-vdonnefort@google.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260309162516.2623589-1-vdonnefort@google.com> X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog Message-ID: <20260309162516.2623589-22-vdonnefort@google.com> Subject: [PATCH v14 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-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_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__ */ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 410ffd41fd73..1371f9b3ecea 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -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 */ 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, }; -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/hyp-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); /* * __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) diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.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); } -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) -- 2.53.0.473.g4a7958ca14-goog