Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp458644imj; Sat, 16 Feb 2019 04:17:12 -0800 (PST) X-Google-Smtp-Source: AHgI3IaWfUW1XBAX77MqtLNtO9Nivv43CTcUCaDAiDg0aJYhImrzoE4JwPOzfvz35EJLXpY78R+U X-Received: by 2002:a17:902:8303:: with SMTP id bd3mr15618614plb.10.1550319432500; Sat, 16 Feb 2019 04:17:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550319432; cv=none; d=google.com; s=arc-20160816; b=fQxlEFDrzdP2maXDAXQTWMjjNDAfXnHYBpW8aUBQVLh4p3sH+yu7N+WooN1293fKph 29ZKFdp08LwbT7x/6NvvOw1GxoIV7TYFJzwOkCcs25xYOcuKZhWdTe8doJGVJqwKSg/1 RXRCxorEdHBhlvrBFz3QGEz6Ar7tH0BKPr6dRjcTNwLTowWKaLIvaJ494uGT2LJBJnk1 Mh+Oy8QFUx30FxD9MEdJ1bExDS1YtNPn6rSqtNOjmqYWnQNq79SDkQGobTS/lQgZvDZR gREaxtjp9YDVYgG80Pw8IicFOrlpDXsWdx6ge5MK8D2DGGyKZcypVNBwq6Xl7uqVYdyU q01A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=ttBoO2frlyyz23G82VR0VvyQ5rwJE4Unbh3P0+Iv5Zw=; b=AMdzbeE2HJbSrDsfxANmE59rRuhnIsn/ibQCxHOY4vVSYVhKLoZabwYC7HEw/ISAcC 2vXSWOlfnAqvKlwBS4kp7NSyjy3RHl0Hql4ePRJ4jaU4+iGRnfaaZcSerBenofzHo74A jSDf8CJaIfpZaT3nUV/hHVolY9ZPFYl4v83AUA4EJa0zNljwglYUn1oz0P4oC3ZXoAYM taFVQQiUTArK7ExhCJOIaVGi++FtEnat0jG8Y1KPNjcfzC1HE5+WNoFw5OB12WQlK3sJ WZbPXxsggpoNfT1Sngt2IB1uLbyUH/ySdzfsiKlI2UyeYntDEgvk65n1bWKcI2Rm1Pfo VzsA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a1si4299490pgt.332.2019.02.16.04.16.56; Sat, 16 Feb 2019 04:17:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731422AbfBPIzk (ORCPT + 99 others); Sat, 16 Feb 2019 03:55:40 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:53304 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726647AbfBPIzk (ORCPT ); Sat, 16 Feb 2019 03:55:40 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 04E1A382F4554B57FFD9; Sat, 16 Feb 2019 16:55:36 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.408.0; Sat, 16 Feb 2019 16:55:27 +0800 From: Jason Yan To: , , , CC: Jason Yan Subject: [PATCH v2] ata: fix a race condition when internal cmd time out Date: Sat, 16 Feb 2019 16:53:47 +0800 Message-ID: <20190216085347.35228-1-yanaijie@huawei.com> X-Mailer: git-send-email 2.14.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For internal cmds, we will unmap DMA memory associated with the cmd before we abort the cmd. If DMA transferring data before the aborting, bus error will occur. ata_exec_internal_sg ->ata_port_freeze if timeout ->ata_qc_complete ->ata_sg_clean dma transferring data = bus error ->ap->ops->post_internal_cmd ->sas_ata_post_internal ->sas_ata_internal_abort ->abort the cmd Fix this by moving post_internal_cmd() before unmapping the DMA memory when time out. Notice that we have to set ATA_QCFLAG_FAILED flag before calling post_internal_cmd() so that the aborting will work. Reported-by: luojian Signed-off-by: Jason Yan --- v2: fix some typos drivers/ata/libata-core.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index adf28788cab5..d0ff5711e805 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -1665,6 +1665,13 @@ unsigned ata_exec_internal_sg(struct ata_device *dev, */ if (qc->flags & ATA_QCFLAG_ACTIVE) { qc->err_mask |= AC_ERR_TIMEOUT; + qc->flags |= ATA_QCFLAG_FAILED; + + spin_unlock_irqrestore(ap->lock, flags); + /* do post_internal_cmd */ + if (ap->ops->post_internal_cmd) + ap->ops->post_internal_cmd(qc); + spin_lock_irqsave(ap->lock, flags); if (ap->ops->error_handler) ata_port_freeze(ap); @@ -1679,9 +1686,10 @@ unsigned ata_exec_internal_sg(struct ata_device *dev, spin_unlock_irqrestore(ap->lock, flags); } - /* do post_internal_cmd */ - if (ap->ops->post_internal_cmd) - ap->ops->post_internal_cmd(qc); + if (!(qc->err_mask & AC_ERR_TIMEOUT)) + /* do post_internal_cmd */ + if (ap->ops->post_internal_cmd) + ap->ops->post_internal_cmd(qc); /* perform minimal error analysis */ if (qc->flags & ATA_QCFLAG_FAILED) { -- 2.14.4