Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp736372rwb; Thu, 15 Dec 2022 01:32:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf5EfGkvTWQS0J+S2dn3Vz5HIrL4byve5D8/nfyo6UaBq7gPiMZ76+7ABdPxNSYW3r+gPf1+ X-Received: by 2002:a17:90a:3808:b0:21c:3f4c:7e6 with SMTP id w8-20020a17090a380800b0021c3f4c07e6mr27254536pjb.14.1671096749881; Thu, 15 Dec 2022 01:32:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671096749; cv=none; d=google.com; s=arc-20160816; b=burDNx0JMRdrHH1A770Rb3sBicOfzjPW+cSjoaNAez2nitICyCYkK70J/S8ZXas4mH qY59653UuUaZjKczOmgTL1PR6MjDn55EwBuFn9pnRYfjc56LV+18V/1ApzKPuXu62NAf EYSdYGT4E637/hZuxtlG1ITlvLmh1P/grH9c1UDRe8SsgnZufDuYGML9zBc1PTAWu+zL KZPKzNZIy+3y+WUrpG4mSreiO49kX296YS7h2+ozMKAoYt3Sv6/6mKQSNw0+Q5veK/mg /Vinwk0L/tFTtkLCxWM5yRCagk8Zzy9AVero1UHQIxEvLt6hW4MfX3OwxEfyQf6/i7Hd OsNg== 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=gB4B32bR6R4QfBXd2gUI/zoeys45VD7bCSxY/Wdup4c=; b=E0WMDe9SmqaZW+b4P1o0CAfHQLGN06XYqCST3Li5U9qLgbamXqWm2F9JFZsFbiEmEJ uY4wEnnZQWauFowKQf0OetWztEm1DuWzOB/4IOzpj7Br3OQ94zedx6RwUrC6aNIhWapf /9eD1hFmZ3lMRjyIIDOBTG0Bnrgw/jOc7bNyCSBOGfBZgD+TUzEqdYk7mJK/i7bdk5OU wIZrV1XOtx7gKX61v8pN0mKe9pXrejZIghvjcOW2QkQ0XWhsM5OgvA0Lt6Op03Pxv1f4 H43vyOToLjzjqOWf6oBM8ejU2fS92BGEm63l4xK19NHMXd6RjvAQ5mMPVzILFc61UhSW kk2g== 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 z6-20020a630a46000000b004769f0faab8si2406561pgk.740.2022.12.15.01.32.21; Thu, 15 Dec 2022 01:32:29 -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 S229895AbiLOJUO (ORCPT + 68 others); Thu, 15 Dec 2022 04:20:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229678AbiLOJUD (ORCPT ); Thu, 15 Dec 2022 04:20:03 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1932B47329; Thu, 15 Dec 2022 01:20:01 -0800 (PST) Received: from dggpemm500017.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NXmrS49cZzJqZr; Thu, 15 Dec 2022 17:19:04 +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; Thu, 15 Dec 2022 17:19:59 +0800 Message-ID: <44f7297f-6f3a-cba9-ada1-c59188a98c9a@huawei.com> Date: Thu, 15 Dec 2022 17:19:58 +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] ata:libata-eh:Cleanup ata_scsi_cmd_error_handler Content-Language: en-US To: Niklas Cassel CC: Damien Le Moal , "linux-ide@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "liuzhiqiang26@huawei.com" , "linfeilong@huawei.com" References: <20221215050416.1891113-1-haowenchao@huawei.com> From: Wenchao Hao In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.220] X-ClientProxiedBy: dggpeml100019.china.huawei.com (7.185.36.175) 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,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 16:54, Niklas Cassel wrote: > On Thu, Dec 15, 2022 at 01:04:16PM +0800, Wenchao Hao wrote: >> If ap->ops->error_handler is NULL, just go out and release the >> spinlock. This patch is just a cleanup, which would not change >> the origin error handle logic. >> >> 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..66ca3ac7cd58 100644 >> --- a/drivers/ata/libata-eh.c >> +++ b/drivers/ata/libata-eh.c >> @@ -565,6 +565,8 @@ 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); >> @@ -584,62 +586,60 @@ 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->error_handler) >> + goto out; > > Nice cleanup! > > However, I don't think there is any point in taking the spin lock if there is > no error_handler. > > So I think that you can do similar to the skip_eh label in ata_port_detach(): > https://github.com/torvalds/linux/blob/master/drivers/ata/libata-core.c#L5904 > > > Kind regards, > Niklas > I did not want to change the origin logic. But it looks unnecessary to take the spin lock, would update. >> >> - 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; >> +out: >> spin_unlock_irqrestore(ap->lock, flags); >> >> } >> -- >> 2.32.0 >> .