Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp805785pxb; Tue, 9 Nov 2021 00:01:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVtNu1irzjH/yvbhnBap69ZKiZgSQY7PfRLfgeXLtR3D0rbqu8CllQ6PxKUhE+WF0fYAih X-Received: by 2002:a02:c908:: with SMTP id t8mr3891346jao.55.1636444874039; Tue, 09 Nov 2021 00:01:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636444874; cv=none; d=google.com; s=arc-20160816; b=lJyV26zCNmuAes2MfRE7i54YpU4bxHbMAwmlxSXPcpTZI6eXLHzHfibGgAxKDeIK4g SDyFT0fHQx8KKuuIaNjxdRx4hCvpgNfBIFqLiJ+h7EfBcRK0o6tjSfclag/XnlXeUHuH n0zlRZGIbRBWVoXYVPv2uDRThitCTyYzwzjdPVd1JlNjc6K+6HQ6EE1QW5JXdmtdVzqf eTzi3RVtQiLfRD+we1y5QRGmUm82JpjnnP2PZk1TC7S3x4OY7zm1YukE+5NBw9abx2hw 2mf3HXttyP8DRVur7NPVUgJCwFDEusf8voelOmH/qm+4JJbFMw4I9vq27j9NNLfgf2ws QbCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Ddwo8+d/yz5mljzI5La4PaW9B3INTKdyykEKe0hUYdA=; b=Cgtkrd+flVPjy6io5JR2Ks+LBmDnZUrqboNB9zAv61AjkJP1GXkR3zKCNbVad/pAav wgXDJcneKFdEkOmc2zIrFk5x9QgLB+hsXXAXe7E2Yuj7OIMv4mzm0P4oI2N815AzxQh0 6VMbv6CY7G8i8Y0VGJkwYtUSYQTCqWsYPOEVL/7xtfAu5HpeMOJaCRuYPM6y2QLEy0si 34gAsqDYmfzJMfeRb4ZJjq/3zygb74fSayXQCOJ3S4fVf5lopghvXBFslDbbrBLM/iro QQl73hBU9yOlFqy21yttrTGW/Emi7bAMRbKgXtUwHXHIL6j2VYS8mQPysKLivAEAYKt+ ZsTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hYPmH3UY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f25si213118iox.8.2021.11.09.00.00.58; Tue, 09 Nov 2021 00:01:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hYPmH3UY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236699AbhKIBCZ (ORCPT + 99 others); Mon, 8 Nov 2021 20:02:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:58052 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236525AbhKIBCZ (ORCPT ); Mon, 8 Nov 2021 20:02:25 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id EE649611BD; Tue, 9 Nov 2021 00:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636419579; bh=qmHOld4pvSzd7AF+W6wQ4Nj6bQyCu6INWj0h1+yktDw=; h=From:To:Cc:Subject:Date:From; b=hYPmH3UYjMsL2pTdfIZmE+jerAc18ju/8lYAOtJ+oKbjmiKjszLfe3Hny6AxspflR NmzZgfbe/YOasgDuZX+loVZLub2Z8caH54Woj7ztEXOD5kJU5IkPZ6iV6H1LKtGprM 974wRO2NeS7t0UX9SzenjcRBcaD/6DuvxRMANFNH00FOs3WbB45DKLtlsNa5SraXvq egwygga6Lp6eBwYWXtJlbypcCd4ijuzy9WztiZjtN7craHP1rQu6YjyEv42Y/QgP9+ eCzsN43PcLpmiyJ9qGs1oiOdMooSFmmEjtzpofeBVzY7eEd5kua9NQ3rjQVjbLzvj5 FWLALIqtMjHbw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Charan Teja Reddy , =?UTF-8?q?Christian=20K=C3=B6nig?= , Sasha Levin , sumit.semwal@linaro.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH AUTOSEL 5.15 001/146] dma-buf: WARN on dmabuf release with pending attachments Date: Mon, 8 Nov 2021 12:42:28 -0500 Message-Id: <20211108174453.1187052-1-sashal@kernel.org> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Charan Teja Reddy [ Upstream commit f492283b157053e9555787262f058ae33096f568 ] It is expected from the clients to follow the below steps on an imported dmabuf fd: a) dmabuf = dma_buf_get(fd) // Get the dmabuf from fd b) dma_buf_attach(dmabuf); // Clients attach to the dmabuf o Here the kernel does some slab allocations, say for dma_buf_attachment and may be some other slab allocation in the dmabuf->ops->attach(). c) Client may need to do dma_buf_map_attachment(). d) Accordingly dma_buf_unmap_attachment() should be called. e) dma_buf_detach () // Clients detach to the dmabuf. o Here the slab allocations made in b) are freed. f) dma_buf_put(dmabuf) // Can free the dmabuf if it is the last reference. Now say an erroneous client failed at step c) above thus it directly called dma_buf_put(), step f) above. Considering that it may be the last reference to the dmabuf, buffer will be freed with pending attachments left to the dmabuf which can show up as the 'memory leak'. This should at least be reported as the WARN(). Signed-off-by: Charan Teja Reddy Reviewed-by: Christian König Link: https://patchwork.freedesktop.org/patch/msgid/1627043468-16381-1-git-send-email-charante@codeaurora.org Signed-off-by: Christian König Signed-off-by: Sasha Levin --- drivers/dma-buf/dma-buf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 63d32261b63ff..474de2d988ca7 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -82,6 +82,7 @@ static void dma_buf_release(struct dentry *dentry) if (dmabuf->resv == (struct dma_resv *)&dmabuf[1]) dma_resv_fini(dmabuf->resv); + WARN_ON(!list_empty(&dmabuf->attachments)); module_put(dmabuf->owner); kfree(dmabuf->name); kfree(dmabuf); -- 2.33.0