Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp391283imj; Sat, 16 Feb 2019 02:44:14 -0800 (PST) X-Google-Smtp-Source: AHgI3IYq7C3xl38XxEXdB4hVaQa9qJ4FX/wlZ1CGRIxICUvkN3qmAh2ITNwMvKWRGbk5hK0bLX55 X-Received: by 2002:a17:902:2468:: with SMTP id m37mr14936675plg.314.1550313854803; Sat, 16 Feb 2019 02:44:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550313854; cv=none; d=google.com; s=arc-20160816; b=D/2ktOk88jcJ8ISzj/HMjtDXopEVUjA7icofXwT/Er3t+fXGWasR3Dam9FXMaYTcR7 8I5jNCfXmqJcZ/7j9e7PuR9VqQUtzhIqg7Mkdk9uLQJjPcDNW1TCA5M5Vc6IFWFEF0H6 0oNAp3zSM3/7jII59+ftzKXnS/JLJT/jR8RXg36ACv8xzBYnElsYxNkQabmzNBmzCL9H hMsQ+A1WjqcD7w/yvnAOTiQv6Go1NWQRDsZi/rb77KAMp+3/ASHH692hVD1X6i/VbqM5 BxTX00ueU2y+xcsWnIqlVEyFBx4hKLsFsk+ruMCf4EmsnQzLB+BkVXQRC4U20kS/u53n EYSw== 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=T6bU0rX+1dpYNY9xMfCD5SMLLfRebY6yBZx7mrOsNuU=; b=0Ple8BrgFnR2yXrOFPr39Y/PQphVRqxfy1TRHCLccl6zoy5x2vASL8jKVauSUXKMyv +zXZREUGrzLAU9axcKo4056weEUZDnvk6Al4BJMI40JZYI7h3P54vnqWa/ZftOn+De/s +Hpv5gARez6Vt1zJvde3B00P2GrBsL7SuOSJq6q/v1YOZka99aCbtylAjRWTQgURkwiY 12hfU8mPfEfGRaQNkg5uhkOyAICSrVvD5tVvWuyvFWxg4Pour8ffdSjaOB1n7TygOhlk +9ADocP0C1w/9KTTFTArrHykI8R9qIy+ay29JMh/c0+o0g+XbPFd8YEiqmX+4uVYKmgT qZUw== 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 ci9si8729641plb.252.2019.02.16.02.43.58; Sat, 16 Feb 2019 02:44:14 -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 S2387406AbfBPDo6 (ORCPT + 99 others); Fri, 15 Feb 2019 22:44:58 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:3218 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726102AbfBPDo6 (ORCPT ); Fri, 15 Feb 2019 22:44:58 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id BF3734A42167FF7ECD55; Sat, 16 Feb 2019 11:44:54 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.408.0; Sat, 16 Feb 2019 11:44:46 +0800 From: Jason Yan To: , , , CC: Jason Yan Subject: [PATCH] ata: fix a race condition when internal cmd time out Date: Sat, 16 Feb 2019 11:42:57 +0800 Message-ID: <20190216034257.30226-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 transfering data before the aborting, bus error will occured. ata_exec_internal_sg ->ata_port_freeze if timeout ->ata_qc_complete ->ata_sg_clean dma transfering data = bus error ->ap->ops->post_internal_cmd ->sas_ata_post_internal ->sas_ata_internal_abort ->abort the cmd Fix this by move 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 --- 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