From owner-svn-src-all@freebsd.org Tue Apr 19 20:43:07 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 18D45B1568D; Tue, 19 Apr 2016 20:43:07 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E4B881AFE; Tue, 19 Apr 2016 20:43:06 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u3JKh677042796; Tue, 19 Apr 2016 20:43:06 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u3JKh69L042795; Tue, 19 Apr 2016 20:43:06 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201604192043.u3JKh69L042795@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Tue, 19 Apr 2016 20:43:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r298295 - head/usr.sbin/bhyve X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Apr 2016 20:43:07 -0000 Author: jhb Date: Tue Apr 19 20:43:05 2016 New Revision: 298295 URL: https://svnweb.freebsd.org/changeset/base/298295 Log: Always emit an error message on passthru configuration errors. Previously, many errors (such as the PCI device not being attached to the ppt(4) driver) resulted in bhyve silently exiting without starting the virtual machine. Now any errors encountered when configuring a virtual slot for a PCI passthru device should be noted on stderr. Reviewed by: neel Differential Revision: https://reviews.freebsd.org/D5990 Modified: head/usr.sbin/bhyve/pci_passthru.c Modified: head/usr.sbin/bhyve/pci_passthru.c ============================================================================== --- head/usr.sbin/bhyve/pci_passthru.c Tue Apr 19 20:28:30 2016 (r298294) +++ head/usr.sbin/bhyve/pci_passthru.c Tue Apr 19 20:43:05 2016 (r298295) @@ -43,7 +43,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#include #include #include @@ -483,9 +483,9 @@ init_msix_table(struct vmctx *ctx, struc PROT_WRITE, MAP_SHARED, memfd, start + pi->pi_msix.pba_page_offset); if (pi->pi_msix.pba_page == MAP_FAILED) { - printf( - "Failed to map PBA page for MSI-X on %d/%d/%d: %s\n", - b, s, f, strerror(errno)); + warn( + "Failed to map PBA page for MSI-X on %d/%d/%d", + b, s, f); return (-1); } } @@ -559,7 +559,7 @@ cfginitbar(struct vmctx *ctx, struct pas if (bartype != PCIBAR_IO) { if (((base | size) & PAGE_MASK) != 0) { - printf("passthru device %d/%d/%d BAR %d: " + warnx("passthru device %d/%d/%d BAR %d: " "base %#lx or size %#lx not page aligned\n", sc->psc_sel.pc_bus, sc->psc_sel.pc_dev, sc->psc_sel.pc_func, i, base, size); @@ -617,11 +617,17 @@ cfginit(struct vmctx *ctx, struct pci_de sc->psc_sel.pc_dev = slot; sc->psc_sel.pc_func = func; - if (cfginitmsi(sc) != 0) + if (cfginitmsi(sc) != 0) { + warnx("failed to initialize MSI for PCI %d/%d/%d", + bus, slot, func); goto done; + } - if (cfginitbar(ctx, sc) != 0) + if (cfginitbar(ctx, sc) != 0) { + warnx("failed to initialize BARs for PCI %d/%d/%d", + bus, slot, func); goto done; + } error = 0; /* success */ done: @@ -639,34 +645,45 @@ passthru_init(struct vmctx *ctx, struct memflags = vm_get_memflags(ctx); if (!(memflags & VM_MEM_F_WIRED)) { - fprintf(stderr, "passthru requires guest memory to be wired\n"); + warnx("passthru requires guest memory to be wired"); goto done; } if (pcifd < 0) { pcifd = open(_PATH_DEVPCI, O_RDWR, 0); - if (pcifd < 0) + if (pcifd < 0) { + warn("failed to open %s", _PATH_DEVPCI); goto done; + } } if (iofd < 0) { iofd = open(_PATH_DEVIO, O_RDWR, 0); - if (iofd < 0) + if (iofd < 0) { + warn("failed to open %s", _PATH_DEVIO); goto done; + } } if (memfd < 0) { memfd = open(_PATH_MEM, O_RDWR, 0); - if (memfd < 0) + if (memfd < 0) { + warn("failed to open %s", _PATH_MEM); goto done; + } } if (opts == NULL || - sscanf(opts, "%d/%d/%d", &bus, &slot, &func) != 3) + sscanf(opts, "%d/%d/%d", &bus, &slot, &func) != 3) { + warnx("invalid passthru options"); goto done; + } - if (vm_assign_pptdev(ctx, bus, slot, func) != 0) + if (vm_assign_pptdev(ctx, bus, slot, func) != 0) { + warnx("PCI device at %d/%d/%d is not using the ppt(4) driver", + bus, slot, func); goto done; + } sc = calloc(1, sizeof(struct passthru_softc)); @@ -777,10 +794,8 @@ passthru_cfgwrite(struct vmctx *ctx, int sc->psc_sel.pc_dev, sc->psc_sel.pc_func, pi->pi_msi.addr, pi->pi_msi.msg_data, pi->pi_msi.maxmsgnum); - if (error != 0) { - printf("vm_setup_pptdev_msi error %d\r\n", errno); - exit(1); - } + if (error != 0) + err(1, "vm_setup_pptdev_msi"); return (0); } @@ -796,11 +811,8 @@ passthru_cfgwrite(struct vmctx *ctx, int pi->pi_msix.table[i].msg_data, pi->pi_msix.table[i].vector_control); - if (error) { - printf("vm_setup_pptdev_msix error " - "%d\r\n", errno); - exit(1); - } + if (error) + err(1, "vm_setup_pptdev_msix"); } } return (0);