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: 662936 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/w9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t16DlURidh5Y8v9+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: 662942 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+oUrGE2MOlhcE6HRRuq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fdtFzkKn9xm7jw3VKf1WzAfIp1a7Yd24p2kn1ykFD30CAKzLvQIe1MBCH4+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: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: 662943 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+hrCDyrrGnV5TSX/Mf5zpjZNdLcmem8VVInP9k5Am/+Ef9yUVf4xAlWmBI49FRPKJ5vKAEyF8CNkjkZ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dmKmus7hWOd77kUsjnoOr3D0A+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: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: 662937 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/DHVy1YOnYq2G3Vcj6BJVE4EnJnQ04gPe1N3hzg6weQvVnUAW1bnUpqS7gCvibyLN1bXzGE8oSYFYQGjNtSPnVX04iXmf2KwoDDA85c2T1MavLyinkGtokIMxP1Hz5HEfZg8xS65t2VzAFjbnPemZOI6Aa/ZWv1pSjiWk1BclzLajaQunf76mGg0/h70WPplkDocBhKeB8g39o5WqKwL6ionGY1fWvL5rPeKv3hHtT/fyk7HzK/lWFKZ7J9ZRtETBvpOxtw31rsXmASWHC/+QZs0X+xzFV+cjPeQF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change-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;