Received: by 10.192.165.148 with SMTP id m20csp2487260imm; Sun, 22 Apr 2018 08:03:24 -0700 (PDT) X-Google-Smtp-Source: AIpwx48q1si0HSuYzDX8YTCPOL+oGQQPUJXfe0DUn6W567RzaYdgBTtU6QpDQAhHlJ3ZxmS1mT2q X-Received: by 2002:a17:902:be06:: with SMTP id r6-v6mr11841059pls.158.1524409404316; Sun, 22 Apr 2018 08:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524409404; cv=none; d=google.com; s=arc-20160816; b=m68Z1I8ZdpWJq7Mk2RTjoacbk2ME90+n3uue23fJp0h2+FU2rH1cAHd9mKp/jJY/PT 8O+JGsQEIvHJ34gop5+/BquMl0ZZ4r6nTWZ3bTwBHGVx9I1krWtnG1FeMSyZRSmwj3lD u3v7ErokQXYDY2kRpainuXCl7XcHwTsC/jn0y3Fs9vDjpzHsEbMCEes8UX76sLbTUDOP wZmakj3RoS05KHKb1rk9D5RO8ornqs7YltfY6Xl4Hag5WEnmVLhefocgG451W0B0p7fJ Sj5/0v9d3LwkuJIXx5mJBUC14MWGOpBUtNScuz5d6g/Wmgz4g+fyMusfy6EuKWiBWT18 XxLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=jsOLuxG1ryBk5LZnadQ7ygc+uFLTBG+qPPwTMZBtm68=; b=K1yZEF7si4W6qFaEhEL8aBDgktUk0Muv2tWr52a8Ruoxun5ax+cQg5VCDk7Q5DmklL 7T2T8frQU4QDPO5yioh5v/k2zYUDAgUWFtk8e3zSVb+YeoloAindXiFOcy1tmAV2Qbk/ 9ntatyueRCd00+AAXQ4330LVixAXsMjqxGv9bKtVarTV3BLKen6hku/fVSbLs7WCCigt +uap3cRWHcPMCbrua98RgIsnwUglWQ2J2F8JYOqV7RYpBZXDUoOOzFPHwQoyjQTreEuY Lnoyv8merEvkgVp1j1sLToSIhqacdMUdK9eTf0ea0H3RgV4SLW5R88VHLCDNLY4zfli9 IDIg== 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 e16si8190838pgr.502.2018.04.22.08.03.09; Sun, 22 Apr 2018 08:03:24 -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 S1754443AbeDVPA7 (ORCPT + 99 others); Sun, 22 Apr 2018 11:00:59 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55236 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756468AbeDVOMp (ORCPT ); Sun, 22 Apr 2018 10:12:45 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 40703C97; Sun, 22 Apr 2018 14:12:44 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxime Jayat , Ludovic Desroches , Vinod Koul Subject: [PATCH 4.9 44/95] dmaengine: at_xdmac: fix rare residue corruption Date: Sun, 22 Apr 2018 15:53:13 +0200 Message-Id: <20180422135212.217825317@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135210.432103639@linuxfoundation.org> References: <20180422135210.432103639@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Maxime Jayat commit c5637476bbf9bb86c7f0413b8f4822a73d8d2d07 upstream. 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 Acked-by: Ludovic Desroches Signed-off-by: Vinod Koul Signed-off-by: Greg Kroah-Hartman --- drivers/dma/at_xdmac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/dma/at_xdmac.c +++ b/drivers/dma/at_xdmac.c @@ -1473,10 +1473,10 @@ at_xdmac_tx_status(struct dma_chan *chan 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();