Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp406339pxb; Tue, 19 Oct 2021 05:28:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6mMlhk14Fo724su8VbDXlcjaygFCfSpebmWE9LzGc578jwg+xzqcMkvu+0lnu56qb/KyH X-Received: by 2002:a17:907:118d:: with SMTP id uz13mr39678934ejb.382.1634646497658; Tue, 19 Oct 2021 05:28:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634646497; cv=none; d=google.com; s=arc-20160816; b=URaYxEzYuLTgcB1QRS207dm8yKeEOkRUit9cMMvQqAfpbC8Agc5vg+QG8d6bvGXFLD 055OYYMcqCPcnriv3uOMzS1GxoXHeEPKFe9+5Ck1G9W8SXaNoee9Uk0ngFwJ/pi0CKFS JC1OXUuB6Q+LNCTBHfCUOQnYDcBK7eSiKYpj727SoEXTe7psNpSYT6YYfu9KQXB16C5F 66WLalI++xvblcchuP6LkWf6ppUTZ9TARl0grXcFzPQCOHUdbSKIT7+bQoCwk38BjE/I w6E8D8QuaCjyvOqHmM6Ztrl5VZ7+FvDUiataFD/5bfrgduxP8p+2ZfpERuNGKYimECA8 MfQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=o9UcFhmEHhK/RMi7jtOLIZjnKLOJFv1869RT4KJUTG4=; b=JElkFDBLq5czW8jfo+F+HR3jT+CHPfIDh/7sXlTKW5SeD8IwoUM6tUyJf0xO1kwGXj iGuAUtgPi0fDK01ZCO7KtqEbwJSpOoMyNUoRtRLhOYki6LJNGi6UCdRb497lN+rJ1Mlz gpmaf1xh1Himpc+gDERdFsYcoivAWrT33hHbxDK+jI78nsVl85ytGoLLiuV1vitbeObW aGcduDhhTivKsC6ycjAZNX4rrxFn96EkNLCICjepM6qEo4XqTMHKOWZq26UU+TABv69M zp0oKAr+YzA5nLo/QvCU3YTeW3IicpF34g339PfKcnidK83KJVntcsb4dq85+p9sIxJf JYjA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nc12si29941119ejc.696.2021.10.19.05.27.54; Tue, 19 Oct 2021 05:28:17 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231564AbhJSM0C (ORCPT + 99 others); Tue, 19 Oct 2021 08:26:02 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:52618 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230231AbhJSM0C (ORCPT ); Tue, 19 Oct 2021 08:26:02 -0400 X-UUID: 397e8be8ddc3439cbd8ea5e09e71b96b-20211019 X-UUID: 397e8be8ddc3439cbd8ea5e09e71b96b-20211019 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 2146541762; Tue, 19 Oct 2021 20:23:44 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Tue, 19 Oct 2021 20:23:43 +0800 Received: from mszswglt01.gcn.mediatek.inc (10.16.20.20) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 19 Oct 2021 20:23:42 +0800 From: To: Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Matthias Brugger , "open list:DMA BUFFER SHARING FRAMEWORK" , "open list:DMA BUFFER SHARING FRAMEWORK" , "moderated list:DMA BUFFER SHARING FRAMEWORK" , open list , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" CC: , Guangming Cao Subject: [PATCH] dma-buf: add attachments empty check for dma_buf_release Date: Tue, 19 Oct 2021 20:23:45 +0800 Message-ID: <20211019122345.160555-1-guangming.cao@mediatek.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guangming Cao Since there is no mandatory inspection for attachments in dma_buf_release. There will be a case that dma_buf already released but attachment is still in use, which can points to the dmabuf, and it maybe cause some unexpected issues. With IOMMU, when this cases occurs, there will have IOMMU address translation fault(s) followed by this warning, I think it's useful for dma devices to debug issue. Signed-off-by: Guangming Cao --- drivers/dma-buf/dma-buf.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 511fe0d217a0..672404857d6a 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -74,6 +74,29 @@ static void dma_buf_release(struct dentry *dentry) */ BUG_ON(dmabuf->cb_shared.active || dmabuf->cb_excl.active); + /* attachment check */ + if (dma_resv_trylock(dmabuf->resv) && WARN(!list_empty(&dmabuf->attachments), + "%s err, inode:%08lu size:%08zu name:%s exp_name:%s flags:0x%08x mode:0x%08x, %s\n", + __func__, file_inode(dmabuf->file)->i_ino, dmabuf->size, + dmabuf->name, dmabuf->exp_name, + dmabuf->file->f_flags, dmabuf->file->f_mode, + "Release dmabuf before detach all attachments, dump attach:\n")) { + int attach_cnt = 0; + dma_addr_t dma_addr; + struct dma_buf_attachment *attach_obj; + /* dump all attachment info */ + list_for_each_entry(attach_obj, &dmabuf->attachments, node) { + dma_addr = (dma_addr_t)0; + if (attach_obj->sgt) + dma_addr = sg_dma_address(attach_obj->sgt->sgl); + pr_err("attach[%d]: dev:%s dma_addr:0x%-12lx\n", + attach_cnt, dev_name(attach_obj->dev), dma_addr); + attach_cnt++; + } + pr_err("Total %d devices attached\n\n", attach_cnt); + dma_resv_unlock(dmabuf->resv); + } + dmabuf->ops->release(dmabuf); if (dmabuf->resv == (struct dma_resv *)&dmabuf[1]) -- 2.17.1