Received: by 10.223.185.116 with SMTP id b49csp7159921wrg; Thu, 1 Mar 2018 00:26:49 -0800 (PST) X-Google-Smtp-Source: AG47ELuxq2kaJmu+2cE2XXBHyqPGMb88votVJllOUG/p8cqY4QirsY2eE5/Uq/X0OMkDj9ERx8/P X-Received: by 10.101.72.198 with SMTP id o6mr875548pgs.279.1519892809230; Thu, 01 Mar 2018 00:26:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519892809; cv=none; d=google.com; s=arc-20160816; b=tlLN5vldRLVqMobNFWSn8ZU/PMmnM/oT8BPbeuZ6zUco1IIWIQTI6jdd2+k1jHsquL Tdju2GBZRHxlSGiCIvzKa+NPszF23tMeX6d4/AqCg0w3lYz/KXCCSahy5FTrzJ8hUTYG TBbbvyFRd8bH4olxhepXEdLeVXYyr+eNJ62zggzR8EsgS+Ynd86w8isL0WyJ0mMwsemD p+seNBHr80J1WKnkrHdv7iY68HEDUBZX/cDigEr7F5egnbJ38yEnXfPcyq2l2wRC/AHp 5ivg0vV5VDSl3rMycabaHpPVRBurrRv8ZRwv9BweuKBShwdOt/X7W1J4lgsphlt4tD3M Kflg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=gvIv5IVz0KnuXlFV9RIhli0WjnhwsbxCA+gHre0M/aY=; b=TSbiZjRCpFLJXZaeh+a5EqrKvPJ7Q41+Axv5WYX1EAwyhKDzneWvLFb3Qv3UNG1Kw+ 9bC/EYgA/K2fY/gQyzGdHx+5EJ94yfnqCh6ayvrsdkuKyZ8BzeBo7+qHB9br2LMyR0Oy 0q0wGLUX6/j3Ojw2NJWPGDZUxPjFe0umfKedlPhuts3lGtBML4++itDWgM/8RbfFxjJQ vXm0ml8Et72Zi4wOQwbGK7tGQ6nhDQKcQTdTJ/6PyTydY8f+nYgmyrYc6jx+3X+iVoMu c2oSUm0tVfTvwozegmODxpmQ+zjZfmnGuiMgC40IyYSm6tF6El6PC2iJeZWUukUUpp+P Ra9Q== 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 y12-v6si2735644plk.705.2018.03.01.00.26.34; Thu, 01 Mar 2018 00:26:49 -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 S965294AbeCAIZq (ORCPT + 99 others); Thu, 1 Mar 2018 03:25:46 -0500 Received: from esa2.microchip.iphmx.com ([68.232.149.84]:63078 "EHLO esa2.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965138AbeCAIZo (ORCPT ); Thu, 1 Mar 2018 03:25:44 -0500 X-IronPort-AV: E=Sophos;i="5.47,407,1515481200"; d="scan'208";a="11878920" Received: from exsmtp02.microchip.com (HELO email.microchip.com) ([198.175.253.38]) by esa2.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 01 Mar 2018 01:25:43 -0700 Received: from localhost (10.10.76.4) by chn-sv-exch02.mchp-main.com (10.10.76.38) with Microsoft SMTP Server id 14.3.352.0; Thu, 1 Mar 2018 01:25:42 -0700 Date: Thu, 1 Mar 2018 09:25:16 +0100 From: Ludovic Desroches To: Maxime Jayat CC: Ludovic Desroches , Vinod Koul , Nicolas Ferre , Dan Williams , , , Subject: Re: [PATCH] dmaengine: at_xdmac: fix rare residue corruption Message-ID: <20180301082516.GL22457@rfolt0960.corp.atmel.com> References: <20180222113955.4043-1-maxime.jayat@mobile-devices.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20180222113955.4043-1-maxime.jayat@mobile-devices.fr> User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Maxime, On Thu, Feb 22, 2018 at 12:39:55PM +0100, Maxime Jayat wrote: > Despite the efforts made to correctly read the NDA and CUBC registers, > the order in which the registers are read could sometimes lead to an > inconsistent state. > > Re-using the timeline from the comments, this following timing of > registers reads could lead to reading NDA with value "@desc2" and > CUBC with value "MAX desc1": > > INITD -------- ------------ > |____________________| > _______________________ _______________ > NDA @desc2 \/ @desc3 > _______________________/\_______________ > __________ ___________ _______________ > CUBC 0 \/ MAX desc1 \/ MAX desc2 > __________/\___________/\_______________ > | | | | > Events:(1)(2) (3)(4) > > (1) check_nda = @desc2 > (2) initd = 1 > (3) cur_ubc = MAX desc1 > (4) cur_nda = @desc2 > > This is allowed by the condition ((check_nda == cur_nda) && initd), > despite cur_ubc and cur_nda being in the precise state we don't want. > > This error leads to incorrect residue computation. > > Fix it by inversing the order in which CUBC and INITD are read. This > makes sure that NDA and CUBC are always read together either _before_ > INITD goes to 0 or _after_ it is back at 1. > The case where NDA is read before INITD is at 0 and CUBC is read after > INITD is back at 1 will be rejected by check_nda and cur_nda being > different. > > Fixes: 53398f488821 ("dmaengine: at_xdmac: fix residue corruption") > Cc: stable@vger.kernel.org > Signed-off-by: Maxime Jayat Nice work! I agree with the change you propose. I am disappointed we didn't spot this case so I would like to double-check with the hardware guy there is no issue with the sequence you propose. That's why I am waiting a bit before giving my ack. Regards Ludovic > --- > Hi, > > I had a bug where the serial ports on the Atmel SAMA5D2 were sometimes > returning the same data twice, for up to 4096 bytes. > > After investigation, I noticed that the ring buffer used in > atmel_serial (in rx dma mode) had sometimes a incorrect "head" value, > which made the ring buffer do a complete extraneous loop of data > pushed to the tty layer. > > I tracked it down to the residue of the dma being wrong, and after > more head scratching, I found this bug in the reading of the > registers. > > Before fixing this, I was able to reproduce the bug reliably in a few > minutes. With this patch applied, the bug did not reappear after > several hours in testing. > > > drivers/dma/at_xdmac.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/dma/at_xdmac.c b/drivers/dma/at_xdmac.c > index c00e3923d7d8..94236ec9d410 100644 > --- a/drivers/dma/at_xdmac.c > +++ b/drivers/dma/at_xdmac.c > @@ -1471,10 +1471,10 @@ at_xdmac_tx_status(struct dma_chan *chan, dma_cookie_t cookie, > for (retry = 0; retry < AT_XDMAC_RESIDUE_MAX_RETRIES; retry++) { > check_nda = at_xdmac_chan_read(atchan, AT_XDMAC_CNDA) & 0xfffffffc; > rmb(); > - initd = !!(at_xdmac_chan_read(atchan, AT_XDMAC_CC) & AT_XDMAC_CC_INITD); > - rmb(); > cur_ubc = at_xdmac_chan_read(atchan, AT_XDMAC_CUBC); > rmb(); > + initd = !!(at_xdmac_chan_read(atchan, AT_XDMAC_CC) & AT_XDMAC_CC_INITD); > + rmb(); > cur_nda = at_xdmac_chan_read(atchan, AT_XDMAC_CNDA) & 0xfffffffc; > rmb(); > > -- > 2.14.1 >