From patchwork Thu Dec 15 15:37:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 33690 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp439173wrn; Thu, 15 Dec 2022 07:52:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf6QmDLzBrAqTJwJSdPIPID+1gFVFMsV46icOJYQNyQ4lJn0sQ8sRnLwarUz3yLwZx9ronUG X-Received: by 2002:a05:6a21:598:b0:ad:c2f5:27a0 with SMTP id lw24-20020a056a21059800b000adc2f527a0mr15417863pzb.42.1671119522273; Thu, 15 Dec 2022 07:52:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671119522; cv=none; d=google.com; s=arc-20160816; b=Q7ERMlN/0vVEEuFADWd1Wqd2MHpydP6M6YfIAbdJo/R15BcdaqUqYZ88xr3V/Jiiot Pulq859IGOnC1R/awmTZ3ZqgquIbLJ2648JbXIZZuatAihZtmTPK0tR0BrelYm6jaKGA ZHBZVl6gBz8C8mjOAXYonZqh9RNyp9V7dNiI2Bl1oJqFC2vkFd9vgGoVX8vi5TWG9tTF 7oyEaoMQEey6rjY6bMXHU8g6mLMZof0gPboAyheK8W7wNEFxBlwHy885dIlIfsR8BHQY Y/ONK32GzlfkVBzWWsNhMHHHjGB6sEx23H1M9mueyhZG0mCtcC+n/HUwN/tmv6MUF41k cihQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=wgiqKr8yG5mh8KZEURLJo++9mW1jlSl2SuzTJ9XH/uQ=; b=F0p6eT0J3kY6SplbA2x2+1p5ppKH8yJxc9lByGuI4bKP/oHmcO2/ds/1oWVsOgjutc DD/kih+O1jYMkNGhnvTXpmrXWbl80toY950YLtAVMNr33/kYg0QteQ/pyFD8deYGXo5F /V6LC78PGfwoIDVSEhv0VlQ6I8PrFgR6MwMrHtt/b8qP6/3qiOpJVAiasBgknfq6V2Lo J2GpcYDLTaPif5dA/D1isfWFA7GLnRsgNmxvhDqzTGHDTotdW/fnsyvdT5hImdAh87ZJ odo7aVH7yrCLqESuwuTN/MLJOJ9JZ37n21t2bGPChzvuE/EMA4nGwQhqbfHqTfsGt+B9 /Grw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i4-20020a6561a4000000b00422c003b4c9si3282442pgv.46.2022.12.15.07.51.49; Thu, 15 Dec 2022 07:52:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229985AbiLOPiN (ORCPT + 99 others); Thu, 15 Dec 2022 10:38:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbiLOPiM (ORCPT ); Thu, 15 Dec 2022 10:38:12 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59A6223169; Thu, 15 Dec 2022 07:38:10 -0800 (PST) Received: from dggpemm500017.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NXx8s590fzqT8c; Thu, 15 Dec 2022 23:33:49 +0800 (CST) Received: from build.huawei.com (10.175.101.6) by dggpemm500017.china.huawei.com (7.185.36.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 15 Dec 2022 23:38:08 +0800 From: Wenchao Hao To: Damien Le Moal , , CC: , , Wenchao Hao Subject: [PATCH v3] ata: libata-eh: Cleanup ata_scsi_cmd_error_handler() Date: Thu, 15 Dec 2022 23:37:49 +0800 Message-ID: <20221215153749.1947570-1-haowenchao@huawei.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500017.china.huawei.com (7.185.36.178) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752295823775149706?= X-GMAIL-MSGID: =?utf-8?q?1752295823775149706?= If ap->ops->error_handler is NULL just return. This patch also fixes some comment style issue. Reviewed-by: Niklas Cassel --- v3: - Start with a "/*" empty line for multi-line comments. - Correct the commit subject v2: - Check ap->ops->error_handler without taking the spin lock Signed-off-by: Wenchao Hao --- drivers/ata/libata-eh.c | 101 +++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 34303ce67c14..56820b8e953a 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -565,13 +565,19 @@ void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, { int i; unsigned long flags; + struct scsi_cmnd *scmd, *tmp; + int nr_timedout = 0; /* make sure sff pio task is not running */ ata_sff_flush_pio_task(ap); + if (!ap->ops->error_handler) + return; + /* synchronize with host lock and sort out timeouts */ - /* For new EH, all qcs are finished in one of three ways - + /* + * For new EH, all qcs are finished in one of three ways - * normal completion, error completion, and SCSI timeout. * Both completions can race against SCSI timeout. When normal * completion wins, the qc never reaches EH. When error @@ -584,62 +590,59 @@ void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, * timed out iff its associated qc is active and not failed. */ spin_lock_irqsave(ap->lock, flags); - if (ap->ops->error_handler) { - struct scsi_cmnd *scmd, *tmp; - int nr_timedout = 0; - - /* This must occur under the ap->lock as we don't want - a polled recovery to race the real interrupt handler - - The lost_interrupt handler checks for any completed but - non-notified command and completes much like an IRQ handler. - We then fall into the error recovery code which will treat - this as if normal completion won the race */ - - if (ap->ops->lost_interrupt) - ap->ops->lost_interrupt(ap); + /* + * This must occur under the ap->lock as we don't want + * a polled recovery to race the real interrupt handler + * + * The lost_interrupt handler checks for any completed but + * non-notified command and completes much like an IRQ handler. + * + * We then fall into the error recovery code which will treat + * this as if normal completion won the race + */ + if (ap->ops->lost_interrupt) + ap->ops->lost_interrupt(ap); - list_for_each_entry_safe(scmd, tmp, eh_work_q, eh_entry) { - struct ata_queued_cmd *qc; + list_for_each_entry_safe(scmd, tmp, eh_work_q, eh_entry) { + struct ata_queued_cmd *qc; - ata_qc_for_each_raw(ap, qc, i) { - if (qc->flags & ATA_QCFLAG_ACTIVE && - qc->scsicmd == scmd) - break; - } + ata_qc_for_each_raw(ap, qc, i) { + if (qc->flags & ATA_QCFLAG_ACTIVE && + qc->scsicmd == scmd) + break; + } - if (i < ATA_MAX_QUEUE) { - /* the scmd has an associated qc */ - if (!(qc->flags & ATA_QCFLAG_FAILED)) { - /* which hasn't failed yet, timeout */ - qc->err_mask |= AC_ERR_TIMEOUT; - qc->flags |= ATA_QCFLAG_FAILED; - nr_timedout++; - } - } else { - /* Normal completion occurred after - * SCSI timeout but before this point. - * Successfully complete it. - */ - scmd->retries = scmd->allowed; - scsi_eh_finish_cmd(scmd, &ap->eh_done_q); + if (i < ATA_MAX_QUEUE) { + /* the scmd has an associated qc */ + if (!(qc->flags & ATA_QCFLAG_FAILED)) { + /* which hasn't failed yet, timeout */ + qc->err_mask |= AC_ERR_TIMEOUT; + qc->flags |= ATA_QCFLAG_FAILED; + nr_timedout++; } + } else { + /* Normal completion occurred after + * SCSI timeout but before this point. + * Successfully complete it. + */ + scmd->retries = scmd->allowed; + scsi_eh_finish_cmd(scmd, &ap->eh_done_q); } + } - /* If we have timed out qcs. They belong to EH from - * this point but the state of the controller is - * unknown. Freeze the port to make sure the IRQ - * handler doesn't diddle with those qcs. This must - * be done atomically w.r.t. setting QCFLAG_FAILED. - */ - if (nr_timedout) - __ata_port_freeze(ap); - + /* + * If we have timed out qcs. They belong to EH from + * this point but the state of the controller is + * unknown. Freeze the port to make sure the IRQ + * handler doesn't diddle with those qcs. This must + * be done atomically w.r.t. setting QCFLAG_FAILED. + */ + if (nr_timedout) + __ata_port_freeze(ap); - /* initialize eh_tries */ - ap->eh_tries = ATA_EH_MAX_TRIES; - } + /* initialize eh_tries */ + ap->eh_tries = ATA_EH_MAX_TRIES; spin_unlock_irqrestore(ap->lock, flags); }