From nobody Fri May 03 00:15:59 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 4VVrtm1bXCz5KJtK; Fri, 3 May 2024 00:16:00 +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 4VVrtl69Xrz4Qkb; Fri, 3 May 2024 00:15:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714695360; 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=rSIihZsbxBClWFI1pby7PXxG2iGXrsnaZwEnWZ2BwhA=; b=qbHaYSnV0AvXxxYFRlcBfKwPC/r/l4dJL3v5/C9NX+xrZ83qhzFZcIemefWX6uSa9HKkaY U1dlRPx6aLROjnM+rDb8BKFcg4sOYV5aUlHQTd9UN1xB4cgA8lwAMIVvGE9z+thj8XNA5w ynaNQEPhCUVBKIl/c5o94ayDYaqoXTsvBn/C1NDg1cBcAz47bB7/DjqouWDNdoo17S4QhY nZW8lH9PwReFN9wVI2TjLyChddpY7nb/rzcA/nkZf7Uq3m3tNAWI2ZF6EwXXMXQuNFyxXh EJD5DiwM9439mhhppr5GNFJPzkkFwFzcCe+dESYMRs27gLcFiPuqpb9O41kBEw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1714695359; a=rsa-sha256; cv=none; b=SoJfk8jaYJBJRVFbBDrsLt+4sEYMq2OKYlioWTwgrIOpD6AuGRQcLcClrToJLriGAzdHiS dvDPbU7bTkaLc6Hc2E+vtsDT9Cbm1pT28Qj24ydjoroaWsg7dJHrXfkyP/uuQNZIH25gD4 Qe7HRcQrSjXDK+qlajR9nUK/OQdFkDWW8gJN55c/CbhZc2U0zOK8faltZVWKip9uE1kIvU PJOG5J3JUsKBcgrILOC+amB3VmWWcrilL08mDw0n6/gXVvGbGCJC+OS1Dr1KBicp4Ut4a+ TNO70036Fdggz1q3QUr1j+gDiYrWS320LAfwEheQo9kmkiTeyjXGhgXn6aJhFA== 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=1714695359; 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=rSIihZsbxBClWFI1pby7PXxG2iGXrsnaZwEnWZ2BwhA=; b=Byzo3D569J9VyhYy0irt1YafQLwmgdcM+rsVP4mPNCOiqfw/0aBlSuF3qqZF9zor8BYgL7 Z0ljMKINYgHwRtO60axF1u5Led2/1RL1c/81Qx39YPn9i8aQQh9x5I+ZC3ZHZ/pe0qRiO+ VURMCZ28u6TJYMNDBEfKmGhysoN/zDN46H+e19Z3ftGQZCsI57a783B29+C4SG43+ZEWjY iNlZYNAeiThllw6ViZV81hYKgnEX557tdte1EYAtuzZE2GRFOiLttYPn4V7aDnHVO2CaBF X/3sAHtWhjLkv3RbnMuAM21jJRiy9dJb2xWs6wXoBJjxIMR8dz3idfj5M9oOSA== 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 4VVrtl5nMJzP16; Fri, 3 May 2024 00:15:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 4430Fxwr079692; Fri, 3 May 2024 00:15:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4430FxFc079689; Fri, 3 May 2024 00:15:59 GMT (envelope-from git) Date: Fri, 3 May 2024 00:15:59 GMT Message-Id: <202405030015.4430FxFc079689@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 105333f1d6ee - main - ctl: Add assertions in SCSI-only paths 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 105333f1d6ee4c736e4d9101f8a90bea57f62425 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=105333f1d6ee4c736e4d9101f8a90bea57f62425 commit 105333f1d6ee4c736e4d9101f8a90bea57f62425 Author: John Baldwin AuthorDate: 2024-05-02 23:31:59 +0000 Commit: John Baldwin CommitDate: 2024-05-02 23:31:59 +0000 ctl: Add assertions in SCSI-only paths Assert that only SCSI I/O requests are passed in various places that assume a SCSI I/O request (that is, places that access fields in io->scsiio directly). Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D44847 --- sys/cam/ctl/ctl.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c index 61c80d7cc1b3..59e8cba1b671 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -617,6 +617,8 @@ ctl_ha_datamove(union ctl_io *io) uint32_t sg_entries_sent; int do_sg_copy, i, j; + CTL_IO_ASSERT(io, SCSI); + memset(&msg.dt, 0, sizeof(msg.dt)); msg.hdr.msg_type = CTL_MSG_DATAMOVE; msg.hdr.original_sc = io->io_hdr.remote_io; @@ -1528,6 +1530,8 @@ ctl_isc_event_handler(ctl_ha_channel channel, ctl_ha_event event, int param) /* XXX KDM do something here */ break; } + CTL_IO_ASSERT(io, SCSI); + io->io_hdr.msg_type = CTL_MSG_DATAMOVE; io->io_hdr.flags |= CTL_FLAG_IO_ACTIVE; /* @@ -1601,6 +1605,8 @@ ctl_isc_event_handler(ctl_ha_channel channel, ctl_ha_event event, int param) * back to the initiator. */ io = msg->hdr.serializing_sc; + CTL_IO_ASSERT(io, SCSI); + io->io_hdr.msg_type = CTL_MSG_DATAMOVE_DONE; io->io_hdr.flags &= ~CTL_FLAG_DMA_INPROG; io->io_hdr.flags |= CTL_FLAG_IO_ACTIVE; @@ -2442,6 +2448,8 @@ ctl_ioctl_fill_ooa(struct ctl_lun *lun, uint32_t *cur_fill_num, union ctl_io *io = (union ctl_io *)ioh; struct ctl_ooa_entry *entry; + CTL_IO_ASSERT(io, SCSI); + /* * If we've got more than we can fit, just count the * remaining entries. @@ -5543,6 +5551,8 @@ ctl_write_same_cont(union ctl_io *io) struct ctl_lba_len_flags *lbalen; int retval; + CTL_IO_ASSERT(io, SCSI); + ctsio = &io->scsiio; ctsio->io_hdr.status = CTL_STATUS_NONE; lbalen = (struct ctl_lba_len_flags *) @@ -5888,6 +5898,8 @@ ctl_do_mode_select(union ctl_io *io) uint16_t *len_left, *len_used; int retval, i; + CTL_IO_ASSERT(io, SCSI); + ctsio = &io->scsiio; page_index = NULL; page_len = 0; @@ -8801,6 +8813,8 @@ ctl_cnw_cont(union ctl_io *io) struct ctl_lba_len_flags *lbalen; int retval; + CTL_IO_ASSERT(io, SCSI); + ctsio = &io->scsiio; ctsio->io_hdr.status = CTL_STATUS_NONE; ctsio->io_hdr.flags &= ~CTL_FLAG_IO_CONT; @@ -10841,6 +10855,8 @@ static ctl_action ctl_check_for_blockage(struct ctl_lun *lun, union ctl_io *pending_io, const uint8_t *serialize_row, union ctl_io *ooa_io) { + CTL_IO_ASSERT(pending_io, SCSI); + CTL_IO_ASSERT(ooa_io, SCSI); /* * The initiator attempted multiple untagged commands at the same @@ -10949,6 +10965,8 @@ ctl_check_ooa(struct ctl_lun *lun, union ctl_io *pending_io, const uint8_t *serialize_row; ctl_action action; + CTL_IO_ASSERT(pending_io, SCSI); + mtx_assert(&lun->lun_lock, MA_OWNED); /* @@ -11006,6 +11024,8 @@ ctl_try_unblock_io(struct ctl_lun *lun, union ctl_io *io, bool skip) union ctl_ha_msg msg_info; ctl_action action; + CTL_IO_ASSERT(io, SCSI); + mtx_assert(&lun->lun_lock, MA_OWNED); if (io->io_hdr.blocker == NULL) @@ -11246,6 +11266,8 @@ bailout: static void ctl_failover_io(union ctl_io *io, int have_lock) { + CTL_IO_ASSERT(io, SCSI); + ctl_set_busy(&io->scsiio); ctl_done(io); } @@ -11813,6 +11835,7 @@ ctl_abort_tasks_lun(struct ctl_lun *lun, uint32_t targ_port, uint32_t init_id, if (!other_sc && !(lun->flags & CTL_LUN_PRIMARY_SC)) { union ctl_ha_msg msg_info; + CTL_IO_ASSERT(xio, SCSI); msg_info.hdr.nexus = xioh->nexus; msg_info.task.task_action = CTL_TASK_ABORT_TASK; msg_info.task.tag_num = xio->scsiio.tag_num; @@ -11953,6 +11976,8 @@ ctl_abort_task(union ctl_io *io) */ LIST_FOREACH(xioh, &lun->ooa_queue, ooa_links) { union ctl_io *xio = (union ctl_io *)xioh; + + CTL_IO_ASSERT(xio, SCSI); if ((xioh->nexus.targ_port != io->io_hdr.nexus.targ_port) || (xioh->nexus.initid != io->io_hdr.nexus.initid) || (xioh->flags & CTL_FLAG_ABORT)) @@ -12024,6 +12049,8 @@ ctl_query_task(union ctl_io *io, int task_set) mtx_unlock(&softc->ctl_lock); LIST_FOREACH(xioh, &lun->ooa_queue, ooa_links) { union ctl_io *xio = (union ctl_io *)xioh; + + CTL_IO_ASSERT(xio, SCSI); if ((xioh->nexus.targ_port != io->io_hdr.nexus.targ_port) || (xioh->nexus.initid != io->io_hdr.nexus.initid) || (xioh->flags & CTL_FLAG_ABORT)) @@ -12137,6 +12164,8 @@ ctl_handle_isc(union ctl_io *io) const struct ctl_cmd_entry *entry; uint32_t targ_lun; + CTL_IO_ASSERT(io, SCSI); + targ_lun = io->io_hdr.nexus.targ_mapped_lun; switch (io->io_hdr.msg_type) { case CTL_MSG_SERIALIZE: @@ -12272,6 +12301,8 @@ ctl_inject_error(struct ctl_lun *lun, union ctl_io *io) { struct ctl_error_desc *desc, *desc2; + CTL_IO_ASSERT(io, SCSI); + mtx_assert(&lun->lun_lock, MA_OWNED); STAILQ_FOREACH_SAFE(desc, &lun->error_list, links, desc2) { @@ -12487,6 +12518,8 @@ ctl_send_datamove_done(union ctl_io *io, int have_lock) struct bintime cur_bt; #endif + CTL_IO_ASSERT(io, SCSI); + memset(&msg, 0, sizeof(msg)); msg.hdr.msg_type = CTL_MSG_DATAMOVE_DONE; msg.hdr.original_sc = io; @@ -12529,6 +12562,7 @@ ctl_datamove_remote_write_cb(struct ctl_ha_dt_req *rq) uint32_t i; io = rq->context; + CTL_IO_ASSERT(io, SCSI); if (rq->ret != CTL_HA_STATUS_SUCCESS) { printf("%s: ISC DMA write failed with error %d", __func__, @@ -12573,6 +12607,8 @@ ctl_datamove_remote_write(union ctl_io *io) int retval; void (*fe_datamove)(union ctl_io *io); + CTL_IO_ASSERT(io, SCSI); + /* * - Get the data from the host/HBA into local memory. * - DMA memory from the local controller to the remote controller. @@ -12601,6 +12637,8 @@ ctl_datamove_remote_dm_read_cb(union ctl_io *io, bool samethr) { uint32_t i; + CTL_IO_ASSERT(io, SCSI); + for (i = 0; i < io->scsiio.kern_sg_entries; i++) free(CTL_LSGLT(io)[i].addr, M_CTL); free(CTL_RSGL(io), M_CTL); @@ -12623,6 +12661,7 @@ ctl_datamove_remote_read_cb(struct ctl_ha_dt_req *rq) void (*fe_datamove)(union ctl_io *io); io = rq->context; + CTL_IO_ASSERT(io, SCSI); if (rq->ret != CTL_HA_STATUS_SUCCESS) { printf("%s: ISC DMA read failed with error %d\n", __func__, @@ -12657,6 +12696,8 @@ ctl_datamove_remote_sgl_setup(union ctl_io *io) int retval; int i; + CTL_IO_ASSERT(io, SCSI); + retval = 0; local_sglist = CTL_LSGL(io); len_to_go = io->scsiio.kern_data_len; @@ -12694,6 +12735,8 @@ ctl_datamove_remote_xfer(union ctl_io *io, unsigned command, rq = ctl_dt_req_alloc(); + CTL_IO_ASSERT(io, SCSI); + /* * If we failed to allocate the request, and if the DMA didn't fail * anyway, set busy status. This is just a resource allocation @@ -12845,6 +12888,7 @@ ctl_datamove_remote_read(union ctl_io *io) static void ctl_datamove_remote(union ctl_io *io) { + CTL_IO_ASSERT(io, SCSI); mtx_assert(&((struct ctl_softc *)CTL_SOFTC(io))->ctl_lock, MA_NOTOWNED); @@ -13104,6 +13148,7 @@ ctl_queue_sense(union ctl_io *io) uint32_t initidx, p, targ_lun; CTL_DEBUG_PRINT(("ctl_queue_sense\n")); + CTL_IO_ASSERT(io, SCSI); targ_lun = ctl_lun_map_from_port(port, io->io_hdr.nexus.targ_lun);