From nobody Thu Jul 04 14:27:42 2024 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 4WFJrt3wfBz5QGZT; Thu, 04 Jul 2024 14:27:42 +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 4WFJrt3RP6z4bJt; Thu, 4 Jul 2024 14:27:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720103262; 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=BrC7MEE+zOK/XofsS0tD6UP+3gzqe+PQj31rpiGtFco=; b=e9EJxMv7JjMirzOFkT0KjB9+lab7kE3JoX0NaUILjFjPzhasWJv1FyQ6zqzbwgI3VtQ8by QoZHoP3PyBkboxTnY0CNSChW2S86qmRvoiZ6+F1cqwTaLaDEwE7KF4yMlE1Q5F6a3lJS+w 9/6M1fwjLVN6Gj0MhBo8ZNhdg8mXQR06lBKyhX3SzdVLW/bgYei0hQmnqZkvD3P4Qat/0o gPlkwLxtuSl89xFKDN/xGthCRpg7BDAI5yFt8KmE1SOVGRIRFNd+7U/dOUKkA37d2sudUx SUCaqPiikmypDgOSrx58Psv+fTxawMNucwwxcxDga8ck9bW0cZ7cZO27aEvzVA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1720103262; a=rsa-sha256; cv=none; b=VmQdcuKSNTeVgC4JSvbLdLwuSikFPb+zzBMqQciE4bX88h1tw2sul1F21wXvbYPZthprPL XnMfNuKwpkbMs5aKMqeuG2ubUHUTY0PGLwiwcw8B9yorScpGoOPedsApDulV0SBelVbsjh dACwLeZ5ZWHePIIVtj5emk24lUu4Z4pf4ELwNiYihKlIAfjx67LAXjfet8DvprqiqPqhUO OMbBLHhaDrCb2monbvJIA+z1Tl90+s2vRyLX87YH89zbvt9a18o2VTzS/7hInw9gexpq7Q Nw8DK6UgM+EDEMSjonX1M4E1pu0RQB7Ws/JyeJVTZ7eSd1ap18tLyAR8JwBMgg== 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=1720103262; 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=BrC7MEE+zOK/XofsS0tD6UP+3gzqe+PQj31rpiGtFco=; b=rT/KZ9p/rU/+yXHdd0BWkGKgtQdyr0A30h2MqHtK881RUPRPR7N0ONDdNEm7kOffE8qFb8 QRFudWS/A/u1H7rGe7DoF0mHR3zJdrWjJuV8rq0b4htD4xa17W0dsG30JBRVQppQBS6Qea V7zniV941kZwYQ3grqBKtO06SPJN+PjmV34xGG8PKLMmDQNAGYdSCh/xxa8thZtP1csxZc HUsbBNotYraNbFCYi1zaEv5MarS6FG9v8Pn5BWVjV3q1mYxH/R2gbG9RY93Ik4BRe80OuS mWN3UmNWElf27fMFxgiKklxlD0uL2HcAncht0bEP6yt+H61SkNOZ90fDkkAp1Q== 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 4WFJrt2wy6zHPB; Thu, 4 Jul 2024 14:27:42 +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 464ERghb078484; Thu, 4 Jul 2024 14:27:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 464ERgCZ078481; Thu, 4 Jul 2024 14:27:42 GMT (envelope-from git) Date: Thu, 4 Jul 2024 14:27:42 GMT Message-Id: <202407041427.464ERgCZ078481@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: b1dd06703274 - main - vtblk: Invoke busdma completion callbacks when polling 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-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: b1dd067032747c12ae237d2f7aeed6d81285c121 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b1dd067032747c12ae237d2f7aeed6d81285c121 commit b1dd067032747c12ae237d2f7aeed6d81285c121 Author: Mark Johnston AuthorDate: 2024-07-04 14:15:33 +0000 Commit: Mark Johnston CommitDate: 2024-07-04 14:15:33 +0000 vtblk: Invoke busdma completion callbacks when polling vtblk_poll_request() is used for kernel dumps and for fetching the block device's identifier string during device probing. In the latter case, it was not calling bus_dmamap_sync() after completing the I/O, but this is required in general. Thus: - Factor out per-request code from vtblk_queue_completed(). - Use it in vtblk_poll_request() once virtqueue_poll() finishes. - While here, assert that virtqueue_poll() returns the request that we expect. Reported by: KMSAN Fixes: 782105f7c898 ("vtblk: Use busdma") Reviewed by: cperciva, imp Sponsored by: Klara, Inc. Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D45665 --- sys/dev/virtio/block/virtio_blk.c | 66 +++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/sys/dev/virtio/block/virtio_blk.c b/sys/dev/virtio/block/virtio_blk.c index d7fa903936a1..d3eb3cf97831 100644 --- a/sys/dev/virtio/block/virtio_blk.c +++ b/sys/dev/virtio/block/virtio_blk.c @@ -1177,6 +1177,35 @@ vtblk_request_error(struct vtblk_request *req) return (error); } +static struct bio * +vtblk_queue_complete_one(struct vtblk_softc *sc, struct vtblk_request *req) +{ + struct bio *bp; + + if (sc->vtblk_req_ordered != NULL) { + MPASS(sc->vtblk_req_ordered == req); + sc->vtblk_req_ordered = NULL; + } + + bp = req->vbr_bp; + if (req->vbr_mapp != NULL) { + switch (bp->bio_cmd) { + case BIO_READ: + bus_dmamap_sync(sc->vtblk_dmat, req->vbr_mapp, + BUS_DMASYNC_POSTREAD); + bus_dmamap_unload(sc->vtblk_dmat, req->vbr_mapp); + break; + case BIO_WRITE: + bus_dmamap_sync(sc->vtblk_dmat, req->vbr_mapp, + BUS_DMASYNC_POSTWRITE); + bus_dmamap_unload(sc->vtblk_dmat, req->vbr_mapp); + break; + } + } + bp->bio_error = vtblk_request_error(req); + return (bp); +} + static void vtblk_queue_completed(struct vtblk_softc *sc, struct bio_queue *queue) { @@ -1184,31 +1213,9 @@ vtblk_queue_completed(struct vtblk_softc *sc, struct bio_queue *queue) struct bio *bp; while ((req = virtqueue_dequeue(sc->vtblk_vq, NULL)) != NULL) { - if (sc->vtblk_req_ordered != NULL) { - MPASS(sc->vtblk_req_ordered == req); - sc->vtblk_req_ordered = NULL; - } + bp = vtblk_queue_complete_one(sc, req); - bp = req->vbr_bp; - if (req->vbr_mapp != NULL) { - switch (bp->bio_cmd) { - case BIO_READ: - bus_dmamap_sync(sc->vtblk_dmat, req->vbr_mapp, - BUS_DMASYNC_POSTREAD); - bus_dmamap_unload(sc->vtblk_dmat, - req->vbr_mapp); - break; - case BIO_WRITE: - bus_dmamap_sync(sc->vtblk_dmat, req->vbr_mapp, - BUS_DMASYNC_POSTWRITE); - bus_dmamap_unload(sc->vtblk_dmat, - req->vbr_mapp); - break; - } - } - bp->bio_error = vtblk_request_error(req); TAILQ_INSERT_TAIL(queue, bp, bio_queue); - vtblk_request_enqueue(sc, req); } } @@ -1412,8 +1419,6 @@ vtblk_ident(struct vtblk_softc *sc) error = vtblk_poll_request(sc, req); VTBLK_UNLOCK(sc); - vtblk_request_enqueue(sc, req); - if (error) { device_printf(sc->vtblk_dev, "error getting device identifier: %d\n", error); @@ -1423,7 +1428,9 @@ vtblk_ident(struct vtblk_softc *sc) static int vtblk_poll_request(struct vtblk_softc *sc, struct vtblk_request *req) { + struct vtblk_request *req1 __diagused; struct virtqueue *vq; + struct bio *bp; int error; vq = sc->vtblk_vq; @@ -1436,13 +1443,18 @@ vtblk_poll_request(struct vtblk_softc *sc, struct vtblk_request *req) return (error); virtqueue_notify(vq); - virtqueue_poll(vq, NULL); + req1 = virtqueue_poll(vq, NULL); + KASSERT(req == req1, + ("%s: polling completed %p not %p", __func__, req1, req)); - error = vtblk_request_error(req); + bp = vtblk_queue_complete_one(sc, req); + error = bp->bio_error; if (error && bootverbose) { device_printf(sc->vtblk_dev, "%s: IO error: %d\n", __func__, error); } + if (req != &sc->vtblk_dump_request) + vtblk_request_enqueue(sc, req); return (error); }