From patchwork Mon Mar 27 07:43:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13188691 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 4A863C77B60 for ; Mon, 27 Mar 2023 07:44:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232661AbjC0HoB (ORCPT ); Mon, 27 Mar 2023 03:44:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232579AbjC0Hny (ORCPT ); Mon, 27 Mar 2023 03:43:54 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1979E3A9A; Mon, 27 Mar 2023 00:43:32 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32R7UWO6011911; Mon, 27 Mar 2023 07:43:23 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=CFbVnRCbp8kb/+4WUvNh36x/qZFuDuie9cKdEUsnwYLTI1uX3AtgILZiFppl8AWEY88Y xtp0uGkbUIaT72/ShHd1Tgb64mwyWC+GvUwkVWnY5Ucl6aviAedqJdZdfYNY2evDfJ58 Wnwen5RHkj2W2PshXPT7ygKYfpHFMCweT75L4J2LtKKolFUOxOEmUuMde2yobwQjJWx2 DRChMb8O7Ncbhg39rpG5OIr3gIUKF9bDmzmrbxhtIvKzvk+hhOgnz9vKgYypOmycN5C8 2BlWgkUkCqvI76L/Rjk3MhxVxaCV6Gwhux+Pkj/1lY3oe/N+jtSNplOz/zRDxZaeFOJg 3w== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pk6t581nv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:23 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32R78xFe032830; Mon, 27 Mar 2023 07:43:21 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2046.outbound.protection.outlook.com [104.47.56.46]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3phqdc4vyt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g3ACjbBxLvkUsL3X3WsvDuPui1yDMeh7kRxsjGuvQK6oMdcDABR4g8cIkd9HSs6ScQuSxxZuJW6Jz9GBHCCCfREIxGsIucxjpCw2RkQXFSEkpOLXQM+ebURGedFCEJ81uz9LzL5DlJYkhrFQMpI6vMEVr+RPw+29yvetaTYxewzH8pYq3olQ0KFyI05FYa1x/o8o/o2d6luVq/QHOwixNKGYe/Z/zrjqZXd7SR+gHs1c9Z2ko4VINk4+VFBO+jXedKheP/tMoBtDrOZRfHQG1W1V1s8SHrDN+iODVThbBa6SzEKyXs00JHVsoOc3A8gqXgTjshbmXOjiEKGp6Mg4BA== 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=U9Ln/7qbMRfah8SueCIAaMuszRNcW4fsezzoEdTQX+K/BQuhRmnJAAXufiO9DewAPWbNH9fXfqKawLEwSKNuZgdKnxfWtHNJMrLvcHID4h4yiz7RdFg636Ex1r1aGCZNAx04rc+q4g6tRuGfBH4M+66+WzYNzrCzRWe7z6Iwqn39nwOfhw6R1+XnU9J9/7FTy7Q3qNhsr3Oo7iKoMTrIlRgqhnezvu9LMU4vWqZuUpBAwHKKM7W2arBgM6+HRh7MAiXLpAMwHZOWtKKkrOs9th4OAHdl6adBVFe8zMC90lawGqwuQEKhVTYaDihlnXYjqnPeAy9n3I3Tr0CZvaayeA== 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=rK4bObvYGPlGshWDRdH3UotV1Vqr8bMDCnJc6YyVRtFdUSxxUh5vIFtAcTKNYNSsBtw0VNDDLc3+QhQpxpAxiNPglC4Mdcaa/t6YxQPuA2soar4SkxX3v+P9l8VgdUDYtl3SB4AK5wY8EfoNvI3uNP4E0SxukpChYEbshXwn/BU= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS0PR10MB6728.namprd10.prod.outlook.com (2603:10b6:8:11c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.41; Mon, 27 Mar 2023 07:43:20 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%4]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 07:43: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 , kernel test robot Subject: [PATCH v3 01/11] scsi: scsi_debug: Fix check for sdev queue full Date: Mon, 27 Mar 2023 07:43:00 +0000 Message-Id: <20230327074310.1862889-2-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230327074310.1862889-1-john.g.garry@oracle.com> References: <20230327074310.1862889-1-john.g.garry@oracle.com> X-ClientProxiedBy: DM6PR07CA0047.namprd07.prod.outlook.com (2603:10b6:5:74::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_|DS0PR10MB6728:EE_ X-MS-Office365-Filtering-Correlation-Id: 761a205e-4817-4f9e-d396-08db2e96ef56 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lNag7CZFjnC+5GdStFkNMjsz6pqbTy8wijP2rUq+SIkKu8LZYwUrovLGA8wI9secXUmYgZO0WpjcNTFB3O+hw513cRRYLjeKqcGtDYASlDaufnp3w5RdO407FvBDDPDbRrRjXBICYuxVF10C0PPQiklT4kZIplClQqnL5y/ruBZSfeDZzEBt71fIeEcb3zbC+oos95JKNqRSv/FRE9PBKSiULchjRIAH5IV2SrkQc74cyDYLXD+2Qv5jkm0ChR+8STCnT9eL2aNe+oV942mtrH42F4udyNhhPXLj6tS/gAQLs9qx7AhBWogneNieKpGTrWv8/akeO/VkHuHugmNQ5cuwKjgLX/lhT9HJoNSkUIbPqA/pa3ICh168tGD8wqCBaJ4FRptP0reg5i39f5jf8kvVy5OdbA8bfJk3Two1FJkpQ72DAAI6sfVpdJ95cXCafV2bAm4emRjLVn79ndfYxJPRJ7OwH7kq1VTey3dnGuSI2uc5NbtwO42EBlJpgHp3azhj7z6B80UJYrvJRfBEpFMdKVs0lGfUukkZTgCXK7k= 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:(13230028)(39860400002)(376002)(346002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(54906003)(316002)(186003)(8676002)(66946007)(66556008)(66476007)(4326008)(41300700001)(103116003)(6512007)(38100700002)(2906002)(1076003)(8936002)(6506007)(5660300002)(83380400001)(26005)(6666004)(2616005)(86362001)(6486002)(966005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Sh+E0RA2CPapXzYD/xGZpLOIDhWS8aRtjEoWY9J1JwzuQLBrbd21fWfYUahyKggq6MYlgCI1EHi+uOY1vAU+EklcNF8TkMiEniZLzGFNNz9hUMmdjgXRhjclcB79AhS1GJja98swtM3R151N+D2/jjaqepXIpoX5ZyiB6ZhwoVe+EPcV4IiwTaMaCQEA7ZRTTGG3837Blz44nNIuISS7wnIrfeXXOVL5HIeXHPE21DjYM2c451CwojD2SwgyoZW0z8og+CXv7oQQmS9l8AABnaWHRT876gdX4vENZqgQOBhNZnhoIrfxxNd881FVq6YFttB9fNBUif9uBUKFLLnKBsui5QWb4MC7TIRJJ+ieS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DW0QfOhLuffwUN6hQIYA9+UEHYr1VQ9bsXDkfRLBiZgSr4G66ryRRMnNzKTdYIVhU/4ph/OmVv19I694qCUs+IOX/JhbRiOsRbffCQ0Cf+R4AmkyttIJ8rbHo+L/N2/u/Cf3h7e+5TJyptyqRV67kXUSd+bdI+YKfsD5AzbIIWB4jflLh87MGM+oFWpM9VZulKjg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: bd540h/zif7lhtAPJzcKv7m6cEWatDE3X19c+zMuBypCd939pDolowdVKbqntag3zT1GuJm6s7qF9KiWdrIbSYVN4JScWaUSViho+dS6V722uD5sVo37eO50mEOVLjYhyzJUv3HHv6eHXIIV/fDTf7RE+K4Wx2SHTdHM0hyPQ/VXmbCLYm7otcBgX+vsf2aTbgklZGV2EpgyRPTUqvozLd8LcVXW/BZuKqBcTGWxV6EDjuVCZAyezBWnfdRpMl5ieyjv1eyJ4hSruPclT+Nq0lw6E8q5wey00ByT1n3qOf21oV3eT6hYauZr+aM25gIg58FLXibe/zIJI49z3v7LkyY0zywiqN0ZePx1A/tKoh1skBNGR3G4plQiNo5qjbGC+X9JxYTINlLs67UtW4Rz58OJYlJUpka7Q2NIvUPEfA83iralUgeg1LljGsAu7QN0A0vJAPI+DWPmZTGQwF82uzIor7HDYK6XeCHQkutRgkUXfDFEO/hYa2u6lyRQaUeyzF3T6i9/qVBB7zMpn4Xti49pRsSZySD3EjcVLXhMljHNW/yxdYnzuIuiaRUxSdcbSQ95oIk3xrn15nl7H021hDvkj91o5RAGVBeEjfiOAtBfKsaX0N+0V/VCD+OFBgLk7lfs+tXOj9o4sDUyUQWEhGw1ywiDfcTKboTkvjKeHS/AX6dw9XDqclbLxaLxhQgJxYbVDfHqPtB1nV1bH9lH8oQx2PusccVmVYokT8LJycXLz1m7Lc++jwNga5UJpEc2JDIoipCMjRDo40+QexW39/KBPEU9CC4iZDa8IzgojejwG8kCMJZyrTD5qBrvKxyeEgvtMETTF/TweupIsvRD/JMqVdNT4HIZj+MCT+DLkAxiRJlRW1W+wn7oKKpUdUO7 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 761a205e-4817-4f9e-d396-08db2e96ef56 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 07:43:19.9099 (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: xZzEUqfjYXvEzeFQXDy+/EdZOQ8Im2JQC+LYljZSAL8nu+qfCqT/QTmbnAsDdgeZEux1iIGqAjfY3J1wFmVc0A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6728 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-24_11,2023-03-24_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 spamscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303270062 X-Proofpoint-GUID: FLhV0qV68jDpUq5e0-xH3ntVw7uu7diR X-Proofpoint-ORIG-GUID: FLhV0qV68jDpUq5e0-xH3ntVw7uu7diR 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 Acked-by: Douglas Gilbert --- 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 Mon Mar 27 07:43:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13188689 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 8EE0DC77B60 for ; Mon, 27 Mar 2023 07:43:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232651AbjC0Hn6 (ORCPT ); Mon, 27 Mar 2023 03:43:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232282AbjC0Hnx (ORCPT ); Mon, 27 Mar 2023 03:43:53 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0980219A3; Mon, 27 Mar 2023 00:43:30 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32R7ZAsL021894; Mon, 27 Mar 2023 07:43:24 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=fPakMDu+aZPNyMgPMLy1YTdSOF2XTTb8eocJQCbBFTUl7CsmDDegIXIC7Z08vh05kTRV UB7iPdN7PLYsiXUu/eDcZ9wkPRdiZfw1a6q0HEMJVdXw7VRpX9tFziDTdCyV77hK7OGj yFdaaehmkEWtJcpYQ3M1Fxji/gNzBaZRfPUyD5cGPnHdg2v/TKBGd1LlB4DlPxvi2RH+ tZ/LMOP7bNDqhGfN4stiEKLFGXcrcj3h5Ukfka9TuJa17InI0gPDdAOSfawGRPCRq40x jV4yvz7uukwNJ/c4ZbjcoWr2tyauwklBXdIrKVAnJHGXXu7ESLi1eKP64jZlNJC+rcJl lg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pk6vmr13t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:24 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32R7g6O9005488; Mon, 27 Mar 2023 07:43:23 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2043.outbound.protection.outlook.com [104.47.56.43]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3phqd4d57f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e9l7kpoKOEGHUhRoQ83K58H+j4ysIfbMZz1whT9V37LFDOuSShnO/Dmo51cdolpFfvFMcAHaLu7Y1q7+a5wxd2KKNYz3ElcUMWStG12p/A+m1MdxWc7QMsKf63aGWiC7Rj4eRtzeDR5GoEuT76Al382st2IK6GTzrmFzOyxDjYK+UxtJf6aZhfnnqIeM0IHAxwNK1QwSoU6CFjIFpYwxAcezzzLdNNwO4uvHAUZOWJhngut9SyXAy/lh3GaXZBpn/sPocSqcV4hZOKzlG44LDA48MZr61WQO0Tin2IQajjCih6Xm3Hpip1GFMgQABZYh8BuQ6I5rUid2+ckGIv9ncw== 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=ctpWafmLzFkwSATS6ac6ISnr+uUvjiV9B0PEHSfMGcY+/m/q9Ti0rNWsx6e8kOF6zv8q5gwal46rOinJlll9nIWqb77UU9JBXbM6BFP9JVCU+WzWN3MtX/aTYGCrB5mcuZYZXsNkttSnvXfi9bJeY2ZA2mGyTDPVFI6di4WGTMvoTh/gwqb9S4c3fsEtgE2hSkA4eClUzNL0jihRSs0Pk50fjb6UncGTMCD43btI4sljBHcYgzRqUJzmC+KhSYvZl3i6J52rhc/s+8JLFwV+CFXlIfTo6SulEO2VgwPHgflnSKkrKLfdDqU+VrD4w1VPPR/doBmQl2lwOyWuNmo3EQ== 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=RJkelobwHN5iI+Z7M6X+uvThMzcm4p95jNsJMErWp3r+mRy9YEUGtb87pTLIjTi1/Dehj9I8I7I+iFiqkAt1UmjSHEz2tHdu71ibzkAGimkl9GziLx9fGi33FBDXYRIsVUXZhX+0+KBVP3SKYz0v+e8Z6ZCVJOTslRNb21kMtMo= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS0PR10MB6728.namprd10.prod.outlook.com (2603:10b6:8:11c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.41; Mon, 27 Mar 2023 07:43:21 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%4]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 07:43:21 +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 v3 02/11] scsi: scsi_debug: Don't iter all shosts in clear_luns_changed_on_target() Date: Mon, 27 Mar 2023 07:43:01 +0000 Message-Id: <20230327074310.1862889-3-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230327074310.1862889-1-john.g.garry@oracle.com> References: <20230327074310.1862889-1-john.g.garry@oracle.com> X-ClientProxiedBy: DM6PR05CA0038.namprd05.prod.outlook.com (2603:10b6:5:335::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_|DS0PR10MB6728:EE_ X-MS-Office365-Filtering-Correlation-Id: f0a69e6e-548d-48d4-b5f7-08db2e96f053 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jIclQ1o/Hasx1PVyU1l6qGMtRgbZPY5pKhtulx+Dv46fl0fEB9pMOsqn7oaJdHy6tQSsJOtQ6y89V83aecAlOLRzrjuFDxsWYnW9daEnLi/Xw0s0tQ1/xpZaQxfhZyEo3iHKG5iHmVHfNny5n+TnnkMKE5c/7ALkP98Sev093wp651yVw6MpjmFeFBuzzGFjapsJKaXMK3XnvwnfDArSK9oGc40Vz7eZ+w7dKhHd2b5PE7mTxUpNMHjh56cn95M4qWne0J/pHEXcYn+An1E/ycv+fwh6GHjH13rqbfjIvpmppoazJTr6/TqEJtgDmxayYu5r0gbQn3EsLMLe06o7hx+ng7l5qn59ogk45+k8cuq29fLcMZwUkSS57H0HMsCIs8A8D/HA4HSQOePLJ/Fl5bdq+Rpf24fAt6VpC6jUrOSpCX446yO3mBlnBcYfAzEPxLNPuQyf0zKLyffQrLHRwbn73G8EiRyXXa5AVYsUTVYLI2KS4pu7NpDtsmV/dXX8E3gzEcyw0RG/WZvTuNvHMQHeg3hyF7vGgrJMEP/Fr9Eb2KPkXeWT2m//wBnR92U8 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:(13230028)(39860400002)(376002)(346002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(316002)(186003)(8676002)(66946007)(66556008)(66476007)(4326008)(41300700001)(103116003)(6512007)(38100700002)(2906002)(1076003)(8936002)(6506007)(5660300002)(83380400001)(26005)(6666004)(107886003)(2616005)(86362001)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3uOgYgX/yO5Mor1BDndTcp4jzCAEUQ8UE5N3E+tjZrFsReAo3/FNRv2EBjYb8MQWDEh9O3J7k0KZ2LdeEm/kFh/sqyLyDxHsOiiHuApLi9cgQh3tg4KPF9LHpWV2Sf/3xAqK14+EGTDa+KIV96zUI1lxHC4/sXHORuuvH3S2PkLeGdL9EsSe1TemcK/YKwtDTgheqfFcJo29L+1vvkZa3w+rCzeRrWEzWYU0UWG1s6zkXBDH9K4lrzgQe5kscjIBfOjAPvyKI23ahT6ZdvQ9kkv//5S8sBuxc6f5qYHeIw0mtIl8fwVa2n0dpCt3r9rfEyd2gUg41yhwRwtJsK9BCtQr8CGQaZ0RElaNmvaqu7iVDykLL7saCZ/WTxG3bwO4i8p83S7rqqGo8UJv6IjbWc77mwXn3Eh+KN9+0vkahnnQsCG37kwVnuCrPqzH/7AqR4CF1yJTfsh8vw6qeftgm7y3VutTRKT3zfBNqfXezIJaB1pDJDTnZiOZ6jfQ4zgfjR2cY47JSO/UugLAow6E+QKRKGrJ70wKEb1kHmyzN9A+cpc35Jx2dR2iYv/mmIZp5dT0hnCHJti6k645H6V7AIVsyeKFG7Y3xHk/uYdOGn4oboYJWrj1aQda3Us8ZOYVH+C1Y4pDjaGPhkkPKwG/wBKw5V1E+6QxlkAgLErFU4AteRCBM1JSNjVV2BqxAQE/S68b3Jtir2XYlhZh7YxHUF7MzskQdHxZPbv5FXFy7q4jTNlQObumuF7LvIBP3CBL2SXkdSsbWVkHkrRPczGL+ovslZ1c1iZDw9dN/Uy1Hmn8zCpVJA41g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v8AEi1rAqWYwig/q/zpTnkIXmvZeTdCRGwA7564j+smEmtxHqUS4TVQfMQfLKWzB/Y8dhP10D7E0EFDYr95vage4+TjmyXdGoix5qB4qougNEJR3va78xy3Fhhc6jdmLl/RtgZ4uDIFpYSLl5SrVXhHBLiIWEOgGEE9bmDbSQyFfgVe/Z4gWZt/f/Iz2aqs4XA+JvSoqZP8i1h3luInoP52yD6UCoBVbTMrgrAvym51fT8gzeU3O246bhS8eA4tu8cu7alDjzBV75HYdxy7uDtKQntDbBuUD1AC66dZdBcGAswJb0MUK10wFuSVvU3GFUQunI5P0vlrLckNOQjS/xjynyo4UfIYMsLjy19NSmOAskpzVbarzjT51CJGbplPiap/z6KRs/ZDU+ZRQ7e3zfK3LVG88JSgpf/0/I34gx6Rc6cU0kWo3k7J/OFLSucxa27U5jHMw6AxdbbwsuuUqYlEqtI9d3G0F82eNZFR6Osb/azExWkaBx5sPPWV8qDQM/42QDKC73AqglQrQMPKZLJXKSEvLqE71+fBy+aHJheTcPjGrD/sCIH5XXcSIBWc5BDd7aWPi7mM9WvF5HsljBCNGxHOPUWnltdi0vt0LGVzGjT9gE58wuZUpjC4Pi6JbTtVw2lqE1ltz2iFKxvKq/IEF5NXV4R7DA/tQqA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f0a69e6e-548d-48d4-b5f7-08db2e96f053 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 07:43:21.5515 (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: DQp1AV6dSIVtEh2gFTj0+P1vzsPyij/m3bysRC3BHXvc1yRzvyETLNhKaXdqrjFMxUgNua/Z3pe6H2/bSrCRaQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6728 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-24_11,2023-03-24_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303270062 X-Proofpoint-ORIG-GUID: E4bcptEgjTaHcCUNOOELuuaEYSoo7d4v X-Proofpoint-GUID: E4bcptEgjTaHcCUNOOELuuaEYSoo7d4v 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 Acked-by: Douglas Gilbert 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 Mon Mar 27 07:43:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13188688 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 D04BEC7619A for ; Mon, 27 Mar 2023 07:43:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232715AbjC0Hn5 (ORCPT ); Mon, 27 Mar 2023 03:43:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231979AbjC0Hnx (ORCPT ); Mon, 27 Mar 2023 03:43:53 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C2C31BF2; Mon, 27 Mar 2023 00:43:30 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32R7Z9eT021879; Mon, 27 Mar 2023 07:43:26 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=v03kwAFn/JEZS4DGsIXLF2axqDwUz/MEVUF0vTQO60lmKm4dOXBfyNPuGNNtypwcxqK1 1/j04H3UwrrrefVgHnP9EjJWOB6WcL3kM6A2cv32uHFFKoZehCJ6B/8Z6J5kjZLOR869 GEdzdEHjRaTxuaJ2WURf3hn/YtjNcn7YiXMV36SuLX1e1vELTClrlaqC0ro2l51ZY7v4 tHYvS69OS4G766yi8gy6No5ie7rGFU2SjPVCGCivptMHw35f+jh6xDwxqkV7Bn9nMxKq qT1vnnUCvlzqRk9vCOk/YcsDtofh78Kn86MN+oRK2LqpoIgW9LUNyYnaQU6e+blWgqi4 rQ== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pk6vmr13x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:25 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32R7CWk8005330; Mon, 27 Mar 2023 07:43:25 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2041.outbound.protection.outlook.com [104.47.56.41]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3phqd4d584-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KcNBhSrZ4EFUrQ9kZjowk9VG8BD1xx5Bc4WAZPlzNdn5zgRViUGkF8367TGt0UrZzvuZABuxARyZSiB7C3J+beo2SVr4uw8MI0k3WzkWerpJRUTwO9rlonWXIRnKXDAdraNknOqR/cTlcjnSrINjMgFYps9g4aABc7S5tGVes9ngjGcK0WIzBAmIFHPqkmOWPmfFTqNm7gnommUcSUUvM32G5tYO+TwIxdWjCL9UVLuTyDEegEeaiGZS2LGrT3z07AmNGyuGrrgxbJmz+TpogBoDUod0lNZDQOu1Hkz9k37CdbvDJqDSJYjWC53jT4lDy2wtltD1tnZEe47KZP+lGw== 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=obUZ0WmlRJBggYBmZnQrsWV2rg2yhysLyRE7bQVc3ABVj8mow4ed0IKm7jAKTNpDLEmB+MS6VZRd9lu5nDXrPszfr/sOGFRsh/oyT8vakMJFAKZWurS8AUw3btc5D8JjeU8FXQg5LL9Y9Peo4QGQts2GNQaPwcOqWZnvxxfG0fCmm71MYgXJZfxk+6JNLfxwjNzECNoqMNXNeWxiQMtidqr6d3E6/ZRNM++9WMtncmUJVbJ3QYwW7wTAvP9ONynj2i/jN6TL8fz3KxDyh6OGIlBEYVUXkdeFwCizHFSkZqhQdrB7yAxWsl/CHQdkoX0IC8sLJIDrech6jcRbcYwIYw== 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=CYhMG+JWrJMh+jmlOLL4gGkxWij1AAYyHnt5/vBsW7QUAI4aB1DbEf1Ikwc+EL9r/+bbwi+6HXLGfUkiXTbVayUUT9x7WWXEfsI3hB38VMSSt9pClAk1moUD+PjFNoHuBhvZYw6fYP/p4A5fsuU38o6pO7ARrHTg7LMylWEKt4E= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS0PR10MB6728.namprd10.prod.outlook.com (2603:10b6:8:11c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.41; Mon, 27 Mar 2023 07:43: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%4]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 07:43: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 v3 03/11] scsi: scsi_debug: Change shost list lock to a mutex Date: Mon, 27 Mar 2023 07:43:02 +0000 Message-Id: <20230327074310.1862889-4-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230327074310.1862889-1-john.g.garry@oracle.com> References: <20230327074310.1862889-1-john.g.garry@oracle.com> X-ClientProxiedBy: DM6PR02CA0087.namprd02.prod.outlook.com (2603:10b6:5:1f4::28) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS0PR10MB6728:EE_ X-MS-Office365-Filtering-Correlation-Id: d866a630-dc76-4b09-ecb5-08db2e96f127 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KZykfMe42X3l2gJM4L4L9IInkKni9eQdZi6qfyCk48Yq6+1nuvMly6i6HrkfHZUIgWd/7wTrrezQ0xnxjLlQVubzel8c1PhnXr+hTuRDs3jJ65YqsUB/pox1I9pLZoUid6wnCXeiX+i1LbcpDNQ1J783EfejbenhCL21LG84bYlwMEpbJywXNdCFP6dNq1sUYg27O3wfWfH3a+bMq/DqVrYZleMqqe4BhyOREdoAibTWUgC/e9HG/uacBEiboZFXiIv0hPRPSo/+CDFI08ec8D9PnGxGua03XN0MJKH6gCHrQ7uVxjzmspYpXtKEyZF8lb4dqH4aRGmOTBhilrdqih2F48ztAhpEuxx3608iKSN6wHog4xLWKMwaCUtX5UZ5LRtph//XrFlsE7vM2B17JFirhNBC0nIDTUCLxtwfQGa51rotiwmyydDUmkp8EGuL3tS8icawbyEEIbIVEj2mF/UvlVkISw7JOV/mk77k2mJ1KcO9k0qxwasIDj0u4yoUxMZy5yrJqr7k8yd1lhj1QCA8d2Nz7EmHGnuzOza3pKn7aaoao6tVKWYsRaa8s8Yg 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:(13230028)(39860400002)(376002)(346002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(316002)(186003)(8676002)(66946007)(66556008)(66476007)(4326008)(41300700001)(103116003)(6512007)(38100700002)(2906002)(1076003)(8936002)(6506007)(5660300002)(83380400001)(26005)(6666004)(107886003)(2616005)(86362001)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Mj0BeX4b1UBcdW+jDiQBH0jVbXtiBH6jV3XsU70pRLV9XWYg/Arj4+c3kGMDnGmbQrbOrXnvWzqwHOFitLumEfNbS3/5lSkt9Xx2soiWAzjnmUzwz6P7oV7Vmvax7pO6vW3rNUpRTkY/OPWrxY+4mUoaZ3P0zAmsM6q9v8yztcFLL0BIQgUkfWVgNPtM5OqNO97S0pMpYY3/sF1jZZnYHfBHb4WsSk10vSKqjGpX+bfB81sjuVzuQLOzg9v/5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1AY1ndpVx73wpuylHOCU0nRO8KfnEazgcKumws8o1w/PI5QfNh+OQjAUChrotI3G/lm9PKie1RBah4mgR7OeIt1jH3P01ZZ5svZPzk1cDA+q7h6I3c9kbJ9F0cXXH1SHQYlVqVhV7dClRF7TdecbBO8qtpa+gNolbqh0GFG/L/ekWs5pQMvRms0RgUMhiywJfAARc2nGR4u19Hl6J+fItVMkmkqI91FBfb8Oz+LThl4KtsLKLRlubovry8DMxaStdt8SsJHdYwKz/0ToKcMdg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: R/GyxkWWOfkAvGl2qhfj+YWC6TR9PskH9N/WTm5kdwNjGcH5NwdE5jkawdidQTzXJN6Y65/q0TDAV7/7qvz4awZ6z6O8BfBpEnVITgorm/LLCxj4Htd+ET2otcpNwxOeSuWutNFzO6x7SpH52cspathndbzhE256/VKyP0eF+TTCCcGnXottMW/zVWIrHUoKdeokTtVdqP6QT+w53J/b82x3IZx2EXzFdqXJFUn1mJfrhHAEoZgViPuGUhpAG4ydfFaA3fa+U0XhXqSGkmkiqM9j85yk9pUw5JtGDHc45lclVYO2XdLo4yhacLtwKv4dYLsJgdubasPYW0OCrr2kFIsPlGBtIBtE9lYsjC5UL96keWlA4waTd7sRYmO5OEiKqWvj0KLZXCDxKkfJo6G0Al0lvIhtB55yMX+6gVrEs4o/4zgZJJb/mA75C7e3gJh12OjsAUSBjpTKjRvHzlbaF9wZMM7gfym45TCHndtvMrSPQuvkCvNFcyLWxo0P+0fREJ4FVwHq4F03Jfb/5zF9S60y2GBhSlJ1fRb0v80SayRXiKQdSOsgRY6D96vFVdHxnxC6Q/MeXUa9l9RlToWtdpAndfbmjAyHLZHlRWWIxJkbNc07IH49CS3VJTB+Ayq1JTfA4tT83sxrlo2ZVWgSDGEVtiPts7CwjShEjwaG/yZH732pCy24KqKfMIUOwLSzJxOlqqGHWyNm96hLCpx2k7aaoX0f+Z5hKRV2WNh/Ex8OEDZ6IF88VhuAPKfQYd25AsiJgO8iSye8d0XKHF8DAuaxhz5PZzpuKEixtESaXoeWObJmCtFdoJT9p0iDNxjIgh6loWxyN33+Y3kAgIR4/7tOoxuYglfWP0uj2oly60w= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d866a630-dc76-4b09-ecb5-08db2e96f127 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 07:43:22.9423 (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: xEluDJzxJ3IktHFiycdc+lYBBoke0B6QfwKpWDbRyaraKRdSEHmRN+BSDBvZyUy0m+ygHTwTFzx/ilUNXfUgXw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6728 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-24_11,2023-03-24_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303270062 X-Proofpoint-ORIG-GUID: Rnz-g2SpsPBbKVlyNjHEynAihCyFNoza X-Proofpoint-GUID: Rnz-g2SpsPBbKVlyNjHEynAihCyFNoza 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 Acked-by: Douglas Gilbert 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 Mon Mar 27 07:43:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13188692 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 6CA4FC761AF for ; Mon, 27 Mar 2023 07:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232769AbjC0HoC (ORCPT ); Mon, 27 Mar 2023 03:44:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232647AbjC0Hny (ORCPT ); Mon, 27 Mar 2023 03:43:54 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 016543C2B; Mon, 27 Mar 2023 00:43:32 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32R7USIt011843; Mon, 27 Mar 2023 07:43:28 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=Dj1AaXeRvOQgILs6XjwbjvqZAA6E7lQQlE55PClqVVtvgni2wGlNAkU4TjkdjQlPCJ7P zfggcIBXIBfKPFwOml/uyC1bZIbn9DwCwNl6kAfuzkKlmYipX3QgYCHvjp0+dIVCgH1j aj8V9/CFrGzuzHDzDonQY43Xl9thXdCCo5u9wVBw5Z4Mu/SuzZ2DzrGcRScWleOAdBBF AJPwr5aN1FPW2BnSTCIpAMhP3aqYikoiX2TQTFFTEoiLSR/k91YOaNlI03Y3rLvkHaxw ZlGGvQdLQlJWH0ua7G5K3zaIn+4+Iw7VR3TDKe7wc2+lcdUMkYNNyGfJmUT55HUWkUGX PA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pk6t581p9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:27 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32R5W5gW032993; Mon, 27 Mar 2023 07:43:26 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2049.outbound.protection.outlook.com [104.47.56.49]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3phqdc4w2q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lV+mSG0yTpqF4fKRr0eINWghALsIaH+I9sVkCwWKG4oPseaGrpaArV6pFvT2dEZ6uWU5J5Pbv6AO0trq6yy5YvsxiObPSNTAh+4Je5abvMI5Txt0U+2IzHDQrlbLbbuzDTdxezWBqMp+qMhoUXyA5WboedXoR1gacbPf2J/eEouiuPBS4PVCV94bbyp0es855M6Avd1m9yMUB4r8psHHVIb+mikaJKJxma7xZ4PMmWgtyyC4MWvPLZMJLl9WquTrEt7Jfi4v1pD5atYnJb30JqQpEFEX8l8edRCGsFqQ/0Vu632dpGwJBWcuPeChJDbraXADnOJhGmPwb2lp02TH8Q== 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=cl+2u42N6wxKEs/8o7RZJVGOYInZek6oOuVirYN/DyDo4xIi2Yc0GtV5XwSMI4wGXOZ/TTT02nsQGIcwDM4sGKmjFfJyhpmR+0oUiGmbfIfGrCUvpF6aHN4PzACx8eyYvAgU0i8XQ0FY0ryk9CotMgUVAejit8cwzvS2TFoRdmE4bpAZVdT48tIiQED2xklegGp2/i/ojBozgAtdIou1kFpVpBr0yv0GRhWqTzieQFEvcy7rQM2Vpc4c/draMZPeSBv10cU2LQzAxRoJXlwdmWs/f1nPhSCJKC4/tHXcsiljAis7mwODB1voA8DhbHQUkohtb7c+iYOlPlkIeltBIA== 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=lu8kz4/4ZZJn6EE5f+fy3CmxqkoyXXrKRa2F7KkFK+FxEOo3xOq8PJOX6Kv5Ek4TIkSL/Zav1jNr+TTAauzIsMOs3QTXPmtWs6bHuqbgY/zYYDxQCdFYbuAOUE80sCtuMKVbtUWddSuHblz5sWtVtcYOlcuo0CoXEsHA8oV3pRA= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS0PR10MB6728.namprd10.prod.outlook.com (2603:10b6:8:11c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.41; Mon, 27 Mar 2023 07:43:24 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%4]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 07:43:24 +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 v3 04/11] scsi: scsi_debug: Protect block_unblock_all_queues() with mutex Date: Mon, 27 Mar 2023 07:43:03 +0000 Message-Id: <20230327074310.1862889-5-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230327074310.1862889-1-john.g.garry@oracle.com> References: <20230327074310.1862889-1-john.g.garry@oracle.com> X-ClientProxiedBy: DM6PR07CA0046.namprd07.prod.outlook.com (2603:10b6:5:74::23) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS0PR10MB6728:EE_ X-MS-Office365-Filtering-Correlation-Id: b5f28132-57f2-4829-ba2b-08db2e96f211 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0zFkg/NLYST9h/X+sRQgLM9TSaysVPsinUv5LRCiEi8/fiqvE1IT3NO+jda2C095DXLO+35KsjU8mHAml8I9ZmVmPNA4fer0tVHN/aLjfigHkKFHS1UaKfOUD/iBoTVLrVwEXNT/0AF0+rw35WyOP8NoBUv7Pje3u8SyrDxPmZTKOhJXcqRd2MCNK91GTaq8N3a5rYWa+iqiuMMA1X2HeHPgwWqFlUx/zpX20Qx1JEg3oMPz0JQylsWMs+OLywm6qeL3uiIU9GVKnYIqphUwCBSwW9Tp2XMz/Tr3OCuNXRg/HG6JtJc/a86O5T6BZD9HdrUHJvDHkS+Bcb5xUUTj9RooAYBornZIf8OeP+8xfEWDK3RPJged6YKlXgXz7tqAiKoNC0PhHvKbyLwx03xMIi+YB1raqAZVzQXJqCgcPL4iS42qXfdKqbSb7/Hc+GcqRCPE5XCpfTPZuP1HgPEdY+Y5OIZChx+TfPGftvLSwOm0X6zJuaORtgkw6BlIfwS3apH8XUmtzouw8PSIAVCC8S3jj0DeU1wG5draMRZal2wunUaes4C9Od/GVBPdZxtP 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:(13230028)(39860400002)(376002)(346002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(316002)(186003)(8676002)(66946007)(66556008)(66476007)(4326008)(41300700001)(103116003)(6512007)(38100700002)(2906002)(1076003)(8936002)(6506007)(5660300002)(83380400001)(26005)(6666004)(107886003)(2616005)(86362001)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-M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PKqTzxxIJ5oKJFaTw7rFk5u+wQ5M9DPRH7riUQRKe2sCRMA6TPiyLKbN1fO+AwmP7gsfa06VlbQGiOBfSiVN+1id5u9WPmMm4pY0CD8JKbo+HglcLXCmXCKpRQY8Ie8ELwUpippGMdIXgiLJYS7a8Kc0fk7BYbIisJqngDYjxnlG4tAeY1tO4ELYSFsh3Q3DW4TYNzKSEhuJvCSMPVj1u3rxjj8uFHx7LRHRvl2zx4ISz+N6PS2CwLcaTJGZZ31i/oS03LxDiFesOFq4s+3G4fjD6SmbIduaMhXVQX/v2IF9XV4Sd7KBo73vUhVC2eNKiXOcTEgXu+ztdvHULM4ChSMbmyFT8FC1shimX6dT9XNO4PRAVz+Ftxju8/R7Md3+Drg3tjvEw5cZAlsj7ElAYSeF6ccFy1FW5uck+DMU3DiI70koxT8dA9fYU6QyvL6bIaVTfdejyZssyYIUQZC1/sFA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b5f28132-57f2-4829-ba2b-08db2e96f211 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 07:43:24.4745 (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: UUoZoDKcyGRET7l2GSsEjFPWZ9rFsNTs/QmSXXBjy3/zQrDK21iK46auZye4pLcVdxv2k5B3a7NFY4NXCuSlZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6728 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-24_11,2023-03-24_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 spamscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303270062 X-Proofpoint-GUID: eVBNTZO0C1y13-X0B8TMUOS_YiMlZ3-0 X-Proofpoint-ORIG-GUID: eVBNTZO0C1y13-X0B8TMUOS_YiMlZ3-0 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 Acked-by: Douglas Gilbert --- 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 Mon Mar 27 07:43:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13188690 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 5E618C76195 for ; Mon, 27 Mar 2023 07:44:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232747AbjC0HoA (ORCPT ); Mon, 27 Mar 2023 03:44:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232594AbjC0Hny (ORCPT ); Mon, 27 Mar 2023 03:43:54 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96DB73AA4; Mon, 27 Mar 2023 00:43:32 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32R7UWOA011911; Mon, 27 Mar 2023 07:43:28 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=Ur0apetNVtPBjDOhbq5Eh3Tck259udJKGLB5p/aO/IGGo0wFfmdWk5wna3lJ4NySaoDl hsNIo8acPxg3FgFNtKeLlWZup2iJPWHMKRXlVt+ggXsKSRlzbvJD/Z1f7l+eo/kXZ1rN 3mQA2EizVGcnuPzP/JR/z5oI/tKyL3Xr4ScUovKPftwEYldzfQ4RHrr8kpET3MwBGyEC 1OGVg7kQ//Vez8G2VC1gQdU7N4eSPgskoNYjlp5K/gkZ4oi/QtELkb12AGP0Yq3qvpRS h/EOiHoxRzNiBQ1rBGgYxnGaqA19jRx8dLcxbE2BUNzhvRRS40MjgYELKyjQqkQGtdsp SA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pk6t581pe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:28 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32R6XPrI005430; Mon, 27 Mar 2023 07:43:27 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2042.outbound.protection.outlook.com [104.47.56.42]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3phqd4d59s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=babxMktU13HMKnbbGrnqYidlqe0USx9HBl5Ut+KHkpe6HU43SC99ERMtFmGqhNgeHPViG35d1WOd768fVrI7lgb9/bM3EcAz7IhSAQRnHIz4XaTfDAwOmTv9eyWvkEMyKp5q1ZlnFP5JnJK+VPVgLcxtPMuZpGdKZq+rB4hnZHigc6yOEFi3yWlzcAo1ZZDL2/wWulIdVa65JnudMecMhbcSu2SaXBr7SRyuQ693ADwrh0E6/aOKk+WCQXeaiFNkMxSlkMETXMw09va5WQ9Zusumekt/oh3lOvpj8ibDrN39O6uIlMDrwC7S1QqYx8Y8vaGVuYRT6t129vGHYC204Q== 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=k0wI/QvhJXXeQ/h5C4/vPWvcxegtNPHz4rxfr8KgUBspjuIl2LlKdsoX9UToSTLN9iQX7Q8vCVYDzUwICJwzSEGuOMjIJvVmDRx+xpyAVNUt/a3uNk7xVUq6gl3qXGUdoP7Pfru99/aOVuMp/99w4TXGf1U2vrPMMqUDzIuK9yHuQTbtyG7gpHhieqaecpGlBPalTlSb/865qVNPmgTwFvX7J7ThUZjoqiSpg81+Jpf/mibHA+3ltqYdK7Y+urQ91IyUAyKekeC0gS66P0oi5Krz0TF+4tFOHq15Lk/OTlSj6W9mgWAeBeHQWsn32J87+aDyZeb+512nA3/3rsBMkA== 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=f9q5GWumHvO/dSbjjIqxq07wuyrvsqUSfWTBrReCS0wytjA2261wWDbTcfKwpJBG3ODl8DK2c2mNDybupsPv1cb3+sFu8YIJUZX4TqIWVu1jevFpzHS5+tDLzphctR8HdFw1P9uEwXFMkgs7C9RuGfnorF8/j81rUBf+HeeoC7s= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS0PR10MB6728.namprd10.prod.outlook.com (2603:10b6:8:11c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.41; Mon, 27 Mar 2023 07:43:26 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%4]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 07:43:26 +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 v3 05/11] scsi: scsi_debug: Use scsi_block_requests() to block queues Date: Mon, 27 Mar 2023 07:43:04 +0000 Message-Id: <20230327074310.1862889-6-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230327074310.1862889-1-john.g.garry@oracle.com> References: <20230327074310.1862889-1-john.g.garry@oracle.com> X-ClientProxiedBy: DM6PR05CA0066.namprd05.prod.outlook.com (2603:10b6:5:335::35) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS0PR10MB6728:EE_ X-MS-Office365-Filtering-Correlation-Id: 38fe7fd7-2546-4b96-91b0-08db2e96f2f6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TE5r4OLaRf3yo5D4HI/G+uUSxsl3AGqVE3vGTFupJjJgkFjW7L61oo7NWGyuD7ynWfDORY+IOE63bLIc3XFY2h9u43Fj6frdcVJ1skSEcgHRF/Nlvyzyssdkig6YSpMx80FolZfZKiSw0Sg6X/VFrUUFTuRBudiZml5oUjr7/273rjmuRJsJbGwhUFlbPQlXEDu6X0LYjzGLN7mIl/d6uSOz5GDrerTpwWCSsm8WzOhQNFvXHn+cF5XYd+0osTrg2M5KaCfTHdGkBEaPSMdwLG0z5pW54SvCC5Pl1nX8vJEndrEy+fddB2XZ+cbhAb6MTsNHhxh3zObNSbhyKublE/Vk08+YDBcuu91CRdkAb08wkfnLV0R3utqzcemH4h+4BJHFjtReD9qgOslQHDKUYyUK+j+kL2qI0ZWAbZe1d7zkiHMbmqc+N5Lm4k9Fi00/uQUhoJ08Ums29+Lpq1NYyyQO9WU/9wWwW5iXDR0iYkH6JGJpo10ksw018N9DMuanqLb+iDxCapDTt6SUVF0Y+5VLg9NTxzXRG4w0ehsgxm5OBy+YtMgNdrz/ENTOfoxn 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:(13230028)(39860400002)(376002)(346002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(316002)(186003)(8676002)(66946007)(66556008)(66476007)(4326008)(41300700001)(103116003)(6512007)(38100700002)(2906002)(1076003)(8936002)(6506007)(5660300002)(83380400001)(26005)(6666004)(107886003)(2616005)(86362001)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YZjNpru6IEcf3ujOmfZ8CFGzQMqKZEotiZ66ZAPwpsHcRxKf+1QWYBBWerlAxj8RVFH4+ER0n5YaRBUS6Qr6OPFt5WP3nSQZddLnhaEAG72BfmbvVhZQLMte6pipDS8CfIJ4oFBD3gn3VCj2+E4US54dQqZfn1XU18FPqda/+HiIoMQhNzH7VaejWiLgfLQ5lGLhFeXiHLflUq0lRrdUZ/t26DLQUxDdtKtuobapk7gt8ZteEJB3ravJada67DNRNsOdG8Z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l6PxZZfQK28PojW/BueUGbqW2owLipeoBB3dKh9MIwSlSLOsd6j8YqzzFhEnIb3MjaaAr3be9KVmwD4M9DZyWkz7qOspddqE/C+4QpJGhBSTuiAZwiYIWirTXBEMEVIappgpk+1zYai39at2qO4dToo0JCJ5+xDJsZPpBEPmnfKJ96FMMHUYhND1swZkH9smKNYlasjvemK10I4SlCdHGyrFZbkF4QaxsWob/0pjLNh1tXNw6typdLDYaUuqKh/1hYW4VJmPS0sSXvh9AdfJDGepQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: fHTae4/cR1PPHuejW4LbdzviS6E8Y2q7fIzD8DC23jabWOyAvWbwn6WyMbWlZ9Uxfdnw4gUdyTD894QMFHhPRF0RiL+q69KJ8JxylVf/J36y+hMr0X3hAilnfXkH8Zbl6mbO69AYbxkAzzkzz2ihePtLF5XH6tyRJhNnfFFknMVFZyYrxDyRRmCo+xuqiFjTYvAHgOnEsnRFBwuYdpj+fAWA216ttWzg7uexlZDqUkclBq5sevT7bkWYAFm1A0g52eNM8WHDcQwhTohujB1J1UnA7jNzipjR1QkLSALTf04fpuZcNbO/XC1cA+CiitwYv/rxx9s8mPYM95i5Nxy0zPjj/1+Giox6Ki86I8PObeEnEoKCSsezIM7TlAqwMpKlBEliUksGHw9AmchmWuW+w0dcMO/m20TZD8iMO1OONU1+8pDtzFOPmlv+3+MsyBOcpTTMadhiO4PbjoZPV4RaOszq0Qn0mxMgamdDm73dEzzcoZH2f0W58EI1lh8sFemAE1EYNQ5Icg9IWFtu/fZukGM70AZPqOqCEqxUr1nQEivH3DFWxbkMFD9AQUmzwd5IhVaF+abmS90sbUh4kAE9D2xzYV7uUg3i+1X6vVG10h7ZMWRpmoH8kcOJ9oPiFC+F/A+Gv+WxMb+7iAu2z1qQZjSRMDywkmcRbo8EmSo2dzZ1cL0mGc8z1DCDe+357RfakP4mhoomZYhDb9i4qYJ6iIqUaKAcJjCKKaIfFkq+zm2kb7XbnP7CvDu2KhsHftZLqNMcaRCa53PwXxUeP8GOiP3y431EQRZ+voI/xUn8R4or9mMHXW8MkQBWn5v9FumM0ke41zMOeKHy3nTKVyiLXo0OAGvRLLyuHzGzbYRtiOM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 38fe7fd7-2546-4b96-91b0-08db2e96f2f6 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 07:43:26.0055 (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: UpFwnu6byat4Cf58DJRYTUaRwqBYFbseEiCUEREAVheO4zz2vjUita8EDlVk2ZYMk5z+t3vWLlUyURPgqJ46oA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6728 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-24_11,2023-03-24_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303270062 X-Proofpoint-GUID: IFUrKRRrDa18tkTFR9iD9_mr-UCrAvDo X-Proofpoint-ORIG-GUID: IFUrKRRrDa18tkTFR9iD9_mr-UCrAvDo 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 Acked-by: Douglas Gilbert --- 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 Mon Mar 27 07:43:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13188696 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 9FEC8C7619A for ; Mon, 27 Mar 2023 07:44:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232807AbjC0HoJ (ORCPT ); Mon, 27 Mar 2023 03:44:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232696AbjC0Hn4 (ORCPT ); Mon, 27 Mar 2023 03:43:56 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00CE4213F; Mon, 27 Mar 2023 00:43:35 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32R7UQdg011809; Mon, 27 Mar 2023 07:43:30 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=S17hF1GsYVXbSkIhmkwRDLjUlWb6GePaYmwY60w7+VM=; b=jDmw0WnnqpQ3l/zTV9aZ8wsPUZDmn23O6xdTIC04h+JDMqmQx1Fpk6xo1kdSwJ7mUPq1 pOycU65HXibVHz1ikDVbgFyu/iAE3apWxUfhAQxycX0DHvvp1TxlPzXDEEeV+khnhbpm C8B8ISI4QfazSXKIb+SOumH6UnYbgBRzQf3ba+5HBqU9iGh/Xn+2rWoB1ggxCXAuzkwC laKqfORRpfgue6nRScS9VXNjhgD3oV3NprzRplYIJM5mC84PbdRfyMMVjw3t9+R3XE1q wmZQUib/bXmJReuAzo8rsRiAwhc08S2d90avf5oFCYdTvIdxebrN0P522T7UqR9dmEAA hQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pk6t581pn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:30 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32R7XUfR020313; Mon, 27 Mar 2023 07:43:29 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2045.outbound.protection.outlook.com [104.47.56.45]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3phqd4mwa6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q+CA5shhmDu/dPOCRfqz6jhv4N4D/P7X6Ejd0hKikG5orR2HpRNcsgRZKUVoKudkmvDs7EQSltIL7fEsk9ZyxAuLP3DBgwLpclYsQHxmk7XD9ceHzSPumevcKa02Sa/C6UIO5zLX58RVGp6CCyerDCLbae+QQXfrZziFWIZOYgxm7GXfwQvutyZI9VH/VubLL5123yjq3kOdcMKG7OX0MLG+Rv0/HRAg1+FEo37SVneT0jphHIiwZhZrrDrRTgnSRCQkHzSPmo1qVTwDFZmcaRR3YPhl35ch3Shkuymy34+EUISdMbx9bZ7asfL2H+N2+/NcjKxPx0dWxbc4j7d2aA== 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=S17hF1GsYVXbSkIhmkwRDLjUlWb6GePaYmwY60w7+VM=; b=PKyBAWowsh3YNrJ861Vs6UKqngd3NTkiUlV0GjPl8AoWmI5loQTu49vza2wv73TbcAEJLbWtMd0GeGjH9xUFE9LCjkjOPMsSHz0p3gS2PzYBhzRL/ogC+YDIcR6T2DEDhloqcHl12/uHP5hXr9jVY7qP1w8BifRy6Ss2uDXRCpL8aWc7dkeBQuLsBQHaihwf3a+kLVE4HN0YOnXntwxw2nLLX/Ua5AaNHxPg04/gmzYAb1b1js77XOSQaruFdhk5RjmU685SO/SdRnmOmTimi+Pxm/MA+9G4sbZJkuEH8238ctPXtgeDlR2umWmszK4XG7dqSMrtc4n3WFV3Va4V5g== 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=S17hF1GsYVXbSkIhmkwRDLjUlWb6GePaYmwY60w7+VM=; b=XsYo+Tc9YMU+dYjeDf3MAnn2fulFlVWTkhj/RXdPluszrYiYj1kf+RItNBwDdOC8L8aKkNQtMMF+NeW7pTTcEvX4BFvjjgCdzViczTxhjZm4PfvOKlKocwrre+NyaQIh5N20jM62cTPT/5r9i5vZo0AfntvL0GZYqEDgsC1Oc5g= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS0PR10MB6728.namprd10.prod.outlook.com (2603:10b6:8:11c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.41; Mon, 27 Mar 2023 07:43:27 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%4]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 07:43:27 +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 v3 06/11] scsi: scsi_debug: Dynamically allocate sdebug_queued_cmd Date: Mon, 27 Mar 2023 07:43:05 +0000 Message-Id: <20230327074310.1862889-7-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230327074310.1862889-1-john.g.garry@oracle.com> References: <20230327074310.1862889-1-john.g.garry@oracle.com> X-ClientProxiedBy: DS7PR07CA0021.namprd07.prod.outlook.com (2603:10b6:5:3af::23) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS0PR10MB6728:EE_ X-MS-Office365-Filtering-Correlation-Id: 8c53e66c-63a7-4212-a803-08db2e96f3be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K/Fcfy3wmCjUXKaezPq9+22hyPgVnIN4GJLoHs/Ug1kjbBUqp/BrkmHtJ2WPgnSMJ8nSFDZ27RMe8yYXkDcXascfsn39EVjtqNQlM6CJ4G7ikuU5i20CIkCcaKnnUc3v7stJ5G2uqy5Dulg483OQsLSBgJnwlp3UxV63ishDbt6h8lSsxgTXYNrZdShz/8T/V6T1NzHuDEQyX8xK3B/2inRaFbD24HCDdJ2U1uEHf1OWKJxx4sQ3SMMGkUi3XS2lFVor61Z6KCrg1m332UDdGknnKlpeJ+1d+qqMYPFVs+LgEOgFsmmP3sBVi7BsKpxWWh+JRvzLZVRMaK0JJPlNDzbpkGlGsXsA1FkHRHbHKr43U/VSY6OyzB/WKXYDCI/0o9iPKHcEykAJin/HVLHsDC46yCIVOmmSm6i6X3oNaF1tKvVFW7wde5VR9DhneIJJChng0flE63kLKQf9VJOmTjqNqR0v2w096dYIgnWKOGb5x69M4on6lTDPT+9snTWfvsKEAcF3u6kfYP5idb2TPKFtds2Mn0AivxgdMu7/9z5pIfcdefD9LYb3Wsv7Yffh 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:(13230028)(39860400002)(376002)(346002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(316002)(186003)(8676002)(66946007)(66556008)(66476007)(4326008)(41300700001)(103116003)(6512007)(30864003)(38100700002)(2906002)(1076003)(8936002)(6506007)(5660300002)(83380400001)(26005)(66899021)(6666004)(107886003)(2616005)(86362001)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PIiGSVGRUu8rIKB2pdmXJ3veFTP9LVdDWHbpW5LWv5HWp3v2a9k2ZpaR2+a3V325nmld+vgYTYVs8Iu63v7S41MIn+r1Mkki0FFMM34v5D3GKFjolfcre0+GwftaOcdWzvfAig12dihO/59M+WthBBqDUwDnxlFB+FgY1ixX/5thx92vyLt0PGeZy+CzkOYnvzLVarJcBFw3mV/K0kVi1ryyuLjro7pvgIAe+fOZx+4qtN4b+OL5SgWR7G4nXcmiXFzZraFbtdDYmcZ0JQXq2N7XLGLEvKYIUuU7F3nwP6e8cMPbt0qGa9WII/lBVKvnLBMatxi/DkQqvTIbNfoEsbWIKD5/qT0AsRdtx/uSB+M9PLrqEqx48kYbJw3KyVW9EZzGAXcvPcky194Tv809hiWX7ed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rTmBMqSaiczD5g= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c53e66c-63a7-4212-a803-08db2e96f3be X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 07:43:27.3168 (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: xnncfoxk+xXJbjQT9LbdMoh/MMxFm5c4NLtURuK6ZlSVlKigfmw0TGc3eUP7fEymFLqAByE4zyRjwA9CxPm85w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6728 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-24_11,2023-03-24_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 phishscore=0 malwarescore=0 adultscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303270062 X-Proofpoint-GUID: vKVrxNQ5y6_Vtv16K_a_xfhbgX0z7-jo X-Proofpoint-ORIG-GUID: vKVrxNQ5y6_Vtv16K_a_xfhbgX0z7-jo 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 Acked-by: Douglas Gilbert --- drivers/scsi/scsi_debug.c | 427 ++++++++++++++++++++++---------------- 1 file changed, 253 insertions(+), 174 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index f53f3e78aaa1..7dd2dd6cbd6c 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,34 @@ 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); +} + +static struct sdebug_queued_cmd *sdebug_alloc_queued_cmd(struct scsi_cmnd *scmd) +{ + struct sdebug_queued_cmd *sqcp; + struct sdebug_defer *sd_dp; + + sqcp = kmem_cache_zalloc(queued_cmd_cache, GFP_ATOMIC); + 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 +5608,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 +5661,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 +5723,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 +5735,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 +5766,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 +7101,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 +7127,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 +7144,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 +7533,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 +7545,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 +7607,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 +7616,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 +7800,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 +7837,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 Mon Mar 27 07:43:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13188693 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 E9A38C76195 for ; Mon, 27 Mar 2023 07:44:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232282AbjC0HoE (ORCPT ); Mon, 27 Mar 2023 03:44:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232656AbjC0Hny (ORCPT ); Mon, 27 Mar 2023 03:43:54 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8E551B8; Mon, 27 Mar 2023 00:43:35 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32R7UXro011933; Mon, 27 Mar 2023 07:43:31 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=nsbdq0bx0WgEt87oVe9t/Q1PgHe29PlR8uZ5X9lCgRA=; b=zayWh/9AePrkurYg7Kuy0w5q7cJJAFvXpBF3l5ST6+jcjbnw3nc7bbMrr8DStsSwD8xz ob+0kbOWQhSOE/WP7Fr7WwWC+nG1AL1aQ75vHMBdArpXALzxdUMt2jUrfBNTWCiQyGrX Q0ieTruYFgd0L+xbo9xlwtYiCqI9K27VzOcuvTJEOb31465dnbqgrE5/ZipPBCC/K/W1 +/IPJfy+DkTBc9dGvjjYZDxiJ2a3qxzpeqZ4jxv6/ICDWbbMA2AqC6qyU5F3akG/67V6 +WVmlWtUAlimFnLpdqbABobPbAem6f7xnIE6KdeHa6NnGi8pKeDX3gDK52fvkF2VnVWk QA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pk6t581pq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:30 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32R7XUfS020313; Mon, 27 Mar 2023 07:43:30 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2045.outbound.protection.outlook.com [104.47.56.45]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3phqd4mwa6-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=htHUiUk+LzT6Xb0KDSx8BdWn4n6UFXwv5f+euxK0/zScIQHdaaYEt+EIu0v8UV7vjGz4Pla2/lFew1hE+djicshwfZZtLs2Fd91T3HWygPsXzY/Gq5lnN5LfqsCwgGinodgsXmkWDIq8nXK7maKgn/jPM6uZVAr3OspCbRstWsuNA10ZpXjbJSyUD7L1NIUQIdFFxeImaDhPj9hiaLjGznC3lhtDLJa6v8yEn4YE045Gc9JkoHXCYUUEkgzr8Ur9w0UMrV1jAKsZDOdlYc8oeMnN63m2BJnzDFo6Zc7ZHshkVK3WMbA9BDLeeYYzI1oyNf33UT9L/9UNLvxdl6DQ2A== 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=nsbdq0bx0WgEt87oVe9t/Q1PgHe29PlR8uZ5X9lCgRA=; b=IGKmSEnkjDeehEYzVA0fRhe6qZb29jzAJCxFrBIgB9ZtXFH9/qKBWOrb3l1VhuaXVRSHmJpVdcwRLwjUgNBYTrIYzKTXQ0VOFzXDhpjuL1uiEyd99AUVWd1AQyYHgHaKHH6O8WXCWI1DYuLKjxqqjAoqbzeaWAMzvgR0WIPgbvJFH8er9epUjUs8Mg8dXQDKzxxJ1WTsoaFySKY5mDbtIdy1HALMOoH7pZOhDl0TIf7VAvJZ4RBFhZdCuXJaFKSsjXSaz1aKYQAFBA2NVwth4xOkaeTkSMgQWtUD5UUT2IWkcuDDMm123nkJK60JMwB5Tj1uzyxRMZsOr33UohOiIg== 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=nsbdq0bx0WgEt87oVe9t/Q1PgHe29PlR8uZ5X9lCgRA=; b=WpndySI60htgAELQSNLlwoLySH3D7S2oBRhG3mqrlU2fifaj/vEmxnbDWwJF/pJAVtXZTxd6eoxkKbUGSev2P1TxuqJczNszH+J70I9EOFjET03F5j+X6fqzxceqQugS4ztOkaltVbAK2pInZBvYhERgo/XL+N/p4XwHJr5iqaU= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS0PR10MB6728.namprd10.prod.outlook.com (2603:10b6:8:11c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.41; Mon, 27 Mar 2023 07:43:28 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%4]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 07:43:28 +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 v3 07/11] scsi: scsi_debug: Use blk_mq_tagset_busy_iter() in sdebug_blk_mq_poll() Date: Mon, 27 Mar 2023 07:43:06 +0000 Message-Id: <20230327074310.1862889-8-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230327074310.1862889-1-john.g.garry@oracle.com> References: <20230327074310.1862889-1-john.g.garry@oracle.com> X-ClientProxiedBy: DS7P222CA0012.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::15) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS0PR10MB6728:EE_ X-MS-Office365-Filtering-Correlation-Id: 3c67c3fd-87e1-4b2b-182f-08db2e96f4a6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3l8ifFRG+90hDI5Ck4K1eMxbELgqv5azMKNtMeQzFNG21wdxk+BbMUNkj11Ywux9zdz4dsfIJy4MclJDFeiYkol0+mDm/RvRqsEiXcnTZcKfqg8fceDyjeLuncC52dhe/Xicv6V5Uv50mMe1tBH0ufjZZcrpf79DHavkz2SqhreotEHvdsfYJheX+b2Q3aBmiv3j0r3a1aRW3jHJtyzMXDz3j/dESHvH/l3Cqqmg9PDck8s3A+rCp6G4Tid6iftTk3knJJqrJc1Upw5NIe4orIXtGYhKTO36Jerdfy+6eZfUnezLsZGIGhjjqPh80IPN8OpqU3kdkhgWeLkMQ/DAPgLEI8P5f2pyqOYPCJJe9m7qaj8SnyvDSUGqxiwlR4xjXF2N1VRqVcavmj556e9vgsuCl/ZZ/lZOwhIw8EAS3KQgl8BtCleB4TXPZMy66jr5Qh5jZMS72nD/yugUUA4OHdIokZyA3H+IMrlVXeeaBoPbqX4V51ks7qQWhTQlPfBvTjZQqy/iQoicpQqo0KiVxLeg7MYIh96qqE0lTbHJzVByY86CFAso1GJi2/JnVo7R 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:(13230028)(39860400002)(376002)(346002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(316002)(186003)(8676002)(66946007)(66556008)(66476007)(4326008)(41300700001)(103116003)(6512007)(38100700002)(2906002)(1076003)(8936002)(6506007)(5660300002)(83380400001)(26005)(6666004)(107886003)(2616005)(86362001)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7M8P1NIniIfaeWgo/4hCLhNM0XLSp4pKk+QARQYj3rW5aclLw6z1/ERMlOrHRDAQNWLib5dxUo9v60mSD+kmlErc2IZfc7e3Es5CKZnxOclqgeUd0u1PNICyY2FKGAKix8r9ew+Jkwn/ACUmKxtMzHp8nonLsnD5flBtmFEbwb2v6CLqIeu5SLmwxVlD+TwGQuRo66IGD2DlehzqV0hqAR/YWJgRPAjrWWonN9r38RkkPPKpUe29wvTkaBbdRyD0xbtdGK2HrcaPqPoWshjZ99HeivEFEor5WVpzu9+IPV22psNTj7eGypWr/V6VHBTlZui9rEHYlD+DIciumHup5FSWbkAAIK7DWX1LenL8UVQYQtsD17ZnB5IIscVSYlC4bTMk7PbXPe/ojfOCkHn8qQzrCFxZL+oSzvjeWBblvbrfYclvEprwyQAV6l/t9S/7SttNFxPvsbgHcf8RimveuJBedpV/NGvk8lDmlkAe/AxUai1c0Fmod6ykJeadyIKQqzKCCiQXhBb6M3Myfvo5+RxnYdeQhxSrQzFAPbRfSNLuKJr3TI9QfH5KaCU5WmoEFl+ZxwD1UmzILRI4YYyh7svnAI73JX9NsfvHvNobkHN6h9k4ILDUVKvG42MsEpJbvG68XigJu0TnbzyoOBE9WLxMRmOU0HBgLYy0FUNI/GyDENnBmJPmcYIjppR290w+e9E/9hilmMS3Yg8CoHQYozYDmqca2JX6nuVx/czcTODjM/59EEy9ouYbxOpZyPdioxSUnIL5jx0FvWPElX30cCHZ3wJ1GdLVlsqNcF5o/b6zb+Dl2tUx+AwMH9sbzaGTTi0X14JCxx04MkZbl0J18TduDSALQ0eL9/NWN1BNpqhriZEdNtQKArkg6ZXtD8BDh5c/4IDgLwenXuRO4zyYw0RvmaspJcfRFYYgWy20x6DWHvruWbD5bu8zpX/LkoE0ucZFHHWIhiUrU6A/DxZTtLT+sn2NAcqeF8iKpgQHQATgqSFQrSwv4tm91IYQ90RtqQIU+xp5DL8YWKI5kMaAshOuLz5rPaThL6+vLyx72rEOvad/C7MEgdDuqb1jdpMtGaA28LCO0W/taMxrajQCiStcFFvHeYsKkZJhe/JBfkovFbEddVDXGyVF9NSbeJdPp2+m7wf2Sv3kouM4QL1HteqAEfn28le9Syc7NGI/bhxSiXYvVhW7FwZNL0JxgCTtyuvkV9mmHAZ82bR89TxngxtEV5Ip0Yz4Up8VEMiO04eXPUnZ8rzY8NSQT9s83XnwtmFmN6nFa0NYEE2Dkrihl9UC6yf1y851ENdWkyriEwDBhMzqc5TImnzL5BAOaBUD0ZvgvqiHo1o1AOQIfCNi/s5+Pliv95vPCjTjRFvv4nAmwCQHf8iqPNhFceptYyEI4vL76jCII1P9GPksw9IWRv6q34JGperM1GtAeQGaad2cNmdgtOBYg4dLhs/N1JrxegZ+CnyDUek/o4TsWvrOvJkqmSP43cWKB8E2PJuwiL784oS+YKCmbk7QFwFScxl6zCejPiDAr5gM4/W8lakLIuTYkrTnVqWA87mPbvs0jirwfcAEyDZqOTSlK2RMjUh0EDUYn3XXiTiO/e9XLi+YAA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: qO5jgZ3NcODGlrX63BXrH+Rf9aRk1jWr787BGNsCR9QtNJaEOH5Xw0efVeG1gC6o+gte+BDiiswx7AbODttrvGOeiNZ/5IamDLJdmuwjosXNPrrZWWkOMcArECTj+T01CBewFEPe01Qv3KJHAK2QVD+wX9XL64oEuWDbDJpj2PmsGR7J7vWGiJAqgPUKEjwJf+47ub9ULBPCvfKEwUykp6yF5AfGbCRRO/gglTFpW5sa7XuorUbQY1UusI1GV/bteEZipx1Sgodl6urMjtPLtDihTqLiFcZeiEFf12fV6IjaxQVX02RZL675Y1TumPuzPcWCJFeRwQnk3x+n/SDi3eMs4SgqFO0H1uVYq/ymJuNgsRdHA+rrFyoABmY4t13omywE9fwVNatOkjpNYywyRrX0u2l+4FsJtVw/BHPs4AfZBKcnVQXk0YdYhMw0wVerywLnP8CkgnsInQKHgUtjQ83/HiLpust2933Q4F7oprMbjiDyMaKOkHw7B3naNf7l/1rU0wAaOe9xF0UmvCn0Rt/rNslaTRUMxyUMRAG4U6Ph9TIDnNyDb9li85EHruWchQ6o3ZQ4zMToa4GO0DWlGTmjMeT572lTAg7yEl1wPhfB+LsiIxRAVPbd98lpYUdZBpeidhs+uLoib3hSghssdAKKEMER1+TTFkOckDEnjAeyijHnPrlu1QsOq+k3jT7jtgSK7KpJXik9HwR3fsYfaZKSltrCMk3JhQ2mEPyn888yH7yu/afqJ8UbwFiiY4sRhcoEsarlbrL5UX9OI/qaVVyAH0r+S60DPkHX99P+PwrVXjQDsk56OHp4X/nLclHn4as6e/DS2Ju6VivtSeLECZy8bKq4bXroGyZ5NpniWbY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3c67c3fd-87e1-4b2b-182f-08db2e96f4a6 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 07:43:28.8492 (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: HWg7ZSs8tGo49/81wfK1Bc/G6TP4tw8VfHssmeNeL0YuE8iv/EkBvBVELtjeS6NgfWyh2jlTsrFq4ov3ohyjSg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6728 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-24_11,2023-03-24_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 phishscore=0 malwarescore=0 adultscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303270062 X-Proofpoint-GUID: QsS17e_DSMsJNMvtjtLqNdO_waK3lzdk X-Proofpoint-ORIG-GUID: QsS17e_DSMsJNMvtjtLqNdO_waK3lzdk 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 Acked-by: Douglas Gilbert --- 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 7dd2dd6cbd6c..3330848f13cc 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -7511,123 +7511,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 Mon Mar 27 07:43:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13188695 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 AF694C76195 for ; Mon, 27 Mar 2023 07:44:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232797AbjC0HoH (ORCPT ); Mon, 27 Mar 2023 03:44:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232514AbjC0Hn4 (ORCPT ); Mon, 27 Mar 2023 03:43:56 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3D1D4200; Mon, 27 Mar 2023 00:43:38 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32R7ZFqX021908; Mon, 27 Mar 2023 07:43:33 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=FbruwxeZvxhz+ztTERWaYgYRUcNdNyZJpt5tNzAdTFM=; b=TWlBOMpWrVgZv/13wwKXBIsJ7SXrzbTdUEXKZVFsHVY2PKwiNar3dpDX8Sxuw+UWXJEx l98sUsA+eGHKI8DiNCWl1SDWy02KIcnzXGKS11aoQNgrs45LQ+x8slO//Z/iB3vA/C8u RTGXIH1NJCYYzcMx0kdHZg/tXKouObh3sNw75Ws7jrzBdQYQzALp7tpLeXmMQwt/xQXZ ZzKLHuDRTVVhEmhY/bPTxvN4s+7k7Ku4+V5hdUtEAVYoT58Xi2S6g3nKzl0SHCdoHFN9 gAgAHq4G15JGkUm0mevfQbIDVO3Zker2A5bjeXjzimsNMDvYqQFt+WTx4JAHZa68cxzD yA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pk6vmr14t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:32 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32R66ahp005510; Mon, 27 Mar 2023 07:43:32 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2041.outbound.protection.outlook.com [104.47.56.41]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3phqd4d5e3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TiNGo6/N42bQZ0kKlWqK4CueIdagFrVsC39xoS+sH4sMs9R+aCMzo1a9Easa6xY4hz1NmXthA0Nwt3744V6svVSAgpzaG4UAVf3aE6SNBvRKECSoqk+xu8HxnDQnyt3qhNYpH/6R9BoH+ae4EXLgemOfs3xL+z1JIqjqWITiPTiPwagTwRThe/ZhN7K+YpA/1DrtALcge6EccoOFQwWfEYuEgaCMovc3b3z5pQnY53IQbCsLVZGdWJInd7AwONTGMSwR3bOqRVkBjzwN+SGkrDOm9YjQsOPCmB7s+rfMVCAQo9X+HffCFmqb6FKO0qW0bL0gLO2ckkw4+4TkQXW+vw== 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=FbruwxeZvxhz+ztTERWaYgYRUcNdNyZJpt5tNzAdTFM=; b=MykeNe5LpW1l/+QzSxTCoDwncMf+jaR4r/OI/cQA6kaydZeSlUCwUmB5P7xz3Zvs64VpkjUaSRzKnl+iL2T5bvFwrlN8qYq0FO7xLYnPbxd3slf9bHGmBVSxi7kdIjrEDWW68cu2MF1G/rp0EnTLlzEZUMfnj78uDX2DFVh1Yu+TQK4LHiiM0b0D9IaIKwziLe97rlDIBoTkTr0mf9nNgYoWviBtRmFkWKhrkSvbb2dpu5FimS+49wTmkQc5MCUgPRA0iRZIIfGoVQ+Ov5IHqHyH4x4LIiYLz82OZAM9p/mwrpl2m7VdEdDSHF0Iwa/qT9wsw3nC9tO0kkJdbrqHCg== 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=FbruwxeZvxhz+ztTERWaYgYRUcNdNyZJpt5tNzAdTFM=; b=Z0WBZ0j6VHFgaMF1TU98zb4pFpsnrZ2/hqY24rXDVkiWcXnLyVt+vPHEjkDmpu+MzK4hyBAEe35TZC7f4yS1Ye60W0WYBC9to4yR4S45cqHQGVrR6JENC5Xhnj7ZSqL2CVkQk2xMWwPkx+GHNLTshGmld+8LTe8OZMP4VIJ25Po= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS0PR10MB6728.namprd10.prod.outlook.com (2603:10b6:8:11c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.41; Mon, 27 Mar 2023 07:43:30 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%4]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 07:43:30 +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 v3 08/11] scsi: scsi_debug: Use blk_mq_tagset_busy_iter() in stop_all_queued() Date: Mon, 27 Mar 2023 07:43:07 +0000 Message-Id: <20230327074310.1862889-9-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230327074310.1862889-1-john.g.garry@oracle.com> References: <20230327074310.1862889-1-john.g.garry@oracle.com> X-ClientProxiedBy: DM6PR07CA0108.namprd07.prod.outlook.com (2603:10b6:5:330::14) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS0PR10MB6728:EE_ X-MS-Office365-Filtering-Correlation-Id: 52418e41-9b66-4455-d104-08db2e96f55d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PJseONH8OLwI7/Tp6nGhKNa8dJYIerbGB7S97xP2B23g/E/WjWG0DVfO1rRZZPlbXK2ny816v/ZsCN7g8pAQiCDk4CHF/ZR+0z2kk73jSEaoiaenuSfvkjP3zE9vqgPtwb4o/4+9gcZh32wAVxnhrZe9nLPwNb4ppmEayYQuVxK0SffOSCriZMulHEM7OWZUE3vu1VM3GwvMxbdqnDmMwg6SYx418E9ZD+szUJNlO2vtv5k2SP+CTU64T6Go8OzPSMGlDDD5gjKCLhS1QMGyWxLkm4FQ18ZU7rQGi/4hCbqefw7BWzShJNRD4d3lZvwX6CdGWCB3JcLMo6Y1HTTlZf1T2Zh8cLpvlc8GDyavtl1njoUpUT1KMharwtWMOrueOMFYgjCAWlbeu2Up3AVyLBkjmC9EpS5CN6rYNSZOON+ftM8IeC4gya52PdvoATK9IWKP/QqS7I0jPj5I+JSudJ+gK5n+PVmBc8Gv/GYkfkr1VIuzddzHDPSUVaWWdErxlukSjSOOjfV9a4cvzpCmcpe0VAKho2pPM8HhdBjvjJmTvEv5XPW4deCzkmh085Wl 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:(13230028)(39860400002)(376002)(346002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(316002)(186003)(8676002)(66946007)(66556008)(66476007)(4326008)(41300700001)(103116003)(6512007)(38100700002)(2906002)(1076003)(8936002)(6506007)(5660300002)(83380400001)(26005)(6666004)(107886003)(2616005)(86362001)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Id68dCqrTcLzcS6hKX9SX/ubq3Zj+S3f08DVXbpt2ay0J3ZPZzJAyp0/yqgCUbd0D6fWxeyPDx0pivhhOtgOhhOszyAWiC32WIKa/7MWWSfNdSn1CfLw7HiJjYJA2LDqEAW4UomupFeid52+HaypzCVWVTGnKcBxjASqfJ3DnHB/tKXqFVya7mpi9fN6JS/8NYV20u26hAAeaMaoqY6/FpQG3PoZ9CGVMxk+7/H5JZhU+kX2vteayalP0XK9R1mjPrdet1D9TTGiLKW5n+nzlEmcmHcPgOGBzBPkFEu5gpPGZP3NGv4DIh+TGuBMsNgGWIWMtc3ethNu8NPJdRh7AzbM1aDNyA9fk6/rDv9/M2b7YFYuEHECEuvzonTEza4YwBmxH31MW7oiOZYCGPmQZrVE7Qjb1Lh/hOkR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FP4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 52418e41-9b66-4455-d104-08db2e96f55d X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 07:43:30.0220 (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: kUhT8KU26vfW8qS1XKfZ+MgGRHDSQD5TV6ZRK072nqmDpR5rwPCl0YfUwzAih5OVV/bV/LX8wbTWWaUFuWtf5w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6728 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-24_11,2023-03-24_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303270062 X-Proofpoint-ORIG-GUID: KDNLsvIDvhklt04hjN3jl4BQZb0G1LSa X-Proofpoint-GUID: KDNLsvIDvhklt04hjN3jl4BQZb0G1LSa 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 Acked-by: Douglas Gilbert --- 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 3330848f13cc..677fb177ccd3 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 Mon Mar 27 07:43:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13188694 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 6FB6CC7619A for ; Mon, 27 Mar 2023 07:44:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232787AbjC0HoF (ORCPT ); Mon, 27 Mar 2023 03:44:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232664AbjC0Hnz (ORCPT ); Mon, 27 Mar 2023 03:43:55 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F10D44EEB; Mon, 27 Mar 2023 00:43:37 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32R7Z4ZB021839; Mon, 27 Mar 2023 07:43:34 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=3a0rDP2b1ci287MOeHi9JzLp3A5W7MtK50jkyh882PU=; b=WdmN+D5cXbfnLSW8jUCIdcWJSfvNWphi0FSg4jar5aMUTHh86j6YVV1NUVY9WGVwIqMP rT14BOOJtpRv+bNuxv3+6C9UYZ7uAV8eH1aOBVtt8i3toNn/Prz7IMT2qNsIyq9gRfFe fot1m4eGInVXyqu09hdcD9okIUEohvhT4YKDBbFEdWjx13uI3wduUw4SuCOCywxDJnlS tSwD5MfIbG4j9RByo5PlXVW/NxSkx02eqIKiaSAsGol1OHubuYAFpUYh0k2csw2kaoV8 b3O5AkPQj87jgl0CqTUIJZ/XA+r2savv/wVyBxyr/vj6tmpjID9uamf+hXbF1I/RUQAO 2Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pk6vmr150-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:34 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32R6RqjH020441; Mon, 27 Mar 2023 07:43:33 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2048.outbound.protection.outlook.com [104.47.56.48]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3phqd4mwe7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ddu1Tw8+9F77c/b/U/XYp3nnSAgMZU3W663qDw3H8tHohbxGqkz//fcfG0WvMn2/IPB0zwDnyrXN6wf0AsU84pR1/zJdo+utzxt6BIuAvd0QOCJ00IJximg7GUmx7tSE+9pPNxzueixtJQ7ev4l+TAyVGsseM9jO2jqwNC+n9k/E6phftXxXsBsTVqDWcO+atViaXbL3RCC7RO2ZD4xFCQy6GjO2+LdLdzGSdh5l3atZtlMhAsU1taTtwDiGrcu9Snv/pQurshm5/4K3ZbrFT24O1vkHYxUVazuLMZnzq2zlyjfiyzXGfeO2WwjHEP5vIv+HWX/sr8ibBIZTwct5kg== 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=3a0rDP2b1ci287MOeHi9JzLp3A5W7MtK50jkyh882PU=; b=b31854uYQbV2/N5NZjkiuTvwGOny1s62ZdfG/LOzqFV+swIVpG4VN2YCW1KX2/6RRncfOWBjNrSiL19ci1A1JrFim9YcyDaatTMqravdwibX5p4Ns0hPhg8Z3V+1UZg6ezX1UK+9xFM6RNnHQoHuGAg+PIA7fRZ2LUWE35f2atPOdO3RbTq3HlXMZsUYw87ZJL233C8FDcdQlrU7splwalUcX+wo4uS/4WsRr0e6q7vHq5SImCT7WiBV58gPz1QYIRqftMfAUnmRckXk/ZPq7SnhNiVZu3hCVOPjRydAJ0KeUQ6qtHndq7CqgZLNg/1sUfkUhkz09JPSm+wGXTg/IQ== 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=3a0rDP2b1ci287MOeHi9JzLp3A5W7MtK50jkyh882PU=; b=DkIIurmqfcAQOL+VHuH4jmRuQ8g7DCtTg7x3LKMe8XDc4D/Vu318gjVazUX8hMx1eKyYRqniQKIsno7sTuOXXD0RTxWEFNBZoxn5GUJ6ylMsQc6vlMivQUvEnewk19kflU8bYgoWKqPL20LzVRgMkMEBZCj4heCv0rStjo0/rsI= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS0PR10MB6728.namprd10.prod.outlook.com (2603:10b6:8:11c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.41; Mon, 27 Mar 2023 07:43:31 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%4]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 07:43:31 +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 v3 09/11] scsi: scsi_debug: Use scsi_host_busy() in delay_store() and ndelay_store() Date: Mon, 27 Mar 2023 07:43:08 +0000 Message-Id: <20230327074310.1862889-10-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230327074310.1862889-1-john.g.garry@oracle.com> References: <20230327074310.1862889-1-john.g.garry@oracle.com> X-ClientProxiedBy: DS7P222CA0001.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::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_|DS0PR10MB6728:EE_ X-MS-Office365-Filtering-Correlation-Id: cca53401-70f8-44a6-d5e8-08db2e96f661 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8d2miScP4HqKyR+wvioOCoDv+IwUwRfSeXku63eKgumS4e6i9n8BLYdQRCYmeK9ymSGNM01xjJyi0B08v3M1cfj1jaVawjfY05BzJ/EtkSsuFZrgGtnjr9PaM2/7vYFB6tHnSiSuKNSYVy9OpMe+zs8znEUMpZCje1CoNzv3FXmEKH63/mm8TL5AxsXwD4vpYKzakdCAuO3TcMLF/rQ5aLbmHLc5GH1mrVD5jT6OUiG93a94S30IkNDu4hCCr8DqkRa/yGMlBXBa7Nn2TAzbFj5AwLW75T8xvavlGiNcM63Mf8utrVpSW9fKlYlZoveHuKUc6UmYoS6shznpOPOYf0SoGbLwnmgu3vw3IbJ5jkndr3rk00kpLTOB1CFKb0Lglz1pKi4pybq2yLloHzA+zqhDKQmC3jIiDFnC/xYA1YBOcbKklm9Qc7YoN4TRI80rp8BUec8yUo14MYJjMNmxwLUqHMSYdtWkoiwCc/uEYWPYgq6TPumFf8GkwQqavFjB0y19hIQxnRvE8LKyDP0RuZa8N1xiFSlvQf75clnKDUGvOyFWB0SJxjUBxTciu2ej 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:(13230028)(39860400002)(376002)(346002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(316002)(186003)(8676002)(66946007)(66556008)(66476007)(4326008)(41300700001)(103116003)(6512007)(38100700002)(2906002)(1076003)(8936002)(6506007)(5660300002)(83380400001)(26005)(6666004)(107886003)(2616005)(86362001)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jm5FZQtFe6rrCPqBKl+D7dhMHSYszqZSoUcWp8MbG0pmk3+ZqXjDPUhTEuLLOSuN2sNoi7I43ndKbSUvR9wHpEDLJ9+xZUhxV2jhAiAYhpgm2cOmPf7GLKppZiaxqjzo+dtbbUau1Z/t9r/RVumx1ESNnrascCuowGwpX2uAoYnF3K+19ltJYwvpSKNUGQ95F9/26MnkqsSeUiNDAQ0VUc4CAyGOqEUUzK2hjBtEFsMAOZw1UaDD9VaNHR0iI3Q68+bUdlhIzUQNef5xw8EVq8MFWTYx2pZXEoMuII882pvqjs6iEnOkq8DIB8l+XWbagqRoFIYAGMnTYq+faKRq2Pe2fk5wg6v02r2d35kp/3euxLSrnKGJspaB2g1AVRU4BHJGCslkDBzBytjYhsl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QVo0/+f6AGWiCp0dJk18= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: cca53401-70f8-44a6-d5e8-08db2e96f661 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 07:43:31.7261 (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: 9Bouh4uUJdKlKC3Xjzj4PCCO+LBo6+rZAfy5++Bm4wbLczprPwu9lfUoeHmwgLuX9xMZkp7AsRtVVw2Qm7MTtg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6728 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-24_11,2023-03-24_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 phishscore=0 malwarescore=0 adultscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303270062 X-Proofpoint-ORIG-GUID: y_brcbRKfO03aTbdbnZ4uy0o2EgKXu8Y X-Proofpoint-GUID: y_brcbRKfO03aTbdbnZ4uy0o2EgKXu8Y 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 Acked-by: Douglas Gilbert --- 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 677fb177ccd3..6e40e9253393 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -6062,16 +6062,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; } @@ -6104,20 +6103,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 Mon Mar 27 07:43:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13188697 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 6DC73C77B60 for ; Mon, 27 Mar 2023 07:44:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232816AbjC0HoL (ORCPT ); Mon, 27 Mar 2023 03:44:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232720AbjC0Hn5 (ORCPT ); Mon, 27 Mar 2023 03:43:57 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 504E55249; Mon, 27 Mar 2023 00:43:39 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32R7ZFqa021908; Mon, 27 Mar 2023 07:43:36 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=wgjRk98w/OAWYBQ3HlwyEhUAkcSEBVv5ule5dectEC8=; b=gsobvQfmRWWj+vS2XNLOATLLOuHmJ+LPrXyYOQKt8GqW0R9H4VRzPHt4lxX8WS+7Uncm UtTW2mCADHKpoVAWbR5sL+Dvq2uh94FF553dTYzSmFGl+ZwVB6GAzWA53Qkj+1sclPy1 gpmsw/Zy+yraN+UZfpc/d8qCyZUSdydByHJQkQGR3KJDj9L0BrS6dYyNCIMs4lsUwgyb vK/cIugVewFqr9nRZCMCkHinxkvJ9RpDf7WNA5RvBeY4Th44mlyzgAYp6XGjON9UEdzt dWlVbpec8D+CSJCz9jwvujkNA1XpxftXxweOt6n+5a9DZ0BArLA3Z39VMQTEyryi3Osa Ow== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pk6vmr158-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:36 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32R69ZkK032943; Mon, 27 Mar 2023 07:43:35 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2042.outbound.protection.outlook.com [104.47.56.42]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3phqdc4waq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HOLhWDHIQm0UB/vgkSktojFsg1S+xjMCQRYaxsN03pDOfjttnDJ4kK76Bkh7kTbeFwYFkS7zDkCwbUhudH9+Bsg4fUYNief5wQ5mRM98QPRGYfDLcSwhc2JhNRqBDyc/ej1vbVDlQR/I4zLoMgBgphrL/E0B9Cvvfr7DtCSxJk+EBjcLnThbIupfFwsrPMyfQi+VpUTh0d8YYk+dyl3MLVuLguUKZFr2fcMeHRCU0Swjf9D3B2VcovY0ZmTkIz+nVRP7bwLUrqLanfUSQCN6QDnx61D9IgJzrwTrnlpBfKMAOxlQaSWi4skyreZS2ifOTCjIa18CS2QWl2y036DLRQ== 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=wgjRk98w/OAWYBQ3HlwyEhUAkcSEBVv5ule5dectEC8=; b=hb8ykBBlN2VoFDsJHBdZq1vGXcRL4V8cXhIH0orxF9V9DRVKqv/qodhrvwQuOLtDil/vV3CJSNbuSSs/B1OEOZmz30jHwfkaUyO9xF+WcqKLKfEk2g2uZX3QEJDqh9hN8A+ePgZ/tz+iw4eO0si2DcxzrEhklbxCUUcmbI9ptV2fO83Ks4WYidGBjQNAt1mEMAHyQXNXhHZoABPgMeC6IERw5NkZRYGP/9Js2xpyQWJEv4EKwc0Ww3S+l+HV+wPqTSxlqvIX8qU+W0ma0V+uMYwLsCBXJjn6A698brOrNbXWNPjWFkIAz8m4RhCLGckKPLcqMpCv/bflES4o5FWVpQ== 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=wgjRk98w/OAWYBQ3HlwyEhUAkcSEBVv5ule5dectEC8=; b=homTKIGhP2SGokRDy+FbwIVaQzRfIgdPjOGiPnYCCdq6RaXoVuAEGia27OFSwDLtjJq4670XwpVaLlZIUdeoLP6peuDOfUgk6q3/tfOHuT6sZPbhwPwcv9K8I5PHIQGAc5q05c40O2DIjRjbRfVTVyj5BcA6jaD8+3r3lafEdQQ= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS0PR10MB6728.namprd10.prod.outlook.com (2603:10b6:8:11c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.41; Mon, 27 Mar 2023 07:43:33 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%4]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 07:43:33 +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 v3 10/11] scsi: scsi_debug: Only allow sdebug_max_queue be modified when no shosts Date: Mon, 27 Mar 2023 07:43:09 +0000 Message-Id: <20230327074310.1862889-11-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230327074310.1862889-1-john.g.garry@oracle.com> References: <20230327074310.1862889-1-john.g.garry@oracle.com> X-ClientProxiedBy: DM6PR07CA0107.namprd07.prod.outlook.com (2603:10b6:5:330::21) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS0PR10MB6728:EE_ X-MS-Office365-Filtering-Correlation-Id: 6cf3985f-7eb5-4e72-b72d-08db2e96f71e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V4JNdha2FyGNYgp4GeVHStLSO6gGf3X7V+ydVKsCQwu2GwtqsjJrKYWJyB2uOUEroTjspx5rUcKiIZpTAl5ANNJ3PQfMCYgJjVDO8ZfKvGmrITvz1/HU/RZsEmK7jGQVbQX/R742kgKdiZfkswK1bfecYdt3YJVUbyXVz549glchb7sqSdaraStzvUSe9skdTnFs6TKR2HPp5pi5qoJMN2ErK97Z8CkcESJrvQaiC7/OzDK90tXk1//k7WbjOAbWlG+fEdnODn/jtnMWnOmgo8EIrRYx6lM4d//o1JCVvrIzjp//jbQnFWl9vkM56Zca5G3oml3HHoNTZx0SUeOLUZ5KSIflmyldHRjTg/6k/q7qKvFztzaVzd9Z5XUg6zK6jJMdRohFO3LdXZQivyurB58UTOPc+el6W1yFmWDHgzCbMWJtcOE4uk1w2QrpV0ELroLce2KqO6+VhMhuZRZDd6HdOYw3pnuIF0TXCvuEJJmpIyxJ9yfFamenx8rlH0l6ITrRrwMRCt8MVSaKrTqZX3VEiMvoNwfXkLO4D91wRARv/SwwFY8Q9qD+zjdI94NH 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:(13230028)(39860400002)(376002)(346002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(316002)(186003)(8676002)(66946007)(66556008)(66476007)(4326008)(41300700001)(103116003)(6512007)(38100700002)(2906002)(1076003)(8936002)(6506007)(5660300002)(83380400001)(26005)(66899021)(6666004)(107886003)(2616005)(86362001)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kGLelM0SOTjL26NpJ4NPLZcGrAGlHXtkTipSOj+vNs3Ja8RW7rkJbH+39VDRdTQ6ZPzbhj3jsCcn4iX1vES0sN5q75zp3s+tNOxKY+TjXtp/CZm7zdcYqarqdMpsmI5JcVqqiXrVUJ4aMLJDzIyRqqyyrBB6kBFg/8bH7+hpk8h+OK6ui8DkeyScrc5GfZ3YMwLjZJm/82SxF9kTOtPS+6AzHWC4mvb/houxR+FZZm02+3adydalxbfMGkU3cGA27RPjYpItKHnjjpLk5PfPe6NQdkuzz8qhfu71xeUqlzv1Pk39orEWxBNKG0uXR+v/CP6pje3iGdsnFiZkwe2EgHS3gwGGOR958K9dcIp/eLWBj82IFWz/BQSP1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3IJQRROQVo4T61y78HYONadU/HvILc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6cf3985f-7eb5-4e72-b72d-08db2e96f71e X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 07:43:32.9952 (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: LUttcXb5ICrWhsGlAjS2FAgjO/YpCteROba6xVZRS14WGEHlE/WS1O9kDpvwHTA+OjN5fYv2UvFbH5vpmBuByg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6728 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-24_11,2023-03-24_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 spamscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303270062 X-Proofpoint-ORIG-GUID: 9XbTbSQ0qYGdemeoXesCEEX_PvY5tei9 X-Proofpoint-GUID: 9XbTbSQ0qYGdemeoXesCEEX_PvY5tei9 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 Acked-by: Douglas Gilbert --- 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 6e40e9253393..b6e5b1f2a746 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); @@ -6431,29 +6409,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; } @@ -6882,7 +6849,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"); @@ -7520,7 +7486,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; @@ -7554,9 +7519,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))) { @@ -7567,23 +7529,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 Mon Mar 27 07:43:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13188698 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 7F56BC76195 for ; Mon, 27 Mar 2023 07:44:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232842AbjC0HoQ (ORCPT ); Mon, 27 Mar 2023 03:44:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232729AbjC0Hn6 (ORCPT ); Mon, 27 Mar 2023 03:43:58 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0F7A5260; Mon, 27 Mar 2023 00:43:42 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32R7UXru011933; Mon, 27 Mar 2023 07:43:38 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=nDoC24lVfShOVXR9i3dk8W6SQsGYGg1ltJYLMJanUDQ=; b=ARi7pozybbhOv1N5ODKahjXKB4Uk5eLDXBdXPt9b9wbOxSqmYhq/8c6mOsqtg6czr/8y WD3LWs09j0oLGMgqHi+GjdW1h+WZOAcQeI8UqL2pyaSaBpKbErnnJrCMjCy5VkHbcDK7 ZSn6ksBiW66gg0F9Wngc5NoPhYnKmUpNwBD46dCGjbe7V1OIMjJcGdALyuyiHHnaZ5op lTm2Rrbzieu1C+1Ne6ScY8HoUgHOUpEqeqpcI2JQJdCVgd6Xe3zXIozegeQSaNsJgyHw ll518HRq0E6JzXCGRSh5CgieikP9F82RwXZBVwfDLpk1J65UNdfOJbxcFBqUPQZxOtbG tA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pk6t581q9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:37 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32R5wg03005499; Mon, 27 Mar 2023 07:43:37 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2045.outbound.protection.outlook.com [104.47.56.45]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3phqd4d5j7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 07:43:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dQaQOnjkbKw3k+/TFvaTQijPEH+zY23Js4UiTdFPlYPypb3wwXk9f/KZHFMWDMCAeM09CVRya1SK3OJ+sQ2/YlnoEyRELSQfnXZ7lErAK+HU2PcZ9H3eZ8YMnd72rirBDixQp67AlW4xI1eouLctW5871LsG6LuBp2WhVAJr/M6V32aAgJhut9uln7Py99TExNnSEsWzU23UIXJC2XQ4DNgr3jjaxmQ8QEmrWo+yydLZ5X9jl+yJuIN61GHU231s1N+ct1zkNKBG5032gXVwNYqSdJKi3qwaEfYSOciJSAHW+1TiDz1Vcr4o/QCgRU47tS8MtQRuKnLp2XR0ZM0cBg== 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=nDoC24lVfShOVXR9i3dk8W6SQsGYGg1ltJYLMJanUDQ=; b=b3MAzIBRdc+wVDerYsqR4+Qxr9pnyEi85nh63YisZ6KyXaci1C35T71Cqxw3bwglcvcHej+9F8Vo7G2SUNppcEFHhk01CSf45GhLZpJQk1QqBIA8kUHQq+8muCYAKJbJGTp2SshDh76Z6U5qdhh1YbYLaI8wSwEBjqZQWIi4Pnc7oobGvSjnOmzSiYLK3SjLDbgDFcmTAMKZ/Ie4mJ7E4deSxgA7jbQaYHZk8d90KfPulpPS0yuqqWqy/HmPuKjYXzjPPv/wx2HfgmJaDi5pfSYBpzAZMTp2m7folo6otGnJrEKAT+HeJs4+0GWwaJgpxiWyHDimg7yZ0k8xcia9/g== 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=nDoC24lVfShOVXR9i3dk8W6SQsGYGg1ltJYLMJanUDQ=; b=vm1GMVX4pAid68h4zXlsch6uiakZtjJUuAzln13ntvGlkFzb+3gITOFf8tnMW9eJUUew8q/I4QiwUE7sfmX2zAsHzamoJ38VN5oBYeXhhs/HsmhX3TDb5A+9bvQFrzlt+QupXxorpqbTJwEl4qt19hnUG7z3dVBvB6Toso31eRQ= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS0PR10MB6728.namprd10.prod.outlook.com (2603:10b6:8:11c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.41; Mon, 27 Mar 2023 07:43: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%4]) with mapi id 15.20.6178.041; Mon, 27 Mar 2023 07:43: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 v3 11/11] scsi: scsi_debug: Drop sdebug_queue Date: Mon, 27 Mar 2023 07:43:10 +0000 Message-Id: <20230327074310.1862889-12-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230327074310.1862889-1-john.g.garry@oracle.com> References: <20230327074310.1862889-1-john.g.garry@oracle.com> X-ClientProxiedBy: DS7PR05CA0006.namprd05.prod.outlook.com (2603:10b6:5:3b9::11) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS0PR10MB6728:EE_ X-MS-Office365-Filtering-Correlation-Id: ba0b4ced-7563-4234-2009-08db2e96f806 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ky43UUNCbFBPWVwMb1hVelU2AJO5VrbmyXDP0EGWTITmdu6HDIcqfoorcO67AR1TRxlMNnCb09g2ZhERMogZqPdLQAOMHNKZecgovjoQ6owfKXpwB2r+CK/K/JXZLFQjPS3Ht+xn9t8qlvF6KeQHq9dLNfgnzw1LZctVJTu56lCEEKc+KaBlLBWiJuDSAjCyjrw/4GpbTUO+q6LVyR/TeF5Aovf3ccN7ZWIEmLH3dEXuRVlreinDbrvBPdumVpAgbA6TDI2EqT9ie9NvSA32V9zD2yHo2LACOAbQ+duhCWJuWNK9v+Vl/QlVA8FFr36jm5esbXmqQ/HuI2Aj6hDI/MLWbjiBtq6bES/so/kmN3WhwNtLzh4mbFO3zs9dxjHiwtUTPVQ+izmXVt7MushNHkPdzwbiJSGMn2xVJ2zIWS/BpIck7jc+G9HjZ3ALxseP86ypm+JyJk8bqIHOhCuZu0wzH+uuqqi7AXa1NO31Z+xGD3fqPxCxvfLoupiFI6EIqeY5p/vs9+A4yDAtUg/jJqhLTdtcyEhzp1rcgZNP7HtMou4T/3buqsGAIiC5nltPJptC7YlbuIDuLgynRWH6k20IWcKW7cLC8o60Mm/yzy8= 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:(13230028)(39860400002)(376002)(346002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(316002)(186003)(8676002)(66946007)(66556008)(66476007)(4326008)(41300700001)(103116003)(6512007)(30864003)(38100700002)(2906002)(1076003)(8936002)(6506007)(5660300002)(83380400001)(26005)(6666004)(107886003)(2616005)(86362001)(6486002)(21314003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uOksgQ4ECDkxScc6wqp4cO7DVVUbQlphfOLaHYPxPmdHttHcwypzuthAzRUhbXzyi+duXP6FQ1b5GRTb2ixAi6CvQiTgKYJMQLqupoQwpyRz1M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AAQ4mWKerPCluHvw4VJOqXFRsXZI2xjYlzKIAWfy5FxM9N3pAwS0GBjViKJr/OZYz7hW8ri4I8jQGrgQK5lHaAaH3SKdI9dBuIDtLUih3GEE8TBTd/CMjydvCRDpJkJAM2epHwFK61RWpWEG3rl5tGHGRim1PYUTZSSqsAZ8jImd0sLA78H5hvb8bAwEVuXz+HkEturHxCBmhXYoUJbyQWgR0E5wJV6XoAAPusuf7biYhxgprxvK3EIvsvan6QiSTQCfppypjOAb4d4LdxCp+6eJ92Y= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba0b4ced-7563-4234-2009-08db2e96f806 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 07:43:34.5273 (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: yAAaIJ8vxIEHraM0+u9V3At32Tn6NT4gUZ5XdVC9paaU+VplOlkp4nzz+8ru1N7OonTNMzk5L9DiqVbNhiS9xA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6728 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-24_11,2023-03-24_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303270062 X-Proofpoint-GUID: sIlN3UnDFsnxCnAkI7fegMAJBVLDb6yW X-Proofpoint-ORIG-GUID: sIlN3UnDFsnxCnAkI7fegMAJBVLDb6yW 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 Acked-by: Douglas Gilbert --- 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 b6e5b1f2a746..c1706b9dabba 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; } @@ -5559,7 +5507,6 @@ static 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; } @@ -5578,13 +5525,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) @@ -5596,8 +5541,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))) { @@ -5616,33 +5559,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(); @@ -5689,10 +5611,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); @@ -5950,14 +5868,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); @@ -5985,11 +5928,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); } @@ -6944,13 +6893,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. @@ -6959,10 +6901,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: @@ -6974,8 +6914,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) { @@ -7022,17 +6961,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"); @@ -7089,8 +7025,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; } @@ -7107,7 +7041,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); @@ -7483,10 +7416,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 */ @@ -7506,9 +7437,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; @@ -7519,16 +7448,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); @@ -7548,20 +7467,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;