From patchwork Sat Apr 24 22:05:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 427407 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B83A6C433ED for ; Sat, 24 Apr 2021 22:06:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 99551611BF for ; Sat, 24 Apr 2021 22:06:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232120AbhDXWHJ (ORCPT ); Sat, 24 Apr 2021 18:07:09 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:48350 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231911AbhDXWHI (ORCPT ); Sat, 24 Apr 2021 18:07:08 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13OM5THb051156; Sat, 24 Apr 2021 22:06:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=3WxM/r7mgYpVYjBA3HJL1OhUDs02JhzdIexylbakZN0=; b=JGm+zDgEpeJ3rITHpR/iyiBvXDIqpJXMoRbx47ouLAvWL2bUTGz8B0y1QyvbdHStgcpf 2rZt/xEJEfhzgOBT99vsJIJkmmzyCN3wZhPPcVNtHOJm8W8vQMdqw/wajZFT+2Ndg/M5 oVJnw2MR2ToCFL9gDbsRTfhxz21MuYHn48RvlhkeEVqlYVp4IbEFM01BQx+J/JnVmXma nujHO3LxX7TrGQ29e4jJLJdMXYXy7mUGXX2n1dyXLEZb4pxzUIBj09+KajIBDT/AmCqa 4FgPmasQSXe5wbTBtYr2VGCSG1rkclRf2nGxgpQ6JXS36+UMc/KuHJAG3wCwnJY0JNAU 1Q== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 3848ubrvdy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 24 Apr 2021 22:06:21 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13OM66YT182267; Sat, 24 Apr 2021 22:06:21 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2104.outbound.protection.outlook.com [104.47.58.104]) by aserp3030.oracle.com with ESMTP id 3849cakfth-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 24 Apr 2021 22:06:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DbDfgcpq7I4KD9u4XZEty8/q9ULgO8fSnVZ/KvRY1hh0A+rX8uhwG4lMj9AhQRshlXWtZ7nvp7pjxwfMjDfFEsTrG/7N9hVO3bNBVEJhUl61oYnkHQdGKUIiAba2sx7pbtoq5LWslJmh+eATpkK7eUcRuHHJbDMRNlrX1iN6Rzx6RoelPzZv6b/vWs59AWMW5OJ0w32O2Xg/9ejXztF+GH+bjo//JgfQVTbYWkCMFiin00eBngZfYjcz9qTOsYvwEs4nZmyT14BtlRUz8mmZoCVWq0OiJ5oz4zxx+hd+/ptkoRZNHcbEPWJ6FK3qfS0FRw5KXHavpGpH353ZfU/pWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3WxM/r7mgYpVYjBA3HJL1OhUDs02JhzdIexylbakZN0=; b=Vd53iAxg1m4CrLkCnUI0raqiAIejgJKkR6Wo9maWDGT7L/IwZ1LLJiszVkIUyLfn3y8jFG7tL4EJfV9b5fGgOywVnG7QfJrg/mwdN6z298LG74M3rUVmsDhAcSPe89vIlrOCw+eyg0cfclBYKbm0W5XpqdfOA0+FNJ7bD6UpiWw13joAuCoKNhgTVBV4UhHDAlbDjfbr45kYYeA7rq60dzMud6Il50P69lmpMg0iaoMoN/akVM2ttGZ/3p9QQGTNFTplJPjYbZ2y/AKwPUmLpn6bgdWU9qXfwFYNtCYiqbnzfJwWhuUXE0c9qHZbJruxIFsVDHDNzeVi3+QLihPS6A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3WxM/r7mgYpVYjBA3HJL1OhUDs02JhzdIexylbakZN0=; b=ebWTv0CUeUsjNkJvqvMyutSBTDCSlkA4qFYemk61nC7dpAtV6L6wNPAyIa3JaKrILk8/TimL09/LAVUHeu0Q+IxmegP7nffqNd1Tyfc+sssJpgYEmLcQ/2TxtjkahCSSfCb8OtaxTB8wdKg1yPmk4YrEcLZzYy9pnp3j21phI8E= Authentication-Results: suse.com; dkim=none (message not signed) header.d=none; suse.com; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) by BYAPR10MB3317.namprd10.prod.outlook.com (2603:10b6:a03:158::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.24; Sat, 24 Apr 2021 22:06:19 +0000 Received: from BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::50bb:7b66:35ee:4a4]) by BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::50bb:7b66:35ee:4a4%7]) with mapi id 15.20.4065.021; Sat, 24 Apr 2021 22:06:19 +0000 From: Mike Christie To: lduncan@suse.com, martin.petersen@oracle.com, mrangankar@marvell.com, svernekar@marvell.com, linux-scsi@vger.kernel.org, jejb@linux.ibm.com Cc: Mike Christie Subject: [PATCH v4 06/17] scsi: iscsi: fix use conn use after free Date: Sat, 24 Apr 2021 17:05:52 -0500 Message-Id: <20210424220603.123703-7-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210424220603.123703-1-michael.christie@oracle.com> References: <20210424220603.123703-1-michael.christie@oracle.com> X-Originating-IP: [73.88.28.6] X-ClientProxiedBy: DM5PR16CA0044.namprd16.prod.outlook.com (2603:10b6:4:15::30) To BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (73.88.28.6) by DM5PR16CA0044.namprd16.prod.outlook.com (2603:10b6:4:15::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20 via Frontend Transport; Sat, 24 Apr 2021 22:06:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 65873b30-ae56-459e-7750-08d9076d3032 X-MS-TrafficTypeDiagnostic: BYAPR10MB3317: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:608; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IO8HW4m7sVH9QGW9ELsaJHf/5MuWvqE13HmRALrCs4ek1/NFw9gigPUz+jbd7ejKdrRKapeAXNtXIqnz04xQ3HekV2xt8BCWMpGoA4upZM3CO30m4Ygizm2npKqWEMbWfeh1zQO4QLkydssAvG1krlLh2fSJ0HjwAQUZio9n6EFUqNCAzg955fhbQJ9+K7Q/aIjRzJsfMnhJ89SE4W6xrcPnxuof1jumE2l/57AzBHdw0Duyuwvb6N9cQIf2ui9BNbHNE/pcXIc3Fp9tb3TZ/IS68sNpejXLw71pPSRl/AoIGeuRdb/YAoYEgz0eV/cNcu7fOQe3sT6HXEzTAd2DYVJjQS6d+B+FV4I2yZbEiZbBnIDMCDAEImLrn3jISGNRAQ8YBwA65WC+q7GK/kNAg8YKY3m57k6hPeZG2IFGNyWmdhYkn8wARmlrCXsqbCbbvcCIVus13OPcBru/dcfPn+KI9/PXFNN99uEsTekv+jkpSxN9blowfz69f0wRVbwV1jXnnAt1iYamHkQBKKD/MTsLM/DZf99Dk50vlwi6cSiFqHqZcexIUXM+NmKkvLmHb8dqcDcIgxmzGzSu8rAjmPmoBeJg0dY+pvTWfgrxTDoAB+eluBfQryBhNS7lnSVk9RPsYsaOxEGP23wMRR8gpX5F2NyozKzuKa7ZXfAWRXCYP6mQLzRxJGkclUznV9/x X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB3573.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(136003)(366004)(346002)(396003)(376002)(39860400002)(4326008)(6666004)(1076003)(36756003)(86362001)(52116002)(478600001)(83380400001)(38350700002)(38100700002)(8936002)(5660300002)(26005)(30864003)(16526019)(316002)(6512007)(8676002)(956004)(186003)(2616005)(66476007)(2906002)(66946007)(66556008)(6486002)(107886003)(6506007)(69590400013); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: C/IMlinQk8NDV6WoNA+uqYW3ubPSjZVc65E+H/lEifUJsuO4mG5BH5XDaoxDOOI0nDPpEwxgzzif0MPYu1VvLAbavCa3KctVFRMw8tyUPDdBmS/SjeA3qaJVCA8kIbRQtboqMM14n6Jj0lzCBdggAf4siw2WUefAt4+mpKo17DnHjcUMPKxLNC8lUkBvoTvhT4eBbkc4e062S6CvUgx6R30RG0SBqYzPW087eILwU0gZo3BiY6vEuluaE+8dY/7tY8WsnX9p29WaBYDbza4uaFTJXSWvNtlTJTQUzOF+GeaHRlnXGSS2SKrksYah2kEKRcycR1JTnLMamZONPvjgQ8Y2qQYayXHHGdHTMBMTSgfs6WaTmnVatzlGMTMfd02qDTRHKuNR27u06HJxxPsP/BwRhanxsB8zGFSOt/95OV5VW405jyYRXBSttxL5SAv/lW6ZCRBTS5alVDWiPTiTjERJuN10rBIr4QBX7ihmc8GLtDiGRGIZe1LV3WJAv8zCO2j1M6OIjdk9DlvCTAiFz4QLoUVsbNSD1/3Uql0vNnmwaeMdaCOijHLIs1LLKvg5DqqWL6NPaNeDteKe9h5ph25lXd+LRBYeNsAlGbGe6pGdekBH5hpziRhZ6jYNyZuPNS0DD0fbN1+622rTCAoDYAN9mxOFVxHzn4XWSK3BWBowKnfXqnIBxBJ0pBANG9sLPLzYO060pcinmgUXrgL7p3PqlqNyq4raRm9v9Ti2K+SzgRy45F7UDvrp4PDm4coLAzhpZik5ixP/VhXzjoQ3dpUroiXHr0ix1f8wOev9JKP0m+TL5UA0OOgSdPMY6wodN0vOSr0ihmTRitaTAwrFnPrII2mzOnEWUbaCsjl22oN7lOmRHfX7ACg1RCxRIBZpte1VAhaYHgI+2JWL34nVIost+X98B4V+x2UB4CAbkosy+FeROdb70DaetWCxcw/hfznQq1+5JlgirNXyDpENuRkbLPFiPkmeyVllP2h9iNMFGhz0GK1tjlOuvX0t5Lmki2fP8zV7y6JWd6OkB6xcmaa+6kdDN4HW2mOCmeOIEehDbcxKfQezSvthY7gu9qDEOlMW06HbPqMck9Zw3J8/jj2PDduEA88KEc3mk3/4Z4P0nCk5OFmQarpcwAaAix76bTlaeOMS88Ap9qRxkuLeHgP1wCva0aIMID3EyDMmMboJu6z7RTaS9jlP24cMO5B/SP6VE1ZNyFIflD3MzqBuCemrYVIIkngYu5gGLnehCtbHpxJMN2mTfoIjbgYWgGayuIW1NPw/gODAw4gY0goXPOkHeRcb3tjfJN2bl2CTm7JbTvtQWmAcoolYXyi74QLs X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 65873b30-ae56-459e-7750-08d9076d3032 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3573.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2021 22:06:19.3238 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EOrtIpbO1Q3JSWZvd9qKcPZgLCMGIzde15Pnd4Kgid9JBs5fjdvWd0dU4VGa5UzBp2IqCNIz3cvePEylGr7Us2WqeReTF1vkC2pYQYabIBU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3317 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9964 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 adultscore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104240168 X-Proofpoint-GUID: mz4HQlJhPaaBOCywbU3XyROUWWME52et X-Proofpoint-ORIG-GUID: mz4HQlJhPaaBOCywbU3XyROUWWME52et X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9964 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 spamscore=0 adultscore=0 clxscore=1015 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104240168 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If we haven't done a unbind target call we can race where iscsi_conn_teardown wakes up the eh/abort thread and then frees the conn while those threads are still accessing the conn ehwait. We can only do one TMF per session so this just moves the TMF fields from the conn to the session. We can then rely on the iscsi_session_teardown->iscsi_remove_session->__iscsi_unbind_session call to remove the target and it's devices, and know after that point there is no device or scsi-ml callout trying to access the session. Reviewed-by: Lee Duncan Signed-off-by: Mike Christie --- drivers/scsi/libiscsi.c | 123 +++++++++++++++++++--------------------- include/scsi/libiscsi.h | 11 ++-- 2 files changed, 64 insertions(+), 70 deletions(-) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index e340a67c6764..32363e758df2 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -230,11 +230,11 @@ static int iscsi_prep_ecdb_ahs(struct iscsi_task *task) */ static int iscsi_check_tmf_restrictions(struct iscsi_task *task, int opcode) { - struct iscsi_conn *conn = task->conn; - struct iscsi_tm *tmf = &conn->tmhdr; + struct iscsi_session *session = task->conn->session; + struct iscsi_tm *tmf = &session->tmhdr; u64 hdr_lun; - if (conn->tmf_state == TMF_INITIAL) + if (session->tmf_state == TMF_INITIAL) return 0; if ((tmf->opcode & ISCSI_OPCODE_MASK) != ISCSI_OP_SCSI_TMFUNC) @@ -254,24 +254,19 @@ static int iscsi_check_tmf_restrictions(struct iscsi_task *task, int opcode) * Fail all SCSI cmd PDUs */ if (opcode != ISCSI_OP_SCSI_DATA_OUT) { - iscsi_conn_printk(KERN_INFO, conn, - "task [op %x itt " - "0x%x/0x%x] " - "rejected.\n", - opcode, task->itt, - task->hdr_itt); + iscsi_session_printk(KERN_INFO, session, + "task [op %x itt 0x%x/0x%x] rejected.\n", + opcode, task->itt, task->hdr_itt); return -EACCES; } /* * And also all data-out PDUs in response to R2T * if fast_abort is set. */ - if (conn->session->fast_abort) { - iscsi_conn_printk(KERN_INFO, conn, - "task [op %x itt " - "0x%x/0x%x] fast abort.\n", - opcode, task->itt, - task->hdr_itt); + if (session->fast_abort) { + iscsi_session_printk(KERN_INFO, session, + "task [op %x itt 0x%x/0x%x] fast abort.\n", + opcode, task->itt, task->hdr_itt); return -EACCES; } break; @@ -284,7 +279,7 @@ static int iscsi_check_tmf_restrictions(struct iscsi_task *task, int opcode) */ if (opcode == ISCSI_OP_SCSI_DATA_OUT && task->hdr_itt == tmf->rtt) { - ISCSI_DBG_SESSION(conn->session, + ISCSI_DBG_SESSION(session, "Preventing task %x/%x from sending " "data-out due to abort task in " "progress\n", task->itt, @@ -936,20 +931,21 @@ iscsi_data_in_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr, static void iscsi_tmf_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr) { struct iscsi_tm_rsp *tmf = (struct iscsi_tm_rsp *)hdr; + struct iscsi_session *session = conn->session; conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1; conn->tmfrsp_pdus_cnt++; - if (conn->tmf_state != TMF_QUEUED) + if (session->tmf_state != TMF_QUEUED) return; if (tmf->response == ISCSI_TMF_RSP_COMPLETE) - conn->tmf_state = TMF_SUCCESS; + session->tmf_state = TMF_SUCCESS; else if (tmf->response == ISCSI_TMF_RSP_NO_TASK) - conn->tmf_state = TMF_NOT_FOUND; + session->tmf_state = TMF_NOT_FOUND; else - conn->tmf_state = TMF_FAILED; - wake_up(&conn->ehwait); + session->tmf_state = TMF_FAILED; + wake_up(&session->ehwait); } static int iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr) @@ -1734,20 +1730,20 @@ static bool iscsi_eh_running(struct iscsi_conn *conn, struct scsi_cmnd *sc, * same cmds. Once we get a TMF that can affect multiple cmds stop * queueing. */ - if (conn->tmf_state != TMF_INITIAL) { - tmf = &conn->tmhdr; + if (session->tmf_state != TMF_INITIAL) { + tmf = &session->tmhdr; switch (ISCSI_TM_FUNC_VALUE(tmf)) { case ISCSI_TM_FUNC_LOGICAL_UNIT_RESET: if (sc->device->lun != scsilun_to_int(&tmf->lun)) break; - ISCSI_DBG_EH(conn->session, + ISCSI_DBG_EH(session, "Requeue cmd sent during LU RESET processing.\n"); sc->result = DID_REQUEUE << 16; goto eh_running; case ISCSI_TM_FUNC_TARGET_WARM_RESET: - ISCSI_DBG_EH(conn->session, + ISCSI_DBG_EH(session, "Requeue cmd sent during TARGET RESET processing.\n"); sc->result = DID_REQUEUE << 16; goto eh_running; @@ -1868,15 +1864,14 @@ EXPORT_SYMBOL_GPL(iscsi_target_alloc); static void iscsi_tmf_timedout(struct timer_list *t) { - struct iscsi_conn *conn = from_timer(conn, t, tmf_timer); - struct iscsi_session *session = conn->session; + struct iscsi_session *session = from_timer(session, t, tmf_timer); spin_lock(&session->frwd_lock); - if (conn->tmf_state == TMF_QUEUED) { - conn->tmf_state = TMF_TIMEDOUT; + if (session->tmf_state == TMF_QUEUED) { + session->tmf_state = TMF_TIMEDOUT; ISCSI_DBG_EH(session, "tmf timedout\n"); /* unblock eh_abort() */ - wake_up(&conn->ehwait); + wake_up(&session->ehwait); } spin_unlock(&session->frwd_lock); } @@ -1899,8 +1894,8 @@ static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn, return -EPERM; } conn->tmfcmd_pdus_cnt++; - conn->tmf_timer.expires = timeout * HZ + jiffies; - add_timer(&conn->tmf_timer); + session->tmf_timer.expires = timeout * HZ + jiffies; + add_timer(&session->tmf_timer); ISCSI_DBG_EH(session, "tmf set timeout\n"); spin_unlock_bh(&session->frwd_lock); @@ -1914,12 +1909,12 @@ static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn, * 3) session is terminated or restarted or userspace has * given up on recovery */ - wait_event_interruptible(conn->ehwait, age != session->age || + wait_event_interruptible(session->ehwait, age != session->age || session->state != ISCSI_STATE_LOGGED_IN || - conn->tmf_state != TMF_QUEUED); + session->tmf_state != TMF_QUEUED); if (signal_pending(current)) flush_signals(current); - del_timer_sync(&conn->tmf_timer); + del_timer_sync(&session->tmf_timer); mutex_lock(&session->eh_mutex); spin_lock_bh(&session->frwd_lock); @@ -2351,17 +2346,17 @@ int iscsi_eh_abort(struct scsi_cmnd *sc) } /* only have one tmf outstanding at a time */ - if (conn->tmf_state != TMF_INITIAL) + if (session->tmf_state != TMF_INITIAL) goto failed; - conn->tmf_state = TMF_QUEUED; + session->tmf_state = TMF_QUEUED; - hdr = &conn->tmhdr; + hdr = &session->tmhdr; iscsi_prep_abort_task_pdu(task, hdr); if (iscsi_exec_task_mgmt_fn(conn, hdr, age, session->abort_timeout)) goto failed; - switch (conn->tmf_state) { + switch (session->tmf_state) { case TMF_SUCCESS: spin_unlock_bh(&session->frwd_lock); /* @@ -2376,7 +2371,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc) */ spin_lock_bh(&session->frwd_lock); fail_scsi_task(task, DID_ABORT); - conn->tmf_state = TMF_INITIAL; + session->tmf_state = TMF_INITIAL; memset(hdr, 0, sizeof(*hdr)); spin_unlock_bh(&session->frwd_lock); iscsi_start_tx(conn); @@ -2387,7 +2382,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc) goto failed_unlocked; case TMF_NOT_FOUND: if (!sc->SCp.ptr) { - conn->tmf_state = TMF_INITIAL; + session->tmf_state = TMF_INITIAL; memset(hdr, 0, sizeof(*hdr)); /* task completed before tmf abort response */ ISCSI_DBG_EH(session, "sc completed while abort in " @@ -2396,7 +2391,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc) } fallthrough; default: - conn->tmf_state = TMF_INITIAL; + session->tmf_state = TMF_INITIAL; goto failed; } @@ -2455,11 +2450,11 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc) conn = session->leadconn; /* only have one tmf outstanding at a time */ - if (conn->tmf_state != TMF_INITIAL) + if (session->tmf_state != TMF_INITIAL) goto unlock; - conn->tmf_state = TMF_QUEUED; + session->tmf_state = TMF_QUEUED; - hdr = &conn->tmhdr; + hdr = &session->tmhdr; iscsi_prep_lun_reset_pdu(sc, hdr); if (iscsi_exec_task_mgmt_fn(conn, hdr, session->age, @@ -2468,7 +2463,7 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc) goto unlock; } - switch (conn->tmf_state) { + switch (session->tmf_state) { case TMF_SUCCESS: break; case TMF_TIMEDOUT: @@ -2476,7 +2471,7 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc) iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST); goto done; default: - conn->tmf_state = TMF_INITIAL; + session->tmf_state = TMF_INITIAL; goto unlock; } @@ -2488,7 +2483,7 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc) spin_lock_bh(&session->frwd_lock); memset(hdr, 0, sizeof(*hdr)); fail_scsi_tasks(conn, sc->device->lun, DID_ERROR); - conn->tmf_state = TMF_INITIAL; + session->tmf_state = TMF_INITIAL; spin_unlock_bh(&session->frwd_lock); iscsi_start_tx(conn); @@ -2511,8 +2506,7 @@ void iscsi_session_recovery_timedout(struct iscsi_cls_session *cls_session) spin_lock_bh(&session->frwd_lock); if (session->state != ISCSI_STATE_LOGGED_IN) { session->state = ISCSI_STATE_RECOVERY_FAILED; - if (session->leadconn) - wake_up(&session->leadconn->ehwait); + wake_up(&session->ehwait); } spin_unlock_bh(&session->frwd_lock); } @@ -2557,7 +2551,7 @@ int iscsi_eh_session_reset(struct scsi_cmnd *sc) iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST); ISCSI_DBG_EH(session, "wait for relogin\n"); - wait_event_interruptible(conn->ehwait, + wait_event_interruptible(session->ehwait, session->state == ISCSI_STATE_TERMINATE || session->state == ISCSI_STATE_LOGGED_IN || session->state == ISCSI_STATE_RECOVERY_FAILED); @@ -2618,11 +2612,11 @@ static int iscsi_eh_target_reset(struct scsi_cmnd *sc) conn = session->leadconn; /* only have one tmf outstanding at a time */ - if (conn->tmf_state != TMF_INITIAL) + if (session->tmf_state != TMF_INITIAL) goto unlock; - conn->tmf_state = TMF_QUEUED; + session->tmf_state = TMF_QUEUED; - hdr = &conn->tmhdr; + hdr = &session->tmhdr; iscsi_prep_tgt_reset_pdu(sc, hdr); if (iscsi_exec_task_mgmt_fn(conn, hdr, session->age, @@ -2631,7 +2625,7 @@ static int iscsi_eh_target_reset(struct scsi_cmnd *sc) goto unlock; } - switch (conn->tmf_state) { + switch (session->tmf_state) { case TMF_SUCCESS: break; case TMF_TIMEDOUT: @@ -2639,7 +2633,7 @@ static int iscsi_eh_target_reset(struct scsi_cmnd *sc) iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST); goto done; default: - conn->tmf_state = TMF_INITIAL; + session->tmf_state = TMF_INITIAL; goto unlock; } @@ -2651,7 +2645,7 @@ static int iscsi_eh_target_reset(struct scsi_cmnd *sc) spin_lock_bh(&session->frwd_lock); memset(hdr, 0, sizeof(*hdr)); fail_scsi_tasks(conn, -1, DID_ERROR); - conn->tmf_state = TMF_INITIAL; + session->tmf_state = TMF_INITIAL; spin_unlock_bh(&session->frwd_lock); iscsi_start_tx(conn); @@ -2981,7 +2975,10 @@ iscsi_session_setup(struct iscsi_transport *iscsit, struct Scsi_Host *shost, session->tt = iscsit; session->dd_data = cls_session->dd_data + sizeof(*session); + session->tmf_state = TMF_INITIAL; + timer_setup(&session->tmf_timer, iscsi_tmf_timedout, 0); mutex_init(&session->eh_mutex); + spin_lock_init(&session->frwd_lock); spin_lock_init(&session->back_lock); @@ -3085,7 +3082,6 @@ iscsi_conn_setup(struct iscsi_cls_session *cls_session, int dd_size, conn->c_stage = ISCSI_CONN_INITIAL_STAGE; conn->id = conn_idx; conn->exp_statsn = 0; - conn->tmf_state = TMF_INITIAL; timer_setup(&conn->transport_timer, iscsi_check_transport_timeouts, 0); @@ -3110,8 +3106,7 @@ iscsi_conn_setup(struct iscsi_cls_session *cls_session, int dd_size, goto login_task_data_alloc_fail; conn->login_task->data = conn->data = data; - timer_setup(&conn->tmf_timer, iscsi_tmf_timedout, 0); - init_waitqueue_head(&conn->ehwait); + init_waitqueue_head(&session->ehwait); return cls_conn; @@ -3164,7 +3159,7 @@ void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn) * leading connection? then give up on recovery. */ session->state = ISCSI_STATE_TERMINATE; - wake_up(&conn->ehwait); + wake_up(&session->ehwait); } spin_unlock_bh(&session->frwd_lock); @@ -3249,7 +3244,7 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn) * commands after successful recovery */ conn->stop_stage = 0; - conn->tmf_state = TMF_INITIAL; + session->tmf_state = TMF_INITIAL; session->age++; if (session->age == 16) session->age = 0; @@ -3263,7 +3258,7 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn) spin_unlock_bh(&session->frwd_lock); iscsi_unblock_session(session->cls_session); - wake_up(&conn->ehwait); + wake_up(&session->ehwait); return 0; } EXPORT_SYMBOL_GPL(iscsi_conn_start); @@ -3357,7 +3352,7 @@ void iscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag) spin_lock_bh(&session->frwd_lock); fail_scsi_tasks(conn, -1, DID_TRANSPORT_DISRUPTED); fail_mgmt_tasks(session, conn); - memset(&conn->tmhdr, 0, sizeof(conn->tmhdr)); + memset(&session->tmhdr, 0, sizeof(session->tmhdr)); spin_unlock_bh(&session->frwd_lock); mutex_unlock(&session->eh_mutex); } diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index 13d413a0b8b6..9d7908265afe 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -202,12 +202,6 @@ struct iscsi_conn { unsigned long suspend_tx; /* suspend Tx */ unsigned long suspend_rx; /* suspend Rx */ - /* abort */ - wait_queue_head_t ehwait; /* used in eh_abort() */ - struct iscsi_tm tmhdr; - struct timer_list tmf_timer; - int tmf_state; /* see TMF_INITIAL, etc.*/ - /* negotiated params */ unsigned max_recv_dlength; /* initiator_max_recv_dsl*/ unsigned max_xmit_dlength; /* target_max_recv_dsl */ @@ -277,6 +271,11 @@ struct iscsi_session { * and recv lock. */ struct mutex eh_mutex; + /* abort */ + wait_queue_head_t ehwait; /* used in eh_abort() */ + struct iscsi_tm tmhdr; + struct timer_list tmf_timer; + int tmf_state; /* see TMF_INITIAL, etc.*/ /* iSCSI session-wide sequencing */ uint32_t cmdsn;