From patchwork Thu Jun 16 22:45: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: 582720 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 CE78BC43334 for ; Thu, 16 Jun 2022 22:46:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379159AbiFPWqm (ORCPT ); Thu, 16 Jun 2022 18:46:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379150AbiFPWqV (ORCPT ); Thu, 16 Jun 2022 18:46:21 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C46262205 for ; Thu, 16 Jun 2022 15:46:20 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25GIm6DL032726; Thu, 16 Jun 2022 22:46:14 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-2021-07-09; bh=JCRsGOWJ1NTG9Fa7EtV71ZLam/8OEdct4i79GPCrAao=; b=ONRhVgZ+ab/wmqAzvbUWf9G2RsZc261bEICTEDbuR1WTannxBLpC0Jl56IMIALYZYcvC pJlw4EVwe6NU5uxkbzEwzoahit7Ypbaftmh7wKioRA5eSaMRVqmB4sPeKlFn7SA3h1Pr FWHuGklVmT7L/py5xd3P0imubY762lHCb6XPYQuCiKi/GZdku5O2L2m0v2sbrW5vXhdn ZLyFUQhklVPhU7aw/KtMtoNtB+CODx7E6cd5G6nQL8IkEbPIfw/rHTVUUsDAupYmtHZb SIhnksMwrYtV13SmuTbNjbBjwoe3A+lS4kJiNzvZq93GQ37s5ckFfEzeCtUMLYd16YPH ow== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmhu2vmp3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Jun 2022 22:46:14 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25GMaPd3035724; Thu, 16 Jun 2022 22:46:13 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam04lp2046.outbound.protection.outlook.com [104.47.74.46]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gpr27dmqw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Jun 2022 22:46:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uf78ckl40ouUjEVqtWGpZiEKKER/N/S4SWxIBfDcvWKH3pLbzKydNi2/mJWQbqyu26kVe+SMIJqhgpcrSUx5TOTKAVDZ261eA+OvR4CZXkWyK+DFb0kajlbTOKHJvH64g7UdCSHqaGrWuYPztHH958r+b5ZV3jHdMM7Zoe6W48YLnoRgTRxq7fIJyTY4dzKPOK15aPMaJW0c6XGPgyFl3uXNxtZPjL4QviLgIK2H4841Cch/2HYALTrbUXvkBZ+rbP0Z6REej9RC4n6oms517CSrfj+/ZH05Cw7kAUVNd7w2N31r5Oya++i7KbKqxAhJX0vcwqC3XaGgbEgApb8eaQ== 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=JCRsGOWJ1NTG9Fa7EtV71ZLam/8OEdct4i79GPCrAao=; b=MvIyxlHbbsVaBMEukr7zDvYBpsGDYKQ04iSYwYpLCzr3K6Y2m8zXd3iQPYHFFse4OVFtOJxLVGpCZ0P0ScfDfDUVySUp6Yh05bWImZBmkkGLRFMMGI0bthngTNE7Jm28jt9+zwZT0LfDUZaRtvaPqw33lPetoouW+IDb2293qIbVGf9DU/Osw9G2y001Nki+ZDY/UVbG7QFvT0pV6dZQJbnfks61mpv8jiYOnUbzuaerXnttbkjjpows3CpB1YOgpbi5auh1ON/dLa2QGe9+8CFJVWBkwzcE+gai1wg2k2ygIGoMvbOxMhpzEFZVpqNaZN+PD0sbLFAyXjbYxDUF7g== 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=JCRsGOWJ1NTG9Fa7EtV71ZLam/8OEdct4i79GPCrAao=; b=mJ+rCuoaAd96vbc+Sxyd60yTP+4x2PuBymdGlq3Kwa6E8QZDG5ZK/458shZlj12tUq6ZNuQSh9uL00gcmEuh077B63UTY8RGGfsAT4Ndqz6NtwJcUAhYLhNksNnB6Qtr5tcVU82uvjyqAZXAOeo0lUlfF/GOz9s6fVg838LDqqU= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by CO6PR10MB5617.namprd10.prod.outlook.com (2603:10b6:303:148::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.15; Thu, 16 Jun 2022 22:46:10 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::f81d:b8ef:c5a4:9c9b]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::f81d:b8ef:c5a4:9c9b%3]) with mapi id 15.20.5332.016; Thu, 16 Jun 2022 22:46:10 +0000 From: Mike Christie To: lduncan@suse.com, cleech@redhat.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, jejb@linux.ibm.com Cc: Mike Christie Subject: [PATCH 8/9] scsi: iscsi: Try to avoid taking back_lock in xmit path Date: Thu, 16 Jun 2022 17:45:56 -0500 Message-Id: <20220616224557.115234-9-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220616224557.115234-1-michael.christie@oracle.com> References: <20220616224557.115234-1-michael.christie@oracle.com> X-ClientProxiedBy: DS7PR03CA0264.namprd03.prod.outlook.com (2603:10b6:5:3b3::29) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f2c43f00-d94c-41a9-1076-08da4fea021e X-MS-TrafficTypeDiagnostic: CO6PR10MB5617:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lD6A9EM4yEoPk+UGZm4L1XY2PolGuSWgxauptNoFMyaSh9KwkCDRt2Y8Sj64T2mNcq8zI+fo/EjuqUhzM0T+XAk2X91cooGPzeCpi2S5529JvnkU6PoUuDAhkNQ6Z3eMRNZWvUewiEde0OMxaNLX5/NdcfHch8WKtjOjroQxJn+BGUfF6nCE+/zS2r/AKpnItLZ4y7pQ6Dkf1uG791ZYnq2zpQ7XGBAer/VWiT5RuGG25qZTe1i4eLHpMEsijcHLI7DGsOxbq+dw47KK6HIGsuNQfXAQTwdv0C+VvsDD2/ImFwGOln5LRzvxMY9MRgQBH2MZTwgbglXHszaE/Fa3mxg93FfqKOAGCSi65eSj1qIzA9WgHj4Gw+VA0j9UTfCKXxw6L/chbxCiaT8+y4jJwAUHPObZJUajAUMup6mt0WRpyb7v+P+x6lV4Ua7KFQIvmYQdfynJXO9vyVPK5TVHyvfz4nyN5ilw535I6eIoa+E1e8Dwq712MB2nnRDEvbH7MUakZm+oZxR11PcMyKE4dyJhO53jkF10gjtfU/igSiE461cd7h3eu7p7o0q2ySIvS/ad3aTHwU+ME4IPx8lWAUH+3umGjmYXeoiaKWljmqIPSSqhgc1iqYzAzTuCmgYO2OKvO9Xtq47vD+Ig6q39QYP8F5WtIDIO2+h3b2vlXWXbYDPiKygaAofG7WS2lIGuoT/66WCKVtnfnnZmLrK3sQ== 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:(13230016)(366004)(83380400001)(2616005)(52116002)(6666004)(66476007)(5660300002)(38350700002)(38100700002)(36756003)(4326008)(6506007)(8936002)(508600001)(6486002)(66556008)(8676002)(6512007)(26005)(186003)(107886003)(1076003)(66946007)(316002)(2906002)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Syfs0AJm7tnvPz+xSTAbUxxDcZnPWWXysozwOSCHbjGSb9B8EU+o/DEBWwaWAciM2CCORKlXWRpsp24jDKebLhfEdoRcx+QkWRpr5pE4/4+bWKIPz7IuI2V4A3INv6kIOQhPO3AX1Obut7IY/TaD+avYmkeP1t/v996TDgBK0OwzXIDmFKOlJigMixDCa9X01mbaiZf1hZIg1Wowheu0n53KuV48p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dsKlJgIV9bqQ9soEIgcHhCF4cOH0NFJy90+NmNF2y3YpMbqdT0rdWyvLJDzwzmGJcOCYT65YmSvO9/AIC7Ly7wv003LBXcK+hwtwtbTP3joygbbwnzctPvfjYwDqGZsj12f4+gMqWnka25xCckEsqYZtZDKU/TSLeEJk/qge95kgH+/Ln8ys5eMDzF0HWEaIFjVzFaWOdU1oJ5wBhvvSuwZsYdV5qo9l91F6eEqJAxyKalCc87aBkrHESHkV+q974I1vURCwcR0UZiaUMjRtAOo3D7i1/8s5QWuU4KCedZx+sq+eh/L4KwS7egUrvCSiwzqi6bgJLq7kiHc83b5rYLV/j3bS+ZFF1FzbkMOvtEBlCHip5rm2/F+dqyhw7d1hT7Z0FbHPTeCp+U8Z+TwBLhoWqMkzgQjc9VkuHaOg6DTKCp7be9gwxE5oEttOAf/vlr7hhUWwfgIATiQGfKPE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f2c43f00-d94c-41a9-1076-08da4fea021e X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2022 22:46:10.6718 (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: /iuohUXkofAlSLu/zCLn33fDyH126bGWyBdC8HK63l6TNtrraEp52G7mBYsKHjkGdZhCy4qLeXevajPX9AXi96BG/FUnhdWd7o5OZWDm90U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR10MB5617 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.883 definitions=2022-06-16_16:2022-06-16, 2022-06-16 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206160091 X-Proofpoint-GUID: P-EVV3nJOR_3gMh_VDZmOauWyh0TiHcc X-Proofpoint-ORIG-GUID: P-EVV3nJOR_3gMh_VDZmOauWyh0TiHcc Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org We need the back lock when freeing a task, so we hold it when calling __iscsi_put_task() from the completion path to make it easier and to avoid having to retake it in that path. For iscsi_put_task() we just grabbed it while also doing the decrement on the refcount but it's only really needed if the refcount is zero and we free the task. This modifies iscsi_put_task() to just take the lock when needed then has the xmit path use it. Normally we will then not take the back lock from the xmit path. It will only be rare cases where the network is so fast that we get a response right after we send the header/data. Reviewed-by: Lee Duncan Signed-off-by: Mike Christie --- drivers/scsi/libiscsi.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index 07fc78aa1aa2..da292761995f 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -490,6 +490,12 @@ bool iscsi_get_task(struct iscsi_task *task) } EXPORT_SYMBOL_GPL(iscsi_get_task); +/** + * __iscsi_put_task - drop the refcount on a task + * @task: iscsi_task to drop the refcount on + * + * The back_lock must be held when calling in case it frees the task. + */ void __iscsi_put_task(struct iscsi_task *task) { if (refcount_dec_and_test(&task->refcount)) @@ -501,10 +507,11 @@ void iscsi_put_task(struct iscsi_task *task) { struct iscsi_session *session = task->conn->session; - /* regular RX path uses back_lock */ - spin_lock_bh(&session->back_lock); - __iscsi_put_task(task); - spin_unlock_bh(&session->back_lock); + if (refcount_dec_and_test(&task->refcount)) { + spin_lock_bh(&session->back_lock); + iscsi_free_task(task); + spin_unlock_bh(&session->back_lock); + } } EXPORT_SYMBOL_GPL(iscsi_put_task); @@ -1454,8 +1461,6 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task, { int rc; - spin_lock_bh(&conn->session->back_lock); - if (!conn->task) { /* * Take a ref so we can access it after xmit_task(). @@ -1464,7 +1469,6 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task, * stopped the xmit thread. */ if (!iscsi_get_task(task)) { - spin_unlock_bh(&conn->session->back_lock); WARN_ON_ONCE(1); return 0; } @@ -1478,7 +1482,7 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task, * case a bad target sends a cmd rsp before we have handled the task. */ if (was_requeue) - __iscsi_put_task(task); + iscsi_put_task(task); /* * Do this after dropping the extra ref because if this was a requeue @@ -1490,10 +1494,8 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task, * task and get woken up again. */ conn->task = task; - spin_unlock_bh(&conn->session->back_lock); return -ENODATA; } - spin_unlock_bh(&conn->session->back_lock); spin_unlock_bh(&conn->session->frwd_lock); rc = conn->session->tt->xmit_task(task); @@ -1501,10 +1503,7 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task, if (!rc) { /* done with this task */ task->last_xfer = jiffies; - } - /* regular RX path uses back_lock */ - spin_lock(&conn->session->back_lock); - if (rc) { + } else { /* * get an extra ref that is released next time we access it * as conn->task above. @@ -1513,8 +1512,7 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task, conn->task = task; } - __iscsi_put_task(task); - spin_unlock(&conn->session->back_lock); + iscsi_put_task(task); return rc; }