Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp5214376rwj; Tue, 20 Dec 2022 22:47:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXvI2JwHUbCrfCHcuFIG6bttTMz9bkxqVMSedCzZ8ApnfuFy/A31hXGWbyWqD9gfJWQtDzLx X-Received: by 2002:a17:906:284d:b0:7ad:b865:d3b7 with SMTP id s13-20020a170906284d00b007adb865d3b7mr344084ejc.21.1671605238685; Tue, 20 Dec 2022 22:47:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671605238; cv=none; d=google.com; s=arc-20160816; b=iK4hICH+u4ZXtzGvquhIMQjj3w6dqHgRp+6hyjXkJ2H4A4aawlpT+BK9YTcPCX4Nou I+GbarwKfg3QFZy7UivsmL74cj1ZEVDxzAIJqiRKta+LJ7Hrx21u3t6KDyycJXP1Vw4c 2HJIxsuW7X2WXekhQbPNTyTNYLQDvvBIQ0x1Siot5fBtBfNf1pliqebAWqJ58kKQrFKd PHWbS3RNBN2QJS/Zm4aBaT9N7gQeP7m4OGWfMQYj+WpsnRe9qH3St8FuYLBuMOyuybVO 3/RMmhvPaz8sYnKU/5Q8pe9Ur+TlbB7GfmOUmd5/GXgmCCGOHMQh9rQyHvVQOTnpUPQ1 gYVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=/VKuhuLngldk3doLGgbqR1ew1ssfRkr+vYwbEhSH8p4=; b=VCY1qhH/v4Oilkg7BweWc0Wa07ww0JgGq8ZufU3y+Q2HozsuP4uem870G1lbnhkcH+ mS7mINnZd+YFKoRYLGI25LMPTnh24wmz55HomisucnaQb9nrxb+ld/pIGyzdUlTTJAVx SSWBiYa7sc77PpfwK+J8GYHHFmE8EfDCjgTDdRlkD0psW56g/d9HB/G9FkDhyaOLDQCV wxWwX8KP3g3kWmIzjzZxSO2JTac5aWqB5+6KjflSKlQ13UgoGT+HnjwSkYd2Cf6s4Ib3 SPHre6TN8gOlRk3kn5lwpwNgYswRhbooTE8I2Oee7+pmJdYsoKmumrF8AMImY1LVMcgD tKug== 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 sa25-20020a1709076d1900b007f46a3735c4si11633611ejc.555.2022.12.20.22.47.02; Tue, 20 Dec 2022 22:47:18 -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 S233733AbiLUGfW (ORCPT + 69 others); Wed, 21 Dec 2022 01:35:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233763AbiLUGfQ (ORCPT ); Wed, 21 Dec 2022 01:35:16 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DADD1DF30; Tue, 20 Dec 2022 22:35:11 -0800 (PST) Received: from canpemm500004.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NcNvP30bFzJqVh; Wed, 21 Dec 2022 14:34:09 +0800 (CST) Received: from [10.174.179.14] (10.174.179.14) by canpemm500004.china.huawei.com (7.192.104.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 21 Dec 2022 14:35:09 +0800 Subject: Re: [PATCH] scsi: libsas: Grab the host lock in sas_ata_device_link_abort() To: Damien Le Moal , John Garry , Xingui Yang , , , CC: , , , , References: <20221220125349.45091-1-yangxingui@huawei.com> <4ec9dbed-1758-d6b4-dc1d-ac42e8c22731@oracle.com> <7347d117-6e0b-dd18-90a8-25685f757689@huawei.com> <4ff0ca00-31f5-2867-ff59-cecb5d6d1048@opensource.wdc.com> From: Jason Yan Message-ID: <755d7a9c-427e-024a-8509-449ebc5a00e6@huawei.com> Date: Wed, 21 Dec 2022 14:35:08 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <4ff0ca00-31f5-2867-ff59-cecb5d6d1048@opensource.wdc.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.14] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500004.china.huawei.com (7.192.104.92) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-5.4 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/21 11:59, Damien Le Moal wrote: > On 2022/12/21 11:42, Jason Yan wrote: >> On 2022/12/21 8:36, Damien Le Moal wrote: >>> On 2022/12/20 23:59, John Garry wrote: >>>> On 20/12/2022 12:53, Xingui Yang wrote: >>>>> Grab the host lock in sas_ata_device_link_abort() before calling >>>> >>>> This is should be the ata port lock, right? I know that the ata comments >>>> say differently. >>>> >>>>> ata_link_abort(), as the comment in ata_link_abort() mentions. >>>>> >>>> >>>> Can you please add a fixes tag? >>>> >>>>> Signed-off-by: Xingui Yang >>>> >>>> Reviewed-by: John Garry >>>> >>>>> --- >>>>> drivers/scsi/libsas/sas_ata.c | 3 +++ >>>>> 1 file changed, 3 insertions(+) >>>>> >>>>> diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c >>>>> index f7439bf9cdc6..4f2017b21e6d 100644 >>>>> --- a/drivers/scsi/libsas/sas_ata.c >>>>> +++ b/drivers/scsi/libsas/sas_ata.c >>>>> @@ -889,7 +889,9 @@ void sas_ata_device_link_abort(struct domain_device *device, bool force_reset) >>>>> { >>>>> struct ata_port *ap = device->sata_dev.ap; >>>>> struct ata_link *link = &ap->link; >>>>> + unsigned long flags; >>>>> >>>>> + spin_lock_irqsave(ap->lock, flags); >>>>> device->sata_dev.fis[2] = ATA_ERR | ATA_DRDY; /* tf status */ >>>>> device->sata_dev.fis[3] = ATA_ABORTED; /* tf error */ >>>>> >>>>> @@ -897,6 +899,7 @@ void sas_ata_device_link_abort(struct domain_device *device, bool force_reset) >>>>> if (force_reset) >>>>> link->eh_info.action |= ATA_EH_RESET; >>>>> ata_link_abort(link); >>> >>> Really need to add lockdep annotations in libata to avoid/catch such bugs... >>> Will work on that. >> >> Actually in libata there are many places calling ata_link_abort() not >> holding port lock. And some places are holding the real host >> lock(ata_host->lock) while calling ata_link_abort(). So if you add the >> lockdep annotations, there may be too many warnings. If these are real >> issues, we should fix them first. > > libata-EH does most of its work without the port lock held because by the time > we get EH started, we are guaranteed to be idle with no commands in flight. That > is why the calls you mention look like "bugs" but are not. What about the interrupt handler such as ahci_error_intr()? I didn't see the callers hold the port lock too. Do they need the port lock?