From nobody Wed Jul 31 14:50:52 2024 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 4WYw591RBSz5S2W1; Wed, 31 Jul 2024 14:50:53 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WYw586WDbz4nRh; Wed, 31 Jul 2024 14:50:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722437452; 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=rvyM04Up+TuG6y+1VUCkaJ/DLGW4ZEMnTzem+GINc0I=; b=UN2Nb59ed3WDw25xn1bl47kbOnAi63ckVR5AUVNRvFIn3qm1MWxTWQVadNNEmy8HO4Uxmj UROSE+J9uY32bC5b+vsbjWwxkZ9BWgbOJGbnlNKVTz46hS+SpTdBzcfwQEDFHMS5jCc5bd UDKooPxtmbn0qftYzG20fzYYxS+kQS6jrTlF9bZdWScoQbrLsGCVoBPewDMRejmPwcctdy MayIVcQLUlLZoFodECh99rCA4R+WL1PaH75WwFapKs+BmsFIPGLaPa7sBXblF5A2t0PHeu rtSoCbssmD0ImmGZRMqVYMHN4+jgGW7Qu61lGT/8W5fMKXRLj5LXIWEdreMDoQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722437452; a=rsa-sha256; cv=none; b=umXPEqoOLDAfp55mxAf4NgJ2W/HYsRmkf3XlVu5N9QZjj+v9fMkQDCgrtnpDXkOoKn1PTD TuXjAowdUPwhxaB6DeDtMTzeszhDnXDT4kjglZJBh8vpIJ7DH7OQYvcCqiFXQ1UnsJcEv9 XYhQeHUG92STC79s3cYKuCAI8QbN63C1aauTLZTL9zmb7B6f7vXAD0pZ7/1/9gkNMWdcxO lxODbvk3/S4XyhdSjx8SwdpJiEYrZ8Lp2lP4tvGP0ED7FhpQPq5EKxOneygnIwYOc2gfnm hPOfM13k1uaXTfLwT9b3FKqLyNdkJYzodxvt1RSsgWPdXk9HLfjs0Eaajfk0Dw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722437452; 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=rvyM04Up+TuG6y+1VUCkaJ/DLGW4ZEMnTzem+GINc0I=; b=WJuNc9UD0kcQSbNemjaZdSKtuoAwavYyZUKrsLsy4LV0RcNPOUwjyBMMvSzoFU5BZDnAZU +Jmvs8gJxRVLLkSOuWaVm8Exy4dYMGQvE9JJ0gevzsP+9mk+N5VZ0gcwNXntOknfl0QMhi 7FNmESHsE7Q2hOPx0/hyEY5m5+GU2zZfecPnmwHWd4bpTbSHxkqgEZ5eoRvxCJbz93ZhO+ UH9Ys5DqFfQqSkL1lH+rtU8u9+sxyZw/NYRyaCTMa4QFip2y9NAGN9A2p+UmEJ/9/FKGif 6TiLHm3fqDSWkCa92BrqWNrKlAiGjXcC2HbfqzJo1IGIAvO6aN+32R2ua0G0rw== 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 4WYw5861kPz158T; Wed, 31 Jul 2024 14:50:52 +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 46VEoq1M014733; Wed, 31 Jul 2024 14:50:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46VEoql9014730; Wed, 31 Jul 2024 14:50:52 GMT (envelope-from git) Date: Wed, 31 Jul 2024 14:50:52 GMT Message-Id: <202407311450.46VEoql9014730@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: f44ff2aba2d6 - main - bhyve: Treat the COMMAND register for PCI passthru devices as emulated 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f44ff2aba2d64d1d9312cb55008dc90275ccdc04 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=f44ff2aba2d64d1d9312cb55008dc90275ccdc04 commit f44ff2aba2d64d1d9312cb55008dc90275ccdc04 Author: John Baldwin AuthorDate: 2024-07-31 14:50:33 +0000 Commit: John Baldwin CommitDate: 2024-07-31 14:50:33 +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 --- 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 13d422eaa59c..b8ac782bd7be 100644 --- a/usr.sbin/bhyve/pci_passthru.c +++ b/usr.sbin/bhyve/pci_passthru.c @@ -607,6 +607,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; @@ -618,16 +619,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); @@ -643,13 +646,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) { @@ -919,7 +915,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; @@ -1073,28 +1069,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); }