Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp882189rwb; Thu, 15 Dec 2022 03:53:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXt+qnIqHSZuCpv9KZbW3bjfKyoCsVblaoz+eHpkthE59SGEIN5qQg3xVVrr7yUt2+Y7kDbr X-Received: by 2002:aa7:d38b:0:b0:473:280e:1959 with SMTP id x11-20020aa7d38b000000b00473280e1959mr2761879edq.16.1671105213178; Thu, 15 Dec 2022 03:53:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671105213; cv=none; d=google.com; s=arc-20160816; b=X9GadkDX9Y/z9fXLliy46n+MFOyIIJ7kp893azH9cQ8XyoEMyloP+3NE+odWdHNCTR f4jPdsUq652akbMZAr0EZeoDwXMetK3X0qdwqStQ3gvj/lELek7ZRNLkBMNbph9pGIc4 5MldIehPR4cEEn1crSdm2INKYEhYrbmbHTAkC8smCe6uI2bIaHSzYRtkCrBoBFgnV1hU IEDF1+EcMZsqpDMWsvVJhKPRjMU7qI7eO8GQhxAvX/UsxVqn8YfoqgcyraDg5QS9G1pE V4rUYEfaM/ykzm910V5gxLJKoJhZolKhfH8LOXySRGvIveOXDKxjiJC0HUDQYts7Sccs f0BQ== 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=/1ZuTv4Rosr43Enr5oXX5hJDEditRc3so1WAYqXWdw4=; b=iSRfbRlP8pK3l3Vh76xTyUgdTJx7lyIzkw96enmoiPjW8uxywu8PjYxyBEKUzVvIt2 OVM0r8qUoZ+vErbEsXi4d4KVlgtPf13G9ODMjf8tuwu0IU3V9hf0H62wbNVQeJRyubHV 1nqlXWYu/RN7KabuiR7tXSWn7lgaeeqbsPa5QNIoLp7RwrXQMwo8QG/k3aHbMJu3A5w2 viEPptKYHWv7dm7Z990OZQFN6U9b1NhIxmD4+cBMN1nHXqJRVMLniM422YmB9m+ZYoAD kgawQ2ki0DAAaw4g8mfdVQuCu4BRmSwvTtmpAe6Ca2Hj84NKlJSb+eG5NcODQ67PMo66 TOCQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a0564021e8a00b004639a46d725si17214401edf.31.2022.12.15.03.53.16; Thu, 15 Dec 2022 03:53:33 -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 S229595AbiLOK6y (ORCPT + 68 others); Thu, 15 Dec 2022 05:58:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230271AbiLOK6X (ORCPT ); Thu, 15 Dec 2022 05:58:23 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B66C02CE30; Thu, 15 Dec 2022 02:58:11 -0800 (PST) Received: from dggpemm500017.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NXq1d5Wp2zmWZb; Thu, 15 Dec 2022 18:57:09 +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 18:58:09 +0800 From: Wenchao Hao To: Damien Le Moal , , CC: , , Wenchao Hao Subject: [PATCH v2] ata:libata-eh:Cleanup ata_scsi_cmd_error_handler Date: Thu, 15 Dec 2022 18:57:47 +0800 Message-ID: <20221215105747.1927412-1-haowenchao@huawei.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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 If ap->ops->error_handler is NULL, just return. V2: - Check ap->ops->error_handler without taking the spin lock Signed-off-by: Wenchao Hao --- drivers/ata/libata-eh.c | 96 ++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 34303ce67c14..c445c272e77f 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -565,10 +565,15 @@ 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 - @@ -584,62 +589,57 @@ 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); } -- 2.32.0