From nobody Fri Jan 28 21:09:51 2022 X-Original-To: dev-commits-src-all@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 162FA19816F9; Fri, 28 Jan 2022 21:09:52 +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 4Jlqpm03dmz4rsX; Fri, 28 Jan 2022 21:09:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643404192; 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=fZbADQqbLTBVGFQUuCPHCfwdBnYqLU8UhJmBTKhONIM=; b=ZSR0r3CJSerMzp1eN7dgQp77gB3rY9/SdZIJsTMqqbFYKzz1OI8ayus86yTpWG9IIiRw+L 8nzAjAXronZ5MI7ztglRHTglJiCjYaPgrMHShnHSkOcGqKUMl7pwV/THkg+s+2kq2tYQPk bYTwu0DahGWeL4DIItuZgre9q3XHfUko2LeC6JS7c2mV4SScV8wif2Dx+EOp0GcccJQn9p xGsCWe4ufoaOSADdzhr8jkh4K9ydP7qu7efZLef/Nnjg71yF64QWfBC/l+H1bR/VNqNLgl 19dYpoc/ZUQTx425unSyaiuGMs0FdQ/KraZ/OdvqxSJwv1uJ4ZdO/Pqq1ZaOyw== 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 D0EEED60; Fri, 28 Jan 2022 21:09:51 +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 20SL9pBB004041; Fri, 28 Jan 2022 21:09:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20SL9pJo004040; Fri, 28 Jan 2022 21:09:51 GMT (envelope-from git) Date: Fri, 28 Jan 2022 21:09:51 GMT Message-Id: <202201282109.20SL9pJo004040@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: 2e8d1a55258d - main - iscsi: Allocate a dummy PDU for the internal nexus reset task. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 2e8d1a55258d39f7315fa4f2164c0fce96e79802 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643404192; 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=fZbADQqbLTBVGFQUuCPHCfwdBnYqLU8UhJmBTKhONIM=; b=NexSybKOEU2SJEt9cgjLC3+LueXyk86328TqAaoGsj/femT80Mq25NTjNKxda/pZNbG75/ IwpKkfBNJennVwyf99YWwZdF0XwlVxTJojLdDf2Sm7wrU/JvdezfUcByNd1YrW0pwmAvhe pHK3WcXcZUNw5eo6EY6OjLQftFW/N7pJfcwcTfbz2bTOHwYx77l6Tjo3NDPweEWz1xbf6x rgBAyeXR+jCgxqFoDdzVRVpAmtkBu51LzY2idv37YE+3vVKsQZ+s/jxajtOru5rfAbcm/N Ib8k98pWLuCNRs2zPgWOKnELy8bm3yzITw/piq7EdaOO1YjD2z308X+TciBSmA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643404192; a=rsa-sha256; cv=none; b=yDRAFftRbaJwb7JhnjPrcETi9Zz30hngnfzYbGkTYXg6dLCKmn0/5Y02A6ydgVN9P1zI4h zxQZPovEmuqYdboZBlIsOBaFEUUv5vXw+Vq2I0sDsumzFQuNynzrYu0tV1xkk+m3n2FP5S S77LKGLww1fPL+lJHNkqbTcXFW3Cb8FrxpF1Ypb6XAE1koG51BQ7mBs/B24EZTnDeAK6UB D/Jxs+OD1/R+Pr0lXurYTgKRvHPN3tjHEUnP1veDtXAoMhGDkcZ47mRp7RpI11PQiVI6u4 aTG8DTFCyb4N7EACy+8I7FNsAKTqCav6jc4taNfxSZ47uqAobjUL24pFAcIDLA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=2e8d1a55258d39f7315fa4f2164c0fce96e79802 commit 2e8d1a55258d39f7315fa4f2164c0fce96e79802 Author: John Baldwin AuthorDate: 2022-01-28 21:07:04 +0000 Commit: John Baldwin CommitDate: 2022-01-28 21:07:04 +0000 iscsi: Allocate a dummy PDU for the internal nexus reset task. When an iSCSI target session is terminated, an internal nexus reset task is posted to abort existing tasks belonging to the session. Previously, the ctl_io for this internal nexus reset stored a pointer to the session in the slot that normally holds a pointer to the PDU from the initiator that triggered the I/O request. The completion handler then assumed that any nexus reset I/O was due to an internal request and fetched the session pointer (instead of the PDU pointer) from the ctl_io. However, it is possible to trigger a nexus reset via an on-the-wire task management PDU. If such a PDU were sent to the target, then the completion handler would incorrectly treat this request as an internal request and treat the pointer to the received PDU as a pointer to the session instead. To fix, allocate a dummy PDU for the internal reset task and use an invalid opcode to differentiate internal nexus resets from resets requested by the initiator. PR: 260449 Reported by: Robert Morris Reviewed by: mav Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D34055 --- sys/cam/ctl/ctl_frontend_iscsi.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/sys/cam/ctl/ctl_frontend_iscsi.c b/sys/cam/ctl/ctl_frontend_iscsi.c index 42abc49b7025..9827491dba4d 100644 --- a/sys/cam/ctl/ctl_frontend_iscsi.c +++ b/sys/cam/ctl/ctl_frontend_iscsi.c @@ -84,6 +84,9 @@ __FBSDID("$FreeBSD$"); FEATURE(cfiscsi_kernel_proxy, "iSCSI target built with ICL_KERNEL_PROXY"); #endif +/* Used for internal nexus reset task. */ +#define ISCSI_BHS_OPCODE_INTERNAL 0x3e + static MALLOC_DEFINE(M_CFISCSI, "cfiscsi", "Memory used for CTL iSCSI frontend"); static uma_zone_t cfiscsi_data_wait_zone; @@ -1131,14 +1134,17 @@ static void cfiscsi_session_terminate_tasks(struct cfiscsi_session *cs) { struct cfiscsi_data_wait *cdw; + struct icl_pdu *ip; union ctl_io *io; int error, last, wait; if (cs->cs_target == NULL) return; /* No target yet, so nothing to do. */ + ip = icl_pdu_new(cs->cs_conn, M_WAITOK); + ip->ip_bhs->bhs_opcode = ISCSI_BHS_OPCODE_INTERNAL; io = ctl_alloc_io(cs->cs_target->ct_port.ctl_pool_ref); ctl_zero_io(io); - PRIV_REQUEST(io) = cs; + PRIV_REQUEST(io) = ip; io->io_hdr.io_type = CTL_IO_TASK; io->io_hdr.nexus.initid = cs->cs_ctl_initid; io->io_hdr.nexus.targ_port = cs->cs_target->ct_port.targ_port; @@ -1152,6 +1158,7 @@ cfiscsi_session_terminate_tasks(struct cfiscsi_session *cs) CFISCSI_SESSION_WARN(cs, "ctl_run() failed; error %d", error); refcount_release(&cs->cs_outstanding_ctl_pdus); ctl_free_io(io); + icl_pdu_free(ip); } CFISCSI_SESSION_LOCK(cs); @@ -3041,19 +3048,6 @@ cfiscsi_done(union ctl_io *io) KASSERT(((io->io_hdr.status & CTL_STATUS_MASK) != CTL_STATUS_NONE), ("invalid CTL status %#x", io->io_hdr.status)); - if (io->io_hdr.io_type == CTL_IO_TASK && - io->taskio.task_action == CTL_TASK_I_T_NEXUS_RESET) { - /* - * Implicit task termination has just completed; nothing to do. - */ - cs = PRIV_REQUEST(io); - cs->cs_tasks_aborted = true; - refcount_release(&cs->cs_outstanding_ctl_pdus); - wakeup(__DEVOLATILE(void *, &cs->cs_outstanding_ctl_pdus)); - ctl_free_io(io); - return; - } - request = PRIV_REQUEST(io); cs = PDU_SESSION(request); @@ -3064,6 +3058,16 @@ cfiscsi_done(union ctl_io *io) case ISCSI_BHS_OPCODE_TASK_REQUEST: cfiscsi_task_management_done(io); break; + case ISCSI_BHS_OPCODE_INTERNAL: + /* + * Implicit task termination has just completed; nothing to do. + */ + cs->cs_tasks_aborted = true; + refcount_release(&cs->cs_outstanding_ctl_pdus); + wakeup(__DEVOLATILE(void *, &cs->cs_outstanding_ctl_pdus)); + ctl_free_io(io); + icl_pdu_free(request); + return; default: panic("cfiscsi_done called with wrong opcode 0x%x", request->ip_bhs->bhs_opcode);