From nobody Thu Oct 27 14:49:28 2022 X-Original-To: dev-commits-src-main@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 4MypVJ4xRWz4gDKv; Thu, 27 Oct 2022 14:49:28 +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 4MypVJ4Pq4z3Y8L; Thu, 27 Oct 2022 14:49:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666882168; 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=JxiS7nGHz/lHrxjRJk5tC+Wbgf2c+L79qUFEEs790Mg=; b=HJ4/iBzYJ9dPOry9/9n1IDyRURrOzvTzqUnDWiZbuCdO3M64QED1fyV/WQnf52td/WWlQB yJuGsbEg5QuTE7Wi6bfAqp7Q52efDxbAx7wGj41l3GVh7fPy6Wqq6jkBykgg6zquDs9i79 4/Z4tZv1TZj9IRJ5fn2sAdofnw40o/M/E2Z26M+S+wgNSaM9YdWZlNNtUeRssu2eq5D6xG zx1+oBZZLroDRfZXP7Th5UFoNUvO7J6a9Se8d4XOKUlCOz6hZ1HdxbdvoMjXKLHi6mswwE JlpkEM1raQHn10Q4WqISIEenVPRPmsyvcA75lXqNcPI+zBVI1ykAcRFvfBT+zg== 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 4MypVJ37rKz11KV; Thu, 27 Oct 2022 14:49:28 +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 29REnSB7049107; Thu, 27 Oct 2022 14:49:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29REnSPF049106; Thu, 27 Oct 2022 14:49:28 GMT (envelope-from git) Date: Thu, 27 Oct 2022 14:49:28 GMT Message-Id: <202210271449.29REnSPF049106@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: a309ad7bd123 - main - bhyve: Fix an apparent pointer arithmetic bug in the xhci emulation List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org 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: a309ad7bd1230353da3d7c98afd850c1e9427944 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666882168; 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=JxiS7nGHz/lHrxjRJk5tC+Wbgf2c+L79qUFEEs790Mg=; b=UY5GwmEzvOT/Cjg39L9E/CLCF7BZcBHxm0JZKg72eKNJ0YX8F3zRTSRYlducxjwRf0+xFy /NXw2QvPny/sLMt6H3FZk8J5/lSIb+NaLj+57zR/FvKoitQZguS6oy12OthgZuKmcHVW4D aW76WTaZy/MtZgOwDLvacBtUMckRmwij2M6aCch64vsIsb1KYs+UfN+70VA/o3C7JQupJ2 ohbKn23uVQx04uGS6XXP5K0iYm8Y95NvrvxZU3VW6JeP/WC3zvyvZYdg5Cn96fOZ86mS4E iXtGmp3FMAMttMd0TI8inRjcB9y4oRnSbPgoSWXtgICdyxZysG0jnpbD3A6SFw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666882168; a=rsa-sha256; cv=none; b=r2l5OFDZgYW+PQkEFXfVCVmpwR6rZ8DCmsdb4xRY0ib52gsvmYYiqUVcU2Q23R/E8q6aPl 5Dcf3+XQRhASWXwUWxZGmXwbkuI0jj6l4KzM5ZWZy2Arf34c9BJxP1ZxtP6HzBnt9toQaN ydtXH4Vzli1c0pqy7VQGZep498xoZbXS6h489eUa9s0BIOoAlRE97f0gr+zKvTX8fJvWr3 Pe27FAJ/hwjDYJk5gjkvVVzEEZ6j/bmf/ATe/Bfc4og2ac1LHHWsJbBNu7FlqjZHrxRybi JoecPXl8CUUFW52WwFGQL3qkAZ4+xxTmvwZuTH6HgtRAqn74LiDPRwdcNfS8Ag== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=a309ad7bd1230353da3d7c98afd850c1e9427944 commit a309ad7bd1230353da3d7c98afd850c1e9427944 Author: Mark Johnston AuthorDate: 2022-10-27 14:46:53 +0000 Commit: Mark Johnston CommitDate: 2022-10-27 14:48:55 +0000 bhyve: Fix an apparent pointer arithmetic bug in the xhci emulation Also remove the out-parameter of pci_xhci_find_stream(), since it's unused by all callers. MFC after: 1 week Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D37118 --- usr.sbin/bhyve/pci_xhci.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/usr.sbin/bhyve/pci_xhci.c b/usr.sbin/bhyve/pci_xhci.c index 5f12762dfeb1..8eff332099df 100644 --- a/usr.sbin/bhyve/pci_xhci.c +++ b/usr.sbin/bhyve/pci_xhci.c @@ -1183,8 +1183,7 @@ done: static uint32_t pci_xhci_find_stream(struct pci_xhci_softc *sc, struct xhci_endp_ctx *ep, - struct pci_xhci_dev_ep *devep, uint32_t streamid, - struct xhci_stream_ctx **osctx) + struct pci_xhci_dev_ep *devep, uint32_t streamid) { struct xhci_stream_ctx *sctx; @@ -1203,12 +1202,11 @@ pci_xhci_find_stream(struct pci_xhci_softc *sc, struct xhci_endp_ctx *ep, if (streamid > devep->ep_MaxPStreams) return (XHCI_TRB_ERROR_STREAM_TYPE); - sctx = XHCI_GADDR(sc, ep->qwEpCtx2 & ~0xFUL) + streamid; + sctx = (struct xhci_stream_ctx *)XHCI_GADDR(sc, ep->qwEpCtx2 & ~0xFUL) + + streamid; if (!XHCI_SCTX_0_SCT_GET(sctx->qwSctx0)) return (XHCI_TRB_ERROR_STREAM_TYPE); - *osctx = sctx; - return (XHCI_TRB_ERROR_SUCCESS); } @@ -1263,12 +1261,8 @@ pci_xhci_cmd_set_tr(struct pci_xhci_softc *sc, uint32_t slot, streamid = XHCI_TRB_2_STREAM_GET(trb->dwTrb2); if (devep->ep_MaxPStreams > 0) { - struct xhci_stream_ctx *sctx; - - sctx = NULL; - cmderr = pci_xhci_find_stream(sc, ep_ctx, devep, streamid, - &sctx); - if (sctx != NULL) { + cmderr = pci_xhci_find_stream(sc, ep_ctx, devep, streamid); + if (cmderr == XHCI_TRB_ERROR_SUCCESS) { assert(devep->ep_sctx != NULL); devep->ep_sctx[streamid].qwSctx0 = trb->qwTrb0; @@ -1910,6 +1904,7 @@ pci_xhci_device_doorbell(struct pci_xhci_softc *sc, uint32_t slot, struct xhci_trb *trb; uint64_t ringaddr; uint32_t ccs; + int error; DPRINTF(("pci_xhci doorbell slot %u epid %u stream %u", slot, epid, streamid)); @@ -1949,8 +1944,6 @@ pci_xhci_device_doorbell(struct pci_xhci_softc *sc, uint32_t slot, /* get next trb work item */ if (devep->ep_MaxPStreams != 0) { - struct xhci_stream_ctx *sctx; - /* * Stream IDs of 0, 65535 (any stream), and 65534 * (prime) are invalid. @@ -1960,10 +1953,10 @@ pci_xhci_device_doorbell(struct pci_xhci_softc *sc, uint32_t slot, return; } - sctx = NULL; - pci_xhci_find_stream(sc, ep_ctx, devep, streamid, &sctx); - if (sctx == NULL) { - DPRINTF(("pci_xhci: invalid stream %u", streamid)); + error = pci_xhci_find_stream(sc, ep_ctx, devep, streamid); + if (error != XHCI_TRB_ERROR_SUCCESS) { + DPRINTF(("pci_xhci: invalid stream %u: %d", + streamid, error)); return; } sctx_tr = &devep->ep_sctx_trbs[streamid];