Received: by 10.213.65.68 with SMTP id h4csp1343847imn; Mon, 19 Mar 2018 01:12:44 -0700 (PDT) X-Google-Smtp-Source: AG47ELtWbgSlpRv+XG3+djEvgUzSS4JuThyaHGsn2Qy7mjME8XlHfbrosZCA4ERBV8SFZ1e9Tt0T X-Received: by 2002:a17:902:6085:: with SMTP id s5-v6mr8393203plj.307.1521447164193; Mon, 19 Mar 2018 01:12:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521447164; cv=none; d=google.com; s=arc-20160816; b=DUxKWk7z7Zs9An0wqgoTdnfBPKLbVZJkjYn+2kExqbowaSkl8r9tAp/O07qAzyfdqk Lfq3yz2NzcRRFEZj9iXcmT8hAbBH6I/CeSIPCvUbxEtxyL8uz06chBxVlwX9dGMBb2HJ qj4ZheKZLgQ0YVcOQ9y4qbueIE2JmPtFJbW+T+TMKNRFCWo3F/bjB8IUSWJ8q3UXjdoi 08Buic89XCvOYssj4WnzeL6Y/EPvkWPwG9vdMISs95cLf3hSRGLQZo+S9fYPKxGUVCh0 rdhTzJ8jCP0+yxdiooawAlSLxV52OgcbX9u1Uo0GNEq+56vGIV/j2aE/pr/j9ffj/o4O 3q+g== 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=sQPjGERTuNVnLs4WZVMiuMhjXeqCGB7liOhADzdsbTA=; b=rXeYcr5KRaH9FtkqD4Yznt281mtKOd3IhqMj26aFy0EtAQEcFlTCmt32MGqupCJG3/ XNWQPJZBEp8ulwmt0Tl04bdHYTnZxlDihweNXz0tzVc73cgnszZ2Bpr0g/6soPAG9oRF ooprnrD9ZRW+KF2qW0a/xkwfEGMHXmbcUIKGvjjf1RZqztxK4f00os9xqySyOOp5lvlb pQt+3hxb5yHkgSqhC4cKdf04RGm2QYW0ZwpreYVvRryK0LUZT2EFu00GR0dmpaD4bzrh qaSMHGKGmdnUF2JQ6htbG7xc3MfmZvd2ui1S4fVhSDXNCVrBBSHPLzcp/v8s8mdsjTAh hWBg== 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-v6si9670642plr.42.2018.03.19.01.12.30; Mon, 19 Mar 2018 01:12:44 -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; 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 S1755361AbeCSHwG (ORCPT + 99 others); Mon, 19 Mar 2018 03:52:06 -0400 Received: from mga06.intel.com ([134.134.136.31]:5384 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754524AbeCSHwE (ORCPT ); Mon, 19 Mar 2018 03:52:04 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Mar 2018 00:52:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,329,1517904000"; d="scan'208";a="26831891" Received: from vkoul-udesk7.iind.intel.com (HELO localhost) ([10.223.84.143]) by orsmga006.jf.intel.com with ESMTP; 19 Mar 2018 00:52:01 -0700 Date: Mon, 19 Mar 2018 13:26:09 +0530 From: Vinod Koul To: Ludovic Desroches Cc: Maxime Jayat , Nicolas Ferre , Dan Williams , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] dmaengine: at_xdmac: fix rare residue corruption Message-ID: <20180319075608.GM15443@localhost> References: <20180222113955.4043-1-maxime.jayat@mobile-devices.fr> <20180301082516.GL22457@rfolt0960.corp.atmel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180301082516.GL22457@rfolt0960.corp.atmel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 01, 2018 at 09:25:16AM +0100, Ludovic Desroches wrote: > 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. any update on that? This has been pending for a while... > > 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 > > -- ~Vinod