From: Inki Dae Subject: RE: [RFC] deadlock in "drm/exynos: fix wrong pointer access at vm close" Date: Mon, 23 Sep 2013 16:49:30 +0900 Message-ID: <055301ceb831$6f8d42c0$4ea7c840$%dae@samsung.com> References: <20130922212911.GU13318@ZenIV.linux.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by gabe.freedesktop.org (Postfix) with ESMTP id 15288E5F5C for ; Mon, 23 Sep 2013 00:49:32 -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 <0MTK008JIJ040KG0@mailout3.samsung.com> for dri-devel@lists.freedesktop.org; Mon, 23 Sep 2013 16:49:30 +0900 (KST) In-reply-to: <20130922212911.GU13318@ZenIV.linux.org.uk> Content-language: ko List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org Errors-To: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org To: 'Al Viro' , 'YoungJun Cho' Cc: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org Hi, > -----Original Message----- > From: Al Viro [mailto:viro@ftp.linux.org.uk] On Behalf Of Al Viro > Sent: Monday, September 23, 2013 6:29 AM > To: YoungJun Cho > Cc: dri-devel@lists.freedesktop.org; Inki Dae > Subject: [RFC] deadlock in "drm/exynos: fix wrong pointer access at vm > close" > > You have drm_dev->struct_mutex grabbed before ->mmap_sem in > exynos_drm_gem_mmap_ioctl() and after - in exynos_drm_gem_fault() > (since ->fault() is always called with ->mmap_sem held). Looks like > a garden-variety AB-BA deadlock... > Right, if mmap system call is requested by another process between ->f_op pointer changing and restoring, the deadlock can be incurred. For this, I think we can resolve this issue like below, At exynos_drm_gem_mmap_ioctl() down_write(&mm->mmap_sem); mutex_lock(&dev->struct_mutex); ... addr = security_mmap_file(...); if (!addr) { unsigned long populate; addr = do_mmap_pgoff(...); if (populate) mm_populater(...); } ... mutex_unlock(&dev->struct_mutex); up_write(&mm->mmap_sem); The point above is to call down_write(&mm->mmap_sem) before do_mmap_pgoff, and then to call up_write(...) after do_mmap_pg_off so that when another process called mmap system call, the process can wait for up_write(...) until the ->f_op pointer is restored. I will post this patch soon. other opinions? Thanks, Inki Dae > Incidentally, what should happen if another process shares the > same opened file (e.g. inherited over fork()) and does mmap() just > as we have ->f_op switched?