From patchwork Fri Oct 13 23:13:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 10006111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 09C6760325 for ; Fri, 13 Oct 2017 23:16:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED2522918A for ; Fri, 13 Oct 2017 23:16:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1E112918E; Fri, 13 Oct 2017 23:16:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 645622918A for ; Fri, 13 Oct 2017 23:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Q58yXSZcV+FhKjyzsESkLYMM+JvzJ6LNAOh4W3vhs9o=; b=NMUzPzkcH7Na9BMzAX9WLKI8J7 YXBJisN0LmCUSzY45gu8zc8sitJfsCoEkPqJmLBqPD9dpObcZP3IkgcOZCZlhKf977I8kxO+jeDbO KAV1p1VaqJ+sJjrhWaeruuQNczikmTbrCRMpnqffKpqSSvd7GTj+v61bU45ZjiUW85UJ2NBUJCqvr aqv4vq9hvnOmWauIX6Dd1durtY0Ve9QeEbN3qt3YD7rdB+cDqfjFVWp5lyy67ZLvvxw/rx772yog3 bP40gY3SN/gxedRESn4UJ4WV/Fmv3CdCPIWVaFSEkVR4eZt8/xmPcf65qav1ourmKxmrBOliwErkQ bL1dsrSQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e39BR-00006d-Le; Fri, 13 Oct 2017 23:16:01 +0000 Received: from osg.samsung.com ([64.30.133.232]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e399Z-0005ZH-JV for linux-arm-kernel@lists.infradead.org; Fri, 13 Oct 2017 23:14:16 +0000 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id 3CF5F314CE; Fri, 13 Oct 2017 16:13:44 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from osg.samsung.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fxlRuY61Fc4O; Fri, 13 Oct 2017 16:13:42 -0700 (PDT) Received: from localhost.localdomain (c-24-9-64-241.hsd1.co.comcast.net [24.9.64.241]) by osg.samsung.com (Postfix) with ESMTPSA id 5C874314BD; Fri, 13 Oct 2017 16:13:42 -0700 (PDT) From: Shuah Khan To: mchehab@kernel.org, hansverk@cisco.com, kgene@kernel.org, krzk@kernel.org, s.nawrocki@samsung.com, shailendra.v@samsung.com, shuah@kernel.org, Julia.Lawall@lip6.fr, kyungmin.park@samsung.com, kamil@wypas.org, jtp.park@samsung.com, a.hajda@samsung.com Subject: [PATCH 1/2] media: exynos-gsc: fix lockdep warning Date: Fri, 13 Oct 2017 17:13:36 -0600 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171013_161406_373600_3E2690C2 X-CRM114-Status: GOOD ( 16.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The driver mmap functions shouldn't take lock when calling vb2_mmap(). Fix it to not take the lock. The following lockdep warning is fixed with this change. [ 1990.972058] ====================================================== [ 1990.978172] WARNING: possible circular locking dependency detected [ 1990.984327] 4.14.0-rc2-00002-gfab205f-dirty #4 Not tainted [ 1990.989783] ------------------------------------------------------ [ 1990.995937] qtdemux0:sink/2765 is trying to acquire lock: [ 1991.001309] (&gsc->lock){+.+.}, at: [] gsc_m2m_mmap+0x24/0x5c [exynos_gsc] [ 1991.009108] but task is already holding lock: [ 1991.014913] (&mm->mmap_sem){++++}, at: [] vm_mmap_pgoff+0x44/0xb8 [ 1991.021932] which lock already depends on the new lock. [ 1991.030078] the existing dependency chain (in reverse order) is: [ 1991.037530] -> #1 (&mm->mmap_sem){++++}: [ 1991.042913] __might_fault+0x80/0xb0 [ 1991.047096] video_usercopy+0x1cc/0x510 [videodev] [ 1991.052297] v4l2_ioctl+0xa4/0xdc [videodev] [ 1991.057036] do_vfs_ioctl+0xa0/0xa18 [ 1991.061102] SyS_ioctl+0x34/0x5c [ 1991.064834] ret_fast_syscall+0x0/0x28 [ 1991.069072] -> #0 (&gsc->lock){+.+.}: [ 1991.074193] lock_acquire+0x6c/0x88 [ 1991.078179] __mutex_lock+0x68/0xa34 [ 1991.082247] mutex_lock_interruptible_nested+0x1c/0x24 [ 1991.087888] gsc_m2m_mmap+0x24/0x5c [exynos_gsc] [ 1991.093029] v4l2_mmap+0x54/0x88 [videodev] [ 1991.097673] mmap_region+0x3a8/0x638 [ 1991.101743] do_mmap+0x330/0x3a4 [ 1991.105470] vm_mmap_pgoff+0x90/0xb8 [ 1991.109542] SyS_mmap_pgoff+0x90/0xc0 [ 1991.113702] ret_fast_syscall+0x0/0x28 [ 1991.117945] other info that might help us debug this: [ 1991.125918] Possible unsafe locking scenario: [ 1991.131810] CPU0 CPU1 [ 1991.136315] ---- ---- [ 1991.140821] lock(&mm->mmap_sem); [ 1991.144201] lock(&gsc->lock); [ 1991.149833] lock(&mm->mmap_sem); [ 1991.155725] lock(&gsc->lock); [ 1991.158845] *** DEADLOCK *** [ 1991.164740] 1 lock held by qtdemux0:sink/2765: [ 1991.169157] #0: (&mm->mmap_sem){++++}, at: [] vm_mmap_pgoff+0x44/0xb8 [ 1991.176609] stack backtrace: [ 1991.180946] CPU: 2 PID: 2765 Comm: qtdemux0:sink Not tainted 4.14.0-rc2-00002-gfab205f-dirty #4 [ 1991.189608] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree) [ 1991.195686] [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [ 1991.203393] [] (show_stack) from [] (dump_stack+0x98/0xc4) [ 1991.210586] [] (dump_stack) from [] (print_circular_bug+0x254/0x410) [ 1991.218644] [] (print_circular_bug) from [] (check_prev_add+0x468/0x938) [ 1991.227049] [] (check_prev_add) from [] (__lock_acquire+0x1314/0x14fc) [ 1991.235281] [] (__lock_acquire) from [] (lock_acquire+0x6c/0x88) [ 1991.242993] [] (lock_acquire) from [] (__mutex_lock+0x68/0xa34) [ 1991.250620] [] (__mutex_lock) from [] (mutex_lock_interruptible_nested+0x1c/0x24) [ 1991.259812] [] (mutex_lock_interruptible_nested) from [] (gsc_m2m_mmap+0x24/0x5c [exynos_gsc]) [ 1991.270159] [] (gsc_m2m_mmap [exynos_gsc]) from [] (v4l2_mmap+0x54/0x88 [videodev]) [ 1991.279510] [] (v4l2_mmap [videodev]) from [] (mmap_region+0x3a8/0x638) [ 1991.287792] [] (mmap_region) from [] (do_mmap+0x330/0x3a4) [ 1991.294986] [] (do_mmap) from [] (vm_mmap_pgoff+0x90/0xb8) [ 1991.302178] [] (vm_mmap_pgoff) from [] (SyS_mmap_pgoff+0x90/0xc0) [ 1991.309977] [] (SyS_mmap_pgoff) from [] (ret_fast_syscall+0x0/0x28) Signed-off-by: Shuah Khan Suggested-by: Hans Verkuil Acked-by: Hans Verkuil --- drivers/media/platform/exynos-gsc/gsc-m2m.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c b/drivers/media/platform/exynos-gsc/gsc-m2m.c index 2a2994e..722d7c4 100644 --- a/drivers/media/platform/exynos-gsc/gsc-m2m.c +++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c @@ -726,14 +726,9 @@ static unsigned int gsc_m2m_poll(struct file *file, static int gsc_m2m_mmap(struct file *file, struct vm_area_struct *vma) { struct gsc_ctx *ctx = fh_to_ctx(file->private_data); - struct gsc_dev *gsc = ctx->gsc_dev; int ret; - if (mutex_lock_interruptible(&gsc->lock)) - return -ERESTARTSYS; - ret = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma); - mutex_unlock(&gsc->lock); return ret; }