Re: drm_vm.c:drm_mmap: possible circular locking dependency detected (was: Re: Linux 2.6.33-rc2 - Merry Christmas ...)

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

On Mon, 28 Dec 2009, KOSAKI Motohiro wrote:

Actually, this painful dependency may technically be a bug in drm, but at 
the same time, it's really filldir() that makes it _very_ hard for certain 
locking scenarios because it has that callback to the VFS layer that takes 
the mmap_sem, and sysfs itself wants the sysfs_mutex in paths where it is 
not at all unreasonable to hold the mmap_sem.

We've seen it several times (yes, mostly with drm, but it's been seen with 
others too), and it's very annoying. It can be fixed by having very 
careful readdir implementations, but I really would blame sysfs in 
particular for having a very annoying lock reversal issue when used 
reasonably.

So the optimal situation would be for sysfs to not have that annoying lock 
dependency, and it would really have to be sysfs_readdir() that drops the 
sysfs_mutex around the filldir call (and that obviously implies having to 
re-validate and be really careful).

Added Eric and Greg to the cc, in case the sysfs people want to solve it.

The other alternative would be to fix this on a VFS layer by changing how 
'readdir/filldir' interacts, and instead make it fill in a kernel buffer - 
avoiding the mmap_sem issue entirely. And than later (in readdir) that 
kernel buffer could be copied to user space without holding any other 
locks.

I like the VFS approach because I think we could possibly use that as a 
first approach to eventually try to think about caching readdir() results 
at a VFS level - readdir() is currently the _only_ main filesystem 
callback that always calls into the low-level filesystem, and always takes 
a lot of locks. I'm adding Al to the Cc for that - he knows about this 
issue from me previously thinking aloud along these lines.

And yes, one option would be to just fix drm - by avoiding calling any 
sysfs functions while holding the mmap_lock (either in the mmap callback 
or the page fault paths). However, as mentioned, I really do think that 
the blame can be laid on sysfs for trying to be a nice generic interface, 
but having a damn inconvenient locking model.

			Linus
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Linux 2.6.33-rc2 - Merry Christmas ..., Linus Torvalds, (Thu Dec 24, 3:00 pm)
-tip: origin tree boot crash, Ingo Molnar, (Fri Dec 25, 3:27 am)
Re: Linux 2.6.33-rc2 - Blank screen for Intel KMS, Miguel Calleja, (Fri Dec 25, 6:10 am)
Re: -tip: origin tree boot crash, Dmitry Torokhov, (Fri Dec 25, 12:49 pm)
Re: Linux 2.6.33-rc2 - Merry Christmas ..., Borislav Petkov, (Fri Dec 25, 1:00 pm)
Re: Linux 2.6.33-rc2 - Merry Christmas ..., Borislav Petkov, (Fri Dec 25, 2:50 pm)
Re: Linux 2.6.33-rc2 - Merry Christmas ..., Jesse Barnes, (Fri Dec 25, 11:00 pm)
Re: Linux 2.6.33-rc2 - Merry Christmas ..., Borislav Petkov, (Sat Dec 26, 1:02 am)
Re: -tip: origin tree boot crash, Len Brown, (Sat Dec 26, 1:17 pm)
Re: -tip: origin tree boot crash, Len Brown, (Sat Dec 26, 1:19 pm)
Re: -tip: origin tree boot crash, Len Brown, (Sat Dec 26, 9:20 pm)
Re: -tip: origin tree boot crash, Ingo Molnar, (Mon Dec 28, 2:44 am)
Re: -tip: origin tree boot crash, Ingo Molnar, (Mon Dec 28, 5:01 am)
Re: -tip: origin tree boot crash, Paul Rolland, (Mon Dec 28, 8:02 am)
Re: -tip: origin tree boot crash, Paul Rolland, (Mon Dec 28, 9:15 am)
Re: -tip: origin tree boot crash, Paul Rolland, (Mon Dec 28, 9:53 am)
Re: -tip: origin tree boot crash, Dmitry Torokhov, (Mon Dec 28, 1:17 pm)
Re: Linux 2.6.33-rc2 - Blank screen for Intel KMS, Miguel Calleja, (Tue Dec 29, 2:50 am)
Re: Linux 2.6.33-rc2 - Blank screen for Intel KMS, Rafael J. Wysocki, (Tue Dec 29, 7:01 am)
Re: -tip: origin tree boot crash, Len Brown, (Tue Dec 29, 11:14 pm)
Re: -tip: origin tree boot crash, Paul Rolland, (Wed Dec 30, 12:13 am)
Re: drm_vm.c:drm_mmap: possible circular locking dependenc ..., Linus Torvalds, (Wed Dec 30, 2:10 pm)
Re: drm_vm.c:drm_mmap: possible circular locking dependenc ..., Eric W. Biederman, (Wed Dec 30, 2:34 pm)
Re: drm_vm.c:drm_mmap: possible circular locking dependenc ..., Eric W. Biederman, (Thu Dec 31, 1:40 am)
Re: drm_vm.c:drm_mmap: possible circular locking dependenc ..., Eric W. Biederman, (Thu Dec 31, 1:40 am)
Re: drm_vm.c:drm_mmap: possible circular locking dependenc ..., Eric W. Biederman, (Sat Jan 2, 10:38 pm)
Re: drm_vm.c:drm_mmap: possible circular locking dependenc ..., Eric W. Biederman, (Mon Jan 4, 12:43 pm)
Re: [PATCH] sysfs: Add lockdep annotations for the sysfs a ..., Eric W. Biederman, (Sun Jan 17, 10:18 am)
Re: [PATCH] sysfs: Add lockdep annotations for the sysfs a ..., Dominik Brodowski, (Sun Jan 17, 11:03 am)