From patchwork Wed Jun 26 02:14:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seung-Woo Kim X-Patchwork-Id: 2782281 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 214DBC0AB1 for ; Wed, 26 Jun 2013 02:15:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 22A392019F for ; Wed, 26 Jun 2013 02:15:14 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C993C20190 for ; Wed, 26 Jun 2013 02:15:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 88B44E62B6 for ; Tue, 25 Jun 2013 19:15:12 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by gabe.freedesktop.org (Postfix) with ESMTP id 6D94FE5D3C for ; Tue, 25 Jun 2013 19:14:54 -0700 (PDT) Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MOZ00DVBA8LRM80@mailout2.samsung.com> for dri-devel@lists.freedesktop.org; Wed, 26 Jun 2013 11:14:53 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.112]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id 11.32.17404.C9E4AC15; Wed, 26 Jun 2013 11:14:52 +0900 (KST) X-AuditID: cbfee68d-b7f096d0000043fc-9e-51ca4e9cd290 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id FA.26.28381.C9E4AC15; Wed, 26 Jun 2013 11:14:52 +0900 (KST) Received: from localhost.localdomain ([10.90.8.56]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MOZ006PYA87RK70@mmp2.samsung.com>; Wed, 26 Jun 2013 11:14:52 +0900 (KST) From: Seung-Woo Kim To: dri-devel@lists.freedesktop.org, airlied@linux.ie Subject: [PATCH] drm/gem: add mutex lock when using drm_gem_mmap_obj Date: Wed, 26 Jun 2013 11:14:42 +0900 Message-id: <1372212882-19082-1-git-send-email-sw0312.kim@samsung.com> X-Mailer: git-send-email 1.7.4.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrPLMWRmVeSWpSXmKPExsWyRsSkQHeO36lAg79LFS16z51ksrjy9T2b xdmmN+wWE5vusFg8X/iD2WLG5JdsFnt3TmZ0YPfYOesuu8fsjpmsHtu/PWD1uN99nMmjb8sq xgDWKC6blNSczLLUIn27BK6MFR8amArWiVdc2XOZsYFxq3AXIyeHhICJxIe+/cwQtpjEhXvr 2boYuTiEBJYyShw+vpwFpuhHzyZWiMR0RomV3UfBEkICzUwS366zg9hsAjoS+5f8ZgWxRQRM Jc5evsYM0sAs0MsocfLLTbCEsICLxNXtLxlBbBYBVYmeq/uBmjk4eAXcJBZu84ZYpiCx4N5b sCskBNrZJfYc/coGUS8g8W3yIRaQegkBWYlNB6CulpQ4uOIGywRGwQWMDKsYRVMLkguKk9KL DPWKE3OLS/PS9ZLzczcxAgP39L9nvTsYbx+wPsSYDDRuIrOUaHI+MPDzSuINjc2MLExNTI2N zC3NSBNWEudVa7EOFBJITyxJzU5NLUgtii8qzUktPsTIxMEp1cAYfLw2ULCZtWLlh3sFL+bp LGznUrE/M/sX/80HHG8nehaXJhzc9Oe4sPFbW9n7iZ1zgu4eXnbrvdyZ8A6ZWcx/XSTUow4E ugsH6f5O4Zt1xtqpqVSsyFKoS23dRs+q6Jm/fL//v7h+WU3qG5eNsrLTJIIPVteEi27Z83Py q0kzv6lyee37w5qixFKckWioxVxUnAgASCeX2XICAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsVy+t9jQd05fqcCDdYvlLToPXeSyeLK1/ds Fmeb3rBbTGy6w2LxfOEPZosZk1+yWezdOZnRgd1j56y77B6zO2ayemz/9oDV4373cSaPvi2r GANYoxoYbTJSE1NSixRS85LzUzLz0m2VvIPjneNNzQwMdQ0tLcyVFPISc1NtlVx8AnTdMnOA DlFSKEvMKQUKBSQWFyvp22GaEBripmsB0xih6xsSBNdjZIAGEtYwZqz40MBUsE684sqey4wN jFuFuxg5OSQETCR+9GxihbDFJC7cW8/WxcjFISQwnVFiZfdRFpCEkEAzk8S36+wgNpuAjsT+ Jb/BGkQETCXOXr7GDNLALNDLKHHyy02whLCAi8TV7S8ZQWwWAVWJnqv7gZo5OHgF3CQWbvOG WKYgseDeW7YJjNwLGBlWMYqmFiQXFCel5xrqFSfmFpfmpesl5+duYgTHxTOpHYwrGywOMQpw MCrx8CpsPRkoxJpYVlyZe4hRgoNZSYQ3/wZQiDclsbIqtSg/vqg0J7X4EGMy0PKJzFKiyfnA mM0riTc0NjEzsjQyN7QwMjYnTVhJnPdAq3WgkEB6YklqdmpqQWoRzBYmDk6pBsb+vuZ/PJL/ LFa2bDDrum6/QDRmDvNe/3fr8w/Wp8+f1npVWvhQmFmvdcOaYyuqpu/ccNC84cMGFevIv56W 4iFpyZWl/rcUjXetqjhSbHtD4VjuuRP9SmdDDr+cOyUsSDrrbcyRHsO7R19JTer+cJV3Vq5x R9MFoS+x1jMa9Mu/Kb7edyLtd6cSS3FGoqEWc1FxIgAwApAazwIAAA== DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Cc: kyungmin.park@samsung.com, laurent.pinchart+renesas@ideasonboard.com, sw0312.kim@samsung.com, yj44.cho@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: YoungJun Cho The drm_gem_mmap_obj() has to be protected with dev->struct_mutex, but some caller functions do not. So it adds mutex lock to missing callers and adds WARN_ON assertion whether drm_gem_mmap_obj() is called with mutex lock or not. Signed-off-by: YoungJun Cho Signed-off-by: Seung-Woo Kim Signed-off-by: Kyungmin Park CC: Laurent Pinchart CC: Rob Clark --- This patch is based on drm-next branch. drivers/gpu/drm/drm_gem.c | 4 ++++ drivers/gpu/drm/drm_gem_cma_helper.c | 3 +++ drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c | 3 +++ 3 files changed, 10 insertions(+), 0 deletions(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 4321713..b19bba0 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -661,6 +661,8 @@ EXPORT_SYMBOL(drm_gem_vm_close); * the GEM object is not looked up based on its fake offset. To implement the * DRM mmap operation, drivers should use the drm_gem_mmap() function. * + * NOTE: This function has to be protected with dev->struct_mutex + * * Return 0 or success or -EINVAL if the object size is smaller than the VMA * size, or if no gem_vm_ops are provided. */ @@ -669,6 +671,8 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, { struct drm_device *dev = obj->dev; + WARN_ON(!mutex_is_locked(&dev->struct_mutex)); + /* Check for valid size. */ if (obj_size < vma->vm_end - vma->vm_start) return -EINVAL; diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c index 9efabce..ce06397 100644 --- a/drivers/gpu/drm/drm_gem_cma_helper.c +++ b/drivers/gpu/drm/drm_gem_cma_helper.c @@ -487,9 +487,12 @@ static int drm_gem_cma_dmabuf_mmap(struct dma_buf *dmabuf, { struct drm_gem_cma_object *cma_obj = dmabuf->priv; struct drm_gem_object *gem_obj = &cma_obj->base; + struct drm_device *dev = gem_obj->dev; int ret; + mutex_lock(&dev->struct_mutex); ret = drm_gem_mmap_obj(gem_obj, gem_obj->size, vma); + mutex_unlock(&dev->struct_mutex); if (ret < 0) return ret; diff --git a/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c b/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c index 3256693..4fcca8d 100644 --- a/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c +++ b/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c @@ -140,12 +140,15 @@ static int omap_gem_dmabuf_mmap(struct dma_buf *buffer, struct vm_area_struct *vma) { struct drm_gem_object *obj = buffer->priv; + struct drm_device *dev = obj->dev; int ret = 0; if (WARN_ON(!obj->filp)) return -EINVAL; + mutex_lock(&dev->struct_mutex); ret = drm_gem_mmap_obj(obj, omap_gem_mmap_size(obj), vma); + mutex_unlock(&dev->struct_mutex); if (ret < 0) return ret;