From nobody Thu Aug 7 16:42:39 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4byXyS21P4z64TK6; Thu, 07 Aug 2025 16:42:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4byXyS0dHJz3WTf; Thu, 07 Aug 2025 16:42:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754584960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NfVL4ree/jBo07ePex/zY21WVHTYQPHpKN71FRHGe9g=; b=I5DaIwmxgYnc6RBa94ubLKaZhFPQQXHkhbQTmYOGWHW09wuhxir2XzPHziV0F/T7GUxiZT JO4vHvwJVx/ujyQB5oLVnj9vE3Xa6yJZZUBm93Ivuy1+FYKZD+hSSW7mvjVqFmqhE7ZYyt t/KMqMxLZpQrZtm7jF1dTH0r4Gi2ok28pRc5G007abNzUHoEn1Gszmuq62YEpM7v+sGp5P ILXZ4tPYKsNqcvsBSvoqHFZDQkkx5w4nxFp2kebzGAd/RDbT/YW9i5YqrA7L0FoUfD8q/c c7LWpOwhSAk7tXktx62twcM9iVKhKhssZeGr5T+5gTwp6IfoLRkL5M5fn4/YOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754584960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NfVL4ree/jBo07ePex/zY21WVHTYQPHpKN71FRHGe9g=; b=AiSI/iO1BbPrVS7ZN7FLI/8oYqOohulwVsMQyDVQENcNQndmjd6aL87oBHJGhLNGWmzhRT X0R3YGMiTOuiiKyTpNyn7RPhC0gCvIvz3CO3jhqjmsWroaxCB/kW0D5bAVya1VspYZxvOz OOo7rjqWeF4h2FOfA9GGog7u4n7aldww8JwQcHCEzsuxIl86eDJnh6BAy5Uhvg82kwKvMk SA056lCkVHwkJRVvoXeM7Gxew+FKXrQZ2Z+vVUltiqv9ZD4xVfhTTuYMpBucr+INYNsrQ8 Ed2DzJeEEvvzkkWtOaonNyg+N8cGT/AGKY5KHeSI1wdSrml1P4+cjdeLclcVYA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1754584960; a=rsa-sha256; cv=none; b=ocWE5/ULCINyQcdokn71Jb1W3lqB93Y5CjagZwOSU+dt6L2lLdzqwo0qCQ4AA8Qxiy2E3j A6SiAgIe5DaEY3/RSoiR3dTybYE36d0/9uCOZTjb1dIN9QXQPy58LHf+oclVuWyYT+ob7L V7hgdrU0vJdxasCEYeO5CWSxQDAItbsVvaHsjsomhXle4xXwho0AiDd+CcpoGqhru33kK+ hBA5tfiBDZa5tfCdRAgcBXUa1MZ7C1iBrl3Q/wm3w1U8tIfTxgv9Utoh4401Fygk9naaXA SdfnE5rlpA25NH+55onCdqyTU25En0e68OI2ThCyeg3OZv8eKSxJ2dG9aNcVsQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4byXyS01Hcz1D4W; Thu, 07 Aug 2025 16:42:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 577GgdYY093840; Thu, 7 Aug 2025 16:42:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 577GgdFl093837; Thu, 7 Aug 2025 16:42:39 GMT (envelope-from git) Date: Thu, 7 Aug 2025 16:42:39 GMT Message-Id: <202508071642.577GgdFl093837@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 6227d0f81a5e - main - bhyve/arm64: Stop assuming the CPU index is MPIDR List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6227d0f81a5e5e2473ceb8b185098ee9a53c82ff Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=6227d0f81a5e5e2473ceb8b185098ee9a53c82ff commit 6227d0f81a5e5e2473ceb8b185098ee9a53c82ff Author: Andrew Turner AuthorDate: 2025-08-07 11:12:39 +0000 Commit: Andrew Turner CommitDate: 2025-08-07 11:30:59 +0000 bhyve/arm64: Stop assuming the CPU index is MPIDR We need the MPIDR value in a few places in userspace. Rather than calculate it ask the kernel to give it to us. This allows us to change how it is calculated without having to change userspace. Reviewed by: markj Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D51763 --- usr.sbin/bhyve/aarch64/bhyve_machdep.h | 1 + usr.sbin/bhyve/aarch64/bhyverun_machdep.c | 21 +++++++++++++++++++++ usr.sbin/bhyve/aarch64/fdt.c | 3 ++- usr.sbin/bhyve/aarch64/vmexit.c | 23 +++++++++++------------ 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/usr.sbin/bhyve/aarch64/bhyve_machdep.h b/usr.sbin/bhyve/aarch64/bhyve_machdep.h index e487bb5a0f44..2dde231091fc 100644 --- a/usr.sbin/bhyve/aarch64/bhyve_machdep.h +++ b/usr.sbin/bhyve/aarch64/bhyve_machdep.h @@ -7,6 +7,7 @@ #ifndef _BHYVE_MACHDEP_H_ #define _BHYVE_MACHDEP_H_ +extern uint64_t *cpu_to_mpidr; extern cpuset_t running_cpumask; #endif /* _BHYVE_MACHDEP_H_ */ diff --git a/usr.sbin/bhyve/aarch64/bhyverun_machdep.c b/usr.sbin/bhyve/aarch64/bhyverun_machdep.c index 098454169272..06fe85f96e0a 100644 --- a/usr.sbin/bhyve/aarch64/bhyverun_machdep.c +++ b/usr.sbin/bhyve/aarch64/bhyverun_machdep.c @@ -30,6 +30,8 @@ #include #include +#include + #include #include #include @@ -74,6 +76,8 @@ #define PCIE_INTC 36 #define PCIE_INTD 37 +uint64_t *cpu_to_mpidr; + void bhyve_init_config(void) { @@ -364,6 +368,23 @@ bhyve_init_platform(struct vmctx *ctx, struct vcpu *bsp) int error; int pcie_intrs[4] = {PCIE_INTA, PCIE_INTB, PCIE_INTC, PCIE_INTD}; + cpu_to_mpidr = calloc(guest_ncpus, sizeof(*cpu_to_mpidr)); + if (cpu_to_mpidr == NULL) { + warnx("unable to allocate space for mpidr list"); + return (ENOMEM); + } + + for (uint64_t cpu = 0; cpu < (uint64_t)guest_ncpus; cpu++) { + uint64_t mpidr; + + error = vm_get_register(fbsdrun_vcpu(cpu), VM_REG_GUEST_MPIDR_EL1, + &mpidr); + assert(error == 0); +#define MPIDR_AFF_MASK (MPIDR_AFF0_MASK | MPIDR_AFF1_MASK | MPIDR_AFF2_MASK | MPIDR_AFF3_MASK) + cpu_to_mpidr[cpu] = mpidr & MPIDR_AFF_MASK; +#undef MPIDR_AFF_MASK + } + bootrom = get_config_value("bootrom"); if (bootrom == NULL) { warnx("no bootrom specified"); diff --git a/usr.sbin/bhyve/aarch64/fdt.c b/usr.sbin/bhyve/aarch64/fdt.c index 3fb97a40c241..8832a99a6cf1 100644 --- a/usr.sbin/bhyve/aarch64/fdt.c +++ b/usr.sbin/bhyve/aarch64/fdt.c @@ -39,6 +39,7 @@ #include #include "config.h" +#include "bhyve_machdep.h" #include "bhyverun.h" #include "fdt.h" @@ -92,7 +93,7 @@ add_cpu(void *fdt, int cpuid) fdt_begin_node(fdt, node_name); fdt_property_string(fdt, "device_type", "cpu"); fdt_property_string(fdt, "compatible", "arm,armv8"); - fdt_property_u64(fdt, "reg", cpuid); + fdt_property_u64(fdt, "reg", cpu_to_mpidr[cpuid]); fdt_property_string(fdt, "enable-method", "psci"); fdt_end_node(fdt); } diff --git a/usr.sbin/bhyve/aarch64/vmexit.c b/usr.sbin/bhyve/aarch64/vmexit.c index 6b7f80e67a92..e6dd4b074d39 100644 --- a/usr.sbin/bhyve/aarch64/vmexit.c +++ b/usr.sbin/bhyve/aarch64/vmexit.c @@ -152,7 +152,7 @@ vmexit_bogus(struct vmctx *ctx __unused, struct vcpu *vcpu __unused, static uint64_t smccc_affinity_info(uint64_t target_affinity, uint32_t lowest_affinity_level) { - uint64_t cpu_aff, mask = 0; + uint64_t mask = 0; switch (lowest_affinity_level) { case 0: @@ -172,13 +172,7 @@ smccc_affinity_info(uint64_t target_affinity, uint32_t lowest_affinity_level) } for (int vcpu = 0; vcpu < guest_ncpus; vcpu++) { - /* TODO: We should get this from the kernel */ - cpu_aff = (vcpu & 0xf) << MPIDR_AFF0_SHIFT | - ((vcpu >> 4) & 0xff) << MPIDR_AFF1_SHIFT | - ((vcpu >> 12) & 0xff) << MPIDR_AFF2_SHIFT | - (uint64_t)((vcpu >> 20) & 0xff) << MPIDR_AFF3_SHIFT; - - if ((cpu_aff & mask) == (target_affinity & mask) && + if ((cpu_to_mpidr[vcpu] & mask) == (target_affinity & mask) && CPU_ISSET(vcpu, &running_cpumask)) { /* Return ON if any CPUs are on */ return (PSCI_AFFINITY_INFO_ON); @@ -194,9 +188,9 @@ vmexit_smccc(struct vmctx *ctx, struct vcpu *vcpu, struct vm_run *vmrun) { struct vcpu *newvcpu; struct vm_exit *vme; - uint64_t newcpu, smccc_rv; + uint64_t mpidr, smccc_rv; enum vm_suspend_how how; - int error; + int error, newcpu; /* Return the Unknown Function Identifier by default */ smccc_rv = SMCCC_RET_NOT_SUPPORTED; @@ -211,8 +205,13 @@ vmexit_smccc(struct vmctx *ctx, struct vcpu *vcpu, struct vm_run *vmrun) case PSCI_FNID_CPU_OFF: break; case PSCI_FNID_CPU_ON: - newcpu = vme->u.smccc_call.args[0]; - if (newcpu > (uint64_t)guest_ncpus) { + mpidr = vme->u.smccc_call.args[0]; + for (newcpu = 0; newcpu < guest_ncpus; newcpu++) { + if (cpu_to_mpidr[newcpu] == mpidr) + break; + } + + if (newcpu == guest_ncpus) { smccc_rv = PSCI_RETVAL_INVALID_PARAMS; break; }