From patchwork Mon Sep 23 10:42:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inki Dae X-Patchwork-Id: 2927531 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 34B1BBFF05 for ; Mon, 23 Sep 2013 10:42:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 83B9C203E9 for ; Mon, 23 Sep 2013 10:42:50 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 1ACCD203E3 for ; Mon, 23 Sep 2013 10:42:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5C2AFE638E for ; Mon, 23 Sep 2013 03:42:48 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by gabe.freedesktop.org (Postfix) with ESMTP id 9E5E8E5C6D for ; Mon, 23 Sep 2013 03:42:34 -0700 (PDT) Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MTK00EAMR1GLU40@mailout3.samsung.com> for dri-devel@lists.freedesktop.org; Mon, 23 Sep 2013 19:42:32 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.115]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id 1B.8C.17682.81B10425; Mon, 23 Sep 2013 19:42:32 +0900 (KST) X-AuditID: cbfee68e-b7f756d000004512-85-52401b18b2a9 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 54.F8.09055.81B10425; Mon, 23 Sep 2013 19:42:32 +0900 (KST) Received: from daeinki-desktop.10.32.193.11 ([10.252.75.62]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MTK009GFR2VN950@mmp2.samsung.com>; Mon, 23 Sep 2013 19:42:32 +0900 (KST) From: Inki Dae To: airlied@linux.ie, dri-devel@lists.freedesktop.org Subject: [PATCH] drm/exynos: fix deadlock issue at mmap Date: Mon, 23 Sep 2013 19:42:31 +0900 Message-id: <1379932951-9089-1-git-send-email-inki.dae@samsung.com> X-Mailer: git-send-email 1.7.9.5 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrCLMWRmVeSWpSXmKPExsWyRsSkWFdC2iHIYN8rAYvecyeZLK58fc9m Men+BBaLs01v2B1YPLZ/e8Dqcb/7OJNH35ZVjAHMUVw2Kak5mWWpRfp2CVwZS3YJFTwSqbg3 aQVzA2OnYBcjJ4eEgInE+xWzmSFsMYkL99azdTFycQgJLGWUOLFkJSNM0Zx781hAbCGB6YwS 35vUIIq6mSR+LjwF1s0moCoxccV9NhBbRMBUomPSUrAGZgE/iRPnV4LZwgLmEtt2bwGrYQGq n/d7P9gCXgFniR2nP7B2MXIALVOQmDPJBmS+hMB9NolTx9uh6gUkvk0+xAJRIyux6QDU0ZIS B1fcYJnAKLiAkWEVo2hqQXJBcVJ6kZFecWJucWleul5yfu4mRmAInv73rG8H480D1ocYk4HG TWSWEk3OB4ZwXkm8obGZkYWpiamxkbmlGWnCSuK8ai3WgUIC6YklqdmpqQWpRfFFpTmpxYcY mTg4pRoYW/+tbGwp3aycEHomJzJh9b3yFT7W2qtXCqaY/d4Y29N2q9w14o2qkNGSHU52F9wS DsRK7mfZ+ePu1m0mmXPnd/AuU7L2l784oXdmIW+AoL3j6lM78yff6Vp0zmDZ5TdfUrqcTSW3 vLHdEHdp/w/tqWu1iqaqf97F+/+87fP8exneMU9XPBJdosRSnJFoqMVcVJwIADMkHrVXAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrIIsWRmVeSWpSXmKPExsVy+t9jQV0JaYcgg2svOCx6z51ksrjy9T2b xaT7E1gszja9YXdg8dj+7QGrx/3u40wefVtWMQYwRzUw2mSkJqakFimk5iXnp2TmpdsqeQfH O8ebmhkY6hpaWpgrKeQl5qbaKrn4BOi6ZeYA7VNSKEvMKQUKBSQWFyvp22GaEBripmsB0xih 6xsSBNdjZIAGEtYwZizZJVTwSKTi3qQVzA2MnYJdjJwcEgImEnPuzWOBsMUkLtxbzwZiCwlM Z5T43qTWxcgFZHczSfxceIoZJMEmoCoxccV9sCIRAVOJjklLwZqZBfwkTpxfCWYLC5hLbNu9 BayGBah+3u/9jCA2r4CzxI7TH1i7GDmAlilIzJlkM4GRewEjwypG0dSC5ILipPRcQ73ixNzi 0rx0veT83E2M4AB/JrWDcWWDxSFGAQ5GJR7eiET7ICHWxLLiytxDjBIczEoivH6sDkFCvCmJ lVWpRfnxRaU5qcWHGJOBlk9klhJNzgdGX15JvKGxiZmRpZG5oYWRsTlpwkrivAdarQOFBNIT S1KzU1MLUotgtjBxcEo1MHrNfL9n/os1NxdYFEfvY9l7MDmH8fLh8+ebm1prlsc2ld205Tz1 3j5LutdbLeOp+a8t+14ufHmmbNZivW/bZ12dz71m5dKXYi+fzlqSEXd6Ulr9EVuNMxqvd/ev XOsR4mXXWDjL1q9jCdOsQ+esi86sTeys22Dkw/XrruHK3mlSNzV7FyyOnSOoxFKckWioxVxU nAgASLhPubQCAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Cc: Kyungmin Park 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=-6.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 This patch fixes the deadlock issue when another process requested mmap system call. This issue can incur the deadlock if another process sharing the same file called mmap system call between ->f_op pointer chaning and restoring. So this patch calls down_write(&mm->mmap_sem) before do_mmap_pgoff call and then up_write(&mm->mmap_sem) after do_mmap_pg_off call so that when another process called mmap system call, the process can wait for up_write() call until the ->f_op pointer is restored. Signed-off-by: Inki Dae Signed-off-by: Kyungmin Park --- drivers/gpu/drm/exynos/exynos_drm_gem.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c index 49f9cd2..779c2d7 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_gem.c +++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c @@ -13,6 +13,7 @@ #include #include +#include #include #include "exynos_drm_drv.h" @@ -420,6 +421,7 @@ int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data, { struct drm_exynos_gem_mmap *args = data; struct drm_gem_object *obj; + struct mm_struct *mm = current->mm; unsigned long addr; if (!(dev->driver->driver_features & DRIVER_GEM)) { @@ -433,6 +435,8 @@ int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data, return -EINVAL; } + down_write(&mm->mmap_sem); + /* * We have to use gem object and its fops for specific mmaper, * but vm_mmap() can deliver only filp. So we have to change @@ -457,8 +461,17 @@ int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data, */ file_priv->filp->private_data = obj; - addr = vm_mmap(file_priv->filp, 0, args->size, - PROT_READ | PROT_WRITE, MAP_SHARED, 0); + addr = security_mmap_file(file_priv->filp, PROT_READ | PROT_WRITE, + MAP_SHARED); + if (!addr) { + unsigned long populate; + + addr = do_mmap_pgoff(file_priv->filp, 0, args->size, + PROT_READ | PROT_WRITE, + MAP_SHARED, 0, &populate); + if (populate) + mm_populate(addr, populate); + } drm_gem_object_unreference(obj); @@ -469,10 +482,13 @@ int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data, file_priv->filp->private_data = file_priv; } mutex_unlock(&dev->struct_mutex); + up_write(&mm->mmap_sem); + return (int)addr; } mutex_unlock(&dev->struct_mutex); + up_write(&mm->mmap_sem); args->mapped = addr;