Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp4205752rwl; Wed, 28 Dec 2022 00:27:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXvkNikQp0m9N16OSv8mxIw5ETNbOCgo6GSt3Gz0n8BYzZFJ0zI9rkTH+6+lEWh8RgKXKz+K X-Received: by 2002:a05:6300:8109:b0:a5:60d7:fb82 with SMTP id bs9-20020a056300810900b000a560d7fb82mr29620534pzc.60.1672216072182; Wed, 28 Dec 2022 00:27:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672216072; cv=none; d=google.com; s=arc-20160816; b=rlrga1UOZxlsFr6rP/OboT0KYrDxh6AUIUGXBR3wI5tIu2Gb23qCpDH4jZvsRdVFam IRtoVdjRGslKX3kVT5y2XlA+N0DjSNEIX9hIquWM7iP7MxxTqORsVM5x/NGkG5drPEWm Xb6rVXxV5f+b6nlb1AlGPFthUugr+LneqO1T/nMTYmz4hy3oHpSKvMPVIUQYt1Yo9NEP /NUhr6EORJ5Mg/6f3ucWeMPoIqCIffF5GKEd0nSRxXdagO0GTIdsVXmyQyotjdhiBjnn EGUcOgPaHNm7sj92bUZtnruNLtx7hKpXkulJu50vL5lFQBqS5aIPEQGT7GpQwP+isptK wVyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=O2die1kbivFBpyeFFls+8s5j+wpjRYyZyeUOpXlPPXs=; b=bHedh6nAvrMTO9XlX+XIhUc484onicsg5ShL9Soi0MIT7PDq/G7uuZE4bwyxNvYVGq F9jpWD2z6Udb9l2g490GNrRmIyi4BuN72zFw9S343NVUTG4xISrkVRNf+lkkR3nLGx+3 M9qaieQlOMKJ2iKxjJuhj3e9mZNhEUsKrYLlm+BBRUjZ8f6ZZhMQSB87Jb5hRTz9dUjz MFBlEQHF0L2IkdlWVbK2vCvYCfU1FzXHh41i9nSUs2ubt/9Wp0jUOgtsZ0WkDievpxHB vB33ofPJL3DQi7UQq6Mx/T0So3HMvVjuJ3CMJyfhgXGFjmdtgkMI/dNXKDPUnITPYV0k 9tPg== 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 u27-20020a63235b000000b00478c967a88bsi17465847pgm.379.2022.12.28.00.27.43; Wed, 28 Dec 2022 00:27:52 -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 S232050AbiL1IS5 (ORCPT + 64 others); Wed, 28 Dec 2022 03:18:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbiL1ISz (ORCPT ); Wed, 28 Dec 2022 03:18:55 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 866DBDF69; Wed, 28 Dec 2022 00:18:52 -0800 (PST) Received: from dggpemm500017.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NhksP1cBmzRqLq; Wed, 28 Dec 2022 16:17:29 +0800 (CST) Received: from [10.174.178.220] (10.174.178.220) 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; Wed, 28 Dec 2022 16:18:50 +0800 Message-ID: Date: Wed, 28 Dec 2022 16:18:49 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH v3] ata: libata-eh: Cleanup ata_scsi_cmd_error_handler() Content-Language: en-US To: Damien Le Moal , , CC: , References: <20221215153749.1947570-1-haowenchao@huawei.com> From: Wenchao Hao In-Reply-To: <20221215153749.1947570-1-haowenchao@huawei.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.220] X-ClientProxiedBy: dggpeml100018.china.huawei.com (7.185.36.133) To dggpemm500017.china.huawei.com (7.185.36.178) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 On 2022/12/15 23:37, Wenchao Hao wrote: > If ap->ops->error_handler is NULL just return. This patch also > fixes some comment style issue. > > --- > 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 friendly pinging... > --- > 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); > > }