From patchwork Mon Mar 13 11:10:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13172266 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 3BFCFC61DA4 for ; Mon, 13 Mar 2023 11:11:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230141AbjCMLLB (ORCPT ); Mon, 13 Mar 2023 07:11:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230130AbjCMLLA (ORCPT ); Mon, 13 Mar 2023 07:11:00 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A6D25D8B1; Mon, 13 Mar 2023 04:10:56 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32CN2m0T027099; Mon, 13 Mar 2023 11:10:44 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=rgfVvGUoXO5A/cySkwEaPA/9Kk865j2gO+lEXo5cKZk=; b=SixkXK0W3C5guBtnV56iHDvoqe2OjAf93f39jrZCpN7MC1nuMqCvnh5lxn/iElkjF9qX cUwgcbM8vhrS/EB+pLgE1tn6jHmRRQGjRYaOn1/DPvOVsYX8utu4AmNMmJn2P9j6QHBJ wOEEpaii6kxZJWLaW8nmnNBBPmZOdgKiDLOFVh4rX666b5q6SjnDOgx1FhpFNGHpomEQ 2+uULL4xb2P/5F48SaGZC7WO9vNaW6vd5gjezQtQlEmViaWhLxggiDmOZ3HBJKixcYFx F9mg2dYFmhF9lK0aWSZch5vk5d7CVPWijUWPabasX6wdH9k8jnUOf8LEBE97yrhtxz48 Ag== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p8j6u3h7k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:44 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32DA5Xnl002375; Mon, 13 Mar 2023 11:10:43 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2049.outbound.protection.outlook.com [104.47.66.49]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3p8g3b0k85-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W6x2wppzFP51+127CfLylSbCs6yPpyApSoVh8gxturQiMWTbk+AkkRge9WqalBComVJE1o6+ec55g2u4BGsXVXXCTsy8m1lIfeLcBvMqzmIOG55p5DbOl6VLfvkcO+PCJLZKsRMmfPA2mssGB3fmqn1Ca5blRzHF2Ka7jN3RUYWh/ImbwdrM5AKict7TscbYPPHb4lPj4qhJE1BkXUf/LixqnpHRV9d617ZTrK1b1Ffyqm4QjM8gdifZCTFgoZkeg90DiJaJQnQs7NiCxMxgIws6FuD/uFRvED9AnTx4kOFOqtJ8A5WB7rfUgAMaKRNnOl1HNWR6HVN0HeLIBw3Wmg== 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=rgfVvGUoXO5A/cySkwEaPA/9Kk865j2gO+lEXo5cKZk=; b=Jv0z2yllaOVownH9EG++A8H8E+xnDhsMrZGEF/BaeB1KoIMZSGXrGZnx3lN1681MYF9/5Le0Op0bPz4RRAubQ4c0aEXl7ll+n4kIQe64eL/l92igEFBi7qNaW5kJ81b3OGssSzBMG1H5HreIY0Bf40pufXDE3c//ZL0RM7QkKGl9u7oi6uIQIOb0ZH4MjtFHmdM9qV795Dyy/d8wFF4qMOrWlFuWNmLb2CafgqXnOOw24L7uTlJ8rbtano2osMLZD69rQmUUTiZkWoC/oW7RmZhrk3FhforlWZWYv3P6gPBmdE94NijynSF76yY3S06NGpsWy+3rdrFgnPxx4ZxUWA== 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=rgfVvGUoXO5A/cySkwEaPA/9Kk865j2gO+lEXo5cKZk=; b=aLq96P7cB42vQnldW/iaY+nmqswxSkzV0iuFn34bStvY1M+9yrXMvk2K4JzfvE0PYTnw9FtOgooe0ayUGRsInx76lJ5FjCdEtMimcbE9CAjWK618Oa5yBpo2m/SOHSd0PT7aDUCTTdVA+wKeT9YR0VaZEkjNtq6xGT+4YKIr4cY= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ2PR10MB7672.namprd10.prod.outlook.com (2603:10b6:a03:53e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.24; Mon, 13 Mar 2023 11:10:41 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%6]) with mapi id 15.20.6178.024; Mon, 13 Mar 2023 11:10:41 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, hch@lst.de, dgilbert@interlog.com, hare@suse.com, ming.lei@redhat.com, bvanassche@acm.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, John Garry Subject: [PATCH 1/9] scsi: scsi_debug: Don't iter all hosts in clear_luns_changed_on_target() Date: Mon, 13 Mar 2023 11:10:11 +0000 Message-Id: <20230313111019.1521680-2-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230313111019.1521680-1-john.g.garry@oracle.com> References: <20230313111019.1521680-1-john.g.garry@oracle.com> X-ClientProxiedBy: SN6PR08CA0023.namprd08.prod.outlook.com (2603:10b6:805:66::36) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ2PR10MB7672:EE_ X-MS-Office365-Filtering-Correlation-Id: 7562f3be-4e5d-4a75-5ba1-08db23b3951a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r4EMYFJZtwg4DY4QrXL7pBuamOcRSZKwyoUwUmVsmFPl3jP4K1wZEI0tcxKRUW+9dwQPzo8iyo1oBcI7lNOz/0fSYXaoz+u4Pmotix32IiqoE3Or2CwgmAToUCMXKQv7mfhnNxsE68doj/b/KvNSTDIDpjCrwTdP8h5hcQzyK2UgVjJh5GZXoiz3xGhPZb1lWg3NtbossW9u9t4eBX6QqDzQalp6txhuHFMz1UeamVM8D8eEHS8dzg/8vc2ompaXTwtHJ8Gpel+C1IqC04B3b7dCbf+M88Pzs+LHsM1I2Rrs04FWtimDmBKU3QROiWHsbgk9MQ9wuD75TZtIzEhNeuFy28uIZumHAsamC/de3A0omkW3GHFJR7b9CYcaO+RcKu0l4zM+DBfLDadcwbF4Iu+a+aet7DGvM0jYl1XAaV06OfkWraMJ6CzQ7T7rtigxAoLJQppsCLz02rrYO7tjQAay17a8H1176KSeUc5Ky+Msdd9gFBuJL4oYVbD5m52QTb2A/YC/vVoYjiB+1y30BMP4ZF3nDv95N3/qYjV7ZeDeMRlmngAotTffo6Pa9ZScxVQObkGsTpBY/dMTcH3pd2DdeELCX4B5uvFfDvUagErZne69e0V0UUiZJZxEb6xEjFKUPYtgLVDwgIVC2cmrKw== 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)(39860400002)(396003)(136003)(346002)(376002)(366004)(451199018)(66946007)(66556008)(66476007)(8676002)(4326008)(316002)(8936002)(5660300002)(41300700001)(6666004)(107886003)(6512007)(6506007)(26005)(1076003)(186003)(2616005)(83380400001)(478600001)(6486002)(103116003)(86362001)(36756003)(38100700002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IydlCYLTB6zH8FqfPotZl1jm0SHGnH6H0IQl97J+SHCKi505eLXM+wkc62X6Nfz0pAanRJp8x5RTabKku2I/89+LsWaVV47fNJ53UbL7dlDVtQGmM+vH7Z6q8cBiNr4tyyK/VamR1Teo3slla9dweiyKufjvP1F9BlOkkPKnmrTdPSliHVkD1erwvp1nESnopfmBP9gjGINr1AduO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Mfp16bAHEvM2W7kk5l5SiIi+289nO4Hl3HmDB79bRFe87J7yDYRMZCKgRno3+sNonWxN9bWdBtC8kUtMctYQcOIDMiX4Hpepc4nOd1JM/K6GbHwYTqymKAndYKn1+3+8WAFU4qtj0s0nlE/Sjre5m+RXTIUiYjlvVmu1BDSNshYZrGODAwP/UV8MW72ZXSUWL4JrBTr/JXOKwqDY+8Ky4/w4PfoAzqRol1CTvaX/vyDzpDMsvvDJwJkVqz4zpiw9TGnC6yVeX2y37o= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7562f3be-4e5d-4a75-5ba1-08db23b3951a X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2023 11:10:41.2113 (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: yENFQFLdBuBPlhyVxG87z6OgEWk25g+slLwXwwmr/yWWA0JZuKCdX8qgpZuv2HFtdss2/rn8pWpXTTltU5NfbQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7672 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-13_04,2023-03-13_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303130091 X-Proofpoint-GUID: HbrYbHoRJDi4Glp0xYU1Hl26jTmYNvpw X-Proofpoint-ORIG-GUID: HbrYbHoRJDi4Glp0xYU1Hl26jTmYNvpw Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In clear_luns_changed_on_target(), we iter all devices for all hosts to conditionally clear the SDEBUG_UA_LUNS_CHANGED flag in the per-device uas_bm. One condition to see whether we clear the flag is to test whether the host for the device under consideration is the same as the matching device's (devip) host. This check will only ever pass for devices for the same host, so only iter the devices for the matching device host. We can now drop the spinlock'ing of the sdebug_host_list_lock in the same function. This will allow us to use a mutex instead of the spinlock for the global host lock, as clear_luns_changed_on_target() could be called in non-blocking context, in scsi_debug_queuecommand() -> make_ua() -> clear_luns_changed_on_target() (which is why required a spinlock). Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 52e33ecc6122..6e6eca694bb5 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -1063,18 +1063,15 @@ static void all_config_cdb_len(void) static void clear_luns_changed_on_target(struct sdebug_dev_info *devip) { - struct sdebug_host_info *sdhp; + struct sdebug_host_info *sdhp = devip->sdbg_host; struct sdebug_dev_info *dp; - spin_lock(&sdebug_host_list_lock); - list_for_each_entry(sdhp, &sdebug_host_list, host_list) { - list_for_each_entry(dp, &sdhp->dev_info_list, dev_list) { - if ((devip->sdbg_host == dp->sdbg_host) && - (devip->target == dp->target)) - clear_bit(SDEBUG_UA_LUNS_CHANGED, dp->uas_bm); + list_for_each_entry(dp, &sdhp->dev_info_list, dev_list) { + if ((devip->sdbg_host == dp->sdbg_host) && + (devip->target == dp->target)) { + clear_bit(SDEBUG_UA_LUNS_CHANGED, dp->uas_bm); } } - spin_unlock(&sdebug_host_list_lock); } static int make_ua(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) From patchwork Mon Mar 13 11:10:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13172268 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 2F5ADC61DA4 for ; Mon, 13 Mar 2023 11:11:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230301AbjCMLLT (ORCPT ); Mon, 13 Mar 2023 07:11:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230212AbjCMLLP (ORCPT ); Mon, 13 Mar 2023 07:11:15 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C69D937F3D; Mon, 13 Mar 2023 04:10:59 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32CNmDdC011721; Mon, 13 Mar 2023 11:10:47 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=lIcb29IVQ0WmJBpSmHrLVYnR5uAVBvUoMqHimF8gMqk=; b=NRAenYvhy/JWM1YwOgFbotdoMGQtR9bT2mlwPkr5pPNDrekidcXdh7wztUYN5Jtxx2nD tAp1kD8xwJoobcmD5tHMpD/m1zAlbRnWflaGf4LKjre6iIN4BKJfOs0c38C3mcei1T67 +dPnwkxv+2KL6VvOUG5WFjzTIwjLf4U3kAM74oyBHIyESy9sQzXXJ1UZoAny4eBfi26Y 4Z0QVJSIOB/UsIPqWPPcZfYMZHQzll6O+W7EK6MowT8/xwdqz8IW8W8IJzIMCDszg2hA izJHstS1ZAy1HNmsMDeubU6qSyDRJs+erlqgSDe0xQW+6+jzGXBzxVHAxmqPyTgzzNaT Kw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p8j6u3h7q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:47 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32DA39YD007583; Mon, 13 Mar 2023 11:10:45 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3p8g3b8jtr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A40fbWxEvFgvGAe7KQ+SRQ+0BfUI3DqgqxZjCAJgrnEFucAagKp6T4V1Lm5cn8T+kGM+n8RYjscwWYLztK5hyP6C0OFzSWVYp+g2UVt/2qVSnexnLCzOZ3weyekJIejaTfmDmHx1XBttE4K3I6Q0T2LtrX6m98M9bXytrRnBIsz0Dtoe4Ju+pGB3zTK2OgeR6yAGSsYssH8EC1Ric652UFW8O0KLsEWbo2bfxnLOQ20oaUWFvz64NOD9Di88xN9rseqcuSId062/AvPANWJrLcftHOM1dedAtGsqCu55EAlAE+yV8VhXUk9lyTkM3aba2bV9zGgXQVNAX8g7j1I4DA== 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=lIcb29IVQ0WmJBpSmHrLVYnR5uAVBvUoMqHimF8gMqk=; b=DFaLlz+zrfdwA+pzdPCln9jHhfZ8ZbeK60YbxGmlISSy7KGQVzBbtmPmK/BtvasUlMolDhhBMqUaiztD6JatmjfAhmtt4Jstzk40Fyh7PUY5/+AApLUPuVHH2FNe4ZNLAMA6FZkpSj3Pi3vz9j2602juHBQ0xCDfQ3kYcVcG2gy2x1KGxPxTcSOT1mxvJPYmTmYAHwgfnm/Mse2OtahrZvwfZwJuG9h7LU1Z3Xjq0uYeCUQ0NhLGoM6hywxqUpEzxE4toOGh5tg/fxW2QFLgBHc312KqqXFRKXI4jN/zQxkFgg5HBykSTX2P0jwGvWJD15s507nEt9ejNLk2EXAW1Q== 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=lIcb29IVQ0WmJBpSmHrLVYnR5uAVBvUoMqHimF8gMqk=; b=r5mjM9RQo+KT9F4FnONnDuEzec5eY0D9m/7ydrhz1nltJBahaal0pv7qNPcpeJCdPjQR5byTSU2x6kqSWFQJsHR/f6jQkwRqH8drdYMeuRXR0GFoQKuhLX5f2haSIz4j5jR4Q3dTx38fOso4hSr4Kn4b9JvWQWVOQN/Hbx/rkCk= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ2PR10MB7672.namprd10.prod.outlook.com (2603:10b6:a03:53e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.24; Mon, 13 Mar 2023 11:10:43 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%6]) with mapi id 15.20.6178.024; Mon, 13 Mar 2023 11:10:43 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, hch@lst.de, dgilbert@interlog.com, hare@suse.com, ming.lei@redhat.com, bvanassche@acm.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, John Garry Subject: [PATCH 2/9] scsi: scsi_debug: Change host list lock to a mutex Date: Mon, 13 Mar 2023 11:10:12 +0000 Message-Id: <20230313111019.1521680-3-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230313111019.1521680-1-john.g.garry@oracle.com> References: <20230313111019.1521680-1-john.g.garry@oracle.com> X-ClientProxiedBy: SN6PR08CA0002.namprd08.prod.outlook.com (2603:10b6:805:66::15) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ2PR10MB7672:EE_ X-MS-Office365-Filtering-Correlation-Id: 08954994-0eb3-499a-55c6-08db23b39680 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AslqcHWPk45G0sIGhdGhYJdfgzFK7fat+y9RvEl/H/nhMAdANgvBbKDNDGcG349YKBja6CP9YlhOqHeixpDjsqDfDls2OoFUAs3kmki2TzcvNo3EoXeexI4qM4s4QlEZy5I4bBoBYy5diE8CiK6Mwpj8eY1P6S95xmti8cAJBye+5NpHR2DB0pfASir8rqWUIPPG624Dh4R1Bm3ui6baDCgwZtxnNEBN/kvtoa/L/zap7s+a6hkzzABS1lEZyB5LztJUbGShniMBzqdBiXPoEjHjD6/n+Pi6o1cNzB0kYMO/n4ok6Jk9+fcz/IDDEyLFdai+mYtvBXujd6Kv6LmWM1IFE5T0m3NMasjUlFLIaYlO4s74EBZqA8Nir+QNsrq201WhGHlMWmJwAFEW2dfWma0VBPqi71lJ69nqj4Uf1EufIXrWK0jMrQIKgu3sR0Mm+tJCaJcujti00Y13QpcA/3O9soYIj78BwfTfZHKpsoIUV5AumMYdyA80iAQomDLxUhiBtxD0DGD+W+BVwZVF5OpFOo/9YTMQe+xaYh2010qGDALMldF7jRc4khwWoKvAWkadFgwivnTL/Wne7Yt1htRkQXHYwl0+NSWJr8GWPT1SFidD3/WELjhjm/T3eZ15lSFQp1e1NKl3m49C8834cA== 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)(39860400002)(396003)(136003)(346002)(376002)(366004)(451199018)(66946007)(66556008)(66476007)(8676002)(4326008)(316002)(8936002)(5660300002)(41300700001)(6666004)(107886003)(6512007)(6506007)(26005)(1076003)(186003)(2616005)(83380400001)(478600001)(6486002)(103116003)(86362001)(36756003)(38100700002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: I6dpIDE/DuVbUtcUXcqeuF4kVSQINGWB3PBzGN2naAqYESk/mIerW0XVk2U1692xkc/YFgILIt8S3poLo6WmaKEUpI1E2Rmqnjsu+ni5k166NsXp288RBGx912xWg1NfbjR1/7tROo3w7NBmfSWhLb5MsctUm9/sB/a2uPG7QrznXPoAWezFJFCXLIzWry/mqeaQ8FwIAA2OtncDmNh3HPb3beh1z3zB565MUs78f9dUWp0ZUF5twIRfzBpORXYxFD9ypQUXxhrXDAvA2ZlooEWI3zOPrCXVX7ySRxahR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paNqvs3qGTKXLkmJYAa8GbatBcbMihEVXSvGuzEZcfuH5gvlpNx6bbvHoMQmAXFdXfJs/TrOFrwqKgbeyNqevf4A7D420Ify2Eul/G40xqUWO2XiBT16bSLWnk3E7zMVHS2t6cASONMkr4knN3z6vfVHnPXm8ldPdq1kGTQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 08954994-0eb3-499a-55c6-08db23b39680 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2023 11:10:43.5272 (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: DeeM7PFV4YBgGriwseon3j0HkZldyUxAtFl9w/ffqfDTEr0usgll0g2hwvAfdjBnluIiEv0TBFXLCkKoVMW2dQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7672 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-13_04,2023-03-13_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303130091 X-Proofpoint-GUID: VEoyahrgcChEDwkojuDX0vOJIkVeE06f X-Proofpoint-ORIG-GUID: VEoyahrgcChEDwkojuDX0vOJIkVeE06f Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The host 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 6e6eca694bb5..711aff1b4258 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 Mon Mar 13 11:10:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13172272 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 7BEAFC61DA4 for ; Mon, 13 Mar 2023 11:15:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230453AbjCMLPo (ORCPT ); Mon, 13 Mar 2023 07:15:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231244AbjCMLPL (ORCPT ); Mon, 13 Mar 2023 07:15:11 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 228D4E388; Mon, 13 Mar 2023 04:14:23 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32CMgpIi030831; Mon, 13 Mar 2023 11:10:49 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=qBek8aEeVGcHmQdGCFkM3zwMwz52I7bLMI+rszc1Txg=; b=J5iGl7I+WC7qU0sSOcPowrHtdEcjyJKyB7AJvgtlAdtiSQWY9cC0LtAeNP2+I2UkJ3HQ nu17vihQX9MeeNUe0QWSv5TrtdYqO3qK3yR957NEWQoMVJw6hRacuWT3mclVUkAsHnZo NYn9zKk5icarolJg0nBbibAmladbWnCwnP0kinYsDerntZREGWRWwFrlP2H1qy4JYBkv ubI6YTky/JHRtCcIbm08SI3DNf/0R12drYrET7a1p6u0XBxSv0yFe0LK0xw6rpYbSXyq wbZi1R4ENTQ0w7Kp2lz2d9kx5FKoqs+X6j2qGumDIWHCgofwmhzflnNILV4cOS9mAPmS Jw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p8g81bkrs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:48 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32DB0QKl002455; Mon, 13 Mar 2023 11:10:47 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2172.outbound.protection.outlook.com [104.47.55.172]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3p8g3b0kb3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FQGvnCl6SzQyMslz+hg+r6nZkqQbbkkdMKoyrJSPZe0CGzwTvCzqkosix5UQL17FRvdex/UTy3k4p1VYHBQ0z8RPrQCpUnd7/v/FCucAMxQUc40wJVTkueDV91hUGxa7H0q0xjF0k3dvyTsXF8i3sjeyQfCBngnj648PcIdhrsr5xu8TTOVF0Zn+SoeW/SiEpmUzzxodCbvewpvdSHtHVOOG6zqbPAj3CoX7MmvPpnWqo0A99GLOGdcyLnw0HNx9JmBE1KSmZ3V9ACnnQIk1ho+D+ritaEkqQyI1DKa4ypzvDOW8W+uQBP2rH29lZcGD5vjWACx4khUGb2LZ5GrBmg== 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=qBek8aEeVGcHmQdGCFkM3zwMwz52I7bLMI+rszc1Txg=; b=REwDZxxDKq1QCu+2mSC+cZy7YS4nfQ4TUfndD1rTnOI+ghWwCjWwuT17nCAmy+PUIy+VMOcFvnfXV43dhmFw+4NGcl53ShTMorUtiDJHeAqrH6HnaJ0OwTltKnszzjfYpIieGuGcid+uMXj1vIuO8NmmFDDDVujE3a4hgr/qngd7j4l6sEGTO4JKYF609mDokKe54hCNGEQqlTKvrYCqAcmZ4d3MvWAZ1PDoyq4dM96PTRGn1aMSP/RSHJmnOnKXzaFuCDiwPV8r+059oTC9ghKTdKz9evF30C31w6NgWflMaCXuaeJwe+AgenPomDxOzm2lZr/bC7r3YdWSKyJP7g== 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=qBek8aEeVGcHmQdGCFkM3zwMwz52I7bLMI+rszc1Txg=; b=IDR9hyCtXO31O7IrIzwNSbpLBKvFvcviOFTlmQnJQj0ktPRo29PtfWsiXZjgSBRhIWKelKKfd7suFWgLDqTmY+VgQw5qziODP6t98SaXt224ZrZZIiQy8zj4ppo+OHCBN+/yotibNFJHbwfW949+uYbYQsQw5Neoz+EbleLaLro= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ2PR10MB7672.namprd10.prod.outlook.com (2603:10b6:a03:53e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.24; Mon, 13 Mar 2023 11:10:45 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%6]) with mapi id 15.20.6178.024; Mon, 13 Mar 2023 11:10:45 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, hch@lst.de, dgilbert@interlog.com, hare@suse.com, ming.lei@redhat.com, bvanassche@acm.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, John Garry Subject: [PATCH 3/9] scsi: scsi_debug: Protect block_unblock_all_queues() with mutex Date: Mon, 13 Mar 2023 11:10:13 +0000 Message-Id: <20230313111019.1521680-4-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230313111019.1521680-1-john.g.garry@oracle.com> References: <20230313111019.1521680-1-john.g.garry@oracle.com> X-ClientProxiedBy: SA0PR11CA0070.namprd11.prod.outlook.com (2603:10b6:806:d2::15) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ2PR10MB7672:EE_ X-MS-Office365-Filtering-Correlation-Id: af2722a2-3ce0-473a-533e-08db23b397a3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AciIa62oCgYTFaKF5StbCupflN2I88Nq+Q/2ySYtOGPLB/XqZ9VPfBLmRJqdhnfAVLInC7zE/Ox8+yuZeY0nuzt10azsmjcS2cyfs2kk4SJENrcSmiLtb9LJesgGOSxIOnPcq8R8KHTm2S+HU09LfiHlNl6D+QQVtUWYtULYP/rTPKYtIXeoD5AlXdYcPxeI7EGN0b8GnBZVK8mhGq6zYE+KqZVoD1EC0fQhcKQTls/KoN+Q72wJ9dyEwXCjYob8mTVlMukzxHoexDULIwV4aG9F/LkbvBA5Gjfu6HUWSI6K31M6X8eGOb2J0G9Tj2Bya9uzVDpIxhVh+4uAerPCmlrkLc4V40L6DnNRaU8yKFCZrEsJ9B8TJi7FOU2iIpN1VeCeuPWEFem0achiA0BWiVVPTcYLYR7HKpwmQPrAh89aFrd3fhbvF2CkyFrG6xvbv34E60EdcQUK4NlrUisdr+hsOYsSbrPZAH7rTK/bsNQ5vQg9YBkxcQzb9M0auLCyh3NZkjnqNVbw19F3NPb3m4/7tzbSoixwbykmew6si6xeQj4gCM96FuCaiaNZk/ZiQn5tB1EVpt08NcYA/0WHrv5r2HSCjgte96wPqryspuihbHe8CiEPW1TPMPPIo4aiSRjBhVyDjqnLRD20VmVMtw== 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)(39860400002)(396003)(136003)(346002)(376002)(366004)(451199018)(66946007)(66556008)(66476007)(8676002)(4326008)(316002)(8936002)(5660300002)(41300700001)(6666004)(107886003)(6512007)(6506007)(26005)(1076003)(186003)(2616005)(83380400001)(478600001)(6486002)(103116003)(86362001)(36756003)(38100700002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +KHhzbAT//2QzghGIIhYH5PbEE/J61N9DeJR1C+dxWiTFvPWhoB3JHrAibSrc9ndk2I7GqqBwgNsvpHxY9/3siRRB5JphjKA4l/elPaNBCAynWHku+kfVf4TDerOKRRRCw4sTZkh1pBzxGuMknk1nUcq/xqk+Q3RMYW5uEv0whgPRo2cDA3CEbs/QeHu8+PMz1BL+n54eaf/obB4nwRJzrv3Ah8iXKHchlUzd6Iqj0KMrbmoMit78p2yxEbe2bDrAYhrfLcogO0yoDzK/6dIlOpWB+QaPd67SzLxU3YloAD0Z1au+Pva2PA06NsIUp1FXi9+IvmEjl5k4tQ9IjSLN7TAlIpKFK5J6HK9dg22yLRERVJCmMLdFUwOSSVn5FtFj/ndTX/eLSiTobtxpFcWl8bPtb8T/oblSSSkIqDnJ1HPK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4rWYbhd/hVjCb/HWOB3SB0uLgShJKoZNYzcmLM/ePCWKWAUQMsJOBxc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: af2722a2-3ce0-473a-533e-08db23b397a3 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2023 11:10:45.4656 (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: xICXIoCrVnqoDqZVzWFYNg636pH/iV3iSY0aSpeLpyBeyMUHnlap5DBzbkEMKkMrj6Mib6lYJuSNW/Pv05Rofw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7672 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-13_04,2023-03-13_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303130091 X-Proofpoint-ORIG-GUID: qzdzWcooA2w117xqfscZAqXtFCbtvx9Z X-Proofpoint-GUID: qzdzWcooA2w117xqfscZAqXtFCbtvx9Z Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org There is no reason that calls to block_unblock_all_queues() from different context can't race with one another, so protect with the sdebug_host_list_mutex. There's no need for a more fine-grained per shost locking here (and we don't have a per-host lock anyway). Also simplify some touched code in sdebug_change_qdepth(). Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 711aff1b4258..ad6002c28b6b 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -5497,6 +5497,8 @@ static void block_unblock_all_queues(bool block) int j; struct sdebug_queue *sqp; + lockdep_assert_held(&sdebug_host_list_mutex); + for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) atomic_set(&sqp->blocked, (int)block); } @@ -5511,10 +5513,13 @@ static void tweak_cmnd_count(void) modulo = abs(sdebug_every_nth); if (modulo < 2) return; + + mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); count = atomic_read(&sdebug_cmnd_count); atomic_set(&sdebug_cmnd_count, (count / modulo) * modulo); block_unblock_all_queues(false); + mutex_unlock(&sdebug_host_list_mutex); } static void clear_queue_stats(void) @@ -6036,6 +6041,7 @@ static ssize_t delay_store(struct device_driver *ddp, const char *buf, int j, k; struct sdebug_queue *sqp; + mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { @@ -6051,6 +6057,7 @@ static ssize_t delay_store(struct device_driver *ddp, const char *buf, sdebug_ndelay = 0; } block_unblock_all_queues(false); + mutex_unlock(&sdebug_host_list_mutex); } return res; } @@ -6076,6 +6083,7 @@ static ssize_t ndelay_store(struct device_driver *ddp, const char *buf, int j, k; struct sdebug_queue *sqp; + mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { @@ -6092,6 +6100,7 @@ static ssize_t ndelay_store(struct device_driver *ddp, const char *buf, : DEF_JDELAY; } block_unblock_all_queues(false); + mutex_unlock(&sdebug_host_list_mutex); } return res; } @@ -6405,6 +6414,7 @@ static ssize_t max_queue_store(struct device_driver *ddp, const char *buf, if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n > 0) && (n <= SDEBUG_CANQUEUE) && (sdebug_host_max_queue == 0)) { + mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); k = 0; for (j = 0, sqp = sdebug_q_arr; j < submit_queues; @@ -6421,6 +6431,7 @@ static ssize_t max_queue_store(struct device_driver *ddp, const char *buf, else atomic_set(&retired_max_queue, 0); block_unblock_all_queues(false); + mutex_unlock(&sdebug_host_list_mutex); return count; } return -EINVAL; @@ -7352,7 +7363,9 @@ static int sdebug_change_qdepth(struct scsi_device *sdev, int qdepth) if (!devip) return -ENODEV; + mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); + if (qdepth > SDEBUG_CANQUEUE) { qdepth = SDEBUG_CANQUEUE; pr_warn("%s: requested qdepth [%d] exceeds canqueue [%d], trim\n", __func__, @@ -7363,9 +7376,12 @@ static int sdebug_change_qdepth(struct scsi_device *sdev, int qdepth) if (qdepth != sdev->queue_depth) scsi_change_queue_depth(sdev, qdepth); + block_unblock_all_queues(false); + mutex_unlock(&sdebug_host_list_mutex); + if (SDEBUG_OPT_Q_NOISE & sdebug_opts) sdev_printk(KERN_INFO, sdev, "%s: qdepth=%d\n", __func__, qdepth); - block_unblock_all_queues(false); + return sdev->queue_depth; } From patchwork Mon Mar 13 11:10:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13172485 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 8A533C61DA4 for ; Mon, 13 Mar 2023 13:08:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230354AbjCMNIT (ORCPT ); Mon, 13 Mar 2023 09:08:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230229AbjCMNIP (ORCPT ); Mon, 13 Mar 2023 09:08:15 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A9907DBC; Mon, 13 Mar 2023 06:08:13 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32D0r84u011810; Mon, 13 Mar 2023 11:10:51 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=XHlX712xm68FZo87Tb53dlohUvNpiY8pf4sl6s6vR7k=; b=YNkTG/+fPFd/uqEuoFvJo8il2rk1qFk1po2lUB4JpjRFW0cDfzOn5POcnpb5swONTltS PfPdwcVl1oPV6JgyM7wZTqe0uywBgyhHjWxpfOwSF7y5TnN0+gZo41ScTKSwlwfW8kWX D2hG+qpFtA/d/JWP7XZ5zQjhg5h/o+/rrc9nli3lxgxacMzbkv0mz4fY5DuGJvImi/RQ pVSNFsF8jqriBBzAJdShejHEswSEwQkqpVQEJROUui9t2ImUAUv4dVHxwWjagyEVgEiu rpcrscvezlLEzSALtES/jN8dUwJzmPkZsbhnVy0vZFk3vuh4wmgovqt0SJefVdSURXBb ww== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p8g81bkrv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:51 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32D96hwJ015289; Mon, 13 Mar 2023 11:10:49 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2046.outbound.protection.outlook.com [104.47.66.46]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3p8g3509e6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IGeZzh6QRpoaMNJmZ/WFqhGiCKqpqTrrneyVels08Ax9g/u8HWGh5OTnMn1b62wmVkO75+EDm9PRzVTdrcI4ggP9PpZFM9AXpkT1wQy6om4zOp+VxMGWcJXY7IqK2+Z5W4Ut6RbsxGVqJI8Bk4Jhsgqpim37tV86k5vzGwnDjjrViR08K44dumB5ULrNl20ZCxfEQrhjgQuE5VkZxqj94nAABKjHzHQDPAjB1zTWXKMzAk9FfsOApC9+Iz8KKqA81ZcVthUe96rf2DhdgaPIBbW5DX+/7CdMY0YbAQUvcYxt/llZ0878Alu0pqxSLRC8LvA8FAlMIFwlYJZmm9/kPA== 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=XHlX712xm68FZo87Tb53dlohUvNpiY8pf4sl6s6vR7k=; b=oeJSpYiQyEmnli/2wk/7ge9o/KtWT2M8zxlr+k39mJPQP1dyA1st0QXj6OwJzcfeCJhaFSvF7IE108AnDPdkUBChVELFESsSEcIIrZAG7PRM1PwbzES6lkDV7c89RoaddM1ksO0YwHGekyFjb0CL8mzC7Pl0J5UEKFyc2P9oJD+zfKV/C3KsPYTlkZGIbWEWHO2py2TG/OP9Xo1agLzcS+QbBVZ3WInEWH0HZGHy8av6+dezLXzcFWRg2GQCsGltEz+lzxPKTG/Co2ndFLDc9zempHjMqKj1cG6Hpl8+/qrH9kP03+1gWHUXQwApvWH3N7GaY0BbC2b41ZCzgOoz/A== 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=XHlX712xm68FZo87Tb53dlohUvNpiY8pf4sl6s6vR7k=; b=ruzmXaDrly1tgJalHfY5E8v+Py3BtxQFMV8aasHv1WA4NntpAHSkXN4KxfrW4Gehb23+e7FgIKrPJFCFUJc/b0NS9MZZl1AahqBSET+nvPi0NxO13SoD3COLzbtvS/klbisAeMYcNl2Xc1/O3s6vmTj9Sri8LN1VeLtwrHYkVx0= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ2PR10MB7672.namprd10.prod.outlook.com (2603:10b6:a03:53e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.24; Mon, 13 Mar 2023 11:10:47 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%6]) with mapi id 15.20.6178.024; Mon, 13 Mar 2023 11:10:47 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, hch@lst.de, dgilbert@interlog.com, hare@suse.com, ming.lei@redhat.com, bvanassche@acm.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, John Garry Subject: [PATCH 4/9] scsi: scsi_debug: Use scsi_block_requests() to block queues Date: Mon, 13 Mar 2023 11:10:14 +0000 Message-Id: <20230313111019.1521680-5-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230313111019.1521680-1-john.g.garry@oracle.com> References: <20230313111019.1521680-1-john.g.garry@oracle.com> X-ClientProxiedBy: SA9PR13CA0147.namprd13.prod.outlook.com (2603:10b6:806:27::32) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ2PR10MB7672:EE_ X-MS-Office365-Filtering-Correlation-Id: fa4d4c4d-b23b-4dae-3a2a-08db23b398c1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dHCpRRsNfvHUyiUgVeSTNC2oZUIj+wmYusIwRTAb+1c2j6XP79C7RJH4F7CzAQI6PKG8b9bfBJ3gvWCKZMWe8jtQOeQ7z3E9VZv9kKpKFm92rmcZ0zrOGrhsRfpwDmP23p2cEhIPiunr5bzRVfjjNw+P65nkiguwN+HrMAGY7oTO9h6uzq1wRBBdyA9rOF/j/1oGAcLusZeHW2Il2xWtHSMXQsijVVS2UyseVvpx/OatGZUSjFH9rv8roi2zfr1o5bjFgzX1eI08PfJ0tkXvAJHktFGAT5CDoNCR9BfbQRQiEVFMtaUbflmXXM934nYc6n3bULELUTAX7CkbApxcJSw5E3kVgzCg9TNxvrGqmPsU4c9ZcPiiCoFLNJw0PqSm2Dzk7xccyVSa5Odbl1VCQDvJD6C3YUYMxz4RseuOcIZB5p01Zo/OSIrI0qqWB4/nKO0Rmk7r++7tg5qZ3BrW+KMcdPoX98B9jJmDjkEA+5fyde/dJaazfoW60FdVKAcKjhkxdUqGYz0dk5S42K46ZR0ae6HBqoUW6PMwTWzmvxAsMkZrjWXYhUEXMZx8gwVHs3S8rA75kMWEJGPlOrVKocppVEIDj3n9mFAZrnz7daBxmZbz/31Dxy22EYEs/XSfLUvXVe/KIb5IJw6zaNzZ9w== 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)(39860400002)(396003)(136003)(346002)(376002)(366004)(451199018)(66946007)(66556008)(66476007)(8676002)(4326008)(316002)(8936002)(5660300002)(41300700001)(6666004)(107886003)(6512007)(6506007)(26005)(1076003)(186003)(2616005)(83380400001)(478600001)(6486002)(103116003)(86362001)(36756003)(38100700002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0bLAKDqKws/9R+B4Bv8UYGm0OP/6zNOaXeLnBxTnZs+ujP3NYSAxYhK6D9gzkrEwHfMFFzqnH8bCSYTp8EKUxV9Wq01zBBTSFBAOJj2kxUZGuuzS2iwTEif+KPIVbktijdKxuS7Oufi4vaClOdZknIUZSseJhPzsPvjLu4qLo8AkTjsK3WRCcrQN9w4Exmitz2awHagV+EU/w9RdlPNJNgA01Bad7ROKWlA1YclcX+qMIDVRCCSI2LnDqHLV64zqlSMClJJUnhR+N7SmJXzsNtna1x/vb533q84rQ7QdV5bLUbt/2iPQT4PiBNkVQ6B/eCxuecF9bYI3oWvefNO6j3Io4G0hYA+d6B2RpAGrz5FMdRB+nie+SZJDtmu/DF63BuhpKQA4Eu52ua0Bgvr1BfA+dtW1D8jUKWZv3nlwfHupdLWTkgHYm4AS7GeBK+0YoIL8WDyAvEcXvrcOQv6693ePkeLyCQMDabUqomb8+zBMfr1Q1gh+XMZgqqRgwETQNe0Es2rDAOjRCaLT3MZcoLPjG+PFndIrM1xJM0cTzxjp/KYS4zeJinhs/jqEZESLKutg7uiJmosk/Ic3E+xpFG7HfxJ6GDPxsOq4W9qIRtPY/0DyQSoTICZamgy0tXgartNwKc4aJdK0NxK7+dAO0wW0TMHL8v26vRbgSJWNu31WK9xAHbc9nwYikv2Gfuw3x2DR40JwStjAQjce1qng1kCxMLm9ffZ7IIspC9OaCdES7TI8AxYCRggInTvQR3XKGMUiIK+F/pZd025FT2AUmZD3Cf9+h68ckCXbTJ2grFH3QgbTfoOIeuH3vXtmA1uv5Bbvm3yLNxKs5tyiGfU6F2f8dOK47Yxds4tNuXPTt+4a8mhAJH9J1jjgBVzONmrGMbjTx2RemmqsXG4t7xQKeJ79vGFEYagVMATtE+L3IDv9JRyLvtOFF0LPfXDAowKSMstQb81/iUexHrdHZ8iAV2+xsijhbeJE/Gy3lBoLMbtdg8rQLNOctIqLZqyTWL6sGjH2khiVuekfmx9gsfZzC7gkHUPlyC8YrPApaSEQI5lM2ZrkesXUfgmV1QUxykMqZjur8dPvJDA/cjRhHvOwsvV2EkZVlqIMpcAO4TaOmsBgmH7g13+BVOOI55LtTSaAJzaJhBY/5cPU8GiFujkpRpki+musVhiVocwRtDH0AFM2/GVHcEcwyYgxGGyf5nPal+W5JfaxTTuL0wZ2vtOD9LgrL8TZyS420nUK4xr6C3itqA8F1MniKnI7Zf8L3jb/OswPF+osDvkzQvTvq0osjRbSmlKQvxxfVXzyB/EBK4RjBp9oZViXc9LO/ZRRS/igbzr6KW7YY050/4y0oPmKFiVOatW4f3pMwB4C94v7rP1egbqv6kY9ilSr15/hcde4rPpxZ9LKCWZiQ3Iewn3Fkd4hhIccralURR2rxRvZCTvBNsEIy3NJdixyweveI1zCWNzIkFWhbmjecdYPpe6ax/vnriMirqdpwM3G/oAzpgCh2T7Hdu3Z3SWLt6ltFjXKJQjC1s7f22KXp02grDegmqxjPhAHINiAv39VktL4oKGjvyt7UbJkxqwT3Xonb9jwfmIEKubLbINQ753VtrWs8A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: +qdIgnPCQ1tqqFoSyV43Eto0PzOVnEVZ2YGthlyMBXgyiBdEEyB81BfZD8VlfCO38FuDv+4827KDDRXn5Dj33gb8AHrh4vtQWU1uuATeh/Y/PzalqSfYhV6MP0l02+0mqAzgpifzPiIcQgURfSvxmcO/6GkXClJzMBvbPmqMT8+kt6VG0QEnAuNll7Q3bMBEb1gZ9SGyJQZOKlSHrdKlew+KwMy8J0fHaoM2QuaAsFXjuhkGutn0sQpyPytucHsKro3jDfrC+4ky2q/Kwg4kwv2cI0OBalRu91JQ77lvNDRqzit+iLFx8I/fGAtw3z23JOZO4CkTnJ1Q7stD2yIby1I+E2EC3g87C3KBT+SefsqyZe7rDjNxqvGoE0WZiSnlkQ46ntJ/d/Z0LSla/w8BYYomI4MqtUXuUu+c4xDaPDFr5U7sSa4C2v2ETPMkK5Eb69mOEO2ulfwDNzT1IEx0AaEu+3FwsbAzIKwXD/QNWluFkav5J6YfE6VqccI39mqm4eP7sNMqfrCl7KIQmHI1JYt/PiP9s4a2looUGD3zkqnO+vx3FvxOo+W5EGfy9YIMPesMEiBZpum1uMktKeWWIqjhQgXdxruBlPZ6/m6BjdLg2+m75UNP7/rkWcSErUf6GWjO8oGGFnkNjL2uwrBsMTf2B1fzqMWt16DlURidh5Y8v9+39PI7hOlpZ0zX8+37vNmRVE3YLx/Tie+azvxAg8MTu30h8J3tVEbtnjX780VdQ0yvIscHOuKdaG2uP54SDeVgXYJ6JpLtKyghDPX7/ZPWnggxz9I/7TNMYDLml1q/sjCzAl1ziLJo12bVJQa1FXqTyZzPcEdokA1yrxirAZ4X83i2gCRAQ6ZCH7AO+bfjv74CfMSKh4Pdjt9EDAhw/g0wiu/okTeIwUxCivHhNu1WyRC/eDWw2ieXEm6QOEs= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fa4d4c4d-b23b-4dae-3a2a-08db23b398c1 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2023 11:10:47.3381 (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: r+nghzMbHEaXRETMKo4ohsFODGnqj6Ul2MDObXVo92I227RZvwUAGuSKLDwOhUFaf3Pq9qbcmBd+obF4HJmThg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7672 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-13_04,2023-03-13_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303130091 X-Proofpoint-ORIG-GUID: nvMcHZqYelsIieue50zSXrG7K5x2iVcG X-Proofpoint-GUID: nvMcHZqYelsIieue50zSXrG7K5x2iVcG Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The feature to block queues is quite dubious, since it races with in-flight IO. Indeed, it seems unnecessary for block queues for any times we do so. Anyway, to keep the same behaviour, use standard SCSI API to stop IO being sent - scsi_{un}block_requests(). Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index ad6002c28b6b..fecdaa5be11e 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -359,7 +359,6 @@ struct sdebug_queue { struct sdebug_queued_cmd qc_arr[SDEBUG_CANQUEUE]; unsigned long in_use_bm[SDEBUG_CANQUEUE_WORDS]; spinlock_t qc_lock; - atomic_t blocked; /* to temporarily stop more being queued */ }; static atomic_t sdebug_cmnd_count; /* number of incoming commands */ @@ -5494,13 +5493,18 @@ static void sdebug_build_parts(unsigned char *ramp, unsigned long store_size) static void block_unblock_all_queues(bool block) { - int j; - struct sdebug_queue *sqp; + struct sdebug_host_info *sdhp; lockdep_assert_held(&sdebug_host_list_mutex); - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) - atomic_set(&sqp->blocked, (int)block); + list_for_each_entry(sdhp, &sdebug_host_list, host_list) { + struct Scsi_Host *shost = sdhp->shost; + + if (block) + scsi_block_requests(shost); + else + scsi_unblock_requests(shost); + } } /* Adjust (by rounding down) the sdebug_cmnd_count so abs(every_nth)-1 @@ -5572,10 +5576,6 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, sqp = get_queue(cmnd); spin_lock_irqsave(&sqp->qc_lock, iflags); - if (unlikely(atomic_read(&sqp->blocked))) { - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - return SCSI_MLQUEUE_HOST_BUSY; - } if (unlikely(sdebug_every_nth && (SDEBUG_OPT_RARE_TSF & sdebug_opts) && (scsi_result == 0))) { From patchwork Mon Mar 13 11:10:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13172271 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 8CDDDC6FD19 for ; Mon, 13 Mar 2023 11:15:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230398AbjCMLPY (ORCPT ); Mon, 13 Mar 2023 07:15:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231197AbjCMLPH (ORCPT ); Mon, 13 Mar 2023 07:15:07 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81A4E23877; Mon, 13 Mar 2023 04:14:15 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32CNpTtJ017235; Mon, 13 Mar 2023 11:10:54 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=jLosYjE40HR35OgZ18qhqr/stcxoHZgkEEw55vC09v4=; b=dbK8NQgY2Sg2euEL4Mkawcdfj+kiejo5o/4Vke8QrByC/vw0sdPuMzqi/ofvfh7LFdk3 1VDMsJxDJb/DK2QM1EG2BXtJRsy0VEvYgezP2UOAqRJtEmLJWxCuIcrU5Gw0IJz8FtQr YYoQWNQ7qKLsY+AbzdOK/g3JViKZ2goFh3eyrU7Hwuxt3M6xPDLZzYn7ZB6SPWquOrbO iwYt5U4yiOxA1E61yBHck3U/AJ8fzJAbq+EZAcdsKkXJHxlXIqlNN6czKlGR6DYSNnAg DS+dj8StcDZBfHzf82qf5BDWQd2FUg7V427nv20gIi1vRrOcnNaWnp2gxTuR07wyNErJ Rg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p8j6u3h80-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:54 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32D944A7002312; Mon, 13 Mar 2023 11:10:52 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2045.outbound.protection.outlook.com [104.47.66.45]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3p8g3b0kd2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VRORxpqqoRIMB08kKoLPLa+8ILQSRz67wQsgQb6TDY89SmnV03yQ6YwbZS6Eq1MFfTF+D6ihMhGHh+HXu5I+dVVcwmxLsXry0dZUfvEaPnEiXb/T0Qqs28EOrfAx1+pr1mun1SXZ+yPBdVnGAL9QalvImJjgd50HVqFkLXTbV8ydHKAlMh5V21iQuIoO531Su6LoAZo/yC3xFaRc+hYje7L+uRADYgsEbDiOFxxHskU5DKouxNMub0lGc9hDvmvP5AlKpl3kbMyiDFwUhQ7MFDwwzDv8q5i8n1i8OC3irxkjhBjpxXC6Zyayn1EPZiu08uYBF/AIrHeWFHTZHtzVKQ== 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=jLosYjE40HR35OgZ18qhqr/stcxoHZgkEEw55vC09v4=; b=ErSZFI9U3QBr0aDf11+jfWlblsTy71KM1kK1AloLNr4PMdWrbggnbxpZVlLkQPmgeNIfiGk+ZtIWxiMGrCib6Tdv2BjxnsONWMqjkrHSijr7eBJuHcdfeS4pRpAd5FFWMdQ6UVTgmtqMByRokOtINTPq242Uf1l4JHZTwmXON1Z4Nbf/jcuvYLsi0e5jrduyPVbHLCuUBfUq7mK0DX/sEAOwiDQdh95uXy0gq8ihhCOhCMKESkyTM/sL9OxA+nZT5CRgiQISCgh0hZG2r5VyqVgWO5RV+VNqI55hfJkOWTPu6VXADuI+1P2Tdc44l591uzq4NgnC6ycvyP512c7WeQ== 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=jLosYjE40HR35OgZ18qhqr/stcxoHZgkEEw55vC09v4=; b=QleaZg25bC9r7c/NztHFSdobk71EtsKUP0WUDRMH8D7xqWR2lPPfP9bKySrHMGLb74s3qoVGhm/neYtRKsgmrE6FZlrYlznBm241JhIHYvWc6J1unrH4r+A9J6R9oL/7HMgi6vLK7bcxFC/15dNWELMQ2oiVQEE4+7oQS34Q2tI= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ2PR10MB7672.namprd10.prod.outlook.com (2603:10b6:a03:53e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.24; Mon, 13 Mar 2023 11:10:49 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%6]) with mapi id 15.20.6178.024; Mon, 13 Mar 2023 11:10:49 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, hch@lst.de, dgilbert@interlog.com, hare@suse.com, ming.lei@redhat.com, bvanassche@acm.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, John Garry Subject: [PATCH 5/9] scsi: scsi_debug: Dynamically allocate sdebug_queued_cmd Date: Mon, 13 Mar 2023 11:10:15 +0000 Message-Id: <20230313111019.1521680-6-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230313111019.1521680-1-john.g.garry@oracle.com> References: <20230313111019.1521680-1-john.g.garry@oracle.com> X-ClientProxiedBy: SN1PR12CA0048.namprd12.prod.outlook.com (2603:10b6:802:20::19) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ2PR10MB7672:EE_ X-MS-Office365-Filtering-Correlation-Id: 613e648a-c6fb-41f7-0117-08db23b39a08 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YKxZwpIjExDDdAaGe/5sN/cGwq8GC0eTb7LwTWHy6oQ4YJGbUMR+zNukgDodVzun0xmaSJsE9g80c6HX9ZxFp3ttjPImBzjGbK8h0zTJBT7M7ZiK3vO6XQDkkn9TvHoIZps6NEDEF/bs3GMv/Qzik57d7C/JXbZ4npsiVexgtd9WtO9nQkyO/nPmNx9w7PtY0wviJr3T9CVW7NW74ALJQYckGCSHWlKBu2vvsqcTw+RtUd/QhvFeMMHhJ2A6WGkQrEyIs6uNPANj9PsefAsGP4XGRFkRgZhGS4zXBChviU3W5Z9A1/zrKrhIKaV9u5P2i0yimt7lIdV0fXjpy/+APiuUpd/SfWqcVYxvJXBQQbsL4QoNNI8DW2mQ/wheVZRtwNxbNSnKR9YTZAKpLFIEhqESpsPVa0k9vj8OjYHG4L7e69qSokDXlJsst+77VarC4GhfMJa5xe6Bof6z3CqR+Wtye3+CbV79gtuGPrbPRIEfO9isCwkvnwYbRtZby/Dd/1k+JUSbxfBzKaeZAGu879vKZQUVWdPhWdx8Yn8/uTlIGC6bNJaTgeE6jtkbzqrPTQMpUxHENXF7M4QkglE+jKQ/tz4vOaw86JwkvHI8E938hLxd394JINSMvu+mCujg 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)(39860400002)(396003)(136003)(346002)(376002)(366004)(451199018)(66946007)(66556008)(66476007)(8676002)(4326008)(316002)(8936002)(5660300002)(41300700001)(6666004)(107886003)(6512007)(6506007)(26005)(1076003)(186003)(2616005)(83380400001)(478600001)(6486002)(30864003)(103116003)(86362001)(36756003)(38100700002)(2906002)(66899018);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: iB/LEGKT3ssVOV1oydrl2OH3w5tmgsucxIKM3Ahm8jTULaIZPgL8peVqTZ7o7NbFABeyR7xwYQQpmVBhl1y06SsX41E7or0kGF5TA011sgPpIns4nAP1bHR6Lej7wNoJ3/M+wZBINgUk/bbfePWJqJujDhBHdZ+DinBVS/aDDuv+C/c8wxeFrmhjPr+oUrGE2MOlhcE6HRRuqheDL/yCDZXYYTGerhuvPW72VZPCC1wS8eDgu7cpVD6Z1jmTUNjJRh8/VZgIDOixqHO6EqdDj6r1m9aJZi0M/nNr2GhvmcQRsMVGci7clIU0Q1IEVxuO7pYEr/bwvgKjNanV5nHcGm9+L8UZCG5V7SJWtRifndLF+pNIoUxI2CdUNIuhHkJWF20wT/Ixtzs+docbnytKjMHiT0XJSeGlPofb3qRu6HReNjVFhGrq9zBI8/bBs+lg8C8X8kAaxhn2iSG3gdA8MGMxVJpxfPrdIUfNEA/bu7ErOWUmtj5wtIBvskD5RSlHCP7ZqgJ8dgPdD/Ji7tgwVpKGdLyJ1DwW48dPaHClwVN6iMzwXew8njUWo5FKyNEupapFxDMfZ07ahbnhN596eikzS+bW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ExternalHop-MessageData-0: U5lQU2xDRsQ8RDjfuRjYwXAnip5E0DICB80Jn1qoNknbapM+QyQXmzPj6KHqvBAFuxk1MebJY5cJ7TeZSalgju+BM8I07vCf6/nIS9ma0t1pYEQq4dWwUUtBsSJC133RsMDKUBa7mECu4S+jS18Wq14oPyXk1PiRCHDt7Ys/HTynjOEYXCHI3j+OJX5NBW6sHK1/oqtnnQzcT0mDDPVxPk02FrbdYHK72Jj7v0BaG5PgJOIjMtopn8LM55yZ4IL/OLI/JYGd0APd/CzfSr1X57btTy4C2VtKC4WA9ef9xkqGyCv7N19NxqG8mzBiGs1VmQ6UZzZs058hBLYa/0l8m3hI4sZFnipdGhXf/a98ascSjU/9rSDUIQlH+D+M/tjGWyJPCKzhF2VgYBvmS8iTlMx3gdGU7BjA6TvsnLKL58guO9ZzqTyUl6xrEvdo4gyE06PhYx5+IyHM2Tu5eenQ38LfO244Ed7qw/WGBQ9LVZ2qZSLTEGdqnXzZL7dNh3tvufKX5UShaGsXOkXVDVCYw7evJdU9ppXWauyd+GXVM20ETLw4m64otv/ffyZZF9AvW+P9PJkgb49O6zFt7eXZiFBrIQDVyeWpGQ9lcDlQMDP4ONl73B7VT65LAW2X9+/yFML1lTIWsXvdB2GQ5MGdfdtFzkKn9xm7jw3VKf1WzAfIp1a7Yd24p2kn1ykFD30CAKzLvQIe1MBCH4+7mVNABqCLycCjbQCLHVNVbAcph2wMIrb5asFEpq3KdTm6fduZ9DbaSMc/t2TAUu6rPLwpePIScCxT9CnX927W3vNal42KPZljuXnKpmf9Fiww0e21N964/HWksjnK3WrMxGow44+oqc/g4/eNIF8+kDPhq2nEjNGd1ySroZzkq0rIvEs5qMHdQ+wRehoDyFUrfbdFQaxkDOC6+93eTqjZJmHy5Ek= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 613e648a-c6fb-41f7-0117-08db23b39a08 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2023 11:10:49.5122 (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: l0vY4xOeM2lXXlylI+u8DS+pPShcWINoySMRYgq24vDVrzPyuI2Im0ZO/6lrPyREiMX1lONeCcUKdoXT6rVg0g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7672 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-13_04,2023-03-13_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303130091 X-Proofpoint-GUID: VXR0zrVEFqHUXxcrdtD_7NzGJ0jW3VUA X-Proofpoint-ORIG-GUID: VXR0zrVEFqHUXxcrdtD_7NzGJ0jW3VUA 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 | 415 ++++++++++++++++++++++---------------- 1 file changed, 241 insertions(+), 174 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index fecdaa5be11e..4db66edcc9bb 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,124 @@ 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; + } + + 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; + 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; - 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); + } + 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 +5567,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 +5605,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 +5658,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 +5720,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 +5732,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 +5763,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 +7098,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 +7124,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 +7141,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 +7530,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 +7542,51 @@ 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) + 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 +7595,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 +7604,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 +7788,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 +7825,8 @@ static struct scsi_host_template sdebug_driver_template = { .max_segment_size = -1U, .module = THIS_MODULE, .track_queue_depth = 1, + .cmd_size = sizeof(struct sdebug_scsi_cmd), + .init_cmd_priv = sdebug_init_cmd_priv, }; static int sdebug_driver_probe(struct device *dev) From patchwork Mon Mar 13 11:10:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13172270 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 1E7D6C6FD19 for ; Mon, 13 Mar 2023 11:15:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230289AbjCMLPW (ORCPT ); Mon, 13 Mar 2023 07:15:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231158AbjCMLPE (ORCPT ); Mon, 13 Mar 2023 07:15:04 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CADCC13D74; Mon, 13 Mar 2023 04:14:11 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32D01VoX018846; Mon, 13 Mar 2023 11:10:55 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=mpfFqbGWfiJfSOdBbdUS5NSh6oFnRQ9DPEte4/4Casc=; b=ViWFV0MI5HO20n+8oeOK46p9BmsO9JKDMfBLJsIP9JBiOUcmfY74G8+4kR2BP3jx8vJN zNsNIJbs7y7Ap9XgHyNZumixNZMCA5oNqOq25te8sHjPw1P9LiGNA5EkqWnt4gTCAoRD uiSb8gxTblYq916Wpv1gIxk0dWpHv+Tb1wjRrj/YcIoCyrqACbCwfo/SC7G14c93vemH z8DhB0ioUB53qELqXThDQxQ5IbdI+T2JON7U3fezWcV7J9kFn8CqaH7FZxBE66moY3WA u4ORr9vaGtYm4ysidbBbVLQnjrEOF2gUY7GMrfDdCd7xY6WRjv1A5SP3aAw67VHhDxjQ Gg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p8hhabgq5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:54 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32D944A9002312; Mon, 13 Mar 2023 11:10:53 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2045.outbound.protection.outlook.com [104.47.66.45]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3p8g3b0kd2-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lQiXYY/Lj9gzjAu6RBO9/x6Zq8/SLxTaTThAXwvk8R2qm6G6CujV1wRsBgix9ghNnWSBYSvdCYoyRDVCX+wru1u1jgsj18cLIXu4x4YpstPpKerUUY9M950b1bjS9iKGSg/eQOOgRERSgQ/Xi8cP7yga761q50BDvpHlvlb//PsW94ljckt5+dYmXLc+Ikli2k3TCAHX3vpqqySlZXWhq+BqguB6VT/VYKHFafRt7d1ci3a23BDsivsB+9ok2yXDIhpDXwYUlNLN98BgCW9ZQ+d/3jyXoSfib1SbrOBrnj/OO/0UmG+9ccDapdpU+CvRL9qMZB87EHKG/n4Ak5p5gw== 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=mpfFqbGWfiJfSOdBbdUS5NSh6oFnRQ9DPEte4/4Casc=; b=mt591is5fjGSBx1Pjjvd0RzCXkx71Insg/ChoRb+JVzn6CEji2/OtL9mD7jPddFM/TNGpmRyjmsMtCfzAwH9SV6pUafzOyiZb2wJaO93m2698YbN5IEQrGsYB8peQpr7h2+4iBqk4PqKL7XCwWRi1uxxjdOLtV//tZOOb4lJ2Oi6vTvLdR4r0gdhgrUb/CyYnFUQNRQW5vZG6qRlK6giiYnlMv1ngNPrv8iw82QK2oygEQygC1E71HATzaiKRPJTys6ihH/bV1QeziyZNpbvq+ZDn5FtWm4c/3QzS+8m/XmI1+OZA7sgttZdunBLZulp/NLZOz+lAFGMyaXn1f7yqQ== 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=mpfFqbGWfiJfSOdBbdUS5NSh6oFnRQ9DPEte4/4Casc=; b=I/qU3NA2qaqZpHjQGGD4Rag6ggacRKWHRX03bZiFsRpE5vgx7EKTovxSnol8may2Euv18Z0/4bG9hs+Rxq59wFwVbwt0xUGdOC6lp67MyGnSu/TF8AyqONVO9T1YX60SYxko2Y7w35TB7C/gEnvArjqGkadnMUvamkxP3pdTju8= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ2PR10MB7672.namprd10.prod.outlook.com (2603:10b6:a03:53e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.24; Mon, 13 Mar 2023 11:10:51 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%6]) with mapi id 15.20.6178.024; Mon, 13 Mar 2023 11:10:51 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, hch@lst.de, dgilbert@interlog.com, hare@suse.com, ming.lei@redhat.com, bvanassche@acm.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, John Garry Subject: [PATCH 6/9] scsi: scsi_debug: Use blk_mq_tagset_busy_iter() in sdebug_blk_mq_poll() Date: Mon, 13 Mar 2023 11:10:16 +0000 Message-Id: <20230313111019.1521680-7-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230313111019.1521680-1-john.g.garry@oracle.com> References: <20230313111019.1521680-1-john.g.garry@oracle.com> X-ClientProxiedBy: SA1P222CA0015.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:22c::33) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ2PR10MB7672:EE_ X-MS-Office365-Filtering-Correlation-Id: 7d27ca9f-11ea-47cb-7a9e-08db23b39b2f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gso4UgNNGJW4SEXa/jHA7Dr8SJHjQ3YTwe2spGhLSpfrroVdefM3Z6VDoIXnSKv8TaRMlbsQt4Ow9/JvDOe7rsTUKkFECnBIbhdTAmiHecPLFz5Q9Zj8gZikKA1JbtSdypC5a5D5jC7ZxYuxRZflIve/QPGsZC7OcyXW2rxyVfdhFE4I31lRzULlD2X0DAsPWDOBNblXp5QdSWsAQRYt5sgsZFWc0djkM3MAKU+yPEk7n8GbPFjclYo/7XQqjy5nGLeLid/0WXn1f9zGGIpGWKE91WFJJRdGhfamnghSYHFSHxMgzRqkHGONtopF6Hok7aRpCxagOq6ui6bouJ2tmIKOhJkLKyR3o4x4SbpTzo+0h1uinKY2KXDhGQR/sDOXc2ueceVGnpcTdhuXGpkL3M/pK6Fvm55DXmUu7hdCyBtomIS7XfpNBpLT45GdZujFs6C+U5t/XeByJOqWw4N+JNK/omuJ89DFAYGXrDIvaVA+x9leeBPKt7aCC54/CKqOA1b2H6fpzaVcMLOGpS809wjCVxoZMSEiWYZoq42ekAG6TQSmssZ1KKYJKqYfaeXFhvzftf525wouCYsXMlmpp6LbQtiwFaZpYnu+GhIuXeM1/B2YzYB0CJhGxuevzEyS+v7eRoaYdBM+/4XjMtU55A== 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)(39860400002)(396003)(136003)(346002)(376002)(366004)(451199018)(66946007)(66556008)(66476007)(8676002)(4326008)(316002)(8936002)(5660300002)(41300700001)(6666004)(107886003)(6512007)(6506007)(26005)(1076003)(186003)(2616005)(83380400001)(478600001)(6486002)(103116003)(86362001)(36756003)(38100700002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kmam0EKRxn7/XL3736g2yW327jWAV9IY+yhJhuERQrzcrFcCeLG0wUS2mEoOQ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Hxsb/AxFpGn0lwEQsmSGYEjECucfmBoFIYw7p+gLRtnRLMZBO9y8d0VzXJNdj2GX+JOhrK6Ywp/yJE3Rb7x1uINqh/siAiQGQduyxhIII2U2wIuK/x9DpTg1jLC2IjXI0TebIMFvvCZwjV836TjH5U61Nzvp2eOnrx1RPf1b+0ex42RMcxEnJQUMPrmedQ/OR2uRjPEtQCOh/Uh5ULIsLDD01u+XDGMSZHD3Jr2zoOIbWKRNgRdNvmJN03aXngM4rfwFse01ptBEOmzWZ5LPsupbSWV364v9TsE5XbvxLLjhGpvc/WI07iP5AhOmmcltnOtbdntoQmRkZzSKPACFsF26K34WpgazsKVi94xgKi1gSjfJCq7H5legPvQ4nOApwAFNXHvmSFKzMlmzQZilkIqJ8Pxj0Luxs= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7d27ca9f-11ea-47cb-7a9e-08db23b39b2f X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2023 11:10:51.4317 (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: KHd0lq2YCvv0U2cYzgiZvxjXO6OsK/pNgzAfc0jj8MjYouHlQ7QUSJioFsvBtMKbDS7QMEpaJDYB3nKu7/JPnQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7672 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-13_04,2023-03-13_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303130091 X-Proofpoint-GUID: j-b-mfFrc_0fBV6_uqERmnZZCS6QN_4U X-Proofpoint-ORIG-GUID: j-b-mfFrc_0fBV6_uqERmnZZCS6QN_4U 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 | 187 ++++++++++++++++++++------------------ 1 file changed, 99 insertions(+), 88 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 4db66edcc9bb..890241b852ec 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -7508,114 +7508,125 @@ static void sdebug_map_queues(struct Scsi_Host *shost) } } -static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) +struct sdebug_blk_mq_poll_data { + unsigned int queue_num; + int *num_entries; +}; + +/* + * We don't handle aborted commands here, but it does not seem possible to have + * aborted polled commands from schedule_resp() + */ +static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) { - bool first; - bool retiring = false; - int num_entries = 0; - unsigned int qc_idx = 0; - unsigned long iflags; - ktime_t kt_from_boot = ktime_get_boottime(); - struct sdebug_queue *sqp; - struct sdebug_queued_cmd *sqcp; - struct scsi_cmnd *scp; + struct sdebug_blk_mq_poll_data *data = opaque; + struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); + struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmd); struct sdebug_defer *sd_dp; + u32 unique_tag = blk_mq_unique_tag(rq); + u16 hwq = blk_mq_unique_tag_to_hwq(unique_tag); + struct sdebug_queued_cmd *sqcp; + struct sdebug_queue *sqp; + unsigned long flags; + int queue_num = data->queue_num; + bool retiring = false; + int qc_idx; + ktime_t time; + + /* We're only interested in one queue for this iteration */ + if (hwq != queue_num) + return true; + + /* Subsequent checks would fail if this failed, but check anyway */ + if (!test_bit(SCMD_STATE_INFLIGHT, &cmd->state)) + return true; + time = ktime_get_boottime(); + + spin_lock_irqsave(&sdsc->lock, flags); + sqcp = TO_QEUEUED_CMD(cmd); + if (!sqcp) { + spin_unlock_irqrestore(&sdsc->lock, flags); + return true; + } sqp = sdebug_q_arr + queue_num; + sd_dp = &sqcp->sd_dp; - spin_lock_irqsave(&sqp->qc_lock, iflags); - qc_idx = find_first_bit(sqp->in_use_bm, sdebug_max_queue); - if (qc_idx >= sdebug_max_queue) - 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)) - continue; - } else { - qc_idx = find_next_bit(sqp->in_use_bm, sdebug_max_queue, qc_idx + 1); - } - if (qc_idx >= sdebug_max_queue) - break; + if (READ_ONCE(sd_dp->defer_t) != SDEB_DEFER_POLL) { + spin_unlock_irqrestore(&sdsc->lock, flags); + return true; + } - sqcp = sqp->qc_arr[qc_idx]; - if (!sqcp) { - pr_err("sqcp is NULL, queue_num=%d, qc_idx=%u from %s\n", - queue_num, qc_idx, __func__); - break; - } - sd_dp = &sqcp->sd_dp; + if (time < sd_dp->cmpl_ts) { + spin_unlock_irqrestore(&sdsc->lock, flags); + return true; + } - 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) { - spin_unlock_irqrestore(&sdsc->lock, flags); - continue; - } + if (unlikely(atomic_read(&retired_max_queue) > 0)) + retiring = true; - } else /* ignoring non REQ_POLLED requests */ { - spin_unlock_irqrestore(&sdsc->lock, flags); - continue; - } - 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))) { + spin_unlock_irqrestore(&sdsc->lock, flags); + pr_err("Unexpected completion sqp %p queue_num=%d qc_idx=%u\n", + sqp, queue_num, qc_idx); + sdebug_free_queued_cmd(sqcp); + return true; + } + + if (unlikely(retiring)) { /* user has reduced max_queue */ + int k, retval = atomic_read(&retired_max_queue); - if (unlikely(!test_and_clear_bit(qc_idx, sqp->in_use_bm))) { + if (qc_idx >= retval) { + pr_err("index %d too large\n", retval); spin_unlock_irqrestore(&sdsc->lock, flags); - pr_err("Unexpected completion sqp %p queue_num=%d qc_idx=%u from %s\n", - sqp, queue_num, qc_idx, __func__); sdebug_free_queued_cmd(sqcp); - break; - } - sqp->qc_arr[qc_idx] = NULL; - if (unlikely(retiring)) { /* user has reduced max_queue */ - int k, retval; - - retval = atomic_read(&retired_max_queue); - if (qc_idx >= retval) { - pr_err("index %d too large\n", retval); - spin_unlock_irqrestore(&sdsc->lock, flags); - sdebug_free_queued_cmd(sqcp); - break; - } - k = find_last_bit(sqp->in_use_bm, retval); - if ((k < sdebug_max_queue) || (k == retval)) - atomic_set(&retired_max_queue, 0); - else - atomic_set(&retired_max_queue, k + 1); + return true; } - spin_unlock_irqrestore(&sdsc->lock, flags); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - if (sdebug_statistics) { - atomic_inc(&sdebug_completions); - if (raw_smp_processor_id() != sd_dp->issuing_cpu) - atomic_inc(&sdebug_miss_cpus); - } + k = find_last_bit(sqp->in_use_bm, retval); + if ((k < sdebug_max_queue) || (k == retval)) + atomic_set(&retired_max_queue, 0); + else + atomic_set(&retired_max_queue, k + 1); + } - sdebug_free_queued_cmd(sqcp); + ASSIGN_QEUEUED_CMD(cmd, NULL); + spin_unlock_irqrestore(&sdsc->lock, flags); - scsi_done(scp); /* callback to mid level */ - num_entries++; - spin_lock_irqsave(&sqp->qc_lock, iflags); - if (find_first_bit(sqp->in_use_bm, sdebug_max_queue) >= sdebug_max_queue) - break; + if (sdebug_statistics) { + atomic_inc(&sdebug_completions); + if (raw_smp_processor_id() != sd_dp->issuing_cpu) + atomic_inc(&sdebug_miss_cpus); } -unlock: - spin_unlock_irqrestore(&sqp->qc_lock, iflags); + sdebug_free_queued_cmd(sqcp); + scsi_done(cmd); /* callback to mid level */ + (*data->num_entries)++; + return true; +} + +static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) +{ + int num_entries = 0; + unsigned long iflags; + struct sdebug_queue *sqp; + struct sdebug_blk_mq_poll_data data = { + .queue_num = queue_num, + .num_entries = &num_entries, + }; + sqp = sdebug_q_arr + queue_num; + + spin_lock_irqsave(&sqp->qc_lock, iflags); + + blk_mq_tagset_busy_iter(&shost->tag_set, sdebug_blk_mq_poll_iter, + &data); + + spin_unlock_irqrestore(&sqp->qc_lock, iflags); if (num_entries > 0) atomic_add(num_entries, &sdeb_mq_poll_count); return num_entries; From patchwork Mon Mar 13 11:10:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13172269 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 5AE82C61DA4 for ; Mon, 13 Mar 2023 11:11:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230365AbjCMLLd (ORCPT ); Mon, 13 Mar 2023 07:11:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230213AbjCMLLS (ORCPT ); Mon, 13 Mar 2023 07:11:18 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34DE461523; Mon, 13 Mar 2023 04:11:06 -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 32CNW0t2008272; Mon, 13 Mar 2023 11:10:56 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=sLC4UuzOmxR6AmfP0OdcdaskgZ3royTr9hU2ZYeBYE4=; b=fT+CC722hg4kkA5gEOqAj9XfPTH4j++Un/X9MbzYCrileaR6l2sZNJxRh2sCXwr1VJUn KfeLwO7J0jY6AC817O8Amsx1aW1YUNIMGfnPl4R6ATwKnVlsbp52/XIIZ6xwunjHHDnS IkLPDhb/tOMQCS3ex8t/nfgMT5IZ+T/2AtxX5K5+tJXe3C7dACI/fb81bInAc5nQxwdy uX/W7fVMeiWbCp/BAM0WFJSc5Oq4XVSNotmlRdlDyl/Q3Mv1udvJzgQSLPF2tC22nNVY p/N7+7jrzcZueBVGwdXNKAifcouc2fwwedQJ40ca5bSOUE9G7DCm1GcMEdAT5copSku6 rg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p8ge2uhj0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:56 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32D9FVC0008168; Mon, 13 Mar 2023 11:10:55 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2045.outbound.protection.outlook.com [104.47.66.45]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3p8g34fm9t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A/OUOHUXLT+v+6U55RUIm5/7hsRUGEBpb+or1ofnhRTZ/RjAGtbbe0L0B1i2VyIxCFQ9j8VWceEK9/Bb+rHWt+LA5X0/GUBZCsx6/YI/Xefi2Bq4OjtANehTcFd9VLVo6VKCAOvqdN8vQdCwqgW6D17JAaFiNSP9+c/icYrcYCSKu43wgi6zK2hWOMDNM/YqGK79A1Ip0GHYMCQzA4Pfqn3iGu0i6kwWMQambQz9IT55GZEWXde3RrFi+6Flf15ecRT5aDYHdILhZp6QH7LyS0Cab8SmB5YDceUyXh842BUS4Ikc5bkqqbwhDKj8kfMroN3lszIsqRvWSzW+Gvi7Xw== 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=sLC4UuzOmxR6AmfP0OdcdaskgZ3royTr9hU2ZYeBYE4=; b=nlQuBBChmJN3vc2wPMTWOTYMPIrmOrAoJqoqvTj9eiQNJZAX4zegg7h86plKwp8dFwrJ+FEBITn2/cMHDu0m/S9BwB58TMPVZV5cCXcWPhuf3QloZbe38ME5oMKPCADs5hbWvGVlEBkctX3oqvo7darG16/9ntjpCXumzPZMbkuNjiw28qoyhEqa6DsGC6/C99G9hpPJR1wUEQO+Z41b39SCu2F0FSkLOhOJbvWrJGmHcEFiJYFXU7nY3lOCLSqY2d/JIwVvY7i2Xaj4pYXYlHaQCEQ3D8bEuKYjuSW08WcEd+reEWlPmvn2MQD6zdCMQjRydYIUHBoZWypQPHOL2Q== 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=sLC4UuzOmxR6AmfP0OdcdaskgZ3royTr9hU2ZYeBYE4=; b=BR9kk23w1TDSJ+3csYfhJZUG5rP5jbo7aTR7xN5i6D791ytRynf0iNueHIfWD1fPRmtdGaiSWpR6yZ6+mxGd615VKeDcX7Ew98RM3dM7FlrKDllu5M5bRRsXoXhJhbo7BOcMmVziY6FeM6Z41ASaEBZXQam/I+4D2L7wy42PcMc= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ2PR10MB7672.namprd10.prod.outlook.com (2603:10b6:a03:53e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.24; Mon, 13 Mar 2023 11:10:53 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%6]) with mapi id 15.20.6178.024; Mon, 13 Mar 2023 11:10:53 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, hch@lst.de, dgilbert@interlog.com, hare@suse.com, ming.lei@redhat.com, bvanassche@acm.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, John Garry Subject: [PATCH 7/9] scsi: scsi_debug: Use blk_mq_tagset_busy_iter() in stop_all_queued() Date: Mon, 13 Mar 2023 11:10:17 +0000 Message-Id: <20230313111019.1521680-8-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230313111019.1521680-1-john.g.garry@oracle.com> References: <20230313111019.1521680-1-john.g.garry@oracle.com> X-ClientProxiedBy: SA9PR10CA0003.namprd10.prod.outlook.com (2603:10b6:806:a7::8) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ2PR10MB7672:EE_ X-MS-Office365-Filtering-Correlation-Id: 15439fc5-4b21-49bb-00fc-08db23b39c23 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aubg+tfMCFh5Z3/9cXLc+MBRYm2h3lYP2Umw5TvA2zFVNJe5VXKWpbSWetsEFDDNsUWGUecYR7+jZ06UMgfGESzVgTlrD+h9CZdzcEAXOAcUUPHUeeowjg6L+96saebc4Lutaatgksx/9Kiv8/WcO5RZ5+YDwnhAnFrkvAObZDK8Y1P5Xb4Avp+OoDxEYA34zpT2Ok7EHmB5k5fJWVmHLJOkf3EOqEWsARB5Pi0IqEdm6QsacPFmr9AkcSmqS977AMYguFtm0sZPMZ1lmGjk2WlnSKer6roBpxaL/tBowziWTieIlDybhTd7jnRaXzOqSZZ5NLPkvyRxU71vc6mJBxOAR5X6cdgEVylRrD/dq/PPpQCEq3ZENLJ8oscj7sQLiVVYXfIYDo6KbLd3CYURYAa6IRRjjN2D4L8jcp5YT47gujGdMFufv70kKQm84+35GPjhX8hP7uZuKfq2We8vLRYvV0f/PKvAkw3x+f8I3XQ25bwgkqSTY1ogrz7tMCsz9K4nRpaBG79XanAwpft4aTdbcEtv7ZYPxsD3/8Ki8hJOC1lP1dZjhtWa4GuxuE25RuM6rWt5sR6YgO8GanyBYR9Uylz2xC1DYi5ccn+d1rIr4xlvigazMhwdq3myjnJLV+iO+fcJeRJ1Tm/5awjQew== 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)(39860400002)(396003)(136003)(346002)(376002)(366004)(451199018)(66946007)(66556008)(66476007)(8676002)(4326008)(316002)(8936002)(5660300002)(41300700001)(6666004)(107886003)(6512007)(6506007)(26005)(1076003)(186003)(2616005)(83380400001)(478600001)(6486002)(103116003)(86362001)(36756003)(38100700002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: II/XHegazTjzWuPbk/aWE27BVYNt3MFJB9k+bA4B1WH/pr5UOKmkbl2LIjAb8b8udbqpFIcC30HRwHducc10q7rzh08xgthjrAQ9FXqO9cnOCEbqwcxA3Sy0U+mcutrSdCwbCWTACF19e6pR+Vh6Mnimnud9E1uxXkLWkvV0rIVJIAMUQTBNpWZcurAQd0AhxeGfHK2TjfFDdQypXmnB0cSUuBa610vIJPmMl5NTcfQOCblrYpE32CmGHP6NKSsaZfI02FmQonMSO+fMEf2r6qSlt1qHhSxdZBmLcHcZ5OEzhwgF6vUwFx01RDijH65X7nwOKeo2sjaSD/hprBgxxcuTHr57SXAPhwKVJObxqfxhGyFMxFwM9E51aLlWRX70lCo1EbXQB4+7FdNe5g7W3xe/ZtsrP796Pr73vtKGFx3tKtJBpNalHncUn9kAQNVptAPYTsD+59QO0NqaiF8il9JK8ZmJuQLap8H4Lv/j84fypU63DrI0yhjW4WzpsaAXL7BSzRM126mgXNAF/dH89Wlncg/Vej4gZlm417SocLFooEkNl/SvMl1YWkaO7C/yfW1su9dsfSx3jeTPvP4GbFgXyQklpiyyKRRusveBNJFkxjgKv7JkPctOS8s1aD7iKbTh0c76Q1dfURsnTCSSFUZf+hrCD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2PXl5id5ZEkuNJ4gJjB5CwpdIkx9lJvAvq5MCKSeVjWWfPKpemA9hiZ1ZoZvSMUBUrqEw38cMdmKmus7hWOd77kUsjnoOr3D0A+1ivB3SDn9nBxOMiB2OMZu32ijBiUhos+2sIUkzAr/VZOb/W1jBt+zCM2pts6MvWPZ8xuMTaMhhOtpC8EQdzQompYXbMzgvLJ/YlZt14HZMjAWnOeNAcrrSrtRQUH+rAibYwe3Uaz0lT95oCIgoiuUPJXNWeoJS+S+xl41AXCBxUfj8UHwTnN0HM9206OWN05JP76/Dj1x9sC1s85ruakta5gB+a35gxJK9tU2RlxZ8E3ulvQSgYF0OcT01V9evQOhZcXVyzssn6+RcEuDX+h+U6M+cIq7ifTYJvVd43CYcc3hawsZohoQfNqiu9utP1LgqP1ET30rI+pDPRiQ31wGy3E4inGECdYtbFXNPl4Q9248UTH8v22eYAdEWEiURojm8OrmI8VSyKQEtCTUfYZhmlEEwKRuc3gUIaWjL/bvsX/vkdli7g1x+t8DjfoFuT7cXb50FvIaf8wOtN0IiQdtMaHxCG7P/l3TQXp5LeQgxY8wlI4u0jp/47uycUx32/NpMBD05p91gKICFw3qdeDWxoUR5FQqjlUSPE3XMXi72wxi9cjSKCiUa3JcW+OC8eG0ZWHArp87knU3jbtLwUeLPukYPTr3L6+ItmbYTD8T2kGKdAHdx8Jv9Jgk1jzCyD/NU5Jm0e9CUguhKjSCxpwSltqL8ifyfWQe97Um4ChUO7pkrm5lKG2YUUPpJF9d4lNJjBWR7gJIL+sW1EAXPAnvG4REGuFDvzcjpVq0/785ZRaG/29Tsdq7oBaQu+DIHRrXmhikPd+PWYbHaf1ly+NhiY7On5hc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15439fc5-4b21-49bb-00fc-08db23b39c23 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2023 11:10:53.0277 (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: r6ozOh8FRcTMqd3qvfGrFuuHon7rliSXZh+lj9nVJ5gEroHAFaaE4ErkmJZohIB6RXOdh/pFn50YxDJeHPpLEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7672 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-13_04,2023-03-13_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 suspectscore=0 spamscore=0 malwarescore=0 adultscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303130091 X-Proofpoint-GUID: AXiV1dRmGVt5ZcKk87q1Gp28NPSeeLZ_ X-Proofpoint-ORIG-GUID: AXiV1dRmGVt5ZcKk87q1Gp28NPSeeLZ_ 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 890241b852ec..cc2da4cc62b5 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -5324,40 +5324,29 @@ static bool scsi_debug_abort_cmnd(struct scsi_cmnd *cmnd) return res; } +/* + * All we can do is set the cmnd as internally aborted and wait for it to + * finish. We cannot call scsi_done() as normal completion path may do that. + */ +static bool sdebug_stop_cmnd(struct request *rq, void *data) +{ + scsi_debug_abort_cmnd(blk_mq_rq_to_pdu(rq)); + + return true; +} + /* Deletes (stops) timers or work queues of all queued commands */ static void stop_all_queued(void) { - unsigned long iflags, flags; - int j, k; - struct sdebug_queue *sqp; + struct sdebug_host_info *sdhp; - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { - spin_lock_irqsave(&sqp->qc_lock, iflags); - for (k = 0; k < SDEBUG_CANQUEUE; ++k) { - if (test_bit(k, sqp->in_use_bm)) { - struct sdebug_queued_cmd *sqcp = sqp->qc_arr[k]; - struct sdebug_scsi_cmd *sdsc; - struct scsi_cmnd *scmd; + mutex_lock(&sdebug_host_list_mutex); + list_for_each_entry(sdhp, &sdebug_host_list, host_list) { + struct Scsi_Host *shost = sdhp->shost; - if (!sqcp) - continue; - scmd = sqcp->scmd; - if (!scmd) - continue; - sdsc = scsi_cmd_priv(scmd); - spin_lock_irqsave(&sdsc->lock, flags); - if (TO_QEUEUED_CMD(scmd) != sqcp) { - spin_unlock_irqrestore(&sdsc->lock, flags); - continue; - } - scsi_debug_stop_cmnd(scmd, NULL); - spin_unlock_irqrestore(&sdsc->lock, flags); - sqp->qc_arr[k] = NULL; - clear_bit(k, sqp->in_use_bm); - } - } - spin_unlock_irqrestore(&sqp->qc_lock, iflags); + blk_mq_tagset_busy_iter(&shost->tag_set, sdebug_stop_cmnd, NULL); } + mutex_unlock(&sdebug_host_list_mutex); } static int scsi_debug_abort(struct scsi_cmnd *SCpnt) From patchwork Mon Mar 13 11:10:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13172413 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 4086FC6FD19 for ; Mon, 13 Mar 2023 11:57:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231233AbjCML55 (ORCPT ); Mon, 13 Mar 2023 07:57:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230415AbjCML5i (ORCPT ); Mon, 13 Mar 2023 07:57:38 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B4E6211EF; Mon, 13 Mar 2023 04:57:35 -0700 (PDT) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32CMpq11016396; Mon, 13 Mar 2023 11:10:58 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=g0Rzw+eRZpRhuJgCsIWnnQHJOZib2dCc0mMTz27LTUQ=; b=iQJN0CelMhu0PiK0GN5fM2dz0/F1++Fjq1nIy3bcAkaej/H98k/KekMz0VntSgBQSivo +D1uXh4uWNYIsFA8OKgtwZ3bkP98DOQbSqDkhb+3D6rLQ0V5cLsYrksJqPSMXCEUVtw3 7uH2oBVLzOzRXRxPN0Kj/nq6Og/eSeIkejQ127TaUrPeAos8MCIq63q1qrmbEmhwahGH gE9fyZhJ19YyL9RKRi73mC0EdlLmtNE2gqw/16ioJP0lgiufujoqo07IKdIZmrfnKKoe mdp+YtwdFqGMU3yiP9J/eNY5OeiAng8qiPPAIqmJEnBvHo+ugWZgwXKLPWdVC8ApQyNJ Rg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p8gjbbkgb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:58 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32D9Ppck002459; Mon, 13 Mar 2023 11:10:57 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2040.outbound.protection.outlook.com [104.47.66.40]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3p8g3b0kf0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F4wX0Z0vcP2rsg5E6M8DyM9qgIjLaiVDvOV8nwnI6v2bgjER2zZdg+HnakP+2ERCFl/yCj5YFmJPJ1GPgtnzcF+0MYCJAlphgquQlnNJjb2+SlZB94PHlQ7IHT4VbkEtohpqErtnrJib70ypNaJeBnMxabBGVlJ+PE8F2awFJ1VPjo/vWu4Od705KxzBh/+KAdPB//lRzTYXH2DOI6L1hMnnF1ev01stnpTSRqdrGhpMiSjTpIL5Yas+z4K+Iay9H85SAtuh8pLyGLH+iQTSF+VXmzc/MjEoP/4VWVYWJT4DODu9Y0g2Q9sZiwIjb9SjsgEYeXye6kMwO4N7vODErQ== 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=g0Rzw+eRZpRhuJgCsIWnnQHJOZib2dCc0mMTz27LTUQ=; b=IlNPDrarbx1wzerMb8VroSri+RnykcgElDsZcJu1pTN2QoqKd8WfqAZKJumEcDmB4iAptvRDiI9UV72vv4WAUYbtIPvV6NoKZdWLYu/q8ZpYpnBWKEDtOFKGP0CJafjhL/Y+IBn0PI1H5maKzxbwVSwxGlSTsfayeWSnblLk8hODsJMYtAarB4O7o+1tkicupXk9Hh+DZwLid9ctiC71ucsoK1m+aT66KPzTmy93rv8Uvhw69G/dPu+NhFCCxQ6oA53bbTlsuYbc4GeBtdH4gRUktLhKLlg+ikzm2qQEXok8AY3Y21SC2iIkVb1vQZPt8HmGJCOJpvt96UU8rpcw/Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=g0Rzw+eRZpRhuJgCsIWnnQHJOZib2dCc0mMTz27LTUQ=; b=sCMW+jrR1LcX/cjVFcYj11Wg4dDu1+6kk1A3kkLmQzFAHFWyGyG+p40z5THmzNQpwdpfgeTi5T3K4H5AIgUOK7GMvyAn8+IH7Ms6JKODXDXDjMOo6CEK7ATkBR5Z5bC735qGpRnoOD1L7EpqSrSGkSJwt8M+b1XqEpVIT+Lr4WU= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ2PR10MB7672.namprd10.prod.outlook.com (2603:10b6:a03:53e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.24; Mon, 13 Mar 2023 11:10:54 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%6]) with mapi id 15.20.6178.024; Mon, 13 Mar 2023 11:10:54 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, hch@lst.de, dgilbert@interlog.com, hare@suse.com, ming.lei@redhat.com, bvanassche@acm.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, John Garry Subject: [PATCH 8/9] scsi: scsi_debug: Use scsi_host_busy() in delay_store() and ndelay_store() Date: Mon, 13 Mar 2023 11:10:18 +0000 Message-Id: <20230313111019.1521680-9-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230313111019.1521680-1-john.g.garry@oracle.com> References: <20230313111019.1521680-1-john.g.garry@oracle.com> X-ClientProxiedBy: SA1P222CA0027.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:22c::11) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ2PR10MB7672:EE_ X-MS-Office365-Filtering-Correlation-Id: 0126624c-171e-4797-0e1c-08db23b39d08 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ddb1KhGR8SjBsmuIta5MRZx+tol+ySNx5Fr8y+lLP/Onz7w2DNJiwml4XBkdQzLQkIpDmScIrBd3GLh5stDwKT/9+GNeS0OIeh6uopmt5GUAVnmn+OlB5kMbFr40kIVVCy2bJ2arXaY6sD5rUH5cBFFIbVmsEfxn1OI/DgoKnedv1eF++lg0gkrQLsmn0o5l4G0T8pa0MxL58WyE47zc6+FBEPHaMDevusXmfDB3QKr+3Rp2X54w5hQ5GxZ2yMf/bbRnYtpprwilQ+hOb7OAhfUP23vKT/c6bmc5x39dJpCnHgU6gpFn6+6maAxdysRaNTTUssLbHSTW2eEGqDsJeZv5VZxreRVejD2YYLvgrTR/jIVpIqiBsyMn7rrSKHmJHYBQcbxrv2N1Uf9MjQwIiHKS/qU9on33pUr+gTG0JF9U/B9FtPWvhGF/jcvUo7QJ1pnly0H2PCX01odMVjjX3eiWwh30zfCnQB8MvszP8xKMzeppOOtM0xeCxaPOo0zcT+9QyxA2mAjj2S0AWRQthAl5yOdNm6hA6VWZRRnEU7E7lHZB2lxSGsL3DkVcfRa/ei4xcujgKY5AMCIbdmD/J+6T8YbIAw+RfKS6pHK0XJ44AyWQWkuuheZM8o7X0QwbVKfEUdJelkLyi1/a9muYNA== 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)(39860400002)(396003)(136003)(346002)(376002)(366004)(451199018)(66946007)(66556008)(66476007)(8676002)(4326008)(316002)(8936002)(5660300002)(41300700001)(6666004)(107886003)(6512007)(6506007)(26005)(1076003)(186003)(2616005)(83380400001)(478600001)(6486002)(103116003)(86362001)(36756003)(38100700002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7D5RLzCvCCUNhWLLSk4ijFySZfz2CCHyM7vQ03GN7rYapcuj1Eaa64ac9sofqvyEy/hwMubuv/WUlEMm9MC6QU34xW/q+42iIDtVKAxLARx8FKDTKFTV+1VHz0wqaXvOupaJb80JUwF7q1dQWOV/lTYWasq57tYko3TCrwv+z25/mzV/I6asLjnpl/GzQaPs0wTlMmrbWksHRX5R+2AauQiSGBXv7pptoHiq1380BoOHxwX16kJlEPSo2Cxr9rMrjmOgfxiQUlQvgRL8fWMO8gjqWN8dxWwaZenZFRpvz0l3ozz8u1T+XGAoGq+0K8EK+aE56BZ9w+PF+zeU3M/0c/Dq34a4O6t6DwiSGWL9CvWRGdmU7+RM83GqRO0MVlcY5EJPnM5K9Syfegwn4oolZA9kvkvC4G2MV5JAij/YUlLeZQykoSv0D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T7yGCRWPtXNzB/3loENpzGd45jse9uiE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0126624c-171e-4797-0e1c-08db23b39d08 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2023 11:10:54.4975 (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: 35wrOQbASI6CdLYWcOn+rFKr9fr82dMsb+s+S1OiPEDh1DGTIZm3/rrv7W2R9tJk20negpVRcWqqdAUHiMfTPg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7672 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-13_04,2023-03-13_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303130091 X-Proofpoint-ORIG-GUID: HzIi2gXS7Pb7fhmvDXLLLZAuOmeJsq2A X-Proofpoint-GUID: HzIi2gXS7Pb7fhmvDXLLLZAuOmeJsq2A 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 will not 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 cc2da4cc62b5..7ef195072d97 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -6059,16 +6059,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; } @@ -6101,20 +6100,20 @@ static ssize_t ndelay_store(struct device_driver *ddp, const char *buf, (ndelay >= 0) && (ndelay < (1000 * 1000 * 1000))) { res = count; if (sdebug_ndelay != ndelay) { - int j, k; - struct sdebug_queue *sqp; + struct sdebug_host_info *sdhp; mutex_lock(&sdebug_host_list_mutex); block_unblock_all_queues(true); - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; - ++j, ++sqp) { - k = find_first_bit(sqp->in_use_bm, - sdebug_max_queue); - if (k != sdebug_max_queue) { + + list_for_each_entry(sdhp, &sdebug_host_list, host_list) { + struct Scsi_Host *shost = sdhp->shost; + + if (scsi_host_busy(shost)) { res = -EBUSY; /* queued commands */ break; } } + if (res > 0) { sdebug_ndelay = ndelay; sdebug_jdelay = ndelay ? JDELAY_OVERRIDDEN From patchwork Mon Mar 13 11:10:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13172476 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 6D9ADC61DA4 for ; Mon, 13 Mar 2023 12:50:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230151AbjCMMuD (ORCPT ); Mon, 13 Mar 2023 08:50:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230252AbjCMMtv (ORCPT ); Mon, 13 Mar 2023 08:49:51 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C645E34002; Mon, 13 Mar 2023 05:49:20 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32CNnMkh027922; Mon, 13 Mar 2023 11:11:01 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=ucE3cL4PR7AOUni+7/JDokTo+JB5U/1xhxd2PuZSBqI=; b=ETLlxGV/FnZmKjd3w9ePaPn6jEU3hZBAHKvtbmraru6csUQ/N23baNNdpZr7CwfnB5mf g3nxwgseZ8DMRPOwBOahD7dW5BeXNjrCCdOm+qbblfOfgmO/fYAwFTCLaafKA2Ua6NeD zUVsbzMZBqZAgL9nPm21j2gLvIYsiQOMseVPW+omKlsPQt8+pK8XbCyiJln/dp5+N4Wu +Dj5pP2+C4+xUanVAuLkiEClJbGcfKDhfC9+m+vxGaU42or41DaSDfqJSUe8V+XrXC4A 3VdOoRqygB9y0m0OmGLSAPIj/ngwVK3DVsCH7US6sKofRKsdYnxdLlb0DSIDSCMNgqhR HQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p8hhabgqd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:11:00 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32D9abXM002270; Mon, 13 Mar 2023 11:10:59 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2046.outbound.protection.outlook.com [104.47.66.46]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3p8g3b0kgm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Mar 2023 11:10:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gYhLKqER1KiBx/SMbfcWg+ib8tqznGJHbYxJtYy6YmYLG4KS6907kWgD7f5rYsXRma+n0bu1rAI2AL6tJqg3aiiYhQ2FHCJl+XycAg3nRlPSdrciAa3rVX90j2mRjwie1eDxjkZScn0Q6zM3bBZS5FWRo5+bHarj6DAlOTHv2s0WbJ9vnR7jzv9B7nYq7xA44vNmja/2V0ZYzDquAyfFe0CIBKzzSQvJpCxOUUY22N39nPno3CMDVMt7EA1LB7J38fxy22oqYMbUe9sZrqjEYzgaBTexd8skG4Nv5WkcJubBdmhHnGveLVykehfcHteMxOQ5xngUWK7SlRrPU7sAeg== 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=ucE3cL4PR7AOUni+7/JDokTo+JB5U/1xhxd2PuZSBqI=; b=ZRMoxqDITgfzXkx5x3/7KGJTrsz4UT8b6EtekAykC59yq05i1gVuT+vuceWNj56JAeWzUgPgdFsmdI2jehYMUBmvljjgfCo4xPLVlJXj1XkEwg8q/7StfCJ0HrK6VhQ6e8OjEDYcQ4zHNXF1orQz612IKCdtyrRlXvtDDgp3q4SQcspsrM2eYaxeC5icgorUR9Co1uGw7SpV7P94POXjuKvVgxi30wnNJWjlvkrB3/i9kqUhtQeNgsjLOZbuO6x0zofVOfo6833WR+lUNjog2eoAYzCME1gnhKg/V3TEskaY2Nku6IXQlPmHUbK5y6lrGEvB8pgxX1nvEgBMgy37ng== 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=ucE3cL4PR7AOUni+7/JDokTo+JB5U/1xhxd2PuZSBqI=; b=GH5n576svcS84mB8tCjxN3S80rZVvLg8iZus0XQ0fPJc+603RbKlOBgrubePOcLFF83C2kDLXWM+Yins5SpkONmZwpwMxrye9MgevuOMIjqiDuVEyucjdnQXSfTkBATurpDznyLyFVyz12XxcrrXu8cmU3uKaJoPh9Er+MEuuvQ= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ2PR10MB7672.namprd10.prod.outlook.com (2603:10b6:a03:53e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.24; Mon, 13 Mar 2023 11:10:56 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::7276:bc4c:17a0:7267%6]) with mapi id 15.20.6178.024; Mon, 13 Mar 2023 11:10:56 +0000 From: John Garry To: jejb@linux.ibm.com, martin.petersen@oracle.com, hch@lst.de, dgilbert@interlog.com, hare@suse.com, ming.lei@redhat.com, bvanassche@acm.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, John Garry Subject: [PATCH RFC 9/9] scsi: scsi_debug: Drop sdebug_queue concept Date: Mon, 13 Mar 2023 11:10:19 +0000 Message-Id: <20230313111019.1521680-10-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230313111019.1521680-1-john.g.garry@oracle.com> References: <20230313111019.1521680-1-john.g.garry@oracle.com> X-ClientProxiedBy: SN6PR05CA0025.namprd05.prod.outlook.com (2603:10b6:805:de::38) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ2PR10MB7672:EE_ X-MS-Office365-Filtering-Correlation-Id: 42b4f940-02f5-4bf1-3f60-08db23b39e02 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /9w35mZwx7nAT/lqKneFwabgU+3qMcC+ANmtLxH80Jhh2+4UgaUxYTl+8vytJSLK1LUnbU91rLBUVNUQQQIUMECJjxgEDoQHB6lVhouzPD6DoKkgqnyiuHW/AlDma7MuTOl47lqdEH8JHe3ymQ8I0QTcXZg+zGjAQEYv/UJ8r8yJikTpK+xOQRMTO3AwefJkexTl2I7I6oa+Ov2Nd/EKX0V2J39B6wgoyDdd3bUUl4MvDQxHKTOr/8+6sUgjo/lq3pVEV/ZKAaNvB0fkUuZEi1uwPHkhu4oeVveFqKrPcrpCO3bcH12vWteM1JRXVG5N6dMFmk21xcGvhr/nBF5sB846PFrkN48kOx4vqCPYaI++3sxat3NyhHMlGVUApaVWzOTYoPNHFsh4FLxhNyuk5sFAu/1JDK8LDUfHe3rvACQjIVM8J6p/9iQyCpZbCIp4g7bzi0/v0lVpeymBVlB2hwV4Oavv1AqCXIINQwx4ZwrlPbVVV6Yp/YQPeB6ULNLOZQLjcPmcfnlGYqGBHTtux74BkhplJkE89pQJ1jRlk1L2oTPX/H/5QVPnHCu7DaXJWMDSmOADFHoIY/E+GpPaiwH4tRn6asmvuztmb3SnxRHdZklU4trxw6Aino3md3BTRZx3wy+AiHUFHIhXG+b5+kDxqU4H+h5gMNR0FRGJolZbCgqsIkEgDzAKaXGUv5Ak 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)(39860400002)(396003)(136003)(346002)(376002)(366004)(451199018)(66946007)(66556008)(66476007)(8676002)(4326008)(316002)(8936002)(5660300002)(41300700001)(6666004)(107886003)(6512007)(6506007)(26005)(1076003)(186003)(2616005)(83380400001)(478600001)(6486002)(30864003)(103116003)(86362001)(36756003)(38100700002)(2906002)(66899018)(21314003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: oZh4/Uche7wjDzbJW9l0CzknpArd/S3UfNZwqEG73rYYC39gcFGjj0e/d5QNWmYboEoniuvFPBxiLhkwO441UyYP+2GmCNDFHHRxF9dqcBMxBnSHi6lD+1UqPh7vYFqqlyZsgkNX1ogU28O1HrnfsmZDyxS/3hXtQuwqEygSjEFlTn7SKkxUHg53P9Dmd2JUZPkX6W021cuiiErfgNpFSNNWt/DHVy1YOnYq2G3Vcj6BJV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RcvEt3jglNNnNHJzLWaCJqzmQ3HhQ4PFZt5JdEccyoQi1eWfRDo90Dg1DX3HIB0fo/htzwZzQhwEt0AejXFQm3SEbdCKfzTcu18y82RVlBzCC72Y2oNbhnlmMgru13Dy+qzSU+8X1ZFu4CvHcnlHE9+9+D2wVS6u+ZJ4i0SXPRmph/rXty+JT7xGHyL6PaCp2UMDEE0ZxSxB5NzOU4hlYhzjQmka37VLgUifQWblsHtlwboY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 42b4f940-02f5-4bf1-3f60-08db23b39e02 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2023 11:10:56.1684 (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: ypissdXOOeL11WBrpz2M7pU4OgPTDIgJUsSiYqKOjN+OCAs4JJ0Bo2m9CwTh8Z4t1VTDohhu0Z+PqKwOHFK0rQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7672 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-13_04,2023-03-13_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303130091 X-Proofpoint-GUID: zHUE6ermDfdbM7UqBczb8pwBf3DiZgeV X-Proofpoint-ORIG-GUID: zHUE6ermDfdbM7UqBczb8pwBf3DiZgeV Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The struct sdebug_queue is to manage tags and hold the associated queued command entry pointer (for that tag). Since the tagset iters are now used for functions like sdebug_blk_mq_poll(), there is no real need to manage these queues. Indeed, blk-mq already provides what we need for managing tags and requests. However the sdebug_queue concept was still being used in max_queue_store() to find tags which we need to "retire" when lowering sdebug_max_queue. However the method to reduce sdebug_max_queue separate from shost->can_queue is fundamentally broken. 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 meant that we can easily overload the shost. Indeed, since sdebug_q_arr is shared amount all shosts, it is possible to easily consume all tags in sdebug_q_arr while the shosts are not overloaded according to SCSI ml/block layer, i.e. shosts may be sent more commands than they can consume. Resolve this by changing per-HW queue context tag depth when we change sdebug_max_queue. The submit queue tags info shown in scsi_debug_show_info() is dropped - tag info may be got from /sys/kernel/debug/block/ path. Signed-off-by: John Garry --- We should not call sbitmap_queue_resize(), below - any better ideas? drivers/scsi/scsi_debug.c | 246 +++++++------------------------------- 1 file changed, 42 insertions(+), 204 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 7ef195072d97..2bfb6db538fc 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -341,8 +341,6 @@ struct sdebug_defer { struct hrtimer hrt; struct execute_work ew; ktime_t cmpl_ts;/* time since boot to complete this cmd */ - int sqa_idx; /* index of sdebug_queue array */ - int hc_idx; /* hostwide tag index */ int issuing_cpu; bool aborted; /* true when blk_abort_request() already called */ enum sdeb_defer_type defer_t; @@ -360,12 +358,6 @@ struct sdebug_scsi_cmd { spinlock_t lock; }; -struct sdebug_queue { - struct sdebug_queued_cmd *qc_arr[SDEBUG_CANQUEUE]; - unsigned long in_use_bm[SDEBUG_CANQUEUE_WORDS]; - spinlock_t qc_lock; -}; - static atomic_t sdebug_cmnd_count; /* number of incoming commands */ static atomic_t sdebug_completions; /* count of deferred completions */ static atomic_t sdebug_miss_cpus; /* submission + completion cpus differ */ @@ -848,8 +840,8 @@ static int sdeb_zbc_max_open = DEF_ZBC_MAX_OPEN_ZONES; static int sdeb_zbc_nr_conv = DEF_ZBC_NR_CONV_ZONES; static int submit_queues = DEF_SUBMIT_QUEUES; /* > 1 for multi-queue (mq) */ + static int poll_queues = 2; /* iouring iopoll interface.*/ -static struct sdebug_queue *sdebug_q_arr; /* ptr to array of submit queues */ static DEFINE_RWLOCK(atomic_rw); static DEFINE_RWLOCK(atomic_rw2); @@ -4904,20 +4896,6 @@ static int resp_rwp_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return res; } -static struct sdebug_queue *get_queue(struct scsi_cmnd *cmnd) -{ - u16 hwq; - u32 tag = blk_mq_unique_tag(scsi_cmd_to_rq(cmnd)); - - hwq = blk_mq_unique_tag_to_hwq(tag); - - pr_debug("tag=%#x, hwq=%d\n", tag, hwq); - if (WARN_ON_ONCE(hwq >= submit_queues)) - hwq = 0; - - return sdebug_q_arr + hwq; -} - static u32 get_tag(struct scsi_cmnd *cmnd) { return blk_mq_unique_tag(scsi_cmd_to_rq(cmnd)); @@ -4927,68 +4905,30 @@ static u32 get_tag(struct scsi_cmnd *cmnd) static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) { struct sdebug_queued_cmd *sqcp = container_of(sd_dp, struct sdebug_queued_cmd, sd_dp); - int qc_idx; - int retiring = 0; - unsigned long flags, iflags; + unsigned long flags; struct scsi_cmnd *scp = sqcp->scmd; struct sdebug_scsi_cmd *sdsc; bool aborted; - struct sdebug_queue *sqp; - qc_idx = sd_dp->sqa_idx; if (sdebug_statistics) { atomic_inc(&sdebug_completions); if (raw_smp_processor_id() != sd_dp->issuing_cpu) atomic_inc(&sdebug_miss_cpus); } + if (!scp) { pr_err("scmd=NULL\n"); goto out; } - if (unlikely((qc_idx < 0) || (qc_idx >= SDEBUG_CANQUEUE))) { - pr_err("wild qc_idx=%d\n", qc_idx); - goto out; - } sdsc = scsi_cmd_priv(scp); - sqp = get_queue(scp); - spin_lock_irqsave(&sqp->qc_lock, iflags); spin_lock_irqsave(&sdsc->lock, flags); aborted = sd_dp->aborted; if (unlikely(aborted)) sd_dp->aborted = false; ASSIGN_QEUEUED_CMD(scp, NULL); - 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); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - pr_err("Unexpected completion qc_idx=%d\n", qc_idx); - 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); if (aborted) { pr_info("bypassing scsi_done() due to aborted cmd, kicking-off EH\n"); @@ -5275,21 +5215,18 @@ static bool stop_qc_helper(struct sdebug_defer *sd_dp, } -static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd, int *sqa_idx) +static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd) { enum sdeb_defer_type l_defer_t; - struct sdebug_queued_cmd *sqcp; struct sdebug_defer *sd_dp; struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd); + struct sdebug_queued_cmd *sqcp = TO_QEUEUED_CMD(cmnd); lockdep_assert_held(&sdsc->lock); - sqcp = TO_QEUEUED_CMD(cmnd); if (!sqcp) return false; sd_dp = &sqcp->sd_dp; - if (sqa_idx) - *sqa_idx = sd_dp->sqa_idx; l_defer_t = READ_ONCE(sd_dp->defer_t); ASSIGN_QEUEUED_CMD(cmnd, NULL); @@ -5305,22 +5242,13 @@ static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd, int *sqa_idx) static bool scsi_debug_abort_cmnd(struct scsi_cmnd *cmnd) { struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd); - struct sdebug_queue *sqp = get_queue(cmnd); - unsigned long flags, iflags; - int k = -1; + unsigned long flags; bool res; spin_lock_irqsave(&sdsc->lock, flags); - res = scsi_debug_stop_cmnd(cmnd, &k); + res = scsi_debug_stop_cmnd(cmnd); spin_unlock_irqrestore(&sdsc->lock, flags); - if (k >= 0) { - spin_lock_irqsave(&sqp->qc_lock, iflags); - clear_bit(k, sqp->in_use_bm); - sqp->qc_arr[k] = NULL; - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - } - return res; } @@ -5578,7 +5506,6 @@ struct sdebug_queued_cmd *sdebug_alloc_queued_cmd(struct scsi_cmnd *scmd) INIT_WORK(&sd_dp->ew.work, sdebug_q_cmd_wq_complete); sqcp->scmd = scmd; - sd_dp->sqa_idx = -1; return sqcp; } @@ -5597,13 +5524,11 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, struct request *rq = scsi_cmd_to_rq(cmnd); bool polled = rq->cmd_flags & REQ_POLLED; struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd); - unsigned long iflags, flags; + unsigned long flags; u64 ns_from_boot = 0; - struct sdebug_queue *sqp; struct sdebug_queued_cmd *sqcp; struct scsi_device *sdp; struct sdebug_defer *sd_dp; - int k; if (unlikely(devip == NULL)) { if (scsi_result == 0) @@ -5615,8 +5540,6 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, if (delta_jiff == 0) goto respond_in_thread; - sqp = get_queue(cmnd); - spin_lock_irqsave(&sqp->qc_lock, iflags); if (unlikely(sdebug_every_nth && (SDEBUG_OPT_RARE_TSF & sdebug_opts) && (scsi_result == 0))) { @@ -5635,33 +5558,12 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, } } - k = find_first_zero_bit(sqp->in_use_bm, sdebug_max_queue); - if (unlikely(k >= sdebug_max_queue)) { - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - if (scsi_result) - goto respond_in_thread; - scsi_result = device_qfull_result; - if (SDEBUG_OPT_Q_NOISE & sdebug_opts) - sdev_printk(KERN_INFO, sdp, "%s: max_queue=%d exceeded: TASK SET FULL\n", - __func__, sdebug_max_queue); - goto respond_in_thread; - } - set_bit(k, sqp->in_use_bm); - sqcp = sdebug_alloc_queued_cmd(cmnd); if (!sqcp) { - clear_bit(k, sqp->in_use_bm); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); + pr_err("%s no alloc\n", __func__); return SCSI_MLQUEUE_HOST_BUSY; } sd_dp = &sqcp->sd_dp; - sd_dp->sqa_idx = k; - sqp->qc_arr[k] = sqcp; - spin_unlock_irqrestore(&sqp->qc_lock, iflags); - - /* Set the hostwide tag */ - if (sdebug_host_max_queue) - sd_dp->hc_idx = get_tag(cmnd); if (polled) ns_from_boot = ktime_get_boottime_ns(); @@ -5708,10 +5610,6 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, u64 d = ktime_get_boottime_ns() - ns_from_boot; if (kt <= d) { /* elapsed duration >= kt */ - spin_lock_irqsave(&sqp->qc_lock, iflags); - sqp->qc_arr[k] = NULL; - clear_bit(k, sqp->in_use_bm); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); /* call scsi_done() from this thread */ sdebug_free_queued_cmd(sqcp); scsi_done(cmnd); @@ -5974,8 +5872,7 @@ static int scsi_debug_write_info(struct Scsi_Host *host, char *buffer, * output are not atomics so might be inaccurate in a busy system. */ static int scsi_debug_show_info(struct seq_file *m, struct Scsi_Host *host) { - int f, j, l; - struct sdebug_queue *sqp; + int j; struct sdebug_host_info *sdhp; seq_printf(m, "scsi_debug adapter driver, version %s [%s]\n", @@ -6003,16 +5900,6 @@ static int scsi_debug_show_info(struct seq_file *m, struct Scsi_Host *host) atomic_read(&sdebug_a_tsf), atomic_read(&sdeb_mq_poll_count)); - seq_printf(m, "submit_queues=%d\n", submit_queues); - for (j = 0, sqp = sdebug_q_arr; j < submit_queues; ++j, ++sqp) { - seq_printf(m, " queue %d:\n", j); - f = find_first_bit(sqp->in_use_bm, sdebug_max_queue); - if (f != sdebug_max_queue) { - l = find_last_bit(sqp->in_use_bm, sdebug_max_queue); - seq_printf(m, " in_use_bm BUSY: %s: %d,%d\n", - "first,last bits", f, l); - } - } seq_printf(m, "this host_no=%d\n", host->host_no); if (!xa_empty(per_store_ap)) { @@ -6428,30 +6315,36 @@ 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)) { + (n <= SDEBUG_CANQUEUE)) { + struct sdebug_host_info *sdhp; + 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; + list_for_each_entry(sdhp, &sdebug_host_list, host_list) { + struct Scsi_Host *shost = sdhp->shost; + struct blk_mq_tag_set *tag_set = &shost->tag_set; + struct scsi_device *sdev; + int i; + + scsi_block_requests(shost); + shost_for_each_device(sdev, shost) + scsi_device_quiesce(sdev); + + for (i = 0; i < tag_set->nr_hw_queues; i++) { + struct blk_mq_tags *tags = tag_set->tags[i]; + + /* yuck, we should not do this */ + sbitmap_queue_resize(&tags->bitmap_tags, n); + } + + shost_for_each_device(sdev, shost) + scsi_device_resume(sdev); + scsi_unblock_requests(shost); } - 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); - else - atomic_set(&retired_max_queue, 0); - block_unblock_all_queues(false); mutex_unlock(&sdebug_host_list_mutex); + sdebug_max_queue = n; return count; } return -EINVAL; @@ -6975,13 +6868,6 @@ static int __init scsi_debug_init(void) sdebug_max_queue); } - sdebug_q_arr = kcalloc(submit_queues, sizeof(struct sdebug_queue), - GFP_KERNEL); - if (sdebug_q_arr == NULL) - return -ENOMEM; - for (k = 0; k < submit_queues; ++k) - spin_lock_init(&sdebug_q_arr[k].qc_lock); - /* * check for host managed zoned block device specified with * ptype=0x14 or zbc=XXX. @@ -6990,10 +6876,8 @@ static int __init scsi_debug_init(void) sdeb_zbc_model = BLK_ZONED_HM; } else if (sdeb_zbc_model_s && *sdeb_zbc_model_s) { k = sdeb_zbc_model_str(sdeb_zbc_model_s); - if (k < 0) { - ret = k; - goto free_q_arr; - } + if (k < 0) + return k; sdeb_zbc_model = k; switch (sdeb_zbc_model) { case BLK_ZONED_NONE: @@ -7005,8 +6889,7 @@ static int __init scsi_debug_init(void) break; default: pr_err("Invalid ZBC model\n"); - ret = -EINVAL; - goto free_q_arr; + return -EINVAL; } } if (sdeb_zbc_model != BLK_ZONED_NONE) { @@ -7053,17 +6936,14 @@ static int __init scsi_debug_init(void) sdebug_unmap_granularity <= sdebug_unmap_alignment) { pr_err("ERR: unmap_granularity <= unmap_alignment\n"); - ret = -EINVAL; - goto free_q_arr; + return -EINVAL; } } xa_init_flags(per_store_ap, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ); if (want_store) { idx = sdebug_add_store(); - if (idx < 0) { - ret = idx; - goto free_q_arr; - } + if (idx < 0) + return idx; } pseudo_primary = root_device_register("pseudo_0"); @@ -7120,8 +7000,6 @@ static int __init scsi_debug_init(void) root_device_unregister(pseudo_primary); free_vm: sdebug_erase_store(idx, NULL); -free_q_arr: - kfree(sdebug_q_arr); return ret; } @@ -7138,7 +7016,6 @@ static void __exit scsi_debug_exit(void) sdebug_erase_all_stores(false); xa_destroy(per_store_ap); - kfree(sdebug_q_arr); } device_initcall(scsi_debug_init); @@ -7514,11 +7391,8 @@ static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) u32 unique_tag = blk_mq_unique_tag(rq); u16 hwq = blk_mq_unique_tag_to_hwq(unique_tag); struct sdebug_queued_cmd *sqcp; - struct sdebug_queue *sqp; unsigned long flags; int queue_num = data->queue_num; - bool retiring = false; - int qc_idx; ktime_t time; /* We're only interested in one queue for this iteration */ @@ -7537,7 +7411,7 @@ static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) spin_unlock_irqrestore(&sdsc->lock, flags); return true; } - sqp = sdebug_q_arr + queue_num; + sd_dp = &sqcp->sd_dp; @@ -7552,36 +7426,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))) { - spin_unlock_irqrestore(&sdsc->lock, flags); - pr_err("Unexpected completion sqp %p queue_num=%d qc_idx=%u\n", - sqp, queue_num, qc_idx); - sdebug_free_queued_cmd(sqcp); - return true; - } - - if (unlikely(retiring)) { /* user has reduced max_queue */ - int k, retval = atomic_read(&retired_max_queue); - - if (qc_idx >= retval) { - pr_err("index %d too large\n", retval); - spin_unlock_irqrestore(&sdsc->lock, flags); - 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); @@ -7601,20 +7445,14 @@ static bool sdebug_blk_mq_poll_iter(struct request *rq, void *opaque) static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) { int num_entries = 0; - unsigned long iflags; - struct sdebug_queue *sqp; struct sdebug_blk_mq_poll_data data = { .queue_num = queue_num, .num_entries = &num_entries, }; - sqp = sdebug_q_arr + queue_num; - - spin_lock_irqsave(&sqp->qc_lock, iflags); blk_mq_tagset_busy_iter(&shost->tag_set, sdebug_blk_mq_poll_iter, &data); - spin_unlock_irqrestore(&sqp->qc_lock, iflags); if (num_entries > 0) atomic_add(num_entries, &sdeb_mq_poll_count); return num_entries;