From patchwork Thu Mar 23 09:45:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13185382 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 E112FC6FD1D for ; Thu, 23 Mar 2023 09:48:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231225AbjCWJss (ORCPT ); Thu, 23 Mar 2023 05:48:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229702AbjCWJsX (ORCPT ); Thu, 23 Mar 2023 05:48:23 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2CFC26C0E; Thu, 23 Mar 2023 02:47:05 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32N5hncE019250; Thu, 23 Mar 2023 09:46:39 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=89hlhwavpoRCxdyyerkjcxBDKORDxXA2jkte/ztT5V4=; b=S0dmYK+z8t79pcc/1k8Jqe6csJuqScTUkKvFLeb3wbS7nZFQwujNmGjIEC77mA4LmdTW GY8F9s55t+ZnSWY0FqAaxmX3Qncjpadr66Zd0ec9ipeTawSxbp27zxFuEwz6bodyiJ/o o4TAok8h6slnG3ljNfW/VpaMBcfTsUD7WX9IXf1jInoJmFiva1PUorLlWFqP0o+8ZVcn BxXZ4+BpXFQ41hPWCO0jpakO7bEmVmndZANddun3yiSXcGZtf4fVMskvqhyc2xsV7Ols +SnWTgHboORzqJvDCsjlGNr84JLtYp3TAGe0ztb7S7Ae5vM7JU1oKSPAok67u7ErNdKB tA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd5bckbpx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:39 +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 32N9cdi8006987; Thu, 23 Mar 2023 09:46:38 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I9S3XvMiHnIvcK8HB2SaqkM04PywFHAIy8Zmojf0y7m/gYq4ks0BDPIWmW4pKDAxcUQ5HTk3ZWXsp5OZV3XtuQjzaLIukdxdSfxOE72bjtBNyHGLyGtV7sB8fLmVwlpYZfRFPrrAjL+IM7jM12zBNt93HbVyxSJrJf960dpB/yCdVqrhZu7SOpBBlbD5J104/A8spojhhCFDaMVZm2uGluNIZkz6KhZ5rBKgrjL6E/gL7xozxrt/cYSCXmwbRG6QzLLQkIdEVGnj9Mc5ACVMjPbYbbjipUmqp/dkvlPs1CGnWymVM/3MXEmbh59WZ67KW1ZT1sNNXXawyTw9+O6WIg== 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=89hlhwavpoRCxdyyerkjcxBDKORDxXA2jkte/ztT5V4=; b=PPgPSCc4bFVtdoiHmUrWzmBdXa5k4CoFNP3mL3MlvnBKtkbg8BQCFYOBcY/2fApu1ig8w3SKcpAJo2sLRArcgnb/7Q/36kETsWN4aNbqe9V7B+8Z9r764o/6adB83XHIr/NjcU9YKhjQ47d8neDF6B45vbb1LenI4vw9zzeQ/M502X+ENPPqQR0Vl5fGqKP93hH2nmtFXF8g7Ijx04MRVexgIBPbCg/oBI5+orNWet9/Dpj6vggiWOv64qQAyUEDSz0SR38QMNmdni7NMkyntfjZiGRSj/reN2ZK/SLXsiAuUQEsI/9F6F5UNS744MAjuBrK9fpv1ZgW/U8O7YHATw== 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=89hlhwavpoRCxdyyerkjcxBDKORDxXA2jkte/ztT5V4=; b=FFq6XxNQh5DD5G88JcPsS0pd0cV6ICpDIA7jwCEOZBQEwvjlS8edAalTLBEAd8eOv2UH5CdNL/ffUseJTYz1HfF4eBZVQ7WD0bjOIuhZfumh4vrgMHyDFzJED4pTg2rDbKoF6rZYm+8en+0T+lQ1O3wE+axHLq12E5wehSsB6eI= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:14 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:14 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry , kernel test robot Subject: [PATCH v2 01/11] scsi: scsi_debug: Fix check for sdev queue full Date: Thu, 23 Mar 2023 09:45:45 +0000 Message-Id: <20230323094555.584624-2-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: DS7PR06CA0016.namprd06.prod.outlook.com (2603:10b6:8:2a::29) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: b70293ec-d926-433d-b941-08db2b837134 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Pj+qktmDauDKmDGEh8dn5QxbBsuWBqVix0c+0PcJSznVUYFu/Egqmc2fU+jrcyOhqAe1sTh4HPcqpp4rCalHdOYBecWw94rMgRFyfaKg+u4cIeBAiO6tiBDZDnBw1gB6oIK2jpXYBA4RKc0g5LRWWgN5LsYVzNub126UJWHuEepiV0BMqNvoeT3lIUhQpRQiH1rD5bo1kVkvTYOTeRDz3u0/ntzFiU15e4qrwAZLq9FeWLEtowIQMhGO/eBNRrG0wbDBjJCTGGk7j76Kw+rBt1hkJmZc6mAMhCnSc4wz64wqMV/lTh3aA8kO5Vw9hewih/BPq5Ku2Z/nTZLLrB0j3AqAAeLtWC3EoDB/mwVeokOO8Tor2AG10M7QoAzEfXmg5v+fZBoKDZyxCXZgOMLoBAORwuVKUmBagHMsjQpc8cPDdLtNW9RJZsgNjbBEpQHK8X06U8AL5HDIgiRn/3Nj0wHzgQmmkR42IlbKhhTaXVoJa+yqUd0JFM3v6nXGVhKhBwXAixoB8UJsONPQ9V8/7D4PizAx+S3KsxvB2IhRhIG5Xc7KYsOaemPUn9SA9w3T1XBcWD+C4a6xzK52pAeyNuQTbu7IdluTJVNaIzuKtGfyhJ75zsUyO8FMYiMyROSq X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(966005)(6486002)(54906003)(316002)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(66946007)(1076003)(6512007)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +1ZP/RP9wBYBO0SfaqCMNIq6J6E8uP0Kv+cJV+8+vE0YNcmRE33eVSuBm/DPFJblnsyvO8ELLKZFxm5NXZGJLZ0i6Mjam/AnXqK5FkUsDBRGR8n6ha5V8GdcIlY431qFRsEseid5be3SJ1VDzOwfVIGYDfF6NZpnlKbdfRuN9j0gaRm+nMZdIbv4G2muMKqhiqfGVAqD4BRvJha73kg3vpaUpPBgPYwyhD34ruRoO1IpLa9UsTcDlHtL9AOr3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N7rY3olQ9AHgGgeJbK8i8WwUnWG5APPpvR/A0bQRrLQ5TG1UAKq3HaN8lOvYfSV3O5KSE3qhxD7JTF6y+8OUt4TxYdQCTNRQZaTpgjH1j4WEGNefsOwIYwWLfS3MEA1kN2ilktAfrbDJ2sAxJH8ZPy8kx3ifFnAwjgHYw02e7Ua1H9LTeuUwfV0Ti X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b70293ec-d926-433d-b941-08db2b837134 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:14.4298 (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: i6oJc5gFrSnXtzR+/Zu32t45umzIX1ns1pkTDkJlhRlVTwu6JHah8xtxvMgthSyw5K2uWweQBHnIYQMLn9VZIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-ORIG-GUID: HBhxybKT5bHM7baVPNQfEbij0WQq5wCj X-Proofpoint-GUID: HBhxybKT5bHM7baVPNQfEbij0WQq5wCj Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org There is a report that the blktests scsi/004 test for "TASK SET FULL" (TSF) now fails. The condition upon we should issue this TSF is when the sdev queue is full. The check for a full queue has an off-by-1 error. Previously we would increment the number of requests in the queue after testing if the queue would be full, i.e. test if one less than full. Since we now use scsi_device_busy() to count the number of requests in the queue, this would already account for the current request, so fix the test for queue full accordingly. Fixes: 151f0ec9ddb5 ("scsi: scsi_debug: Drop sdebug_dev_info.num_in_q") Reported-by: kernel test robot Link: https://lore.kernel.org/oe-lkp/202303201334.18b30edc-oliver.sang@intel.com Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 7ed117e78bd4..782515abca2c 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -5580,7 +5580,7 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, int num_in_q = scsi_device_busy(sdp); int qdepth = cmnd->device->queue_depth; - if ((num_in_q == (qdepth - 1)) && + if ((num_in_q == qdepth) && (atomic_inc_return(&sdebug_a_tsf) >= abs(sdebug_every_nth))) { atomic_set(&sdebug_a_tsf, 0); From patchwork Thu Mar 23 09:45:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13185376 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 7111CC6FD1D for ; Thu, 23 Mar 2023 09:46:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230487AbjCWJqy (ORCPT ); Thu, 23 Mar 2023 05:46:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230145AbjCWJqr (ORCPT ); Thu, 23 Mar 2023 05:46:47 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7582224730; Thu, 23 Mar 2023 02:46:46 -0700 (PDT) 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 32N5i64A005171; Thu, 23 Mar 2023 09:46:39 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=CTPolVlOjH3rGDI7HOnmsS+cX2W5umFbzmjcwbFzghM=; b=sYcu5l6yZ8dgQMPToVMkgGAaFCQSnAomwKKQQizahGOwkSfN9UXsChKHBPerwN6pmIxc xzp9kzXW02eSn1SslB4cpuyRS6qbi6T1K3+4SbEVIJKjTZavuZOl1v0rqgE7QbNskkOS XFz3HNueGJ91eGuJ+K+ArzRvSacqY38KHXKSRsPq40UZt64dOwPCMkEAk+cf8XV5sl9U 599a+Yo4/neI2kh9jduXNMTMGR0qWlkUGzVudxFXtfnS80du+Wc9PeGdRzyK7fED5+9Q wGQx08lzfz/OEMDzf1wVQKrtpSt6aHGX/bqm0FyYi0u/YM/pGU5T6ghESkYhUlQt0lUV 4Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd3qdu3y9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:39 +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 32N9cdi9006987; Thu, 23 Mar 2023 09:46:38 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NpRBVKa30QZvMdgTPU1rGq0Pey07xHKGHNfjVomXbqr4tXNoBj09L8Tdi3V8kT3PzgYk3y9ScbdPuEap1HvzJVzbOGGKpvOxHnKULeZHn9biIrMGspTN6bK2OD//Vm7RnJP76LjJcWXJHnQ+JFiRJp8w9wCbPTVkGXDxTjEu7fWhOwLXX4T5uOFLh0aYUzR3kdRwuvjC/JImNaZdT6VH3BK7Z70cvas4jyUU/CiJBjnIDrhb+jpb7aiQfcKAPv5WH+mgXlBtBfIb+QL07vL33B1q+vjiTmwQHjq4OAB9K7n3z25RFUwApZ0XtbSI4c0F4TU7U9pPznj8WQbeAH/uSQ== 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=CTPolVlOjH3rGDI7HOnmsS+cX2W5umFbzmjcwbFzghM=; b=Rhz8JUyRENJgNsKb4iUL1n5p0fKbtLPSFKln/mJwRHD5reVXbzL259UooARRma58x2H+Xww5T9so3F9eNwcglNnFhzsTPhyE+mQSNwny2Kfv44OOLymjPM5ujIYRB08dZqS5ARyERQx4R7RuvW0d3h4t3cADGtKPg3otFv/1QTQbxdYSa0DiY6Rmfk0lDGVW+8t7d/SVlRZ5URCPKFtYgkTvG/uODwK3MTHwjFrtrTE1uZi/+KESxmnG4RVYZ5Yi6ls7blGMx9kyYMjxFYTEaLBNONZttos3vrCiYN4bVTw0N2L/T1Zb5YoW0poiT9/PlUmjlKXad3GRjIWDYhk2FA== 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=CTPolVlOjH3rGDI7HOnmsS+cX2W5umFbzmjcwbFzghM=; b=pCWvgerg5gklrgm9hm+c2dJSSuuIB/qhCzuGw0vyY/QKv+bLLNw4AhywjoTB+hCpAoXbr/vIbaYgHV8Dz8ZB/uQQ/ZfUi86F/6qSEbWT8kJ+WYLzA9qlNc22W1Uq9SV49aT0gJwdPliRyp3CXA9XTsUC8WlIIOKFW4pLGOiAQX0= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:16 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:16 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 02/11] scsi: scsi_debug: Don't iter all shosts in clear_luns_changed_on_target() Date: Thu, 23 Mar 2023 09:45:46 +0000 Message-Id: <20230323094555.584624-3-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: DS7PR03CA0269.namprd03.prod.outlook.com (2603:10b6:5:3b3::34) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: f6cfbf09-7556-4bde-4190-08db2b83722a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o3U/BpSpSaYBgCQeRZZA7CR8xZcZSw04lpWZu+hJtrPdz+ThoY59GsDwi11hkX0QJidZ424A+CjD45NRi0kNS1tFOBIW9LrBPBS2Z1wN7yfiNdZEPBgxquZ9B/NtpiDaqb4enclYJRZsKpwsR24DJ/1GeZ/+gKN8eybhoCVvZmHGbj4KY8tjgYntm7Hc0NE3dFSgZkhZwpXjnBUDLahv/y4rtu/RhIpn2Cb9sLZhUpwBRWn5p8m12KuQofB1QUDHUF+yz8oG3KbQo0Lh2QVnRnELQd5zbLo9z73M1LvlhuHbLE34hevQT6hrMR4xTN/8+4YXfZFTqSR+EWaOWTr7X7XJf7Si9Vg/48SbRTUZ1pVjVyFdJRbRBMsvdbMxIY2kvfDToSxOjo8IfTxkZ5kyLPbWhhxuRCpC8bmHk2/ECxzcjJaafIZbimupKBntAkOvejeBq3iG35MvhXHc4/9JLRifHHg7Qylic/PM/9rmtyj5vdRwg93wv3woJfWqyV4d8FcRc8XQbhAZfAY28+PPlwzyFNrma2Qtgv9UAZeknWTDqJPff0NCdFVQdK+D2sWSUECxFRbRa+u3A4zwMrFftygOMWc11HYBauNvyRGz3fe4I12xbjmH+IOewEwJHHqRaoSzFj+Jd/6jI1xmIacCEw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(6486002)(316002)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(107886003)(66946007)(1076003)(6512007)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Z3RB1RSghvF9+4ypGXaRDiBumtmBndHV47o1rH7bGHwCTSkt7r/phR9pK67rMF3E1dmBiiv84/WutRzxOpwYGY0HFtpL4jbjg4iY+KQSdzO2WTJLeToZ/heKxdXEFiZTn9rGgJv0OaTHeCFiBRJqPJh7eFhgkmMSQV819cxoMbrcfZ9cLwfpj7KcM8XwKXyHrHbM5eL41C2ABRg5DVkswQBUp8e/ijuserFb6FaoLvhT4Bag2WP3yHIS10lUEGAOxeemeA8jxxaW6nk9+biHT70QtGmJ4F9zUjpapPdhFRf9Fds1O7kPZWY752CAamdwl0/Qo+jWJoiXFsoZ1nmDC3pMU1KCtZjq8iT2UM8EA3pEJFZiOiExIjZ+rGkbzLWpbkpSvOL9DWvtY2xsDPGS4vQl4K7hsQGEBr8hsFUggnlhb+lSHSVRfXK9/3Oc6A0G6JFfzvAixoINMiDl7HRTmEP2XlLij6HaJON8Sj1fYpnuHtSvlFK/Fnx6HJXN3tHWB8gYQ4bXKeH4RHz4bS5QGMPK67Oxiuey+DRa3uhyHvp99ZkuiStN2afw0YJYRnq6I5ZS4v5zOK0L3GCMBe/XB+VsoNt+e2NJ1RX8EqpFndHw4CeoNzr4Wwm+ob3YEOWtYf0GkezZQdJ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/S/KxW83geyxDcLjU3rqRn+eUK/4fckxUVf/5iuNMf8U3AwIefymQiJmVUj6HCp2RalEB4nduFE+lAYXuoIerbE8jxALFcZsAaqHSIpAyNq3J78gTNJh7WCZTNSK1wuVGvDVl8MOKyjgC1i4EYkiU/cdbRy9n6eepQh+7p9mQjzxShrfqcugfgvHA4nUBTP/BJhrF7wgmaFjFY9VUyhY1zg6G7yUWfG67UIMvmST95ouEnorfLagqy8lfQ2KuA0aoy7oj30uqqYO2V2hEggR6fmp6As5K6AvCXp7aoFJUX1dNrJTQ0whv1n/URu1uJ8k9XTo2HVDeaJq1EtnMIlM1sxLaa7jT/2zR3el7a68jKW0Yb6QHagNb/tY0ETPw2azdc9QkmzbgSuvZ/RhJgd6zmhheqGCyXEoHhOJcRXJ+f320I78pvG3E4xhVDcOEtUZjk6Mm0tbHN4ejg6soxGzmH+hTzyh5rr8nBNiceWndT8C9UPfnKY5afjytnJPywkP77n0JxxZVbiIRy91+8CJ1+3OpdqFy/QPO+KutXjI7oLpQtnRzxJNcFDg3T0PpUfmsLxtc2okcHtMYUonm51adFHW1SNpIlwsV8cfC2TrHiIycBYDYofIkpBQFNPgcTA0IMU1LmLbfR/vDk1bYkgwG1TMS5Ro2t4r92yA2c+JZiWgt+V1AuDWheoDcJ4CEadx1Yn1GKOhNvUlUb4XBmQSeQNvFDuDi93h+6aIJBSDVn2pLTGigwcbb5U5/NnUBBXzezarJ3xjkfkwi1cAyBXWMtpoHZ63Rf7ZOVdIm/RN3+YGLhUyatbZXMOolUaYYYJCFsGAdVBI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f6cfbf09-7556-4bde-4190-08db2b83722a X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:16.0232 (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: nU/hRZ/4WO43bdS27yo9nTlUBAP2pGSrUQ12lUCufG834J5+2H3nDGJP+EY8KM6Vn2mULdPkoJ5JohTHMxE16w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-GUID: 5vdny6hxZAV0j8NsWSsZjItaXMAHCKb5 X-Proofpoint-ORIG-GUID: 5vdny6hxZAV0j8NsWSsZjItaXMAHCKb5 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In clear_luns_changed_on_target(), we iter all devices for all shosts to conditionally clear the SDEBUG_UA_LUNS_CHANGED flag in the per-device uas_bm. One condition to see whether we clear the flag is to test whether the host for the device under consideration is the same as the matching device's (devip) host. This check will only ever pass for devices for the same shost, so only iter the devices for the matching device shost. We can now drop the spinlock'ing of the sdebug_host_list_lock in the same function. This will allow us to use a mutex instead of the spinlock for the global shost lock, as clear_luns_changed_on_target() could be called in non-blocking context, in scsi_debug_queuecommand() -> make_ua() -> clear_luns_changed_on_target() (which is why required a spinlock). Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 782515abca2c..eba6eca81e84 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -1063,18 +1063,15 @@ static void all_config_cdb_len(void) static void clear_luns_changed_on_target(struct sdebug_dev_info *devip) { - struct sdebug_host_info *sdhp; + struct sdebug_host_info *sdhp = devip->sdbg_host; struct sdebug_dev_info *dp; - spin_lock(&sdebug_host_list_lock); - list_for_each_entry(sdhp, &sdebug_host_list, host_list) { - list_for_each_entry(dp, &sdhp->dev_info_list, dev_list) { - if ((devip->sdbg_host == dp->sdbg_host) && - (devip->target == dp->target)) - clear_bit(SDEBUG_UA_LUNS_CHANGED, dp->uas_bm); + list_for_each_entry(dp, &sdhp->dev_info_list, dev_list) { + if ((devip->sdbg_host == dp->sdbg_host) && + (devip->target == dp->target)) { + clear_bit(SDEBUG_UA_LUNS_CHANGED, dp->uas_bm); } } - spin_unlock(&sdebug_host_list_lock); } static int make_ua(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) From patchwork Thu Mar 23 09:45:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13185373 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 04F99C6FD1D for ; Thu, 23 Mar 2023 09:46:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230367AbjCWJqt (ORCPT ); Thu, 23 Mar 2023 05:46:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbjCWJqq (ORCPT ); Thu, 23 Mar 2023 05:46:46 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59F0B244BE; Thu, 23 Mar 2023 02:46:44 -0700 (PDT) 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 32N5i4am011361; Thu, 23 Mar 2023 09:46:40 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=GhRMO7BnK6dQXX6z1oxGtvLvbEdp7/H2MMrMYl19yOw=; b=vucIeaV0g0FSP5Vxi4uxaceyzdwapi8sKhKTNA/Pkd5ELHhYy7w4v34JpCZeCBY66GmM 9N8EeUuQB9aKe+rFDXM91UbXgvx2zFhU7K/GrsTsTqCAuS1lA23DdrY8CgZQjfYO0tbF 2YHrtlAhVRpCrJ6D+z0ysCLbjmAhBDeF5glf4A45j66PGenQQ1P0x1HjWvOvKbPfV/Ei vRw6guMyIXqAkRXg4BzcuhMRyvbW66UoYzVbKnX1IARyHw6pAbvrE3c94wloLM/1XZq3 NqQ2dclzQhOgNX1ByXCYA5Kgh+Y7PWcBS4DemZAOv01mKxeyTWqcK08H+uuQch5z2/5P Pg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd4wtb7pq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:39 +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 32N9cdiA006987; Thu, 23 Mar 2023 09:46:38 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mq6emKv7zqdOuJNbxGSEuaY63PgDNZG9ETlTeId3Wu7KappGn+p25zLKkRAv9KDFuokcpsLvxyPMVC5ZpRfb1fNu6HSr4F9X86LpcBZaO80VKdUoYaQ3xNeKeZlX9xPFJDQmBbPVeryiYEMfCNgU648NTj2K7T6It+XEb6tAf9wER0YzLYVDZtKjhxNCuT6ZmdUOYwsKNwOJj4HoS6keymush9ho2YLyg4kuxmonPQ2OVQx1AD7+ZJU9yqPr3Sw4BaXcYsyQ+UbU+UfXtWtsTCRwU/oQmlmHrj7Nw41Zz232DVX89OS+EPF5MXtcVH5q5rbetEE2xMD03Z0XQ0OiQA== 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=GhRMO7BnK6dQXX6z1oxGtvLvbEdp7/H2MMrMYl19yOw=; b=FbJe1l4TixlLHtz/TKV/EFXeLU4HG44mInWcYklfZK0hjJTarPW4kwMtyiZWjvWxYqsys2EEZtu8sKN4rLZP6EQvoPzaz2ypZ8vW85roUPaBOLj37341+gXm49NZtHxvGdR47t9+fVKtKzxYaPkEw57LKAWo29Cbtmxxauxhu3B68lPtbJk/3So7QFkKF8IsGZU06RCOrKlRoYeVsYSQ3/aDFziNazHDjxX6RYfv8bYYXCeSyVmW7YIXze6f/DvQMR5P2Z1mr+UApUqrMVJf6uFygTLcJQzFY6dNBVX6Pod4Xl6LMwywISOYFnChbVxly4L36Ofp9stWPGi17qoYJw== 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=GhRMO7BnK6dQXX6z1oxGtvLvbEdp7/H2MMrMYl19yOw=; b=KI+OejzexsB3Frg+2ohZmhzOcoD0n2bwBeQL8O0HQ290FANDLFBNMo7aO7qKxCI62S+5CD+oCWMZSMyjecOBtCaMZeLe5NSpD2ljxtZlh790ygwDMGf8hqUaAQv7XNPsRTe/l/i2itl8KPl1mCL02qHc8uodfkrtDuVfGVhPDQE= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:17 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:17 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 03/11] scsi: scsi_debug: Change shost list lock to a mutex Date: Thu, 23 Mar 2023 09:45:47 +0000 Message-Id: <20230323094555.584624-4-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: DS7PR05CA0102.namprd05.prod.outlook.com (2603:10b6:8:56::22) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: 60a82656-5b4c-4719-61c1-08db2b837303 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pe6d+UQpkkDmOfLpCIztb6ADbkL3rZ7+xvl7azWn+zC0Wlt5SzWFpCfgn2+mOPZbktMrooSb/yCdxNJpgKd52BlHN7FWQbYEZyT3BSJ+yR3DhV/paKvSj+k5WXcuyudfBflLJWFzewsrUdLWE+XwYFa8Gw/qI5CK5iWXb534EpXlAqBejY8BvS8SSw/0iELETQQTFoLBYp0NZmSI70iQ9rqTHOSoSEGc8c/0DfMc2465UzyBUvvDSCFXeBoJCMaw4JOshEMGaPqCJhmFROtvoUFWs+Iu7toEBMw6QziEu/Ixny41mJz23nRWY1Nf0JzPTGI+pLDEtwyyjb5bQyQeIGhMgO5+0totSbOFE5cOrW/Y+09UL9OtptNvisiU2lJYyhleKtDVJ09ZIQHbW93mgWQ48JiD5JdB/91Q1Hvhr3oayCPGF9WrLUD9irmAIDFexg5kGdOUkGmUASVKZAJ5NWGkLdI8qUBRQv+8i7azJidXWfR55AzYWfhzPHKAtwFVX5IXW+vXk9CykWdrTZ74OGCHVpqZx7T+NdFZgLgh+2Fbpjw22wZR6FPdKwZLrwp+oNArfJDfOOPwAMm+aQpfVNf6+AFzpSRV6/T9aWM5ESMUt97Y47RKd0aORhqGWvKR2rD/PQeDpO3M+02c+RadkQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(6486002)(316002)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(107886003)(66946007)(1076003)(6512007)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ya0nQ7eqq9nqzBhsEmprSKxQmzOOp+fQUHcFV7qHJhnVilUfPD4DHTOdf0MEpOcnPmaBgAEm2ZHaOf970k2inLC/hdFRNCGyVNbyD8JDeVoY+nvqmU5bUOEtMIBwhgDp4482o2rix96CKnfKsclva/Arl/i7s5YW3ZOvSXxUSBiuWJUXIfwSmRaZZRpKyE5ubS/wbP+aBO8xtdfs2uuJA81WTlq/9kzo1IUC79gPwE1ReLO8PEbxpjDfIDY9HGvgrDUjuTp2wJTaraAi/G2+zOpgal60+kUw9xMf0OefzvwaE8dI1lwMwllN7v2qwvwLW/9rQfDUnlnOxTtv296Q/PZsLUL47VNG3YsDP3g1fgcr72ervZHY8yukgepT8xnD1RNY0duaiv3BuWvc6q+mbkI6qpQLtDzoxoQZcs5mW/Rx/UhfAJ4D9/YBBgoGstMPt6ihAiqrWsKgsx50Eje7qcgZREZ/euvShC/Kxfkpfa3bDtdKgvnkwSsIUba7vipLZ8cyBwp7SnxFkqb+gIg4iAgFzm1NWX+EMJV7SGKg/48/hrin6GaBopKUCIX8fSflXWLgoFtPDwncJN75WXD9QAfEB9EvghhJ24Li/l+doNAus2v47nRdMq4RXa4zRagTWtt6X630bZkw2ieBQ2UDnQeoK8gbq/mhVYmJcBsydjJGxBlIsm/A7SUdlTHxKCCsgMwH8PcjJxKvRrrYdbaNCLPjxhxUV4cHZVmya5wsGeGgUk7Nw/NgD8bwoChywRNRxQhcE2DpSbwDv2X2cEN5Fd5Kx6Tn2k2buJzacfAgKIb5g7P/hj4Ow/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0wy32z/B4MNwS4WypNUcfadgz7gprzZQ86QVgZrRgohuz5DC8Y8PcPejZaeeyatTrwUxPz+0o88eshF31uwD3nFU9DrP/5Agj6vZe+cZGJNjnj2qPQSgBBIQq6S/568ZVLXD2+CDIQT1f86ClRTX3zUwov92HfTgn0ROOX96e7RlrEX1VvCasXE13VGXLQYVYtJEOMotPqR5zTglYkHd1iYjsRwKFRTf2K9/1Y9+J9kBvfes/tR2U3Q/85dU0Ay5EP9+tAPeMutDfUD+Lb6yBZ8uWP1sRjf50ojz9ENDuj5hEoaQCYoy3Nt1rrvzSELTZrVKryksAzbgPO1/IRGWNcukBemA4z5FX/aFsa4OVcdepFiKnQblbyylCZMmFR6VoUJJI3GrKwFifF1yfo0vTdLbf2oBnHNzXsMPxu6P9fBodlkTDdAHq1ReL5+tWLH1eU1BdOcbwMumW75t5R9A8TUJCYJrp8EBzvn322Ec8LWfo6Os8MUyZVK2YVZZTd3QHyiauxn2x1dXB/1w0x7pLnFzsFnyf/dTCuNHuCVxtjyAKu7F/SQE2Tuv3tOegWIPxIe/PMPTEuCNyQGCmmLlP/5Gcy9PpEj/5OhZ/PZFDCySYQGLGjyZmvWMzM2PlD+bIE3MpmhTXsLdKNPBX+kx3FzLW0T40S8+gE5M= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60a82656-5b4c-4719-61c1-08db2b837303 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:17.4306 (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: YxvbViMdH0wLtxAtbs2luT9yLLig3iAualY9MoKr65Qs07VLESFF4mRXSxMEjrmbCo4WbQQjbnfKHp921eS8KA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-GUID: IudMzMNwS346n8xCa78QHSr_D7rsRokm X-Proofpoint-ORIG-GUID: IudMzMNwS346n8xCa78QHSr_D7rsRokm Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The shost list lock, sdebug_host_list_lock, is a spinlock. We would only lock in non-atomic context in this driver, so use a mutex instead, which is friendlier if we need to schedule when iterating. Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index eba6eca81e84..a61e7c31dab5 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -816,7 +816,7 @@ static int sdebug_cylinders_per; /* cylinders per surface */ static int sdebug_sectors_per; /* sectors per cylinder */ static LIST_HEAD(sdebug_host_list); -static DEFINE_SPINLOCK(sdebug_host_list_lock); +static DEFINE_MUTEX(sdebug_host_list_mutex); static struct xarray per_store_arr; static struct xarray *per_store_ap = &per_store_arr; @@ -908,7 +908,7 @@ static void sdebug_max_tgts_luns(void) struct sdebug_host_info *sdbg_host; struct Scsi_Host *hpnt; - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) { hpnt = sdbg_host->shost; if ((hpnt->this_id >= 0) && @@ -919,7 +919,7 @@ static void sdebug_max_tgts_luns(void) /* sdebug_max_luns; */ hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1; } - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); } enum sdeb_cmd_data {SDEB_IN_DATA = 0, SDEB_IN_CDB = 1}; @@ -1051,14 +1051,14 @@ static void all_config_cdb_len(void) struct Scsi_Host *shost; struct scsi_device *sdev; - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) { shost = sdbg_host->shost; shost_for_each_device(sdev, shost) { config_cdb_len(sdev); } } - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); } static void clear_luns_changed_on_target(struct sdebug_dev_info *devip) @@ -5423,7 +5423,7 @@ static int scsi_debug_host_reset(struct scsi_cmnd *SCpnt) ++num_host_resets; if (SDEBUG_OPT_ALL_NOISE & sdebug_opts) sdev_printk(KERN_INFO, SCpnt->device, "%s\n", __func__); - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) { list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) { @@ -5431,7 +5431,7 @@ static int scsi_debug_host_reset(struct scsi_cmnd *SCpnt) ++k; } } - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); stop_all_queued(); if (SDEBUG_OPT_RESET_NOISE & sdebug_opts) sdev_printk(KERN_INFO, SCpnt->device, @@ -6337,13 +6337,13 @@ static ssize_t lun_format_store(struct device_driver *ddp, const char *buf, struct sdebug_host_info *sdhp; struct sdebug_dev_info *dp; - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_for_each_entry(sdhp, &sdebug_host_list, host_list) { list_for_each_entry(dp, &sdhp->dev_info_list, dev_list) { set_bit(SDEBUG_UA_LUNS_CHANGED, dp->uas_bm); } } - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); } return count; } @@ -6373,7 +6373,7 @@ static ssize_t max_luns_store(struct device_driver *ddp, const char *buf, struct sdebug_host_info *sdhp; struct sdebug_dev_info *dp; - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_for_each_entry(sdhp, &sdebug_host_list, host_list) { list_for_each_entry(dp, &sdhp->dev_info_list, @@ -6382,7 +6382,7 @@ static ssize_t max_luns_store(struct device_driver *ddp, const char *buf, dp->uas_bm); } } - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); } return count; } @@ -6489,7 +6489,7 @@ static ssize_t virtual_gb_store(struct device_driver *ddp, const char *buf, struct sdebug_host_info *sdhp; struct sdebug_dev_info *dp; - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_for_each_entry(sdhp, &sdebug_host_list, host_list) { list_for_each_entry(dp, &sdhp->dev_info_list, @@ -6498,7 +6498,7 @@ static ssize_t virtual_gb_store(struct device_driver *ddp, const char *buf, dp->uas_bm); } } - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); } return count; } @@ -7258,9 +7258,9 @@ static int sdebug_add_host_helper(int per_host_idx) goto clean; } - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_add_tail(&sdbg_host->host_list, &sdebug_host_list); - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); sdbg_host->dev.bus = &pseudo_lld_bus; sdbg_host->dev.parent = pseudo_primary; @@ -7269,9 +7269,9 @@ static int sdebug_add_host_helper(int per_host_idx) error = device_register(&sdbg_host->dev); if (error) { - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_del(&sdbg_host->host_list); - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); goto clean; } @@ -7311,7 +7311,7 @@ static void sdebug_do_remove_host(bool the_end) struct sdebug_host_info *sdbg_host = NULL; struct sdebug_host_info *sdbg_host2; - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); if (!list_empty(&sdebug_host_list)) { sdbg_host = list_entry(sdebug_host_list.prev, struct sdebug_host_info, host_list); @@ -7336,7 +7336,7 @@ static void sdebug_do_remove_host(bool the_end) } if (sdbg_host) list_del(&sdbg_host->host_list); - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); if (!sdbg_host) return; From patchwork Thu Mar 23 09:45:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13185372 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 0E1D4C6FD1C for ; Thu, 23 Mar 2023 09:46:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230154AbjCWJqr (ORCPT ); Thu, 23 Mar 2023 05:46:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229796AbjCWJqq (ORCPT ); Thu, 23 Mar 2023 05:46:46 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C70E5244B6; Thu, 23 Mar 2023 02:46:43 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32N5hoNR019252; Thu, 23 Mar 2023 09:46:40 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=qFXVDiIPGL29fDlEkhrVi8b+mbqq8IgrnJcIxXciOA4=; b=ZLEfu0aU5nRyIISajjzbq9HtR0f0nof4TqpHNrtk6AxbZn+Yz922SMar8toz6Z5yA7LL 8aldaGHFmo24ZWA1Pad/Y59Jmj/Ksb7p145UN7S22L4bpxOKX58tqcDPo+2XAZLecvme kLMSLupyf+uTFv8nWtSdVSD0Wvz4UH4K7p9t6b2dLOrbVCb9oj8BCwjDvpxiMTNiK6wa XQZRjLoLBMfTmKMQQXdit+BdDFU7+R/aBJMNFcUb1+Ly6AdWJ8YvILPvcBAgs3Y+T1Ip t+aQlOvgQ+gXcrwjeV3wZOXHW+MkNbGW8QjbIjg/a1IZejOnoXWVkOR449FWCFPd1c1t 8A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd5bckbpy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:40 +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 32N9cdiB006987; Thu, 23 Mar 2023 09:46:39 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TIicn96HZJgYzqtC+UnF67Vo25gWI+s5GuvJys279HF7oNeVK+czhF/X3z/kAlVz0q9JLTkxSQSXqsRYQKfuczuQeLgASlcSwSWtna02FTlWb7O9KX0scAiOYLSslIVk1KjGLUKdFiwSoaPsMO9p59V2XFt7C19NfzFwI1MNjp72TEElnZ9jBpkBGnIal7IG3Y1QnQ6uFC01J0MJTJiaR9L7mhZhINE4C3wfYYd/dzrqziQSgbUNXTejA02uEIknPbVT8/PvIa4Ld8g9uL7Ska6nRaCxQHGhqhO5DtcO6na+SquJj0udMkxUPe0Pu26/LkTAhRZSCSC4ngYG9svWpQ== 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=qFXVDiIPGL29fDlEkhrVi8b+mbqq8IgrnJcIxXciOA4=; b=buVX/vQ85lApIrSdUj26eFtuz0J6S1otHUOZYG15r0mpI8i4u2OSqnUEs3FVAfKNEBCB8od17Zcfv32sXmNVlkwHI7xW+K2VdtVc1iC4lWFMqBHRzq65TJi0VjxmSUix/CXPqlwgoe+6Yb5SqCsjlD9U/Il6t8ShlJtVnGGNT4Dvx/B0dbNNuFTvzbtFDIXCv4AAxfv/3NZvcNnfgd44fcNUdsg0+0Kykp+bkcTDGe94bkfx82foCuV2a4LQ6XNGu6LIqMbF7amqGPCp77YcQlF2h2HSVJmJarnEkZ6YPWCbSsLCyEG80c92Wt5gz/5RPhfybUgNsBz5EvTdNjkmPQ== 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=qFXVDiIPGL29fDlEkhrVi8b+mbqq8IgrnJcIxXciOA4=; b=drociXgot2iypFeJbtd0TAapcl98sqvXjljHspQHzmxTUBiHM6+proAoCwDDxQ8JhJCM8T5iNdUHkfh39KAeRYbH7KDCZSINS8CeAKOD0zMcDo77YhcDb5wJOgEc4etaZlfnctZxOHFmMoDaMj5mgwxEA8+/5ZtD5A4UbKy2Hck= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:19 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:19 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 04/11] scsi: scsi_debug: Protect block_unblock_all_queues() with mutex Date: Thu, 23 Mar 2023 09:45:48 +0000 Message-Id: <20230323094555.584624-5-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: DS7PR03CA0234.namprd03.prod.outlook.com (2603:10b6:5:3ba::29) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: 4547d2db-dd60-4754-734e-08db2b8373ea X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bi4q1vi8Jw9ZryzDEp68RU+9mhG8leO8/G6UprtoF/xO6K1ea9Shh0RVFhLPoiJHIeuZBYNp5YtZiatB4+b9Yszx3YOlALRRp4abYYBfj2U3RziXGXDDS0UhOVZFufSogaMd45WP90AERmeqXjCGSylxhAU5Wt4Sw3cUkmjA3WZ+5kKWPX/6g0SjjjWd5lDwK3DG9smq2fxSFDLrWbGWC49DoNxFHZPHrizGb0PxYv50CsVNZBfO7qglWj3SjG3hP5oUa3F46yN3ht7mB2an9C1FPYE+IX6AHRce552Za7olgqnUP7nQFRiAt53jmPXL7GyauqU5aJP4voq5b2HsebVdgk2OIAwXJUsgvxdz9jTlt4PYV3LyVSfYP/fqbkt/n6fXT5f0TNA1lUjC6PJwTqtALIGaYc6w/369+kXi13xZtyMbVoR9MLF3UE7m/q9i+pFTG4nQ4ibST+i9O3oT3rlxexk+uYQoW8jQx0Q4+I1F9dSFjPi2oapWLDYjOotC5kLLWIZXpW7A9Gg6evte83g/ezrAdCNqcCiC3qiu3kKMKcueSXGH7815alR9QGaNEnnYVyTXusp5AEDhvWvywd9oTLlDVQPV0+HpJiTI+u9KTLEqFUH5xeGfLmx281lUPSJNCsFwN1f8ER1xUzTDsg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(6486002)(316002)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(107886003)(66946007)(1076003)(6512007)(8676002);DIR:OUT;SFP:1101; X-M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iPx8KG+ktl50L06QA/NH2f1qrt6X68znSKh1xm8TFRNVV4rt7/E2xjDkBTEn3FY366yImMvpg+ZWYuBJv2QoMdWhP/dvbqR7mqx0zxEw9XcAwM4PHB/uiWuhIlNCJZ4jVqF/15N0kiRCBFql2LFmNBVvFOFUFeqHWvtTesA42fa/PKyQrLCBHSH8b2VXDwsqXPb8WHOMwYAY/Ii7+OsPBTr8pCp/s7bcG71yqaJtWHAAdf8Z0oaE2FYTpBSHHsfFlmPcz2uuwGUwFSP18/T4fL6/C525jObklHLXlICgzu1ihum5txR775IJm73omnv7uhpVXqbxSuLnpt1W5Wen4z7SnZt83UxxJcTU1SDwkdv5qJhjIUu0gFz4JEKhT45/NI46nG1PwGhGV5ybiwZ5RkSLSpEbFdVrddrDD35cjNnf4+x4GW40dYj8zBbmAd/cNtvaQUwjT5zZTlMNc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4547d2db-dd60-4754-734e-08db2b8373ea X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:18.9761 (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: 5GpVY/S5RaPMerr6SFBcNtnhWq3AJUUzmBcV3vN6Q20fwik5+ahs/rzwftbGkXBNSK/KTWnmURldT+dcOGnNdg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-ORIG-GUID: 7QhtkHXvG-_ohpPUear8TdYOo29lRViS X-Proofpoint-GUID: 7QhtkHXvG-_ohpPUear8TdYOo29lRViS Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org There is no reason that calls to block_unblock_all_queues() from different context can't race with one another, so protect with the sdebug_host_list_mutex. There's no need for a more fine-grained per shost locking here (and we don't have a per-host lock anyway). Also simplify some touched code in sdebug_change_qdepth(). Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index a61e7c31dab5..cd05e2f87417 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -5497,6 +5497,8 @@ static void block_unblock_all_queues(bool block) int j; struct sdebug_queue *sqp; + lockdep_assert_held(&sdebug_host_list_mutex); + for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) atomic_set(&sqp->blocked, (int)block); } @@ -5511,10 +5513,13 @@ static void tweak_cmnd_count(void) modulo = abs(sdebug_every_nth); if (modulo < 2) return; + + mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); count = atomic_read(&sdebug_cmnd_count); atomic_set(&sdebug_cmnd_count, (count / modulo) * modulo); block_unblock_all_queues(false); + mutex_unlock(&sdebug_host_list_mutex); } static void clear_queue_stats(void) @@ -6036,6 +6041,7 @@ static ssize_t delay_store(struct device_driver *ddp, const char *buf, int j, k; struct sdebug_queue *sqp; + mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { @@ -6051,6 +6057,7 @@ static ssize_t delay_store(struct device_driver *ddp, const char *buf, sdebug_ndelay = 0; } block_unblock_all_queues(false); + mutex_unlock(&sdebug_host_list_mutex); } return res; } @@ -6076,6 +6083,7 @@ static ssize_t ndelay_store(struct device_driver *ddp, const char *buf, int j, k; struct sdebug_queue *sqp; + mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { @@ -6092,6 +6100,7 @@ static ssize_t ndelay_store(struct device_driver *ddp, const char *buf, : DEF_JDELAY; } block_unblock_all_queues(false); + mutex_unlock(&sdebug_host_list_mutex); } return res; } @@ -6405,6 +6414,7 @@ static ssize_t max_queue_store(struct device_driver *ddp, const char *buf, if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n > 0) && (n <= SDEBUG_CANQUEUE) && (sdebug_host_max_queue == 0)) { + mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); k = 0; for (j = 0, sqp = sdebug_q_arr; j < submit_queues; @@ -6421,6 +6431,7 @@ static ssize_t max_queue_store(struct device_driver *ddp, const char *buf, else atomic_set(&retired_max_queue, 0); block_unblock_all_queues(false); + mutex_unlock(&sdebug_host_list_mutex); return count; } return -EINVAL; @@ -7352,7 +7363,9 @@ static int sdebug_change_qdepth(struct scsi_device *sdev, int qdepth) if (!devip) return -ENODEV; + mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); + if (qdepth > SDEBUG_CANQUEUE) { qdepth = SDEBUG_CANQUEUE; pr_warn("%s: requested qdepth [%d] exceeds canqueue [%d], trim\n", __func__, @@ -7363,9 +7376,12 @@ static int sdebug_change_qdepth(struct scsi_device *sdev, int qdepth) if (qdepth != sdev->queue_depth) scsi_change_queue_depth(sdev, qdepth); + block_unblock_all_queues(false); + mutex_unlock(&sdebug_host_list_mutex); + if (SDEBUG_OPT_Q_NOISE & sdebug_opts) sdev_printk(KERN_INFO, sdev, "%s: qdepth=%d\n", __func__, qdepth); - block_unblock_all_queues(false); + return sdev->queue_depth; } From patchwork Thu Mar 23 09:45:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13185378 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 17723C6FD1D for ; Thu, 23 Mar 2023 09:46:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230525AbjCWJq6 (ORCPT ); Thu, 23 Mar 2023 05:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230302AbjCWJqs (ORCPT ); Thu, 23 Mar 2023 05:46:48 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F5B6244BE; Thu, 23 Mar 2023 02:46:47 -0700 (PDT) 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 32N5i7AM005177; Thu, 23 Mar 2023 09:46:41 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=8zn4ye5Wdo3UkBGVsStS8b3TMCzSwtohGd97Hs5Iyrg=; b=IxKaYLng/VXWRiX63dy7+Cv5XXnHdsqqtQKiOFzUM8H6Qcp9Bu3tmivvhC1SrMhNUYGU F81haO+OXCC/onixf0mYAaMImrPayw3fiVTtvuCWmDyigMSzBeRPDBGIAu39W+vpfmIH Mqf7Zs8O7tgRhvSmLLPi1vpnnJkxOjQRiv9MZEcrDHynZDaJBIEe8FcLI86wag0A9YEz JNdnTWEqtJfgvm3oyT2AHEA4ygtrgkz4V0o1gurZAT/4G0pmOrbbneXEkyUne6xySPcZ anpiaIdYQtr7deUQIOcfpSMTsdxRDbWv3tthpA2pFULBD29aLHI2YVkYJuLfwEXlNEWX +g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd3qdu3ya-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:40 +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 32N9cdiC006987; Thu, 23 Mar 2023 09:46:39 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rz9N8RZoufynyrdHPEWahVg/gDtMBnTPvGzguiyLx9AIrDfTXGWOGgW72V0SRXYsSPmz3DEbz9Y2DGNMDtIVOThkbRP7Y1UiPchpFMrCSXiCg+oNpJGVEg3vPilkXVwETnktdEhFObQTk5fpVDyeB7teyiyGjRPNDNF4a6CVHhx/y6Aat8wg4WuwVVZ3XsZHMrsBmn9TZFlKxXwxebvFeG7fPJbnwGx4Zmc3ikv5I5g+Nz9GfOfHLO0cMyzmUriqXGrptNPTvkO0YV7N11CsekzHiaOiXqA5ndvUgU8EBcgHJIjgsulQEC20W9Kbo5CPHAqnVt1B9PXo+1kLhsNiqg== 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=8zn4ye5Wdo3UkBGVsStS8b3TMCzSwtohGd97Hs5Iyrg=; b=N9ns9bPSUvu/0blBngGGcqzaXOxlvE9mSpAfjYLwRT83qVy5THmwJoGYsbdUnbgqddSn7gg/et6FAOipjdI76vVc/kV79RflIy+hHW8tD3Xx3bnMw9lQuDVYF/OF6utBolsomgA4eLV9ZhywJnFisumaDOi5lnQE6xG/W5iyksXPd60co1oAuGLcH/FOfZ4ONesDPg/lBKLIZtj82Xvaot5pFYdFiAeeswX/Zj59oFk5ttm+Dh74Arw+D+99bmWN9FgxxzSNdz28tk7TBmk1DNmIgIj91UJcbw1yMHnb9Pyb4Vw3dtiAkQfQr/rnp/f2aWRj1ySPgwBfW3dmGppTpA== 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=8zn4ye5Wdo3UkBGVsStS8b3TMCzSwtohGd97Hs5Iyrg=; b=Rm8qdkqQ2PWtvzMXN19cMejPrSHL2fxBQZSCtbrzNNBuDlezBvkBsRF+rUrZ1ytysKNDsTD/FruYyGoDAdxqNUJKAC033gfXJNRHqACBQldf7mWmkqTilVhIerWa3KBD/n2eul8deeDOtVmGQcGY+5DjhNSLPvBPqmpsS0ZCHJE= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:23 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:23 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 05/11] scsi: scsi_debug: Use scsi_block_requests() to block queues Date: Thu, 23 Mar 2023 09:45:49 +0000 Message-Id: <20230323094555.584624-6-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO4P123CA0344.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18d::7) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: 8d1e40b6-cd58-4dc8-5553-08db2b8376c6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YEPYMRtKjKWFfLXvm9/k+Xg41oQAR09gRV6p1A3jOv8vpciQwt5PxEyxQRpcHmr7Ydd6d2/ELJVA2YTy/Y1ELrWIPqrzk7P/aLQKv9dkl3SS6xR0pCs0HObrkfbKY0B/nvNFpzqCXqm7a8oBhwHYnH/i1iZxs4bLXGNMC2FmmFVTJH7wswmM/up+BqqN2OGskbUupiRbpfOdgyUFmE3v2Xb/euYqX9BH/olIcnFjNKvNbuwXcLbyz/O3TEXdzOZFFbK8OyomS2gvC2EcVet6lM9mzG12ndJzGoaKRlm1Em9i9zaRfPOyLqJYdZA4nfjJfZqr03X7qx88ACm01WnzeWXO1Ov3h0MsAND3CMLW9zCuwbyhrrO3EAEycVeKcGNXX39mXiIrXXy6JnVizWL+Pd4GSPIkD5R0JZek4EBphKIsDjLYWMGS/pgCZw6DE1s1LErU9xEJ12aKrmY4K3L+KMsvri/U5ZNTEzyvMxvy9TulQi1I27Bkr3GkbZ94jInMEubYODWovHkrhqJGAYADPU4N1dn0wCxkI7UmAGRJ9VpQhuFKDLBelM3ro8hA8iVSn7qBikfg/jZOOJuGh41voKm0dNKR3zR3kDTWpovRTdJQ+Ov/DT5/+htAdDPBLftUvExKTsn6k2992UC0/BWWSA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(6486002)(316002)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(107886003)(66946007)(1076003)(6512007)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wr+R/BNvg1sy9hHmZMnRr/WIg7JJOdBMaZX1lX4lsovq9/9lZYoP4O1jTJesXVfzgymf1Of8ckHO35d+d77ift9huURYoxkFfQGUmC11k1hRpGckKDGLJBmane99gLivRvBQM8Q3pnUBrn6e97PmWAHm+ryPr1qP3YnxoI4MBYtkkGj2WX7VE8paZ/6XZnht8pgsqUCC5wYqk4QrGP+PaM9E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JK2PlMZ7QkXfV18bNW/20NBtXPBnQCjz39b4+sj1oPnDK8HchjCKhd7aR/A9hXYIjUe7OgG/Ty8zd9vTqTq3KhgxiBB9ClGSEXyULkm91c2O4/ZS+WF2jJfVoQvrVByBsgJDgoBn6HwQNqLwrJgtoEdjb3t9mTsa0oKfnyFudiU6hAN5/LxclTWgEuLXLxRPvqFw5NWdZ5nQpyjRx+BZE0c= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8d1e40b6-cd58-4dc8-5553-08db2b8376c6 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:23.8507 (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: tecVkbeST6134Fp47BGqQQdKOdKofAydwky6TZZ+q2FzwGixiTlBudMrA/kS8ZXikIiOMNpSEvGZBNF7rPpmKA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-GUID: -fYRznUDkCSPDpET1p_Lk0rPUmDaaMrt X-Proofpoint-ORIG-GUID: -fYRznUDkCSPDpET1p_Lk0rPUmDaaMrt Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The feature to block queues is quite dubious, since it races with in-flight IO. Indeed, it seems unnecessary for block queues for any times we do so. Anyway, to keep the same behaviour, use standard SCSI API to stop IO being sent - scsi_{un}block_requests(). Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index cd05e2f87417..f53f3e78aaa1 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -359,7 +359,6 @@ struct sdebug_queue { struct sdebug_queued_cmd qc_arr[SDEBUG_CANQUEUE]; unsigned long in_use_bm[SDEBUG_CANQUEUE_WORDS]; spinlock_t qc_lock; - atomic_t blocked; /* to temporarily stop more being queued */ }; static atomic_t sdebug_cmnd_count; /* number of incoming commands */ @@ -5494,13 +5493,18 @@ static void sdebug_build_parts(unsigned char *ramp, unsigned long store_size) static void block_unblock_all_queues(bool block) { - int j; - struct sdebug_queue *sqp; + struct sdebug_host_info *sdhp; lockdep_assert_held(&sdebug_host_list_mutex); - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) - atomic_set(&sqp->blocked, (int)block); + list_for_each_entry(sdhp, &sdebug_host_list, host_list) { + struct Scsi_Host *shost = sdhp->shost; + + if (block) + scsi_block_requests(shost); + else + scsi_unblock_requests(shost); + } } /* Adjust (by rounding down) the sdebug_cmnd_count so abs(every_nth)-1 @@ -5572,10 +5576,6 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, sqp = get_queue(cmnd); spin_lock_irqsave(&sqp->qc_lock, iflags); - if (unlikely(atomic_read(&sqp->blocked))) { - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - return SCSI_MLQUEUE_HOST_BUSY; - } if (unlikely(sdebug_every_nth && (SDEBUG_OPT_RARE_TSF & sdebug_opts) && (scsi_result == 0))) { From patchwork Thu Mar 23 09:45:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13185381 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 66495C6FD1C for ; Thu, 23 Mar 2023 09:47:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231201AbjCWJrG (ORCPT ); Thu, 23 Mar 2023 05:47:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230390AbjCWJqv (ORCPT ); Thu, 23 Mar 2023 05:46:51 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 117F724713; Thu, 23 Mar 2023 02:46:48 -0700 (PDT) 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 32N5i64B005171; Thu, 23 Mar 2023 09:46:42 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=csfUpvnydue3c06Gn5zRcv10idpsejsfMA3qvVv5VuA=; b=JF864nGsQYEheehAf5jiFRlTA51IiJcy80n1ehI2/XVxWvftEauZ8oOo9RKuLkc2qBDS V+KhnEyFh1ki7yFFxMK16SbiHetZCeLOg+bgPJsn/rmUApp5E0FR3fuVihFW8cQ/f7L2 Yps5Tq3gY/B7lw9hrtWFYLzajC8xWbJXLIkakMtSgrkToi0EzbhHQ9j/M59xmOENJ3Cc Of9sbZa8s5ar6B1qX7rFYXO9X+u2Nct6Nc1s3LMt9l9bkAeQ8SihVI49JJ/D861Eb3Z+ ASaWFcIq0QpyHOo5jT7dfaZaxNzdBmf1AdInS0JlVYUe8atiDja2Sv5vMjYhsygZjvmb kg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd3qdu3yb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:41 +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 32N9cdiF006987; Thu, 23 Mar 2023 09:46:40 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nGsCgnSwrZA/gbqGKXNXB56zurH60jyeO9gVuTx/Jn030UlW4hHADfisGhx9o+40EV5MCn3WLl71bGQtV8CltgaadTOMmJj6Ca5hvIFRjczztAwFzS0L0MJ1mRvh9q/iDfgafJJezeFNDyQmquqhCfc0H7yXbh07FFbNbJNQoSGfmT9A/uHsWmODo8f9wtLNgvhaYMIXuuNUcngYhwPAt35NLhEeciI6bSA5NdwdGa2vN6NFBQrp29I4M8yql0Fgt2GY4vMEKcAPvd3hqiZ818G28s0QmhPLYcoe+tReYvrLV123Orf6RcAY9AgvKKpv/xU3f70oB5d5DlGhqjWeIA== 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=csfUpvnydue3c06Gn5zRcv10idpsejsfMA3qvVv5VuA=; b=abppMY43BUR8ow4n5d65L+gYGl0rDLu6u12Nhu2/PTTn+K3lJUGOfLJInMKdVB8RLorBkQMWwL5/eRWihjU0bDSUksRjW0MlizzR/RfD5uvleyQlV7GNMbmMyAMecR3tBCuvdHmGxh8ImgCPegxqy2St8OJPI6BA6Zb+9A1+r+4Fvq4nhri+57O+lw+9KF2VmkWpDDTc4QbtoHgLep03bSgkNPDCS3WF9ulsKKFzsARVySlzik7Z6x16IWo4Ye4UmVBbDLWLEWa76rnxk7ajjl1AQ7100M+41Genc2MYnOWFcdk6KSqvIUBOwBtvufb71KWGHHXZ3jV2zy6Bz71PBg== 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=csfUpvnydue3c06Gn5zRcv10idpsejsfMA3qvVv5VuA=; b=ajGpBkq2ltGyBY8+rLgVo9uE0vjw9JSoK8xUs/NMgQH0YGZy8/6GPrSeBekouut0ybas6p3i4zprNNW1DpcXvoo7SYGZNM5L5ESXUSNXJJLPY1CSS662RsT0QMlNDauT8vhkoqk7fsi7KW4Lx3Q/h4qbyjP1N6egGx2uyzftIUE= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:34 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:34 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 06/11] scsi: scsi_debug: Dynamically allocate sdebug_queued_cmd Date: Thu, 23 Mar 2023 09:45:50 +0000 Message-Id: <20230323094555.584624-7-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO3P123CA0005.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:ba::10) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: 44de09be-26ff-442a-9adc-08db2b8379df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Har4RembVgmSXYd7HohqFOQt/TJV9h/xIr3IhOSDieEkvqiYPkJVKNaNcJW5uqPUEOnGtli7cL8Ad62WWqw4ROinCa4qkQ7phW9uD03pYFkEKQQ6R1bgWvZj1w6QGsvhCNrWaaCJ18hhk4zseyAft/BhCeh/MOZWyHtCLC1QSrnNKpDpOxizpyULn4lT9pvgPN82prUslPB4bu6N34IYN92SzQ5PqDjwC25bP/9vkOcwmPgcxPkROQyvNQI6nuYrq9UU4uumwtGxCjViFUIXSfy8sWDVyO6H7qutRJ4GwP3Gs6OS10/1IqQZ2AVbg2heY454undN3Hz5vOstkbfalzGKJrN9Ov2k6PiaoZDpsJJb8+EalR1MHCKuT+vIT3ZMh3isz0vMp5hvcg9WueS9ObFl51s2bdw/OfQJlY/4OqLbhFG3LFm7tqyTbL9auKTzb8KBHKSSrS3pMsYRz+SL+8K14Ojn+GsiM+Ga6BN28bRHKtRck2SmuchR2wRAridm8sdZuuvwIwC3EDkW4sdYfUp+luQxGAnUhwT+CBnGONy7/6QI/EHQLLxa0G7KV9DWtmNtL51tQTg01NQbYppGUY1JIDtnpQ23wHr/qqS8uX59v12OOQGl5tPqwu3K8nQC X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(6486002)(316002)(66899018)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(30864003)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(107886003)(66946007)(1076003)(6512007)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Zg9svyiH5IkW7kH5xxDh03MRaINZuP7pMthEoV5VUMJCpL1ghBf2LUzBwa34enkBjscOReI5CU9M5hMwjQiyxojd8L5QygN2j0GTqz3zJEzhxkB6J2f15IUBQFC1YZ/WRlRNddgKpELkIcYMXBMLGWo9voeO9Oolhui/he5l7lcTXgIWpBEPWDo8d43zF3UGx8poxiuzviIhXenaqxo5pO9ND7V0jMkoxtTBf1e8CFaoOBGPhVgIzscxw3m5BnN5zdanJwb8xzPmNcETwNrSiCs69u3cBhyW/P9CrAs4se4jmzzvH4mfa6fMZ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p3/VkhjO4GUBdIM4xIr5lue89hgBinZr1EUQUOS602wiiI6qoE8zTinqsEIEwquL4WIO86TB/py1b6RsJ2N+01FxvaKsUjK1ZarWQ14k= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 44de09be-26ff-442a-9adc-08db2b8379df X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:29.0495 (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: Z6lWuSoV00sIXC4cvQjIky0YZw8eq9Stxg1k0dKllNrl8uItkRNvP7XzYbAZvHnjzE1Z7Z/LZXgiKkWhQ8B8iA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-GUID: 0SPmGYgqHW_V3uvCUuv47JwPdD-tYmSy X-Proofpoint-ORIG-GUID: 0SPmGYgqHW_V3uvCUuv47JwPdD-tYmSy Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Eventually we will drop the sdebug_queue struct as it is not really required, so start with making the sdebug_queued_cmd dynamically allocated for the lifetime of the scsi_cmnd in the driver. As an interim measure, make sdebug_queued_cmd.sd_dp a pointer to struct sdebug_defer. Also keep a value of the index allocated in sdebug_queued_cmd.qc_arr in struct sdebug_queued_cmd. To deal with an races in accessing the scsi cmnd allocated struct sdebug_queued_cmd, add a spinlock for the scsi command in its priv area. Races may be between scheduling a command for completion, aborting a command, and the command actually completing and freeing the struct sdebug_queued_cmd. Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 426 ++++++++++++++++++++++---------------- 1 file changed, 252 insertions(+), 174 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index f53f3e78aaa1..6606e71cd0a9 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -250,6 +250,11 @@ static const char *sdebug_version_date = "20210520"; #define SDEB_XA_NOT_IN_USE XA_MARK_1 +static struct kmem_cache *queued_cmd_cache; + +#define TO_QEUEUED_CMD(scmd) ((void *)(scmd)->host_scribble) +#define ASSIGN_QEUEUED_CMD(scmnd, qc) { (scmnd)->host_scribble = (void *) qc; } + /* Zone types (zbcr05 table 25) */ enum sdebug_z_type { ZBC_ZTYPE_CNV = 0x1, @@ -337,12 +342,8 @@ struct sdebug_defer { struct execute_work ew; ktime_t cmpl_ts;/* time since boot to complete this cmd */ int sqa_idx; /* index of sdebug_queue array */ - int qc_idx; /* index of sdebug_queued_cmd array within sqa_idx */ int hc_idx; /* hostwide tag index */ int issuing_cpu; - bool init_hrt; - bool init_wq; - bool init_poll; bool aborted; /* true when blk_abort_request() already called */ enum sdeb_defer_type defer_t; }; @@ -351,12 +352,16 @@ struct sdebug_queued_cmd { /* corresponding bit set in in_use_bm[] in owning struct sdebug_queue * instance indicates this slot is in use. */ - struct sdebug_defer *sd_dp; - struct scsi_cmnd *a_cmnd; + struct sdebug_defer sd_dp; + struct scsi_cmnd *scmd; +}; + +struct sdebug_scsi_cmd { + spinlock_t lock; }; struct sdebug_queue { - struct sdebug_queued_cmd qc_arr[SDEBUG_CANQUEUE]; + struct sdebug_queued_cmd *qc_arr[SDEBUG_CANQUEUE]; unsigned long in_use_bm[SDEBUG_CANQUEUE_WORDS]; spinlock_t qc_lock; }; @@ -508,6 +513,8 @@ static int sdebug_add_store(void); static void sdebug_erase_store(int idx, struct sdeb_store_info *sip); static void sdebug_erase_all_stores(bool apart_from_first); +static void sdebug_free_queued_cmd(struct sdebug_queued_cmd *sqcp); + /* * The following are overflow arrays for cdbs that "hit" the same index in * the opcode_info_arr array. The most time sensitive (or commonly used) cdb @@ -4919,46 +4926,48 @@ static u32 get_tag(struct scsi_cmnd *cmnd) /* Queued (deferred) command completions converge here. */ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) { - bool aborted = sd_dp->aborted; + struct sdebug_queued_cmd *sqcp = container_of(sd_dp, struct sdebug_queued_cmd, sd_dp); int qc_idx; int retiring = 0; - unsigned long iflags; + unsigned long flags, iflags; + struct scsi_cmnd *scp = sqcp->scmd; + struct sdebug_scsi_cmd *sdsc; + bool aborted; struct sdebug_queue *sqp; - struct sdebug_queued_cmd *sqcp; - struct scsi_cmnd *scp; - if (unlikely(aborted)) - sd_dp->aborted = false; - qc_idx = sd_dp->qc_idx; - sqp = sdebug_q_arr + sd_dp->sqa_idx; + qc_idx = sd_dp->sqa_idx; if (sdebug_statistics) { atomic_inc(&sdebug_completions); if (raw_smp_processor_id() != sd_dp->issuing_cpu) atomic_inc(&sdebug_miss_cpus); } + if (!scp) { + pr_err("scmd=NULL\n"); + goto out; + } if (unlikely((qc_idx < 0) || (qc_idx >= SDEBUG_CANQUEUE))) { pr_err("wild qc_idx=%d\n", qc_idx); - return; + goto out; } + + sdsc = scsi_cmd_priv(scp); + sqp = get_queue(scp); spin_lock_irqsave(&sqp->qc_lock, iflags); - WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE); - sqcp = &sqp->qc_arr[qc_idx]; - scp = sqcp->a_cmnd; - if (unlikely(scp == NULL)) { - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - pr_err("scp is NULL, sqa_idx=%d, qc_idx=%d, hc_idx=%d\n", - sd_dp->sqa_idx, qc_idx, sd_dp->hc_idx); - return; - } + spin_lock_irqsave(&sdsc->lock, flags); + aborted = sd_dp->aborted; + if (unlikely(aborted)) + sd_dp->aborted = false; + ASSIGN_QEUEUED_CMD(scp, NULL); if (unlikely(atomic_read(&retired_max_queue) > 0)) retiring = 1; - sqcp->a_cmnd = NULL; + sqp->qc_arr[qc_idx] = NULL; if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { + spin_unlock_irqrestore(&sdsc->lock, flags); spin_unlock_irqrestore(&sqp->qc_lock, iflags); - pr_err("Unexpected completion\n"); - return; + pr_err("Unexpected completion qc_idx=%d\n", qc_idx); + goto out; } if (unlikely(retiring)) { /* user has reduced max_queue */ @@ -4966,9 +4975,10 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) retval = atomic_read(&retired_max_queue); if (qc_idx >= retval) { + spin_unlock_irqrestore(&sdsc->lock, flags); spin_unlock_irqrestore(&sqp->qc_lock, iflags); pr_err("index %d too large\n", retval); - return; + goto out; } k = find_last_bit(sqp->in_use_bm, retval); if ((k < sdebug_max_queue) || (k == retval)) @@ -4976,14 +4986,19 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) else atomic_set(&retired_max_queue, k + 1); } + + spin_unlock_irqrestore(&sdsc->lock, flags); spin_unlock_irqrestore(&sqp->qc_lock, iflags); - if (unlikely(aborted)) { - if (sdebug_verbose) - pr_info("bypassing scsi_done() due to aborted cmd, kicking-off EH\n"); + + if (aborted) { + pr_info("bypassing scsi_done() due to aborted cmd, kicking-off EH\n"); blk_abort_request(scsi_cmd_to_rq(scp)); - return; + goto out; } + scsi_done(scp); /* callback to mid level */ +out: + sdebug_free_queued_cmd(sqcp); } /* When high resolution timer goes off this function is called. */ @@ -5233,115 +5248,126 @@ static void scsi_debug_slave_destroy(struct scsi_device *sdp) } } -static void stop_qc_helper(struct sdebug_defer *sd_dp, +/* Returns true if we require the queued memory to be freed by the caller. */ +static bool stop_qc_helper(struct sdebug_defer *sd_dp, enum sdeb_defer_type defer_t) { - if (!sd_dp) - return; - if (defer_t == SDEB_DEFER_HRT) - hrtimer_cancel(&sd_dp->hrt); - else if (defer_t == SDEB_DEFER_WQ) - cancel_work_sync(&sd_dp->ew.work); + if (defer_t == SDEB_DEFER_HRT) { + int res = hrtimer_try_to_cancel(&sd_dp->hrt); + + switch (res) { + case 0: /* Not active, it must have already run */ + case -1: /* -1 It's executing the CB */ + return false; + case 1: /* Was active, we've now cancelled */ + default: + return true; + } + } else if (defer_t == SDEB_DEFER_WQ) { + /* Cancel if pending */ + if (cancel_work_sync(&sd_dp->ew.work)) + return true; + /* Was not pending, so it must have run */ + return false; + } else if (defer_t == SDEB_DEFER_POLL) { + return true; + } + + return false; } -/* If @cmnd found deletes its timer or work queue and returns true; else - returns false */ -static bool stop_queued_cmnd(struct scsi_cmnd *cmnd) + +static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd, int *sqa_idx) { - unsigned long iflags; - int j, k, qmax, r_qmax; enum sdeb_defer_type l_defer_t; - struct sdebug_queue *sqp; struct sdebug_queued_cmd *sqcp; struct sdebug_defer *sd_dp; + struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd); - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { + lockdep_assert_held(&sdsc->lock); + + sqcp = TO_QEUEUED_CMD(cmnd); + if (!sqcp) + return false; + sd_dp = &sqcp->sd_dp; + if (sqa_idx) + *sqa_idx = sd_dp->sqa_idx; + l_defer_t = READ_ONCE(sd_dp->defer_t); + ASSIGN_QEUEUED_CMD(cmnd, NULL); + + if (stop_qc_helper(sd_dp, l_defer_t)) + sdebug_free_queued_cmd(sqcp); + + return true; +} + +/* + * Called from scsi_debug_abort() only, which is for timed-out cmd. + */ +static bool scsi_debug_abort_cmnd(struct scsi_cmnd *cmnd) +{ + struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd); + struct sdebug_queue *sqp = get_queue(cmnd); + unsigned long flags, iflags; + int k = -1; + bool res; + + spin_lock_irqsave(&sdsc->lock, flags); + res = scsi_debug_stop_cmnd(cmnd, &k); + spin_unlock_irqrestore(&sdsc->lock, flags); + + if (k >= 0) { spin_lock_irqsave(&sqp->qc_lock, iflags); - qmax = sdebug_max_queue; - r_qmax = atomic_read(&retired_max_queue); - if (r_qmax > qmax) - qmax = r_qmax; - for (k = 0; k < qmax; ++k) { - if (test_bit(k, sqp->in_use_bm)) { - sqcp = &sqp->qc_arr[k]; - if (cmnd != sqcp->a_cmnd) - continue; - /* found */ - sqcp->a_cmnd = NULL; - sd_dp = sqcp->sd_dp; - if (sd_dp) { - l_defer_t = READ_ONCE(sd_dp->defer_t); - WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE); - } else - l_defer_t = SDEB_DEFER_NONE; - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - stop_qc_helper(sd_dp, l_defer_t); - clear_bit(k, sqp->in_use_bm); - return true; - } - } + clear_bit(k, sqp->in_use_bm); + sqp->qc_arr[k] = NULL; spin_unlock_irqrestore(&sqp->qc_lock, iflags); } - return false; + + return res; } /* Deletes (stops) timers or work queues of all queued commands */ static void stop_all_queued(void) { - unsigned long iflags; + unsigned long iflags, flags; int j, k; - enum sdeb_defer_type l_defer_t; struct sdebug_queue *sqp; - struct sdebug_queued_cmd *sqcp; - struct sdebug_defer *sd_dp; for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { spin_lock_irqsave(&sqp->qc_lock, iflags); for (k = 0; k < SDEBUG_CANQUEUE; ++k) { if (test_bit(k, sqp->in_use_bm)) { - sqcp = &sqp->qc_arr[k]; - if (sqcp->a_cmnd == NULL) + struct sdebug_queued_cmd *sqcp = sqp->qc_arr[k]; + struct sdebug_scsi_cmd *sdsc; + struct scsi_cmnd *scmd; + + if (!sqcp) continue; - sqcp->a_cmnd = NULL; - sd_dp = sqcp->sd_dp; - if (sd_dp) { - l_defer_t = READ_ONCE(sd_dp->defer_t); - WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE); - } else - l_defer_t = SDEB_DEFER_NONE; - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - stop_qc_helper(sd_dp, l_defer_t); + scmd = sqcp->scmd; + if (!scmd) + continue; + sdsc = scsi_cmd_priv(scmd); + spin_lock_irqsave(&sdsc->lock, flags); + if (TO_QEUEUED_CMD(scmd) != sqcp) { + spin_unlock_irqrestore(&sdsc->lock, flags); + continue; + } + scsi_debug_stop_cmnd(scmd, NULL); + spin_unlock_irqrestore(&sdsc->lock, flags); + sqp->qc_arr[k] = NULL; clear_bit(k, sqp->in_use_bm); - spin_lock_irqsave(&sqp->qc_lock, iflags); } } spin_unlock_irqrestore(&sqp->qc_lock, iflags); } } -/* Free queued command memory on heap */ -static void free_all_queued(void) -{ - int j, k; - struct sdebug_queue *sqp; - struct sdebug_queued_cmd *sqcp; - - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { - for (k = 0; k < SDEBUG_CANQUEUE; ++k) { - sqcp = &sqp->qc_arr[k]; - kfree(sqcp->sd_dp); - sqcp->sd_dp = NULL; - } - } -} - static int scsi_debug_abort(struct scsi_cmnd *SCpnt) { - bool ok; + bool ok = scsi_debug_abort_cmnd(SCpnt); ++num_aborts; - ok = stop_queued_cmnd(SCpnt); if (SDEBUG_OPT_ALL_NOISE & sdebug_opts) sdev_printk(KERN_INFO, SCpnt->device, "%s: command%s found\n", __func__, @@ -5543,6 +5569,33 @@ static bool inject_on_this_cmd(void) #define INCLUSIVE_TIMING_MAX_NS 1000000 /* 1 millisecond */ + +void sdebug_free_queued_cmd(struct sdebug_queued_cmd *sqcp) +{ + if (sqcp) + kmem_cache_free(queued_cmd_cache, sqcp); +} + +struct sdebug_queued_cmd *sdebug_alloc_queued_cmd(struct scsi_cmnd *scmd) +{ + struct sdebug_queued_cmd *sqcp = kmem_cache_zalloc(queued_cmd_cache, GFP_ATOMIC); + struct sdebug_defer *sd_dp; + + if (!sqcp) + return NULL; + + sd_dp = &sqcp->sd_dp; + + hrtimer_init(&sd_dp->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); + sd_dp->hrt.function = sdebug_q_cmd_hrt_complete; + INIT_WORK(&sd_dp->ew.work, sdebug_q_cmd_wq_complete); + + sqcp->scmd = scmd; + sd_dp->sqa_idx = -1; + + return sqcp; +} + /* Complete the processing of the thread that queued a SCSI command to this * driver. It either completes the command by calling cmnd_done() or * schedules a hr timer or work queue then returns 0. Returns @@ -5554,15 +5607,16 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, struct sdebug_dev_info *), int delta_jiff, int ndelay) { - bool new_sd_dp; - bool polled = scsi_cmd_to_rq(cmnd)->cmd_flags & REQ_POLLED; - int k; - unsigned long iflags; + struct request *rq = scsi_cmd_to_rq(cmnd); + bool polled = rq->cmd_flags & REQ_POLLED; + struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd); + unsigned long iflags, flags; u64 ns_from_boot = 0; struct sdebug_queue *sqp; struct sdebug_queued_cmd *sqcp; struct scsi_device *sdp; struct sdebug_defer *sd_dp; + int k; if (unlikely(devip == NULL)) { if (scsi_result == 0) @@ -5606,22 +5660,17 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, goto respond_in_thread; } set_bit(k, sqp->in_use_bm); - sqcp = &sqp->qc_arr[k]; - sqcp->a_cmnd = cmnd; - cmnd->host_scribble = (unsigned char *)sqcp; - sd_dp = sqcp->sd_dp; - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - if (!sd_dp) { - sd_dp = kzalloc(sizeof(*sd_dp), GFP_ATOMIC); - if (!sd_dp) { - clear_bit(k, sqp->in_use_bm); - return SCSI_MLQUEUE_HOST_BUSY; - } - new_sd_dp = true; - } else { - new_sd_dp = false; + sqcp = sdebug_alloc_queued_cmd(cmnd); + if (!sqcp) { + clear_bit(k, sqp->in_use_bm); + spin_unlock_irqrestore(&sqp->qc_lock, iflags); + return SCSI_MLQUEUE_HOST_BUSY; } + sd_dp = &sqcp->sd_dp; + sd_dp->sqa_idx = k; + sqp->qc_arr[k] = sqcp; + spin_unlock_irqrestore(&sqp->qc_lock, iflags); /* Set the hostwide tag */ if (sdebug_host_max_queue) @@ -5673,12 +5722,11 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, if (kt <= d) { /* elapsed duration >= kt */ spin_lock_irqsave(&sqp->qc_lock, iflags); - sqcp->a_cmnd = NULL; + sqp->qc_arr[k] = NULL; clear_bit(k, sqp->in_use_bm); spin_unlock_irqrestore(&sqp->qc_lock, iflags); - if (new_sd_dp) - kfree(sd_dp); /* call scsi_done() from this thread */ + sdebug_free_queued_cmd(sqcp); scsi_done(cmnd); return 0; } @@ -5686,33 +5734,28 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, kt -= d; } } + if (sdebug_statistics) + sd_dp->issuing_cpu = raw_smp_processor_id(); if (polled) { + spin_lock_irqsave(&sdsc->lock, flags); sd_dp->cmpl_ts = ktime_add(ns_to_ktime(ns_from_boot), kt); - spin_lock_irqsave(&sqp->qc_lock, iflags); - if (!sd_dp->init_poll) { - sd_dp->init_poll = true; - sqcp->sd_dp = sd_dp; - sd_dp->sqa_idx = sqp - sdebug_q_arr; - sd_dp->qc_idx = k; - } + ASSIGN_QEUEUED_CMD(cmnd, sqcp); WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_POLL); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); + spin_unlock_irqrestore(&sdsc->lock, flags); } else { - if (!sd_dp->init_hrt) { - sd_dp->init_hrt = true; - sqcp->sd_dp = sd_dp; - hrtimer_init(&sd_dp->hrt, CLOCK_MONOTONIC, - HRTIMER_MODE_REL_PINNED); - sd_dp->hrt.function = sdebug_q_cmd_hrt_complete; - sd_dp->sqa_idx = sqp - sdebug_q_arr; - sd_dp->qc_idx = k; - } - WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_HRT); /* schedule the invocation of scsi_done() for a later time */ + spin_lock_irqsave(&sdsc->lock, flags); + ASSIGN_QEUEUED_CMD(cmnd, sqcp); + WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_HRT); hrtimer_start(&sd_dp->hrt, kt, HRTIMER_MODE_REL_PINNED); + /* + * The completion handler will try to grab sqcp->lock, + * so there is no chance that the completion handler + * will call scsi_done() until we release the lock + * here (so ok to keep referencing sdsc). + */ + spin_unlock_irqrestore(&sdsc->lock, flags); } - if (sdebug_statistics) - sd_dp->issuing_cpu = raw_smp_processor_id(); } else { /* jdelay < 0, use work queue */ if (unlikely((sdebug_opts & SDEBUG_OPT_CMD_ABORT) && atomic_read(&sdeb_inject_pending))) { @@ -5722,30 +5765,21 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, blk_mq_unique_tag_to_tag(get_tag(cmnd))); } + if (sdebug_statistics) + sd_dp->issuing_cpu = raw_smp_processor_id(); if (polled) { + spin_lock_irqsave(&sdsc->lock, flags); + ASSIGN_QEUEUED_CMD(cmnd, sqcp); sd_dp->cmpl_ts = ns_to_ktime(ns_from_boot); - spin_lock_irqsave(&sqp->qc_lock, iflags); - if (!sd_dp->init_poll) { - sd_dp->init_poll = true; - sqcp->sd_dp = sd_dp; - sd_dp->sqa_idx = sqp - sdebug_q_arr; - sd_dp->qc_idx = k; - } WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_POLL); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); + spin_unlock_irqrestore(&sdsc->lock, flags); } else { - if (!sd_dp->init_wq) { - sd_dp->init_wq = true; - sqcp->sd_dp = sd_dp; - sd_dp->sqa_idx = sqp - sdebug_q_arr; - sd_dp->qc_idx = k; - INIT_WORK(&sd_dp->ew.work, sdebug_q_cmd_wq_complete); - } + spin_lock_irqsave(&sdsc->lock, flags); + ASSIGN_QEUEUED_CMD(cmnd, sqcp); WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_WQ); schedule_work(&sd_dp->ew.work); + spin_unlock_irqrestore(&sdsc->lock, flags); } - if (sdebug_statistics) - sd_dp->issuing_cpu = raw_smp_processor_id(); } return 0; @@ -7066,6 +7100,10 @@ static int __init scsi_debug_init(void) hosts_to_add = sdebug_add_host; sdebug_add_host = 0; + queued_cmd_cache = KMEM_CACHE(sdebug_queued_cmd, SLAB_HWCACHE_ALIGN); + if (!queued_cmd_cache) + goto driver_unreg; + for (k = 0; k < hosts_to_add; k++) { if (want_store && k == 0) { ret = sdebug_add_host_helper(idx); @@ -7088,6 +7126,8 @@ static int __init scsi_debug_init(void) return 0; +driver_unreg: + driver_unregister(&sdebug_driverfs_driver); bus_unreg: bus_unregister(&pseudo_lld_bus); dev_unreg: @@ -7103,10 +7143,9 @@ static void __exit scsi_debug_exit(void) { int k = sdebug_num_hosts; - stop_all_queued(); for (; k; k--) sdebug_do_remove_host(true); - free_all_queued(); + kmem_cache_destroy(queued_cmd_cache); driver_unregister(&sdebug_driverfs_driver); bus_unregister(&pseudo_lld_bus); root_device_unregister(pseudo_primary); @@ -7493,6 +7532,8 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) goto unlock; for (first = true; first || qc_idx + 1 < sdebug_max_queue; ) { + unsigned long flags; + struct sdebug_scsi_cmd *sdsc; if (first) { first = false; if (!test_bit(qc_idx, sqp->in_use_bm)) @@ -7503,37 +7544,60 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) if (qc_idx >= sdebug_max_queue) break; - sqcp = &sqp->qc_arr[qc_idx]; - sd_dp = sqcp->sd_dp; - if (unlikely(!sd_dp)) - continue; - scp = sqcp->a_cmnd; + sqcp = sqp->qc_arr[qc_idx]; + if (!sqcp) { + pr_err("sqcp is NULL, queue_num=%d, qc_idx=%u from %s\n", + queue_num, qc_idx, __func__); + break; + } + sd_dp = &sqcp->sd_dp; + + scp = sqcp->scmd; if (unlikely(scp == NULL)) { pr_err("scp is NULL, queue_num=%d, qc_idx=%u from %s\n", queue_num, qc_idx, __func__); break; } + sdsc = scsi_cmd_priv(scp); + spin_lock_irqsave(&sdsc->lock, flags); if (READ_ONCE(sd_dp->defer_t) == SDEB_DEFER_POLL) { - if (kt_from_boot < sd_dp->cmpl_ts) + struct sdebug_queued_cmd *_sqcp = TO_QEUEUED_CMD(scp); + + if (_sqcp != sqcp) { + pr_err("inconsistent queued cmd tag=%#x\n", + blk_mq_unique_tag(scsi_cmd_to_rq(scp))); + spin_unlock_irqrestore(&sdsc->lock, flags); continue; + } + + if (kt_from_boot < sd_dp->cmpl_ts) { + spin_unlock_irqrestore(&sdsc->lock, flags); + continue; + } - } else /* ignoring non REQ_POLLED requests */ + } else /* ignoring non REQ_POLLED requests */ { + spin_unlock_irqrestore(&sdsc->lock, flags); continue; + } if (unlikely(atomic_read(&retired_max_queue) > 0)) retiring = true; - sqcp->a_cmnd = NULL; if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { + spin_unlock_irqrestore(&sdsc->lock, flags); pr_err("Unexpected completion sqp %p queue_num=%d qc_idx=%u from %s\n", sqp, queue_num, qc_idx, __func__); + sdebug_free_queued_cmd(sqcp); break; } + sqp->qc_arr[qc_idx] = NULL; if (unlikely(retiring)) { /* user has reduced max_queue */ int k, retval; retval = atomic_read(&retired_max_queue); if (qc_idx >= retval) { pr_err("index %d too large\n", retval); + spin_unlock_irqrestore(&sdsc->lock, flags); + sdebug_free_queued_cmd(sqcp); break; } k = find_last_bit(sqp->in_use_bm, retval); @@ -7542,7 +7606,7 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) else atomic_set(&retired_max_queue, k + 1); } - WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE); + spin_unlock_irqrestore(&sdsc->lock, flags); spin_unlock_irqrestore(&sqp->qc_lock, iflags); if (sdebug_statistics) { @@ -7551,6 +7615,8 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) atomic_inc(&sdebug_miss_cpus); } + sdebug_free_queued_cmd(sqcp); + scsi_done(scp); /* callback to mid level */ num_entries++; spin_lock_irqsave(&sqp->qc_lock, iflags); @@ -7733,6 +7799,16 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost, return schedule_resp(scp, NULL, DID_NO_CONNECT << 16, NULL, 0, 0); } +static int sdebug_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *cmd) +{ + struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmd); + + spin_lock_init(&sdsc->lock); + + return 0; +} + + static struct scsi_host_template sdebug_driver_template = { .show_info = scsi_debug_show_info, .write_info = scsi_debug_write_info, @@ -7760,6 +7836,8 @@ static struct scsi_host_template sdebug_driver_template = { .max_segment_size = -1U, .module = THIS_MODULE, .track_queue_depth = 1, + .cmd_size = sizeof(struct sdebug_scsi_cmd), + .init_cmd_priv = sdebug_init_cmd_priv, }; static int sdebug_driver_probe(struct device *dev) From patchwork Thu Mar 23 09:45:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13185374 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 BE957C761AF for ; Thu, 23 Mar 2023 09:46:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230418AbjCWJqv (ORCPT ); Thu, 23 Mar 2023 05:46:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229836AbjCWJqq (ORCPT ); Thu, 23 Mar 2023 05:46:46 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E37DF24713; Thu, 23 Mar 2023 02:46:44 -0700 (PDT) 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 32N5hsEn010794; Thu, 23 Mar 2023 09:46:41 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=HfTBBoWYHz2kT7EBYRxC4bYLFSZHaaAwDiRoFHfzvVA=; b=z9PRxXvvGfcrQo3vgLB03+hC0FKv5Eu9UyJ0sJpiNqdcHVkWTWyd2idhHEl7zKsDzNqU TYNTqyL2vZdm6/3oiYiGjxcQ3E/6OPPjvrlv835Y452uoEk7ijvy6ATEmMbt1xNZSkNj hHrt1xMB/xdM5xDdn0U3ZsmNVD5ci1YkOXaSe/p3PVhM0+Gtya75U2Pd6PwH4TXChATW r6AS6h+SwsaVX5xq/ZdXZG8NUHsd3xPvOlAauW5uS9GkIgkmrBYwN5fAMDMUlyuN/0gW lG1Qv69+D/02JGIL4j7Z92BXBMfo2gaw4TX1dAKyiKRxXuhb8aPlxFVzSCqm52D6B5hP hw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd433u9hs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:41 +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 32N9cdiD006987; Thu, 23 Mar 2023 09:46:40 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZRrq6WS6CMlTjaMIOdznYOd+uOI4n4zDYq1h6PraYm8FX3PcLPg1nKSxP6rphISYuGxyNvW1zZv1yqzYyrijp355SyiEZGVAV+aditF/+dBkgv6cJtAcOxLDXkJv9F/juhF/e0rere9iGHG5tL/BCeQLAJzT6jCF3FSA5ZgtlLIip9jW+I5kbEsTbKkwUvrnbZbWpCocy0kl5bUFPhLFP8Q/mbDfG1oDl+1sjba+9pLRqvrTLt0g1QHZl/y69m+RgRH/M6SlehckJcwSkbpviU2BWREHMt1WLlfg0A9qkcWdobnLQBaCESmyFXwP8h5tQfF59OoeWKBTxDceNMg3eQ== 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=HfTBBoWYHz2kT7EBYRxC4bYLFSZHaaAwDiRoFHfzvVA=; b=U22ZCp3bGEShTElhlbYkkd53sFSyNyvve7scw1UV5NBiFvWlfe6/CzukHVEilwX6vcNBfJMKTv0cAQY9JPkcM8WFUp9UsutA86o+LugsSvZo22UdMWHTaYVTxgtFn2kCRa6BK3iXfW5NN68y/mnMdt5w9Oq4TUKOrQxkTnCFrVM0M/BUt91ALxt7+I0Vo8GF+/K5VwUNmltA7QKx/FJa64IA4Bf1qXZZJ8DQn7Q/7ATlTNdleicc/R38mAc7UXmPVHKjPknK+A3vzIRt0rGK8OzV9iC22G8cs/BlKdMVtj4XM5PEmQrjcfisZ+w+n8zppOIi9DbPLHO+F/QuAFsR/Q== 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=HfTBBoWYHz2kT7EBYRxC4bYLFSZHaaAwDiRoFHfzvVA=; b=tkfEc7bon+Mzdk55mM11N7v9fdnHCPd4/1u9QcwGrm9Tpuhma9sIVuETbLmcCzzR6ebNu/N1wRjzW7miFYmbNUs7Lhb21xMNRHmUtGODPS+8YIv7YYkXzQ+MCon+xsVhc+4z79NvoJhQ+qSC1+jX1GuFTRb0NeaOo8BTW9KYDlE= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:35 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:35 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 07/11] scsi: scsi_debug: Use blk_mq_tagset_busy_iter() in sdebug_blk_mq_poll() Date: Thu, 23 Mar 2023 09:45:51 +0000 Message-Id: <20230323094555.584624-8-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO4P123CA0690.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:37b::7) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: 2d2168c3-95f4-4d98-0647-08db2b837cf0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: n2ohzUpCMqrC95/aX/WnHewORNguAk4rPPrKPxXwopU8retitbXGE3BnVkTgNVYZP0xCNmjJ4sqhVdDYoUMp9ZE4pWDkLke9upv+EjFs0xWLQfb19Xvy6XVD87qU7a+EVIrmwHfYj4t+CdgIMuauwkf57UmaAwDN4VdL/9+sBwi0lFVNizMkd8LojxtmJ0JZ058eLgJOyI7tffwTMZIftlxBIyIKLI01bkS/bM176Torf597UvgVWsRG+G+3QImTsC2EHaKJYIxcPJv2aeg/qIZNXWwgsgBuGXYKJSJwegCdUFfPGgv80yJivZaqFBWklUY6lQp9DlqJ26VORb2+zUa8PX3OVavu6v6N6Qs82RWEajoaRDDQa2Zka72V3So5SCnombg4v7eMI/jmrCE1Y3kyd2E9VAECyp7encpXcrsAPR66+Zm4MIhvXC4e9sgiAIirZb1PdZIWpFTMaO/PNm4lLLtIQPc1WYD3oiN+hcMaNKKHqn5PON9BrzOLYsjSAP363dCqlAQTVPMSbV1AUa/qw5yZCbFf13/UwgYOE6Evmfiw2rnu1GhZi34TePKQHZyrYvOwJdENKcbbfXgHXRoIdPzZt0pqDG/YNYqFBnv2G5kRrb2xSU0YVE5hYEPTO0Y6D0fPOOSw9KOOWT03PQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(6486002)(316002)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(107886003)(66946007)(1076003)(6512007)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5smE3f/AXF5eXU8ySbeW3nKHvi8f7Qa0KdpJ0aYPtKrHo3SQJcqC3R2wtxZYjHjd8LDdw+9K2k4mMF2FMl/Ps+G2aTjPY/p6Kkw3aedX6edTie8ClRzNXF0G2kzjII75IJNQSPjk+9wkvfPahlk6MMZbFvahr9C7GjIrP/hDLMKVFd2cff5x1tGYPq4rWa5JuiwdtGrry7lDHblwVtNq50DmRudziQ73lq9P7upPYupjyxd6V5vAINNdLpydeeE4z6YoEZI4aZp+DuAs7jMvUG8Ooa9PphBSpyiZzGrAb8VPoKA+McTwCI7fXcL+c7saUdE+2vIY7fijySrd5wReY9eKEM7OAZ2swarWXgh9oL3yUaUDbRA8ehK9BkqRRJrwx2xNEnr4oJ6hi5b83f0BXffupI8I7bGTUPiWZ0htDx3lDY5uY/WFpUUXQpUUViQKuuHCA2ROX02CC+1hoxd5EEmr0OPRSYTAoqtI2YrHvlj0PoZxusZRQEw/scWd9C6/p0ufK2lVfob47ozQoiLOaQFW2aSk+SeiawsI3NSVLnoZClWF54kXXEdIR1Shk7DA0iIfWmEM9B/hiCZDH/yfxANc2EHH7pQQq0vFdmkLFkTqVnWoXZo35mmYC+ae4/mkPEKktX3BTR0p3FCRgwv64abgqyscEzu5/FvjlxEW+KqVXibJHz1RqWBrInWDGZRd1bq3huTq1SUzXwnrhc/swvs/v9Qoul0pmAXqCECk51e1C8XsT0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zzGEu0SGx29lRk71TWwpPqVFyQ6xXH6JQ3qcrvSF0f2orBMXjdLNipvpQOr2lIaY1uSXpkLLuuCrbk2e21ynFeL2CsLraKt5IRzBYquZOG8SJ9WzOfsY5xGPI1H9fCCzpDmpbK+SYshXDWTpnvLxLdx+FdYZjKMo7lyBB58nO66ZCksryPGWBMiFemeWwz4hiF4PivLEdD7Icahbb3WUhevorfKTMMhs1M4Kjm6uNaYlz/wC7TeU96IYFRmWA4tzy4ClzlRlqSEwBtLDc66GuOiZB5Kb6+0WTyBkYRFh5D9gFFuyh8RZz+DsL/RYiTMANY8zz0arYbXemeqD1sw+7iqQ5F1xJno1CVtFo9GfIUV2ehRyRbKSLQaY3TzPpMt/J4wm7OZC4s2zAfKQ5ObQNI/M8l7FEY5jESBBfmanvSlJ23g1z2MTuKmslVGHfEYReH/5tCr89kqcXXakuJGKqvt91xw6N/BhaNOTM/1T986+PFOpGgITLLC3i06dDlgganl/TCIMwAaulkxdrHTdIHEdbGXcG6jv8/+p3Q4auc5tJ8Rzj8tNPtDY+rhGjv2hH3ScegPyh35J2+w3B6lOFs9Ue/G2pMUm9pANgvu76QhR2DTzR/US2ip/KcUQ3HWX3oEM0+Ke4oK4Flrq1Zc64vv4gV/0R97i6p+1pV2xNBFDHTjOZRCGYsFx+WU9mGnxUs1DpwUvVtsMULJSnz1A9VDLnH2XoiGOUKVQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d2168c3-95f4-4d98-0647-08db2b837cf0 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:34.1903 (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: m6XoToCmXfgFwwUHjBPXMWPa3xVNMeOUmBNANZn4bjM0PmpWHaTwhhP50Ir+SpxlBMNfwJFIHJrNX963tflFAg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-ORIG-GUID: mHb5BfZf9n-aOzpt8GguSYVVuyslwyca X-Proofpoint-GUID: mHb5BfZf9n-aOzpt8GguSYVVuyslwyca Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Instead of iterating all deferred commands in the submission queue structures, use blk_mq_tagset_busy_iter(), which is a standard API for this. Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 195 +++++++++++++++++++------------------- 1 file changed, 98 insertions(+), 97 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 6606e71cd0a9..627bc98c18ae 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -7510,123 +7510,124 @@ static void sdebug_map_queues(struct Scsi_Host *shost) } } -static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) +struct sdebug_blk_mq_poll_data { + unsigned int queue_num; + int *num_entries; +}; + +/* + * We don't handle aborted commands here, but it does not seem possible to have + * aborted polled commands from schedule_resp() + */ +static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) { - bool first; - bool retiring = false; - int num_entries = 0; - unsigned int qc_idx = 0; - unsigned long iflags; - ktime_t kt_from_boot = ktime_get_boottime(); - struct sdebug_queue *sqp; - struct sdebug_queued_cmd *sqcp; - struct scsi_cmnd *scp; + struct sdebug_blk_mq_poll_data *data = opaque; + struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); + struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmd); struct sdebug_defer *sd_dp; + u32 unique_tag = blk_mq_unique_tag(rq); + u16 hwq = blk_mq_unique_tag_to_hwq(unique_tag); + struct sdebug_queued_cmd *sqcp; + struct sdebug_queue *sqp; + unsigned long flags; + int queue_num = data->queue_num; + bool retiring = false; + int qc_idx; + ktime_t time; - sqp = sdebug_q_arr + queue_num; + /* We're only interested in one queue for this iteration */ + if (hwq != queue_num) + return true; - spin_lock_irqsave(&sqp->qc_lock, iflags); + /* Subsequent checks would fail if this failed, but check anyway */ + if (!test_bit(SCMD_STATE_INFLIGHT, &cmd->state)) + return true; - qc_idx = find_first_bit(sqp->in_use_bm, sdebug_max_queue); - if (qc_idx >= sdebug_max_queue) - goto unlock; + time = ktime_get_boottime(); - for (first = true; first || qc_idx + 1 < sdebug_max_queue; ) { - unsigned long flags; - struct sdebug_scsi_cmd *sdsc; - if (first) { - first = false; - if (!test_bit(qc_idx, sqp->in_use_bm)) - continue; - } else { - qc_idx = find_next_bit(sqp->in_use_bm, sdebug_max_queue, qc_idx + 1); - } - if (qc_idx >= sdebug_max_queue) - break; + spin_lock_irqsave(&sdsc->lock, flags); + sqcp = TO_QEUEUED_CMD(cmd); + if (!sqcp) { + spin_unlock_irqrestore(&sdsc->lock, flags); + return true; + } - sqcp = sqp->qc_arr[qc_idx]; - if (!sqcp) { - pr_err("sqcp is NULL, queue_num=%d, qc_idx=%u from %s\n", - queue_num, qc_idx, __func__); - break; - } - sd_dp = &sqcp->sd_dp; + sqp = sdebug_q_arr + queue_num; + sd_dp = &sqcp->sd_dp; - scp = sqcp->scmd; - if (unlikely(scp == NULL)) { - pr_err("scp is NULL, queue_num=%d, qc_idx=%u from %s\n", - queue_num, qc_idx, __func__); - break; - } - sdsc = scsi_cmd_priv(scp); - spin_lock_irqsave(&sdsc->lock, flags); - if (READ_ONCE(sd_dp->defer_t) == SDEB_DEFER_POLL) { - struct sdebug_queued_cmd *_sqcp = TO_QEUEUED_CMD(scp); - - if (_sqcp != sqcp) { - pr_err("inconsistent queued cmd tag=%#x\n", - blk_mq_unique_tag(scsi_cmd_to_rq(scp))); - spin_unlock_irqrestore(&sdsc->lock, flags); - continue; - } + if (READ_ONCE(sd_dp->defer_t) != SDEB_DEFER_POLL) { + spin_unlock_irqrestore(&sdsc->lock, flags); + return true; + } - if (kt_from_boot < sd_dp->cmpl_ts) { - spin_unlock_irqrestore(&sdsc->lock, flags); - continue; - } + if (time < sd_dp->cmpl_ts) { + spin_unlock_irqrestore(&sdsc->lock, flags); + return true; + } - } else /* ignoring non REQ_POLLED requests */ { - spin_unlock_irqrestore(&sdsc->lock, flags); - continue; - } - if (unlikely(atomic_read(&retired_max_queue) > 0)) - retiring = true; + if (unlikely(atomic_read(&retired_max_queue) > 0)) + retiring = true; - if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { + qc_idx = sd_dp->sqa_idx; + sqp->qc_arr[qc_idx] = NULL; + if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { + spin_unlock_irqrestore(&sdsc->lock, flags); + pr_err("Unexpected completion sqp %p queue_num=%d qc_idx=%u\n", + sqp, queue_num, qc_idx); + sdebug_free_queued_cmd(sqcp); + return true; + } + + if (unlikely(retiring)) { /* user has reduced max_queue */ + int k, retval = atomic_read(&retired_max_queue); + + if (qc_idx >= retval) { + pr_err("index %d too large\n", retval); spin_unlock_irqrestore(&sdsc->lock, flags); - pr_err("Unexpected completion sqp %p queue_num=%d qc_idx=%u from %s\n", - sqp, queue_num, qc_idx, __func__); sdebug_free_queued_cmd(sqcp); - break; - } - sqp->qc_arr[qc_idx] = NULL; - if (unlikely(retiring)) { /* user has reduced max_queue */ - int k, retval; - - retval = atomic_read(&retired_max_queue); - if (qc_idx >= retval) { - pr_err("index %d too large\n", retval); - spin_unlock_irqrestore(&sdsc->lock, flags); - sdebug_free_queued_cmd(sqcp); - break; - } - k = find_last_bit(sqp->in_use_bm, retval); - if ((k < sdebug_max_queue) || (k == retval)) - atomic_set(&retired_max_queue, 0); - else - atomic_set(&retired_max_queue, k + 1); + return true; } - spin_unlock_irqrestore(&sdsc->lock, flags); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - if (sdebug_statistics) { - atomic_inc(&sdebug_completions); - if (raw_smp_processor_id() != sd_dp->issuing_cpu) - atomic_inc(&sdebug_miss_cpus); - } + k = find_last_bit(sqp->in_use_bm, retval); + if ((k < sdebug_max_queue) || (k == retval)) + atomic_set(&retired_max_queue, 0); + else + atomic_set(&retired_max_queue, k + 1); + } - sdebug_free_queued_cmd(sqcp); + ASSIGN_QEUEUED_CMD(cmd, NULL); + spin_unlock_irqrestore(&sdsc->lock, flags); - scsi_done(scp); /* callback to mid level */ - num_entries++; - spin_lock_irqsave(&sqp->qc_lock, iflags); - if (find_first_bit(sqp->in_use_bm, sdebug_max_queue) >= sdebug_max_queue) - break; + if (sdebug_statistics) { + atomic_inc(&sdebug_completions); + if (raw_smp_processor_id() != sd_dp->issuing_cpu) + atomic_inc(&sdebug_miss_cpus); } -unlock: - spin_unlock_irqrestore(&sqp->qc_lock, iflags); + sdebug_free_queued_cmd(sqcp); + scsi_done(cmd); /* callback to mid level */ + (*data->num_entries)++; + return true; +} + +static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) +{ + int num_entries = 0; + unsigned long iflags; + struct sdebug_queue *sqp; + struct sdebug_blk_mq_poll_data data = { + .queue_num = queue_num, + .num_entries = &num_entries, + }; + sqp = sdebug_q_arr + queue_num; + + spin_lock_irqsave(&sqp->qc_lock, iflags); + + blk_mq_tagset_busy_iter(&shost->tag_set, sdebug_blk_mq_poll_iter, + &data); + + spin_unlock_irqrestore(&sqp->qc_lock, iflags); if (num_entries > 0) atomic_add(num_entries, &sdeb_mq_poll_count); return num_entries; From patchwork Thu Mar 23 09:45:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13185377 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 A8045C6FD1C for ; Thu, 23 Mar 2023 09:46:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230499AbjCWJq4 (ORCPT ); Thu, 23 Mar 2023 05:46:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229990AbjCWJqq (ORCPT ); Thu, 23 Mar 2023 05:46:46 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39B142472C; Thu, 23 Mar 2023 02:46:46 -0700 (PDT) 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 32N5hvKp010849; Thu, 23 Mar 2023 09:46:42 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=ugvdMQOQLiTnuCTeYWIm73lmLo4cygfDQ9cF0NAB9Sk=; b=KzBWyWKavel+5JNTmkkahULrlgp/mK0yuwPtfYpPJYRbpScsMnFz2tyn0c94tPI3MRlJ 3eLpKmsbkFViEb7o1HkyINkJhwCZn2+txGUa/S2n0BdLnUqb6Kie953toPMlaa/F7nck JSteXiDz7JrIjuEDVA5zIM/Vd+pBxTv9gxQEenbE/ApEyPFGIcPUaiZ5pVAukA+GLPlZ MrOeUojVaxkGmWGZsSk1EOSVaN8liSAU9g3Nu8PzcAEzoOyL59UtGHY089suWYwXClUX loz1u4KRl1xMk1zEjDPV6flVSWM8qSQw1boslIEjFbFRCrYoUyE6nDSYmyMk2I4lJ42k 1g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd433u9ht-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:42 +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 32N9cdiG006987; Thu, 23 Mar 2023 09:46:41 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-8 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V5yVcB0xwbTcsuVK7nhXPq1e7iJOArWGuUmYqOysYEE2RxdLNDAGoz6CYn+KEIqhrlLmpi/tSrEBsk632vsuiOQY3Hcvb6T+yFX9NWpkoxeOzQUpYPNBASk3DtUQ+sLyE9VKZDQj9bHdL/FkVj2H2ixLzkABPQzt6JdXBxCokgopV9NuN5OrVBjZMGDPKYvCHnCrmV+kJkLnYJoFRe+Pumcp94yuL7vrzsJ80PLIM2Gr5akOYytP06b68E7H8A552hluxcuj+TuUAh9yz7L803Ni+JV9Lq6+OMw4S/x+DRtVSw3Ovfv0c98UomrHD7Tte8u5m2bCAZJ0zNuZRy0ZHQ== 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=ugvdMQOQLiTnuCTeYWIm73lmLo4cygfDQ9cF0NAB9Sk=; b=FU9Q38aIbNx8otxTpCQRXQ2HTjk+1FzTof0wKHIGz8bXJG2tlYIh2xfkYlOOl0dYWu31DJl1aIKcDGxmIgcWSICbmR+HaOx1DUtGAQTBe0bd80W2YIWAg5VwzIT7yd5pqGakIK9X6aQQyFgF9BxuLEcbQIzormNMKHIDygqOfMzIvALBR+OOl8CrWzCht+M8PS3a5sPl7YE7m2Rkzkgcgp/VUx2DXBLxL9ucIiqus8LQ0eUPrkgTOFZEkBVRrhSUg7CGoiJ2tnEWUnDgER0scDtUx8CU0deusMpIELGBGcj5vsiLafn0mjEK4FZLqZnrlny9EuikZwagHd6gHc8diQ== 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=ugvdMQOQLiTnuCTeYWIm73lmLo4cygfDQ9cF0NAB9Sk=; b=PkF1tSek4PuE1A7XlTYzJN8TWHdUoqLjGHU0734bBp6Sd8ogGeXHjN5rbZYhvhpOiLAxikB022Qiy0SbkNa5awdgBxaL7FGSKtj6IXwHC1M3c8P7X+HZ304Z/ep5zQKbKW1g3iumL5N0QlGMxOmyWuG8pxO4A45JNSR3ll2BEww= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:36 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:36 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 08/11] scsi: scsi_debug: Use blk_mq_tagset_busy_iter() in stop_all_queued() Date: Thu, 23 Mar 2023 09:45:52 +0000 Message-Id: <20230323094555.584624-9-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: DM6PR06CA0012.namprd06.prod.outlook.com (2603:10b6:5:120::25) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: 18544636-0b46-4338-1e40-08db2b837e26 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mxSkf8gVT87ZhdEoE1Xzod4ggwlftgN075EppOBnhcOTgk5yFDQKIo7ZyplV5zkNsAT0EO3W8rcECMTNWOTG5ftBjzoQnxBdwWGK1KrghaIgREmZDpEiRw2C9avH5DffWrYV503YT7dMUMusbfynS5/Fva2HHMYpVez+YKMaKvIRIGRQL8D8TI/jBF5ithvBxNp1n2ySlevP/sdBl2lLhSWYpH/LiHOGHrRfvQ2opKI2v2ZmzSY7CJCDUDAGmfKgweIzcY7WmMEEbi0lAQk87At4X488NCYUeJO5nhd5Kcb6UbURk6KJaHy5QuiIHuTkFMAJGkIi3oAk8DTeegACDlF8G6tNhnQgk3etCwW7OESewDZydtFWqjDnH57BJQDjDq5j436ibcdAmDLbWmHiVe26xOdAOhX5MTKr+BciJiuQlBHTEUlh22ntUmzYoavjojNfkv8VmUOYU1DwAe9TI9u44IDjkCLeZfK1BnFK9WCjC+y3P3/t9PlXLYMh+sR5PpQ9oKojStZ0xjzfn86xLpiuR9mvNAQXUpgzawHxPZ+krW5fosyTH+5tsakTHivfp+om3yRJYib3jH6WzTrOcHnfz6K9OaVzuFmvlHmwql6CgUEfVwlBhdIPxLlSbA/YDpXBVS1IuqhE5zuTxV0rBQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(6486002)(316002)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(107886003)(66946007)(1076003)(6512007)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: c6rTrpOCNUu/7Ojdl/D+2kWk0SId6EmU8QStv781p56JuhrXo9+PUAkOhGvmWE6MA57VFekQp0f7EdDu6hbXZdLsGwSAyiKnW0kSlqBrSr0dNrgXhokqy06kcszO8gnVBsccj+/r0dEzKvcHyzskulT6UDhMtCuzAblwL8+dctj/n7L06RSY5OlOxIIh/0pSTs+1oQ0SgQJOYT8V8qXjgwssdbg13AVO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TKi4Rf5jk5DbYqVTpbOCwQ2CPbJTdqAEfwaLujSkJSXt1v8Ux7qGMBSOIq9pI6hPE9P81eqCHXdun+TTzsVno/HUSwGMAwVhKc97q0i4ECTgrbBQP9NLB7DQF5OeVIcsspG6G7AI5ZoheeypxVMXEs09SyW8Lzi1B5RvYnlWmzqS/cF5Kn8AHKc2lfokgU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 18544636-0b46-4338-1e40-08db2b837e26 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:36.1288 (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: P8oq5wko6nUjGsWD/ppKmIyMtpP1566hu45ysR/B7ILGIYDp6VT7y5C49cV8kSrSJ0GAZkcsPmwYIxFol91GEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-ORIG-GUID: weJh2WUcXe0kzmckx5UR0YjuHPw4yFvQ X-Proofpoint-GUID: weJh2WUcXe0kzmckx5UR0YjuHPw4yFvQ Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Instead of iterating all deferred commands in the submission queue structures, use blk_mq_tagset_busy_iter(), which is a standard API for this. Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 45 +++++++++++++++------------------------ 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 627bc98c18ae..3e2e7f24d90d 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -5326,40 +5326,29 @@ static bool scsi_debug_abort_cmnd(struct scsi_cmnd *cmnd) return res; } +/* + * All we can do is set the cmnd as internally aborted and wait for it to + * finish. We cannot call scsi_done() as normal completion path may do that. + */ +static bool sdebug_stop_cmnd(struct request *rq, void *data) +{ + scsi_debug_abort_cmnd(blk_mq_rq_to_pdu(rq)); + + return true; +} + /* Deletes (stops) timers or work queues of all queued commands */ static void stop_all_queued(void) { - unsigned long iflags, flags; - int j, k; - struct sdebug_queue *sqp; + struct sdebug_host_info *sdhp; - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { - spin_lock_irqsave(&sqp->qc_lock, iflags); - for (k = 0; k < SDEBUG_CANQUEUE; ++k) { - if (test_bit(k, sqp->in_use_bm)) { - struct sdebug_queued_cmd *sqcp = sqp->qc_arr[k]; - struct sdebug_scsi_cmd *sdsc; - struct scsi_cmnd *scmd; + mutex_lock(&sdebug_host_list_mutex); + list_for_each_entry(sdhp, &sdebug_host_list, host_list) { + struct Scsi_Host *shost = sdhp->shost; - if (!sqcp) - continue; - scmd = sqcp->scmd; - if (!scmd) - continue; - sdsc = scsi_cmd_priv(scmd); - spin_lock_irqsave(&sdsc->lock, flags); - if (TO_QEUEUED_CMD(scmd) != sqcp) { - spin_unlock_irqrestore(&sdsc->lock, flags); - continue; - } - scsi_debug_stop_cmnd(scmd, NULL); - spin_unlock_irqrestore(&sdsc->lock, flags); - sqp->qc_arr[k] = NULL; - clear_bit(k, sqp->in_use_bm); - } - } - spin_unlock_irqrestore(&sqp->qc_lock, iflags); + blk_mq_tagset_busy_iter(&shost->tag_set, sdebug_stop_cmnd, NULL); } + mutex_unlock(&sdebug_host_list_mutex); } static int scsi_debug_abort(struct scsi_cmnd *SCpnt) From patchwork Thu Mar 23 09:45:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13185375 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 A2DC2C76195 for ; Thu, 23 Mar 2023 09:46:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229738AbjCWJqx (ORCPT ); Thu, 23 Mar 2023 05:46:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbjCWJqq (ORCPT ); Thu, 23 Mar 2023 05:46:46 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81C132471D; Thu, 23 Mar 2023 02:46:45 -0700 (PDT) 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 32N5htvh010804; Thu, 23 Mar 2023 09:46:42 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=vTQfNp5u2wr7k5ga6IP7ndOMPutnmoj1QRDsG24TqO8=; b=QT4ws+MJTbg5KCYvzzFroldlkgOSI+27qfUv5z64YC4+tDt7MOTHUViGxoXHv6rwD25F r0QC2IclYN3GOg6TG521CAtR5D142D0efXcUiQUspp5GCcEyzmBPHbaiY5Eq7xoPsJiR mnr0r2Ejue6Ak5pes1UjjDlL23yMDrmmFGD0Xd5Tsm752/EoPZ25W8ukV6t7Qew0Iklv RvogqpDXd37cBSYYwuYUqBpFgMAI92LGEGVqEtXPMO8WQaJnak6OuGyi0etjRO1LIUZc W46RjMcX29YC+HmRSXEkKbOyauqxVm5CV5HDsZuFC6zKl46VdGRri87NJP6P/NFIWg4e 1w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd433u9hu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:42 +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 32N9cdiH006987; Thu, 23 Mar 2023 09:46:41 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-9 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lzFE4lNtOnfGrWapfvnjIWSV5ypEmIEGFSZJ08FybFaJ4H/IbBETi5dAz4E/z9dthmhVEPQu317+pKh2uriaYIAOy1ujtZiq/bUZWu314jlc/Sr9dGQEqK09Vo15CMzzvw166lU8XqbcGIGI/WCSgqKtfTRBTtxZgyhYaqMqBAnU4iTK0jxN83r7uZSPHVho+az/c1CIzR/Kt4YeorYYznL1E175gbBS7DZU8jETJWXajvvuw49zJCBvMwmzGoj8iXOIjztPpCMLFDU23xfz14YrFmTPhh+ovoSNHU6C00ZuhG5xvUj9vSuZ3447g9VeAKvoMfOCsJjek9H83vRudg== 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=vTQfNp5u2wr7k5ga6IP7ndOMPutnmoj1QRDsG24TqO8=; b=Bb46B/uLqPgxXNutFnlQB7s7scT+u1288WUxR6gHPXFx/ayZ6HMPQr9hKgzTp8O+TW3nzEOsUtA0PaGcwvrZ9eWxN05GXEbCNVk5MgEAd8VyfAPJpQaXK1ZvAagQ4K7zMeZ/kdxL0S4UsxZ3g73TVVxUB3SawFJovbrUObCe81lyNzQxJ/kB5CrhDxmF5u/gA/eu5hiLRxEU5MemckzMZmiiXnry//aSDN24lL02iIhURnZcZc86fYwyJ0UIG99J6ZYodlCDzihV6k8eTlPX130tLNC3OfrG1XdiEWBUH8NdD60rdrATVDpCfNij2mZI2Fx3SufD4VaETzkZMBbMCQ== 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=vTQfNp5u2wr7k5ga6IP7ndOMPutnmoj1QRDsG24TqO8=; b=bfK2osoUAxogXo58xZ8dVxdtKAtPFG6kdvbDUc7PsXnPFqolbY91rMkncWxFqN7LUOgfGasEYqCIrxC4xyM5z2txFumaWwRQEhdCRJv3HRmW3/btyDPMEfebhmOG4gvlGkiUzqQRShJyXe4OXAgOOfwTpwDSscZMStguRRmJ0jk= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:37 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:37 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 09/11] scsi: scsi_debug: Use scsi_host_busy() in delay_store() and ndelay_store() Date: Thu, 23 Mar 2023 09:45:53 +0000 Message-Id: <20230323094555.584624-10-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: DM6PR07CA0091.namprd07.prod.outlook.com (2603:10b6:5:337::24) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: 51d043da-d7a1-476e-29e6-08db2b837eec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hrMAQ1uO4q0KQN7G3DpvMWC+vkWh8OYwMdw1jLRfbAMHBBIo3NHRPxDg6y5mO449d4UMNyki1/nTUSvswtEWgcN1Q6FXZ9agO6plIaNrRObSQQXNd0qc9wVdNaagyOVlk8FKWbh2ZYJ5H5tlBXWeHO7+0vU+ilvm2UW5ucyd3cTK5DHDVVrkn6LxazAf7xoDyz7tOgJC+jwd8kEdSmLz2YCmRCL5gtfHAc9rnvzl+4v0LjTdIWQykJrBFy7h8O08QFu09EjS45THp/CuNCq1b2V8v48IGxCSvnN/ZhJ1gKZjNl3xG1mnBVmOy33D2b4tutxjJ8+SbBHTNCur6AdwVuXZ5N+DgTicYGEhKR1XkXH5E95LfiodrDxmtjD2S0ud3MQE02WuXnI4PrnX2SH4Y3Q5Vccpr4RKKY0c8fAomdDwosfmdSvLKrcBQSMeDvyl+CgDk1rIKKIi/BfSirFpQ08mTI+qgXSb3T03akhAmxqhyjI73WVE4yXLD5p6+ybyHidTZ4PLJ9YqmwZqRLWgjHNlfgzIv9XhzFqnbM2wOpIQzrevpIMVMUN1Ps2h8/F9YF54xvu07nav8Cd4rXyDdDVQKwmtolzjpN4pGCA/g2I+CdQvWJgOotnT+Ke3vGln0n54JRw1Z6/DjMzjj8Cnaw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(6486002)(316002)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(107886003)(66946007)(1076003)(6512007)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HHJ4HRfHe+MmCvWUnCct7iYPPvMB/Rmv/xmZOuzaONgteZQFIdUYLjFtMD/0kJWWRub6kFqJFob1T0QJnNInrUauBYKWFvuANQ6KZXZMijin7hVy6OQ3r3ePw5m9g/5DEcppEZXPr4z7Whoz1c6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oIcbvgvUy6AzyzSi3wh9LuurmQ8sbXxgJ0lS7DW+M+YvEVHkZiV9JIL9LY8pJXFTSZBVkLweF4ZyLfPzTjh9V5LmK06J9TFHjojGflAt8lAFM0Qi8pkRHMMAcKyvzKnnDsV5m3kBzITKC4OaqEjxoYP/tWZfICh6/ymub6h9OoShr/XP4UlpyfUOAoGaBOzr05vo6aeIsYWVrWR4A31SOWPYPsL+gQqQ6mYI+WJ8kkW6lX713DzAwk8+gCBbpbcfrjkjD4RNm1EUaLSZlQhO9wQXvpOvdEU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51d043da-d7a1-476e-29e6-08db2b837eec X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:37.4267 (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: fYVvLTWqt2zbgMD/HA6xzd5tVgYIKrXDgkh43s8nUzISHNBg4WeIwoieufY9jvf9zUFwNAxIhVJlwpC/24Y6iw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-ORIG-GUID: 9VCWR6naogU_ZNWC7KJYdI5J_Klcvydx X-Proofpoint-GUID: 9VCWR6naogU_ZNWC7KJYdI5J_Klcvydx Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The functions to update ndelay and delay value first check whether we have any in-flight IO for any host. It does this by checking if any tag is used in the global submit queues. We can achieve the same by setting the host as blocked and then ensuring that we have no in-flight commands with scsi_host_busy(). Note that scsi_host_busy() checks SCMD_STATE_INFLIGHT flag, which is only set per command after we ensure that the host is not blocked, i.e. we see more commands active after the check for scsi_host_busy() returns 0. Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 3e2e7f24d90d..8a0fe403e225 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -6061,16 +6061,15 @@ static ssize_t delay_store(struct device_driver *ddp, const char *buf, if (count > 0 && sscanf(buf, "%d", &jdelay) == 1) { res = count; if (sdebug_jdelay != jdelay) { - int j, k; - struct sdebug_queue *sqp; + struct sdebug_host_info *sdhp; mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; - ++j, ++sqp) { - k = find_first_bit(sqp->in_use_bm, - sdebug_max_queue); - if (k != sdebug_max_queue) { + + list_for_each_entry(sdhp, &sdebug_host_list, host_list) { + struct Scsi_Host *shost = sdhp->shost; + + if (scsi_host_busy(shost)) { res = -EBUSY; /* queued commands */ break; } @@ -6103,20 +6102,20 @@ static ssize_t ndelay_store(struct device_driver *ddp, const char *buf, (ndelay >= 0) && (ndelay < (1000 * 1000 * 1000))) { res = count; if (sdebug_ndelay != ndelay) { - int j, k; - struct sdebug_queue *sqp; + struct sdebug_host_info *sdhp; mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; - ++j, ++sqp) { - k = find_first_bit(sqp->in_use_bm, - sdebug_max_queue); - if (k != sdebug_max_queue) { + + list_for_each_entry(sdhp, &sdebug_host_list, host_list) { + struct Scsi_Host *shost = sdhp->shost; + + if (scsi_host_busy(shost)) { res = -EBUSY; /* queued commands */ break; } } + if (res > 0) { sdebug_ndelay = ndelay; sdebug_jdelay = ndelay ? JDELAY_OVERRIDDEN From patchwork Thu Mar 23 09:45:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13185379 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 42C50C76195 for ; Thu, 23 Mar 2023 09:47:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231142AbjCWJq7 (ORCPT ); Thu, 23 Mar 2023 05:46:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230293AbjCWJqs (ORCPT ); Thu, 23 Mar 2023 05:46:48 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC24E244B6; Thu, 23 Mar 2023 02:46:46 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32N5hoNS019252; Thu, 23 Mar 2023 09:46:43 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=NpF0Loc3vV5MFrD6YCOAk1qLEJTwm3Krk6N0TLS++Pk=; b=XGwYqJlYTm0zFpPXJ2NKpnM6a15Q45WH+KTjRDk+aUBQSj0IL/Mwt4sFcOGlycxesXFC liJFxwZ2BO1dGnZs3N3QW2L07Tink6jXLIo1MhJFmXchSedIi84GhFtYZu8LFQM19tEy UVLv+2cgWCi+gC//YfeD3ZVAIiGzRN6EFjNrfRQvUS35yjlS2AY0orK/iU+nBcczH3kx cO/6d+06Uqsg1be8Qk/Mq7HjKIj0CaUI1RiyXlrVa9rMn9n7Og6ju9y3qcGaPy1SyhGZ bw6tKQaAV4+sr2SGC4WnHgj7RWfxbeLUWcGeLrMaC9Y37sLRiS1ZjHdf82YvqAa2bRqZ tw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd5bckbq2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:42 +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 32N9cdiI006987; Thu, 23 Mar 2023 09:46:42 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-10 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WLlfhYUbL0+6Uxs/LQfXo7XXL+oaXa+b3uwLu+YKvbtA8Ff3HMsZujO+Vi9+FlDMsH84rhhFr4TJN9VfOwj9SPRc1055RZNc1ib2DwXyWlDxaQSt/7fHSh9qv2JxGFRkVUNnZforIJ29OpgDOVImgGNU+lFNVk0WLyPoHIlqM7u6ugPEDrlXrGMI+hIqbodewp0AZ6ZY5dJ6UhLxOjWRjNqRcXsdEjhmM+iMgChXGzqvxqoOgFDjfes2aKUCiDvO4FvLhPUwGgyYvF8r4Q3wlKf6nQp4wn3A6laRzLF9a0d9LX+R9CLtvhsVw/em4Khh4w+iCy09Bz4eK+5cAVu4cA== 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=NpF0Loc3vV5MFrD6YCOAk1qLEJTwm3Krk6N0TLS++Pk=; b=FcV/hBTFHn6IcsDanDfw/eqtoAgfxTA6Eq/R3gF/sr/LqmUE64iwg7rqlvwcerBgjYjxlFZ9q2C51xeP9oliQaXj3oG+IK6kWSBHHGqRE6pdzPc5kC+xBLyywd5PFt3ydEiEL8shn/1+vmp1ADPmZQTgL6GAfsXCQq4kpVjne4eiTwKN798jwsr/9TbirSonqgpYq/uonI+5j/f98IlfdZfuLPeFNZohNsfyFnSncfmacrZvPYs28OTRYK7h8qUmf9ApSVS7F3aNvCPYqBtmo4nKLcOZ79kVp+o3YlZHaOfPFvlnr4qapXfWVfcGvop7PQd8d3kH9VGt6xb9hFrLNw== 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=NpF0Loc3vV5MFrD6YCOAk1qLEJTwm3Krk6N0TLS++Pk=; b=YyxkTi7Q1LJB362OjRXY1cp7tm81Vd3RNZmXTbORSk+fo79xlJUtWShEdOL59DvCIXuf0gB377wWVMDfFqcRXqOQQeilYU8ihtNWBdGgE4gx7BSw2mtBm3GMKbfFVru2pvdu4Odw6SOGV4wpsOf9SYOfxf24v5QC/oMFU974dLI= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:38 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:38 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 10/11] scsi: scsi_debug: Only allow sdebug_max_queue be modified when no shosts Date: Thu, 23 Mar 2023 09:45:54 +0000 Message-Id: <20230323094555.584624-11-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: DM6PR07CA0092.namprd07.prod.outlook.com (2603:10b6:5:337::25) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: 75638bb6-d6b0-48f9-987e-08db2b837fc2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f1XMPHPUnC9ShyKIGme/QEPRPm1nMYy4oAEtrouKGs+Zc1Lycm+2IEeYLz2fxs1kApn9SmqPxRJYU3zDOsLnT0BILD12Wn65+mvCcz/XWCH9Aao6gg+VRby9E6GuCUyh3NS8UChK+L6tqnTx138bLv8CNtG+IqCwLEgq1n6T/udiLreAo3HmbohpTH79iuiau86JYMwjB41e/87tiLBZem9xFW6OzC/VQKY1RSmRgV3JLyOX8/DwyGytzs8ThjmoLqiDAJe6WlgDcWmdSmdhsOildctcD5upE56TT7VivO4dQcMAfoSWqM7xmu3PK3fYXiHVdBqLHgxit+faZdQA4v9/kMhqCqkbYLsHYEKpjiS8jnmjIJZo1Mw0o2PMlVl6FhwN/Gut2eYIRqd7TTfODIbx7P2YmflS+guKwZUEgfCihCPSssrgXz4eyW+UwV3J7XhmtFYU4k/wbGiq7E8RdQqZjTwqNc/RJejfrySajTlsQe8ngdBWN+DEdIS5R04rP6wlsPTqFSrbLQ2kTL9H8d/U0B52cIOVzYqi74/ip3Ol2xsroDGqt2/Tofypt+Wts/L4hnO9mocwS/pX/oiYDEAdoerx1hAxlWGQzEPzz/dvyoSUWwrgbF9tSC2Ywh+4hc3tKLb5VHkFp/k3dHquAQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(6486002)(316002)(66899018)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(107886003)(66946007)(1076003)(6512007)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gPaTv7t8RUyaA6UAhd+nbDgLfM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XKMSQCyogTf8lQ3YiO41zOe+Vo8fXOmCG2AeGWdS2/E4E+VvibnvNbsJ3iuWUr6p5XzWHwMdC0vsrNnPD9f/dLk5rEg0Tyz5Brm2uMsbizVR1yfbWBVWs+VQo1DW2XUQbFwi8gzFCg/dj36QE39TMFZN7i2MvL0AJH3VyGpvvlh/jxl0VWHjLUyhRVQGpJl5If+/BbhPbsTIBT2JBzN89uWGVcJQ6bwNXeUE3BSDsFiqe1rBYFLRwqr5X+kt9Kr+lj1wE47wEcYMqxm8ZzDpMwATgJzgJHWN7cUOn1wxH+1z2IOgto3108xlPvVAIBNj3DIRNWtYQJWF8CE7yvvlVoymmm2ZjQsgTCq9keKCCKxK5ILITzJooDv6crvBZTsIL1ZykdBaWKt/to= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75638bb6-d6b0-48f9-987e-08db2b837fc2 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:38.8477 (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: rsBsRl6CeJ4Ib8hEDp8ZmS2avfhdI8UUAxkVOjkZPvTmWHEswbxg4TgXVx3h1MtgVuCHVmxSp7Qa2S0wD1qAsA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-ORIG-GUID: -LOZwH68QyfTnUJsIIhwjM5HVdJrcdkg X-Proofpoint-GUID: -LOZwH68QyfTnUJsIIhwjM5HVdJrcdkg Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The shost->can_queue value is initially used to set per-HW queue context tag depth in the block layer. This ensures that the shost is not sent too many commands which it can deal with. However lowering sdebug_max_queue separately means that we can easily overload the shost, as in the following example: $ cat /sys/bus/pseudo/drivers/scsi_debug/max_queue 192 $ cat /sys/class/scsi_host/host0/can_queue 192 $ echo 100 > /sys/bus/pseudo/drivers/scsi_debug/max_queue $ cat /sys/class/scsi_host/host0/can_queue 192 $ fio --filename=/dev/sda --direct=1 --rw=read --bs=4k --iodepth=256 --runtime=1200 --numjobs=10 --time_based --group_reporting --name=iops-test-job --eta-newline=1 --readonly --ioengine=io_uring --hipri --exitall_on_error iops-test-job: (g=0): rw=read, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring, iodepth=256 ... fio-3.28 Starting 10 processes [ 111.269885] scsi_io_completion_action: 400 callbacks suppressed [ 111.269885] blk_print_req_error: 400 callbacks suppressed [ 111.269889] I/O error, dev sda, sector 440 op 0x0:(READ) flags 0x1200000 phys_seg 1 prio class 2 [ 111.269892] sd 0:0:0:0: [sda] tag#132 FAILED Result: hostbyte=DID_ABORT driverbyte=DRIVER_OK cmd_age=0s [ 111.269897] sd 0:0:0:0: [sda] tag#132 CDB: Read(10) 28 00 00 00 01 68 00 00 08 00 [ 111.277058] I/O error, dev sda, sector 360 op 0x0:(READ) flags 0x1200000 phys_seg 1 prio class 2 [...] Ensure that this cannot happen by allowing sdebug_max_queue be modified only when we have no shosts. As such, any shost->can_queue value will match sdebug_max_queue, and sdebug_max_queue cannot be modified separately. Since retired_max_queue is no longer set, remove support. Continue to apply the restriction that sdebug_host_max_queue cannot be modified when sdebug_host_max_queue is set. Adding support for that would mean extra code, and no one has complained about this restriction previously. A command like the following may be used to remove a shost: echo -1 > /sys/bus/pseudo/drivers/scsi_debug/add_host Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 67 ++++----------------------------------- 1 file changed, 6 insertions(+), 61 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 8a0fe403e225..78bd393cb2a0 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -762,7 +762,6 @@ static int sdebug_max_luns = DEF_MAX_LUNS; static int sdebug_max_queue = SDEBUG_CANQUEUE; /* per submit queue */ static unsigned int sdebug_medium_error_start = OPT_MEDIUM_ERR_ADDR; static int sdebug_medium_error_count = OPT_MEDIUM_ERR_NUM; -static atomic_t retired_max_queue; /* if > 0 then was prior max_queue */ static int sdebug_ndelay = DEF_NDELAY; /* if > 0 then unit is nanoseconds */ static int sdebug_no_lun_0 = DEF_NO_LUN_0; static int sdebug_no_uld; @@ -4928,7 +4927,6 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) { struct sdebug_queued_cmd *sqcp = container_of(sd_dp, struct sdebug_queued_cmd, sd_dp); int qc_idx; - int retiring = 0; unsigned long flags, iflags; struct scsi_cmnd *scp = sqcp->scmd; struct sdebug_scsi_cmd *sdsc; @@ -4959,9 +4957,6 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) sd_dp->aborted = false; ASSIGN_QEUEUED_CMD(scp, NULL); - if (unlikely(atomic_read(&retired_max_queue) > 0)) - retiring = 1; - sqp->qc_arr[qc_idx] = NULL; if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { spin_unlock_irqrestore(&sdsc->lock, flags); @@ -4970,23 +4965,6 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) goto out; } - if (unlikely(retiring)) { /* user has reduced max_queue */ - int k, retval; - - retval = atomic_read(&retired_max_queue); - if (qc_idx >= retval) { - spin_unlock_irqrestore(&sdsc->lock, flags); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - pr_err("index %d too large\n", retval); - goto out; - } - k = find_last_bit(sqp->in_use_bm, retval); - if ((k < sdebug_max_queue) || (k == retval)) - atomic_set(&retired_max_queue, 0); - else - atomic_set(&retired_max_queue, k + 1); - } - spin_unlock_irqrestore(&sdsc->lock, flags); spin_unlock_irqrestore(&sqp->qc_lock, iflags); @@ -6430,29 +6408,18 @@ static ssize_t max_queue_show(struct device_driver *ddp, char *buf) static ssize_t max_queue_store(struct device_driver *ddp, const char *buf, size_t count) { - int j, n, k, a; - struct sdebug_queue *sqp; + int n; if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n > 0) && (n <= SDEBUG_CANQUEUE) && (sdebug_host_max_queue == 0)) { mutex_lock(&sdebug_host_list_mutex); - block_unblock_all_queues(true); - k = 0; - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; - ++j, ++sqp) { - a = find_last_bit(sqp->in_use_bm, SDEBUG_CANQUEUE); - if (a > k) - k = a; - } - sdebug_max_queue = n; - if (k == SDEBUG_CANQUEUE) - atomic_set(&retired_max_queue, 0); - else if (k >= n) - atomic_set(&retired_max_queue, k + 1); + + /* We may only change sdebug_max_queue when we have no shosts */ + if (list_empty(&sdebug_host_list)) + sdebug_max_queue = n; else - atomic_set(&retired_max_queue, 0); - block_unblock_all_queues(false); + count = -EBUSY; mutex_unlock(&sdebug_host_list_mutex); return count; } @@ -6881,7 +6848,6 @@ static int __init scsi_debug_init(void) ramdisk_lck_a[0] = &atomic_rw; ramdisk_lck_a[1] = &atomic_rw2; - atomic_set(&retired_max_queue, 0); if (sdebug_ndelay >= 1000 * 1000 * 1000) { pr_warn("ndelay must be less than 1 second, ignored\n"); @@ -7519,7 +7485,6 @@ static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) struct sdebug_queue *sqp; unsigned long flags; int queue_num = data->queue_num; - bool retiring = false; int qc_idx; ktime_t time; @@ -7553,9 +7518,6 @@ static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) return true; } - if (unlikely(atomic_read(&retired_max_queue) > 0)) - retiring = true; - qc_idx = sd_dp->sqa_idx; sqp->qc_arr[qc_idx] = NULL; if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { @@ -7566,23 +7528,6 @@ static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) return true; } - if (unlikely(retiring)) { /* user has reduced max_queue */ - int k, retval = atomic_read(&retired_max_queue); - - if (qc_idx >= retval) { - pr_err("index %d too large\n", retval); - spin_unlock_irqrestore(&sdsc->lock, flags); - sdebug_free_queued_cmd(sqcp); - return true; - } - - k = find_last_bit(sqp->in_use_bm, retval); - if ((k < sdebug_max_queue) || (k == retval)) - atomic_set(&retired_max_queue, 0); - else - atomic_set(&retired_max_queue, k + 1); - } - ASSIGN_QEUEUED_CMD(cmd, NULL); spin_unlock_irqrestore(&sdsc->lock, flags); From patchwork Thu Mar 23 09:45:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13185380 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 2FA62C7619A for ; Thu, 23 Mar 2023 09:47:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231149AbjCWJrC (ORCPT ); Thu, 23 Mar 2023 05:47:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230380AbjCWJqu (ORCPT ); Thu, 23 Mar 2023 05:46:50 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 668A22471D; Thu, 23 Mar 2023 02:46:48 -0700 (PDT) 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 32N5hsEo010794; Thu, 23 Mar 2023 09:46:43 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=qg5XdTbWZUwpbpRExqpv15ja87BSh65hIv3SoRSNLIs=; b=X7mJZfz/Kq9RIRljTiOC6ICVCXzguOBYC67R0DQ1gQ5hNhrD/eD/EsYK6+My/Iq1n/sH plSES8N8KnUO6rnKjKi11+tv+GodUh6PNIYYclv5wMLhpoQvbIZrkRbnw2UN48ak2me2 V/hmi+dAMFbSJRXD5YS6ot7pqfy6oBFqAnl9pnTlCuXqGLcinJD/LksLBNHLwHvSv5s1 xcEL7Ia9YFlw6ZIKjJMOgS7l90BmfipJvQ3eH5yMLGWf9dCA/qY7OZV8FxI1NFM6Nadj lHSVh782Cbgor4QYuw0YtzwDZE8y5DyaqeUfSGkJfLMFikt37ng4XDkKYubJqs29e2uf wQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd433u9hv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:43 +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 32N9cgpf020657; Thu, 23 Mar 2023 09:46:43 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2104.outbound.protection.outlook.com [104.47.58.104]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3pgman08yh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GkDmTYKokBBds06mrvSXWdzSknvVAHc6XidCd/vLZDCU2m2m1XyKE/wcajarNNWSLROU2cI4Xbfd+dqcF46peWDQVX9SqYtfr2buO1ZQOTYfi7rd1wBlbuha6Oj+NOlR2b3hv0OsH72cmGjzSo7Ugf1UPHTqBjQkjdrQWejB5nLfgcGLfZThIVsfH2QQJuB42G4w2JvMKWI4eMMQV+kW6Hu6I8ETXkDFYhwfZfbhARZbIWBJ8HCltFV3jPDRUv+AsR/fLj5eXq2l109050TXmCb07NpYQwez1pu6XvZvYmvjAXCO8UXLoq8vDzEZASBvsviGP8URhMT9xoBl5A/YhQ== 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=qg5XdTbWZUwpbpRExqpv15ja87BSh65hIv3SoRSNLIs=; b=O/wGuhysT+x1tjUMnETrXKUFpfLMSscquZIexEsDFQAC8jf1eYn2kbHaje5Au2GjOf1UGEh74RIBb8jNfISXk38o1LWhfmhOMPRzhtvDLyTexUmY0bYoLoMbG9XELytFQ8tfg16MKRBoyabEh5FBKgHaI9ba6h4dXHWCp+2jh8M6yEbKDRtn79UNjycbHw0Zq6Se0+4iz+sd8a3wjnArxgpnYNJ6GSbDPZloRykJYvayHwD/Y6UOYxUHBA2LMeSyUnZc5zDyM9YP2q4dWoDSlAJqF52oKzvHjPPqvoaRv94EpxMQYzV2Bffnt9bSN7hoRiog9fP/7PhwNVl9Vpw2AQ== 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=qg5XdTbWZUwpbpRExqpv15ja87BSh65hIv3SoRSNLIs=; b=x3Dl4xXkZZL0mnlR7ZWWQjkJsTIRUlWkd2sXFlxEI4uvCa7OGaR8MQ05cnZwsxmQK6GzsgJZ3cIIp50lpBChk346uhbUejndNNrbb9stF/h9+GhiE8cnK+kqT3UtSVTpAd5LomzAF+QKJAbF3AE5FtrGmmNBw/oEpiZBih02Jfo= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS0PR10MB7319.namprd10.prod.outlook.com (2603:10b6:8:fd::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Thu, 23 Mar 2023 09:46:40 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:40 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 11/11] scsi: scsi_debug: Drop sdebug_queue Date: Thu, 23 Mar 2023 09:45:55 +0000 Message-Id: <20230323094555.584624-12-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: DS7PR06CA0052.namprd06.prod.outlook.com (2603:10b6:8:54::30) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS0PR10MB7319:EE_ X-MS-Office365-Filtering-Correlation-Id: 4bd2672a-8450-4c59-1d5c-08db2b8380bd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zjGzh76tmnXiXeiMtJeD+4pIE8PGiZf8w9CrqXahIHAKrssN5VpAKZcDURflyQPLK5D1ZmHrJ4N5IdvG4gk5EEazm16doiP6bvDBE3rViEu2ajh8zVqMJkWs9eofSSAAZiMyx1HNVlwPifTGtWkBaMzTpokQ87l4RUj74EiQ7k3VtujsiLJrdivJNNeslw4hQwNw5vZJ2H04NnUJlUXb9VMR+5xp4DhLnHgV8Ba3qNaN7KH9PwoyBinfcogKZeQivXjLBQSN41p41pw4WXkT7YRsLhwIIaVFFiWEG+gv1EeD19ia0+2zXmzH/3ED3OJOwoAcLBzbCTLt3htjgPUfIzFQU8WDmpez6APWoqGqhZwRNDVqQ7bIy3nhgbu9JGaZlufbWQrHLpCJTK8pm6ZpCvHrhkLp5M152m1iRZzfr2+KsfnzDNMn4o42nVvFDo44EPUsgXv/vVnr30qCuFLjGTOZRqtHAJRIUNhnxsP2e7cxwBlTHpyRo0LuuxaO81pfXJyfMsxtdNmlzzN98B25REx2xA6/pCsF1v/YbTIMutGEeVEIR0hygdyVvUgFc8SKJ/qv4aH7DuoeO9kqm7bB2+dcFWjeJmskhfpObXvhJ3HWtR+vdlujdKPjd5PcziL8v/94rwEaPsRoCRVy8N+NVn8RwFHqC5LUvKGvnwxruq9Kx/c5rScH/Bbb+2kuAN/r X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(136003)(346002)(376002)(396003)(366004)(39860400002)(451199018)(478600001)(2616005)(83380400001)(2906002)(41300700001)(86362001)(38100700002)(4326008)(66476007)(8676002)(66556008)(8936002)(36756003)(66946007)(186003)(6512007)(5660300002)(6666004)(26005)(30864003)(1076003)(6506007)(316002)(103116003)(6486002)(107886003)(21314003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: l8dCfoKwc2iiVCom6TDKmt+OULz3Daviy1ENIm50o0MJH0OwHwJoD2u3/9rqrvFI1vxgFVgQ12MG7YVf64ETEALU5LXWgwynYOoRiH4DWe2kLMvC8o2wey7cedBvyF3rM2uzGKZPPknJRAEHmy26AXYsxzsjuG+vHEGffaDOfs+34LBzwTbehdIZWrTlcSsX9LmYVy0MmWHN6TiKTCIf38mMo7gO7mnlMokGpSxT3fqowxg7mKUxn01esKH+B/ItuHr9NVLR/XMNCpahYogYwmDKJoj1BmJ30Zvg1q4C0UFyTcUUlfqQgSXG5608Moy5P0KilrFZdYn02qC/SYGWUU1DBTGOa4o5G7V6zs+oy0kMxN0fr1NXYtyki6ZeV4GsJY0BJvXG+QPLBMfckj+vCOmXpj1PMvy3wwnLLiJpFg/nwH7iy/Tb7edbXuy1VyAA5cUYQargUCvP7K/dHcR8Nl/1lY89nWWZwjHTn05ki+5HN1yGiq4bCYgfXdr1wgLYWAri/BY/PXlnjjP5KnWivi0ysufa1iLsMQZgUh68WbtgK0fXhR87wTDW7sw0ehFcIbdlUeh+nQHOo/RVc7mFAMhIcIJsxHii4Il/64D+6qAq6jkgsJg4lvZyhTmoJsAUGoI1GMRa1c8Dv2jHzQOoKF4mnx3PRk0uH4YSvjlghbGA77MNM2VKyBJ+Cm/xKt8GjsFS2D1/uBghnnf/dg8SHtY4uu4C2aNffDHbCGhO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8J8lnmUtytGCjwmmVS2+yDDR8uBXULipYWyjplx01GqDpxoN8YtaLKCJLaDkje/GpdNqXLGCDXLG/RA+yUNhgoRAtr49hfQUHhF5K4VwtrBKl0atS/2FexffVTqGlu0qA9TsirpFIw79oqKLCC9QsvY7Kani+YJHDGn98KVkgEVZl/C3TNylOd2MOGdJf+O6MPWoT6STwW+VMTMgV7yiEdVH6ZshNcZEcoYqeFo77EljLorHfeS1Lb8LcCX6E3lgjQpxb+oYovRCYNZy6KnMSyDpisJtCHp4ghhkBSf/Rtx+OZKIfn8Sk3S94vJJgHb8j+C04TwVh0XLIifex1+JsFtHQs8UzsOpDMiiFXVSL2tr+3alT+bHANPJkfnwIbaoY+TN51NdMFJ2vqosVraDxgPptHXQfPP3gTJVY2efEYnN0UUT9uxW9KfTYuw8Wji7TTV3Zpuukdj9XOrpltdf4FCetrVhtMTn9opVZUUzkpFV8QBHmNasTpCryA1VOBk6r/me8UAHdrB5Eg9GN/gZVPIbJqiftvaRJYdOdyQjfshM6/mpGqdGBjhXaR6aUN4+TQTlU6puKzL5Qxbf2pZ8Fh5lW7tlIGKC9bTjZ3Q8ATR60v9GuOlH+kUbCkOlWZCUzUrku8+He+ZJO9MdWdXbvn/EQ9uS5XLa3qhWFF7xWVn80fgALJROqMnDOluQJ0EwRxOx1lKcGkmSa74kPUdB88atjwY54b+x9aKY2j2INNyHD8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4bd2672a-8450-4c59-1d5c-08db2b8380bd X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:40.4894 (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: aiCZkuoBmttvsg28hVzYuqUckXmwheh95WW7rr+KKSkOfA5YEJ0Br6FhDEe/PGIzU9q3evXuV8z8PQCxZE9tMw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB7319 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 mlxscore=0 adultscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-ORIG-GUID: yJhg1WPjWjStwiMKI5EPnxU5JwrHvf5A X-Proofpoint-GUID: yJhg1WPjWjStwiMKI5EPnxU5JwrHvf5A Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org It's easy to get scsi_debug to error on throughput testing when we have multiple shosts: $ lsscsi [7:0:0:0] disk Linux scsi_debug 0191 [0:0:0:0] disk Linux scsi_debug 0191 $ fio --filename=/dev/sda --filename=/dev/sdb --direct=1 --rw=read --bs=4k --iodepth=256 --runtime=60 --numjobs=40 --time_based --name=jpg --eta-newline=1 --readonly --ioengine=io_uring --hipri --exitall_on_error jpg: (g=0): rw=read, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring, iodepth=256 ... fio-3.28 Starting 40 processes [ 27.521809] hrtimer: interrupt took 33067 ns [ 27.904660] sd 7:0:0:0: [sdb] tag#171 FAILED Result: hostbyte=DID_ABORT driverbyte=DRIVER_OK cmd_age=0s [ 27.904660] sd 0:0:0:0: [sda] tag#58 FAILED Result: hostbyte=DID_ABORT driverbyte=DRIVER_OK cmd_age=0s fio: io_u error [ 27.904667] sd 0:0:0:0: [sda] tag#58 CDB: Read(10) 28 00 00 00 27 00 00 01 18 00 on file /dev/sda[ 27.904670] sd 0:0:0:0: [sda] tag#62 FAILED Result: hostbyte=DID_ABORT driverbyte=DRIVER_OK cmd_age=0s The issue is related to how the driver manages submit queues and tags. A single array of submit queues - sdebug_q_arr - with its own set of tags is shared among all shosts. As such, for occasions when we have more than one shost it is possible to overload the submit queues and run out of tags. The struct sdebug_queue is to manage tags and hold the associated queued command entry pointer (for that tag). Since the tagset iters are now used for functions like sdebug_blk_mq_poll(), there is no need to manage these queues. Indeed, blk-mq already provides what we need for managing tags and queues. Drop sdebug_queue and all its usage in the driver. Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 189 ++++++++++---------------------------- 1 file changed, 51 insertions(+), 138 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 78bd393cb2a0..e3e63425e415 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -341,8 +341,6 @@ struct sdebug_defer { struct hrtimer hrt; struct execute_work ew; ktime_t cmpl_ts;/* time since boot to complete this cmd */ - int sqa_idx; /* index of sdebug_queue array */ - int hc_idx; /* hostwide tag index */ int issuing_cpu; bool aborted; /* true when blk_abort_request() already called */ enum sdeb_defer_type defer_t; @@ -360,12 +358,6 @@ struct sdebug_scsi_cmd { spinlock_t lock; }; -struct sdebug_queue { - struct sdebug_queued_cmd *qc_arr[SDEBUG_CANQUEUE]; - unsigned long in_use_bm[SDEBUG_CANQUEUE_WORDS]; - spinlock_t qc_lock; -}; - static atomic_t sdebug_cmnd_count; /* number of incoming commands */ static atomic_t sdebug_completions; /* count of deferred completions */ static atomic_t sdebug_miss_cpus; /* submission + completion cpus differ */ @@ -848,7 +840,6 @@ static int sdeb_zbc_nr_conv = DEF_ZBC_NR_CONV_ZONES; static int submit_queues = DEF_SUBMIT_QUEUES; /* > 1 for multi-queue (mq) */ static int poll_queues; /* iouring iopoll interface.*/ -static struct sdebug_queue *sdebug_q_arr; /* ptr to array of submit queues */ static DEFINE_RWLOCK(atomic_rw); static DEFINE_RWLOCK(atomic_rw2); @@ -4903,20 +4894,6 @@ static int resp_rwp_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return res; } -static struct sdebug_queue *get_queue(struct scsi_cmnd *cmnd) -{ - u16 hwq; - u32 tag = blk_mq_unique_tag(scsi_cmd_to_rq(cmnd)); - - hwq = blk_mq_unique_tag_to_hwq(tag); - - pr_debug("tag=%#x, hwq=%d\n", tag, hwq); - if (WARN_ON_ONCE(hwq >= submit_queues)) - hwq = 0; - - return sdebug_q_arr + hwq; -} - static u32 get_tag(struct scsi_cmnd *cmnd) { return blk_mq_unique_tag(scsi_cmd_to_rq(cmnd)); @@ -4926,47 +4903,30 @@ static u32 get_tag(struct scsi_cmnd *cmnd) static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) { struct sdebug_queued_cmd *sqcp = container_of(sd_dp, struct sdebug_queued_cmd, sd_dp); - int qc_idx; - unsigned long flags, iflags; + unsigned long flags; struct scsi_cmnd *scp = sqcp->scmd; struct sdebug_scsi_cmd *sdsc; bool aborted; - struct sdebug_queue *sqp; - qc_idx = sd_dp->sqa_idx; if (sdebug_statistics) { atomic_inc(&sdebug_completions); if (raw_smp_processor_id() != sd_dp->issuing_cpu) atomic_inc(&sdebug_miss_cpus); } + if (!scp) { pr_err("scmd=NULL\n"); goto out; } - if (unlikely((qc_idx < 0) || (qc_idx >= SDEBUG_CANQUEUE))) { - pr_err("wild qc_idx=%d\n", qc_idx); - goto out; - } sdsc = scsi_cmd_priv(scp); - sqp = get_queue(scp); - spin_lock_irqsave(&sqp->qc_lock, iflags); spin_lock_irqsave(&sdsc->lock, flags); aborted = sd_dp->aborted; if (unlikely(aborted)) sd_dp->aborted = false; ASSIGN_QEUEUED_CMD(scp, NULL); - sqp->qc_arr[qc_idx] = NULL; - if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { - spin_unlock_irqrestore(&sdsc->lock, flags); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - pr_err("Unexpected completion qc_idx=%d\n", qc_idx); - goto out; - } - spin_unlock_irqrestore(&sdsc->lock, flags); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); if (aborted) { pr_info("bypassing scsi_done() due to aborted cmd, kicking-off EH\n"); @@ -5255,21 +5215,18 @@ static bool stop_qc_helper(struct sdebug_defer *sd_dp, } -static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd, int *sqa_idx) +static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd) { enum sdeb_defer_type l_defer_t; - struct sdebug_queued_cmd *sqcp; struct sdebug_defer *sd_dp; struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd); + struct sdebug_queued_cmd *sqcp = TO_QEUEUED_CMD(cmnd); lockdep_assert_held(&sdsc->lock); - sqcp = TO_QEUEUED_CMD(cmnd); if (!sqcp) return false; sd_dp = &sqcp->sd_dp; - if (sqa_idx) - *sqa_idx = sd_dp->sqa_idx; l_defer_t = READ_ONCE(sd_dp->defer_t); ASSIGN_QEUEUED_CMD(cmnd, NULL); @@ -5285,22 +5242,13 @@ static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd, int *sqa_idx) static bool scsi_debug_abort_cmnd(struct scsi_cmnd *cmnd) { struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd); - struct sdebug_queue *sqp = get_queue(cmnd); - unsigned long flags, iflags; - int k = -1; + unsigned long flags; bool res; spin_lock_irqsave(&sdsc->lock, flags); - res = scsi_debug_stop_cmnd(cmnd, &k); + res = scsi_debug_stop_cmnd(cmnd); spin_unlock_irqrestore(&sdsc->lock, flags); - if (k >= 0) { - spin_lock_irqsave(&sqp->qc_lock, iflags); - clear_bit(k, sqp->in_use_bm); - sqp->qc_arr[k] = NULL; - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - } - return res; } @@ -5558,7 +5506,6 @@ struct sdebug_queued_cmd *sdebug_alloc_queued_cmd(struct scsi_cmnd *scmd) INIT_WORK(&sd_dp->ew.work, sdebug_q_cmd_wq_complete); sqcp->scmd = scmd; - sd_dp->sqa_idx = -1; return sqcp; } @@ -5577,13 +5524,11 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, struct request *rq = scsi_cmd_to_rq(cmnd); bool polled = rq->cmd_flags & REQ_POLLED; struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd); - unsigned long iflags, flags; + unsigned long flags; u64 ns_from_boot = 0; - struct sdebug_queue *sqp; struct sdebug_queued_cmd *sqcp; struct scsi_device *sdp; struct sdebug_defer *sd_dp; - int k; if (unlikely(devip == NULL)) { if (scsi_result == 0) @@ -5595,8 +5540,6 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, if (delta_jiff == 0) goto respond_in_thread; - sqp = get_queue(cmnd); - spin_lock_irqsave(&sqp->qc_lock, iflags); if (unlikely(sdebug_every_nth && (SDEBUG_OPT_RARE_TSF & sdebug_opts) && (scsi_result == 0))) { @@ -5615,33 +5558,12 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, } } - k = find_first_zero_bit(sqp->in_use_bm, sdebug_max_queue); - if (unlikely(k >= sdebug_max_queue)) { - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - if (scsi_result) - goto respond_in_thread; - scsi_result = device_qfull_result; - if (SDEBUG_OPT_Q_NOISE & sdebug_opts) - sdev_printk(KERN_INFO, sdp, "%s: max_queue=%d exceeded: TASK SET FULL\n", - __func__, sdebug_max_queue); - goto respond_in_thread; - } - set_bit(k, sqp->in_use_bm); - sqcp = sdebug_alloc_queued_cmd(cmnd); if (!sqcp) { - clear_bit(k, sqp->in_use_bm); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); + pr_err("%s no alloc\n", __func__); return SCSI_MLQUEUE_HOST_BUSY; } sd_dp = &sqcp->sd_dp; - sd_dp->sqa_idx = k; - sqp->qc_arr[k] = sqcp; - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - - /* Set the hostwide tag */ - if (sdebug_host_max_queue) - sd_dp->hc_idx = get_tag(cmnd); if (polled) ns_from_boot = ktime_get_boottime_ns(); @@ -5688,10 +5610,6 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, u64 d = ktime_get_boottime_ns() - ns_from_boot; if (kt <= d) { /* elapsed duration >= kt */ - spin_lock_irqsave(&sqp->qc_lock, iflags); - sqp->qc_arr[k] = NULL; - clear_bit(k, sqp->in_use_bm); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); /* call scsi_done() from this thread */ sdebug_free_queued_cmd(sqcp); scsi_done(cmnd); @@ -5949,14 +5867,39 @@ static int scsi_debug_write_info(struct Scsi_Host *host, char *buffer, return length; } +struct sdebug_submit_queue_data { + int *first; + int *last; + int queue_num; +}; + +static bool sdebug_submit_queue_iter(struct request *rq, void *opaque) +{ + struct sdebug_submit_queue_data *data = opaque; + u32 unique_tag = blk_mq_unique_tag(rq); + u16 hwq = blk_mq_unique_tag_to_hwq(unique_tag); + u16 tag = blk_mq_unique_tag_to_tag(unique_tag); + int queue_num = data->queue_num; + + if (hwq != queue_num) + return true; + + /* Rely on iter'ing in ascending tag order */ + if (*data->first == -1) + *data->first = *data->last = tag; + else + *data->last = tag; + + return true; +} + /* Output seen with 'cat /proc/scsi/scsi_debug/'. It will be the * same for each scsi_debug host (if more than one). Some of the counters * output are not atomics so might be inaccurate in a busy system. */ static int scsi_debug_show_info(struct seq_file *m, struct Scsi_Host *host) { - int f, j, l; - struct sdebug_queue *sqp; struct sdebug_host_info *sdhp; + int j; seq_printf(m, "scsi_debug adapter driver, version %s [%s]\n", SDEBUG_VERSION, sdebug_version_date); @@ -5984,11 +5927,17 @@ static int scsi_debug_show_info(struct seq_file *m, struct Scsi_Host *host) atomic_read(&sdeb_mq_poll_count)); seq_printf(m, "submit_queues=%d\n", submit_queues); - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { + for (j = 0; j < submit_queues; ++j) { + int f = -1, l = -1; + struct sdebug_submit_queue_data data = { + .queue_num = j, + .first = &f, + .last = &l, + }; seq_printf(m, " queue %d:\n", j); - f = find_first_bit(sqp->in_use_bm, sdebug_max_queue); - if (f != sdebug_max_queue) { - l = find_last_bit(sqp->in_use_bm, sdebug_max_queue); + blk_mq_tagset_busy_iter(&host->tag_set, sdebug_submit_queue_iter, + &data); + if (f >= 0) { seq_printf(m, " in_use_bm BUSY: %s: %d,%d\n", "first,last bits", f, l); } @@ -6943,13 +6892,6 @@ static int __init scsi_debug_init(void) sdebug_max_queue); } - sdebug_q_arr = kcalloc(submit_queues, sizeof(struct sdebug_queue), - GFP_KERNEL); - if (sdebug_q_arr == NULL) - return -ENOMEM; - for (k = 0; k < submit_queues; ++k) - spin_lock_init(&sdebug_q_arr[k].qc_lock); - /* * check for host managed zoned block device specified with * ptype=0x14 or zbc=XXX. @@ -6958,10 +6900,8 @@ static int __init scsi_debug_init(void) sdeb_zbc_model = BLK_ZONED_HM; } else if (sdeb_zbc_model_s && *sdeb_zbc_model_s) { k = sdeb_zbc_model_str(sdeb_zbc_model_s); - if (k < 0) { - ret = k; - goto free_q_arr; - } + if (k < 0) + return k; sdeb_zbc_model = k; switch (sdeb_zbc_model) { case BLK_ZONED_NONE: @@ -6973,8 +6913,7 @@ static int __init scsi_debug_init(void) break; default: pr_err("Invalid ZBC model\n"); - ret = -EINVAL; - goto free_q_arr; + return -EINVAL; } } if (sdeb_zbc_model != BLK_ZONED_NONE) { @@ -7021,17 +6960,14 @@ static int __init scsi_debug_init(void) sdebug_unmap_granularity <= sdebug_unmap_alignment) { pr_err("ERR: unmap_granularity <= unmap_alignment\n"); - ret = -EINVAL; - goto free_q_arr; + return -EINVAL; } } xa_init_flags(per_store_ap, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ); if (want_store) { idx = sdebug_add_store(); - if (idx < 0) { - ret = idx; - goto free_q_arr; - } + if (idx < 0) + return idx; } pseudo_primary = root_device_register("pseudo_0"); @@ -7088,8 +7024,6 @@ static int __init scsi_debug_init(void) root_device_unregister(pseudo_primary); free_vm: sdebug_erase_store(idx, NULL); -free_q_arr: - kfree(sdebug_q_arr); return ret; } @@ -7106,7 +7040,6 @@ static void __exit scsi_debug_exit(void) sdebug_erase_all_stores(false); xa_destroy(per_store_ap); - kfree(sdebug_q_arr); } device_initcall(scsi_debug_init); @@ -7482,10 +7415,8 @@ static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) u32 unique_tag = blk_mq_unique_tag(rq); u16 hwq = blk_mq_unique_tag_to_hwq(unique_tag); struct sdebug_queued_cmd *sqcp; - struct sdebug_queue *sqp; unsigned long flags; int queue_num = data->queue_num; - int qc_idx; ktime_t time; /* We're only interested in one queue for this iteration */ @@ -7505,9 +7436,7 @@ static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) return true; } - sqp = sdebug_q_arr + queue_num; sd_dp = &sqcp->sd_dp; - if (READ_ONCE(sd_dp->defer_t) != SDEB_DEFER_POLL) { spin_unlock_irqrestore(&sdsc->lock, flags); return true; @@ -7518,16 +7447,6 @@ static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) return true; } - qc_idx = sd_dp->sqa_idx; - sqp->qc_arr[qc_idx] = NULL; - if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { - spin_unlock_irqrestore(&sdsc->lock, flags); - pr_err("Unexpected completion sqp %p queue_num=%d qc_idx=%u\n", - sqp, queue_num, qc_idx); - sdebug_free_queued_cmd(sqcp); - return true; - } - ASSIGN_QEUEUED_CMD(cmd, NULL); spin_unlock_irqrestore(&sdsc->lock, flags); @@ -7547,20 +7466,14 @@ static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) { int num_entries = 0; - unsigned long iflags; - struct sdebug_queue *sqp; struct sdebug_blk_mq_poll_data data = { .queue_num = queue_num, .num_entries = &num_entries, }; - sqp = sdebug_q_arr + queue_num; - - spin_lock_irqsave(&sqp->qc_lock, iflags); blk_mq_tagset_busy_iter(&shost->tag_set, sdebug_blk_mq_poll_iter, &data); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); if (num_entries > 0) atomic_add(num_entries, &sdeb_mq_poll_count); return num_entries;