From nobody Tue Aug 5 14:03:14 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 4bxFWQ6MgDz63GKh; Tue, 05 Aug 2025 14:03:14 +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 4bxFWQ5Bs8z3FCT; Tue, 05 Aug 2025 14:03:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754402594; 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=EUZrhUnVLqdB+cY2Gx4rCKZFg6f+rb5pwZ8JhpDaXuM=; b=KO+uEwTQGMYEA8HTRXWO5g+u+nlB9+0IBYL7NRVUj+qTUIyJoiZkYco/7HObUHIIFv/rs+ Nek7HVNgHHPrG7oNoeoAFISXLyLlF+Flkq5HwQX6SX+ZG7NaPoRdnE5DrcXfKfU80c7oWx dyhML4m5ybAgu9B36PZxpaajlQhNLodrAYxgGPCmWrx+w5LMe63iUuprJNazRMlhBrZTXF iMD3ywab19BLMxaZ9pGXmEKoUl4iTQRKxSTZCe8WEWTIP+uNtHIUYmlzZJRKTBW/npxvlF KL7P7rg6Gpr+Ny+RQDxr4Exnzy/DmmlCq9cQesL8kUuXwa7QYHz28JhCMpNRrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754402594; 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=EUZrhUnVLqdB+cY2Gx4rCKZFg6f+rb5pwZ8JhpDaXuM=; b=DZefJSHQ5eJRVY/55hZDP1ed7tqCpV2OCVCpWcjrgXrKW+aWIF50bFnwoq/e23xqdi0mU5 aITtVv1V5E7pEEKbWwRw1LlKRVRcuR/cDwdSeRrh2YT4V1GXh0h46/OxVgWzl6B4B+ivV5 J8GMAjxSFyH7SKruvuKflBIWlEsHDNog9bhBneSbM1v59xHnEohqBs+8U4XGuZ0GK+1Vg+ fOOlY5WCrasWg6HECIZDPUzf/uD29TcTTj7iBpywZI5P8wEJQl1euXj7KuhPe2LCN+uFNs 3SWCCIUbUo2HggP7ZxZjwA9gbHfbQLelNhEqGpUpZMtIXQLBmZIZER0nIYzcbA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1754402594; a=rsa-sha256; cv=none; b=I4ayaLbgNpj8l5LxPPwW1uEWUWwLF12bugyBJGm33yg8Dy/hmt7cEY93F1xgV6G5Sm2sFQ BrZDE6fm4uuKRNtzBeAE8D2lrO7zIKxmOI4pDaTHKpkret045mMRxRp8hP8rvUcrAYumqv wg6XR3aS7fR9qTFGitDwmhU0iwl7zi+tqk1zqenzGgJVQG0tjClC7BueCVgyaPJanqVVCk FJHpexahUR9bAUMKnmGtRR2SBkN+IZHsmlIo0JgMqsukm0thczP2CnyUiRBTcwXv5CVS7O odpITQh+bLND11P+X5oq+hnEgjs8Pyi0gWcv0K14oofNWTSDIilAiO/evy+prQ== 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 4bxFWQ4Q0wzdgj; Tue, 05 Aug 2025 14:03:14 +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 575E3EG1070527; Tue, 5 Aug 2025 14:03:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 575E3ESl070524; Tue, 5 Aug 2025 14:03:14 GMT (envelope-from git) Date: Tue, 5 Aug 2025 14:03:14 GMT Message-Id: <202508051403.575E3ESl070524@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Corvin =?utf-8?Q?K=C3=B6hne?= Subject: git: 1bc515184d87 - main - bhyve: scan PCI device ID to properly set BDSM address 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: corvink X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1bc515184d875964c95c7732738fd8d8ae0511cb Auto-Submitted: auto-generated The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=1bc515184d875964c95c7732738fd8d8ae0511cb commit 1bc515184d875964c95c7732738fd8d8ae0511cb Author: Corvin Köhne AuthorDate: 2025-06-12 07:56:57 +0000 Commit: Corvin Köhne CommitDate: 2025-08-05 13:49:28 +0000 bhyve: scan PCI device ID to properly set BDSM address The address and size of the BDSM register has changed in recent Intel GPUs. To account for that change, we have to detect the GPU generation. We've recently added all known PCI IDs of Intel GPUs from Linux. Make use of this header to scan the device ID and properly set the BDSM address. Note that even though a bunch of devices is listed in our device array, not all device will work properly. Especially some old devices may not support VT-d, required for passthrough in general, at all. Reviewed by: jhb MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D50807 --- usr.sbin/bhyve/amd64/pci_gvt-d.c | 98 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 6 deletions(-) diff --git a/usr.sbin/bhyve/amd64/pci_gvt-d.c b/usr.sbin/bhyve/amd64/pci_gvt-d.c index 60bf460d71ed..e506b75e77fe 100644 --- a/usr.sbin/bhyve/amd64/pci_gvt-d.c +++ b/usr.sbin/bhyve/amd64/pci_gvt-d.c @@ -20,6 +20,7 @@ #include "amd64/e820.h" #include "pci_gvt-d-opregion.h" #include "pci_passthru.h" +#include "pciids_intel_gpus.h" #define KB (1024UL) #define MB (1024 * KB) @@ -41,6 +42,89 @@ #define GVT_D_MAP_OPREGION 1 #define GVT_D_MAP_VBT 2 +static int +set_bdsm_gen3(struct pci_devinst *const pi, vm_paddr_t bdsm_gpa) +{ + struct passthru_softc *sc = pi->pi_arg; + uint32_t bdsm; + int error; + + bdsm = pci_host_read_config(passthru_get_sel(sc), PCIR_BDSM, 4); + + /* Protect the BDSM register in PCI space. */ + pci_set_cfgdata32(pi, PCIR_BDSM, + bdsm_gpa | (bdsm & (PCIM_BDSM_GSM_ALIGNMENT - 1))); + error = set_pcir_handler(sc, PCIR_BDSM, 4, passthru_cfgread_emulate, + passthru_cfgwrite_emulate); + if (error) { + warnx("%s: Failed to setup handler for BDSM register!", __func__); + return (error); + } + + return (0); +} + +struct igd_ops { + int (*set_bdsm)(struct pci_devinst *const pi, vm_paddr_t bdsm_gpa); +}; + +static const struct igd_ops igd_ops_gen3 = { .set_bdsm = set_bdsm_gen3 }; + +struct igd_device { + uint32_t device_id; + const struct igd_ops *ops; +}; + +#define IGD_DEVICE(_device_id, _ops) \ + { \ + .device_id = (_device_id), \ + .ops = (_ops), \ + } + +static const struct igd_device igd_devices[] = { + INTEL_I915G_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_I915GM_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_I945G_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_I945GM_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_VLV_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_PNV_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_I965GM_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_GM45_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_G45_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_ILK_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_SNB_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_IVB_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_HSW_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_BDW_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_CHV_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_SKL_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_BXT_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_KBL_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_CFL_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_WHL_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_CML_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_GLK_IDS(IGD_DEVICE, &igd_ops_gen3), + INTEL_CNL_IDS(IGD_DEVICE, &igd_ops_gen3), +}; + +static const struct igd_ops * +get_igd_ops(struct pci_devinst *const pi) +{ + struct passthru_softc *sc = pi->pi_arg; + uint16_t device_id; + + device_id = pci_host_read_config(passthru_get_sel(sc), PCIR_DEVICE, + 0x02); + for (size_t i = 0; i < nitems(igd_devices); i++) { + if (igd_devices[i].device_id != device_id) + continue; + + return (igd_devices[i].ops); + } + + return (NULL); +} + static int gvt_d_probe(struct pci_devinst *const pi) { @@ -108,8 +192,8 @@ gvt_d_setup_gsm(struct pci_devinst *const pi) { struct passthru_softc *sc; struct passthru_mmio_mapping *gsm; + const struct igd_ops *igd_ops; size_t sysctl_len; - uint32_t bdsm; int error; sc = pi->pi_arg; @@ -170,12 +254,14 @@ gvt_d_setup_gsm(struct pci_devinst *const pi) "Warning: Unable to reuse host address of Graphics Stolen Memory. GPU passthrough might not work properly."); } - bdsm = pci_host_read_config(passthru_get_sel(sc), PCIR_BDSM, 4); - pci_set_cfgdata32(pi, PCIR_BDSM, - gsm->gpa | (bdsm & (PCIM_BDSM_GSM_ALIGNMENT - 1))); + igd_ops = get_igd_ops(pi); + if (igd_ops == NULL) { + warn("%s: Unknown IGD device. It's not supported yet!", + __func__); + return (-1); + } - return (set_pcir_handler(sc, PCIR_BDSM, 4, passthru_cfgread_emulate, - passthru_cfgwrite_emulate)); + return (igd_ops->set_bdsm(pi, gsm->gpa)); } static int