From patchwork Thu Mar 23 09:45:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 666464 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04F99C6FD1D for ; Thu, 23 Mar 2023 09:46:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230367AbjCWJqt (ORCPT ); Thu, 23 Mar 2023 05:46:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbjCWJqq (ORCPT ); Thu, 23 Mar 2023 05:46:46 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59F0B244BE; Thu, 23 Mar 2023 02:46:44 -0700 (PDT) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32N5i4am011361; Thu, 23 Mar 2023 09:46:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=GhRMO7BnK6dQXX6z1oxGtvLvbEdp7/H2MMrMYl19yOw=; b=vucIeaV0g0FSP5Vxi4uxaceyzdwapi8sKhKTNA/Pkd5ELHhYy7w4v34JpCZeCBY66GmM 9N8EeUuQB9aKe+rFDXM91UbXgvx2zFhU7K/GrsTsTqCAuS1lA23DdrY8CgZQjfYO0tbF 2YHrtlAhVRpCrJ6D+z0ysCLbjmAhBDeF5glf4A45j66PGenQQ1P0x1HjWvOvKbPfV/Ei vRw6guMyIXqAkRXg4BzcuhMRyvbW66UoYzVbKnX1IARyHw6pAbvrE3c94wloLM/1XZq3 NqQ2dclzQhOgNX1ByXCYA5Kgh+Y7PWcBS4DemZAOv01mKxeyTWqcK08H+uuQch5z2/5P Pg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd4wtb7pq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:39 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32N9cdiA006987; Thu, 23 Mar 2023 09:46:38 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mq6emKv7zqdOuJNbxGSEuaY63PgDNZG9ETlTeId3Wu7KappGn+p25zLKkRAv9KDFuokcpsLvxyPMVC5ZpRfb1fNu6HSr4F9X86LpcBZaO80VKdUoYaQ3xNeKeZlX9xPFJDQmBbPVeryiYEMfCNgU648NTj2K7T6It+XEb6tAf9wER0YzLYVDZtKjhxNCuT6ZmdUOYwsKNwOJj4HoS6keymush9ho2YLyg4kuxmonPQ2OVQx1AD7+ZJU9yqPr3Sw4BaXcYsyQ+UbU+UfXtWtsTCRwU/oQmlmHrj7Nw41Zz232DVX89OS+EPF5MXtcVH5q5rbetEE2xMD03Z0XQ0OiQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GhRMO7BnK6dQXX6z1oxGtvLvbEdp7/H2MMrMYl19yOw=; b=FbJe1l4TixlLHtz/TKV/EFXeLU4HG44mInWcYklfZK0hjJTarPW4kwMtyiZWjvWxYqsys2EEZtu8sKN4rLZP6EQvoPzaz2ypZ8vW85roUPaBOLj37341+gXm49NZtHxvGdR47t9+fVKtKzxYaPkEw57LKAWo29Cbtmxxauxhu3B68lPtbJk/3So7QFkKF8IsGZU06RCOrKlRoYeVsYSQ3/aDFziNazHDjxX6RYfv8bYYXCeSyVmW7YIXze6f/DvQMR5P2Z1mr+UApUqrMVJf6uFygTLcJQzFY6dNBVX6Pod4Xl6LMwywISOYFnChbVxly4L36Ofp9stWPGi17qoYJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GhRMO7BnK6dQXX6z1oxGtvLvbEdp7/H2MMrMYl19yOw=; b=KI+OejzexsB3Frg+2ohZmhzOcoD0n2bwBeQL8O0HQ290FANDLFBNMo7aO7qKxCI62S+5CD+oCWMZSMyjecOBtCaMZeLe5NSpD2ljxtZlh790ygwDMGf8hqUaAQv7XNPsRTe/l/i2itl8KPl1mCL02qHc8uodfkrtDuVfGVhPDQE= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:17 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:17 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 03/11] scsi: scsi_debug: Change shost list lock to a mutex Date: Thu, 23 Mar 2023 09:45:47 +0000 Message-Id: <20230323094555.584624-4-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: DS7PR05CA0102.namprd05.prod.outlook.com (2603:10b6:8:56::22) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: 60a82656-5b4c-4719-61c1-08db2b837303 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pe6d+UQpkkDmOfLpCIztb6ADbkL3rZ7+xvl7azWn+zC0Wlt5SzWFpCfgn2+mOPZbktMrooSb/yCdxNJpgKd52BlHN7FWQbYEZyT3BSJ+yR3DhV/paKvSj+k5WXcuyudfBflLJWFzewsrUdLWE+XwYFa8Gw/qI5CK5iWXb534EpXlAqBejY8BvS8SSw/0iELETQQTFoLBYp0NZmSI70iQ9rqTHOSoSEGc8c/0DfMc2465UzyBUvvDSCFXeBoJCMaw4JOshEMGaPqCJhmFROtvoUFWs+Iu7toEBMw6QziEu/Ixny41mJz23nRWY1Nf0JzPTGI+pLDEtwyyjb5bQyQeIGhMgO5+0totSbOFE5cOrW/Y+09UL9OtptNvisiU2lJYyhleKtDVJ09ZIQHbW93mgWQ48JiD5JdB/91Q1Hvhr3oayCPGF9WrLUD9irmAIDFexg5kGdOUkGmUASVKZAJ5NWGkLdI8qUBRQv+8i7azJidXWfR55AzYWfhzPHKAtwFVX5IXW+vXk9CykWdrTZ74OGCHVpqZx7T+NdFZgLgh+2Fbpjw22wZR6FPdKwZLrwp+oNArfJDfOOPwAMm+aQpfVNf6+AFzpSRV6/T9aWM5ESMUt97Y47RKd0aORhqGWvKR2rD/PQeDpO3M+02c+RadkQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR10MB4313.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(6486002)(316002)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(107886003)(66946007)(1076003)(6512007)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ya0nQ7eqq9nqzBhsEmprSKxQmzOOp+fQUHcFV7qHJhnVilUfPD4DHTOdf0MEpOcnPmaBgAEm2ZHaOf970k2inLC/hdFRNCGyVNbyD8JDeVoY+nvqmU5bUOEtMIBwhgDp4482o2rix96CKnfKsclva/Arl/i7s5YW3ZOvSXxUSBiuWJUXIfwSmRaZZRpKyE5ubS/wbP+aBO8xtdfs2uuJA81WTlq/9kzo1IUC79gPwE1ReLO8PEbxpjDfIDY9HGvgrDUjuTp2wJTaraAi/G2+zOpgal60+kUw9xMf0OefzvwaE8dI1lwMwllN7v2qwvwLW/9rQfDUnlnOxTtv296Q/PZsLUL47VNG3YsDP3g1fgcr72ervZHY8yukgepT8xnD1RNY0duaiv3BuWvc6q+mbkI6qpQLtDzoxoQZcs5mW/Rx/UhfAJ4D9/YBBgoGstMPt6ihAiqrWsKgsx50Eje7qcgZREZ/euvShC/Kxfkpfa3bDtdKgvnkwSsIUba7vipLZ8cyBwp7SnxFkqb+gIg4iAgFzm1NWX+EMJV7SGKg/48/hrin6GaBopKUCIX8fSflXWLgoFtPDwncJN75WXD9QAfEB9EvghhJ24Li/l+doNAus2v47nRdMq4RXa4zRagTWtt6X630bZkw2ieBQ2UDnQeoK8gbq/mhVYmJcBsydjJGxBlIsm/A7SUdlTHxKCCsgMwH8PcjJxKvRrrYdbaNCLPjxhxUV4cHZVmya5wsGeGgUk7Nw/NgD8bwoChywRNRxQhcE2DpSbwDv2X2cEN5Fd5Kx6Tn2k2buJzacfAgKIb5g7P/hj4Ow/cj0ewELamFIw58FkeTwp35KB5cql5EdJb2yxIq/JSwgOBh+/HDAcSBK5/kFQnQWyCx+eKThDRCLHFP/zkyUUHRVFCga8n+2zcfzeieycSntpgw9DVcRKOA6WmViLeR1NIQstXM88aPs+bsgTI/BlMlf6BJxYvVdrP3dEnX8ptGPA+n2dy1mQTttzY4MZ3NG3Lsr6u4RFVWeMjY4JGe7wjP8p1B5zqJ/csC29q8O9f1/9NsX+CHvQ4nKUbmqhy56eNL/ijbNEZQRjHL0UqFyxedeJ9t7UyZv3cpFczjZ5uTvY1e7BKOp3M5F0C8BROaOQSxZi0wFc+yHmCTYKTzZl5x8NAPsXBrSgghyipy7KLY3bPtUbb749BV85a1ZVWQbpG4Gnu+MnDmCHlH35HjV6HxiB1WC2ystqLOwqaNWSc01DTQYVjTNJCmzP/T/yNMOLweM4/GVJEg6Pk7IsEdoFoE8HDkcAoELzwi32gSgYjTPDsjqzvFtq6iixru9g5qBnsMlR0JGxzrMHVtGsH14AVv7iDXaEeu+7OjWzLPokb9Zp1NzpzXVkwEvZSLdtHX+KwBqIYyavy7g6t/dPaK6zxdP3Bez8uJVM2aY2ZXQy4GsgjWEY9CAr/Xgd/CkHdpdtspvuRp8eQvZjI5SEDL9qvyE4chffW3LnF+KMawpofvYhJmD+oXhgDjgexeSLBqPvjMXehVURIRFUhwXJGBFLDqekY4pO+hcWvixUWwCRgfl7MU5XupUoyBTo0a91MyIpo16xGMlqQHXhuAvIfbw2afAOWkqT1srg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: xu7h8Gta+9JvTmyvPsA8a2jEkJAhfkZnlkbJJZioVWj8A0ynBnGmtA+FNGDkFo8J1uyEUxkAO4JVpr4VZKxn3LzAtgWba9pvDs+KpfUlqARH6kPHSDS2d0hZgPaLHwA9NUS3oANBjZgyvkTvge1YQIvwc+tF0vkojP5+2duzq2uuwO4+WPyceQqN9u6Raj/DQcv+B2Z0wy32z/B4MNwS4WypNUcfadgz7gprzZQ86QVgZrRgohuz5DC8Y8PcPejZaeeyatTrwUxPz+0o88eshF31uwD3nFU9DrP/5Agj6vZe+cZGJNjnj2qPQSgBBIQq6S/568ZVLXD2+CDIQT1f86ClRTX3zUwov92HfTgn0ROOX96e7RlrEX1VvCasXE13VGXLQYVYtJEOMotPqR5zTglYkHd1iYjsRwKFRTf2K9/1Y9+J9kBvfes/tR2U3Q/85dU0Ay5EP9+tAPeMutDfUD+Lb6yBZ8uWP1sRjf50ojz9ENDuj5hEoaQCYoy3Nt1rrvzSELTZrVKryksAzbgPO1/IRGWNcukBemA4z5FX/aFsa4OVcdepFiKnQblbyylCZMmFR6VoUJJI3GrKwFifF1yfo0vTdLbf2oBnHNzXsMPxu6P9fBodlkTDdAHq1ReL5+tWLH1eU1BdOcbwMumW75t5R9A8TUJCYJrp8EBzvn322Ec8LWfo6Os8MUyZVK2YVZZTd3QHyiauxn2x1dXB/1w0x7pLnFzsFnyf/dTCuNHuCVxtjyAKu7F/SQE2Tuv3tOegWIPxIe/PMPTEuCNyQGCmmLlP/5Gcy9PpEj/5OhZ/PZFDCySYQGLGjyZmvWMzM2PlD+bIE3MpmhTXsLdKNPBX+kx3FzLW0T40S8+gE5M= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60a82656-5b4c-4719-61c1-08db2b837303 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:17.4306 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YxvbViMdH0wLtxAtbs2luT9yLLig3iAualY9MoKr65Qs07VLESFF4mRXSxMEjrmbCo4WbQQjbnfKHp921eS8KA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-GUID: IudMzMNwS346n8xCa78QHSr_D7rsRokm X-Proofpoint-ORIG-GUID: IudMzMNwS346n8xCa78QHSr_D7rsRokm Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The shost list lock, sdebug_host_list_lock, is a spinlock. We would only lock in non-atomic context in this driver, so use a mutex instead, which is friendlier if we need to schedule when iterating. Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index eba6eca81e84..a61e7c31dab5 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -816,7 +816,7 @@ static int sdebug_cylinders_per; /* cylinders per surface */ static int sdebug_sectors_per; /* sectors per cylinder */ static LIST_HEAD(sdebug_host_list); -static DEFINE_SPINLOCK(sdebug_host_list_lock); +static DEFINE_MUTEX(sdebug_host_list_mutex); static struct xarray per_store_arr; static struct xarray *per_store_ap = &per_store_arr; @@ -908,7 +908,7 @@ static void sdebug_max_tgts_luns(void) struct sdebug_host_info *sdbg_host; struct Scsi_Host *hpnt; - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) { hpnt = sdbg_host->shost; if ((hpnt->this_id >= 0) && @@ -919,7 +919,7 @@ static void sdebug_max_tgts_luns(void) /* sdebug_max_luns; */ hpnt->max_lun = SCSI_W_LUN_REPORT_LUNS + 1; } - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); } enum sdeb_cmd_data {SDEB_IN_DATA = 0, SDEB_IN_CDB = 1}; @@ -1051,14 +1051,14 @@ static void all_config_cdb_len(void) struct Scsi_Host *shost; struct scsi_device *sdev; - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) { shost = sdbg_host->shost; shost_for_each_device(sdev, shost) { config_cdb_len(sdev); } } - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); } static void clear_luns_changed_on_target(struct sdebug_dev_info *devip) @@ -5423,7 +5423,7 @@ static int scsi_debug_host_reset(struct scsi_cmnd *SCpnt) ++num_host_resets; if (SDEBUG_OPT_ALL_NOISE & sdebug_opts) sdev_printk(KERN_INFO, SCpnt->device, "%s\n", __func__); - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) { list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) { @@ -5431,7 +5431,7 @@ static int scsi_debug_host_reset(struct scsi_cmnd *SCpnt) ++k; } } - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); stop_all_queued(); if (SDEBUG_OPT_RESET_NOISE & sdebug_opts) sdev_printk(KERN_INFO, SCpnt->device, @@ -6337,13 +6337,13 @@ static ssize_t lun_format_store(struct device_driver *ddp, const char *buf, struct sdebug_host_info *sdhp; struct sdebug_dev_info *dp; - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_for_each_entry(sdhp, &sdebug_host_list, host_list) { list_for_each_entry(dp, &sdhp->dev_info_list, dev_list) { set_bit(SDEBUG_UA_LUNS_CHANGED, dp->uas_bm); } } - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); } return count; } @@ -6373,7 +6373,7 @@ static ssize_t max_luns_store(struct device_driver *ddp, const char *buf, struct sdebug_host_info *sdhp; struct sdebug_dev_info *dp; - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_for_each_entry(sdhp, &sdebug_host_list, host_list) { list_for_each_entry(dp, &sdhp->dev_info_list, @@ -6382,7 +6382,7 @@ static ssize_t max_luns_store(struct device_driver *ddp, const char *buf, dp->uas_bm); } } - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); } return count; } @@ -6489,7 +6489,7 @@ static ssize_t virtual_gb_store(struct device_driver *ddp, const char *buf, struct sdebug_host_info *sdhp; struct sdebug_dev_info *dp; - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_for_each_entry(sdhp, &sdebug_host_list, host_list) { list_for_each_entry(dp, &sdhp->dev_info_list, @@ -6498,7 +6498,7 @@ static ssize_t virtual_gb_store(struct device_driver *ddp, const char *buf, dp->uas_bm); } } - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); } return count; } @@ -7258,9 +7258,9 @@ static int sdebug_add_host_helper(int per_host_idx) goto clean; } - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_add_tail(&sdbg_host->host_list, &sdebug_host_list); - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); sdbg_host->dev.bus = &pseudo_lld_bus; sdbg_host->dev.parent = pseudo_primary; @@ -7269,9 +7269,9 @@ static int sdebug_add_host_helper(int per_host_idx) error = device_register(&sdbg_host->dev); if (error) { - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); list_del(&sdbg_host->host_list); - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); goto clean; } @@ -7311,7 +7311,7 @@ static void sdebug_do_remove_host(bool the_end) struct sdebug_host_info *sdbg_host = NULL; struct sdebug_host_info *sdbg_host2; - spin_lock(&sdebug_host_list_lock); + mutex_lock(&sdebug_host_list_mutex); if (!list_empty(&sdebug_host_list)) { sdbg_host = list_entry(sdebug_host_list.prev, struct sdebug_host_info, host_list); @@ -7336,7 +7336,7 @@ static void sdebug_do_remove_host(bool the_end) } if (sdbg_host) list_del(&sdbg_host->host_list); - spin_unlock(&sdebug_host_list_lock); + mutex_unlock(&sdebug_host_list_mutex); if (!sdbg_host) return; From patchwork Thu Mar 23 09:45:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 666460 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66495C6FD1C for ; Thu, 23 Mar 2023 09:47:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231201AbjCWJrG (ORCPT ); Thu, 23 Mar 2023 05:47:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230390AbjCWJqv (ORCPT ); Thu, 23 Mar 2023 05:46:51 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 117F724713; Thu, 23 Mar 2023 02:46:48 -0700 (PDT) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32N5i64B005171; Thu, 23 Mar 2023 09:46:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=csfUpvnydue3c06Gn5zRcv10idpsejsfMA3qvVv5VuA=; b=JF864nGsQYEheehAf5jiFRlTA51IiJcy80n1ehI2/XVxWvftEauZ8oOo9RKuLkc2qBDS V+KhnEyFh1ki7yFFxMK16SbiHetZCeLOg+bgPJsn/rmUApp5E0FR3fuVihFW8cQ/f7L2 Yps5Tq3gY/B7lw9hrtWFYLzajC8xWbJXLIkakMtSgrkToi0EzbhHQ9j/M59xmOENJ3Cc Of9sbZa8s5ar6B1qX7rFYXO9X+u2Nct6Nc1s3LMt9l9bkAeQ8SihVI49JJ/D861Eb3Z+ ASaWFcIq0QpyHOo5jT7dfaZaxNzdBmf1AdInS0JlVYUe8atiDja2Sv5vMjYhsygZjvmb kg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd3qdu3yb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:41 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32N9cdiF006987; Thu, 23 Mar 2023 09:46:40 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nGsCgnSwrZA/gbqGKXNXB56zurH60jyeO9gVuTx/Jn030UlW4hHADfisGhx9o+40EV5MCn3WLl71bGQtV8CltgaadTOMmJj6Ca5hvIFRjczztAwFzS0L0MJ1mRvh9q/iDfgafJJezeFNDyQmquqhCfc0H7yXbh07FFbNbJNQoSGfmT9A/uHsWmODo8f9wtLNgvhaYMIXuuNUcngYhwPAt35NLhEeciI6bSA5NdwdGa2vN6NFBQrp29I4M8yql0Fgt2GY4vMEKcAPvd3hqiZ818G28s0QmhPLYcoe+tReYvrLV123Orf6RcAY9AgvKKpv/xU3f70oB5d5DlGhqjWeIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=csfUpvnydue3c06Gn5zRcv10idpsejsfMA3qvVv5VuA=; b=abppMY43BUR8ow4n5d65L+gYGl0rDLu6u12Nhu2/PTTn+K3lJUGOfLJInMKdVB8RLorBkQMWwL5/eRWihjU0bDSUksRjW0MlizzR/RfD5uvleyQlV7GNMbmMyAMecR3tBCuvdHmGxh8ImgCPegxqy2St8OJPI6BA6Zb+9A1+r+4Fvq4nhri+57O+lw+9KF2VmkWpDDTc4QbtoHgLep03bSgkNPDCS3WF9ulsKKFzsARVySlzik7Z6x16IWo4Ye4UmVBbDLWLEWa76rnxk7ajjl1AQ7100M+41Genc2MYnOWFcdk6KSqvIUBOwBtvufb71KWGHHXZ3jV2zy6Bz71PBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=csfUpvnydue3c06Gn5zRcv10idpsejsfMA3qvVv5VuA=; b=ajGpBkq2ltGyBY8+rLgVo9uE0vjw9JSoK8xUs/NMgQH0YGZy8/6GPrSeBekouut0ybas6p3i4zprNNW1DpcXvoo7SYGZNM5L5ESXUSNXJJLPY1CSS662RsT0QMlNDauT8vhkoqk7fsi7KW4Lx3Q/h4qbyjP1N6egGx2uyzftIUE= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:34 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:34 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 06/11] scsi: scsi_debug: Dynamically allocate sdebug_queued_cmd Date: Thu, 23 Mar 2023 09:45:50 +0000 Message-Id: <20230323094555.584624-7-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO3P123CA0005.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:ba::10) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: 44de09be-26ff-442a-9adc-08db2b8379df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Har4RembVgmSXYd7HohqFOQt/TJV9h/xIr3IhOSDieEkvqiYPkJVKNaNcJW5uqPUEOnGtli7cL8Ad62WWqw4ROinCa4qkQ7phW9uD03pYFkEKQQ6R1bgWvZj1w6QGsvhCNrWaaCJ18hhk4zseyAft/BhCeh/MOZWyHtCLC1QSrnNKpDpOxizpyULn4lT9pvgPN82prUslPB4bu6N34IYN92SzQ5PqDjwC25bP/9vkOcwmPgcxPkROQyvNQI6nuYrq9UU4uumwtGxCjViFUIXSfy8sWDVyO6H7qutRJ4GwP3Gs6OS10/1IqQZ2AVbg2heY454undN3Hz5vOstkbfalzGKJrN9Ov2k6PiaoZDpsJJb8+EalR1MHCKuT+vIT3ZMh3isz0vMp5hvcg9WueS9ObFl51s2bdw/OfQJlY/4OqLbhFG3LFm7tqyTbL9auKTzb8KBHKSSrS3pMsYRz+SL+8K14Ojn+GsiM+Ga6BN28bRHKtRck2SmuchR2wRAridm8sdZuuvwIwC3EDkW4sdYfUp+luQxGAnUhwT+CBnGONy7/6QI/EHQLLxa0G7KV9DWtmNtL51tQTg01NQbYppGUY1JIDtnpQ23wHr/qqS8uX59v12OOQGl5tPqwu3K8nQC X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR10MB4313.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(6486002)(316002)(66899018)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(30864003)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(107886003)(66946007)(1076003)(6512007)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Zg9svyiH5IkW7kH5xxDh03MRaINZuP7pMthEoV5VUMJCpL1ghBf2LUzBwa34enkBjscOReI5CU9M5hMwjQiyxojd8L5QygN2j0GTqz3zJEzhxkB6J2f15IUBQFC1YZ/WRlRNddgKpELkIcYMXBMLGWo9voeO9Oolhui/he5l7lcTXgIWpBEPWDo8d43zF3UGx8poxiuzviIhXenaqxo5pO9ND7V0jMkoxtTBf1e8CFaoOBGPhVgIzscxw3m5BnN5zdanJwb8xzPmNcETwNrSiCs69u3cBhyW/P9CrAs4se4jmzzvH4mfa6fMZVtG+f88mHmldn2KCwNtYrGpu489qV3j+kj0rl6dUbjPAS/ZIPANMPRvwU6+LJlbJnF96Yh8Wy0x9qYYNoRZeoSY10vE7moKuv823XsTVUy2+fOYJ92CcqbZFbJWwloDzJGr4vnGPKvQ7z1A0D8iEzlAnPluMMGUA7wTxHmYburshqSP67MCAW3xXTavYLejul9BUW/60YsqzYmmgdBB3UuSc3To4HUkeZXrvrQlT5Ng2rJr8ZQShoHa7h5WGe0mGgz7A7PS2mWNSWLbErDn3topLeJua59b+Hlv5suvvInVvHlVqSsWtI9lcGX7CnB4YQhKOMbRUFDwFZ8W6bzcB0IrMoNumcNBSI9OdNirvKNRttIrr3EhWO4elllI3Pq80Q1h79ds+swTX5JRqTjNdLXm+rD4NK/UUDqnSh0H0POo0PnZRzUiXpDx9zG5PcTT4nNmnOubdJ3HYRJJxkPvBrJ7k34fY8iN9SR3enNnn/uI59aChLcfuOT+B0b1huxC0VumkfTJbKoBLP8xzcs9aiZTVLsAQ8FFf+QtdIDSbaDXHmymtkbipIoLEmCd66Jf72iDomiKs2ri7E0toD5epZQnp2H5FYkDlxWyJk5jzeA8zGnDD/62/CcJB5pM6T9KWHXQLMR/79MfKU9zdhKpbRU/Fykmg/EHNL6nWpbPStWBi7qJaXSsUnCrV8JZaecaoqE1S84hQf8E6J51hQj07EDcu0ONFK6a75NnuzfwnnPEHrXcyX5OKxM4HwWLPBt6qAk/eSLF1LIloIp+aQXTfiVHJSXRiErj3ns2l9WUioP2UUcFK6qE8hcRqg9OP4kg0rTQ0L7l8uOJC1fsmQcz91uTAhwHUgD91SGc+FSfNELd3q1xdsgxLW7Y5B4xe87/TyBLSpadTWkur0RBRmHU0G0rH2uGPNQMV37hGtjGB7dPCj/5Xyo8KxEYpOFDAwijh1dUQgiQBYi4ka2F+MEeF8S12nRrJvNZIE+vF/69+G4cCvVKVT+VOmD/HCeLExJrZSOurGtSrmp4kmXSqH8ISevBZK56DLeqTVdPEVMHFh+AXmuNr6lB49nm7nSZirwzy2gorFeGz3gz1Qo1wfq5Em8X3VfbPuD6tTQyD6hgyg2Q6aoLuiDlVcJnJlinY3Eb7DKmZBvhIbWV4k6ZYstUXFIHuW0i0bpAwT9lDiKZ6+tQRfFczcdPGddVB4qWosHl7sxirQq163/KdhmZdoln1MVk5YF4uclMWdSEI8FT/RV96G9zSeSs4U8p7pp/evL87DIQ8VzX10k4DD7LaqdpaQy9EBw9QQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: fFtiPIakjYutDjtAkYXsKGO3+XaWs3Fgu36JVaVmU2tBdnrCAu59BGGJKIV+IUX0UgPlzktEOGc4V9kMtx8aSunoAhbPOQUbNs3TpICuQ5NKntr8gZ0AlUpfcLUZAkyikfJR2JKya9cm8DyKf5dzTSxxDyywdK7aP4ZQI4QcO6AiWj0qTcJ/cXkke0V4g61rU1dAljpKmiqDN9QU6mqN97MArtW2s/qQMSgwu3IZImoAzPo/0UYGlnQrFJRnVxtF+wEWlWwTguqpmVjQhfXyj5qXUewIOC90qNElUyw/Oy+muvthjjUAmTE01aJvWbtu1tcqgnQV/m0P1W5BtAVOz2xWtlaDDNtxt+cqczLzy607ziBqBGZ0ceoeO/eX6i+AxPWSM55Q1Zq4Tk9ATs7aexzxgXsNmmmgLpI1nlNG32A+GWFL1ALzFmY/SLX80Hi/WU43U/X3xdduqIiFz4VZxNJTCRfOOHxxibJELZ7gs0wKLHJM7181OG1aGjK65I9J3dGXgr2065DBU/I5+FOcagfCtu3ABIGPUaOx3mEeB3QCs6gp9L3UEwG1oJ4jhSm6u7aqRIJ1mle7zwpb2vy8ELDUk5E+kYJ8/1pJr9OMNUR4eB7TE1hRO7ExMPMiThOFhCMCSMb7mSyI9PZbtKoOBXE/5cFdd01sXgdsp9YQ9znA2dKJHHnaZ7XEBmih0gbUjwUZb94u/4WwSjQRL4TVKnAicdfPZ8zSsP68vKqdks27G642Wnp4cGV4iQ2+hU7ReLXp3/VkhjO4GUBdIM4xIr5lue89hgBinZr1EUQUOS602wiiI6qoE8zTinqsEIEwquL4WIO86TB/py1b6RsJ2N+01FxvaKsUjK1ZarWQ14k= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 44de09be-26ff-442a-9adc-08db2b8379df X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:29.0495 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Z6lWuSoV00sIXC4cvQjIky0YZw8eq9Stxg1k0dKllNrl8uItkRNvP7XzYbAZvHnjzE1Z7Z/LZXgiKkWhQ8B8iA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-GUID: 0SPmGYgqHW_V3uvCUuv47JwPdD-tYmSy X-Proofpoint-ORIG-GUID: 0SPmGYgqHW_V3uvCUuv47JwPdD-tYmSy Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Eventually we will drop the sdebug_queue struct as it is not really required, so start with making the sdebug_queued_cmd dynamically allocated for the lifetime of the scsi_cmnd in the driver. As an interim measure, make sdebug_queued_cmd.sd_dp a pointer to struct sdebug_defer. Also keep a value of the index allocated in sdebug_queued_cmd.qc_arr in struct sdebug_queued_cmd. To deal with an races in accessing the scsi cmnd allocated struct sdebug_queued_cmd, add a spinlock for the scsi command in its priv area. Races may be between scheduling a command for completion, aborting a command, and the command actually completing and freeing the struct sdebug_queued_cmd. Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 426 ++++++++++++++++++++++---------------- 1 file changed, 252 insertions(+), 174 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index f53f3e78aaa1..6606e71cd0a9 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -250,6 +250,11 @@ static const char *sdebug_version_date = "20210520"; #define SDEB_XA_NOT_IN_USE XA_MARK_1 +static struct kmem_cache *queued_cmd_cache; + +#define TO_QEUEUED_CMD(scmd) ((void *)(scmd)->host_scribble) +#define ASSIGN_QEUEUED_CMD(scmnd, qc) { (scmnd)->host_scribble = (void *) qc; } + /* Zone types (zbcr05 table 25) */ enum sdebug_z_type { ZBC_ZTYPE_CNV = 0x1, @@ -337,12 +342,8 @@ struct sdebug_defer { struct execute_work ew; ktime_t cmpl_ts;/* time since boot to complete this cmd */ int sqa_idx; /* index of sdebug_queue array */ - int qc_idx; /* index of sdebug_queued_cmd array within sqa_idx */ int hc_idx; /* hostwide tag index */ int issuing_cpu; - bool init_hrt; - bool init_wq; - bool init_poll; bool aborted; /* true when blk_abort_request() already called */ enum sdeb_defer_type defer_t; }; @@ -351,12 +352,16 @@ struct sdebug_queued_cmd { /* corresponding bit set in in_use_bm[] in owning struct sdebug_queue * instance indicates this slot is in use. */ - struct sdebug_defer *sd_dp; - struct scsi_cmnd *a_cmnd; + struct sdebug_defer sd_dp; + struct scsi_cmnd *scmd; +}; + +struct sdebug_scsi_cmd { + spinlock_t lock; }; struct sdebug_queue { - struct sdebug_queued_cmd qc_arr[SDEBUG_CANQUEUE]; + struct sdebug_queued_cmd *qc_arr[SDEBUG_CANQUEUE]; unsigned long in_use_bm[SDEBUG_CANQUEUE_WORDS]; spinlock_t qc_lock; }; @@ -508,6 +513,8 @@ static int sdebug_add_store(void); static void sdebug_erase_store(int idx, struct sdeb_store_info *sip); static void sdebug_erase_all_stores(bool apart_from_first); +static void sdebug_free_queued_cmd(struct sdebug_queued_cmd *sqcp); + /* * The following are overflow arrays for cdbs that "hit" the same index in * the opcode_info_arr array. The most time sensitive (or commonly used) cdb @@ -4919,46 +4926,48 @@ static u32 get_tag(struct scsi_cmnd *cmnd) /* Queued (deferred) command completions converge here. */ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) { - bool aborted = sd_dp->aborted; + struct sdebug_queued_cmd *sqcp = container_of(sd_dp, struct sdebug_queued_cmd, sd_dp); int qc_idx; int retiring = 0; - unsigned long iflags; + unsigned long flags, iflags; + struct scsi_cmnd *scp = sqcp->scmd; + struct sdebug_scsi_cmd *sdsc; + bool aborted; struct sdebug_queue *sqp; - struct sdebug_queued_cmd *sqcp; - struct scsi_cmnd *scp; - if (unlikely(aborted)) - sd_dp->aborted = false; - qc_idx = sd_dp->qc_idx; - sqp = sdebug_q_arr + sd_dp->sqa_idx; + qc_idx = sd_dp->sqa_idx; if (sdebug_statistics) { atomic_inc(&sdebug_completions); if (raw_smp_processor_id() != sd_dp->issuing_cpu) atomic_inc(&sdebug_miss_cpus); } + if (!scp) { + pr_err("scmd=NULL\n"); + goto out; + } if (unlikely((qc_idx < 0) || (qc_idx >= SDEBUG_CANQUEUE))) { pr_err("wild qc_idx=%d\n", qc_idx); - return; + goto out; } + + sdsc = scsi_cmd_priv(scp); + sqp = get_queue(scp); spin_lock_irqsave(&sqp->qc_lock, iflags); - WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE); - sqcp = &sqp->qc_arr[qc_idx]; - scp = sqcp->a_cmnd; - if (unlikely(scp == NULL)) { - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - pr_err("scp is NULL, sqa_idx=%d, qc_idx=%d, hc_idx=%d\n", - sd_dp->sqa_idx, qc_idx, sd_dp->hc_idx); - return; - } + spin_lock_irqsave(&sdsc->lock, flags); + aborted = sd_dp->aborted; + if (unlikely(aborted)) + sd_dp->aborted = false; + ASSIGN_QEUEUED_CMD(scp, NULL); if (unlikely(atomic_read(&retired_max_queue) > 0)) retiring = 1; - sqcp->a_cmnd = NULL; + sqp->qc_arr[qc_idx] = NULL; if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { + spin_unlock_irqrestore(&sdsc->lock, flags); spin_unlock_irqrestore(&sqp->qc_lock, iflags); - pr_err("Unexpected completion\n"); - return; + pr_err("Unexpected completion qc_idx=%d\n", qc_idx); + goto out; } if (unlikely(retiring)) { /* user has reduced max_queue */ @@ -4966,9 +4975,10 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) retval = atomic_read(&retired_max_queue); if (qc_idx >= retval) { + spin_unlock_irqrestore(&sdsc->lock, flags); spin_unlock_irqrestore(&sqp->qc_lock, iflags); pr_err("index %d too large\n", retval); - return; + goto out; } k = find_last_bit(sqp->in_use_bm, retval); if ((k < sdebug_max_queue) || (k == retval)) @@ -4976,14 +4986,19 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) else atomic_set(&retired_max_queue, k + 1); } + + spin_unlock_irqrestore(&sdsc->lock, flags); spin_unlock_irqrestore(&sqp->qc_lock, iflags); - if (unlikely(aborted)) { - if (sdebug_verbose) - pr_info("bypassing scsi_done() due to aborted cmd, kicking-off EH\n"); + + if (aborted) { + pr_info("bypassing scsi_done() due to aborted cmd, kicking-off EH\n"); blk_abort_request(scsi_cmd_to_rq(scp)); - return; + goto out; } + scsi_done(scp); /* callback to mid level */ +out: + sdebug_free_queued_cmd(sqcp); } /* When high resolution timer goes off this function is called. */ @@ -5233,115 +5248,126 @@ static void scsi_debug_slave_destroy(struct scsi_device *sdp) } } -static void stop_qc_helper(struct sdebug_defer *sd_dp, +/* Returns true if we require the queued memory to be freed by the caller. */ +static bool stop_qc_helper(struct sdebug_defer *sd_dp, enum sdeb_defer_type defer_t) { - if (!sd_dp) - return; - if (defer_t == SDEB_DEFER_HRT) - hrtimer_cancel(&sd_dp->hrt); - else if (defer_t == SDEB_DEFER_WQ) - cancel_work_sync(&sd_dp->ew.work); + if (defer_t == SDEB_DEFER_HRT) { + int res = hrtimer_try_to_cancel(&sd_dp->hrt); + + switch (res) { + case 0: /* Not active, it must have already run */ + case -1: /* -1 It's executing the CB */ + return false; + case 1: /* Was active, we've now cancelled */ + default: + return true; + } + } else if (defer_t == SDEB_DEFER_WQ) { + /* Cancel if pending */ + if (cancel_work_sync(&sd_dp->ew.work)) + return true; + /* Was not pending, so it must have run */ + return false; + } else if (defer_t == SDEB_DEFER_POLL) { + return true; + } + + return false; } -/* If @cmnd found deletes its timer or work queue and returns true; else - returns false */ -static bool stop_queued_cmnd(struct scsi_cmnd *cmnd) + +static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd, int *sqa_idx) { - unsigned long iflags; - int j, k, qmax, r_qmax; enum sdeb_defer_type l_defer_t; - struct sdebug_queue *sqp; struct sdebug_queued_cmd *sqcp; struct sdebug_defer *sd_dp; + struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd); - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { + lockdep_assert_held(&sdsc->lock); + + sqcp = TO_QEUEUED_CMD(cmnd); + if (!sqcp) + return false; + sd_dp = &sqcp->sd_dp; + if (sqa_idx) + *sqa_idx = sd_dp->sqa_idx; + l_defer_t = READ_ONCE(sd_dp->defer_t); + ASSIGN_QEUEUED_CMD(cmnd, NULL); + + if (stop_qc_helper(sd_dp, l_defer_t)) + sdebug_free_queued_cmd(sqcp); + + return true; +} + +/* + * Called from scsi_debug_abort() only, which is for timed-out cmd. + */ +static bool scsi_debug_abort_cmnd(struct scsi_cmnd *cmnd) +{ + struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd); + struct sdebug_queue *sqp = get_queue(cmnd); + unsigned long flags, iflags; + int k = -1; + bool res; + + spin_lock_irqsave(&sdsc->lock, flags); + res = scsi_debug_stop_cmnd(cmnd, &k); + spin_unlock_irqrestore(&sdsc->lock, flags); + + if (k >= 0) { spin_lock_irqsave(&sqp->qc_lock, iflags); - qmax = sdebug_max_queue; - r_qmax = atomic_read(&retired_max_queue); - if (r_qmax > qmax) - qmax = r_qmax; - for (k = 0; k < qmax; ++k) { - if (test_bit(k, sqp->in_use_bm)) { - sqcp = &sqp->qc_arr[k]; - if (cmnd != sqcp->a_cmnd) - continue; - /* found */ - sqcp->a_cmnd = NULL; - sd_dp = sqcp->sd_dp; - if (sd_dp) { - l_defer_t = READ_ONCE(sd_dp->defer_t); - WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE); - } else - l_defer_t = SDEB_DEFER_NONE; - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - stop_qc_helper(sd_dp, l_defer_t); - clear_bit(k, sqp->in_use_bm); - return true; - } - } + clear_bit(k, sqp->in_use_bm); + sqp->qc_arr[k] = NULL; spin_unlock_irqrestore(&sqp->qc_lock, iflags); } - return false; + + return res; } /* Deletes (stops) timers or work queues of all queued commands */ static void stop_all_queued(void) { - unsigned long iflags; + unsigned long iflags, flags; int j, k; - enum sdeb_defer_type l_defer_t; struct sdebug_queue *sqp; - struct sdebug_queued_cmd *sqcp; - struct sdebug_defer *sd_dp; for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { spin_lock_irqsave(&sqp->qc_lock, iflags); for (k = 0; k < SDEBUG_CANQUEUE; ++k) { if (test_bit(k, sqp->in_use_bm)) { - sqcp = &sqp->qc_arr[k]; - if (sqcp->a_cmnd == NULL) + struct sdebug_queued_cmd *sqcp = sqp->qc_arr[k]; + struct sdebug_scsi_cmd *sdsc; + struct scsi_cmnd *scmd; + + if (!sqcp) continue; - sqcp->a_cmnd = NULL; - sd_dp = sqcp->sd_dp; - if (sd_dp) { - l_defer_t = READ_ONCE(sd_dp->defer_t); - WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE); - } else - l_defer_t = SDEB_DEFER_NONE; - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - stop_qc_helper(sd_dp, l_defer_t); + scmd = sqcp->scmd; + if (!scmd) + continue; + sdsc = scsi_cmd_priv(scmd); + spin_lock_irqsave(&sdsc->lock, flags); + if (TO_QEUEUED_CMD(scmd) != sqcp) { + spin_unlock_irqrestore(&sdsc->lock, flags); + continue; + } + scsi_debug_stop_cmnd(scmd, NULL); + spin_unlock_irqrestore(&sdsc->lock, flags); + sqp->qc_arr[k] = NULL; clear_bit(k, sqp->in_use_bm); - spin_lock_irqsave(&sqp->qc_lock, iflags); } } spin_unlock_irqrestore(&sqp->qc_lock, iflags); } } -/* Free queued command memory on heap */ -static void free_all_queued(void) -{ - int j, k; - struct sdebug_queue *sqp; - struct sdebug_queued_cmd *sqcp; - - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { - for (k = 0; k < SDEBUG_CANQUEUE; ++k) { - sqcp = &sqp->qc_arr[k]; - kfree(sqcp->sd_dp); - sqcp->sd_dp = NULL; - } - } -} - static int scsi_debug_abort(struct scsi_cmnd *SCpnt) { - bool ok; + bool ok = scsi_debug_abort_cmnd(SCpnt); ++num_aborts; - ok = stop_queued_cmnd(SCpnt); if (SDEBUG_OPT_ALL_NOISE & sdebug_opts) sdev_printk(KERN_INFO, SCpnt->device, "%s: command%s found\n", __func__, @@ -5543,6 +5569,33 @@ static bool inject_on_this_cmd(void) #define INCLUSIVE_TIMING_MAX_NS 1000000 /* 1 millisecond */ + +void sdebug_free_queued_cmd(struct sdebug_queued_cmd *sqcp) +{ + if (sqcp) + kmem_cache_free(queued_cmd_cache, sqcp); +} + +struct sdebug_queued_cmd *sdebug_alloc_queued_cmd(struct scsi_cmnd *scmd) +{ + struct sdebug_queued_cmd *sqcp = kmem_cache_zalloc(queued_cmd_cache, GFP_ATOMIC); + struct sdebug_defer *sd_dp; + + if (!sqcp) + return NULL; + + sd_dp = &sqcp->sd_dp; + + hrtimer_init(&sd_dp->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); + sd_dp->hrt.function = sdebug_q_cmd_hrt_complete; + INIT_WORK(&sd_dp->ew.work, sdebug_q_cmd_wq_complete); + + sqcp->scmd = scmd; + sd_dp->sqa_idx = -1; + + return sqcp; +} + /* Complete the processing of the thread that queued a SCSI command to this * driver. It either completes the command by calling cmnd_done() or * schedules a hr timer or work queue then returns 0. Returns @@ -5554,15 +5607,16 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, struct sdebug_dev_info *), int delta_jiff, int ndelay) { - bool new_sd_dp; - bool polled = scsi_cmd_to_rq(cmnd)->cmd_flags & REQ_POLLED; - int k; - unsigned long iflags; + struct request *rq = scsi_cmd_to_rq(cmnd); + bool polled = rq->cmd_flags & REQ_POLLED; + struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd); + unsigned long iflags, flags; u64 ns_from_boot = 0; struct sdebug_queue *sqp; struct sdebug_queued_cmd *sqcp; struct scsi_device *sdp; struct sdebug_defer *sd_dp; + int k; if (unlikely(devip == NULL)) { if (scsi_result == 0) @@ -5606,22 +5660,17 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, goto respond_in_thread; } set_bit(k, sqp->in_use_bm); - sqcp = &sqp->qc_arr[k]; - sqcp->a_cmnd = cmnd; - cmnd->host_scribble = (unsigned char *)sqcp; - sd_dp = sqcp->sd_dp; - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - if (!sd_dp) { - sd_dp = kzalloc(sizeof(*sd_dp), GFP_ATOMIC); - if (!sd_dp) { - clear_bit(k, sqp->in_use_bm); - return SCSI_MLQUEUE_HOST_BUSY; - } - new_sd_dp = true; - } else { - new_sd_dp = false; + sqcp = sdebug_alloc_queued_cmd(cmnd); + if (!sqcp) { + clear_bit(k, sqp->in_use_bm); + spin_unlock_irqrestore(&sqp->qc_lock, iflags); + return SCSI_MLQUEUE_HOST_BUSY; } + sd_dp = &sqcp->sd_dp; + sd_dp->sqa_idx = k; + sqp->qc_arr[k] = sqcp; + spin_unlock_irqrestore(&sqp->qc_lock, iflags); /* Set the hostwide tag */ if (sdebug_host_max_queue) @@ -5673,12 +5722,11 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, if (kt <= d) { /* elapsed duration >= kt */ spin_lock_irqsave(&sqp->qc_lock, iflags); - sqcp->a_cmnd = NULL; + sqp->qc_arr[k] = NULL; clear_bit(k, sqp->in_use_bm); spin_unlock_irqrestore(&sqp->qc_lock, iflags); - if (new_sd_dp) - kfree(sd_dp); /* call scsi_done() from this thread */ + sdebug_free_queued_cmd(sqcp); scsi_done(cmnd); return 0; } @@ -5686,33 +5734,28 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, kt -= d; } } + if (sdebug_statistics) + sd_dp->issuing_cpu = raw_smp_processor_id(); if (polled) { + spin_lock_irqsave(&sdsc->lock, flags); sd_dp->cmpl_ts = ktime_add(ns_to_ktime(ns_from_boot), kt); - spin_lock_irqsave(&sqp->qc_lock, iflags); - if (!sd_dp->init_poll) { - sd_dp->init_poll = true; - sqcp->sd_dp = sd_dp; - sd_dp->sqa_idx = sqp - sdebug_q_arr; - sd_dp->qc_idx = k; - } + ASSIGN_QEUEUED_CMD(cmnd, sqcp); WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_POLL); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); + spin_unlock_irqrestore(&sdsc->lock, flags); } else { - if (!sd_dp->init_hrt) { - sd_dp->init_hrt = true; - sqcp->sd_dp = sd_dp; - hrtimer_init(&sd_dp->hrt, CLOCK_MONOTONIC, - HRTIMER_MODE_REL_PINNED); - sd_dp->hrt.function = sdebug_q_cmd_hrt_complete; - sd_dp->sqa_idx = sqp - sdebug_q_arr; - sd_dp->qc_idx = k; - } - WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_HRT); /* schedule the invocation of scsi_done() for a later time */ + spin_lock_irqsave(&sdsc->lock, flags); + ASSIGN_QEUEUED_CMD(cmnd, sqcp); + WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_HRT); hrtimer_start(&sd_dp->hrt, kt, HRTIMER_MODE_REL_PINNED); + /* + * The completion handler will try to grab sqcp->lock, + * so there is no chance that the completion handler + * will call scsi_done() until we release the lock + * here (so ok to keep referencing sdsc). + */ + spin_unlock_irqrestore(&sdsc->lock, flags); } - if (sdebug_statistics) - sd_dp->issuing_cpu = raw_smp_processor_id(); } else { /* jdelay < 0, use work queue */ if (unlikely((sdebug_opts & SDEBUG_OPT_CMD_ABORT) && atomic_read(&sdeb_inject_pending))) { @@ -5722,30 +5765,21 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, blk_mq_unique_tag_to_tag(get_tag(cmnd))); } + if (sdebug_statistics) + sd_dp->issuing_cpu = raw_smp_processor_id(); if (polled) { + spin_lock_irqsave(&sdsc->lock, flags); + ASSIGN_QEUEUED_CMD(cmnd, sqcp); sd_dp->cmpl_ts = ns_to_ktime(ns_from_boot); - spin_lock_irqsave(&sqp->qc_lock, iflags); - if (!sd_dp->init_poll) { - sd_dp->init_poll = true; - sqcp->sd_dp = sd_dp; - sd_dp->sqa_idx = sqp - sdebug_q_arr; - sd_dp->qc_idx = k; - } WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_POLL); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); + spin_unlock_irqrestore(&sdsc->lock, flags); } else { - if (!sd_dp->init_wq) { - sd_dp->init_wq = true; - sqcp->sd_dp = sd_dp; - sd_dp->sqa_idx = sqp - sdebug_q_arr; - sd_dp->qc_idx = k; - INIT_WORK(&sd_dp->ew.work, sdebug_q_cmd_wq_complete); - } + spin_lock_irqsave(&sdsc->lock, flags); + ASSIGN_QEUEUED_CMD(cmnd, sqcp); WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_WQ); schedule_work(&sd_dp->ew.work); + spin_unlock_irqrestore(&sdsc->lock, flags); } - if (sdebug_statistics) - sd_dp->issuing_cpu = raw_smp_processor_id(); } return 0; @@ -7066,6 +7100,10 @@ static int __init scsi_debug_init(void) hosts_to_add = sdebug_add_host; sdebug_add_host = 0; + queued_cmd_cache = KMEM_CACHE(sdebug_queued_cmd, SLAB_HWCACHE_ALIGN); + if (!queued_cmd_cache) + goto driver_unreg; + for (k = 0; k < hosts_to_add; k++) { if (want_store && k == 0) { ret = sdebug_add_host_helper(idx); @@ -7088,6 +7126,8 @@ static int __init scsi_debug_init(void) return 0; +driver_unreg: + driver_unregister(&sdebug_driverfs_driver); bus_unreg: bus_unregister(&pseudo_lld_bus); dev_unreg: @@ -7103,10 +7143,9 @@ static void __exit scsi_debug_exit(void) { int k = sdebug_num_hosts; - stop_all_queued(); for (; k; k--) sdebug_do_remove_host(true); - free_all_queued(); + kmem_cache_destroy(queued_cmd_cache); driver_unregister(&sdebug_driverfs_driver); bus_unregister(&pseudo_lld_bus); root_device_unregister(pseudo_primary); @@ -7493,6 +7532,8 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) goto unlock; for (first = true; first || qc_idx + 1 < sdebug_max_queue; ) { + unsigned long flags; + struct sdebug_scsi_cmd *sdsc; if (first) { first = false; if (!test_bit(qc_idx, sqp->in_use_bm)) @@ -7503,37 +7544,60 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) if (qc_idx >= sdebug_max_queue) break; - sqcp = &sqp->qc_arr[qc_idx]; - sd_dp = sqcp->sd_dp; - if (unlikely(!sd_dp)) - continue; - scp = sqcp->a_cmnd; + sqcp = sqp->qc_arr[qc_idx]; + if (!sqcp) { + pr_err("sqcp is NULL, queue_num=%d, qc_idx=%u from %s\n", + queue_num, qc_idx, __func__); + break; + } + sd_dp = &sqcp->sd_dp; + + scp = sqcp->scmd; if (unlikely(scp == NULL)) { pr_err("scp is NULL, queue_num=%d, qc_idx=%u from %s\n", queue_num, qc_idx, __func__); break; } + sdsc = scsi_cmd_priv(scp); + spin_lock_irqsave(&sdsc->lock, flags); if (READ_ONCE(sd_dp->defer_t) == SDEB_DEFER_POLL) { - if (kt_from_boot < sd_dp->cmpl_ts) + struct sdebug_queued_cmd *_sqcp = TO_QEUEUED_CMD(scp); + + if (_sqcp != sqcp) { + pr_err("inconsistent queued cmd tag=%#x\n", + blk_mq_unique_tag(scsi_cmd_to_rq(scp))); + spin_unlock_irqrestore(&sdsc->lock, flags); continue; + } + + if (kt_from_boot < sd_dp->cmpl_ts) { + spin_unlock_irqrestore(&sdsc->lock, flags); + continue; + } - } else /* ignoring non REQ_POLLED requests */ + } else /* ignoring non REQ_POLLED requests */ { + spin_unlock_irqrestore(&sdsc->lock, flags); continue; + } if (unlikely(atomic_read(&retired_max_queue) > 0)) retiring = true; - sqcp->a_cmnd = NULL; if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { + spin_unlock_irqrestore(&sdsc->lock, flags); pr_err("Unexpected completion sqp %p queue_num=%d qc_idx=%u from %s\n", sqp, queue_num, qc_idx, __func__); + sdebug_free_queued_cmd(sqcp); break; } + sqp->qc_arr[qc_idx] = NULL; if (unlikely(retiring)) { /* user has reduced max_queue */ int k, retval; retval = atomic_read(&retired_max_queue); if (qc_idx >= retval) { pr_err("index %d too large\n", retval); + spin_unlock_irqrestore(&sdsc->lock, flags); + sdebug_free_queued_cmd(sqcp); break; } k = find_last_bit(sqp->in_use_bm, retval); @@ -7542,7 +7606,7 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) else atomic_set(&retired_max_queue, k + 1); } - WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE); + spin_unlock_irqrestore(&sdsc->lock, flags); spin_unlock_irqrestore(&sqp->qc_lock, iflags); if (sdebug_statistics) { @@ -7551,6 +7615,8 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) atomic_inc(&sdebug_miss_cpus); } + sdebug_free_queued_cmd(sqcp); + scsi_done(scp); /* callback to mid level */ num_entries++; spin_lock_irqsave(&sqp->qc_lock, iflags); @@ -7733,6 +7799,16 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost, return schedule_resp(scp, NULL, DID_NO_CONNECT << 16, NULL, 0, 0); } +static int sdebug_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *cmd) +{ + struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmd); + + spin_lock_init(&sdsc->lock); + + return 0; +} + + static struct scsi_host_template sdebug_driver_template = { .show_info = scsi_debug_show_info, .write_info = scsi_debug_write_info, @@ -7760,6 +7836,8 @@ static struct scsi_host_template sdebug_driver_template = { .max_segment_size = -1U, .module = THIS_MODULE, .track_queue_depth = 1, + .cmd_size = sizeof(struct sdebug_scsi_cmd), + .init_cmd_priv = sdebug_init_cmd_priv, }; static int sdebug_driver_probe(struct device *dev) From patchwork Thu Mar 23 09:45:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 666462 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8045C6FD1C for ; Thu, 23 Mar 2023 09:46:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230499AbjCWJq4 (ORCPT ); Thu, 23 Mar 2023 05:46:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229990AbjCWJqq (ORCPT ); Thu, 23 Mar 2023 05:46:46 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39B142472C; Thu, 23 Mar 2023 02:46:46 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32N5hvKp010849; Thu, 23 Mar 2023 09:46:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=ugvdMQOQLiTnuCTeYWIm73lmLo4cygfDQ9cF0NAB9Sk=; b=KzBWyWKavel+5JNTmkkahULrlgp/mK0yuwPtfYpPJYRbpScsMnFz2tyn0c94tPI3MRlJ 3eLpKmsbkFViEb7o1HkyINkJhwCZn2+txGUa/S2n0BdLnUqb6Kie953toPMlaa/F7nck JSteXiDz7JrIjuEDVA5zIM/Vd+pBxTv9gxQEenbE/ApEyPFGIcPUaiZ5pVAukA+GLPlZ MrOeUojVaxkGmWGZsSk1EOSVaN8liSAU9g3Nu8PzcAEzoOyL59UtGHY089suWYwXClUX loz1u4KRl1xMk1zEjDPV6flVSWM8qSQw1boslIEjFbFRCrYoUyE6nDSYmyMk2I4lJ42k 1g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd433u9ht-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:42 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32N9cdiG006987; Thu, 23 Mar 2023 09:46:41 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-8 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V5yVcB0xwbTcsuVK7nhXPq1e7iJOArWGuUmYqOysYEE2RxdLNDAGoz6CYn+KEIqhrlLmpi/tSrEBsk632vsuiOQY3Hcvb6T+yFX9NWpkoxeOzQUpYPNBASk3DtUQ+sLyE9VKZDQj9bHdL/FkVj2H2ixLzkABPQzt6JdXBxCokgopV9NuN5OrVBjZMGDPKYvCHnCrmV+kJkLnYJoFRe+Pumcp94yuL7vrzsJ80PLIM2Gr5akOYytP06b68E7H8A552hluxcuj+TuUAh9yz7L803Ni+JV9Lq6+OMw4S/x+DRtVSw3Ovfv0c98UomrHD7Tte8u5m2bCAZJ0zNuZRy0ZHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ugvdMQOQLiTnuCTeYWIm73lmLo4cygfDQ9cF0NAB9Sk=; b=FU9Q38aIbNx8otxTpCQRXQ2HTjk+1FzTof0wKHIGz8bXJG2tlYIh2xfkYlOOl0dYWu31DJl1aIKcDGxmIgcWSICbmR+HaOx1DUtGAQTBe0bd80W2YIWAg5VwzIT7yd5pqGakIK9X6aQQyFgF9BxuLEcbQIzormNMKHIDygqOfMzIvALBR+OOl8CrWzCht+M8PS3a5sPl7YE7m2Rkzkgcgp/VUx2DXBLxL9ucIiqus8LQ0eUPrkgTOFZEkBVRrhSUg7CGoiJ2tnEWUnDgER0scDtUx8CU0deusMpIELGBGcj5vsiLafn0mjEK4FZLqZnrlny9EuikZwagHd6gHc8diQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ugvdMQOQLiTnuCTeYWIm73lmLo4cygfDQ9cF0NAB9Sk=; b=PkF1tSek4PuE1A7XlTYzJN8TWHdUoqLjGHU0734bBp6Sd8ogGeXHjN5rbZYhvhpOiLAxikB022Qiy0SbkNa5awdgBxaL7FGSKtj6IXwHC1M3c8P7X+HZ304Z/ep5zQKbKW1g3iumL5N0QlGMxOmyWuG8pxO4A45JNSR3ll2BEww= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:36 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:36 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 08/11] scsi: scsi_debug: Use blk_mq_tagset_busy_iter() in stop_all_queued() Date: Thu, 23 Mar 2023 09:45:52 +0000 Message-Id: <20230323094555.584624-9-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: DM6PR06CA0012.namprd06.prod.outlook.com (2603:10b6:5:120::25) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: 18544636-0b46-4338-1e40-08db2b837e26 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mxSkf8gVT87ZhdEoE1Xzod4ggwlftgN075EppOBnhcOTgk5yFDQKIo7ZyplV5zkNsAT0EO3W8rcECMTNWOTG5ftBjzoQnxBdwWGK1KrghaIgREmZDpEiRw2C9avH5DffWrYV503YT7dMUMusbfynS5/Fva2HHMYpVez+YKMaKvIRIGRQL8D8TI/jBF5ithvBxNp1n2ySlevP/sdBl2lLhSWYpH/LiHOGHrRfvQ2opKI2v2ZmzSY7CJCDUDAGmfKgweIzcY7WmMEEbi0lAQk87At4X488NCYUeJO5nhd5Kcb6UbURk6KJaHy5QuiIHuTkFMAJGkIi3oAk8DTeegACDlF8G6tNhnQgk3etCwW7OESewDZydtFWqjDnH57BJQDjDq5j436ibcdAmDLbWmHiVe26xOdAOhX5MTKr+BciJiuQlBHTEUlh22ntUmzYoavjojNfkv8VmUOYU1DwAe9TI9u44IDjkCLeZfK1BnFK9WCjC+y3P3/t9PlXLYMh+sR5PpQ9oKojStZ0xjzfn86xLpiuR9mvNAQXUpgzawHxPZ+krW5fosyTH+5tsakTHivfp+om3yRJYib3jH6WzTrOcHnfz6K9OaVzuFmvlHmwql6CgUEfVwlBhdIPxLlSbA/YDpXBVS1IuqhE5zuTxV0rBQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR10MB4313.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(6486002)(316002)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(107886003)(66946007)(1076003)(6512007)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: c6rTrpOCNUu/7Ojdl/D+2kWk0SId6EmU8QStv781p56JuhrXo9+PUAkOhGvmWE6MA57VFekQp0f7EdDu6hbXZdLsGwSAyiKnW0kSlqBrSr0dNrgXhokqy06kcszO8gnVBsccj+/r0dEzKvcHyzskulT6UDhMtCuzAblwL8+dctj/n7L06RSY5OlOxIIh/0pSTs+1oQ0SgQJOYT8V8qXjgwssdbg13AVOxKIiC1XbFfl0WXc06/wOLyUfbjy0UEPWuSf/CJgEKp4zPLTroobw/I/SZay6Yi96mtrwF79nUsJYOuXcANIoL7aVDZGBjqxutSwuzriYDXT2koOOzfS7LmkSFZmNYebVcXo6vMQ1CshgxGdTtqrI9RrVy4+3BrYvB1saO66XbL6I+EKbqfjLH3MCk5ZGJ5KBgdvZzECLX7haZ5b9CKteYVdR1CDapSb1V5h8p/KlWCzdh078uFp1YeTFbNkgrZoQZvgUhpt0I0rxCBFGqwBz0m1HogoNe0zwxj2ItMRyhe3VbAimwdwPvE3iVfOcNxoHJ8NEgyC6X6NKSvKhbMlpXP86IUmgDU7mJuEbgo0MOJWPAF2L0eWF9PeaIDQ5H1xveCZ2LD0g72nB6iCIpVY+pPdia56Csyb1N8UKJ5YPnM6uYAEEZPIuLrMLXo6IxW1tgfpMgSdjBShb5grcIp82DW2QaIIYE0rbGe2Baxab/pR2aze1+mjb+Qspk1d5egf1AKbVZm+34mjmi5X7rNzKEms24KyH0UVXY8t3OX7lhjJADJ58q2CXhuswTh67/Etbxb2G7deK6vV9UrYi98cIyo1z1/IeskXZQIFRxcppkhiGXZk+vI5yl98XKpNzcf58sdoiqPfXroV4UAgu2Nd4bUjbJbXW6ghPKQI/r/eYDMDio0TNY8dzZ2gffvKP/5wkyzp+cH6u0swGEQlrR9R7lkFpjNGcK/4AM1xwrkSh5rkJ+0synznexK7XVknOrUcmAHnZub1rqCy1XNwT8WxpWbJJHTkznIMqB2Wa33jXWoJS4XComGeNtHdlbdYCrlIjzT/K0S0vmx7xyjRmIagxbZ00oAEXpmtlqYaCqZATCtSNUns/8z/ImhnHxAWTAjxkTbqq93u5yYHCa0TKG29tEWzz3HggXsCOG+yltMFSDM80NPgqOpIlZ/UZy0tx1bHm+ccTS90M2J7wlGQ+JHYEULTHuL2zlQMpgMf662ag8k5EYNcYNTvKXGOPBkakruoxe8Fzhdz00t2UPca5vUSvT8pT8XmOXrUWgQatDZlLq9temZGi/98buwFuGAPsrQbgbmBabTVqRgKwuE4DQ53eB20Jelz/O0GVJYBxquIANrmUP4aG0n29YViXm1ScTWPc3/1P7hthGWN6j0NGmpgF8ZhMnY/8+X/MAgb/0XY2o913rYrCJCCukgo+WV7P8UKs4LUEam6nd6mxN2g+p+LJ92zKxVa+WsUH8KplKNvMAqEp8H9nLe8gm1OxmqnAUpAYK+sYCUi6N8lPW94Of0UuHxVy5/bggPsxxEw8+Z8ZYGVe6eOwiEE9InQu+RXS3viM+T4kgrDSMT8RpnxGJh4Hfa1kYECtkGuLs+xK7NOLIe/kiUTv71m0Nw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 0DJWFZ8b1wHiPvr/2PyifGbNtQFOQlhM0pNY2EL4cO780+jgJ8hm6Tr8sg2qCJB1eD9makEuWGzn3FK+Dod4eDFp26vsiot9Y0PXpzKNpIjS2kb0Nk3vdQFZLYrWfGDxvV6Qo+c8aWfllj4wNCOeABhvdnEO2jX+CbZktuZtCOJ3qCZiYhScMCuUDG+QleDxCvviM5VIQc4yx89S8owuDVAcVxrG1EXXOuxTn/a0j15xkbgoDnERiXy/UUiJuTtbnxFZQjMrJQ+svcErtf0EUMe6+OtT6TQ/4ArHQfW1dZYWyEKPQkm8vqgYpLiNGKzktoff3ViMgXUkiu7aBd2LebunCezFroTJ9WCY2Qw8w/498DsWGbZjrEsKcAqQrHyCAtb4Wm2H5YOwsQ0eDngL0R0yhDPhh85fbDLutIJ6cGwVms6G04F+wpZZsEWT4hNBB558lOaxOfMOwdZ3Io0hrU3sMa5jAXxCvgPoMNG/iMFWVdnHkePH1PQKGupZt8P2/VmmunumggsjgSj8gcYWX6CBl8AR/JKtCw/qrJgyj2mEJ87bKAE94Jv6qJGGi4W3U6YqhbaSiH2YYDEXERZtyn8r4BwGVwam7x0hOM3453v25e7Mpb20OSFTr5wY6i1T6ZclRt1Qpl9cHvAkMw5fSmYaryxBMhWitTSlkOm/QIe7pTKi4Rf5jk5DbYqVTpbOCwQ2CPbJTdqAEfwaLujSkJSXt1v8Ux7qGMBSOIq9pI6hPE9P81eqCHXdun+TTzsVno/HUSwGMAwVhKc97q0i4ECTgrbBQP9NLB7DQF5OeVIcsspG6G7AI5ZoheeypxVMXEs09SyW8Lzi1B5RvYnlWmzqS/cF5Kn8AHKc2lfokgU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 18544636-0b46-4338-1e40-08db2b837e26 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:36.1288 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: P8oq5wko6nUjGsWD/ppKmIyMtpP1566hu45ysR/B7ILGIYDp6VT7y5C49cV8kSrSJ0GAZkcsPmwYIxFol91GEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-ORIG-GUID: weJh2WUcXe0kzmckx5UR0YjuHPw4yFvQ X-Proofpoint-GUID: weJh2WUcXe0kzmckx5UR0YjuHPw4yFvQ Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Instead of iterating all deferred commands in the submission queue structures, use blk_mq_tagset_busy_iter(), which is a standard API for this. Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 45 +++++++++++++++------------------------ 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 627bc98c18ae..3e2e7f24d90d 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -5326,40 +5326,29 @@ static bool scsi_debug_abort_cmnd(struct scsi_cmnd *cmnd) return res; } +/* + * All we can do is set the cmnd as internally aborted and wait for it to + * finish. We cannot call scsi_done() as normal completion path may do that. + */ +static bool sdebug_stop_cmnd(struct request *rq, void *data) +{ + scsi_debug_abort_cmnd(blk_mq_rq_to_pdu(rq)); + + return true; +} + /* Deletes (stops) timers or work queues of all queued commands */ static void stop_all_queued(void) { - unsigned long iflags, flags; - int j, k; - struct sdebug_queue *sqp; + struct sdebug_host_info *sdhp; - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { - spin_lock_irqsave(&sqp->qc_lock, iflags); - for (k = 0; k < SDEBUG_CANQUEUE; ++k) { - if (test_bit(k, sqp->in_use_bm)) { - struct sdebug_queued_cmd *sqcp = sqp->qc_arr[k]; - struct sdebug_scsi_cmd *sdsc; - struct scsi_cmnd *scmd; + mutex_lock(&sdebug_host_list_mutex); + list_for_each_entry(sdhp, &sdebug_host_list, host_list) { + struct Scsi_Host *shost = sdhp->shost; - if (!sqcp) - continue; - scmd = sqcp->scmd; - if (!scmd) - continue; - sdsc = scsi_cmd_priv(scmd); - spin_lock_irqsave(&sdsc->lock, flags); - if (TO_QEUEUED_CMD(scmd) != sqcp) { - spin_unlock_irqrestore(&sdsc->lock, flags); - continue; - } - scsi_debug_stop_cmnd(scmd, NULL); - spin_unlock_irqrestore(&sdsc->lock, flags); - sqp->qc_arr[k] = NULL; - clear_bit(k, sqp->in_use_bm); - } - } - spin_unlock_irqrestore(&sqp->qc_lock, iflags); + blk_mq_tagset_busy_iter(&shost->tag_set, sdebug_stop_cmnd, NULL); } + mutex_unlock(&sdebug_host_list_mutex); } static int scsi_debug_abort(struct scsi_cmnd *SCpnt) From patchwork Thu Mar 23 09:45:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 666463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2DC2C76195 for ; Thu, 23 Mar 2023 09:46:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229738AbjCWJqx (ORCPT ); Thu, 23 Mar 2023 05:46:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbjCWJqq (ORCPT ); Thu, 23 Mar 2023 05:46:46 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81C132471D; Thu, 23 Mar 2023 02:46:45 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32N5htvh010804; Thu, 23 Mar 2023 09:46:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=vTQfNp5u2wr7k5ga6IP7ndOMPutnmoj1QRDsG24TqO8=; b=QT4ws+MJTbg5KCYvzzFroldlkgOSI+27qfUv5z64YC4+tDt7MOTHUViGxoXHv6rwD25F r0QC2IclYN3GOg6TG521CAtR5D142D0efXcUiQUspp5GCcEyzmBPHbaiY5Eq7xoPsJiR mnr0r2Ejue6Ak5pes1UjjDlL23yMDrmmFGD0Xd5Tsm752/EoPZ25W8ukV6t7Qew0Iklv RvogqpDXd37cBSYYwuYUqBpFgMAI92LGEGVqEtXPMO8WQaJnak6OuGyi0etjRO1LIUZc W46RjMcX29YC+HmRSXEkKbOyauqxVm5CV5HDsZuFC6zKl46VdGRri87NJP6P/NFIWg4e 1w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd433u9hu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:42 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32N9cdiH006987; Thu, 23 Mar 2023 09:46:41 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-9 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lzFE4lNtOnfGrWapfvnjIWSV5ypEmIEGFSZJ08FybFaJ4H/IbBETi5dAz4E/z9dthmhVEPQu317+pKh2uriaYIAOy1ujtZiq/bUZWu314jlc/Sr9dGQEqK09Vo15CMzzvw166lU8XqbcGIGI/WCSgqKtfTRBTtxZgyhYaqMqBAnU4iTK0jxN83r7uZSPHVho+az/c1CIzR/Kt4YeorYYznL1E175gbBS7DZU8jETJWXajvvuw49zJCBvMwmzGoj8iXOIjztPpCMLFDU23xfz14YrFmTPhh+ovoSNHU6C00ZuhG5xvUj9vSuZ3447g9VeAKvoMfOCsJjek9H83vRudg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vTQfNp5u2wr7k5ga6IP7ndOMPutnmoj1QRDsG24TqO8=; b=Bb46B/uLqPgxXNutFnlQB7s7scT+u1288WUxR6gHPXFx/ayZ6HMPQr9hKgzTp8O+TW3nzEOsUtA0PaGcwvrZ9eWxN05GXEbCNVk5MgEAd8VyfAPJpQaXK1ZvAagQ4K7zMeZ/kdxL0S4UsxZ3g73TVVxUB3SawFJovbrUObCe81lyNzQxJ/kB5CrhDxmF5u/gA/eu5hiLRxEU5MemckzMZmiiXnry//aSDN24lL02iIhURnZcZc86fYwyJ0UIG99J6ZYodlCDzihV6k8eTlPX130tLNC3OfrG1XdiEWBUH8NdD60rdrATVDpCfNij2mZI2Fx3SufD4VaETzkZMBbMCQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vTQfNp5u2wr7k5ga6IP7ndOMPutnmoj1QRDsG24TqO8=; b=bfK2osoUAxogXo58xZ8dVxdtKAtPFG6kdvbDUc7PsXnPFqolbY91rMkncWxFqN7LUOgfGasEYqCIrxC4xyM5z2txFumaWwRQEhdCRJv3HRmW3/btyDPMEfebhmOG4gvlGkiUzqQRShJyXe4OXAgOOfwTpwDSscZMStguRRmJ0jk= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:37 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:37 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 09/11] scsi: scsi_debug: Use scsi_host_busy() in delay_store() and ndelay_store() Date: Thu, 23 Mar 2023 09:45:53 +0000 Message-Id: <20230323094555.584624-10-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: DM6PR07CA0091.namprd07.prod.outlook.com (2603:10b6:5:337::24) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: 51d043da-d7a1-476e-29e6-08db2b837eec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hrMAQ1uO4q0KQN7G3DpvMWC+vkWh8OYwMdw1jLRfbAMHBBIo3NHRPxDg6y5mO449d4UMNyki1/nTUSvswtEWgcN1Q6FXZ9agO6plIaNrRObSQQXNd0qc9wVdNaagyOVlk8FKWbh2ZYJ5H5tlBXWeHO7+0vU+ilvm2UW5ucyd3cTK5DHDVVrkn6LxazAf7xoDyz7tOgJC+jwd8kEdSmLz2YCmRCL5gtfHAc9rnvzl+4v0LjTdIWQykJrBFy7h8O08QFu09EjS45THp/CuNCq1b2V8v48IGxCSvnN/ZhJ1gKZjNl3xG1mnBVmOy33D2b4tutxjJ8+SbBHTNCur6AdwVuXZ5N+DgTicYGEhKR1XkXH5E95LfiodrDxmtjD2S0ud3MQE02WuXnI4PrnX2SH4Y3Q5Vccpr4RKKY0c8fAomdDwosfmdSvLKrcBQSMeDvyl+CgDk1rIKKIi/BfSirFpQ08mTI+qgXSb3T03akhAmxqhyjI73WVE4yXLD5p6+ybyHidTZ4PLJ9YqmwZqRLWgjHNlfgzIv9XhzFqnbM2wOpIQzrevpIMVMUN1Ps2h8/F9YF54xvu07nav8Cd4rXyDdDVQKwmtolzjpN4pGCA/g2I+CdQvWJgOotnT+Ke3vGln0n54JRw1Z6/DjMzjj8Cnaw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR10MB4313.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(6486002)(316002)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(107886003)(66946007)(1076003)(6512007)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HHJ4HRfHe+MmCvWUnCct7iYPPvMB/Rmv/xmZOuzaONgteZQFIdUYLjFtMD/0kJWWRub6kFqJFob1T0QJnNInrUauBYKWFvuANQ6KZXZMijin7hVy6OQ3r3ePw5m9g/5DEcppEZXPr4z7Whoz1c6p0k0QzSxBsK/aZCy6qJDatX6ESWnVwAv8L8bkEZqKyf8q7SbI0rzKKSMrhAsXW4BBLBbu70wPmuWLvXpmTTpeSrU0reMM5kcQM5kspCG9X+ytYPwsQUI8OOVGKwzkU3ocBnvJ2y+j8BF/sKSX1PaVY+0zgBNBTPZ6Z50uVJQbydBh6DYWb7HCXXalzBz+5kmhOzxXktFf33yFNW0wnIhuhgSsN+9tzEQJ+w0PmPlEfIJVVeU7cXLLSRX1nCOxrGh8b2q2B3ggwib4esZqAR7D0X0klhr0Fi7swWL0UntGAN0Osz7GlH+PQ0Ul8dwmpCf1KFk+sbGkq66fvCQyKeRAbPeP5uw4ONTn1UDy4a1E00jJfiFDQlabsEutKpxoi/NMVQw0iprBnciNjsNRkgPgV+TyjkGGZj0goODiy8U8Ez9Y548cYPQDKcjBA2NVqhyfEUoDkfZ1xESKucHp9EwSrJ1YcZoS+zrP8fdTjdzIfsUnoH6IZ0l3caN8yXBFjBFyqnxJ+L907gv0bfM9mdAefZTYSdXYUEQHLDQw2khsJ6a1WLZ7ZWSZ74tlf4FUBy4E6gYaFQLOuAdrjpuA7Ht43L2d61O6wYk9x3QpQJFRUc5fPVdAXBr/gcTkTiiayQ/iLkG9NN9cYIRuIaTXEa+YnkESJFqwGM0G1atQSXngz7QxZ5ASCAXjrUr1BukBY8ZA0n/2gkSbZFn5n6jAULtXLUMkygxiofcpfKHHt6UGkJbisOwd7bU4SOcb0GbLYwlMkPFMkP1OQQrNgeXiLHRBkwuhGgdbO02Uu/2saSdmdJyLjeHjFrXwSvxK8NXKZdOOIzTGeA524Sr5wylwMNmQ0e3neju4zFYujdollBSF/VojAz7PC1He8Mj0RGLvpWDGc1Cb2FBSnCi3g5dLcpqNyVk8kHlMdJfYOnkwXpKceV3s2JzvpICxGbklwE9yHIsvD801AoyAc6FlMNnqvbIKoxiTWj+luz+4ZlMeysmN+Oz4hzFsqxklla3P5LcHrX5U5yuIZEMxHBRCyLwvV6n4Q0aJjCGpYBGhYtXGGFGgb3RSCsZXRKMNbMlaVlZYV1pVjFc17ip1Imy0NaBliLRm0rSJJf4XHTwe1Ma8QxtZLG3YvR2V/birHJ5q7tD79Vh3TMCWpnwEnKEK5uUmWbYhYLaKGwgaVlcVELO8S/AqRVcE5ZjpP4OuNcsmGbGkIrqdZBR/sa0E4lCOm+Ei2Uw0pUjD3Q9K/L16YVj0REtYwidIaN7QiT9ipqFkxLpOD27BriJN/d0WAbKwtcStGiKnbHGwtOpZM4DNu/QUXqpDppahM8vEycqyyxlZdIARvq7bhBf14ccMZuHrPn2YwaRZBH4VcC3Rn8TJGEDogDKOQ6j61YoEJyZIW59Z/Yl2GSEmjgAFclNcVgxnzI4U7DWzAUaXy013sm4HEYtp24vcb3wY6WWlwObWis/ROHnwLsk4HQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 4ICosJD9M1e9LkOTjgO9EmOeeOm3PRWKM/ELiWhPc3hCJCayeduGDbqdxxx9oFtByyUotyhPIj+11XBMCK8Ymh5D1qeFNkmP2rj3Lq7kBur/VnUHwZtUGIaE7mE8ddEs5XWxBGXzN4SLz+QC9kmHHPB+ZQMwPv1VJbNMqiHUv2ycHfQPTBfUtsi80bFgS6zaKmgMx9LahJYjrWNjQcEKem2m+1m3s+ftWhshy5T6njYt1PiF/mn6I1Swqw4B/MWyMDy7ATtHJ8ctFnu1kHCctBOcpTcga67zH5eACEOigeV3nijVGclE06zyI2a/c7cnVW4QPH5+o3BydT2HjSIlQ065uUGUu02qp8ZIyRi7HrvejiBwpWgdHTdrUSFeMZssecj1zNH7DKzL/84Tp0my81ugLFL7XRWBquj92spK7t+M4wHHVq2IplNBPjhuA6W5ziHOYpY6ivRYNozYz1JAZlWCQPIjXHhq+cxefuln8x5Bc+/o2vpdp6WbBJv5mdlykydiHUal49Cl25hqXAUhue/mQO/gL0eLiGDfsWGKWGNQdxwNjAOaaO127HMlDVILcvhwb31KM9zRoIcbvgvUy6AzyzSi3wh9LuurmQ8sbXxgJ0lS7DW+M+YvEVHkZiV9JIL9LY8pJXFTSZBVkLweF4ZyLfPzTjh9V5LmK06J9TFHjojGflAt8lAFM0Qi8pkRHMMAcKyvzKnnDsV5m3kBzITKC4OaqEjxoYP/tWZfICh6/ymub6h9OoShr/XP4UlpyfUOAoGaBOzr05vo6aeIsYWVrWR4A31SOWPYPsL+gQqQ6mYI+WJ8kkW6lX713DzAwk8+gCBbpbcfrjkjD4RNm1EUaLSZlQhO9wQXvpOvdEU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51d043da-d7a1-476e-29e6-08db2b837eec X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:37.4267 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fYVvLTWqt2zbgMD/HA6xzd5tVgYIKrXDgkh43s8nUzISHNBg4WeIwoieufY9jvf9zUFwNAxIhVJlwpC/24Y6iw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-ORIG-GUID: 9VCWR6naogU_ZNWC7KJYdI5J_Klcvydx X-Proofpoint-GUID: 9VCWR6naogU_ZNWC7KJYdI5J_Klcvydx Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The functions to update ndelay and delay value first check whether we have any in-flight IO for any host. It does this by checking if any tag is used in the global submit queues. We can achieve the same by setting the host as blocked and then ensuring that we have no in-flight commands with scsi_host_busy(). Note that scsi_host_busy() checks SCMD_STATE_INFLIGHT flag, which is only set per command after we ensure that the host is not blocked, i.e. we see more commands active after the check for scsi_host_busy() returns 0. Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 3e2e7f24d90d..8a0fe403e225 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -6061,16 +6061,15 @@ static ssize_t delay_store(struct device_driver *ddp, const char *buf, if (count > 0 && sscanf(buf, "%d", &jdelay) == 1) { res = count; if (sdebug_jdelay != jdelay) { - int j, k; - struct sdebug_queue *sqp; + struct sdebug_host_info *sdhp; mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; - ++j, ++sqp) { - k = find_first_bit(sqp->in_use_bm, - sdebug_max_queue); - if (k != sdebug_max_queue) { + + list_for_each_entry(sdhp, &sdebug_host_list, host_list) { + struct Scsi_Host *shost = sdhp->shost; + + if (scsi_host_busy(shost)) { res = -EBUSY; /* queued commands */ break; } @@ -6103,20 +6102,20 @@ static ssize_t ndelay_store(struct device_driver *ddp, const char *buf, (ndelay >= 0) && (ndelay < (1000 * 1000 * 1000))) { res = count; if (sdebug_ndelay != ndelay) { - int j, k; - struct sdebug_queue *sqp; + struct sdebug_host_info *sdhp; mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; - ++j, ++sqp) { - k = find_first_bit(sqp->in_use_bm, - sdebug_max_queue); - if (k != sdebug_max_queue) { + + list_for_each_entry(sdhp, &sdebug_host_list, host_list) { + struct Scsi_Host *shost = sdhp->shost; + + if (scsi_host_busy(shost)) { res = -EBUSY; /* queued commands */ break; } } + if (res > 0) { sdebug_ndelay = ndelay; sdebug_jdelay = ndelay ? JDELAY_OVERRIDDEN From patchwork Thu Mar 23 09:45:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 666461 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42C50C76195 for ; Thu, 23 Mar 2023 09:47:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231142AbjCWJq7 (ORCPT ); Thu, 23 Mar 2023 05:46:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230293AbjCWJqs (ORCPT ); Thu, 23 Mar 2023 05:46:48 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC24E244B6; Thu, 23 Mar 2023 02:46:46 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32N5hoNS019252; Thu, 23 Mar 2023 09:46:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=NpF0Loc3vV5MFrD6YCOAk1qLEJTwm3Krk6N0TLS++Pk=; b=XGwYqJlYTm0zFpPXJ2NKpnM6a15Q45WH+KTjRDk+aUBQSj0IL/Mwt4sFcOGlycxesXFC liJFxwZ2BO1dGnZs3N3QW2L07Tink6jXLIo1MhJFmXchSedIi84GhFtYZu8LFQM19tEy UVLv+2cgWCi+gC//YfeD3ZVAIiGzRN6EFjNrfRQvUS35yjlS2AY0orK/iU+nBcczH3kx cO/6d+06Uqsg1be8Qk/Mq7HjKIj0CaUI1RiyXlrVa9rMn9n7Og6ju9y3qcGaPy1SyhGZ bw6tKQaAV4+sr2SGC4WnHgj7RWfxbeLUWcGeLrMaC9Y37sLRiS1ZjHdf82YvqAa2bRqZ tw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd5bckbq2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:42 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32N9cdiI006987; Thu, 23 Mar 2023 09:46:42 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3pgmamg7ry-10 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Mar 2023 09:46:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WLlfhYUbL0+6Uxs/LQfXo7XXL+oaXa+b3uwLu+YKvbtA8Ff3HMsZujO+Vi9+FlDMsH84rhhFr4TJN9VfOwj9SPRc1055RZNc1ib2DwXyWlDxaQSt/7fHSh9qv2JxGFRkVUNnZforIJ29OpgDOVImgGNU+lFNVk0WLyPoHIlqM7u6ugPEDrlXrGMI+hIqbodewp0AZ6ZY5dJ6UhLxOjWRjNqRcXsdEjhmM+iMgChXGzqvxqoOgFDjfes2aKUCiDvO4FvLhPUwGgyYvF8r4Q3wlKf6nQp4wn3A6laRzLF9a0d9LX+R9CLtvhsVw/em4Khh4w+iCy09Bz4eK+5cAVu4cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NpF0Loc3vV5MFrD6YCOAk1qLEJTwm3Krk6N0TLS++Pk=; b=FcV/hBTFHn6IcsDanDfw/eqtoAgfxTA6Eq/R3gF/sr/LqmUE64iwg7rqlvwcerBgjYjxlFZ9q2C51xeP9oliQaXj3oG+IK6kWSBHHGqRE6pdzPc5kC+xBLyywd5PFt3ydEiEL8shn/1+vmp1ADPmZQTgL6GAfsXCQq4kpVjne4eiTwKN798jwsr/9TbirSonqgpYq/uonI+5j/f98IlfdZfuLPeFNZohNsfyFnSncfmacrZvPYs28OTRYK7h8qUmf9ApSVS7F3aNvCPYqBtmo4nKLcOZ79kVp+o3YlZHaOfPFvlnr4qapXfWVfcGvop7PQd8d3kH9VGt6xb9hFrLNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NpF0Loc3vV5MFrD6YCOAk1qLEJTwm3Krk6N0TLS++Pk=; b=YyxkTi7Q1LJB362OjRXY1cp7tm81Vd3RNZmXTbORSk+fo79xlJUtWShEdOL59DvCIXuf0gB377wWVMDfFqcRXqOQQeilYU8ihtNWBdGgE4gx7BSw2mtBm3GMKbfFVru2pvdu4Odw6SOGV4wpsOf9SYOfxf24v5QC/oMFU974dLI= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CH0PR10MB5273.namprd10.prod.outlook.com (2603:10b6:610:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 09:46:38 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%5]) with mapi id 15.20.6178.038; Thu, 23 Mar 2023 09:46:38 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, bvanassche@acm.org, John Garry Subject: [PATCH v2 10/11] scsi: scsi_debug: Only allow sdebug_max_queue be modified when no shosts Date: Thu, 23 Mar 2023 09:45:54 +0000 Message-Id: <20230323094555.584624-11-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230323094555.584624-1-john.g.garry@oracle.com> References: <20230323094555.584624-1-john.g.garry@oracle.com> X-ClientProxiedBy: DM6PR07CA0092.namprd07.prod.outlook.com (2603:10b6:5:337::25) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CH0PR10MB5273:EE_ X-MS-Office365-Filtering-Correlation-Id: 75638bb6-d6b0-48f9-987e-08db2b837fc2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f1XMPHPUnC9ShyKIGme/QEPRPm1nMYy4oAEtrouKGs+Zc1Lycm+2IEeYLz2fxs1kApn9SmqPxRJYU3zDOsLnT0BILD12Wn65+mvCcz/XWCH9Aao6gg+VRby9E6GuCUyh3NS8UChK+L6tqnTx138bLv8CNtG+IqCwLEgq1n6T/udiLreAo3HmbohpTH79iuiau86JYMwjB41e/87tiLBZem9xFW6OzC/VQKY1RSmRgV3JLyOX8/DwyGytzs8ThjmoLqiDAJe6WlgDcWmdSmdhsOildctcD5upE56TT7VivO4dQcMAfoSWqM7xmu3PK3fYXiHVdBqLHgxit+faZdQA4v9/kMhqCqkbYLsHYEKpjiS8jnmjIJZo1Mw0o2PMlVl6FhwN/Gut2eYIRqd7TTfODIbx7P2YmflS+guKwZUEgfCihCPSssrgXz4eyW+UwV3J7XhmtFYU4k/wbGiq7E8RdQqZjTwqNc/RJejfrySajTlsQe8ngdBWN+DEdIS5R04rP6wlsPTqFSrbLQ2kTL9H8d/U0B52cIOVzYqi74/ip3Ol2xsroDGqt2/Tofypt+Wts/L4hnO9mocwS/pX/oiYDEAdoerx1hAxlWGQzEPzz/dvyoSUWwrgbF9tSC2Ywh+4hc3tKLb5VHkFp/k3dHquAQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR10MB4313.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199018)(6486002)(316002)(66899018)(5660300002)(2616005)(8936002)(83380400001)(26005)(103116003)(41300700001)(478600001)(86362001)(38100700002)(2906002)(36756003)(4326008)(6506007)(66476007)(186003)(66556008)(6666004)(107886003)(66946007)(1076003)(6512007)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gPaTv7t8RUyaA6UAhd+nbDgLfMpLF5DmKOfmuLWvMjnwMCNABEXPOhk14sHX63Ak9erza0sFjnIpVvSUyQtapFTA8rfSA+pzKbUi6F+Hwt/UkmSZtRn1o3L8ygAS71IQDb/Fuo8udZ7FtlfNtUI2iYAjyHNgd5BTAtouX2iXD4Vvn4H5vWDHEB4Zwp/5RhivVL6bFXo3hNWCP4KXSvBsNG+QNNCd5HSrxRl7XWpGK/XRuYFptDVPS5NjFPS0R/a9FF2nqi6VDEA9tMP0hY07d/T5RDlV2u0zKZmTh09lsdWsHmyJHqCBAd7AgKgxbHNptU0vHvZ5Fai7Oa4bC38/pXrndOAf+JSLHqkhT+OLfFkFDcSJP0dBTBZakie5mpEF8VniYkOGuUYT0sZbY+4zw6BRAtboNjTiB8D4cFfUZy1hsmprQhV8WUGOBPUqEn2ZvArFX7Wvs5mbC6KA6fU+rjaCT3Jk6LJFJvkadgqY8nAu1qRN/fA/yYTKefsTqDGmC6lTR4rB9hweVvWIgIGiZ49G5/2Bp5W3PvMPQ2UNZ68Jac5r0jDSzf+KdvLG+1Lr7W4GFUwbYQlPMKLz5Wfz7V9kSelPtpCiCzmHoydbHZ5mlbOLgiOfIutbt3MvJvr8yFmo/SjlcLAiZcirZPq/VSy0gl+k2egYVVLZsIQ7KKPQw6eRVKNL8Si6AAlgFJ21Uioq7ugj45yiURj6GIQVbr8BK+bCftW8dBarORmegU27qKos5c9H0j3N3QAO1RZlxkJks09gu/SDPjDCzyBzdtiKRZ/iQOiegroMdVLOtcx+BZqb4FF15SCRqXCY5z4DGRJo8e3CUTDzkbU8g117U4iCHXaAvJFywdZ6mGhEXzWHueTl6KLxivI8d0uQGsQes0EzTXzVruvS5igXgBP6s4TnmPIuoqsSnwBLkGFgFgpKn19ZA7uHbozDicbnv9mz2rTKhMGH8smuzbM6HBYh1EpQ7JFvJmZuipr3j7qkCcyAQfCVZneziaNKaC8O0X2nWaXioBf24BBLlA3Dnt2VII3nPzaSmdX+TIIACWKlJeyZwUsvfJKu5R/OIP4cu9WarxB2NnYxawDd40vzPRS4Vw43X54rOZa+7xI3/9+33CekECzsuNXn4IK0K/kRAxZeuzG7jtsBCqlQpzDtLky8/HjrxQh+aOU7djCL1wgoPyr29OHrbwV7VSWS+cs23nRM0oWnR34oJIci/jftpQhj3iAAxaI9oPGHiWSU3kSdwdaF5tamogza+jmZqFREgatzHTPPJ3p8jgX0iCzNpvvkSU7PzOSPNgAa0lAzfH3rwzP1Nnb70v+MmzVLY4Cxbd2SsCXHZ+Iw6Izy1JQgqidOPaeW7a+OBNbTkq0cBzAnyg6Prv+cIkiocdvzvECKyjEOeZOAmXCb0agYSyjJvyyKVYInc9oFCm4qkmm7Zq3jWBMDZHSewjRK4COeB9VzgJtbWhbKpNjs2ekkctdxqxfsUmSjb8f4RZJPTYcLhVz38MBkmJ4fYh6ZbDwCNMUdJoYzFu89G32yUph5NGTGbKmOKxszBRFUC/MXxyXX+zY9xx/VgtvkB7+d65jqBT8hKxXbBF5806pdYBupSzFqX9E6ng== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: agNJuYndNz9uW1RH54kvYAOagioHuRePo7qcf0EpH9x7g2wORNbdKr7BurC+DGAO9ByQt75kMcy9hCgzECucOWilEemja9VBWdghmbw0JGOtDaFxJqUww3q3dEF2YQFjNB3a4HzqdY388exlPII1Vb+aPpe2ofY5ETi2X1KHZcGvEjnXORKv0iVulMgJ1cpztcjpHCxt7yUH5jTHfBROZ7yA02nsbdNgnOvRfpgHFJ0OqhB7NvypqebMDeMdrRYE+M/BakQjrAt4uXuxP9lR5hvXipR/vvC+dlXI5lhpW07WsBEyyIVcFyvJQ6DLrUHe2kHiZ+h2rMhDw7jME9dsyOxuSuv0CeQX3l5vGFFCRzQHv4mRdiJJRnvzgoTL5eRdjLzq6YYGKNPhfe6ULALtvYHAu/8fbuyPdLG2Brf0saqmIF/wxeyWyJ0PWYmhSx3vIyYbEEK+W4UdMhfhLAGKpAibeP/ohXKMSQCyogTf8lQ3YiO41zOe+Vo8fXOmCG2AeGWdS2/E4E+VvibnvNbsJ3iuWUr6p5XzWHwMdC0vsrNnPD9f/dLk5rEg0Tyz5Brm2uMsbizVR1yfbWBVWs+VQo1DW2XUQbFwi8gzFCg/dj36QE39TMFZN7i2MvL0AJH3VyGpvvlh/jxl0VWHjLUyhRVQGpJl5If+/BbhPbsTIBT2JBzN89uWGVcJQ6bwNXeUE3BSDsFiqe1rBYFLRwqr5X+kt9Kr+lj1wE47wEcYMqxm8ZzDpMwATgJzgJHWN7cUOn1wxH+1z2IOgto3108xlPvVAIBNj3DIRNWtYQJWF8CE7yvvlVoymmm2ZjQsgTCq9keKCCKxK5ILITzJooDv6crvBZTsIL1ZykdBaWKt/to= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75638bb6-d6b0-48f9-987e-08db2b837fc2 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 09:46:38.8477 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rsBsRl6CeJ4Ib8hEDp8ZmS2avfhdI8UUAxkVOjkZPvTmWHEswbxg4TgXVx3h1MtgVuCHVmxSp7Qa2S0wD1qAsA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5273 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-22_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303230073 X-Proofpoint-ORIG-GUID: -LOZwH68QyfTnUJsIIhwjM5HVdJrcdkg X-Proofpoint-GUID: -LOZwH68QyfTnUJsIIhwjM5HVdJrcdkg Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The shost->can_queue value is initially used to set per-HW queue context tag depth in the block layer. This ensures that the shost is not sent too many commands which it can deal with. However lowering sdebug_max_queue separately means that we can easily overload the shost, as in the following example: $ cat /sys/bus/pseudo/drivers/scsi_debug/max_queue 192 $ cat /sys/class/scsi_host/host0/can_queue 192 $ echo 100 > /sys/bus/pseudo/drivers/scsi_debug/max_queue $ cat /sys/class/scsi_host/host0/can_queue 192 $ fio --filename=/dev/sda --direct=1 --rw=read --bs=4k --iodepth=256 --runtime=1200 --numjobs=10 --time_based --group_reporting --name=iops-test-job --eta-newline=1 --readonly --ioengine=io_uring --hipri --exitall_on_error iops-test-job: (g=0): rw=read, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring, iodepth=256 ... fio-3.28 Starting 10 processes [ 111.269885] scsi_io_completion_action: 400 callbacks suppressed [ 111.269885] blk_print_req_error: 400 callbacks suppressed [ 111.269889] I/O error, dev sda, sector 440 op 0x0:(READ) flags 0x1200000 phys_seg 1 prio class 2 [ 111.269892] sd 0:0:0:0: [sda] tag#132 FAILED Result: hostbyte=DID_ABORT driverbyte=DRIVER_OK cmd_age=0s [ 111.269897] sd 0:0:0:0: [sda] tag#132 CDB: Read(10) 28 00 00 00 01 68 00 00 08 00 [ 111.277058] I/O error, dev sda, sector 360 op 0x0:(READ) flags 0x1200000 phys_seg 1 prio class 2 [...] Ensure that this cannot happen by allowing sdebug_max_queue be modified only when we have no shosts. As such, any shost->can_queue value will match sdebug_max_queue, and sdebug_max_queue cannot be modified separately. Since retired_max_queue is no longer set, remove support. Continue to apply the restriction that sdebug_host_max_queue cannot be modified when sdebug_host_max_queue is set. Adding support for that would mean extra code, and no one has complained about this restriction previously. A command like the following may be used to remove a shost: echo -1 > /sys/bus/pseudo/drivers/scsi_debug/add_host Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 67 ++++----------------------------------- 1 file changed, 6 insertions(+), 61 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 8a0fe403e225..78bd393cb2a0 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -762,7 +762,6 @@ static int sdebug_max_luns = DEF_MAX_LUNS; static int sdebug_max_queue = SDEBUG_CANQUEUE; /* per submit queue */ static unsigned int sdebug_medium_error_start = OPT_MEDIUM_ERR_ADDR; static int sdebug_medium_error_count = OPT_MEDIUM_ERR_NUM; -static atomic_t retired_max_queue; /* if > 0 then was prior max_queue */ static int sdebug_ndelay = DEF_NDELAY; /* if > 0 then unit is nanoseconds */ static int sdebug_no_lun_0 = DEF_NO_LUN_0; static int sdebug_no_uld; @@ -4928,7 +4927,6 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) { struct sdebug_queued_cmd *sqcp = container_of(sd_dp, struct sdebug_queued_cmd, sd_dp); int qc_idx; - int retiring = 0; unsigned long flags, iflags; struct scsi_cmnd *scp = sqcp->scmd; struct sdebug_scsi_cmd *sdsc; @@ -4959,9 +4957,6 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) sd_dp->aborted = false; ASSIGN_QEUEUED_CMD(scp, NULL); - if (unlikely(atomic_read(&retired_max_queue) > 0)) - retiring = 1; - sqp->qc_arr[qc_idx] = NULL; if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { spin_unlock_irqrestore(&sdsc->lock, flags); @@ -4970,23 +4965,6 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) goto out; } - if (unlikely(retiring)) { /* user has reduced max_queue */ - int k, retval; - - retval = atomic_read(&retired_max_queue); - if (qc_idx >= retval) { - spin_unlock_irqrestore(&sdsc->lock, flags); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - pr_err("index %d too large\n", retval); - goto out; - } - k = find_last_bit(sqp->in_use_bm, retval); - if ((k < sdebug_max_queue) || (k == retval)) - atomic_set(&retired_max_queue, 0); - else - atomic_set(&retired_max_queue, k + 1); - } - spin_unlock_irqrestore(&sdsc->lock, flags); spin_unlock_irqrestore(&sqp->qc_lock, iflags); @@ -6430,29 +6408,18 @@ static ssize_t max_queue_show(struct device_driver *ddp, char *buf) static ssize_t max_queue_store(struct device_driver *ddp, const char *buf, size_t count) { - int j, n, k, a; - struct sdebug_queue *sqp; + int n; if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n > 0) && (n <= SDEBUG_CANQUEUE) && (sdebug_host_max_queue == 0)) { mutex_lock(&sdebug_host_list_mutex); - block_unblock_all_queues(true); - k = 0; - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; - ++j, ++sqp) { - a = find_last_bit(sqp->in_use_bm, SDEBUG_CANQUEUE); - if (a > k) - k = a; - } - sdebug_max_queue = n; - if (k == SDEBUG_CANQUEUE) - atomic_set(&retired_max_queue, 0); - else if (k >= n) - atomic_set(&retired_max_queue, k + 1); + + /* We may only change sdebug_max_queue when we have no shosts */ + if (list_empty(&sdebug_host_list)) + sdebug_max_queue = n; else - atomic_set(&retired_max_queue, 0); - block_unblock_all_queues(false); + count = -EBUSY; mutex_unlock(&sdebug_host_list_mutex); return count; } @@ -6881,7 +6848,6 @@ static int __init scsi_debug_init(void) ramdisk_lck_a[0] = &atomic_rw; ramdisk_lck_a[1] = &atomic_rw2; - atomic_set(&retired_max_queue, 0); if (sdebug_ndelay >= 1000 * 1000 * 1000) { pr_warn("ndelay must be less than 1 second, ignored\n"); @@ -7519,7 +7485,6 @@ static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) struct sdebug_queue *sqp; unsigned long flags; int queue_num = data->queue_num; - bool retiring = false; int qc_idx; ktime_t time; @@ -7553,9 +7518,6 @@ static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) return true; } - if (unlikely(atomic_read(&retired_max_queue) > 0)) - retiring = true; - qc_idx = sd_dp->sqa_idx; sqp->qc_arr[qc_idx] = NULL; if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { @@ -7566,23 +7528,6 @@ static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) return true; } - if (unlikely(retiring)) { /* user has reduced max_queue */ - int k, retval = atomic_read(&retired_max_queue); - - if (qc_idx >= retval) { - pr_err("index %d too large\n", retval); - spin_unlock_irqrestore(&sdsc->lock, flags); - sdebug_free_queued_cmd(sqcp); - return true; - } - - k = find_last_bit(sqp->in_use_bm, retval); - if ((k < sdebug_max_queue) || (k == retval)) - atomic_set(&retired_max_queue, 0); - else - atomic_set(&retired_max_queue, k + 1); - } - ASSIGN_QEUEUED_CMD(cmd, NULL); spin_unlock_irqrestore(&sdsc->lock, flags);