Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2932385ybx; Fri, 8 Nov 2019 11:27:14 -0800 (PST) X-Google-Smtp-Source: APXvYqwLb+ffmfcPEmFcO9zC01k9yzvv5I7IKGcBmhyt6DkD8bAdjejGSC5mH6dTJE9FVHUjU5Jg X-Received: by 2002:aa7:d1c9:: with SMTP id g9mr12077047edp.162.1573241234562; Fri, 08 Nov 2019 11:27:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573241234; cv=none; d=google.com; s=arc-20160816; b=zB9GIoq9ddkPiMeLYqzBbCMHqCY/K8TU705+gGmnqEXSclZ8aUcNyMtDkW7GwR8tWO PmWlCeGzbWRMl3qJfPItNGDeD7kGc56L90fIFeEMLU37GfspM4TO1FRKJSIOExKB5d+u Dc17usnScU9n10WJPxsUDy+3obtQJTllEuIFOPG3tIAHA5zoGdkaQxjRYzObbkAIukej kcwMfXrfhzZ5LnPoVvNH6vaW054x0TSGJv7vd0yNGDLRJ4i69UIDipTSantMA7M6Pz9z IcT6irfpVvDukJ2kw1Od/T363a1aGCNXp07UJlDSECQNTqBr4epjQmoE8JyhS6ENQMPk 5rbg== 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=MWejWGF+4KGZQyxWEHegXgemXk1fScYNYhjHV4LjseI=; b=HPRN2IRan2RBzDL710rZz2n3mVUT7Xn1oIp49pnnLLtiEcRBMZiVgJXlczOK0FNVRK CLqTDoy8ioeDtASY2SWNW7wyecVItDSW4MYU14afrLCIt01AbDOzddKMdFnvQUHE85TG Beq0HXh/A2p3zFaJhW41di3kb5WDZJ5NGA7qIopMhy4xWpIZUqpaJ8j50tkbUsJ6QgSX hjfB0u6BSWv7uKQ6Tsk9lK6emzaQkrJx1g7Weuq6AXbyFpjsJN4vnGTUtKUhbujA40dN hCdNyEEQUcpsQiJzVBOWZkcIwwYEWvgHAvgVA+JaDeXfyE715Vpi6LSHXdD1a6X2CSZ0 i0Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tQxQ8sUu; 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 b34si5104503edc.74.2019.11.08.11.26.51; Fri, 08 Nov 2019 11:27:14 -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=tQxQ8sUu; 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 S1731882AbfKHSww (ORCPT + 99 others); Fri, 8 Nov 2019 13:52:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:49296 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731679AbfKHSwv (ORCPT ); Fri, 8 Nov 2019 13:52:51 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 EE6C5214DB; Fri, 8 Nov 2019 18:52:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573239170; bh=dDebS2nB2SScPS7tERpMCfwCatLC2gM5jAc2BMuIdCc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tQxQ8sUuxpvJHwAnFWF+w/XxebqwVfua0FBjNwm9TXMY+qiTGCxwdQedkSGrqzwCz hLy3iQIoMMmwtfJmnmandV3+pGpX/I6SqxxYwdyGjvhJkJDSHTZ2OFCWZLDrDDVjLN OF//jWH5RenYulryE1+XYlRmfxZcoVz4gKCWpI40= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeffrey Hugo , Vinod Koul Subject: [PATCH 4.4 23/75] dmaengine: qcom: bam_dma: Fix resource leak Date: Fri, 8 Nov 2019 19:49:40 +0100 Message-Id: <20191108174730.068632771@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191108174708.135680837@linuxfoundation.org> References: <20191108174708.135680837@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 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) --- a/drivers/dma/qcom_bam_dma.c +++ b/drivers/dma/qcom_bam_dma.c @@ -671,7 +671,21 @@ 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 (bchan->curr_txd) { + bam_chan_init_hw(bchan, bchan->curr_txd->dir); list_add(&bchan->curr_txd->vd.node, &bchan->vc.desc_issued); bchan->curr_txd = NULL; }