Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1317127pxv; Fri, 23 Jul 2021 05:35:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKnu9A2SZl2gTXE8Bs/jZ8SKInKvv1Mk8VNgW7+1MGfporf1eth1toNoGx96eHmP9tXGfk X-Received: by 2002:a02:a797:: with SMTP id e23mr4022102jaj.121.1627043722190; Fri, 23 Jul 2021 05:35:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627043722; cv=none; d=google.com; s=arc-20160816; b=JTe/+lBspMgwqSvL+zShDM8PT/Eb0fBvG+RwCuhS2HyT+y5kSf4HLi7B/Yw9hzPqf+ dOr5ixHYYsOKGnpoyMMxUHBXPATH9zyoOurtdGWHR644/WLxiwoknAelnK5J1bylRWe0 z5Sw3vAgDQscNqHJEE9dkNtY6I2gAwUAU+nTtzwQ0UO5OocPP5okYFbEzJD699dtnCDw VZyIyWmpchWh5WKakr6Iv8+zT9u32WQ+4YXYk2hp4gk3F7iEdUeSKVPxMuBAPYigLeBe xorFPaLC2L7hkKB0YlOJ4/CELa+8/B0TxIyKHdGiyLCXO3ZhwaXLcO3ntE1AI1yTYCtI tA8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:dmarc-filter :sender:dkim-signature; bh=wysabhsQt0sSAqX5dRirGa+wnwar64nTD29qqOFcFoM=; b=ALcVMpdDyZAWIHYegadp+EEAIkFcSHp/rv9L7PDhvk5emrOJJjuVJVqDVFqDagn0Is ag+m/mn3kNyWl4JjfC/mSWuFwoAnMPtDRUxGzHK2PFkkmXVqu5mGSnXW5fiSoOjxN6cp EMaaDF/qAnyMMbVKGRHcrdPHFqRshDfSS19z8u2EmROrtt2ufJ8uZWDx9CmTGKsB1dtQ CiF4jOlTZLW3npmkCxpt9Ree1cRONt8hOpyn7rbod3EDQ82sYcY56MfxS0lh9vE6DMOi ukElEDVbJ51fjlzjOOeydpDUm2LM3xHtyx4hBFrOw2b7F7dps40o8s6e0ayWi34mQw5m 1HJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=A8PlE7Me; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t4si4165986iln.104.2021.07.23.05.35.10; Fri, 23 Jul 2021 05:35:22 -0700 (PDT) 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=@mg.codeaurora.org header.s=smtp header.b=A8PlE7Me; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234857AbhGWLwY (ORCPT + 99 others); Fri, 23 Jul 2021 07:52:24 -0400 Received: from so254-9.mailgun.net ([198.61.254.9]:13903 "EHLO so254-9.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234865AbhGWLvo (ORCPT ); Fri, 23 Jul 2021 07:51:44 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1627043503; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=wysabhsQt0sSAqX5dRirGa+wnwar64nTD29qqOFcFoM=; b=A8PlE7MeOL9owTQ+49gawUgeVHzG7TKb8irkHm7sUuX64dX9dfHLY2J3fbJXvu9roL/auyaK pA8oIPmpPyFZgHR4sWCIa8VFfzfkVf1IQ3DangyUihacF20W3ZhcJP0Ep3qigFNPEYAN4uUl OcqZRB2G6pjbO0ZAm0UY7HLCsCg= X-Mailgun-Sending-Ip: 198.61.254.9 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n03.prod.us-east-1.postgun.com with SMTP id 60fab697b653fbdadd2df865 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Fri, 23 Jul 2021 12:31:19 GMT Sender: charante=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 8FC5FC433D3; Fri, 23 Jul 2021 12:31:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00,SPF_FAIL, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from hu-charante-hyd.qualcomm.com (unknown [202.46.22.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: charante) by smtp.codeaurora.org (Postfix) with ESMTPSA id 5A739C433F1; Fri, 23 Jul 2021 12:31:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 5A739C433F1 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=charante@codeaurora.org From: Charan Teja Reddy To: sumit.semwal@linaro.org, christian.koenig@amd.com Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, vinmenon@codeaurora.org, Charan Teja Reddy Subject: [PATCH] dma-buf: WARN on dmabuf release with pending attachments Date: Fri, 23 Jul 2021 18:01:08 +0530 Message-Id: <1627043468-16381-1-git-send-email-charante@codeaurora.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 511fe0d..733c8b1 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -79,6 +79,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); -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation