From owner-dev-commits-src-all@freebsd.org Sat Aug 14 15:00:57 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id DFF7866E0B8; Sat, 14 Aug 2021 15:00:57 +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 4Gn3X93MCxz3sZh; Sat, 14 Aug 2021 15:00:57 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 5B89624383; Sat, 14 Aug 2021 15:00:57 +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 17EF0vp8002229; Sat, 14 Aug 2021 15:00:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17EF0vAo002228; Sat, 14 Aug 2021 15:00:57 GMT (envelope-from git) Date: Sat, 14 Aug 2021 15:00:57 GMT Message-Id: <202108141500.17EF0vAo002228@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 42375556e5b2 - main - bhyve: Use pci(4) to access I/O port BARs MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 42375556e5b2e68746d999b43d124040b6affb91 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 15:00:58 -0000 The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=42375556e5b2e68746d999b43d124040b6affb91 commit 42375556e5b2e68746d999b43d124040b6affb91 Author: Mark Johnston AuthorDate: 2021-08-14 14:42:34 +0000 Commit: Mark Johnston CommitDate: 2021-08-14 14:59:04 +0000 bhyve: Use pci(4) to access I/O port BARs This removes the dependency on /dev/io. PR: 251046 Reviewed by: jhb MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D31308 --- usr.sbin/bhyve/pci_passthru.c | 65 ++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c index 9028369217d4..2c6a2ebd8dd9 100644 --- a/usr.sbin/bhyve/pci_passthru.c +++ b/usr.sbin/bhyve/pci_passthru.c @@ -69,10 +69,6 @@ __FBSDID("$FreeBSD$"); #define _PATH_DEVPCI "/dev/pci" #endif -#ifndef _PATH_DEVIO -#define _PATH_DEVIO "/dev/io" -#endif - #ifndef _PATH_MEM #define _PATH_MEM "/dev/mem" #endif @@ -83,7 +79,6 @@ __FBSDID("$FreeBSD$"); #define MSIX_CAPLEN 12 static int pcifd = -1; -static int iofd = -1; static int memfd = -1; struct passthru_softc { @@ -649,8 +644,8 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) const char *value; #ifndef WITHOUT_CAPSICUM cap_rights_t rights; - cap_ioctl_t pci_ioctls[] = { PCIOCREAD, PCIOCWRITE, PCIOCGETBAR }; - cap_ioctl_t io_ioctls[] = { IODEV_PIO }; + cap_ioctl_t pci_ioctls[] = + { PCIOCREAD, PCIOCWRITE, PCIOCGETBAR, PCIOCBARIO }; #endif sc = NULL; @@ -681,21 +676,6 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) errx(EX_OSERR, "Unable to apply rights for sandbox"); #endif - if (iofd < 0) { - iofd = open(_PATH_DEVIO, O_RDWR, 0); - if (iofd < 0) { - warn("failed to open %s", _PATH_DEVIO); - return (error); - } - } - -#ifndef WITHOUT_CAPSICUM - if (caph_rights_limit(iofd, &rights) == -1) - errx(EX_OSERR, "Unable to apply rights for sandbox"); - if (caph_ioctls_limit(iofd, io_ioctls, nitems(io_ioctls)) == -1) - errx(EX_OSERR, "Unable to apply rights for sandbox"); -#endif - if (memfd < 0) { memfd = open(_PATH_MEM, O_RDWR, 0); if (memfd < 0) { @@ -910,7 +890,7 @@ passthru_write(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, int baridx, uint64_t offset, int size, uint64_t value) { struct passthru_softc *sc; - struct iodev_pio_req pio; + struct pci_bar_ioreq pio; sc = pi->pi_arg; @@ -918,13 +898,18 @@ passthru_write(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, int baridx, msix_table_write(ctx, vcpu, sc, offset, size, value); } else { assert(pi->pi_bar[baridx].type == PCIBAR_IO); - bzero(&pio, sizeof(struct iodev_pio_req)); - pio.access = IODEV_PIO_WRITE; - pio.port = sc->psc_bar[baridx].addr + offset; - pio.width = size; - pio.val = value; - - (void)ioctl(iofd, IODEV_PIO, &pio); + assert(size == 1 || size == 2 || size == 4); + assert(offset <= UINT32_MAX && offset + size <= UINT32_MAX); + + bzero(&pio, sizeof(pio)); + pio.pbi_sel = sc->psc_sel; + pio.pbi_op = PCIBARIO_WRITE; + pio.pbi_bar = baridx; + pio.pbi_offset = (uint32_t)offset; + pio.pbi_width = size; + pio.pbi_value = (uint32_t)value; + + (void)ioctl(pcifd, PCIOCBARIO, &pio); } } @@ -933,7 +918,7 @@ passthru_read(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, int baridx, uint64_t offset, int size) { struct passthru_softc *sc; - struct iodev_pio_req pio; + struct pci_bar_ioreq pio; uint64_t val; sc = pi->pi_arg; @@ -942,15 +927,19 @@ passthru_read(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, int baridx, val = msix_table_read(sc, offset, size); } else { assert(pi->pi_bar[baridx].type == PCIBAR_IO); - bzero(&pio, sizeof(struct iodev_pio_req)); - pio.access = IODEV_PIO_READ; - pio.port = sc->psc_bar[baridx].addr + offset; - pio.width = size; - pio.val = 0; + assert(size == 1 || size == 2 || size == 4); + assert(offset <= UINT32_MAX && offset + size <= UINT32_MAX); + + bzero(&pio, sizeof(pio)); + pio.pbi_sel = sc->psc_sel; + pio.pbi_op = PCIBARIO_READ; + pio.pbi_bar = baridx; + pio.pbi_offset = (uint32_t)offset; + pio.pbi_width = size; - (void)ioctl(iofd, IODEV_PIO, &pio); + (void)ioctl(pcifd, PCIOCBARIO, &pio); - val = pio.val; + val = pio.pbi_value; } return (val);