From nobody Mon Jan 23 19:21:43 2023 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 4P10Mq51Lsz3bBGB; Mon, 23 Jan 2023 19:21:43 +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 4P10Mq4Z4qz4GBm; Mon, 23 Jan 2023 19:21:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674501703; 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=JFr+FQfs3UrnRkQ1sCM0vslPreBNDtANiiFIsAtnSNs=; b=r768mrYPsacTCGUWIXXEn+vTLqwoPPLuus/TloWHNiD2Kq2RR2I/zrb2sne3yKWyDyNymR myquZFkZWJPK1SqdFDFyFVD6g1sxF4Bh0t0GzPhT8ssbKMeACZ05gD8Ie+oWIhKQh66D4X rWh6RRAV5SxAHxwN+TiRs7SiLaA8EbgV3FqebgwGPPjUfri085V1+xxYDLNPO8/jWtpeyH wYIsMEkjjnPOJjVENdp7GPYO13N+6F6dejNHAlorF9VNtbz1IdDEyP+PG7ursz4ejNGWsA om8V2avzzxpsHH/rY60iGWd19EKgtRka7v2I/sB27YKSzLxBkLCB75ZuHNgyUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674501703; 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=JFr+FQfs3UrnRkQ1sCM0vslPreBNDtANiiFIsAtnSNs=; b=anaw9pIvotgWyV7Okrp7dsd3s8Vsupjga+U5J9hggJSkz7li+K4h32tavQdpuzwNI8X5im FNPLCOriQab2yIKPTOixqhZcJ4UlcW5r2M4uTvzcbpPQlYlhn6rwyqTDXevX+d7C/ZmDnC BzZFbAh/A3mCgQGeyFGBALmeIWYXT9/PS5r9fgieK9Ts9yYpYRBfw3B3b8oeuqcuWtIv0C zJPw8GOV8iJ0abjQPsE6+R1tPyw6KN/WEKiwXzlfqmZMrGtTAZmZTT7GM6+qCJzh79R9nB 5F+NmuH7mkdHRp9EAQf84lvDN1iYZdL7CbEZMO6AK00jQ65kSxx/nAItEeM3DA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674501703; a=rsa-sha256; cv=none; b=RMPb9mKf663hoCxIeUAyloLvHu2q5OCYvg19+NY067PGhh+qJOfY2J6zEwbazohwmnOVf8 0iDtHDQHNIA3M8Gli9DTXoFsY/MnKQzk1PU0rqv2t0kouHDCn07YgZzKmtzRGJ4SwZMMlJ cctSyT84AieV0aGMd0uvuhOOs0Th/EEOLa9xpFXRMBSswPPqo7Iz6qTPA6s/cj/6vHGYHl wLkdbBAgZ1omnExF/uCchzf3tqgoN2oAi1+3137KxIbMrZaMgY74judlIKX95NkqdycDbt 7l+SDZ/hLnGJ+9c3nU6gJFy1KIsRHytFAQkrxVU4DoyQWORyRsacwlqJ28zmQw== 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 4P10Mq3dgszgvm; Mon, 23 Jan 2023 19:21:43 +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 30NJLhev071857; Mon, 23 Jan 2023 19:21:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30NJLhfP071856; Mon, 23 Jan 2023 19:21:43 GMT (envelope-from git) Date: Mon, 23 Jan 2023 19:21:43 GMT Message-Id: <202301231921.30NJLhfP071856@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 6f5141456ed0 - main - vtblk: secondary fix for dumping 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: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6f5141456ed07a24097c2cf3d6c389bf971d78d2 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=6f5141456ed07a24097c2cf3d6c389bf971d78d2 commit 6f5141456ed07a24097c2cf3d6c389bf971d78d2 Author: Mitchell Horne AuthorDate: 2023-01-09 17:14:19 +0000 Commit: Mitchell Horne CommitDate: 2023-01-23 19:21:36 +0000 vtblk: secondary fix for dumping The code paths while dumping do not got through busdma. As such, safeguard against calling bus_dmamap_sync() with a NULL map. The x86 implementation tolerates this but others do not, resulting in a NULL dereference panic when dumping to a vtblk device on arm64, riscv, etc. Fixes: 782105f7c898 ("vtblk: Use busdma") Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D37990 --- sys/dev/virtio/block/virtio_blk.c | 46 ++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/sys/dev/virtio/block/virtio_blk.c b/sys/dev/virtio/block/virtio_blk.c index 052017251c22..0e66cd3c89db 100644 --- a/sys/dev/virtio/block/virtio_blk.c +++ b/sys/dev/virtio/block/virtio_blk.c @@ -1126,15 +1126,17 @@ vtblk_request_execute_cb(void * callback_arg, bus_dma_segment_t * segs, sglist_append(sg, &req->vbr_ack, sizeof(uint8_t)); readable = sg->sg_nseg - writable; - switch (bp->bio_cmd) { - case BIO_READ: - bus_dmamap_sync(sc->vtblk_dmat, req->vbr_mapp, - BUS_DMASYNC_PREREAD); - break; - case BIO_WRITE: - bus_dmamap_sync(sc->vtblk_dmat, req->vbr_mapp, - BUS_DMASYNC_PREWRITE); - break; + if (req->vbr_mapp != NULL) { + switch (bp->bio_cmd) { + case BIO_READ: + bus_dmamap_sync(sc->vtblk_dmat, req->vbr_mapp, + BUS_DMASYNC_PREREAD); + break; + case BIO_WRITE: + bus_dmamap_sync(sc->vtblk_dmat, req->vbr_mapp, + BUS_DMASYNC_PREWRITE); + break; + } } error = virtqueue_enqueue(vq, req, sg, readable, writable); @@ -1191,17 +1193,21 @@ vtblk_queue_completed(struct vtblk_softc *sc, struct bio_queue *queue) } bp = req->vbr_bp; - 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; + 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);