Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5612631img; Wed, 27 Mar 2019 11:42:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqy0jNSngPHp0B/GCkL7TARt5nlsxzgUt7B+ONY9NnLgblQtvp0PXL7k8aO0ICNp5M9RAAQO X-Received: by 2002:a17:902:2ec1:: with SMTP id r59mr38019140plb.171.1553712143825; Wed, 27 Mar 2019 11:42:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553712143; cv=none; d=google.com; s=arc-20160816; b=y+KpMChVG6YMrwL0oth4X5TGAW5NcbcYAIRscYfbxX4d9V/Op3zjONkM41X78NDOeK BW8neYk3UZ9US9M2iHOkNbl3GHET1329l2EnJsXmIfpacwdtxaSitdJBCRo/J0vepguI zm5xwH2FXlROyPPVPfXRTSxdVwMdz9jBI1SRTSm0qMoBGxZJ2EqD9NAIoCD6OAVL8kYL A2aFISowoFkvvhkzOlR0sawfGKwYARIB+ZJLEv0+MvTzad/NtFCBOaPdp4MItw3wzc3/ nFmqkUVZ1XBrQXYSV/D1sYaHO/+CtgzW4zEldSGY9JP7jJflzfVRuPIVj5FjmpCVz46D qo4w== 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=RCpVNXaEfxn2Sz+BQv6WhPgvMcU0dkBZ0C+TBL8pO2M=; b=YEp/N39FzGqPW9uSHgSPpdC0EtUnuEAw6gPyNYJECK+t/ImlYqJXiK7q2B8+8uLKR5 ihjvcnTvHjsFYDLHaP2IzutlVAQAEztuHAV5Clxjo9JhIBR7WXOLeWlWSzNYfYyTJ15T VibAUJGiO4MFjP2Vf0AZ/Ae/EcUGgzTjX52JdSX3pcxNVRFibRlaDEbdLm4XjTZvAs3M Z1TdIO1Z+CDAJpwN49W7GF2lG4ynoTlt3ecNc1OlMxLjTHq4xEI4xjbjNHW8sAY30sxz 41DpLADV1SDiHm74gFQOBimXxC0lpRDqCEm68xjv7lX/LUduIiKrspxi/aF2/Fk9rAq/ rmig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=inUFkwuz; 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 g123si2395588pfb.24.2019.03.27.11.42.07; Wed, 27 Mar 2019 11:42:23 -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=inUFkwuz; 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 S2391406AbfC0SXE (ORCPT + 99 others); Wed, 27 Mar 2019 14:23:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:41270 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391394AbfC0SXD (ORCPT ); Wed, 27 Mar 2019 14:23:03 -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 01D2D20651; Wed, 27 Mar 2019 18:23:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710982; bh=pF7cRpKupTgJir7JwcqQ1gcxxdEG2FsTFsJXmzOPQh8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=inUFkwuzkpT1TGndjm8mEBtwqac8PYed0YgbNFOPjperuAw+WqoT7R0dMsXMJeMQk Zc6cn6HbSU9PMOuUmXevBWTpk7xhquctxow8iFJE2Q3T5dHQ8yqUUtBWRaUA8l0ahr +0YKaWfwaKQvoYywnsDjv9k63pSuqRN+W+BIMxhU= 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 4.9 76/87] dmaengine: qcom_hidma: assign channel cookie correctly Date: Wed, 27 Mar 2019 14:20:29 -0400 Message-Id: <20190327182040.17444-76-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327182040.17444-1-sashal@kernel.org> References: <20190327182040.17444-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 e244e10a94b5..5444f39bf939 100644 --- a/drivers/dma/qcom/hidma.c +++ b/drivers/dma/qcom/hidma.c @@ -131,24 +131,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