Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5641170img; Wed, 27 Mar 2019 12:15:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6NJH/7sBKTtbyBMYZ+2SaGMbgdQjUYZ/uSFUFgyF51FSBuQMRX/fIkfMTD75dJJWz2lhG X-Received: by 2002:a17:902:e091:: with SMTP id cb17mr15329946plb.222.1553714143904; Wed, 27 Mar 2019 12:15:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714143; cv=none; d=google.com; s=arc-20160816; b=ED44/A9emvlE8T31KJYEiQT0xrD5Ud3fsgk6XK6M4jj9wtsRkXW+UZ/rez1SytZhnO jqGJ9/G4QTCHtKWkQXbc7wqGO43lA6VIEfMJbcdUPYtTg2etGzPe7Y/dKMudc9TEJGPl 0f+MZ2Qcf6IVhFesuPY9aGwGoc46Ar3XBoPJ0xgqTZ68IsuohJX6hmBF92c+z/PR4P6I px55OyXjwOs+VUlZ0OnMYMdNa4o4Tn9MYqaHSsq9B6gkqbuWO2UDUH3zr3sUCeopxJEu ZBCEoY5p4MwqBxirZjNfdKjbYvQXMaZWIVrbtfuw0oZiC2eiPxvEuovW1A2XagB4+VYr S5bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xKjjlqFxMUQrKlR4Y4osnypA39p/3ryojYV9xOyg3lo=; b=eQdLsBZmVegSPPcS6NtbcrGhNWZTHUMCM7JXfloU27IyeaM5Yk2Ds6UC4hpEDMs8IZ gSsHEPr0EiZasI5ch46GohbD8C3cjeqAzutfpvIaetHtAntp0KOcf0j+jq3h2I55h+Af LcTTALNnDN+s8vKJhQC3ygb/cfn80VLAGsLhdYgxHYgZSZoQ+URBHXdhIaQnrUApU3Ae OOG0ijCkl69YpOCMTFdRULcByOntENZ9tSztgJspvQBKqTxmwrJiDRoD0CDIwIjAwWNC tkFSKm2v9b3s621Z5pIv+KzojKmBnPXB9ESwPPihAy52qokZrtuIltZYmbNZ3ZXIuuV/ Qr/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fTr8sK2n; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f124si6769672pgc.596.2019.03.27.12.15.28; Wed, 27 Mar 2019 12:15:43 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=fTr8sK2n; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388595AbfC0SJd (ORCPT + 99 others); Wed, 27 Mar 2019 14:09:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:51308 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388574AbfC0SJ3 (ORCPT ); Wed, 27 Mar 2019 14:09:29 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 533392177E; Wed, 27 Mar 2019 18:09:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710168; bh=TU11IEFQmzAcat+wyr6E/gYvnDZhZQZoN/16brW+tII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fTr8sK2nOlX1jbgfTuR4FRfbFErlU8dOSzH+nUwDNTtl012rfV9LU0xAo87fPb1ca LImfz9beXEE9FivUhKP8eoYli82tMIRR3KYjc6Xr84XU1ddjvHo1qx+ku9KpIBMqKO 7o97x/B1iz5Wx2+BJxgEyuqOcyd5/JNelENDmiuI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Shunyong Yang , Joey Zheng , Vinod Koul , Sasha Levin , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, dmaengine@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 231/262] dmaengine: qcom_hidma: assign channel cookie correctly Date: Wed, 27 Mar 2019 14:01:26 -0400 Message-Id: <20190327180158.10245-231-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shunyong Yang [ Upstream commit 546c0547555efca8ba8c120716c325435e29df1b ] When dma_cookie_complete() is called in hidma_process_completed(), dma_cookie_status() will return DMA_COMPLETE in hidma_tx_status(). Then, hidma_txn_is_success() will be called to use channel cookie mchan->last_success to do additional DMA status check. Current code assigns mchan->last_success after dma_cookie_complete(). This causes a race condition of dma_cookie_status() returns DMA_COMPLETE before mchan->last_success is assigned correctly. The race will cause hidma_tx_status() return DMA_ERROR but the transaction is actually a success. Moreover, in async_tx case, it will cause a timeout panic in async_tx_quiesce(). Kernel panic - not syncing: async_tx_quiesce: DMA error waiting for transaction ... Call trace: [] dump_backtrace+0x0/0x1f4 [] show_stack+0x24/0x2c [] dump_stack+0x84/0xa8 [] panic+0x12c/0x29c [] async_tx_quiesce+0xa4/0xc8 [async_tx] [] async_trigger_callback+0x70/0x1c0 [async_tx] [] raid_run_ops+0x86c/0x1540 [raid456] [] handle_stripe+0x5e8/0x1c7c [raid456] [] handle_active_stripes.isra.45+0x2d4/0x550 [raid456] [] raid5d+0x38c/0x5d0 [raid456] [] md_thread+0x108/0x168 [] kthread+0x10c/0x138 [] ret_from_fork+0x10/0x18 Cc: Joey Zheng Reviewed-by: Sinan Kaya Signed-off-by: Shunyong Yang Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/qcom/hidma.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/dma/qcom/hidma.c b/drivers/dma/qcom/hidma.c index 43d4b00b8138..ea219bca116d 100644 --- a/drivers/dma/qcom/hidma.c +++ b/drivers/dma/qcom/hidma.c @@ -138,24 +138,25 @@ static void hidma_process_completed(struct hidma_chan *mchan) desc = &mdesc->desc; last_cookie = desc->cookie; + llstat = hidma_ll_status(mdma->lldev, mdesc->tre_ch); + spin_lock_irqsave(&mchan->lock, irqflags); + if (llstat == DMA_COMPLETE) { + mchan->last_success = last_cookie; + result.result = DMA_TRANS_NOERROR; + } else { + result.result = DMA_TRANS_ABORTED; + } + dma_cookie_complete(desc); spin_unlock_irqrestore(&mchan->lock, irqflags); - llstat = hidma_ll_status(mdma->lldev, mdesc->tre_ch); dmaengine_desc_get_callback(desc, &cb); dma_run_dependencies(desc); spin_lock_irqsave(&mchan->lock, irqflags); list_move(&mdesc->node, &mchan->free); - - if (llstat == DMA_COMPLETE) { - mchan->last_success = last_cookie; - result.result = DMA_TRANS_NOERROR; - } else - result.result = DMA_TRANS_ABORTED; - spin_unlock_irqrestore(&mchan->lock, irqflags); dmaengine_desc_callback_invoke(&cb, &result); -- 2.19.1