From patchwork Mon Oct 30 21:04:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 10033253 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 C659E6039A for ; Mon, 30 Oct 2017 21:05:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B72C728965 for ; Mon, 30 Oct 2017 21:05:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA62528968; Mon, 30 Oct 2017 21:05:36 +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 2136228965 for ; Mon, 30 Oct 2017 21:05:36 +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: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:In-Reply-To: References:List-Owner; bh=teB9vLuISqo9P4gi/hUuGEPrdsJq9Sa2jYec4gh7fXs=; b=d1g /FIGs012nA3f9+hWP2ZT1kvh0y2/psv6SpkOVnqRzD5Tqoj5yhXfdx5rj2Za2qPw2zihhUnUxF/qT iZmu1jimp6FG+FN2AqNH7eI0smzULGsBs4iggMeLdb0vgavtEO+I8aWA+SHhyHp5s0UYOt7cfzHUP VxRqqkR6/B7trKcAYpUf7UfE8ERTnbjhaUX3fS3+sKvvyJZ7mrc7rTDl3jELiLBhOHevKbVEHKgV7 LQ4eWQBr5mASb0LTP7AAP8OSyhVmVv91skl6MobTM9/X+Ym0cbrBvTZT6HkAD5QPE+0Exg1ZoL9I1 KgZnv0POCBC/tawBI+tZbVJgKsq2PXw==; 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 1e9HFT-0000f0-Ur; Mon, 30 Oct 2017 21:05:31 +0000 Received: from osg.samsung.com ([64.30.133.232]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e9HFM-0007vI-PV for linux-arm-kernel@lists.infradead.org; Mon, 30 Oct 2017 21:05:27 +0000 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id F25AD1F225; Mon, 30 Oct 2017 14:05:02 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com Received: from osg.samsung.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WTFarA6sFOC3; Mon, 30 Oct 2017 14:05:01 -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 19F861F21A; Mon, 30 Oct 2017 14:05:01 -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 v2] media: s5p-mfc: fix lockdep warning Date: Mon, 30 Oct 2017 15:04:57 -0600 Message-Id: <20171030210457.17583-1-shuahkh@osg.samsung.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171030_140524_953439_83ABD9FD X-CRM114-Status: GOOD ( 18.33 ) 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. [ 2106.181412] ====================================================== [ 2106.187563] WARNING: possible circular locking dependency detected [ 2106.193718] 4.14.0-rc2-00002-gfab205f-dirty #4 Not tainted [ 2106.199175] ------------------------------------------------------ [ 2106.205328] qtdemux0:sink/2614 is trying to acquire lock: [ 2106.210701] (&dev->mfc_mutex){+.+.}, at: [] s5p_mfc_mmap+0x28/0xd4 [s5p_mfc] [ 2106.218672] [ 2106.218672] but task is already holding lock: [ 2106.224477] (&mm->mmap_sem){++++}, at: [] vm_mmap_pgoff+0x44/0xb8 [ 2106.231497] [ 2106.231497] which lock already depends on the new lock. [ 2106.231497] [ 2106.239642] [ 2106.239642] the existing dependency chain (in reverse order) is: [ 2106.247095] [ 2106.247095] -> #1 (&mm->mmap_sem){++++}: [ 2106.252473] __might_fault+0x80/0xb0 [ 2106.256567] video_usercopy+0x1cc/0x510 [videodev] [ 2106.261845] v4l2_ioctl+0xa4/0xdc [videodev] [ 2106.266596] do_vfs_ioctl+0xa0/0xa18 [ 2106.270667] SyS_ioctl+0x34/0x5c [ 2106.274395] ret_fast_syscall+0x0/0x28 [ 2106.278637] [ 2106.278637] -> #0 (&dev->mfc_mutex){+.+.}: [ 2106.284186] lock_acquire+0x6c/0x88 [ 2106.288173] __mutex_lock+0x68/0xa34 [ 2106.292244] mutex_lock_interruptible_nested+0x1c/0x24 [ 2106.297893] s5p_mfc_mmap+0x28/0xd4 [s5p_mfc] [ 2106.302747] v4l2_mmap+0x54/0x88 [videodev] [ 2106.307409] mmap_region+0x3a8/0x638 [ 2106.311480] do_mmap+0x330/0x3a4 [ 2106.315207] vm_mmap_pgoff+0x90/0xb8 [ 2106.319279] SyS_mmap_pgoff+0x90/0xc0 [ 2106.323439] ret_fast_syscall+0x0/0x28 [ 2106.327683] [ 2106.327683] other info that might help us debug this: [ 2106.327683] [ 2106.335656] Possible unsafe locking scenario: [ 2106.335656] [ 2106.341548] CPU0 CPU1 [ 2106.346053] ---- ---- [ 2106.350559] lock(&mm->mmap_sem); [ 2106.353939] lock(&dev->mfc_mutex); [ 2106.353939] lock(&dev->mfc_mutex); [ 2106.365897] lock(&dev->mfc_mutex); [ 2106.369450] [ 2106.369450] *** DEADLOCK *** [ 2106.369450] [ 2106.375344] 1 lock held by qtdemux0:sink/2614: [ 2106.379762] #0: (&mm->mmap_sem){++++}, at: [] vm_mmap_pgoff+0x44/0xb8 [ 2106.387214] [ 2106.387214] stack backtrace: [ 2106.391550] CPU: 7 PID: 2614 Comm: qtdemux0:sink Not tainted 4.14.0-rc2-00002-gfab205f-dirty #4 [ 2106.400213] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree) [ 2106.406285] [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [ 2106.413995] [] (show_stack) from [] (dump_stack+0x98/0xc4) [ 2106.421187] [] (dump_stack) from [] (print_circular_bug+0x254/0x410) [ 2106.429245] [] (print_circular_bug) from [] (check_prev_add+0x468/0x938) [ 2106.437651] [] (check_prev_add) from [] (__lock_acquire+0x1314/0x14fc) [ 2106.445883] [] (__lock_acquire) from [] (lock_acquire+0x6c/0x88) [ 2106.453596] [] (lock_acquire) from [] (__mutex_lock+0x68/0xa34) [ 2106.461221] [] (__mutex_lock) from [] (mutex_lock_interruptible_nested+0x1c/0x24) [ 2106.470425] [] (mutex_lock_interruptible_nested) from [] (s5p_mfc_mmap+0x28/0xd4 [s5p_mfc]) [ 2106.480494] [] (s5p_mfc_mmap [s5p_mfc]) from [] (v4l2_mmap+0x54/0x88 [videodev]) [ 2106.489575] [] (v4l2_mmap [videodev]) from [] (mmap_region+0x3a8/0x638) [ 2106.497875] [] (mmap_region) from [] (do_mmap+0x330/0x3a4) [ 2106.505068] [] (do_mmap) from [] (vm_mmap_pgoff+0x90/0xb8) [ 2106.512260] [] (vm_mmap_pgoff) from [] (SyS_mmap_pgoff+0x90/0xc0) [ 2106.520059] [] (SyS_mmap_pgoff) from [] (ret_fast_syscall+0x0/0x28) Signed-off-by: Shuah Khan Suggested-by: Hans Verkuil Acked-by: Marek Szyprowski Acked-by: Hans Verkuil --- Changes since v1: - Fixed unused warning. Added Han's Ack drivers/media/platform/s5p-mfc/s5p_mfc.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c index 4c253fb..3611016 100644 --- a/drivers/media/platform/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c @@ -1043,12 +1043,9 @@ static unsigned int s5p_mfc_poll(struct file *file, static int s5p_mfc_mmap(struct file *file, struct vm_area_struct *vma) { struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data); - struct s5p_mfc_dev *dev = ctx->dev; unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; int ret; - if (mutex_lock_interruptible(&dev->mfc_mutex)) - return -ERESTARTSYS; if (offset < DST_QUEUE_OFF_BASE) { mfc_debug(2, "mmaping source\n"); ret = vb2_mmap(&ctx->vq_src, vma); @@ -1057,7 +1054,6 @@ static int s5p_mfc_mmap(struct file *file, struct vm_area_struct *vma) vma->vm_pgoff -= (DST_QUEUE_OFF_BASE >> PAGE_SHIFT); ret = vb2_mmap(&ctx->vq_dst, vma); } - mutex_unlock(&dev->mfc_mutex); return ret; }