• Frederic Weisbecker's avatar
    reiserfs: fix unwanted reiserfs lock recursion · 9d8117e7
    Frederic Weisbecker authored
    Prevent from recursively locking the reiserfs lock in reiserfs_unpack()
    because we may call journal_begin() that requires the lock to be taken
    only once, otherwise it won't be able to release the lock while taking
    other mutexes, ending up in inverted dependencies between the journal
    mutex and the reiserfs lock for example.
    
    This fixes:
    
      =======================================================
      [ INFO: possible circular locking dependency detected ]
      2.6.35.4.4a #3
      -------------------------------------------------------
      lilo/1620 is trying to acquire lock:
       (&journal->j_mutex){+.+...}, at: [<d0325bff>] do_journal_begin_r+0x7f/0x340 [reiserfs]
    
      but task is already holding lock:
       (&REISERFS_SB(s)->lock){+.+.+.}, at: [<d032a278>] reiserfs_write_lock+0x28/0x40 [reiserfs]
    
      which lock already depends on the new lock.
    
      the existing dependency chain (in reverse order) is:
    
      -> #1 (&REISERFS_SB(s)->lock){+.+.+.}:
             [<c10562b7>] lock_acquire+0x67/0x80
             [<c12facad>] __mutex_lock_common+0x4d/0x410
             [<c12fb0c8>] mutex_lock_nested+0x18/0x20
             [<d032a278>] reiserfs_write_lock+0x28/0x40 [reiserfs]
             [<d0325c06>] do_journal_begin_r+0x86/0x340 [reiserfs]
             [<d0325f77>] journal_begin+0x77/0x140 [reiserfs]
             [<d0315be4>] reiserfs_remount+0x224/0x530 [reiserfs]
             [<c10b6a20>] do_remount_sb+0x60/0x110
             [<c10cee25>] do_mount+0x625/0x790
             [<c10cf014>] sys_mount+0x84/0xb0
             [<c12fca3d>] syscall_call+0x7/0xb
    
      -> #0 (&journal->j_mutex){+.+...}:
             [<c10560f6>] __lock_acquire+0x1026/0x1180
             [<c10562b7>] lock_acquire+0x67/0x80
             [<c12facad>] __mutex_lock_common+0x4d/0x410
             [<c12fb0c8>] mutex_lock_nested+0x18/0x20
             [<d0325bff>] do_journal_begin_r+0x7f/0x340 [reiserfs]
             [<d0325f77>] journal_begin+0x77/0x140 [reiserfs]
             [<d0326271>] reiserfs_persistent_transaction+0x41/0x90 [reiserfs]
             [<d030d06c>] reiserfs_get_block+0x22c/0x1530 [reiserfs]
             [<c10db9db>] __block_prepare_write+0x1bb/0x3a0
             [<c10dbbe6>] block_prepare_write+0x26/0x40
             [<d030b738>] reiserfs_prepare_write+0x88/0x170 [reiserfs]
             [<d03294d6>] reiserfs_unpack+0xe6/0x120 [reiserfs]
             [<d0329782>] reiserfs_ioctl+0x272/0x320 [reiserfs]
             [<c10c3188>] vfs_ioctl+0x28/0xa0
             [<c10c3bbd>] do_vfs_ioctl+0x32d/0x5c0
             [<c10c3eb3>] sys_ioctl+0x63/0x70
             [<c12fca3d>] syscall_call+0x7/0xb
    
      other info that might help us debug this:
    
      2 locks held by lilo/1620:
       #0:  (&sb->s_type->i_mutex_key#8){+.+.+.}, at: [<d032945a>] reiserfs_unpack+0x6a/0x120 [reiserfs]
       #1:  (&REISERFS_SB(s)->lock){+.+.+.}, at: [<d032a278>] reiserfs_write_lock+0x28/0x40 [reiserfs]
    
      stack backtrace:
      Pid: 1620, comm: lilo Not tainted 2.6.35.4.4a #3
      Call Trace:
       [<c10560f6>] __lock_acquire+0x1026/0x1180
       [<c10562b7>] lock_acquire+0x67/0x80
       [<c12facad>] __mutex_lock_common+0x4d/0x410
       [<c12fb0c8>] mutex_lock_nested+0x18/0x20
       [<d0325bff>] do_journal_begin_r+0x7f/0x340 [reiserfs]
       [<d0325f77>] journal_begin+0x77/0x140 [reiserfs]
       [<d0326271>] reiserfs_persistent_transaction+0x41/0x90 [reiserfs]
       [<d030d06c>] reiserfs_get_block+0x22c/0x1530 [reiserfs]
       [<c10db9db>] __block_prepare_write+0x1bb/0x3a0
       [<c10dbbe6>] block_prepare_write+0x26/0x40
       [<d030b738>] reiserfs_prepare_write+0x88/0x170 [reiserfs]
       [<d03294d6>] reiserfs_unpack+0xe6/0x120 [reiserfs]
       [<d0329782>] reiserfs_ioctl+0x272/0x320 [reiserfs]
       [<c10c3188>] vfs_ioctl+0x28/0xa0
       [<c10c3bbd>] do_vfs_ioctl+0x32d/0x5c0
       [<c10c3eb3>] sys_ioctl+0x63/0x70
       [<c12fca3d>] syscall_call+0x7/0xb
    Reported-by: default avatarJarek Poplawski <jarkao2@gmail.com>
    Tested-by: default avatarJarek Poplawski <jarkao2@gmail.com>
    Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
    Cc: Jeff Mahoney <jeffm@suse.com>
    Cc: All since 2.6.32 <stable@kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    9d8117e7
ioctl.c 5.54 KB