From patchwork Thu Aug 9 09:36:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 10615 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 1D2AE23E56 for ; Thu, 9 Aug 2012 09:36:50 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id E14CBA189DD for ; Thu, 9 Aug 2012 09:36:49 +0000 (UTC) Received: by mail-yx0-f180.google.com with SMTP id q6so206819yen.11 for ; Thu, 09 Aug 2012 02:36:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:x-auditid :from:to:date:message-id:x-mailer:in-reply-to:references :x-brightmail-tracker:x-tm-as-mml:cc:subject:x-beenthere :x-mailman-version:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-gm-message-state; bh=KfxUWxqfCsRCrj0EQS3Txu/9g8VDwupWws2GDn9CzYo=; b=mAAvi+e1kzCnudocnfpMPKeCtPJoI8ZtA7LorDWm0PkaPUg3kq04yu8VI/AtlUcgZK XtfA0FP/4wpGe5YLJ9t8LEG4mpzrHsCgzqe3MZt24zVD+mPWXQ1YC1TbLDNrHjQp8IZg h1E+YzslvQHTgYYYQK/ZI5zPOKSLaP25jIcCvmXTeLaz2UMkHNfUO86hrqydrZsX3B9W mNgJQOSwPWAHdFS8S4SpfKRXiCydzP+3R3vV2WjflDxk3mwboDGpWUZVF1BLwT9qfPBJ LvlBLAScNfrcAbpTZbA08xpunig4Jrrw7aK6wd1BcQfHj6brZU7UdzPaWaZew/SI+JJq omPg== Received: by 10.50.57.168 with SMTP id j8mr406557igq.16.1344505009407; Thu, 09 Aug 2012 02:36:49 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.200 with SMTP id ew8csp411igc; Thu, 9 Aug 2012 02:36:48 -0700 (PDT) Received: by 10.180.91.228 with SMTP id ch4mr1361852wib.7.1344505007286; Thu, 09 Aug 2012 02:36:47 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id bd3si910269wib.22.2012.08.09.02.36.46; Thu, 09 Aug 2012 02:36:47 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SzPAb-00085g-4J; Thu, 09 Aug 2012 09:36:45 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SzPAZ-00085M-QT for linaro-mm-sig@lists.linaro.org; Thu, 09 Aug 2012 09:36:44 +0000 Received: from epcpsbgm1.samsung.com (mailout4.samsung.com [203.254.224.34]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M8H00CBPEOYWYV0@mailout4.samsung.com> for linaro-mm-sig@lists.linaro.org; Thu, 09 Aug 2012 18:36:42 +0900 (KST) X-AuditID: cbfee61a-b7f616d000004b7e-02-502384aa3e4a Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id B9.3A.19326.AA483205; Thu, 09 Aug 2012 18:36:42 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0M8H00KSJEOOS280@mmp1.samsung.com> for linaro-mm-sig@lists.linaro.org; Thu, 09 Aug 2012 18:36:42 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Thu, 09 Aug 2012 11:36:21 +0200 Message-id: <1344504982-30415-2-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1344504982-30415-1-git-send-email-t.stanislaws@samsung.com> References: <1344504982-30415-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrEJMWRmVeSWpSXmKPExsVy+t9jAd1VLcoBBtte8ll8ufKQyYHR4/a/ x8wBjFFcNimpOZllqUX6dglcGQ3zzzAVPJGo6P99gKWBcYZIFyMnh4SAicTsL4fZIGwxiQv3 1gPZXBxCAosYJQ7MnswK4axlkjiyrp8ZpIoNqOPYks+MILaIgIPE6buzmEGKmAV2MkscvbUG yOHgEBbwljjWKAlisgioSnTt8QMp5xXwkPjZOoUdYpm8xNP7fWCLOQU8JRavfg02Xgio5lbf FaYJjLwLGBlWMYqmFiQXFCel5xrqFSfmFpfmpesl5+duYgT7/JnUDsaVDRaHGAU4GJV4eDU2 KAUIsSaWFVfmHmKU4GBWEuG9Va4cIMSbklhZlVqUH19UmpNafIhRmoNFSZzX2Purv5BAemJJ anZqakFqEUyWiYNTqoExOt7feT6v8G3r2PIctfl1mSVbDdgPzjbZcqZqz/yTx3k4W77/E0q+ 65AcpznVwXj2Vr8/O7TDVi/J+tFpvvL6fU2lVJ09jz7lP/rdJSUbvfyEWep2t5Qf86bP6b1Q M6VG3Pb2Q4YkuyedWZpa83V5/C5O/G+StOx35qrev5sCVtwJX/HvruFMJZbijERDLeai4kQA mx8/GPUBAAA= X-TM-AS-MML: No Cc: linaro-mm-sig@lists.linaro.org, jy0922.shim@samsung.com, pawel@osciak.com, gregkh@linuxfoundation.org, linux-doc@vger.kernel.org, sw0312.kim@samsung.com, linux-kernel@vger.kernel.org, inki.dae@samsung.com, kyungmin.park@samsung.com, laurent.pinchart@ideasonboard.com, airlied@redhat.com, dan.j.williams@intel.com Subject: [Linaro-mm-sig] [PATCH v2 1/2] dma-buf: add reference counting for exporter module X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQlRZu7KQFx3/XaKCYgNfURlD5Lx1TwHHTXBO/FzKgjfuYZVXWwmV+X5azM/UZ45jyQk71b7 This patch adds reference counting on a module that exported dma-buf and implements its operations. This prevents the module from being unloaded while DMABUF file is in use. Signed-off-by: Tomasz Stanislawski Acked-by: Sumit Semwal Acked-by: Daniel Vetter CC: linux-doc@vger.kernel.org --- Documentation/dma-buf-sharing.txt | 3 ++- drivers/base/dma-buf.c | 9 ++++++++- include/linux/dma-buf.h | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Documentation/dma-buf-sharing.txt b/Documentation/dma-buf-sharing.txt index ad86fb8..2613057 100644 --- a/Documentation/dma-buf-sharing.txt +++ b/Documentation/dma-buf-sharing.txt @@ -49,7 +49,8 @@ The dma_buf buffer sharing API usage contains the following steps: The buffer exporter announces its wish to export a buffer. In this, it connects its own private buffer data, provides implementation for operations that can be performed on the exported dma_buf, and flags for the file - associated with this buffer. + associated with this buffer. The operations structure has owner field. + You should initialize this to THIS_MODULE in most cases. Interface: struct dma_buf *dma_buf_export(void *priv, struct dma_buf_ops *ops, diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index c30f3e1..a1d9cab 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -27,6 +27,7 @@ #include #include #include +#include static inline int is_dma_buf_file(struct file *); @@ -40,6 +41,7 @@ static int dma_buf_release(struct inode *inode, struct file *file) dmabuf = file->private_data; dmabuf->ops->release(dmabuf); + module_put(dmabuf->ops->owner); kfree(dmabuf); return 0; } @@ -105,9 +107,14 @@ struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops, return ERR_PTR(-EINVAL); } + if (!try_module_get(ops->owner)) + return ERR_PTR(-ENOENT); + dmabuf = kzalloc(sizeof(struct dma_buf), GFP_KERNEL); - if (dmabuf == NULL) + if (dmabuf == NULL) { + module_put(ops->owner); return ERR_PTR(-ENOMEM); + } dmabuf->priv = priv; dmabuf->ops = ops; diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index eb48f38..22953de 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -37,6 +37,7 @@ struct dma_buf_attachment; /** * struct dma_buf_ops - operations possible on struct dma_buf + * @owner: the module that implements dma_buf operations * @attach: [optional] allows different devices to 'attach' themselves to the * given buffer. It might return -EBUSY to signal that backing storage * is already allocated and incompatible with the requirements @@ -70,6 +71,7 @@ struct dma_buf_attachment; * @vunmap: [optional] unmaps a vmap from the buffer */ struct dma_buf_ops { + struct module *owner; int (*attach)(struct dma_buf *, struct device *, struct dma_buf_attachment *);