From patchwork Fri Feb 14 23:32:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siva Yerramreddy X-Patchwork-Id: 3655091 X-Patchwork-Delegate: dan.j.williams@gmail.com Return-Path: X-Original-To: patchwork-dmaengine@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8ACDEBF13A for ; Fri, 14 Feb 2014 23:32:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AE707201C7 for ; Fri, 14 Feb 2014 23:32:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E926201BF for ; Fri, 14 Feb 2014 23:32:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751692AbaBNXcx (ORCPT ); Fri, 14 Feb 2014 18:32:53 -0500 Received: from mga09.intel.com ([134.134.136.24]:17695 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752798AbaBNXcw (ORCPT ); Fri, 14 Feb 2014 18:32:52 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 14 Feb 2014 15:28:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.95,848,1384329600"; d="scan'208";a="483734891" Received: from syerramr456.amr.corp.intel.com (HELO localhost.localdomain) ([10.10.34.114]) by orsmga002.jf.intel.com with ESMTP; 14 Feb 2014 15:32:51 -0800 From: Siva Yerramreddy To: Dan Williams , Vinod Koul Cc: dmaengine@vger.kernel.org, Sudeep Dutt , Nikhil Rao , Ashutosh Dixit , linux-kernel@vger.kernel.org, Russell King , Siva Yerramreddy Subject: [PATCH dmaengine-fixes 1/1] dmaengine: read completed cookie before used cookie Date: Fri, 14 Feb 2014 15:32:57 -0800 Message-Id: X-Mailer: git-send-email 1.8.2.2 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When running dmatest with my yet-to-be submitted driver for the Intel MIC DMA engine, dmatest detected "dma0chan3-copy5: result #8096161:completion busy status with src_off=0x0 dst_off=0x0 len=0x40 (0)". This is caused by reading the used cookie before the completed cookie in dma_cookie_status(), if a DMA request is submitted in between the two reads, and completes, the completed cookie will be newer than the used cookie value read previously. Reversing the order of reads ensures that the completed cookie is for a DMA request older than the used cookie. Reviewed-by: Ashutosh Dixit Reviewed-by: Sudeep Dutt Reviewed-by: Nikhil Rao Signed-off-by: Siva Yerramreddy --- drivers/dma/dmaengine.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/dma/dmaengine.h b/drivers/dma/dmaengine.h index 17f983a..4c96892 100644 --- a/drivers/dma/dmaengine.h +++ b/drivers/dma/dmaengine.h @@ -7,6 +7,7 @@ #include #include +#include /** * dma_cookie_init - initialize the cookies for a DMA channel @@ -69,8 +70,13 @@ static inline enum dma_status dma_cookie_status(struct dma_chan *chan, { dma_cookie_t used, complete; - used = chan->cookie; complete = chan->completed_cookie; + /* + * If this order is not maintained, used can end up being older than + * complete + */ + smp_rmb(); + used = chan->cookie; barrier(); if (state) { state->last = complete;