From nobody Thu Oct 2 13:03:48 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CB273054D8; Tue, 16 Sep 2025 10:21:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758018106; cv=none; b=eLdaq4mR2sd8GKHLABuikjVHJdoG6BZaOD+i5xPQbyR+f8A9ie3vvoOdAU3K5LJ5N9fFxBlzjL9+PLRoOyJo92gXfO0gwa0TME9AX+HVuTLUGX+lFfLNWt3/hEf/4hqo3pXw4fL+2HtzorbEvceKoq9DxsgTZquWscs/WC049Kg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758018106; c=relaxed/simple; bh=ixirhmQX+M7Mx0rV9PmCX28aWsPWIaCM3Zlgc6w7sUM=; h=Date:From:To:Subject:Cc:MIME-Version:Message-ID:Content-Type; b=do/q+S4Gqyxy1clz72bK9W9gXZJf0ir9WJf5H0OH3ujmLtTmuPBNbTbewpZth8DVIT2U5WhBGbtNmfeArasg2xoaZ108uTh+uknVS+PJ0mE9bzhnsDLvCVsKR9ny6KE8MLJKPOsauG01L1+N4pU8CYeQUxGN2iZzNEzcKWJICJ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jC3QsmSL; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=8ehATlTb; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jC3QsmSL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="8ehATlTb" Date: Tue, 16 Sep 2025 10:21:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1758018101; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4ukWNdziucicXSqxg6R7ev3kbpXKHxX2lBHSpyeN5Jg=; b=jC3QsmSLXNePxdXqISEwgVBS1ShX77Fnnb+DTWxPTgXGMnhxP3URZFuERu1h6nzc3gyLV1 nf1uCRcy2qhdyvCPX9YDoXrPEpbofOUzH8ycGIZmsz3c4506ypZCpAvbyXPesNFrkLV+dx 1hzQP1R0fftAtNLdiqEBFCcrcqq6XU3+3yJPJkjRoRouxPzHuBrC3x7CPseQrLqio0W6WP lmJ8J4Atblcxu7+l5bHk1kSdZzfqgPS7bcRkfTGdb4q7LsvOLF8ZCXiKYfLO6Mzsvy+wPk IDZkn6hfTW79l5DmEssi2ZihHMXOWyuCax197l/B4H8/FICdK3fwLiYOo6R6mw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1758018101; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4ukWNdziucicXSqxg6R7ev3kbpXKHxX2lBHSpyeN5Jg=; b=8ehATlTb2eTVnKH/WCtHodlD3mb093ykwpjzSa6rz6uD/p9TuA20ACAgCLF/xLErE9VuQc EkwIar5uc1q7VjDA== From: "tip-bot2 for David Woodhouse" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/cpu] x86/cpu: Detect FreeBSD Bhyve hypervisor Cc: David Woodhouse , "Borislav Petkov (AMD)" , "Ahmed S. Darwish" , x86@kernel.org, linux-kernel@vger.kernel.org Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <175801810003.709179.2933247918536663829.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/cpu branch of tip: Commit-ID: fa1d117162aa820a8f73a31ccab85bde6c84725b Gitweb: https://git.kernel.org/tip/fa1d117162aa820a8f73a31ccab85bde6= c84725b Author: David Woodhouse AuthorDate: Sat, 16 Aug 2025 11:06:32 +01:00 Committer: Borislav Petkov (AMD) CommitterDate: Mon, 15 Sep 2025 14:06:44 +02:00 x86/cpu: Detect FreeBSD Bhyve hypervisor Detect the Bhyve hypervisor and enable 15-bit MSI support if available. Detecting Bhyve used to be a purely cosmetic issue of the kernel printing 'Hypervisor detected: Bhyve' at boot time. But FreeBSD 15.0 will support=C2=B9 the 15-bit MSI enlightenment to support more than 255 vCPUs (http://david.woodhou.se/ExtDestId.pdf) which means there's now actually some functional reason to do so. =C2=B9 https://github.com/freebsd/freebsd-src/commit/313a68ea20b4 [ bp: Massage, move tail comment ontop. ] Signed-off-by: David Woodhouse Signed-off-by: Borislav Petkov (AMD) Acked-by: Ahmed S. Darwish Link: https://lore.kernel.org/03802f6f7f5b5cf8c5e8adfe123c397ca8e21093.came= l@infradead.org --- arch/x86/Kconfig | 9 ++++- arch/x86/include/asm/hypervisor.h | 2 +- arch/x86/kernel/cpu/Makefile | 1 +- arch/x86/kernel/cpu/bhyve.c | 66 ++++++++++++++++++++++++++++++- arch/x86/kernel/cpu/hypervisor.c | 3 +- 5 files changed, 81 insertions(+) create mode 100644 arch/x86/kernel/cpu/bhyve.c diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 52c8910..2be5a50 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -879,6 +879,15 @@ config ACRN_GUEST IOT with small footprint and real-time features. More details can be found in https://projectacrn.org/. =20 +config BHYVE_GUEST + bool "Bhyve (BSD Hypervisor) Guest support" + depends on X86_64 + help + This option allows to run Linux to recognise when it is running as a + guest in the Bhyve hypervisor, and to support more than 255 vCPUs when + when doing so. More details about Bhyve can be found at https://bhyve.o= rg + and https://wiki.freebsd.org/bhyve/. + config INTEL_TDX_GUEST bool "Intel TDX (Trust Domain Extensions) - Guest Support" depends on X86_64 && CPU_SUP_INTEL diff --git a/arch/x86/include/asm/hypervisor.h b/arch/x86/include/asm/hyper= visor.h index e41cbf2..9ad86a7 100644 --- a/arch/x86/include/asm/hypervisor.h +++ b/arch/x86/include/asm/hypervisor.h @@ -30,6 +30,7 @@ enum x86_hypervisor_type { X86_HYPER_KVM, X86_HYPER_JAILHOUSE, X86_HYPER_ACRN, + X86_HYPER_BHYVE, }; =20 #ifdef CONFIG_HYPERVISOR_GUEST @@ -64,6 +65,7 @@ extern const struct hypervisor_x86 x86_hyper_xen_pv; extern const struct hypervisor_x86 x86_hyper_kvm; extern const struct hypervisor_x86 x86_hyper_jailhouse; extern const struct hypervisor_x86 x86_hyper_acrn; +extern const struct hypervisor_x86 x86_hyper_bhyve; extern struct hypervisor_x86 x86_hyper_xen_hvm; =20 extern bool nopv; diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile index 1e26179..2f8a58e 100644 --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -58,6 +58,7 @@ obj-$(CONFIG_X86_SGX) +=3D sgx/ obj-$(CONFIG_X86_LOCAL_APIC) +=3D perfctr-watchdog.o =20 obj-$(CONFIG_HYPERVISOR_GUEST) +=3D vmware.o hypervisor.o mshyperv.o +obj-$(CONFIG_BHYVE_GUEST) +=3D bhyve.o obj-$(CONFIG_ACRN_GUEST) +=3D acrn.o =20 obj-$(CONFIG_DEBUG_FS) +=3D debugfs.o diff --git a/arch/x86/kernel/cpu/bhyve.c b/arch/x86/kernel/cpu/bhyve.c new file mode 100644 index 0000000..f1a8ca3 --- /dev/null +++ b/arch/x86/kernel/cpu/bhyve.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * FreeBSD Bhyve guest enlightenments + * + * Copyright =C2=A9 2025 Amazon.com, Inc. or its affiliates. + * + * Author: David Woodhouse + */ + +#include +#include +#include +#include + +static uint32_t bhyve_cpuid_base; +static uint32_t bhyve_cpuid_max; + +#define BHYVE_SIGNATURE "bhyve bhyve " + +#define CPUID_BHYVE_FEATURES 0x40000001 + +/* Features advertised in CPUID_BHYVE_FEATURES %eax */ + +/* MSI Extended Dest ID */ +#define CPUID_BHYVE_FEAT_EXT_DEST_ID (1UL << 0) + +static uint32_t __init bhyve_detect(void) +{ + if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) + return 0; + + bhyve_cpuid_base =3D cpuid_base_hypervisor(BHYVE_SIGNATURE, 0); + if (!bhyve_cpuid_base) + return 0; + + bhyve_cpuid_max =3D cpuid_eax(bhyve_cpuid_base); + return bhyve_cpuid_max; +} + +static uint32_t bhyve_features(void) +{ + unsigned int cpuid_leaf =3D bhyve_cpuid_base | CPUID_BHYVE_FEATURES; + + if (bhyve_cpuid_max < cpuid_leaf) + return 0; + + return cpuid_eax(cpuid_leaf); +} + +static bool __init bhyve_ext_dest_id(void) +{ + return !!(bhyve_features() & CPUID_BHYVE_FEAT_EXT_DEST_ID); +} + +static bool __init bhyve_x2apic_available(void) +{ + return true; +} + +const struct hypervisor_x86 x86_hyper_bhyve __refconst =3D { + .name =3D "Bhyve", + .detect =3D bhyve_detect, + .init.init_platform =3D x86_init_noop, + .init.x2apic_available =3D bhyve_x2apic_available, + .init.msi_ext_dest_id =3D bhyve_ext_dest_id, +}; diff --git a/arch/x86/kernel/cpu/hypervisor.c b/arch/x86/kernel/cpu/hypervi= sor.c index 553bfbf..f3e9219 100644 --- a/arch/x86/kernel/cpu/hypervisor.c +++ b/arch/x86/kernel/cpu/hypervisor.c @@ -45,6 +45,9 @@ static const __initconst struct hypervisor_x86 * const hy= pervisors[] =3D #ifdef CONFIG_ACRN_GUEST &x86_hyper_acrn, #endif +#ifdef CONFIG_BHYVE_GUEST + &x86_hyper_bhyve, +#endif }; =20 enum x86_hypervisor_type x86_hyper_type;