Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2238043imm; Mon, 28 May 2018 04:32:17 -0700 (PDT) X-Google-Smtp-Source: AB8JxZphIHQ8Gc5JrYg6lfdmzvX9WSnsoSajQojsFyJiKhAXqoG03PLISWjKaUp6dO2VjtpAKXcW X-Received: by 2002:aa7:8609:: with SMTP id p9-v6mr12978554pfn.123.1527507137891; Mon, 28 May 2018 04:32:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527507137; cv=none; d=google.com; s=arc-20160816; b=pcV0un3KrVY5wecnspv7qB/SHfbhuqKdMh/8ywjY2+ahFALVsfgnh+HVFyhVTri8EY oM+1FVc06MAnKNQdZQrbnTtyQG96M6MR9lwyAzm8BbWx7O9QSvW7tfpNouoitcqtUunw Y8Dq/v/z+nH0a7hSAIFU4tWuvYFPH6td4OJIKskIsT10b7qr9S58kROmWcdbKj4/Ue5M 0t6yT3Sfluw8y8p3tIsIATPWOpWV89EAPoODmz0gRN5A+k+xE9VjB1KHxe7SqSfUksBp zGrOlTSP6H8gPPi5Cmyf4kPicdKScic8UpVLaZSGi9EJgn7DuyZrfnG8qunD+kAQpcpP 5zFw== 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=H7zqImQNsZxwO5UdAdGTG4O3w9x4gHtrKt9ymnhZj8M=; b=mq93h37P+9ECrIuVeAO1R5B5S2XqkqBd0UpIEEJ2knmcuhn4xUvxwbC9BojmnETMGj YHP9sOYscXxuPrZkJM6IDJSLv4voiLKkit4cFvofh6gM51loQu22NWsEa8saP7HKYsrE JgnQwYujDal8gJKzxdI5zclHMThQ8kG6z0re881KSv+SlOgolLUf30Pvm7yD1xL3lXOq dNizmxhQRxPg4mKotG+S/vRrk0JSAqgdYSmHs7Ekppv1EtQuOl90JTLASaMc8Lc+DaAL H7S/ASs6RW2b0VMcQn2mf2NtsOyAojX+XNQj2vT5OmWrnpCBBPJrJvsywe/gxZA71dx7 QgyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=a0+5uQOH; 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 m4-v6si29265308plt.561.2018.05.28.04.32.03; Mon, 28 May 2018 04:32:17 -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=a0+5uQOH; 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 S938328AbeE1Lap (ORCPT + 99 others); Mon, 28 May 2018 07:30:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:33860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424002AbeE1LOi (ORCPT ); Mon, 28 May 2018 07:14: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 1E779206B7; Mon, 28 May 2018 11:14:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527506077; bh=mL2FYn2TDK95oDloJYOm4G72pSA+TZkh5Mq8U48DYx0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a0+5uQOHrhsxb+rhb3bV/x4vwfxjdoyJdxNmjN+k63zr3Jw/5T9+CFjufV7sNFNqV Bic10/LAyLzKQ+7032KnQLvtPlB1CGIOW1rQv2O3eJGRoJl5RsllRyIWoAxGoHL25X kedENinVbWSrppNTRphZZQOBamzAenytRtIrfUl0= 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.16 212/272] dmaengine: rcar-dmac: Check the done lists in rcar_dmac_chan_get_residue() Date: Mon, 28 May 2018 12:04:05 +0200 Message-Id: <20180528100258.317133820@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100240.256525891@linuxfoundation.org> References: <20180528100240.256525891@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.16-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 @@ -1301,8 +1301,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;