From nobody Sat Nov 30 21:24:37 2024 X-Original-To: dev-commits-src-branches@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 4Y133964wgz5fhKK; Sat, 30 Nov 2024 21:24:37 +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 4Y13394flzz4b57; Sat, 30 Nov 2024 21:24:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733001877; 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=vQlrQMDgGgR0fn0k/1djWQo7SliRTYUSupDehTgtUGM=; b=l74Vo5mW+3IJhAPYtb/kXYuzvcFfrylbx5D+Y/ZyPpt3dILOjArAjkOhXI/eykkAz/A8OQ l8CX8Fh5y6PMCT+rJotgF8qzv4kCbRfjVNN02b0SVacQqUrEAUDo3RP/suy+PSH/7DZR2b ydcO+f0CDeOLuQluk3SHZTeuChY3LWESs9DS/itrZCPzMP8k0OTi04gDapbODy1nx/3hi5 cL0+OQvHFSjM0ncpzTbaKUPtEG6M9lGzzVty2rjEZhje74OzV7OxzYDMbG6n80Suazg/vC WkkT8OQtCnM6SS6JxPiKRDVxEMu8zMmJcqrTR0COf1/ZQVk/rJ9Q5ZC8upvLpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733001877; 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=vQlrQMDgGgR0fn0k/1djWQo7SliRTYUSupDehTgtUGM=; b=RhFx8X785AzOXIWvEzK0qtjdBgCLvbYwD/Cnz3xW2VLmhiFtvz+AHsUHr5fKu5HsXJEU5k l5LbWea+od7UPLuXtAdQQsMV2Cpf+pLTw8AKK7GAHygP2R1TlRdvaU++tGcn1Hv3dzJObJ EhDB6199jItBIEKFuHEC8bNtgswiDZLroWSh5oGDz2VPrs7Dm3mKb7PS3l3/4vIhreqsMb 1qCFcOAHNE4ZZsj4iBysjDYDgTzWRVViuE2fLSblHz0XTpt8JKmCHcITgLqT0OIOvEe2zC WYr3Jzsh03qc2W7k0OhsHjIU0STKjIhhSG6rU8Rg96YBpLwN72jRr+jm7/A1qA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733001877; a=rsa-sha256; cv=none; b=ihw+vaxGckv19tnMXNWh72cGijxSKGrL5KPEFph74SXjhNrSbr/dJmMkxohfpayY/98pCu zZ2aS9GBs2xSc/o5Mw3QUrqRs+AYRU6pHEtTasR0jWhGAIf3T59K166yy/UHtUh/G5vSTX cWtpouFfMDWyxkA0TpNz/ilvwpY7H6tSU06m20iBPcAGh54/Bsx0Ccj5vBJHcXLV1qmtnc 7I5+nD3PwF/mvq9bATlIOhmyAAkxkV3DpIZ7wjq+5JH6Sx0Djo43cKvIBg8kwcgoXaFZQC dHAXRAlP9XrWnrwyiFeEs4X8CSEu0vzxv/9pZaK+1u0AaMaPIYR8+drMPKEhwQ== 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 4Y13394GKnzPKm; Sat, 30 Nov 2024 21:24:37 +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 4AULOb3l057548; Sat, 30 Nov 2024 21:24:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AULObp2057545; Sat, 30 Nov 2024 21:24:37 GMT (envelope-from git) Date: Sat, 30 Nov 2024 21:24:37 GMT Message-Id: <202411302124.4AULObp2057545@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 4aada122862a - stable/14 - bhyve: Treat the COMMAND register for PCI passthru devices as emulated List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 4aada122862ad5631b4a8eb58a5923e9d79565a0 Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=4aada122862ad5631b4a8eb58a5923e9d79565a0 commit 4aada122862ad5631b4a8eb58a5923e9d79565a0 Author: John Baldwin AuthorDate: 2024-07-31 14:50:33 +0000 Commit: John Baldwin CommitDate: 2024-11-30 20:42:08 +0000 bhyve: Treat the COMMAND register for PCI passthru devices as emulated Don't pass through writes of the command register through to the physical device. These registers do not need to be in sync, and in some cases (e.g. when the guest is sizing the BAR and temporarily disables decoding), the states need to diverge. PR: 205549 Reviewed by: corvink Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D46179 (cherry picked from commit f44ff2aba2d64d1d9312cb55008dc90275ccdc04) --- usr.sbin/bhyve/pci_passthru.c | 46 +++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c index 0a80ee649689..345971641f8a 100644 --- a/usr.sbin/bhyve/pci_passthru.c +++ b/usr.sbin/bhyve/pci_passthru.c @@ -608,6 +608,7 @@ cfginit(struct pci_devinst *pi, int bus, int slot, int func) { int error; struct passthru_softc *sc; + uint16_t cmd; uint8_t intline, intpin; error = 1; @@ -619,16 +620,18 @@ cfginit(struct pci_devinst *pi, int bus, int slot, int func) sc->psc_sel.pc_func = func; /* - * Copy physical PCI header to virtual config space. INTLINE and INTPIN - * shouldn't be aligned with their physical value and they are already set by - * pci_emul_init(). + * Copy physical PCI header to virtual config space. COMMAND, + * INTLINE, and INTPIN shouldn't be aligned with their + * physical value and they are already set by pci_emul_init(). */ + cmd = pci_get_cfgdata16(pi, PCIR_COMMAND); intline = pci_get_cfgdata8(pi, PCIR_INTLINE); intpin = pci_get_cfgdata8(pi, PCIR_INTPIN); for (int i = 0; i <= PCIR_MAXLAT; i += 4) { pci_set_cfgdata32(pi, i, pci_host_read_config(&sc->psc_sel, i, 4)); } + pci_set_cfgdata16(pi, PCIR_COMMAND, cmd); pci_set_cfgdata8(pi, PCIR_INTLINE, intline); pci_set_cfgdata8(pi, PCIR_INTPIN, intpin); @@ -644,13 +647,6 @@ cfginit(struct pci_devinst *pi, int bus, int slot, int func) goto done; } - pci_host_write_config(&sc->psc_sel, PCIR_COMMAND, 2, - pci_get_cfgdata16(pi, PCIR_COMMAND)); - - /* - * We need to do this after PCIR_COMMAND got possibly updated, e.g., - * a BAR was enabled, as otherwise the PCIOCBARMMAP might fail on us. - */ if (pci_msix_table_bar(pi) >= 0) { error = init_msix_table(sc); if (error != 0) { @@ -920,7 +916,7 @@ passthru_init(struct pci_devinst *pi, nvlist_t *nvl) passthru_cfgread_emulate, passthru_cfgwrite_emulate)) != 0) goto done; - /* Allow access to the physical command and status register. */ + /* Allow access to the physical status register. */ if ((error = set_pcir_handler(sc, PCIR_COMMAND, 0x04, NULL, NULL)) != 0) goto done; @@ -1074,28 +1070,26 @@ passthru_cfgwrite_default(struct passthru_softc *sc, struct pci_devinst *pi, return (0); } -#ifdef LEGACY_SUPPORT /* - * If this device does not support MSI natively then we cannot let - * the guest disable legacy interrupts from the device. It is the - * legacy interrupt that is triggering the virtual MSI to the guest. + * The command register is emulated, but the status register + * is passed through. */ - if (sc->psc_msi.emulated && pci_msi_enabled(pi)) { - if (coff == PCIR_COMMAND && bytes == 2) - val &= ~PCIM_CMD_INTxDIS; - } -#endif - - pci_host_write_config(&sc->psc_sel, coff, bytes, val); if (coff == PCIR_COMMAND) { + if (bytes <= 2) + return (-1); + + /* Update the physical status register. */ + pci_host_write_config(&sc->psc_sel, PCIR_STATUS, val >> 16, 2); + + /* Update the virtual command register. */ cmd_old = pci_get_cfgdata16(pi, PCIR_COMMAND); - if (bytes == 1) - pci_set_cfgdata8(pi, PCIR_COMMAND, val); - else if (bytes == 2) - pci_set_cfgdata16(pi, PCIR_COMMAND, val); + pci_set_cfgdata16(pi, PCIR_COMMAND, val & 0xffff); pci_emul_cmd_changed(pi, cmd_old); + return (0); } + pci_host_write_config(&sc->psc_sel, coff, bytes, val); + return (0); }