From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752118AbaBQIiC (ORCPT ); Mon, 17 Feb 2014 03:38:02 -0500 Received: from mga01.intel.com ([192.55.52.88]:9293 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750930AbaBQIiA (ORCPT ); Mon, 17 Feb 2014 03:38:00 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.95,859,1384329600"; d="scan'208";a="482798569" Date: Mon, 17 Feb 2014 14:05:33 +0530 From: Vinod Koul To: Siva Yerramreddy Cc: Dan Williams , dmaengine@vger.kernel.org, Sudeep Dutt , Nikhil Rao , Ashutosh Dixit , linux-kernel@vger.kernel.org, Russell King Subject: Re: [PATCH dmaengine-fixes 1/1] dmaengine: read completed cookie before used cookie Message-ID: <20140217083533.GW10628@intel.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 14, 2014 at 03:32:57PM -0800, Siva Yerramreddy wrote: > 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; The idea is right to grab the channle cookie after completed. But I dont see why you need another barrier in between these two? Dan, This really is intresting case where the request completed raced with status. I am sure for us slow slave users we may not see such issues :D but for these and other memcpy cases do we really need to bother checking the status properly and getting right data or delayed reporting is fine? -- ~Vinod