Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4489152ybx; Mon, 4 Nov 2019 14:16:17 -0800 (PST) X-Google-Smtp-Source: APXvYqypfqk5sxabVxZxXOv3pedCBSNrPJPvr1HoOTDkF1pmKE8tsE2zGlqNwdHhA6NvZyUFfTEb X-Received: by 2002:a50:becf:: with SMTP id e15mr15975493edk.135.1572905776824; Mon, 04 Nov 2019 14:16:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905776; cv=none; d=google.com; s=arc-20160816; b=mAa5RGscjE/Isxpy+rRPZPjFedtj6O7VQkRBfosv8/JYUu1jn/ygUpsfAT/40YUKJg xI5bKJ8sKmrz9gLTFJ4cljmkt/1umjDXTT3FkB6yLm9/wDf8MauY7DEo5sNjY68zvCpF caa2p30WWyXj7b04rbEe4BphiXA1z5C398bQ0N0gBmwKEsSCoRFSQMpaC+8H7LqY4sex BZN9baYU3mGxdpBF4XgwjA3a+d6PZxvM86aEEbz5RqzK6IsuYHVCjQvtJDt4PLNcSoeO ZDPYkUbDsSUmxCv5jAz26ECTtt9OvQk/LXLUUKDN+K8CZ3vfSiwLXVwTF65kJ+TgVjy4 g0vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YveamxPlR4qevnQEp766PeBaMlzQj/BRrJiWwEqeA3E=; b=ovlKUNCBKMLZulIO8pkwGmX705F6W92AC+9bY6nINcITso8fTvJ9Xyjng1GOcsbeLf 3ypC4mdO2NMTBAEST8dxF4INhsCsHEzO0m9OqRL8D32YAL9l5IIkvvvqay8Ws1b/jNpE cru90Fy9l64HqNywju8AHB3q6KGD07yJ66qIQkgAXvpkpLG8eX36Hg7uBsstUKX0v4EB /gZSAn5pIhG7yjtsSxAHKVT9lDm8X+LxNL2EjONp74j0zdJj3UHSH5+wJvcGoAo1TpuE A8SzAk1b+4hbPDflbyV2jBF1SSz+YjxgQbgN5s8P3wnGhQ+rDdTsxnVzIZAlfu18W+S/ nl4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MZvrTpNy; 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 r19si12685979ejz.6.2019.11.04.14.15.49; Mon, 04 Nov 2019 14:16:16 -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; dkim=pass header.i=@kernel.org header.s=default header.b=MZvrTpNy; 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 S2390506AbfKDWKL (ORCPT + 99 others); Mon, 4 Nov 2019 17:10:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:43300 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390131AbfKDWKI (ORCPT ); Mon, 4 Nov 2019 17:10:08 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (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 A497F2084D; Mon, 4 Nov 2019 22:10:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905407; bh=lQk2dCPShHPcrBF0qs2qgGMBx+xyTRvvjgf+a08rBDo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MZvrTpNygJ1WqqwAO1emjMsY0u3m6mXRGknOEsZLoVEGIAznMNV3rIC8YaRc4k73Z dx2hoByfk22IMN4Sm9q8Ek4kIa8dqCgj7Cqp2WPS7pnpLhwCnN/Fbb+ZaVnaYMEeoh M3h68hTBCFbGnUasY5E9d4zsxMHFqzP+zks8R9c4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeffrey Hugo , Vinod Koul Subject: [PATCH 5.3 133/163] dmaengine: qcom: bam_dma: Fix resource leak Date: Mon, 4 Nov 2019 22:45:23 +0100 Message-Id: <20191104212149.973116290@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jeffrey Hugo commit 7667819385457b4aeb5fac94f67f52ab52cc10d5 upstream. bam_dma_terminate_all() will leak resources if any of the transactions are committed to the hardware (present in the desc fifo), and not complete. Since bam_dma_terminate_all() does not cause the hardware to be updated, the hardware will still operate on any previously committed transactions. This can cause memory corruption if the memory for the transaction has been reassigned, and will cause a sync issue between the BAM and its client(s). Fix this by properly updating the hardware in bam_dma_terminate_all(). Fixes: e7c0fe2a5c84 ("dmaengine: add Qualcomm BAM dma driver") Signed-off-by: Jeffrey Hugo Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20191017152606.34120-1-jeffrey.l.hugo@gmail.com Signed-off-by: Vinod Koul Signed-off-by: Greg Kroah-Hartman --- drivers/dma/qcom/bam_dma.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) --- a/drivers/dma/qcom/bam_dma.c +++ b/drivers/dma/qcom/bam_dma.c @@ -694,6 +694,25 @@ static int bam_dma_terminate_all(struct /* remove all transactions, including active transaction */ spin_lock_irqsave(&bchan->vc.lock, flag); + /* + * If we have transactions queued, then some might be committed to the + * hardware in the desc fifo. The only way to reset the desc fifo is + * to do a hardware reset (either by pipe or the entire block). + * bam_chan_init_hw() will trigger a pipe reset, and also reinit the + * pipe. If the pipe is left disabled (default state after pipe reset) + * and is accessed by a connected hardware engine, a fatal error in + * the BAM will occur. There is a small window where this could happen + * with bam_chan_init_hw(), but it is assumed that the caller has + * stopped activity on any attached hardware engine. Make sure to do + * this first so that the BAM hardware doesn't cause memory corruption + * by accessing freed resources. + */ + if (!list_empty(&bchan->desc_list)) { + async_desc = list_first_entry(&bchan->desc_list, + struct bam_async_desc, desc_node); + bam_chan_init_hw(bchan, async_desc->dir); + } + list_for_each_entry_safe(async_desc, tmp, &bchan->desc_list, desc_node) { list_add(&async_desc->vd.node, &bchan->vc.desc_issued);