From nobody Fri Jan 14 14:20:37 2022 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 D2935195D980; Fri, 14 Jan 2022 14:20:38 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jb3P22DkHz3Lww; Fri, 14 Jan 2022 14:20:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642170038; 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=6BvN2Hj8gGr6HPxh28i0WeIIdXm/PaBl52ieBBKfIsc=; b=MjtyilgWAO0ls/ueb58Msda6Tf5Jrr/UC65LoSN2xb9pKFTyKbIVWSXFlqxTKPJ/ypd88X YVaXX8sivcG7D4HyQcLITbGw0Xvx2+jo6fyMjsPOYidZ34zRFVz0veGSSxdgCy8w1liDuq Fe6cRBE0vkUGBj51sP6+CZn9WJw+YiiUMq/QRV2nduc8SjLj8YLzPuAwamvEi4fNjRT+oJ /mcRzPSoDuaj0RNHI0bHuN30XLQPMYiDV7g9gWZfN20smKSCRqnuW2U+Gefp2rwIQQtG63 x04q6RJ6JwBZWzKbTl4HE0DHqKkxqCxsZE/A+g23vN3DTGTjQN3SmeMMHiGzEQ== 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 0FE301539E; Fri, 14 Jan 2022 14:20:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20EEKbt2087917; Fri, 14 Jan 2022 14:20:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20EEKbKk087916; Fri, 14 Jan 2022 14:20:37 GMT (envelope-from git) Date: Fri, 14 Jan 2022 14:20:37 GMT Message-Id: <202201141420.20EEKbKk087916@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Emmanuel Vadot Subject: git: aa5eea98b99c - stable/13 - bhyve: use physical lobits for BARs of passthru devices 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: aa5eea98b99c196646fdaea8eb9708a78627b927 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642170038; 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=6BvN2Hj8gGr6HPxh28i0WeIIdXm/PaBl52ieBBKfIsc=; b=hDmuUEBMctdvB6C1Kq/5opSSgFT9WgDUEi22rPoMIvH+F9e+fWhWHIu3CNLO3MGx6YWy5q PGG53tO9brJAotFaPzyO1ejdgDTHZB3AhMVaLupGlceB74ShctcIdkF3LnFrbazkRve3xa Mr4tV7U3cMOeCBOtA3JGF3YpNwBTOAUp8Bx5AIaIagTNNCEyP4gCr/jG5Hrns3c/7ZsklF ZE1rm9FWIsxrOFg2SgMbOPKFwOfO4/yieycAjOhqZhJgk/FERoy+vCXemRDtMJDrv/WYV4 0jU0ezFMwRVDA9n5TFsxMveIxOFP1/LCMprEYBPk9qs7vs5f1DdoQ4ALg/RnZQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642170038; a=rsa-sha256; cv=none; b=s+YaEz4qv5ORiUDw3O9O5b6texptHRUtvudwGNmJG7p2+bkgNijuBcqrVIdySzkUauBA1C U+Lu1WMIzHuR5dBMuvqFWp9FcbjEHpna79Nk9oObTS5uhQ4Xo1vW/RurCYFj0/1yLqcA+B blj3BN5GjRRbPIX8J4KJMQ/hsME+bIBam3nMgfcKQ97zCY7gzog12ps0gga/JCifWCuHkl hXjYfZli0dgyezI6CmbmnL4E2NXVneJUtLAhmIqaVrpdYxrw5n8VaojJdsvrwrJ16FbNjX 1nfAKA4+jRbkef7A4hiSvUX4dBXCYu+hck97/QrFtFHjL/VNT42ttGZXVhbL8Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=aa5eea98b99c196646fdaea8eb9708a78627b927 commit aa5eea98b99c196646fdaea8eb9708a78627b927 Author: Corvin Köhne AuthorDate: 2021-11-18 15:25:09 +0000 Commit: Emmanuel Vadot CommitDate: 2022-01-14 14:17:18 +0000 bhyve: use physical lobits for BARs of passthru devices Tell the guest whether a BAR uses prefetched memory or not for passthru devices by using the same lobits as the physical device. Reviewed by: grehan Sponsored by: Beckhoff Autmation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D32685 (cherry picked from commit e87a6f3ef284593c01e0fd3f8b5bfc1f645e5b18) --- usr.sbin/bhyve/pci_emul.c | 16 ++++++++++++---- usr.sbin/bhyve/pci_emul.h | 1 + usr.sbin/bhyve/pci_passthru.c | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c index 86a2f995126e..bd94859c4ea1 100644 --- a/usr.sbin/bhyve/pci_emul.c +++ b/usr.sbin/bhyve/pci_emul.c @@ -707,6 +707,15 @@ pci_emul_alloc_bar(struct pci_devinst *pdi, int idx, enum pcibar_type type, pdi->pi_bar[idx].type = type; pdi->pi_bar[idx].addr = addr; pdi->pi_bar[idx].size = size; + /* + * passthru devices are using same lobits as physical device they set + * this property + */ + if (pdi->pi_bar[idx].lobits != 0) { + lobits = pdi->pi_bar[idx].lobits; + } else { + pdi->pi_bar[idx].lobits = lobits; + } /* Initialize the BAR register in config space */ bar = (addr & mask) | lobits; @@ -1946,7 +1955,7 @@ pci_cfgrw(struct vmctx *ctx, int vcpu, int in, int bus, int slot, int func, case PCIBAR_IO: addr = *eax & mask; addr &= 0xffff; - bar = addr | PCIM_BAR_IO_SPACE; + bar = addr | pi->pi_bar[idx].lobits; /* * Register the new BAR value for interception */ @@ -1957,7 +1966,7 @@ pci_cfgrw(struct vmctx *ctx, int vcpu, int in, int bus, int slot, int func, break; case PCIBAR_MEM32: addr = bar = *eax & mask; - bar |= PCIM_BAR_MEM_SPACE | PCIM_BAR_MEM_32; + bar |= pi->pi_bar[idx].lobits; if (addr != pi->pi_bar[idx].addr) { update_bar_address(pi, addr, idx, PCIBAR_MEM32); @@ -1965,8 +1974,7 @@ pci_cfgrw(struct vmctx *ctx, int vcpu, int in, int bus, int slot, int func, break; case PCIBAR_MEM64: addr = bar = *eax & mask; - bar |= PCIM_BAR_MEM_SPACE | PCIM_BAR_MEM_64 | - PCIM_BAR_MEM_PREFETCH; + bar |= pi->pi_bar[idx].lobits; if (addr != (uint32_t)pi->pi_bar[idx].addr) { update_bar_address(pi, addr, idx, PCIBAR_MEM64); diff --git a/usr.sbin/bhyve/pci_emul.h b/usr.sbin/bhyve/pci_emul.h index 5b6a17119960..6eac0720f09f 100644 --- a/usr.sbin/bhyve/pci_emul.h +++ b/usr.sbin/bhyve/pci_emul.h @@ -99,6 +99,7 @@ struct pcibar { enum pcibar_type type; /* io or memory */ uint64_t size; uint64_t addr; + uint8_t lobits; }; #define PI_NAMESZ 40 diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c index 436091cbe8ee..eeb01e61b658 100644 --- a/usr.sbin/bhyve/pci_passthru.c +++ b/usr.sbin/bhyve/pci_passthru.c @@ -532,12 +532,30 @@ cfginitbar(struct vmctx *ctx, struct passthru_softc *sc) sc->psc_bar[i].type = bartype; sc->psc_bar[i].size = size; sc->psc_bar[i].addr = base; + sc->psc_bar[i].lobits = 0; /* Allocate the BAR in the guest I/O or MMIO space */ error = pci_emul_alloc_bar(pi, i, bartype, size); if (error) return (-1); + /* Use same lobits as physical bar */ + uint8_t lobits = read_config(&sc->psc_sel, PCIR_BAR(i), 0x01); + if (bartype == PCIBAR_MEM32 || bartype == PCIBAR_MEM64) { + lobits &= ~PCIM_BAR_MEM_BASE; + } else { + lobits &= ~PCIM_BAR_IO_BASE; + } + sc->psc_bar[i].lobits = lobits; + pi->pi_bar[i].lobits = lobits; + + /* The MSI-X table needs special handling */ + if (i == pci_msix_table_bar(pi)) { + error = init_msix_table(ctx, sc); + if (error) + return (-1); + } + /* * 64-bit BAR takes up two slots so skip the next one. */