From patchwork Thu Dec 8 03:09:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 632167 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7956AC6370C for ; Thu, 8 Dec 2022 03:10:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229779AbiLHDKT (ORCPT ); Wed, 7 Dec 2022 22:10:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbiLHDKP (ORCPT ); Wed, 7 Dec 2022 22:10:15 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C58667614E; Wed, 7 Dec 2022 19:10:12 -0800 (PST) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B7NNehO002203; Thu, 8 Dec 2022 03:10:10 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-2022-7-12; bh=USiJSaGzY3DZonIuycbV+3cob+eNJv+C6IwgcYmV1GA=; b=o+or5IsK0YAklY1/JAKuALrTHseNI7TU7xampFTD30hXJ56FSkGGw8cEm6m9Z1J0xI4n 8ym4eS7yLlttJ+Xod7idYGiVxA59ZLMywX9cD2ZL04gzW0uworllHwfp6dttwe37zdKV RB8Ru5flLSB+TX5YpLtzYl4LUeW87K0/oQOk/cMUj0axsEJ6Zmt+ioCPnxMx6dWAr5Nl 1qwQkeNL0MSofJpcVrFx9qBL98uc3JHjBzYS5+GVLYrNtvxJ2zii7JtIozsDMLdqSX+X HIF7HwX2Onm+2siF2RrqgaNv2TbdZoV7Tit9nKs2+2KNw3ATSwqpwq9F6F0EgD68AdH+ hw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3maudusugc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 03:10:10 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2B81ulYX009791; Thu, 8 Dec 2022 03:10:09 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2172.outbound.protection.outlook.com [104.47.57.172]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3maa6a37hk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 03:10:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B+xZ68oeDcrEpXueGIic6obUhgyMM72cWVQm6Cy1DwFTq36TBlybQ8f89Kkjb8t89PdxIBEdPPwPQ+upkNpx7mBobmMVbmAOKJ8V/MGPgLuRfayImEDX6ay9or7j9TanbZLgoQ6ToRc3Us/pZhpEeg5HySaoqI0dslEiBeZYZXk/0HuvIoQR5sSEXI+3Sz/jqdkJJ8YEgQRD5MfgGGBpcSokVya9jiiNnjCXrhovQMDmOB+DPBwtnxman4FU6ksiFRiLj6qWhFXLO4DTxfbwX/IgP1okN89o9vRIwpEmWjfQNityxPChv1REMc2McarG+NzhLdOOHQB9QPbFXmgl2Q== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=USiJSaGzY3DZonIuycbV+3cob+eNJv+C6IwgcYmV1GA=; b=l6bZ4hHdkOQIrCLK8GjKyXbARmf9kYupApE015CEj2kBlrHGfXJxSN1ii6i04c/gQMRoQJljNfZnS+ZtTcVog5a9Ce6bXa7qMy3REVoEuA7QiqT6a04/5micM48AJn70WjU/goKL7eoJM1TovctmoheJoO4sZ/kn2EvwNu2yr6KolyZnSV1R4h5bqcbLVx9ZvDmftNkQ/UKQse/EhyQWBSnqNrtaWJ2tA5ZJPHeV1hbFafgXbVduWwdqwUkVLk2lpu9YZoKxie5CyWMOlIsQzZjPrmdXNz+6MqX6oQLQCrOyu601vx76zK354rb6ELGL7mfotbo3KNQUflI9yj3gug== 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=USiJSaGzY3DZonIuycbV+3cob+eNJv+C6IwgcYmV1GA=; b=Fb3oA/W5HC6JVCJ6yoq3SJmAu3AWuA/8uKfp47IeXACzRIjd90cbAfLMOR5L7FWD9pBBVgBZwa9uD8OsVC/Y9ZEI5hZcRaisfD3FJSt9gjP/Larvlv8yJzOL1ADa9vgm+3xxutZrCJku2v5Ix2sYJU9Dk2A/Qd/oHY9XPEWNmH0= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by CH0PR10MB5132.namprd10.prod.outlook.com (2603:10b6:610:c2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 03:10:07 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::2dbb:4791:5a67:4372]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::2dbb:4791:5a67:4372%7]) with mapi id 15.20.5880.014; Thu, 8 Dec 2022 03:10:07 +0000 From: Mike Christie To: mlombard@redhat.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Mike Christie Subject: [PATCH 1/7] scsi: target: Move sess cmd counter to new struct Date: Wed, 7 Dec 2022 21:09:56 -0600 Message-Id: <20221208031002.106700-2-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221208031002.106700-1-michael.christie@oracle.com> References: <20221208031002.106700-1-michael.christie@oracle.com> X-ClientProxiedBy: CH2PR02CA0026.namprd02.prod.outlook.com (2603:10b6:610:4e::36) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR10MB1466:EE_|CH0PR10MB5132:EE_ X-MS-Office365-Filtering-Correlation-Id: 469d02d9-8d97-41bb-361b-08dad8c9b56d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QSuegqWe7KdRkwGrAhuFXqmpEu4zdEetaywUtH65BqsAUxuUDI2laVSVcvo8s4Z3XMs2/BJ6UX0Jy6QQeoPIgeskRzZjbt6oxfxxysG4MPvCM3sFJnIu3EOOj6TMCOkhowQzcb+HDeGpSdpn/K93hJL+r0HaPW8TJWPpCUocIwhKCTOFjZ7yWL9VYnbI5jUNGhB5aNzZaTZ8SktApL8p34sd5HjsLbi2c6K2q/t96X9zbFZFw7wjMaq9SOvG1RRk+toT6oRitoMqpVN1fWJARNtLVBoLyWfuLjKFrmOGKfSyQceeNBKY0ZvSqgY9THgGzty56CnQSlwt+Z7rIPwvT1GtK7RGllUZTa/+lMjMq+a7ww8XVa2PzA7XjYWJDd+LswgheebSUVSw+ysteYmmk1z/DgBQvfv792N55KSajzBpdzMzPuz1TNTQbGGoQyjsVEWcGmnkoUMyw7arwX3njx3gang3r70xqANx0+8l0yekNWhXxGRhkS8PPHO9Zy5GEWEmoXBoGMQYuEEsQ1uk5kpwekDXazaZ+v3V5CGpGr9JxrH9RfiMCDBbmteOs9xUru13FBI/OMZYEd/EGSaJRJFXOJRQc5ZSKXUpzcZjq6rbSUSjumaCKMYy67Y8gV/qLC0t/Rj2+n5Ea6P3KOzK8A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR10MB1466.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(366004)(346002)(136003)(396003)(376002)(39860400002)(451199015)(38100700002)(8676002)(86362001)(83380400001)(66946007)(4326008)(41300700001)(2906002)(8936002)(66556008)(66476007)(6506007)(478600001)(6512007)(26005)(107886003)(6666004)(186003)(2616005)(316002)(1076003)(6486002)(5660300002)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 81DxMAPiupVCAhIvrjB553/dGY5r/Mbz5B3awPo0aFUcb2D/QcIxRFpBt7HxbeMjhxFpqUUBd6Vz4K8O7zwLAJj3D33areWgMpikOunUnvhp4CQeVUI9gDSWQBHSGuLx7XUxaj3FSiUCiN7SiXOj21DjGjQ852RNVQPN8+1dwtFrGH5HWfcsGSm1NEzsrmTcsSkXFeSRDRWm+AiXRLt4Zv8ep3KWs9N/e7SpZZhtkbN9BpFBcpwbfCFI+kGMRyiU1YSADmWFv7JetC/hHkWoMxkVe0iTR1izsWyCjkUekjCWSHz4Ga+t8F9vAtdms3jYDT625qhVvmD5jdGD6PiYtHzK5RhKC0M/3M6iC2IMa11b5AFZST+feaXqU5UNyt8ajKZrO0MluzI+tqhZrmk7Ws/Wa0V1GtW+kcl9CdeSEPYaV7c4WK1C5XAv5MIJ1ulwp7uWn0eoL56ajFASa5PBNaEg+ZbNwswlNb4wrIWkQkWGeVxQ7MGVO3CJKx4AG50oaoLJtxnFSRGGF5t47OCzj3ERK7u2cj3sA3X/rfEAEGpm0kRMImkEqhMpgzfuEuzNDvuknS8AYNzjKg8nNxvQp49yL7bD48Cc7JTrdAh6WEo3Dm+44CGnylJ23l1vbbr4SK+mH7aKs4Hz7Y+xhProFD9OteHdvlj0sYDDJLPNsGOOXvrrq/M81rRVylRkXhl0VmntlghdsmzAFwL7mXnEwI3KtgMwsQ/OSQMXNhbf1EuU6mTZVHPQAobiIIUfPYXZ1B5eckpP7SY6KDS9NPPODppaDdPaVfGfg1dZc8lu1hK3QAHIP5EolyWNIhl6AZUt1zqZSwKtL/Bj6UOGQgWyKuv5eLPZ1ESF9o5x6O1Msg8aOHAtjCpoZRVdiNiKB6EYAedD/RaE7aySLt3XXBHSoYTNATBehFkOLa/qvtlSHgFHo2WRmKffT98y+h3FbcWhMHlbiP+M/ON+vFV1iNtmzLk8Q132oqDK2AFxY+oYzmNs/z8hSnGRHYLC9Nlis8KL6m8UjiJIp80edfX1n5rNFceyNOu4vaAO+tMYCVKP/432IFTgpACLaqReCnTqRb326S3M89MiyCww1b0GW1yERXG/ZIKwcOnfNUU0BavTgkf8OrIAw2ZvrLimIiv8rYBdLud/BRcVkjekROsjC60cFsYjXcBUHCnFIXepsHIzd49gOSd9cF07SoHroGW9AAm1Xx9cdN1iZGBGfl6iFrxBpOOzrEq7mA86Azq90CNwFBzDF0lb4Vnijt25Jc7pRqozdkNMXinba7RSJEOrSBf0kRuU4TJFWFihbDC2gaoUZUWrLyR8M1ip6GQipx6vT+Yq4gddjeP2Ch++KtSp7VCkb2LSx95DhC5Mg7cy+CHJyjwDTF2zzO9rhuQBVPgg8ZisGgniAOlWD/JT0To+CfXuFJ/sR0H+oeuwcn9H+xNOPiHgquKgknSPP/pVgr8fHHsDK3abQT0a1LI8uUdQ7kHJaaN9Px0N1wP9F37pZQWg4vfgIfqhxo8X5sYWjz2GLJ3DzJgZTNuzl/C+AJQGLRNpMaoQp+31ZJ+Uz7PSVd943imYBQhGznefQQyj4KYAqU3EMJPZTjnv2ss5+YSSOcPYIg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 469d02d9-8d97-41bb-361b-08dad8c9b56d X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 03:10:07.2393 (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: owCRR036TZ7mDS/Z4kp1veb5EJ11NIBL+F/pqrX8TuadEy0JCUxOOxRvJqNd10tUg6rjToU+e0JIW7DF8fI7qJUN9/M4/z84oPmgHrtpuDc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5132 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-07_11,2022-12-07_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 spamscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212080024 X-Proofpoint-ORIG-GUID: 49hAcVCj6dE_Nd4iarPbxLF06Q6FAji7 X-Proofpoint-GUID: 49hAcVCj6dE_Nd4iarPbxLF06Q6FAji7 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org iSCSI needs to wait on outstanding commands like how srp and the FC/fcoe drivers do. It can't use target_stop_session because for MCS support we can't stop the entire session during recovery because if other connections are ok then we want to be able to continue to execute IO on them. This patch moves the per session cmd counters to a new struct, so iSCSI can allocate it per connection. The xcopy code can also just not allocate it in the future since it doesn't need to track commands. Signed-off-by: Mike Christie --- drivers/target/target_core_tpg.c | 2 +- drivers/target/target_core_transport.c | 141 ++++++++++++++++------- include/target/iscsi/iscsi_target_core.h | 1 + include/target/target_core_base.h | 13 ++- 4 files changed, 112 insertions(+), 45 deletions(-) diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c index 736847c933e5..8ebccdbd94f0 100644 --- a/drivers/target/target_core_tpg.c +++ b/drivers/target/target_core_tpg.c @@ -328,7 +328,7 @@ static void target_shutdown_sessions(struct se_node_acl *acl) restart: spin_lock_irqsave(&acl->nacl_sess_lock, flags); list_for_each_entry(sess, &acl->acl_sess_list, sess_acl_list) { - if (atomic_read(&sess->stopped)) + if (sess->cmd_cnt && atomic_read(&sess->cmd_cnt->stopped)) continue; list_del_init(&sess->sess_acl_list); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 7838dc20f713..60fbebe8c675 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -220,11 +220,49 @@ void transport_subsystem_check_init(void) sub_api_initialized = 1; } -static void target_release_sess_cmd_refcnt(struct percpu_ref *ref) +static void target_release_cmd_refcnt(struct percpu_ref *ref) { - struct se_session *sess = container_of(ref, typeof(*sess), cmd_count); + struct target_cmd_counter *cmd_cnt = container_of(ref, + typeof(*cmd_cnt), + refcnt); + wake_up(&cmd_cnt->refcnt_wq); +} + +static struct target_cmd_counter *target_alloc_cmd_counter(void) +{ + struct target_cmd_counter *cmd_cnt; + int rc; + + cmd_cnt = kzalloc(sizeof(*cmd_cnt), GFP_KERNEL); + if (!cmd_cnt) + return NULL; + + init_completion(&cmd_cnt->stop_done); + init_waitqueue_head(&cmd_cnt->refcnt_wq); + atomic_set(&cmd_cnt->stopped, 0); + + rc = percpu_ref_init(&cmd_cnt->refcnt, target_release_cmd_refcnt, 0, + GFP_KERNEL); + if (rc) + goto free_cmd_cnt; + + return cmd_cnt; + +free_cmd_cnt: + kfree(cmd_cnt); + return NULL; +} + +static void target_free_cmd_counter(struct target_cmd_counter *cmd_cnt) +{ + /* + * Drivers like loop do not call target_stop_session during session + * shutdown so we have to drop the ref taken at init time here. + */ + if (!atomic_read(&cmd_cnt->stopped)) + percpu_ref_put(&cmd_cnt->refcnt); - wake_up(&sess->cmd_count_wq); + percpu_ref_exit(&cmd_cnt->refcnt); } /** @@ -238,25 +276,17 @@ int transport_init_session(struct se_session *se_sess) INIT_LIST_HEAD(&se_sess->sess_list); INIT_LIST_HEAD(&se_sess->sess_acl_list); spin_lock_init(&se_sess->sess_cmd_lock); - init_waitqueue_head(&se_sess->cmd_count_wq); - init_completion(&se_sess->stop_done); - atomic_set(&se_sess->stopped, 0); - return percpu_ref_init(&se_sess->cmd_count, - target_release_sess_cmd_refcnt, 0, GFP_KERNEL); + se_sess->cmd_cnt = target_alloc_cmd_counter(); + if (!se_sess->cmd_cnt) + return -ENOMEM; + + return 0; } EXPORT_SYMBOL(transport_init_session); void transport_uninit_session(struct se_session *se_sess) { - /* - * Drivers like iscsi and loop do not call target_stop_session - * during session shutdown so we have to drop the ref taken at init - * time here. - */ - if (!atomic_read(&se_sess->stopped)) - percpu_ref_put(&se_sess->cmd_count); - - percpu_ref_exit(&se_sess->cmd_count); + target_free_cmd_counter(se_sess->cmd_cnt); } /** @@ -602,7 +632,6 @@ void transport_free_session(struct se_session *se_sess) sbitmap_queue_free(&se_sess->sess_tag_pool); kvfree(se_sess->sess_cmd_map); } - transport_uninit_session(se_sess); kmem_cache_free(se_sess_cache, se_sess); } EXPORT_SYMBOL(transport_free_session); @@ -655,8 +684,13 @@ EXPORT_SYMBOL(transport_deregister_session); void target_remove_session(struct se_session *se_sess) { + struct target_cmd_counter *cmd_cnt = se_sess->cmd_cnt; + transport_deregister_session_configfs(se_sess); transport_deregister_session(se_sess); + + if (cmd_cnt) + target_free_cmd_counter(cmd_cnt); } EXPORT_SYMBOL(target_remove_session); @@ -2970,9 +3004,16 @@ int target_get_sess_cmd(struct se_cmd *se_cmd, bool ack_kref) se_cmd->se_cmd_flags |= SCF_ACK_KREF; } - if (!percpu_ref_tryget_live(&se_sess->cmd_count)) - ret = -ESHUTDOWN; - + /* + * Users like xcopy do not use counters since they never do a stop + * and wait. + */ + if (se_sess->cmd_cnt) { + if (!percpu_ref_tryget_live(&se_sess->cmd_cnt->refcnt)) + ret = -ESHUTDOWN; + else + se_cmd->cmd_cnt = se_sess->cmd_cnt; + } if (ret && ack_kref) target_put_sess_cmd(se_cmd); @@ -2993,7 +3034,7 @@ static void target_free_cmd_mem(struct se_cmd *cmd) static void target_release_cmd_kref(struct kref *kref) { struct se_cmd *se_cmd = container_of(kref, struct se_cmd, cmd_kref); - struct se_session *se_sess = se_cmd->se_sess; + struct target_cmd_counter *cmd_cnt = se_cmd->cmd_cnt; struct completion *free_compl = se_cmd->free_compl; struct completion *abrt_compl = se_cmd->abrt_compl; @@ -3004,7 +3045,8 @@ static void target_release_cmd_kref(struct kref *kref) if (abrt_compl) complete(abrt_compl); - percpu_ref_put(&se_sess->cmd_count); + if (cmd_cnt) + percpu_ref_put(&cmd_cnt->refcnt); } /** @@ -3123,46 +3165,65 @@ void target_show_cmd(const char *pfx, struct se_cmd *cmd) } EXPORT_SYMBOL(target_show_cmd); -static void target_stop_session_confirm(struct percpu_ref *ref) +static void target_stop_cmd_counter_confirm(struct percpu_ref *ref) { - struct se_session *se_sess = container_of(ref, struct se_session, - cmd_count); - complete_all(&se_sess->stop_done); + struct target_cmd_counter *cmd_cnt = container_of(ref, + struct target_cmd_counter, + refcnt); + complete_all(&cmd_cnt->stop_done); +} + +/** + * target_stop_cmd_counter - Stop new IO from being added to the counter. + * @cmd_cnt: counter to stop + */ +static void target_stop_cmd_counter(struct target_cmd_counter *cmd_cnt) +{ + pr_debug("Stopping command counter.\n"); + if (!atomic_cmpxchg(&cmd_cnt->stopped, 0, 1)) + percpu_ref_kill_and_confirm(&cmd_cnt->refcnt, + target_stop_cmd_counter_confirm); } /** * target_stop_session - Stop new IO from being queued on the session. - * @se_sess: session to stop + * @se_sess: session to stop */ void target_stop_session(struct se_session *se_sess) { - pr_debug("Stopping session queue.\n"); - if (atomic_cmpxchg(&se_sess->stopped, 0, 1) == 0) - percpu_ref_kill_and_confirm(&se_sess->cmd_count, - target_stop_session_confirm); + target_stop_cmd_counter(se_sess->cmd_cnt); } EXPORT_SYMBOL(target_stop_session); /** - * target_wait_for_sess_cmds - Wait for outstanding commands - * @se_sess: session to wait for active I/O + * target_wait_for_cmds - Wait for outstanding cmds. + * @cmd_cnt: counter to wait for active I/O for. */ -void target_wait_for_sess_cmds(struct se_session *se_sess) +static void target_wait_for_cmds(struct target_cmd_counter *cmd_cnt) { int ret; - WARN_ON_ONCE(!atomic_read(&se_sess->stopped)); + WARN_ON_ONCE(!atomic_read(&cmd_cnt->stopped)); do { pr_debug("Waiting for running cmds to complete.\n"); - ret = wait_event_timeout(se_sess->cmd_count_wq, - percpu_ref_is_zero(&se_sess->cmd_count), - 180 * HZ); + ret = wait_event_timeout(cmd_cnt->refcnt_wq, + percpu_ref_is_zero(&cmd_cnt->refcnt), + 180 * HZ); } while (ret <= 0); - wait_for_completion(&se_sess->stop_done); + wait_for_completion(&cmd_cnt->stop_done); pr_debug("Waiting for cmds done.\n"); } + +/** + * target_wait_for_sess_cmds - Wait for outstanding commands + * @se_sess: session to wait for active I/O + */ +void target_wait_for_sess_cmds(struct se_session *se_sess) +{ + target_wait_for_cmds(se_sess->cmd_cnt); +} EXPORT_SYMBOL(target_wait_for_sess_cmds); /* diff --git a/include/target/iscsi/iscsi_target_core.h b/include/target/iscsi/iscsi_target_core.h index 94d06ddfd80a..229118156a1f 100644 --- a/include/target/iscsi/iscsi_target_core.h +++ b/include/target/iscsi/iscsi_target_core.h @@ -600,6 +600,7 @@ struct iscsit_conn { struct iscsi_tpg_np *tpg_np; /* Pointer to parent session */ struct iscsit_session *sess; + struct target_cmd_counter *cmd_cnt; int bitmap_id; int rx_thread_active; struct task_struct *rx_thread; diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 12c9ba16217e..bd299790e99c 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -494,6 +494,7 @@ struct se_cmd { struct se_lun *se_lun; /* Only used for internal passthrough and legacy TCM fabric modules */ struct se_session *se_sess; + struct target_cmd_counter *cmd_cnt; struct se_tmr_req *se_tmr_req; struct llist_node se_cmd_list; struct completion *free_compl; @@ -619,22 +620,26 @@ static inline struct se_node_acl *fabric_stat_to_nacl(struct config_item *item) acl_fabric_stat_group); } -struct se_session { +struct target_cmd_counter { + struct percpu_ref refcnt; + wait_queue_head_t refcnt_wq; + struct completion stop_done; atomic_t stopped; +}; + +struct se_session { u64 sess_bin_isid; enum target_prot_op sup_prot_ops; enum target_prot_type sess_prot_type; struct se_node_acl *se_node_acl; struct se_portal_group *se_tpg; void *fabric_sess_ptr; - struct percpu_ref cmd_count; struct list_head sess_list; struct list_head sess_acl_list; spinlock_t sess_cmd_lock; - wait_queue_head_t cmd_count_wq; - struct completion stop_done; void *sess_cmd_map; struct sbitmap_queue sess_tag_pool; + struct target_cmd_counter *cmd_cnt; }; struct se_device; From patchwork Thu Dec 8 03:09:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 633209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73573C63703 for ; Thu, 8 Dec 2022 03:10:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229692AbiLHDKQ (ORCPT ); Wed, 7 Dec 2022 22:10:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229557AbiLHDKP (ORCPT ); Wed, 7 Dec 2022 22:10:15 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03BAE7616E; Wed, 7 Dec 2022 19:10:12 -0800 (PST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B7NO0vA016777; Thu, 8 Dec 2022 03:10:11 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-2022-7-12; bh=Aj8bW69fJwO/TjDmSHtW/CEHCu9iXHXjBGHhUvzFZR8=; b=ylpU0M4WAj6uX6QHdAmemJ6gyIPAw2S+rvvVYIzYaD+nMdXXUGrfBe1LOZ2AYczAonRv Pym0elLFJdvx/Qc/twuYO9/4SwpavdYlaJFV+AdSMSlbXqNvmxeUFvlC6/fBTY9nUMdY U3WqDysDDdIezyOi4sZG5WRVOYnBAayJmt5hMxlRjPcivZkNTzKe/VU6aP0PAZ4y6ge7 W9T57BBttjy9MU7h8bWR98oYv32oqdsDn4s2vFr6TenMbhcC831aDa25AGufeBrqV4E2 ELQoKm371pjKjCRrP1KmXOnGbvy7oULlT0IRqB/Mkkb7Ks5JtuYaYirrWSwHy8Kj9kG2 qg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3maujkht40-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 03:10:10 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2B81ulYY009791; Thu, 8 Dec 2022 03:10:10 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2172.outbound.protection.outlook.com [104.47.57.172]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3maa6a37hk-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 03:10:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S88sFgNdJPtjRGf+96A+bX1voc+B7mdqEIMhd+u6Ajxq7NG+LfCLF65Rwwy5yULRgNUG5Xl08R8+YZkn5eA+ZlmrthSpOSgXSaIvOy+X3scEQS8baljliap/ZUEkGiYRybF1CoLVGxqwaNIlRmRIdWFGozxqafrqmEPlo1mU2H/PJ92s5UV7ce0UzPu9cw87BXUpn0H3WuaXk9/RmedcVCqKLSYaSvZwwKhma+LLwQSJ2k9yjnpUU2zX/84ZQ0ecRNQ5dEhYci77mI3IrOTujudw+D/NbTT+6eRHc4CuH2HQRu5hvDJuaXL2HUMcOsWIPebZB8aq/n+bIRb2IcV1Jg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Aj8bW69fJwO/TjDmSHtW/CEHCu9iXHXjBGHhUvzFZR8=; b=iYZm4dQAXEbOPbCdsysypfgLSJg2yHXOV/vuT/Q6If0zbaP0vwCMfIeWTl/Q6m0IVLS3UgsLeL194sS6el0iI8GV+nVn6+cBb8TXEkSHAZVR23k1Z5RKHRS/ie5yLhlT1CFZeOfXkThO4Bt5hZN3lkrLp4KWrbQahtW6keCoEDaFPZNZUEqR6WC9GHs5t29SBYhhdwN+y63NdU0QN6TdqF/NiOdoSV0GcmMChS0ADiL80DVRp9W5FdDy/R5XrNcjfLi9Q1oRXW+AhwvUSYgtyR/Tjr1SOOeb3HJQ3Mrwx3Y9vLlYRmtprHoEretj3CTW/XHev6w2VtqDL3h4Wfr8Lg== 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=Aj8bW69fJwO/TjDmSHtW/CEHCu9iXHXjBGHhUvzFZR8=; b=0J7cTejURWO0ON1wfPD6GR/3OtmtPcAbgUfwKmSfYCVL+R3qc+Q/UFnRdwexnCJ9BOE8VHpbj+m5HGcsGLZCh3mr5Ih1Ji3KTY9N3NdeiJnaVDVTZxr7q4j8fHyyaNL/VP6fsTHf+l709yBAcNoZ5kD1zz5B4739kgjgiUzQGqA= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by CH0PR10MB5132.namprd10.prod.outlook.com (2603:10b6:610:c2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 03:10:08 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::2dbb:4791:5a67:4372]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::2dbb:4791:5a67:4372%7]) with mapi id 15.20.5880.014; Thu, 8 Dec 2022 03:10:08 +0000 From: Mike Christie To: mlombard@redhat.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Mike Christie Subject: [PATCH 2/7] scsi: target: Move cmd counter allocation Date: Wed, 7 Dec 2022 21:09:57 -0600 Message-Id: <20221208031002.106700-3-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221208031002.106700-1-michael.christie@oracle.com> References: <20221208031002.106700-1-michael.christie@oracle.com> X-ClientProxiedBy: CH0PR04CA0113.namprd04.prod.outlook.com (2603:10b6:610:75::28) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR10MB1466:EE_|CH0PR10MB5132:EE_ X-MS-Office365-Filtering-Correlation-Id: 7658c11c-e96e-4bcb-4e62-08dad8c9b64d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +7wAmDpxHoeiR2fwGiRVXhx1VSYELaqVhcFctMlG3wg5oeWVi3H9wCeXDzJYtpNKcHjdD1MZgo5MiK9wo9bKP/qfxxEo4e4+sUFYDPj/+B6+A8PpVIIoRi+lqlXTbTmaNw/ryztxdI62wvqmNYK3MEmZMFHNcYdAo0wrT1euC2J9LXoih5T4rDVczejhb8Dr8E1q4zl/FZLEVU9k56aZhCge+7ODtp5bIln0CG6X7cz3rxFit6yWJXKDWceVxSFTpUQ/meCeuZXJDmMWXRGq3AdSUZ9yWKYr3TWCIyHTYSWsG+0+HjMZ7TyAXmItrEUWc6tJPPOv8IdThOXvI2R9dJOdGPwXq2+XyBt9YIjccKOqxOQwtAUZ3RH9FMqwHhak9zbQOZFBmaBqMs0ZH7MscKPHnuIHe8b6PY08adCMx4s4CuGndJ0R+sb8FWfSSHsZZPA3RxVfYkvLAMUv4eBwoKagga8dX6MMGk8hIiyNwik1+nlQYT93kTt+UVKvNiQUzcUsXzCNWn3cQYYH8lWW+DsNCHfRSGp/mE3RPx9+hNBY8PLY01CCYSvd1+bHKRX0dTQMi8zeD3P+kUavW7EdaypZ4ibHF8LD4SqxERZxYaHVUkZphNrMaDVjE/p8DudYf6kiw4S3IBNB+UI06KDfCQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR10MB1466.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(366004)(346002)(136003)(396003)(376002)(39860400002)(451199015)(38100700002)(8676002)(86362001)(83380400001)(66946007)(4326008)(41300700001)(2906002)(8936002)(66556008)(66476007)(6506007)(478600001)(6512007)(26005)(107886003)(6666004)(186003)(2616005)(316002)(1076003)(6486002)(5660300002)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YrbWlSZaLeGsnobLIgVGyHryBrWCU9kgH+zSnd6RGwjOwaQX9K/4EsREXfxs7zIV3qSdTlYbkQM2kLMry6PMbmrv40Bbeb4yina71WamK/LoKqS+hInRQJ5B2cmCuvA/QOxY2ecg0iLziOpLu5Fo+TuSavCbE4qKM1rXTLzG1Uus4T1bYL9DOIOoCyQxcdLpmoCa5t9S0qmwkrw6Zdd0NepHNlCpdpqaiQDYiS2Kgo0tKKltqhnS18JzcPfGAWn8o0mbnzJNRylx5z3yzznxa0ASaCsE6q2QO137iSkJpwi93/xExGhdGvfr6DOTaZNMCyYkOJjpxETSx+oN6KEE/DtlCYLV1+IGMToa7S7raUBzRhsWyjL2bkhwfhzqynPwvSRBnUOPwafn857VtpndT2j/xFFNZ8robzBxC7viI2sB3BACYwCxfHBjsjX7tDhEdPpDiAR7xHbfNc52BLpfC3ZmuP8qyJFN4+AxHTkwe13WnPZ87hV2yRXbiIHB9W99XhCUuwYALvcOtDWgR57Kkpeo+/8u9Q1CJPCIOwZj8zstu+zNYUoo8J907+TCmMxKw6G6Vdrsgqf8IRmG3Smb6bt9pEAf0M1IjxdjzECFF1a/a7FTn8gtAyX805PIvvv9+xLEEggVk1Wc5Vkjht38orTDNdQmKLTPZbEDznb8d8G7IoIufN9klDWuXXxDGkz+kLsNw4/2564ucjIiYGBlgn9SFltS3pvKf0DYjjGFKOrd44Y9jiBgknD592tO7lwn5EWMzkITM+BbSrHQ9z16KtAOVpGBA0/RYGIuSYdlzSxaRXIp8s14MKLf6yp8LNXPC6TiLXVlLCpkXUMVScG2N2Z/N34za5sUxsMdq89Qj+LL47PJ5DVZE9NXXGhsspkwR2I8RSD30SJe54J4VL0oxy/QXlOzgpxOd4lJuN/pGOJ5IGVvuZS/QUoGm7VSdX96G8dczY8PyHi00ERqQEpyh6YA3E8SjzrOWHx3e7Pd2FVOqmpyIUDd+rdAYldZdRTkIo1l+Ex9e8Zvq2H7mIOqqj9HOWnfIWvADzdh8+YoNxSmBINSMAzFz0ar5WSpaPtgP8cqYPG28dF/pqEQvWBBrMHRgyN7vVmleXE14TlDQ03420RWE7aiRyHGrKc4YfFSywJ9vHZI2msERvkzYPzoBA29jO9IxI2HMlFpSy34Iq9ZZZpPp0qQFRcTsV5cAc+ZLFRESCugB3V7A3KNMRkLZ/M4sc6gZ/NMtwGP7QBM14XCXR0A2JLwal5wg5llk8+2wCdiAMW7fsgFxS3kZcr4yVSLUIm+sOnVBbNvD5FXvY1jEixHhUU0YvHjpzg/ziEZ4P30C/GGXedzCf/EINvF646ZAmupE1nM1TfMDWFwFuA7zBiKx3G9XlyaCSfPx0FPiwMHJVe7xnBoQrkpz89nzld3pCPneTbT7msXGOIEASFGrh9vGXMZjyzew+/L4RHj3SF97V80HJalp6tH1r1kLbPZTB6M1ykdvWrMRrKzj+yQqYAQ7TuK1md0WuSAWYYmMqHQG5TJWbcLVGuVYd4d2CrxFidx+/GOpLsq/IVi8gNdWu9j+ITTP3wr/5xQiXwGA6UXsCk3JYjya45uyeo8jA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7658c11c-e96e-4bcb-4e62-08dad8c9b64d X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 03:10:08.6298 (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: uAwr3zSP20qpWPKwyXw4x0e93MJ0F5P6yQgoxkBul3lJ73lxpECOIOPlXQ4lkaIMUSLTSIgiIy7FMNBebfjKVZXzMO167/Fc/VFAMGxw4jU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5132 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-07_11,2022-12-07_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 spamscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212080024 X-Proofpoint-ORIG-GUID: HlCWW4Jofqq11ZCZB-IgJnYNio11U_Je X-Proofpoint-GUID: HlCWW4Jofqq11ZCZB-IgJnYNio11U_Je Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org iSCSI needs to allocate its cmd counter per connection for MCS support where we need to stop and wait on commands running on a connection instead of per session. This moves the cmd counter allocation to target_setup_session which is used by drivers that need the stop+wait behavior per session. xcopy doesn't need stop+wait at all, so we will be ok moving the cmd counter allocation outside of transport_init_session. Signed-off-by: Mike Christie --- drivers/target/target_core_internal.h | 1 - drivers/target/target_core_transport.c | 49 ++++++++++++-------------- drivers/target/target_core_xcopy.c | 15 ++------ include/target/target_core_fabric.h | 2 +- 4 files changed, 26 insertions(+), 41 deletions(-) diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h index 30fcf69e1a1d..23e5d7847a1a 100644 --- a/drivers/target/target_core_internal.h +++ b/drivers/target/target_core_internal.h @@ -137,7 +137,6 @@ int init_se_kmem_caches(void); void release_se_kmem_caches(void); u32 scsi_get_new_index(scsi_index_t); void transport_subsystem_check_init(void); -void transport_uninit_session(struct se_session *); unsigned char *transport_dump_cmd_direction(struct se_cmd *); void transport_dump_dev_state(struct se_device *, char *, int *); void transport_dump_dev_info(struct se_device *, struct se_lun *, diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 60fbebe8c675..314e384f4ee6 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -271,24 +271,14 @@ static void target_free_cmd_counter(struct target_cmd_counter *cmd_cnt) * * The caller must have zero-initialized @se_sess before calling this function. */ -int transport_init_session(struct se_session *se_sess) +void transport_init_session(struct se_session *se_sess) { INIT_LIST_HEAD(&se_sess->sess_list); INIT_LIST_HEAD(&se_sess->sess_acl_list); spin_lock_init(&se_sess->sess_cmd_lock); - se_sess->cmd_cnt = target_alloc_cmd_counter(); - if (!se_sess->cmd_cnt) - return -ENOMEM; - - return 0; } EXPORT_SYMBOL(transport_init_session); -void transport_uninit_session(struct se_session *se_sess) -{ - target_free_cmd_counter(se_sess->cmd_cnt); -} - /** * transport_alloc_session - allocate a session object and initialize it * @sup_prot_ops: bitmask that defines which T10-PI modes are supported. @@ -296,7 +286,6 @@ void transport_uninit_session(struct se_session *se_sess) struct se_session *transport_alloc_session(enum target_prot_op sup_prot_ops) { struct se_session *se_sess; - int ret; se_sess = kmem_cache_zalloc(se_sess_cache, GFP_KERNEL); if (!se_sess) { @@ -304,11 +293,7 @@ struct se_session *transport_alloc_session(enum target_prot_op sup_prot_ops) " se_sess_cache\n"); return ERR_PTR(-ENOMEM); } - ret = transport_init_session(se_sess); - if (ret < 0) { - kmem_cache_free(se_sess_cache, se_sess); - return ERR_PTR(ret); - } + transport_init_session(se_sess); se_sess->sup_prot_ops = sup_prot_ops; return se_sess; @@ -474,8 +459,13 @@ target_setup_session(struct se_portal_group *tpg, int (*callback)(struct se_portal_group *, struct se_session *, void *)) { + struct target_cmd_counter *cmd_cnt; struct se_session *sess; + int rc; + cmd_cnt = target_alloc_cmd_counter(); + if (!cmd_cnt) + return ERR_PTR(-ENOMEM); /* * If the fabric driver is using percpu-ida based pre allocation * of I/O descriptor tags, go ahead and perform that setup now.. @@ -485,29 +475,36 @@ target_setup_session(struct se_portal_group *tpg, else sess = transport_alloc_session(prot_op); - if (IS_ERR(sess)) - return sess; + if (IS_ERR(sess)) { + rc = PTR_ERR(sess); + goto free_cnt; + } + sess->cmd_cnt = cmd_cnt; sess->se_node_acl = core_tpg_check_initiator_node_acl(tpg, (unsigned char *)initiatorname); if (!sess->se_node_acl) { - transport_free_session(sess); - return ERR_PTR(-EACCES); + rc = -EACCES; + goto free_sess; } /* * Go ahead and perform any remaining fabric setup that is * required before transport_register_session(). */ if (callback != NULL) { - int rc = callback(tpg, sess, private); - if (rc) { - transport_free_session(sess); - return ERR_PTR(rc); - } + rc = callback(tpg, sess, private); + if (rc) + goto free_sess; } transport_register_session(tpg, sess->se_node_acl, sess, private); return sess; + +free_sess: + transport_free_session(sess); +free_cnt: + target_free_cmd_counter(cmd_cnt); + return ERR_PTR(rc); } EXPORT_SYMBOL(target_setup_session); diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c index 49eaee022ef1..49a83500c8b7 100644 --- a/drivers/target/target_core_xcopy.c +++ b/drivers/target/target_core_xcopy.c @@ -461,8 +461,6 @@ static const struct target_core_fabric_ops xcopy_pt_tfo = { int target_xcopy_setup_pt(void) { - int ret; - xcopy_wq = alloc_workqueue("xcopy_wq", WQ_MEM_RECLAIM, 0); if (!xcopy_wq) { pr_err("Unable to allocate xcopy_wq\n"); @@ -479,9 +477,7 @@ int target_xcopy_setup_pt(void) INIT_LIST_HEAD(&xcopy_pt_nacl.acl_list); INIT_LIST_HEAD(&xcopy_pt_nacl.acl_sess_list); memset(&xcopy_pt_sess, 0, sizeof(struct se_session)); - ret = transport_init_session(&xcopy_pt_sess); - if (ret < 0) - goto destroy_wq; + transport_init_session(&xcopy_pt_sess); xcopy_pt_nacl.se_tpg = &xcopy_pt_tpg; xcopy_pt_nacl.nacl_sess = &xcopy_pt_sess; @@ -490,19 +486,12 @@ int target_xcopy_setup_pt(void) xcopy_pt_sess.se_node_acl = &xcopy_pt_nacl; return 0; - -destroy_wq: - destroy_workqueue(xcopy_wq); - xcopy_wq = NULL; - return ret; } void target_xcopy_release_pt(void) { - if (xcopy_wq) { + if (xcopy_wq) destroy_workqueue(xcopy_wq); - transport_uninit_session(&xcopy_pt_sess); - } } /* diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index 38f0662476d1..ff2ff7703aa6 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h @@ -133,7 +133,7 @@ struct se_session *target_setup_session(struct se_portal_group *, struct se_session *, void *)); void target_remove_session(struct se_session *); -int transport_init_session(struct se_session *se_sess); +void transport_init_session(struct se_session *se_sess); struct se_session *transport_alloc_session(enum target_prot_op); int transport_alloc_session_tags(struct se_session *, unsigned int, unsigned int); From patchwork Thu Dec 8 03:09:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 633208 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B30A5C4708E for ; Thu, 8 Dec 2022 03:10:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229815AbiLHDKU (ORCPT ); Wed, 7 Dec 2022 22:10:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229656AbiLHDKQ (ORCPT ); Wed, 7 Dec 2022 22:10:16 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CCF477209; Wed, 7 Dec 2022 19:10:15 -0800 (PST) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B7NOB1H003577; Thu, 8 Dec 2022 03:10:13 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-2022-7-12; bh=Vkl4PJD1/2l4zl+3/i/6zdJoiOXf3yaKzUulUDtrbfc=; b=udYiYjclfUpEaGZbV+2leTi2fz+Ek3yI1n5LzZ5PTgO34a64WAiJ18PzFE35c1U4bFwZ nLv4E9mrQD2N/FuMUf4mxem0ZRX7j5TYanpc1fhqseQrG9/8PpozHmEv9rgLI5tDAfED UXYVvuqm6rhqz75AdFPECh9yjKuo0ewArh0KbAZ/HnIlVAi5H7UEQTangUUsGaDL3jRJ cmRuL7iRWJJ1lgzRvscehTGmIyI7biC8aMQ5v1rMfNlc8XTB7PmrVaAmbbOu48B42lBj 28pXsAfhnheTNiJy49/xJP3Fdo22v/PYNYutCq3vKAc0Vy2oMp85bDIdB2vgkt0qOC3g VQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3mauf8hu9b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 03:10:13 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2B81cGc8001913; Thu, 8 Dec 2022 03:10:12 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2176.outbound.protection.outlook.com [104.47.57.176]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3maa7daqec-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 03:10:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T8RaROPOgDXyeuN0U8rVsZDTPxd81ow+eeVw+J5Qni1lDodQIG2aLBWRysELM6KRxIj8iEQUfLl6D1uquz5dCalK911GFxhbTYcgipMt54YO7Wbm+ohMlWQNenDSE0tci9g6Q1Ify3tLL6jH+6mTLBUEAF5c5JpLe6PsGccR90mWwrTa7jboPrPbJPJxhNNljvHOdwnBj3Y0QI1nr9yqyQeKTBRm2mV77tVNHUHh9NkxrsESY+w/tpxTqyrxGtghCholaSXZ3C8+vA9bC0pcODfp9QVz0CxxMo5IQ/VbkoOEKYH70kHgyw41wQak2c5d+mizXNXyW0QpcvHHgPg/zQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Vkl4PJD1/2l4zl+3/i/6zdJoiOXf3yaKzUulUDtrbfc=; b=KtvCH3M4hwZw2IS9GkS+hQcTx+ORfYfN7gccJ6HfhBpLSv/kpkE58tFwHqYdi2w0f/lc8PJph4VFVBTgwE90hH1P1hgUsrzp1rAAH2z9QWSt8TPJFZzqPZdZ6PVP3UuT3yR22hRZ1UI6MK8r4XYUxSPIv977EXRC8EfoHz9JcTM5NJqasplJUt6RNMHsW8hI6I0cBiFQHdNK45Ri+PMAdsO5KFyqmilt72tIrBKGh2xk3JAhTvhwaD51esHqTJtHBovUDlN7nUwKBYvTI6OjQMBloFozvRN942HYU0k1F9pO7vULX9BbIHhnum9Fesr+J6CczqwV2dozxZ5X3feacA== 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=Vkl4PJD1/2l4zl+3/i/6zdJoiOXf3yaKzUulUDtrbfc=; b=bLYS+FHxIKXGfvF76gWMMFVRF8I820df3X8QLz9A/jT72Y5DgBQTOt1EvVHjEcq6ZgFeFRvGaDc4wafFHbC2P4aK4XbvFC1xxD3FZfWNAqKNyekodcFg1iv6m6F3ndRZgq2+2AWQIVaTKfBVPW5P3oLB8TcCsgXgbXRJ5aCU6TQ= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by CH0PR10MB5132.namprd10.prod.outlook.com (2603:10b6:610:c2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 03:10:10 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::2dbb:4791:5a67:4372]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::2dbb:4791:5a67:4372%7]) with mapi id 15.20.5880.014; Thu, 8 Dec 2022 03:10:10 +0000 From: Mike Christie To: mlombard@redhat.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Mike Christie Subject: [PATCH 3/7] scsi: target: Pass in cmd counter to use during cmd setup Date: Wed, 7 Dec 2022 21:09:58 -0600 Message-Id: <20221208031002.106700-4-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221208031002.106700-1-michael.christie@oracle.com> References: <20221208031002.106700-1-michael.christie@oracle.com> X-ClientProxiedBy: CH2PR08CA0015.namprd08.prod.outlook.com (2603:10b6:610:5a::25) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR10MB1466:EE_|CH0PR10MB5132:EE_ X-MS-Office365-Filtering-Correlation-Id: 7375c6ce-3c26-48b6-5018-08dad8c9b758 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5tB78H7389SxvoGdT+4yleF17TMyXDq277QcLU0vHGGXnjJpefop9iJ19BFBIcT1soj3bPiDWDbXEyXNtsMNP+d8+eOGLtd+oLf9BHqt+3kQBnzb2MGbs6XH5kWjjZAuk04Ezw3G4dNa7aCno1l0lTeoFvXFzPcb/LfraK6Z3sYmW4Zop1InTtGP0XxatMBuKZuap30JaT6g0CYekvnyaTrxg+UOyHaMru2JfixL5wYaAHIV5oL4CmL4tx9S3xV09u2j2320nU2ROOJIBfxAYStWUVe8rTvb1sLiINzUDeiGi734Gpb2lcAa/OWgA4mCG+4Kdr1N4cRHvo+/BVRIoBSTY4GN3wVouk8UxD8L32oQhlPozRmSgHTvQ4h9u7SsSxF+rKT4s7nOrKV+AHHeVA4R9feGtTEaBh3MAoZnO1KiSrvxSnmTTE07RIjDaWaKdkS1U5F+hGgpoyO4WQLCIGZYzB36ry9FVKtHvB21iYjUMjBXI4mJbACeMxLCl5bu2GaFIHW/vtxjcJqKRCZgdfS+WG75j2LnlFVQQRwQym30OYiXXliwCPmIzfybtz7jhawiVsZz9kMOjx9ut9iLqPqQoovG3sFzuB3ITAfhhldhQns0CzqYo/+Qm0hZGnWiprmrJ1vc+2k82bXYLlKC4g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR10MB1466.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(366004)(346002)(136003)(396003)(376002)(39860400002)(451199015)(38100700002)(8676002)(86362001)(83380400001)(66946007)(4326008)(41300700001)(2906002)(8936002)(66556008)(66476007)(6506007)(478600001)(6512007)(26005)(107886003)(6666004)(186003)(2616005)(316002)(1076003)(6486002)(5660300002)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RL5auG8VfdtQElFoP5bXE/twesXtMRX6ulvf73KdOnBLYoxHdgO96pGNSZrz05OG9p6fsMGX7UsIJywEGwaRe9dlYrkerVfW/t+/rfkQb7N3TfBcyDrO6ZMyICDxWCpmIcGOH1WCl4G7f7Vm4aBINFaJ9S740pAXAjBX29vfsQBMtNyQDRA6DC61ODhsDK7+ukSsMCX1SUpA2K/KG1WqOCfubXx2piSTWK4551v2mJakt0aDl2FYq+Ht93ec7lb06R1Or3u9um1MmCfH5LFCLSxQkHdoHup/pEskKDTuK9aS/h5FIE+eQav9mK+BFg7Z9GXOoiFcPMYd+OVJNLPdfvHCmey7+q30h9GelWeAw5/APTaCoGauHQ9BOUtRowzgFIw3Xk6Sq4Zo3DaGM/oFnpUvzVAQ73Powd+BsKsvdIl9xeYrCg4VuONdiVls5xkpoFfZ1kQLQnJHtWsmJiCKSqWDgNfb5/E80IGcS9y1bLDXl2708ZYfdp2tUKuAHSxae4A/5eL0Lnf518wolxGjPDK0lL2NCkSvUxG8qdWFk9BkBY5zlPhLsuB7WdvmQW6ta0kHcbFRkwXTWu3bGZ4XsbZOr44fvC7ZTltnPxGvmHtMoBnK7SE/WaPLYvL0l4rzeUyq6h4Obr9Zlr9GelLbZFtlczqchIPEuVY2/4eeiIplQ6vYSUl0kiE/w6ZLXRBGF6uOFM7bW9ZTOTYe2FGVCHjipYekLKo6FjtA7PliuhnQiI0EVKTK5GJ9fHPNaFooiRFTMaf63ZfVZzBM8Go/Eonc85yRYFW3tFUaqAufU3uBeE2kVCrC1TlHpr+bDb1Kh6lsCXcu/YasW5u/svxwsY5l1g0LZEOMqXZpUnIJGoscdfHFHrjOcrLkzIVgqmsnxS2WsW3fpf/0+3TlzBkMgNNpdoGOiRY98Yvyw7PnFeYCHyrv3dwk88FUmSv5qNp/Vg/ha019HByvru6P4SQY+T8CG9jR+0Y7WKjoAjXQcS5WMyQuWbFLoI77egYIRv1ecTrso6kYxyZ+ggg9a/mOXheOs/bi6RZrsA9L0pQARq/BuYn65lfNqmvM9D2F0xM/xg7vm4weX3tF8thudMv4R2+oN/DfM/Ci3yfXm1WtQPqOS1lI4k/3j2EBA+WwrjkWqx5evIhU61wXQE6KU312uapqhzAqa7p87qqdzGPFdUlOssNlq3mQ1oqIHxWe8TuDupzuOEQeLfcLVW3guZNwVBBAvadkCAg4tmoSvs/5BAOUfAZpge0jGjF9EKehU/xUlSlldh8rgtD+nPPC6ayVRa6hPw50H/pDac4oeMgFEngch5DcdZqEycmt32ApLJRtInxdRbnv5M2qhbg/QZVOiswHGgK9pDkGU6svSAkE0Aswzl4W5J1enkv7JwqgYA+v1faDvptCMS5j42fHQpGim4FIhUm9WeWxCz0dViQ+HUkaxTXNgCisbGUolDOPEA2APWBn+fcQr+nkav9Id2O1o7fSle/3KEX+cG/0pZUbA30B3JSfijp6Zep3SvfRGRZAGaWiEG+WP/eadGZnSiSGEW2hb4qCujUJKQz0OQo2l+FH06ULUaQAcKxkJvYuEte5cX9M7QB8kIltDLIx2bL1Bg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7375c6ce-3c26-48b6-5018-08dad8c9b758 X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 03:10:10.4109 (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: +X37qdqq9B/7jVgB8/eW+V6Mw8Kucr8YW2owlt6g3hci2+MOMbN0mO+RN+WoRCHsDPZYDrM1YKYB22XkyquK7OCBmrAzN+y3m2hAuk4dbQU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5132 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-07_11,2022-12-07_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212080024 X-Proofpoint-ORIG-GUID: 9BHSk2WyUWA0Vw-sMt1LZXVZCuIiKF_C X-Proofpoint-GUID: 9BHSk2WyUWA0Vw-sMt1LZXVZCuIiKF_C Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This allows target_get_sess_cmd users to pass in the cmd counter they want to use. iSCSI will then pass in it's per connection one, and existing users will use the default session one allocated in target_setup_session, or for xcopy we do not use one. Signed-off-by: Mike Christie --- drivers/target/iscsi/iscsi_target.c | 5 +++-- drivers/target/target_core_transport.c | 28 ++++++++++++-------------- drivers/target/target_core_xcopy.c | 8 ++++---- drivers/usb/gadget/function/f_tcm.c | 4 ++-- include/target/target_core_fabric.h | 8 +++++--- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index baf4da7bb3b4..f5d498c522e0 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -1192,7 +1192,8 @@ int iscsit_setup_scsi_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd, __target_init_cmd(&cmd->se_cmd, &iscsi_ops, conn->sess->se_sess, be32_to_cpu(hdr->data_length), cmd->data_direction, sam_task_attr, - cmd->sense_buffer + 2, scsilun_to_int(&hdr->lun)); + cmd->sense_buffer + 2, scsilun_to_int(&hdr->lun), + NULL); pr_debug("Got SCSI Command, ITT: 0x%08x, CmdSN: 0x%08x," " ExpXferLen: %u, Length: %u, CID: %hu\n", hdr->itt, @@ -2055,7 +2056,7 @@ iscsit_handle_task_mgt_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd, __target_init_cmd(&cmd->se_cmd, &iscsi_ops, conn->sess->se_sess, 0, DMA_NONE, TCM_SIMPLE_TAG, cmd->sense_buffer + 2, - scsilun_to_int(&hdr->lun)); + scsilun_to_int(&hdr->lun), NULL); target_get_sess_cmd(&cmd->se_cmd, true); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 314e384f4ee6..0db70e265d02 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1443,14 +1443,12 @@ target_cmd_size_check(struct se_cmd *cmd, unsigned int size) * * Preserves the value of @cmd->tag. */ -void __target_init_cmd( - struct se_cmd *cmd, - const struct target_core_fabric_ops *tfo, - struct se_session *se_sess, - u32 data_length, - int data_direction, - int task_attr, - unsigned char *sense_buffer, u64 unpacked_lun) +void __target_init_cmd(struct se_cmd *cmd, + const struct target_core_fabric_ops *tfo, + struct se_session *se_sess, u32 data_length, + int data_direction, int task_attr, + unsigned char *sense_buffer, u64 unpacked_lun, + struct target_cmd_counter *cmd_cnt) { INIT_LIST_HEAD(&cmd->se_delayed_node); INIT_LIST_HEAD(&cmd->se_qf_node); @@ -1470,6 +1468,7 @@ void __target_init_cmd( cmd->sam_task_attr = task_attr; cmd->sense_buffer = sense_buffer; cmd->orig_fe_lun = unpacked_lun; + cmd->cmd_cnt = cmd_cnt; if (!(cmd->se_cmd_flags & SCF_USE_CPUID)) cmd->cpuid = raw_smp_processor_id(); @@ -1689,7 +1688,8 @@ int target_init_cmd(struct se_cmd *se_cmd, struct se_session *se_sess, * target_core_fabric_ops->queue_status() callback */ __target_init_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess, data_length, - data_dir, task_attr, sense, unpacked_lun); + data_dir, task_attr, sense, unpacked_lun, + se_sess->cmd_cnt); /* * Obtain struct se_cmd->cmd_kref reference. A second kref_get here is @@ -1984,7 +1984,8 @@ int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess, BUG_ON(!se_tpg); __target_init_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess, - 0, DMA_NONE, TCM_SIMPLE_TAG, sense, unpacked_lun); + 0, DMA_NONE, TCM_SIMPLE_TAG, sense, unpacked_lun, + se_sess->cmd_cnt); /* * FIXME: Currently expect caller to handle se_cmd->se_tmr_req * allocation failure. @@ -2988,7 +2989,6 @@ EXPORT_SYMBOL(transport_generic_free_cmd); */ int target_get_sess_cmd(struct se_cmd *se_cmd, bool ack_kref) { - struct se_session *se_sess = se_cmd->se_sess; int ret = 0; /* @@ -3005,11 +3005,9 @@ int target_get_sess_cmd(struct se_cmd *se_cmd, bool ack_kref) * Users like xcopy do not use counters since they never do a stop * and wait. */ - if (se_sess->cmd_cnt) { - if (!percpu_ref_tryget_live(&se_sess->cmd_cnt->refcnt)) + if (se_cmd->cmd_cnt) { + if (!percpu_ref_tryget_live(&se_cmd->cmd_cnt->refcnt)) ret = -ESHUTDOWN; - else - se_cmd->cmd_cnt = se_sess->cmd_cnt; } if (ret && ack_kref) target_put_sess_cmd(se_cmd); diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c index 49a83500c8b7..91ed015b588c 100644 --- a/drivers/target/target_core_xcopy.c +++ b/drivers/target/target_core_xcopy.c @@ -591,8 +591,8 @@ static int target_xcopy_read_source( (unsigned long long)src_lba, transfer_length_block, src_bytes); __target_init_cmd(se_cmd, &xcopy_pt_tfo, &xcopy_pt_sess, src_bytes, - DMA_FROM_DEVICE, 0, &xpt_cmd.sense_buffer[0], 0); - + DMA_FROM_DEVICE, 0, &xpt_cmd.sense_buffer[0], 0, + NULL); rc = target_xcopy_setup_pt_cmd(&xpt_cmd, xop, src_dev, &cdb[0], remote_port); if (rc < 0) { @@ -636,8 +636,8 @@ static int target_xcopy_write_destination( (unsigned long long)dst_lba, transfer_length_block, dst_bytes); __target_init_cmd(se_cmd, &xcopy_pt_tfo, &xcopy_pt_sess, dst_bytes, - DMA_TO_DEVICE, 0, &xpt_cmd.sense_buffer[0], 0); - + DMA_TO_DEVICE, 0, &xpt_cmd.sense_buffer[0], 0, + NULL); rc = target_xcopy_setup_pt_cmd(&xpt_cmd, xop, dst_dev, &cdb[0], remote_port); if (rc < 0) { diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 658e2e21fdd0..c21acebe8aae 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -1054,7 +1054,7 @@ static void usbg_cmd_work(struct work_struct *work) tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo, tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, cmd->prio_attr, cmd->sense_iu.sense, - cmd->unpacked_lun); + cmd->unpacked_lun, NULL); goto out; } @@ -1183,7 +1183,7 @@ static void bot_cmd_work(struct work_struct *work) tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo, tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, cmd->prio_attr, cmd->sense_iu.sense, - cmd->unpacked_lun); + cmd->unpacked_lun, NULL); goto out; } diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index ff2ff7703aa6..ddfe2070708f 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h @@ -149,9 +149,11 @@ void transport_deregister_session_configfs(struct se_session *); void transport_deregister_session(struct se_session *); -void __target_init_cmd(struct se_cmd *, - const struct target_core_fabric_ops *, - struct se_session *, u32, int, int, unsigned char *, u64); +void __target_init_cmd(struct se_cmd *cmd, + const struct target_core_fabric_ops *tfo, + struct se_session *sess, u32 data_length, int data_direction, + int task_attr, unsigned char *sense_buffer, u64 unpacked_lun, + struct target_cmd_counter *cmd_cnt); int target_init_cmd(struct se_cmd *se_cmd, struct se_session *se_sess, unsigned char *sense, u64 unpacked_lun, u32 data_length, int task_attr, int data_dir, int flags); From patchwork Thu Dec 8 03:09:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 633207 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53649C4708D for ; Thu, 8 Dec 2022 03:10:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229890AbiLHDK3 (ORCPT ); Wed, 7 Dec 2022 22:10:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229742AbiLHDKR (ORCPT ); Wed, 7 Dec 2022 22:10:17 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2755E73F71; Wed, 7 Dec 2022 19:10:17 -0800 (PST) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B7NNtm6015205; Thu, 8 Dec 2022 03:10:15 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-2022-7-12; bh=BsP7tfVGMXjys0IoHNvkNmLrNNlT/AJq5BxMS4cn9ok=; b=haMSK4nVCetPnS/7qymvkqf2Sym+uiGa0B8WYpFRQ5DRjVcnpzM6aWs4A88i39q1OFxz knpj/Qt3BySvTrHgaA1imIqLrFSmCOAuhSHNq9Y2pOL/J3uHKtUfYDVp/lqrox6pmnd9 90ZWjqFPt6YqiCnHsMJM/l7i/RWZsVK+V9aT6/d/RuIXOQ7Av4OesR4qNW2u06aPQ6Xv BVpM9fUWE8l47BJ6ueiZcGASxOabSBmgmxD6e9zbnsCk2FQjz/5HtHJybs/R3i4si17j ARTw5GVsfqLnKQW5Er87JpjmXxm08gFfV6J6sF2Nb8d0YRkdxWrOuHhkBvs9xukEUFR2 VQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3maxeys1e8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 03:10:14 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2B82jsld017083; Thu, 8 Dec 2022 03:10:13 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3maa5yv0q3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 03:10:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mhA14n/XsfLjXrVe2k/AnqzUHYWPYrjcVJUfBHs7vq932HL5yhHSZ4YbCAdW6IAnb754+lNO4fdLpAye1dW8DAhJqNTZSZpLW0expu3p/sMROryXXfB167r6vCv3myy+3fJNPauxP9BRTZyiqDGxaIy+/xAlRR5/NOEDhmnSt3pGcVWqdp76fsFyFzBzagYlaHY/rlkleT45fAjvjPMHgfYg1OyrpcgLIjzFK7611tdHDxZocx7jSjcZsRkUfwihRMCCXLhsw22rzOSYZeTOAWs2hfUJWEArxEBaN6krl54/48ghoxtQ2TRaWPKIXXc8Rw9h0di91JdrODu5OPWNIg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BsP7tfVGMXjys0IoHNvkNmLrNNlT/AJq5BxMS4cn9ok=; b=Rxz0SrX9itB9K4AGRMIZ5+kB5Kp4lq9YwtWBMc97NybjpcEJM20uTy2EbRpAVnH7RqNxFM4mzWQjBjP4Re/4kDU/T+T6OO9b2tUbZAx4Pt3PTov6MTaLNq9BUrBM+ahX42P6tngIlkq3vINV6f+x13zIl0GhDBCQeqKwlwZxXWDHeTW3bBpvZ68KA/RMnRsofr6dox3b1Kzn9q2tg7sx49FkYBcAbT2toGYkhrR05g9YhcmXSg0R+KCoOtChQ0QCX502uXsr1/oWn9UWVnrftkDqVjWYGqG7Jv9CyhQGialOBWsRbQGgc65gWdvUPFkNGzXlqZHrpUI6923tPZ2rbw== 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=BsP7tfVGMXjys0IoHNvkNmLrNNlT/AJq5BxMS4cn9ok=; b=Nn1YIFnVFN7UnbUpNvWPqU1J2V7pcqfSMJoy/j9bh3seocXUX9/SWxwk+mE71TcISHCeBTma0ChYeMPgYjGWe5iRs9VaXsqWbg8u+h4Y5P4lFs2OY+FuosOEaa2PWhfUJQC6a1IyBQPb6cg6RhOwET2itHa6uNcb7GrqtvijBe0= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by CH0PR10MB5132.namprd10.prod.outlook.com (2603:10b6:610:c2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 03:10:11 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::2dbb:4791:5a67:4372]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::2dbb:4791:5a67:4372%7]) with mapi id 15.20.5880.014; Thu, 8 Dec 2022 03:10:11 +0000 From: Mike Christie To: mlombard@redhat.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Mike Christie Subject: [PATCH 4/7] scsi: target: iscsit: Alloc per conn cmd counter Date: Wed, 7 Dec 2022 21:09:59 -0600 Message-Id: <20221208031002.106700-5-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221208031002.106700-1-michael.christie@oracle.com> References: <20221208031002.106700-1-michael.christie@oracle.com> X-ClientProxiedBy: CH2PR08CA0015.namprd08.prod.outlook.com (2603:10b6:610:5a::25) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR10MB1466:EE_|CH0PR10MB5132:EE_ X-MS-Office365-Filtering-Correlation-Id: 0ffd047b-f84a-4acb-685f-08dad8c9b838 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vujWvq0SZOOqiaSQhJItI90v55PQh5XflBJc5nG95BXWZpn3+8cJiODVT5fpEZwDk9lEOqyKnW2Rv/2f95A2mevjvjM4giWRJ2fgPJG9YJxGFvrv6FbfM4fxbLUWQV+o3QNDFTZpDY3E2b7S2VxRdNqW0sTiJEZR2vnM36wwyu/kr9vlFqvDN+hBkFWTxrCDXeXi2ON10KYDDbS2wV8ZmeBF5NGoCft4W/HjYr3yjcYRQbICqs/wNJsPs798U35xnA7Hs+Grn7pBGYSZLI0p/rco9pvkLwC07IuTiCnhQLsAHJ+zSg7vXfy5UA0eAoD87zcgmgH0DD/7iBqhiLO3S/U3EFBlOD6WHpawbpbjze2DIzsKpzARG4bfS7yVTGPbbmis4QRyKKP6jYVVWXRBtqaNvA/qFCGFqiMNd8FWKhsZeA3sy0DWD0jjgZQnz+/q39ytD11TLwlJASC/LyJ1xr9domVFAgZMO9GXbcKQfDhWIyCZaFOoOzZlelCWorndBAWKznFL0wRtsMp1e2WGctij+Nqj9f5Hm3M9dLLwlOEAanv+383OHyCL19FdZpKPFNrjCIAAcpU09Cj2uvkuKtBS13/UYK0BVepdMleBnpVmw7mhebiRr2bzySTlT0XwQrZCTgrmIh3Pwq0G0skljw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR10MB1466.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(366004)(346002)(136003)(396003)(376002)(39860400002)(451199015)(38100700002)(8676002)(86362001)(83380400001)(66946007)(4326008)(41300700001)(2906002)(8936002)(66556008)(66476007)(6506007)(478600001)(6512007)(26005)(107886003)(6666004)(186003)(2616005)(316002)(1076003)(6486002)(5660300002)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uYwnQ9bHdMqFy/j8tFA7pXgRId9S5GxZczQauT1E0HUXMLdDWveNeXEH4ulFlwg2hh//M1LveUQMjJn8pOT3zwH4uKLSFkPauGSdPVOfgNA5C4ZAfRCe1TVqDy08g+faigE2kwS0bFbEUyhJ1K5Ifx4z+wdL6moFy2NSZDOnkA3UMzXYeIfh3qwrka220bpN2B8dD3dJ6SKmVuUa7w2FZdaSdJCqCKvV//ZRrk/Uf2NHUMCP9ueSa18d7sArVB4LUMMbIZijjmVxmEL5e60qYIRA1/ojvqmt0zPkBiZkwkUHVGdjaMU8gg80NUirxzUEFsOUoAqfdSgdxviGTgoOrEvh8mMCIOqiBbKktgvl0KutxmkuRTmP12H1yVlpsf5qhfpU63VjIEl5vc607pKE+1ZNt5rD1vDMdDCr30UEiXksKL4iy2r7XkhbtQzcjgh41bSG7ettqd522iD3XSX3oe5pYxVV6hhnA3Z7SqWSHuGdSfwAQj4y5WS4nxdfp82aRZiQEHC/NvlBx+imv3E7eK6TOrJJIutCPZfgCCeJUejPMRq2NyfwQPBw6xpZg9NC8u38lmvD4d9IAIW530tfpUrs9q0ONvcK9DY+W+RlhqeJ3DTWCzz2EgS1m+EdNYr11I88KOLnNadu2Mq7LefGZhQme/ja0YV0B3Lebg2QufcVRga4moB8hJJdDBmLZAC9AuOAm1/C6d3/C5QvE9QppcqfgFfik3gSwd8i2fbibNtczO3mF4dW+ulFqboXEF8TXHqGX6Apr4bI8IbIL5u2gQtHXAaBQS1FNc8xGqYTwSiibE7blZ6jvox1oGAKfyO9Bk0QIb8zt5IbKgs59MEj4C0BzvFWvEprzHkBxUlJFgin71bs9PPvA5m5tezkAXgufsmuMLO0WVU/0uFyGwSfSMVLEdDftFioZfKAN0lOUjarCmtoVz+ecbVtgfglJfVkDfJ6oKCGywch/zZb6eBiC5tVwtVRdPYJ+NtybH32cNVGDD5yB9tZNrNuGRdPTy7qhvtS63cz7TXhO2z1MLMg86w8iIhc5WsACncbxuln6Ln0Eqe6b3DHMBcGGHeS6BYZbYSGJuWe1KN1jclWsqt9nx3DNt1O1Hj/Rdy8uManzKrmVWd00hwNXWS64TrN2Dm+8YMKMr5pEcOj0kacekKinIDbYVVVLEilNHAwQgwUJL49mW8KlyWkE75SZXlQI86nEjPJysEzZsE9HCe5QbUsfNUKRD57IorijoUvbsm2VAFQueVvbyCNMcqrOByTRIGR29WAyX1bYu37cc0IDJRPnIHtX08PlFKDEuIh4mZlOOPg5GPKrW4iPHroh+izFSegbDIyiKbVQFYJHj4wOq4x0E0Ywf4VTSYqTDcKSuSjws9RYSzzQCnDfa2+k5vn48Cs/yD3pAzSbbiSHfWiDoXlYsAyODIX6f+PvkdIgwVTzpVaQoYjpAMoPlgu/Z2ocEvD7GKU8RKtXNDYlcxszhbJhwn/dVayH+wuE0lQdUcYt68aOwqiMhf2+5fWmmZgI/P8o+p6HhnRq0KJvCdz+m73n0+u3WTj5rjBP9LbFC8ADEx9uoIwt2y8XUxP/c67Daj1GwKCajxzvQXegit4aNhblQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0ffd047b-f84a-4acb-685f-08dad8c9b838 X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 03:10:11.8483 (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: qe6iBwWHxBq+7Os44RGhO1tXFZtySSNLn6DDbGNYQSiLX6xcgZkOdJbBHtWWfF24Dz9BuVhnlgjxvPFRsUCHQJcIRSGQ02JMc/zTOoCirJY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5132 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-07_11,2022-12-07_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 spamscore=0 bulkscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212080024 X-Proofpoint-GUID: gqzrP2aJcXgkPGnPyZCyUJM00i-SZmi7 X-Proofpoint-ORIG-GUID: gqzrP2aJcXgkPGnPyZCyUJM00i-SZmi7 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This has iscsit allocate a cmd counter and use it during command setup, so the next patches can hook iscsit and iser into the cmd counter stop+wait helpers. Signed-off-by: Mike Christie --- drivers/target/iscsi/iscsi_target.c | 4 ++-- drivers/target/iscsi/iscsi_target_login.c | 7 +++++++ drivers/target/target_core_transport.c | 6 ++++-- include/target/target_core_fabric.h | 3 +++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index f5d498c522e0..7a8ffdf33bee 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -1193,7 +1193,7 @@ int iscsit_setup_scsi_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd, conn->sess->se_sess, be32_to_cpu(hdr->data_length), cmd->data_direction, sam_task_attr, cmd->sense_buffer + 2, scsilun_to_int(&hdr->lun), - NULL); + conn->cmd_cnt); pr_debug("Got SCSI Command, ITT: 0x%08x, CmdSN: 0x%08x," " ExpXferLen: %u, Length: %u, CID: %hu\n", hdr->itt, @@ -2056,7 +2056,7 @@ iscsit_handle_task_mgt_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd, __target_init_cmd(&cmd->se_cmd, &iscsi_ops, conn->sess->se_sess, 0, DMA_NONE, TCM_SIMPLE_TAG, cmd->sense_buffer + 2, - scsilun_to_int(&hdr->lun), NULL); + scsilun_to_int(&hdr->lun), conn->cmd_cnt); target_get_sess_cmd(&cmd->se_cmd, true); diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c index 27e448c2d066..274bdd7845ca 100644 --- a/drivers/target/iscsi/iscsi_target_login.c +++ b/drivers/target/iscsi/iscsi_target_login.c @@ -1147,8 +1147,14 @@ static struct iscsit_conn *iscsit_alloc_conn(struct iscsi_np *np) goto free_conn_cpumask; } + conn->cmd_cnt = target_alloc_cmd_counter(); + if (!conn->cmd_cnt) + goto free_conn_allowed_cpumask; + return conn; +free_conn_allowed_cpumask: + free_cpumask_var(conn->allowed_cpumask); free_conn_cpumask: free_cpumask_var(conn->conn_cpumask); free_conn_ops: @@ -1162,6 +1168,7 @@ static struct iscsit_conn *iscsit_alloc_conn(struct iscsi_np *np) void iscsit_free_conn(struct iscsit_conn *conn) { + target_free_cmd_counter(conn->cmd_cnt); free_cpumask_var(conn->allowed_cpumask); free_cpumask_var(conn->conn_cpumask); kfree(conn->conn_ops); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 0db70e265d02..90e3b1aef1f1 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -228,7 +228,7 @@ static void target_release_cmd_refcnt(struct percpu_ref *ref) wake_up(&cmd_cnt->refcnt_wq); } -static struct target_cmd_counter *target_alloc_cmd_counter(void) +struct target_cmd_counter *target_alloc_cmd_counter(void) { struct target_cmd_counter *cmd_cnt; int rc; @@ -252,8 +252,9 @@ static struct target_cmd_counter *target_alloc_cmd_counter(void) kfree(cmd_cnt); return NULL; } +EXPORT_SYMBOL_GPL(target_alloc_cmd_counter); -static void target_free_cmd_counter(struct target_cmd_counter *cmd_cnt) +void target_free_cmd_counter(struct target_cmd_counter *cmd_cnt) { /* * Drivers like loop do not call target_stop_session during session @@ -264,6 +265,7 @@ static void target_free_cmd_counter(struct target_cmd_counter *cmd_cnt) percpu_ref_exit(&cmd_cnt->refcnt); } +EXPORT_SYMBOL_GPL(target_free_cmd_counter); /** * transport_init_session - initialize a session object diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index ddfe2070708f..4cbfb532a431 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h @@ -133,6 +133,9 @@ struct se_session *target_setup_session(struct se_portal_group *, struct se_session *, void *)); void target_remove_session(struct se_session *); +struct target_cmd_counter *target_alloc_cmd_counter(void); +void target_free_cmd_counter(struct target_cmd_counter *cmd_cnt); + void transport_init_session(struct se_session *se_sess); struct se_session *transport_alloc_session(enum target_prot_op); int transport_alloc_session_tags(struct se_session *, unsigned int, From patchwork Thu Dec 8 03:10:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 632166 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06EA9C63709 for ; Thu, 8 Dec 2022 03:10:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229714AbiLHDKf (ORCPT ); Wed, 7 Dec 2022 22:10:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbiLHDKU (ORCPT ); Wed, 7 Dec 2022 22:10:20 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4633D7720E; Wed, 7 Dec 2022 19:10:19 -0800 (PST) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B7NOYFT016849; Thu, 8 Dec 2022 03:10:17 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-2022-7-12; bh=tMEturm9ATL46t8iTK9TWpa4sFH9MXGZtnEz2lAVJYY=; b=CauN4DyTO+5o7Yz+rTSf1t0B5+2L8opd9o4vafobXDiXl0Xj1VY+tklV5XFLgjGr47Uq /PsWbeij13NsDXnr1LGlDte+7tZgvgydtSkFWdU5BkOixsIdJs8YvD+fonff4kjUofU4 v8Py6IkyUiz1R/tSh6J6Uk/icP9+LgKvq147SJWBKlMwEhg7k5chzabXghXAZnRgdju0 7oLMPq4qlz0NfYeo0SeU2g8S34cEte+GAAdNWmFoXPqhegTHdHf3qSsQhQR6D69Em3Dw +/a+jHP0GWBhBAoeXNtYRPhgp+biY+GeDA2mhxgDOb64WkoPNbD4jK0MlKg9t7vhyhS5 vw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3maxeys1e9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 03:10:17 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2B81Q6h8033770; Thu, 8 Dec 2022 03:10:15 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2173.outbound.protection.outlook.com [104.47.57.173]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3maa7xmkt1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 03:10:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TtP8BU9bkkBaO6p/J8gMrcOtgVDeD00fgknnVC1wNr+n8WqinOgwWV4q+yeD6dS7GtjVafLtoz5pnPcNboU4GjpQgNzNQwktt/kmRdzoFrUTMej5VrcFKgiWhDVG4XWKZGBKNanyceeOlETnSoUTLidLkFB0YLQB1VPc5SAy4vhX0bNY9ANJBagr1YQI6/9cHs3Y96xGG6YiibR+EMnzTU8/P3L9xQg6iiEdoHV0rmM2LPIpyYzzmd7rIDkU3Cc/joFU5Y3KstXUx3PMbXLzIW0sNQnvZ0MzsP0i4iCtAv6TMjTskciqGE0YSCLcisG6DPI2EavFkVhmW9iGriSNhg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tMEturm9ATL46t8iTK9TWpa4sFH9MXGZtnEz2lAVJYY=; b=AdWZIepNCEOx4+R6D7Rt2P20NDX/bTScCTFsN298edICxrppxTfciGsrBTGRBTsNcHdiBGJgISZGfgc91vD7njqHahqz+6JwuWwq/SpPjLdLQkEkMOQOPPv6mvhh6qDC0hpXTvaIlrg0FO0Qmtjeb/xWP0Yxi+rNbLkckbU2RAOw89yfNzDd9Xp4HwYH4yEG9r/BubhzrVkqHXG9/lOrE5Zb65UNJCgIcbz6rh6oRwBq7MZN31q3Ofqo+FuUYyfYCy0QlaqHAu1UGKqJ3fk5IAWHN1YdZIIoW2WMx9TL0p+OMA3x3fC2QRmfynPHYAxADVkNnHAOzdK+8GsTVmmohw== 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=tMEturm9ATL46t8iTK9TWpa4sFH9MXGZtnEz2lAVJYY=; b=S/JbMxDZPtU5LpD+pYF53WNp7z7yCW+mhcwU+4P3Jk8vuOlZU4lMh5n8g2OIUxuwBEBCKSDQCO6SO8mugl1IL6qzP93P87vHKfpgOPghXw6Z2vEhel9tiqccQcMY+7zLL5qyYeWDFPn9B3PAtiJvNIzt+RYMYUUa5lHIbsKdSHQ= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by CH0PR10MB5132.namprd10.prod.outlook.com (2603:10b6:610:c2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 03:10:13 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::2dbb:4791:5a67:4372]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::2dbb:4791:5a67:4372%7]) with mapi id 15.20.5880.014; Thu, 8 Dec 2022 03:10:13 +0000 From: Mike Christie To: mlombard@redhat.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Mike Christie Subject: [PATCH 5/7] scsi: target: iscsit/isert: stop/wait on cmds during conn close Date: Wed, 7 Dec 2022 21:10:00 -0600 Message-Id: <20221208031002.106700-6-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221208031002.106700-1-michael.christie@oracle.com> References: <20221208031002.106700-1-michael.christie@oracle.com> X-ClientProxiedBy: CH2PR08CA0017.namprd08.prod.outlook.com (2603:10b6:610:5a::27) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR10MB1466:EE_|CH0PR10MB5132:EE_ X-MS-Office365-Filtering-Correlation-Id: 1264909d-307e-46eb-67f4-08dad8c9b962 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 40j6Te1oOYHrkecpQpdoths6oGDOUT+oeHqDsjhUzAZCsVSrZng9gkx6beeU0rkRg+W8tif94nH/O3t9WCjuWbHVWrmlwcgZcdafGL0qqeEuVQcLoxjuGexQdN7Wbzyk2XDJKMird9+PY614Vm+KglPeKBo7ybVEi60FeqJmi4XmDW9qB9z0QP6tc0nTiuJwnzYCkJ4bm4KGqYGEtt/xD37JtVGC1NnN0m0H8j/gmUid+oDc0AZOJJJSHSRiy3+BrhlrLDJuppP2Q8flV3j7lxQ/AlEPBo/JEzLx2bSvN3l5gXwiQjY3nss7QWfbDo5zZsoHl8ToEExMs683yEBWdplF74do0ZzBhaqrSaikK/59YUXLBAs9lI64oLL+KrMbbl3Q6c+MWecypIt5MprHawi7GSo8pyuq2h9LWiWJq6D3uA6Xy3WOd8y0THVBbpZzQYvc9RgPSuqQ5ZMCJdz8BoQoYV6WI6086MKCrRg7mGkP8BdpE5Erye+dQQoDljdks/2WaaXyDSmSjV4jhwNTjK97Sv8Z9b3Hp1Vdy9Di42zn9KV4OFkFSEAor8m8F4x9gDzGjAOhvHE9KkkO91En1VmhYOtehStMQwoaaxX+wGN4xxbHKeYEbsF/A7vocRPrJu6YesdmoREMJh0Cv2/ERA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR10MB1466.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(366004)(346002)(136003)(396003)(376002)(39860400002)(451199015)(38100700002)(8676002)(86362001)(83380400001)(66946007)(4326008)(41300700001)(2906002)(8936002)(66556008)(66476007)(6506007)(478600001)(6512007)(26005)(107886003)(6666004)(186003)(2616005)(316002)(1076003)(6486002)(5660300002)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fbRS8zguuxeIQbxVGduGuuPkFqjsmUTE7GHy8O4ZluNLzlhH7Gz6qXDl6unlgYzUIXU0/xJ6wHBWGoaIxq6Dczux/l96yWCIPdI8tQ1QRAIM05/01X91068I+vtPot7Sqxt1ljaod7oio0E1qne57/t+hVTqI85/YfLjxb5W/cemLzBu2Q9Ft04t9gAX9SzPyy1CR548dAYxCYCcinIe6yXnBHgxj+Nz5lLMjoe0Vwge/6qQqxi548cV7hIDdQVeRUWA+X/tkTPEN7kuxRXUT7B+604gvjHGKmapxhIDc6OcdG/MdPptnLibka2m2oJ7MRN0GaCqU1U4BXJmpU6wBtZuCYvTqux+FMKdh4duS9/hGii92tuzcYlT2zA43GtOQcH9CIS8uyD7mwfvWJ/9ES3UYBD6RJBd+H2mUL3YRHm9jXHN4jyQFld+CDFX05bCsDHvWXbydK84vSDB7LXiraPkWEz+dTKJgUYP0a1xXS2LB5SGtGydtmesAHQv4P6Yc7a5CVO7xUA5kJgMksW8lDB6koGdSKBvvwQtqP1EIjezFZ4ih6dGjHMP4kgMqSBs8G/NVQXQQrYKq9wQ6jBM2wOpazu++rRJCDrd3tHG1K+hYvJZS+WXybCY58QgQKyDdgcmxykhGcN+A7xLi3H+2T9Aj6Jx3C8Ch/3XLbXociOgK7V3iROJptEEEB5aAAuZR5NF6rFsgtktsATafTEGhNnga4eMfx5eXubWgKUg8Rjgi8kMYWfRJtCypdk5zV6ZR3vKDJwqxSEDv+zVydpiwSUljNqm633Ug7ML2e836CtAaLWDvq5kno4eRPI4bueCBbb3vBdyxv7eVFazSJ46NmYkkmrQJVVEI7MXTOixX46AdxnkFDwaQwNXYqN1Vu4nYfY/5YBmNjS9szvmfE5DmcKgOY3DnqnKtxzctA1yIp40x+d8Cab3O/TE96fnZmwrZQxE+tjf4uchKxXHowShj7tPeDXBRPOrbZgajcEbSCg5OickvonbOgAKtj4N/KpkfWcbvU1NtKHzUICu7edK9NWlxmh21CGdZzqCeKHv+mr0HI5DTKb3mb1Nljn9uxwxTENoJ1cwo4X3W0lMId/tHV77jix6/sjPMYKTFImlnnzDhSSWmshOsPEBQcqBo+iIz9WVPrmJxEGzDMfTfSuxw37jh/s82Wiyw96gHa3pfuIucBARQ2OsCNbaCm5od6Hz+7AydLIzLNL1qM3ThXsgotwl9yAEWa+BycGOkQ0DNjZMj++HhbT/Z4iD6qtXWvPiJUbqND77AJT95mcaYVG9giSx/bYsi0tQBdGRhMJ4D5Il2ZaLynmZlFpKYtdMJrmkM+sbU4GaAgXBh78Db336yKWP8SmPuDK911ypRRTpL1yHXr4EgZvdu2+2669blGvpRavKhyccAeRJubKKnJL4qzr0wJC6LypoxRR58jzEKSdhQWwoDEe1mjaOXMTXF5PJO2fiDJCt8xkDV3CH8eRW8WCAutvefHsn972wkH5Bl9xdf8e97oSPAv/sIzomq4jh1RMJbR0Bco3tuS9aqbNgNbLEsrO/6FS2rvLl0811tYGu2gknALdkrP2dltjEzq7BebO1f85hkNnl/yw91p0EKg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1264909d-307e-46eb-67f4-08dad8c9b962 X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 03:10:13.8012 (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: 7Wdeavs3ThpSRJygqqdfbtc4RbNueDeT/4lkNkcx1jM44SN5KQNSrlS0UHF+9GGkzLSTmK4Wk/6x0+H7MM49gMLzdJMgxxb6FEZAcgV5tLc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5132 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-07_11,2022-12-07_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212080024 X-Proofpoint-GUID: N4OkJQWJdnWkrpNTYibFJy1QzxxPy10I X-Proofpoint-ORIG-GUID: N4OkJQWJdnWkrpNTYibFJy1QzxxPy10I Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This fixes 2 bugs added in: commit f36199355c64 ("scsi: target: iscsi: Fix cmd abort fabric stop race") If we have multiple sessions to the same se_device we can hit a race where a LUN_RESET on one session cleans up the se_cmds from under another session which is being closed. This results in the closing session freeing its conn/session structs while they are still in use. The bug is: 1. Session1 has IO se_cmd1. 2. Session2 can also have se_cmds for IO and optionally TMRs for ABORTS but then gets a LUN_RESET. 3. The LUN_RESET on session2 sees the se_cmds on session1 and during the drain stages marks them all with CMD_T_ABORTED. 4. session1 is now closed so iscsit_release_commands_from_conn only sees se_cmds with the CMD_T_ABORTED bit set and returns immediately even though we have outstanding commands. 5. session1's connection and session are freed. 6. The backend request for se_cmd1 completes and it accesses the freed connection/session. If session1 was executing only IO se_cmds and TAS is set on the se_cmd, then we need to do a iscsit_free_cmd on those commands, so we wait on their completion from LIO core and the backend. If session1 was waiting on tmr se_cmds or TAS is not set then we need to wait for those outstanding se_cmds to have their last put done so we know no user is still accessing them when we free the session/conn. This fixes the TAS set case, by adding a check so if we hit it we now call iscsit_free_cmd. To handle the tmr se_cd and non TAS case, it hooks the iscsit layer into the cmd counter code, so we can wait for all outstanding commands before freeing the connection and possibly the session. Fixes: f36199355c64 ("scsi: target: iscsi: Fix cmd abort fabric stop race") Signed-off-by: Mike Christie --- drivers/infiniband/ulp/isert/ib_isert.c | 13 +------------ drivers/target/iscsi/iscsi_target.c | 13 ++++++++++++- drivers/target/target_core_transport.c | 6 ++++-- include/target/target_core_fabric.h | 2 ++ 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c index b360a1527cd1..600059d8a3a7 100644 --- a/drivers/infiniband/ulp/isert/ib_isert.c +++ b/drivers/infiniband/ulp/isert/ib_isert.c @@ -2501,17 +2501,6 @@ isert_wait4logout(struct isert_conn *isert_conn) } } -static void -isert_wait4cmds(struct iscsit_conn *conn) -{ - isert_info("iscsit_conn %p\n", conn); - - if (conn->sess) { - target_stop_session(conn->sess->se_sess); - target_wait_for_sess_cmds(conn->sess->se_sess); - } -} - /** * isert_put_unsol_pending_cmds() - Drop commands waiting for * unsolicitate dataout @@ -2559,7 +2548,7 @@ static void isert_wait_conn(struct iscsit_conn *conn) ib_drain_qp(isert_conn->qp); isert_put_unsol_pending_cmds(conn); - isert_wait4cmds(conn); + target_wait_for_cmds(conn->cmd_cnt); isert_wait4logout(isert_conn); queue_work(isert_release_wq, &isert_conn->release_work); diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 7a8ffdf33bee..1c3470e4b50c 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -4221,7 +4221,8 @@ static void iscsit_release_commands_from_conn(struct iscsit_conn *conn) if (se_cmd->se_tfo != NULL) { spin_lock_irq(&se_cmd->t_state_lock); - if (se_cmd->transport_state & CMD_T_ABORTED) { + if (se_cmd->transport_state & CMD_T_ABORTED && + !(se_cmd->transport_state & CMD_T_TAS)) { /* * LIO's abort path owns the cleanup for this, * so put it back on the list and let @@ -4244,6 +4245,14 @@ static void iscsit_release_commands_from_conn(struct iscsit_conn *conn) iscsit_free_cmd(cmd, true); } + + /* + * Wait on commands that were cleaned up via the aborted_task path. + * LLDs that implement iscsit_wait_conn will already have waited for + * commands. + */ + if (!conn->conn_transport->iscsit_wait_conn) + target_wait_for_cmds(conn->cmd_cnt); } static void iscsit_stop_timers_for_cmds( @@ -4304,6 +4313,8 @@ int iscsit_close_connection( iscsit_stop_nopin_response_timer(conn); iscsit_stop_nopin_timer(conn); + target_stop_cmd_counter(conn->cmd_cnt); + if (conn->conn_transport->iscsit_wait_conn) conn->conn_transport->iscsit_wait_conn(conn); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 90e3b1aef1f1..8bbf0c834b74 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -3174,13 +3174,14 @@ static void target_stop_cmd_counter_confirm(struct percpu_ref *ref) * target_stop_cmd_counter - Stop new IO from being added to the counter. * @cmd_cnt: counter to stop */ -static void target_stop_cmd_counter(struct target_cmd_counter *cmd_cnt) +void target_stop_cmd_counter(struct target_cmd_counter *cmd_cnt) { pr_debug("Stopping command counter.\n"); if (!atomic_cmpxchg(&cmd_cnt->stopped, 0, 1)) percpu_ref_kill_and_confirm(&cmd_cnt->refcnt, target_stop_cmd_counter_confirm); } +EXPORT_SYMBOL_GPL(target_stop_cmd_counter); /** * target_stop_session - Stop new IO from being queued on the session. @@ -3196,7 +3197,7 @@ EXPORT_SYMBOL(target_stop_session); * target_wait_for_cmds - Wait for outstanding cmds. * @cmd_cnt: counter to wait for active I/O for. */ -static void target_wait_for_cmds(struct target_cmd_counter *cmd_cnt) +void target_wait_for_cmds(struct target_cmd_counter *cmd_cnt) { int ret; @@ -3212,6 +3213,7 @@ static void target_wait_for_cmds(struct target_cmd_counter *cmd_cnt) wait_for_completion(&cmd_cnt->stop_done); pr_debug("Waiting for cmds done.\n"); } +EXPORT_SYMBOL_GPL(target_wait_for_cmds); /** * target_wait_for_sess_cmds - Wait for outstanding commands diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index 4cbfb532a431..b188b1e90e1e 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h @@ -133,6 +133,8 @@ struct se_session *target_setup_session(struct se_portal_group *, struct se_session *, void *)); void target_remove_session(struct se_session *); +void target_stop_cmd_counter(struct target_cmd_counter *cmd_cnt); +void target_wait_for_cmds(struct target_cmd_counter *cmd_cnt); struct target_cmd_counter *target_alloc_cmd_counter(void); void target_free_cmd_counter(struct target_cmd_counter *cmd_cnt); From patchwork Thu Dec 8 03:10:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 633206 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 069A3C63703 for ; Thu, 8 Dec 2022 03:10:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229777AbiLHDKh (ORCPT ); Wed, 7 Dec 2022 22:10:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229834AbiLHDKV (ORCPT ); Wed, 7 Dec 2022 22:10:21 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B4047BC21; Wed, 7 Dec 2022 19:10:20 -0800 (PST) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B7NOoAK016123; Thu, 8 Dec 2022 03:10:18 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-2022-7-12; bh=6+rerFJH39Kros+FS5nyA3QQ4eDzSw915PNvB5CPamA=; b=asXfx6a+5Li+D+i6xASETZ7YJlZizyAEzqbnliLpDUqBzBSBDD5CUnFo6yghfMPcOzIJ Amdpd7p/WXWbc5Bpxq2myX3JGiumftKUBfzMwRUR5KdbwGR8fdivm9ZUwkthNWEH4gAu kojum8MjC/ZdsGawDzvMW9YbEHc5rutIbznSm/YRlVp8MzeJSJF3bHQWo1gF69QPWGM1 OGL6R7vAYf8IqrxNzD2jC8yyAcPXxzDTLO245PRWQ8mFFwrQ3D+lPCMOS9eBKu0+Ania +o6xHvb4Hn8hmRDKEk6dKQSZErQYUbtzD9mrIfjxqpYr2xuyJeigwfh6IIQIBaOnkc3I FA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3maubahwsv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 03:10:18 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2B81NahP033819; Thu, 8 Dec 2022 03:10:17 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3maa7xmkuf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 03:10:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q4WfPx7LbUn1J+aYOoFt5Fnvdzmo0wKTzaCnKI6ik0Klc0nUKOGPIA4JLOPk/NTUhqEPPNyeUzIjnrYZvR+OJcHL/amGeZZ6IDbXItiL+u/5QBraC65IX/nWzGs/u1Ff7XfiUVgO9jNl/S6L9EbJ4ZcEzcc9AAuNvz9IzWXKXDbAz8gAkZUOv3VeLBxLCLJ+rOsk76UiBP+N8lbSDqH8JivGanB2eXy7yK7bAwKwJ1ZCESMxThXT1uYLLfX2DPgzg64IbQScARtWRObsb/wC4+tAqYqb6GhqViBTgyWnzMkpOGTiULfu4ppm/xs4vKIvmk3c2XigccozoZOrEFSKDA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6+rerFJH39Kros+FS5nyA3QQ4eDzSw915PNvB5CPamA=; b=oU3Ivle8gPWcfLDSoi/1liV6bWSwxCW5MUiZq+Z7VoFBi7Q4L2GQ0NblmwNfRVZxMC9HcDGp6eh/60K7Nu3Sh1tbr+xoHlZK2m1NZpksQc7JZrM4/SRF7xPGZZ6J5ZyAeJ4EqIkbZZxtMlrF5bd0aOe+GrESHlZ5uDm4uPG2HtVPFwjJYqlSeHNTKaeSsMN2A9EWbEeA2YJHG+NhNibqDftSZWidaPXTqCC0PY/CYqwdSqlh+jo4o1PIJdbL6diHCm8pRTVbRRaut/HXxxHp9rnJm4TrKj/mcXUmc/ZrV1f9LaavvxnjQTA4TOqdwpyAVdYCGfhDmphDY01Lb8NgUQ== 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=6+rerFJH39Kros+FS5nyA3QQ4eDzSw915PNvB5CPamA=; b=ZuLHrGN6jsGfDvLX0wZkIKRRhTzVac/LcE16um1+lUYaADG0njDRJ7TME8Mi5spm+7EtPxLAbxXdUIYNzefA/iaxgVdzzTgXas935+a7o/RzNkgx4kIfBMrFnSsU79BABChV2Gt2uWPc6bCm3J7lFYIsiYGayNvl2cwbYDrUNo8= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by CH0PR10MB5132.namprd10.prod.outlook.com (2603:10b6:610:c2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 03:10:15 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::2dbb:4791:5a67:4372]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::2dbb:4791:5a67:4372%7]) with mapi id 15.20.5880.014; Thu, 8 Dec 2022 03:10:15 +0000 From: Mike Christie To: mlombard@redhat.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Mike Christie Subject: [PATCH 6/7] scsi: target: drop tas arg from __transport_wait_for_tasks Date: Wed, 7 Dec 2022 21:10:01 -0600 Message-Id: <20221208031002.106700-7-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221208031002.106700-1-michael.christie@oracle.com> References: <20221208031002.106700-1-michael.christie@oracle.com> X-ClientProxiedBy: CH2PR08CA0020.namprd08.prod.outlook.com (2603:10b6:610:5a::30) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR10MB1466:EE_|CH0PR10MB5132:EE_ X-MS-Office365-Filtering-Correlation-Id: 2cf2d77f-2a26-4400-a72b-08dad8c9ba49 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cGGEiItcS0ZbaRBtT655TbneDXvJNKOlZcPxyJBygr3SaRzXyPVwE8X8rrZbojrkjxmSFy6kn6Scm2M0cTu45iILo/gobu5cEWiEY+GtT/Ig3w3lGRX4XNb/R6cJE2I/ZHB8Wsr8CbcqebmiwZK8uZPeon3MEJXHMVvcjCtVcwtYt09Np60gR6RLOSbtp/tU+7cldbvl1LlPyIjialXZqd8R8eO3jr4aFW4HLaTnr8JbWi7qM8B44V6Qd1i9v5brZq8jyg1X72g0w1ILEicMJEirxlAl2KZVzjkiwSEUhxFZnw+5Q9ZjX19pu24gfJY8o8O0vTB9bp93KrJhcg1gnYBzBycxhlO8TJ3nnMilqMjcrZVpgmoKnsytMsXfNZRFH7b5a8VYVmf1r6kBjmog+l/ILg8gw4uCpgirzs3Bxk7himl7cVNc1wEMJNfNq6IUId1MVHF4lb/1f/gQBzlOvIP4NcvVUy535tNoE+dTt2EkoQYJL09k29W7ZndUIhVmhm4CeAjJWX914BrAbrUm30gBNyxoqE9p88kA89iPNBjeLM34FLhlG642MfWyr4Ddkshx0U1ViJ1JXmShmwEtl8UdeXrUGZRKys7QMesgi52XeasQBd+U3Vetn2t2VBYFWayc5JLrYOi2xF7bFLwmvA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR10MB1466.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(366004)(346002)(136003)(396003)(376002)(39860400002)(451199015)(38100700002)(8676002)(86362001)(83380400001)(66946007)(4326008)(41300700001)(2906002)(8936002)(66556008)(66476007)(6506007)(478600001)(6512007)(26005)(107886003)(6666004)(186003)(2616005)(316002)(1076003)(6486002)(5660300002)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jEeYhgHWOT2FQvGd2gbcyn8Pn36Fjpmd8r4PuSdK87OBLIw2DI/E/Og+TgItYH5AVJ9xjhPFnBZ99G0WW5XN8+Tzzt0aEAzio0Hl3tEV3v1J6hashRVr+DyT5vfs4uk9TDOOVhtZtjPdz1mvs24pz/QTtxvAQdFqV6Y7pXUTjHSB9QMZ6hFRDKsXKfCjnoGgc10roEXBcLW94hd+A1UnsKwxTSgMya1rOTcxe6y0byR9mCoLAD+2yrQ0D6wID8r8OxQQtOyeO6moZ5ZmypuaX7+fiykyOlCbhZ8MehrR4xUeOSI4LZSmywbH1WPtk6x8u2aw3E8HpEeAWPETYVQWERnDGARJqu+P+KO5DG8zhXDxny4iSWQgS4ETLm6NAmqG640HV/mwJ2W7ZLtMD/+WIZFLACbL2AIJrT2SzUTFuMrzZQiPl2ovDwThvzhs2X/oozJYHzzdB0xolP9Ci72icpdyB4PbTFMWdd4XpwBKqV6yZBaofSnkKrpwjOXMN672WtD/uxg3daGeqKNH1zUmOzkasQ+TULNPM61rit3oKGXuDC2RI3QEAE4+HX7tl96TD92Unt/lIwWJY8FzE2v450HVToQL1qW37+Qwus+9wFP9q2tu1tUrT3VGavrTO77ox35xhy5FACnXUzAaHywRtSytIqbeghpI8EtgWLf83sVR41tnn7/AKXSPtoRU0Cp6NE1uLOWvo378ALH9NuY0wHV6WjeAO1DpQK9Zp3UmPpWNCteV/HAU5/1W5IQhbEOBsJEL/VMneIGm8gKdhC19Lja2YR3PSa2HV8+rK7gfRTu2K5uQrERUVdSIJRbJkoLld7DpKtvgOf4BLMWWUNQj6ok0Uef3LvEng36l3SypM4BJ8AlodLs95n19JCygTzvGuMKS9CZ10a7XoitO8g0fZkas0kQz7dTrlZBn3PeJMNRGMdX044NrPytsoiEYJB7G6GUHRCaFEkUrGON/BpXGtDVHo5teBSTsTfSvvvHKzGi1eu9/nQoZ52hkmDgFSMA9JLNJrQi/41dOBTlDk9VFowMr64g1P/zWwzuJxQDlC7FJ9CbpIrq7wR4G48sWBO742rzahJWL9c2pfeZXANIE11tygjkX1ND7K999IZvuiWLn6KcIKqNLTweIs+ORpOdGhbs5BHT/Ocr9uE9bYkmb7FRvuUxlCq2cByYd1dXHmH7714edkhmXwXbjCvuPimCn8uK2vGMQQBtR/IASXumFH4v3ktpJl5MbtJ0hpRKAmYYcEKRehdijExTr8n2ThC6Y023pMeh/Kqq+eGbjJWcHNhSrLpa78gBKopWbJKTwBuJUD1/8mavrda0qNQdZwiiDofQ3F6gilOuEK9c+t4wIwujqXYNiBjmo3oJbIrSjuIktVAMg18S2KV8K24MsIKJifYKQXMR8/hdxzAKx3IXhf0+X1d52eBXRMTSMvDY3p3BObjCnv9Raa5KPYhStzAGIgRr+Z9/JfHi4hvaioA9WIgt2hh3jVU0hINz8dVVZv7x+Ts/9XxXdS0cZffZhc9n6n9bT5uvpI1zFu0iRqeYGBZjPFJfSbGfvJqbZCV/FAbbpQgw9oVnIjAz2rXOt0XQE0y6NdFHbM+hu59DhBwTSKg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2cf2d77f-2a26-4400-a72b-08dad8c9ba49 X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 03:10:15.3636 (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: bp2mIkj85rB0I+po4RcoXw+/ylgL6b1pb3Zum6egUagvq6CUz7ySl7UpBmMft9XjOfvmmSLUgnXKFPkYrytlm7jZc1D2Layl+afpqRLwpaA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5132 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-07_11,2022-12-07_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212080024 X-Proofpoint-GUID: MRucY6EswkqOMZ-ztYtOEi7bjv67s4_t X-Proofpoint-ORIG-GUID: MRucY6EswkqOMZ-ztYtOEi7bjv67s4_t Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The tas arg is no longer used by callers of __transport_wait_for_tasks so drop it. Signed-off-by: Mike Christie --- drivers/target/target_core_transport.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 8bbf0c834b74..d42ba260f197 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -2902,15 +2902,14 @@ static void transport_write_pending_qf(struct se_cmd *cmd) } static bool -__transport_wait_for_tasks(struct se_cmd *, bool, bool *, bool *, - unsigned long *flags); +__transport_wait_for_tasks(struct se_cmd *, bool, bool *, unsigned long *flags); -static void target_wait_free_cmd(struct se_cmd *cmd, bool *aborted, bool *tas) +static void target_wait_free_cmd(struct se_cmd *cmd, bool *aborted) { unsigned long flags; spin_lock_irqsave(&cmd->t_state_lock, flags); - __transport_wait_for_tasks(cmd, true, aborted, tas, &flags); + __transport_wait_for_tasks(cmd, true, aborted, &flags); spin_unlock_irqrestore(&cmd->t_state_lock, flags); } @@ -2955,10 +2954,10 @@ int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) { DECLARE_COMPLETION_ONSTACK(compl); int ret = 0; - bool aborted = false, tas = false; + bool aborted = false; if (wait_for_tasks) - target_wait_free_cmd(cmd, &aborted, &tas); + target_wait_free_cmd(cmd, &aborted); if (cmd->se_cmd_flags & SCF_SE_LUN_CMD) { /* @@ -3237,7 +3236,7 @@ void transport_clear_lun_ref(struct se_lun *lun) static bool __transport_wait_for_tasks(struct se_cmd *cmd, bool fabric_stop, - bool *aborted, bool *tas, unsigned long *flags) + bool *aborted, unsigned long *flags) __releases(&cmd->t_state_lock) __acquires(&cmd->t_state_lock) { @@ -3249,9 +3248,6 @@ __transport_wait_for_tasks(struct se_cmd *cmd, bool fabric_stop, if (cmd->transport_state & CMD_T_ABORTED) *aborted = true; - if (cmd->transport_state & CMD_T_TAS) - *tas = true; - if (!(cmd->se_cmd_flags & SCF_SE_LUN_CMD) && !(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) return false; @@ -3292,10 +3288,10 @@ __transport_wait_for_tasks(struct se_cmd *cmd, bool fabric_stop, bool transport_wait_for_tasks(struct se_cmd *cmd) { unsigned long flags; - bool ret, aborted = false, tas = false; + bool ret, aborted = false; spin_lock_irqsave(&cmd->t_state_lock, flags); - ret = __transport_wait_for_tasks(cmd, false, &aborted, &tas, &flags); + ret = __transport_wait_for_tasks(cmd, false, &aborted, &flags); spin_unlock_irqrestore(&cmd->t_state_lock, flags); return ret; From patchwork Thu Dec 8 03:10:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 632165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83091C4708D for ; Thu, 8 Dec 2022 03:10:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229914AbiLHDKi (ORCPT ); Wed, 7 Dec 2022 22:10:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229656AbiLHDKW (ORCPT ); Wed, 7 Dec 2022 22:10:22 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 884DF7614E; Wed, 7 Dec 2022 19:10:21 -0800 (PST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B7NO0vB016777; Thu, 8 Dec 2022 03:10:19 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-2022-7-12; bh=7SaYBMj7V8zOW3nMVU5O00zRbPOiXi9StkVhNbMd7sc=; b=PYRQU8a7hKYppICQ7p4ClhRppjmgKHD7h/ARdYstzE0gz62mqNu+s/RTnIaI8tduW7Mz XFqKRsNvY1z8Tw5ZkOzQMQ3q8LDgUDiHwiiGt76xTtvAJzAYhUc8aU2EgZXTlu3DlLv8 JQ5X7L2curbk/U6SYalojRizbYJGwaCCUANaWJeknvGL01r+xc79bS6hqZVh2kpWwQ9z vpyGK3cDtX2HHXu1eW6d7Hm7KvirfD5Pk4nxUmU0Fmnq6ZwcSRpJr+2ayjljGIFn+fyB 0K5R9FoiOWyzEUgGC0XxcM3YOO7BRNDBO51ZIFk8dAkI2h+bvurhZWF2tnW0NZcO0Dkv Gw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3maujkht41-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 03:10:19 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2B81cZUN001925; Thu, 8 Dec 2022 03:10:18 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3maa7daqke-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 03:10:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ITubdce8BIsUdU5y8TO6IpdIVceJiNyHghK9kjvZeD/cwZOvvmk1mzTbq8A3KsBpOQ9RdmgSl9F00x2Fg7WeKpLJRzE6L25TStwRX/dlNyb3NoPHrxiAkncD7ExXHkaiaKQGhJlaY8rxeKsAAk9PqRDreN8fY6jK6h8ZQYKviHMODq4g3PIK5a0fufzs9FmUsLo06K5Jmt3bIQk2T8SD7DGo66vzKvyWTS2uNfRPIrd9FDiTdCk4+2N5q/oekywlwXEH4jJRkGHGPdkv9v43dFn41AnRlEIA2wpfAHrq4IvOvZXTwp0ClHDy0++sSV2YQuNSqP4wNJI2gl6wJWbLAQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7SaYBMj7V8zOW3nMVU5O00zRbPOiXi9StkVhNbMd7sc=; b=oViCIL1TSFMpkG3tZTjI+1FpGFe5VUxYt3ZP7OFmgBO5tzxUeB4JKk8pOFiE44CZVHiYDIeYBspuMCIvMgQk7zwHJ3nXCbcbLdk1q3pJO2q7joDm4Q1grO3eKEe4o3sF5aTVWmPqRCVg4B6UTuF25I+oKbSO94Cxnf4DkUG/+X/x1jFBCA8qc8HuNxUVi9Htp06t9uHEEyFCgVWbzHD0gj7Ss3/VPfcSceKbVqnJCFqM+IJ5FLdE7m5f0BxgjiD2vhbdmpA5Xm1LB2V6Psa2dNwxtSIo7bU6UXc3IwbMyYsTW3iOOdGfR7JbbQuOEc01FcQAzdHrlB3RUc7+H+V/kA== 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=7SaYBMj7V8zOW3nMVU5O00zRbPOiXi9StkVhNbMd7sc=; b=P9WkS7CD+EhXOXHKCv9dcZDZf8VTgIFYUAXBHX6FWu0srB092xt98sEdfVl1/pNsEELRxeHO4M03OTstFNuBn9YZU3iw6NoX7ra5hNYeQNCuzUu78P7agR1mZk/MyhfZhDnhsVFz+zKv11Fax2Sgr96FlhDhpHV1xXNGAaQtgfg= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by CH0PR10MB5132.namprd10.prod.outlook.com (2603:10b6:610:c2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 03:10:17 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::2dbb:4791:5a67:4372]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::2dbb:4791:5a67:4372%7]) with mapi id 15.20.5880.014; Thu, 8 Dec 2022 03:10:16 +0000 From: Mike Christie To: mlombard@redhat.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Mike Christie Subject: [PATCH 7/7] scsi: target: Fix multiple LUN_RESET handling Date: Wed, 7 Dec 2022 21:10:02 -0600 Message-Id: <20221208031002.106700-8-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221208031002.106700-1-michael.christie@oracle.com> References: <20221208031002.106700-1-michael.christie@oracle.com> X-ClientProxiedBy: CH2PR08CA0012.namprd08.prod.outlook.com (2603:10b6:610:5a::22) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR10MB1466:EE_|CH0PR10MB5132:EE_ X-MS-Office365-Filtering-Correlation-Id: c3fcc6c5-b34b-4264-0d2b-08dad8c9bb38 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jheNutfF1du/UEZl9mz5ATFdaQJXk7oNpTXpUss65gKbpdGE7QqH1INv8ypsnTp9s5oPUCxfU6Oiru3GJCcUmiHuLAAkwGA4RxJo2gAxfp9UMrdK6e76rV5KpVxAJB2Z9zSa6++WsrsbVUnE63w7WnQG1AnfnTMFcU5Ln2K6h+HKQw8tevCZLdh2ibNCrp4gTpDRCI+wfoTB5e3+AisLdAswO8fN/g1X1OULnG41FxRsI0XS4d3pD5jTOxURzo79NkpA3u1z20art+9NEmt9nxkAwOYq3k7shp/oOYhJXQ0F2zqxhk9gYR5Nftp+VAAah8vyX3rEiShxMHPyeG3Pq1ztLILQVfAReRQR8/LiDrA6Vy/gCQavsl+w4V1P8Ednu7YE0itxjJW53gfGCtb5vie2/nOmJ+km3B7Gpv2LGuAZYr8gklLQrPWvC2TTmeQmlvOCtAeWs/79KbGIBVEsQtsd8ZXftq7wXLs9/XBYsChoiIK14YWRkJNPV91i8yqSMNyzsyPCK7TL39jCLx1p7wk/oupokWGgcPk2beqnNk+d7KXGH0uXjjKzuVaeFJpghYsO9bhiQEj9moqwZaOZqus/7Rs3sSUlqX19cQIQ4v8dKbLhQqLw5Fgdgvstt7pba291VBmSnL3P7UNaJYf5Zw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR10MB1466.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(366004)(346002)(136003)(396003)(376002)(39860400002)(451199015)(38100700002)(8676002)(86362001)(83380400001)(66946007)(4326008)(41300700001)(2906002)(8936002)(66556008)(66476007)(6506007)(478600001)(6512007)(26005)(107886003)(6666004)(186003)(2616005)(316002)(1076003)(6486002)(5660300002)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: P9OAYQFNQRapCPaUw/raLAgTsgiXzlrwKxo5JV8JaiZiAiGlZLZrLBbRjqz3yATZ29+qQdbaB7bPkBxz62Ux6BQoCpWAAOZ2Pepi5KQnnFSzSF2JrPKhv/qlAG73Rf7bF9bpPI6PoIMetQk8G0bBgl3baSvnYQrog77fp0iQw9xnvBOq4OyzXGNETzt6juSpAc20nQOhuEWXRq+3B4hUnzQ33gz3/EJrAIQl92pdQQ4AztRXbEcdC2pvUZ40M+Qjq+2vXPUXsqLQCvr4O1w7odoGa6gNf2DEdgMXLbgIauNZuN3s6OHbYSozehWJ0X8gjjD/CPlfJMD/oGb/bZgt0E0LAVr2HSEDfZ4+maCx30UKoPddrFyEY05vq77hERjoZ3WnDnBAj8pOKDSe5HK0TpN7GfVJV+DlHxhoJLN7tr0x29R3/+oHmrEkt6kyw+tcthTZacq6MQ1RquVLGSv7y5YwCC8VzCudT94k+ZgEflvhrRnPe2d/C+M0xL6veZmTHEDIGAeV1doSO6RlxJ6x1uUESu4i33vXuxy8+hjMptJ2lI6MLm7UJVuirGd1jzZ/Ica6X9JqNc7Ra7Hlgf/44WMtxEiaZK6wUUtBxxo1JFujS95fXaNa3oNPHT+HKbvshGZzH2ReBZptiPZkaIpdrOTnYtFjFxjXDfUsiA+LHzi/zMggJPm4dxAjc/wbMsoZv6JD5v44gE4Dh2e69YcNvtroyXlC2RTvKVjgAQbNcYLR4paL6u3faPZetwh8YATqCz10319scW2n25c0ajU7eDIK2F6IbA75HQEV6eEjd4nzLiYHUWZqcokgJq6iuWDG8+InAAzEKexNBCwJloajDm5eR46lJhsDsKmYiSQVHa2mIACmA+cq4OpftIm+RqDXvGrJBhGeh8DTJ94QKIodqbH5aecntvjbJL/nFb2KQdAdvt9+GvG8UQxXdSOSxNYxtyDrsTfJdkCkuwrE8HuuZ5D96RAfLj5u1rQp+VeWgqrQLUQn2s/B91DAJAP6uuachA/zw1UjvQt7qsKMErkPxaE3PKtZ+TehgDwsP+2FKOo0BuRq4MhetqApfH0Ymi/aABXb8Sj3L/QvPz8Eoyp+Nx2zqDURiJKfMQKpQgDECBKwOP/9vq25LXHRqO/PvkFttnYG00XR3uY8+kuxcmgyBIiDTsWQhxOKIoAD2iV3xfSQgJuAp84o6qh6FxCNqp+2PP8UahejloFqdFFA0rdgY6JfX7M2/Zh90/tIVp61iNueCiaZ9rVv44ReeuVACzaSZ7H1PZNF6zgSgSPnZ9vVvjkrhXMXRXcNOg5sfEBXETcTDoPp1roqvE+noVRQ1lmXndANKpaDWBf7Z1LLUTZQBLLoysdD/gusR9gE78LIypdMMXWXQo8/imTYOCftc96Ro+zU+x0AqjdC5sfd1XT0csghYnxZ7D3iIT2qrICdQXGGHcEgi7yH6MjH7n+BhVsdAH0wY+avRGsadub4t4J/w0lDS06tUhmK7Az4R5p3dcOql8EGYFY2GeJlIE8NaHBdAb5z/gBsd4Xl7tR+Sc8U1gmNtRS+5KDmkhNvns99C7H1FkhggtVQqTTnwMvtSPsdM+KF+30M1RDs/BLas/KjBA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3fcc6c5-b34b-4264-0d2b-08dad8c9bb38 X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 03:10:16.8635 (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: fe6y7AEVoTp0eM6yIASn99myPFniPGTTWpzRqyJXhE16bJ7bXGpOxI4huTg46h7ZE6+AHEDYv9Xm8uyq00iVET/pEEVEWToinSgzXTWPhlc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5132 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-07_11,2022-12-07_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212080024 X-Proofpoint-ORIG-GUID: KSAcilpD5O1J7chE8-i0l8Er3EH5aWuP X-Proofpoint-GUID: KSAcilpD5O1J7chE8-i0l8Er3EH5aWuP Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This fixes a bug where an initiator thinks a LUN_RESET has cleaned up running commands when it hasn't. The bug was added in: commit 51ec502a3266 ("target: Delete tmr from list before processing") The problem occurs when: 1. We have N IO cmds running in the target layer spread over 2 sessions. 2. The initiator sends a LUN_RESET for each session. 3. session1's LUN_RESET loops over all the running commands from both sessions and moves them to its local drain_task_list. 4. session2's LUN_RESET does not see the LUN_RESET from session1 because the commit above has it remove itself. session2 also does not see any commands since the other reset moved them off the state lists. 5. sessions2's LUN_RESET will then complete with a successful response. 6. sessions2's inititor believes the running commands on its session are now cleaned up due to the successful response and cleans up the running commands from its side. It then restarts them. 7. The commands do eventually complete on the backend and the target starts to return aborted task statuses for them. The initiator will either throw a invalid ITT error or might accidentally lookup a new task if the ITT has been reallocated already. This fixes the bug by reverting the patch. Fixes: 51ec502a3266 ("target: Delete tmr from list before processing") Signed-off-by: Mike Christie Reviewed-by: Dmitry Bogdanov --- drivers/target/target_core_tmr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index bac111456fa1..ba2a2c18dae9 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -188,9 +188,10 @@ static void core_tmr_drain_tmr_list( * LUN_RESET tmr.. */ spin_lock_irqsave(&dev->se_tmr_lock, flags); - if (tmr) - list_del_init(&tmr->tmr_list); list_for_each_entry_safe(tmr_p, tmr_pp, &dev->dev_tmr_list, tmr_list) { + if (tmr_p == tmr) + continue; + cmd = tmr_p->task_cmd; if (!cmd) { pr_err("Unable to locate struct se_cmd for TMR\n");