Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2285230imm; Mon, 28 May 2018 05:24:06 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLyvy6MkYHlUNIy/Ty69kVi9qB4WUdM+OdvufFIaaaX9iXYxoI7SBI60Gfm8K7YCBjaprfW X-Received: by 2002:a17:902:8bc6:: with SMTP id r6-v6mr8914338plo.257.1527510246122; Mon, 28 May 2018 05:24:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527510246; cv=none; d=google.com; s=arc-20160816; b=tADa8eG0VgPIf1wUeBcsdb/9ft0eW/HLNnqxEz2AXHVotG727NkxsPM/3jrQqd4T15 FtkHHY6me/GcdCGOYUJQk1f9jtU4B8Z/JDbHRqSP5sh1sg6pKiAhGU3+yhlg9KQXKFHQ Q977LtnI2HmGWL9NLZiaXP+YniOxjUDPZEVU7PCQodg4Uqud/o1ZsG+Rw09GFx/WnAC9 TQQ/H4/2dw8QYoP7p3J2ZeMtTcBRfgnLlLY0jnZo/NMO97MxP9zHZv72ljdsb7Mzmrfx 5W45MYzObl79ccaC4UI0XwZHnTecl/j5M1japiUast6h/lFsgbVjtD8tO8YsQbGguYUa K8cQ== 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:dkim-signature :arc-authentication-results; bh=dQrEgeGL+KUy4Mq5UF76EiG0syAzUKYmJAFTAg27Rig=; b=URWeA4/to3WM8Raf3pvyGFDnCmE81CNZ9kOKX72V3rIxpeiG0aZTJ/cV0Ia5E+S66l LQKOYxxF9AmjLn3wft7WjgBHUG4s6aOIXK6uy/xZwFVfqa9SbdAaOyuGcXMMfOqDMkxo yj5XLEVBUebKafLNqEhX0PfJoVDKRAGb7Dz6PPEUulkD4ZCQjDh47pPjqVF/T1wtq3ly 74hjubLH01Rhudb6vMWSjAsc57VZlJwwQKcJr67FR2dalFMM+RKWvVI57R4TZ4XZRXC0 Vq0LC3BHtavAqvT0DPfPj97uwUe1iKPjBBMNdufGPp/9EZPP/KZaYYnl2lNUJ/ReY3pO mbFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=boISTDGQ; 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 f64-v6si30812158pfa.252.2018.05.28.05.23.51; Mon, 28 May 2018 05:24:06 -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; dkim=pass header.i=@kernel.org header.s=default header.b=boISTDGQ; 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 S1422748AbeE1LBn (ORCPT + 99 others); Mon, 28 May 2018 07:01:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:49112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164854AbeE1LBi (ORCPT ); Mon, 28 May 2018 07:01:38 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F171E2075C; Mon, 28 May 2018 11:01:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505297; bh=s86/glsC7fHwaFcSqeAr/hXt4282tkHCxaAw6UUDdV0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=boISTDGQmD07xKPaSbaVmx7NQAziKpRFeP1aSr897UQcX7WO0fp7nR2vK6u/H2qRQ YIlIuFo9QUD1473uYnx9EqHQMGrS/vnhpRKfGdiccB2pwTvCpKhnd75JO6t7yyDJqs 9aVIGnZZ4QuTxa5MeIuX1OlG4/q6fu5o70qWVXh8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nguyen Viet Dung , Yoshihiro Shimoda , Vinod Koul , Sasha Levin Subject: [PATCH 4.14 446/496] dmaengine: rcar-dmac: Check the done lists in rcar_dmac_chan_get_residue() Date: Mon, 28 May 2018 12:03:51 +0200 Message-Id: <20180528100338.673676940@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yoshihiro Shimoda [ Upstream commit 3e081628d510b2ddbe493371d9c574d9275da17e ] This patch fixes an issue that a race condition happens between a client driver and the rcar-dmac driver: - The rcar_dmac_isr_transfer_end() is called. - The done list appears, and desc.running is the next active list. - rcar_dmac_chan_get_residue() is called by a client driver before rcar_dmac_isr_channel_thread() is called. - The rcar_dmac_chan_get_residue() will not find any descriptors. - And, the following WARNING happens: WARN(1, "No descriptor for cookie!"); The sh-sci driver with HSCIF (921,600bps) on R-Car H3 can cause this situation. So, this patch checks the done lists in rcar_dmac_chan_get_residue() and returns zero if the done lists has the argument cookie. Tested-by: Nguyen Viet Dung Signed-off-by: Yoshihiro Shimoda Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/dma/sh/rcar-dmac.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -1264,8 +1264,17 @@ static unsigned int rcar_dmac_chan_get_r * If the cookie doesn't correspond to the currently running transfer * then the descriptor hasn't been processed yet, and the residue is * equal to the full descriptor size. + * Also, a client driver is possible to call this function before + * rcar_dmac_isr_channel_thread() runs. In this case, the "desc.running" + * will be the next descriptor, and the done list will appear. So, if + * the argument cookie matches the done list's cookie, we can assume + * the residue is zero. */ if (cookie != desc->async_tx.cookie) { + list_for_each_entry(desc, &chan->desc.done, node) { + if (cookie == desc->async_tx.cookie) + return 0; + } list_for_each_entry(desc, &chan->desc.pending, node) { if (cookie == desc->async_tx.cookie) return desc->size;