public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Sumit Semwal <sumit.semwal@linaro.org>
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
	linux-arm-kernel@lists.infradead.org,
	rmk+kernel@arm.linux.org.uk, airlied@linux.ie, kgene@kernel.org,
	thierry.reding@gmail.com, pawel@osciak.com,
	m.szyprowski@samsung.com, mchehab@osg.samsung.com,
	linaro-kernel@lists.linaro.org, robdclark@gmail.com,
	daniel@ffwll.ch, intel-gfx@lists.freedesktop.org,
	linux-tegra@vger.kernel.org, inki.dae@samsung.com,
	maarten.lankhorst@canonical.com,
	Tomasz Stanislawski <t.stanislaws@samsung.com>
Subject: Re: [PATCH] dma-buf: add ref counting for module as exporter
Date: Thu, 7 May 2015 10:10:26 +0200	[thread overview]
Message-ID: <20150507081026.GA19773@kroah.com> (raw)
In-Reply-To: <1430983852-19267-1-git-send-email-sumit.semwal@linaro.org>

On Thu, May 07, 2015 at 01:00:52PM +0530, Sumit Semwal wrote:
> Add reference counting on a kernel module that exports dma-buf and
> implements its operations. This prevents the module from being unloaded
> while DMABUF file is in use.
> 
> The original patch [1] was submitted by Tomasz, but he's since shifted
> jobs and a ping didn't elicit any response.
> 
>   [tomasz: Original author]
> Signed-off-by: Tomasz Stanislawski <t.stanislaws@samsung.com>
> Acked-by: Daniel Vetter <daniel@ffwll.ch>
>   [sumits: updated & rebased as per review comments]
> Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
> 
> [1]: https://lkml.org/lkml/2012/8/8/163
> ---
>  drivers/dma-buf/dma-buf.c                      | 9 ++++++++-
>  drivers/gpu/drm/armada/armada_gem.c            | 1 +
>  drivers/gpu/drm/drm_prime.c                    | 1 +
>  drivers/gpu/drm/exynos/exynos_drm_dmabuf.c     | 1 +
>  drivers/gpu/drm/i915/i915_gem_dmabuf.c         | 1 +
>  drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c      | 1 +
>  drivers/gpu/drm/tegra/gem.c                    | 1 +
>  drivers/gpu/drm/udl/udl_dmabuf.c               | 1 +
>  drivers/gpu/drm/vmwgfx/vmwgfx_prime.c          | 1 +
>  drivers/media/v4l2-core/videobuf2-dma-contig.c | 1 +
>  drivers/media/v4l2-core/videobuf2-dma-sg.c     | 1 +
>  drivers/media/v4l2-core/videobuf2-vmalloc.c    | 1 +
>  drivers/staging/android/ion/ion.c              | 1 +
>  include/linux/dma-buf.h                        | 2 ++
>  14 files changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index c5a9138a6a8d..9583eac0238f 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -29,6 +29,7 @@
>  #include <linux/anon_inodes.h>
>  #include <linux/export.h>
>  #include <linux/debugfs.h>
> +#include <linux/module.h>
>  #include <linux/seq_file.h>
>  #include <linux/poll.h>
>  #include <linux/reservation.h>
> @@ -64,6 +65,7 @@ static int dma_buf_release(struct inode *inode, struct file *file)
>  	BUG_ON(dmabuf->cb_shared.active || dmabuf->cb_excl.active);
>  
>  	dmabuf->ops->release(dmabuf);
> +	module_put(dmabuf->ops->owner);
>  
>  	mutex_lock(&db_list.lock);
>  	list_del(&dmabuf->list_node);
> @@ -302,9 +304,14 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
>  		return ERR_PTR(-EINVAL);
>  	}
>  
> +	if (!try_module_get(exp_info->ops->owner))
> +		return ERR_PTR(-ENOENT);
> +
>  	dmabuf = kzalloc(alloc_size, GFP_KERNEL);
> -	if (dmabuf == NULL)
> +	if (!dmabuf) {
> +		module_put(exp_info->ops->owner);
>  		return ERR_PTR(-ENOMEM);
> +	}
>  
>  	dmabuf->priv = exp_info->priv;
>  	dmabuf->ops = exp_info->ops;
> diff --git a/drivers/gpu/drm/armada/armada_gem.c b/drivers/gpu/drm/armada/armada_gem.c
> index 580e10acaa3a..d2c5fc1269b7 100644
> --- a/drivers/gpu/drm/armada/armada_gem.c
> +++ b/drivers/gpu/drm/armada/armada_gem.c
> @@ -524,6 +524,7 @@ armada_gem_dmabuf_mmap(struct dma_buf *buf, struct vm_area_struct *vma)
>  }
>  
>  static const struct dma_buf_ops armada_gem_prime_dmabuf_ops = {
> +	.owner = THIS_MODULE,
>  	.map_dma_buf	= armada_gem_prime_map_dma_buf,
>  	.unmap_dma_buf	= armada_gem_prime_unmap_dma_buf,
>  	.release	= drm_gem_dmabuf_release,

The "easier" way to do this is change the registration function to add
the module owner automatically, which keeps you from having to modify
all of the individual drivers.  Look at how pci and usb do this for
their driver registration functions.  That should result in a much
smaller patch, that always works properly for everyone (there's no way
for driver to get it wrong.)

thanks,

greg k-h

  reply	other threads:[~2015-05-07  8:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-07  7:30 [PATCH] dma-buf: add ref counting for module as exporter Sumit Semwal
2015-05-07  8:10 ` Greg KH [this message]
2015-05-07 10:46   ` Sumit Semwal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150507081026.GA19773@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=airlied@linux.ie \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=inki.dae@samsung.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=kgene@kernel.org \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=maarten.lankhorst@canonical.com \
    --cc=mchehab@osg.samsung.com \
    --cc=pawel@osciak.com \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=robdclark@gmail.com \
    --cc=sumit.semwal@linaro.org \
    --cc=t.stanislaws@samsung.com \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox