1. 14 11月, 2014 1 次提交
  2. 05 6月, 2014 1 次提交
  3. 10 7月, 2013 1 次提交
  4. 12 12月, 2012 7 次提交
    • L
      fsnotify: change locking order · 6960b0d9
      Lino Sanfilippo 提交于
      On Mon, Aug 01, 2011 at 04:38:22PM -0400, Eric Paris wrote:
      >
      > I finally built and tested a v3.0 kernel with these patches (I know I'm
      > SOOOOOO far behind).  Not what I hoped for:
      >
      > > [  150.937798] VFS: Busy inodes after unmount of tmpfs. Self-destruct in 5 seconds.  Have a nice day...
      > > [  150.945290] BUG: unable to handle kernel NULL pointer dereference at 0000000000000070
      > > [  150.946012] IP: [<ffffffff810ffd58>] shmem_free_inode+0x18/0x50
      > > [  150.946012] PGD 2bf9e067 PUD 2bf9f067 PMD 0
      > > [  150.946012] Oops: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC
      > > [  150.946012] CPU 0
      > > [  150.946012] Modules linked in: nfs lockd fscache auth_rpcgss nfs_acl sunrpc ip6t_REJECT nf_conntrack_ipv6 nf_defrag_ipv6 ip6table_filter ip6_tables ext4 jbd2 crc16 joydev ata_piix i2c_piix4 pcspkr uinput ipv6 autofs4 usbhid [last unloaded: scsi_wait_scan]
      > > [  150.946012]
      > > [  150.946012] Pid: 2764, comm: syscall_thrash Not tainted 3.0.0+ #1 Red Hat KVM
      > > [  150.946012] RIP: 0010:[<ffffffff810ffd58>]  [<ffffffff810ffd58>] shmem_free_inode+0x18/0x50
      > > [  150.946012] RSP: 0018:ffff88002c2e5df8  EFLAGS: 00010282
      > > [  150.946012] RAX: 000000004e370d9f RBX: 0000000000000000 RCX: ffff88003a029438
      > > [  150.946012] RDX: 0000000033630a5f RSI: 0000000000000000 RDI: ffff88003491c240
      > > [  150.946012] RBP: ffff88002c2e5e08 R08: 0000000000000000 R09: 0000000000000000
      > > [  150.946012] R10: 0000000000000000 R11: 0000000000000000 R12: ffff88003a029428
      > > [  150.946012] R13: ffff88003a029428 R14: ffff88003a029428 R15: ffff88003499a610
      > > [  150.946012] FS:  00007f5a05420700(0000) GS:ffff88003f600000(0000) knlGS:0000000000000000
      > > [  150.946012] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
      > > [  150.946012] CR2: 0000000000000070 CR3: 000000002a662000 CR4: 00000000000006f0
      > > [  150.946012] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      > > [  150.946012] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
      > > [  150.946012] Process syscall_thrash (pid: 2764, threadinfo ffff88002c2e4000, task ffff88002bfbc760)
      > > [  150.946012] Stack:
      > > [  150.946012]  ffff88003a029438 ffff88003a029428 ffff88002c2e5e38 ffffffff81102f76
      > > [  150.946012]  ffff88003a029438 ffff88003a029598 ffffffff8160f9c0 ffff88002c221250
      > > [  150.946012]  ffff88002c2e5e68 ffffffff8115e9be ffff88002c2e5e68 ffff88003a029438
      > > [  150.946012] Call Trace:
      > > [  150.946012]  [<ffffffff81102f76>] shmem_evict_inode+0x76/0x130
      > > [  150.946012]  [<ffffffff8115e9be>] evict+0x7e/0x170
      > > [  150.946012]  [<ffffffff8115ee40>] iput_final+0xd0/0x190
      > > [  150.946012]  [<ffffffff8115ef33>] iput+0x33/0x40
      > > [  150.946012]  [<ffffffff81180205>] fsnotify_destroy_mark_locked+0x145/0x160
      > > [  150.946012]  [<ffffffff81180316>] fsnotify_destroy_mark+0x36/0x50
      > > [  150.946012]  [<ffffffff81181937>] sys_inotify_rm_watch+0x77/0xd0
      > > [  150.946012]  [<ffffffff815aca52>] system_call_fastpath+0x16/0x1b
      > > [  150.946012] Code: 67 4a 00 b8 e4 ff ff ff eb aa 66 0f 1f 84 00 00 00 00 00 55 48 89 e5 48 83 ec 10 48 89 1c 24 4c 89 64 24 08 48 8b 9f 40 05 00 00
      > > [  150.946012]  83 7b 70 00 74 1c 4c 8d a3 80 00 00 00 4c 89 e7 e8 d2 5d 4a
      > > [  150.946012] RIP  [<ffffffff810ffd58>] shmem_free_inode+0x18/0x50
      > > [  150.946012]  RSP <ffff88002c2e5df8>
      > > [  150.946012] CR2: 0000000000000070
      >
      > Looks at aweful lot like the problem from:
      > http://www.spinics.net/lists/linux-fsdevel/msg46101.html
      >
      
      I tried to reproduce this bug with your test program, but without success.
      However, if I understand correctly, this occurs since we dont hold any locks when
      we call iput() in mark_destroy(), right?
      With the patches you tested, iput() is also not called within any lock, since the
      groups mark_mutex is released temporarily before iput() is called.  This is, since
      the original codes behaviour is similar.
      However since we now have a mutex as the biggest lock, we can do what you
      suggested (http://www.spinics.net/lists/linux-fsdevel/msg46107.html) and
      call iput() with the mutex held to avoid the race.
      The patch below implements this. It uses nested locking to avoid deadlock in case
      we do the final iput() on an inode which still holds marks and thus would take
      the mutex again when calling fsnotify_inode_delete() in destroy_inode().
      Signed-off-by: NLino Sanfilippo <LinoSanfilippo@gmx.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      6960b0d9
    • L
      fsnotify: dont put marks on temporary list when clearing marks by group · 64c20d2a
      Lino Sanfilippo 提交于
      In clear_marks_by_group_flags() the mark list of a group is iterated and the
      marks are put on a temporary list.
      Since we introduced fsnotify_destroy_mark_locked() we dont need the temp list
      any more and are able to remove the marks while the mark list is iterated and
      the mark list mutex is held.
      Signed-off-by: NLino Sanfilippo <LinoSanfilippo@gmx.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      64c20d2a
    • L
      fsnotify: introduce locked versions of fsnotify_add_mark() and fsnotify_remove_mark() · d5a335b8
      Lino Sanfilippo 提交于
      This patch introduces fsnotify_add_mark_locked() and fsnotify_remove_mark_locked()
      which are essentially the same as fsnotify_add_mark() and fsnotify_remove_mark() but
      assume that the caller has already taken the groups mark mutex.
      Signed-off-by: NLino Sanfilippo <LinoSanfilippo@gmx.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      d5a335b8
    • L
      fsnotify: pass group to fsnotify_destroy_mark() · e2a29943
      Lino Sanfilippo 提交于
      In fsnotify_destroy_mark() dont get the group from the passed mark anymore,
      but pass the group itself as an additional parameter to the function.
      Signed-off-by: NLino Sanfilippo <LinoSanfilippo@gmx.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      e2a29943
    • L
      fsnotify: use a mutex instead of a spinlock to protect a groups mark list · 986ab098
      Lino Sanfilippo 提交于
      Replaces the groups mark_lock spinlock with a mutex. Using a mutex instead
      of a spinlock results in more flexibility (i.e it allows to sleep while the
      lock is held).
      Signed-off-by: NLino Sanfilippo <LinoSanfilippo@gmx.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      986ab098
    • L
      fsnotify: take groups mark_lock before mark lock · 104d06f0
      Lino Sanfilippo 提交于
      Race-free addition and removal of a mark to a groups mark list would be easier
      if we could lock the mark list of group before we lock the specific mark.
      This patch changes the order used to add/remove marks to/from mark lists from
      
      1. mark->lock
      2. group->mark_lock
      3. inode->i_lock
      
      to
      
      1. group->mark_lock
      2. mark->lock
      3. inode->i_lock
      Signed-off-by: NLino Sanfilippo <LinoSanfilippo@gmx.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      104d06f0
    • L
      fsnotify: use reference counting for groups · 23e964c2
      Lino Sanfilippo 提交于
      Get a group ref for each mark that is added to the groups list and release that
      ref when the mark is freed in fsnotify_put_mark().
      We also use get a group reference for duplicated marks and for private event
      data.
      Now we dont free a group any more when the number of marks becomes 0 but when
      the groups ref count does. Since this will only happen when all marks are removed
      from a groups mark list, we dont have to set the groups number of marks to 1 at
      group creation.
      
      Beside clearing all marks in fsnotify_destroy_group() we do also flush the
      groups event queue. This is since events may hold references to groups (due to
      private event data) and we have to put those references first before we get a
      chance to put the final ref, which will result in a call to
      fsnotify_final_destroy_group().
      Signed-off-by: NLino Sanfilippo <LinoSanfilippo@gmx.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      23e964c2
  5. 15 1月, 2012 1 次提交
  6. 27 7月, 2011 1 次提交
  7. 31 3月, 2011 1 次提交
  8. 25 3月, 2011 1 次提交
  9. 28 7月, 2010 21 次提交
  10. 30 3月, 2010 1 次提交
    • T
      include cleanup: Update gfp.h and slab.h includes to prepare for breaking... · 5a0e3ad6
      Tejun Heo 提交于
      include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
      
      percpu.h is included by sched.h and module.h and thus ends up being
      included when building most .c files.  percpu.h includes slab.h which
      in turn includes gfp.h making everything defined by the two files
      universally available and complicating inclusion dependencies.
      
      percpu.h -> slab.h dependency is about to be removed.  Prepare for
      this change by updating users of gfp and slab facilities include those
      headers directly instead of assuming availability.  As this conversion
      needs to touch large number of source files, the following script is
      used as the basis of conversion.
      
        http://userweb.kernel.org/~tj/misc/slabh-sweep.py
      
      The script does the followings.
      
      * Scan files for gfp and slab usages and update includes such that
        only the necessary includes are there.  ie. if only gfp is used,
        gfp.h, if slab is used, slab.h.
      
      * When the script inserts a new include, it looks at the include
        blocks and try to put the new include such that its order conforms
        to its surrounding.  It's put in the include block which contains
        core kernel includes, in the same order that the rest are ordered -
        alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
        doesn't seem to be any matching order.
      
      * If the script can't find a place to put a new include (mostly
        because the file doesn't have fitting include block), it prints out
        an error message indicating which .h file needs to be added to the
        file.
      
      The conversion was done in the following steps.
      
      1. The initial automatic conversion of all .c files updated slightly
         over 4000 files, deleting around 700 includes and adding ~480 gfp.h
         and ~3000 slab.h inclusions.  The script emitted errors for ~400
         files.
      
      2. Each error was manually checked.  Some didn't need the inclusion,
         some needed manual addition while adding it to implementation .h or
         embedding .c file was more appropriate for others.  This step added
         inclusions to around 150 files.
      
      3. The script was run again and the output was compared to the edits
         from #2 to make sure no file was left behind.
      
      4. Several build tests were done and a couple of problems were fixed.
         e.g. lib/decompress_*.c used malloc/free() wrappers around slab
         APIs requiring slab.h to be added manually.
      
      5. The script was run on all .h files but without automatically
         editing them as sprinkling gfp.h and slab.h inclusions around .h
         files could easily lead to inclusion dependency hell.  Most gfp.h
         inclusion directives were ignored as stuff from gfp.h was usually
         wildly available and often used in preprocessor macros.  Each
         slab.h inclusion directive was examined and added manually as
         necessary.
      
      6. percpu.h was updated not to include slab.h.
      
      7. Build test were done on the following configurations and failures
         were fixed.  CONFIG_GCOV_KERNEL was turned off for all tests (as my
         distributed build env didn't work with gcov compiles) and a few
         more options had to be turned off depending on archs to make things
         build (like ipr on powerpc/64 which failed due to missing writeq).
      
         * x86 and x86_64 UP and SMP allmodconfig and a custom test config.
         * powerpc and powerpc64 SMP allmodconfig
         * sparc and sparc64 SMP allmodconfig
         * ia64 SMP allmodconfig
         * s390 SMP allmodconfig
         * alpha SMP allmodconfig
         * um on x86_64 SMP allmodconfig
      
      8. percpu.h modifications were reverted so that it could be applied as
         a separate patch and serve as bisection point.
      
      Given the fact that I had only a couple of failures from tests on step
      6, I'm fairly confident about the coverage of this conversion patch.
      If there is a breakage, it's likely to be something in one of the arch
      headers which should be easily discoverable easily on most builds of
      the specific arch.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Guess-its-ok-by: NChristoph Lameter <cl@linux-foundation.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
      5a0e3ad6
  11. 19 10月, 2009 1 次提交
    • E
      fsnotify: do not set group for a mark before it is on the i_list · 9f0d793b
      Eric Paris 提交于
      fsnotify_add_mark is supposed to add a mark to the g_list and i_list and to
      set the group and inode for the mark.  fsnotify_destroy_mark_by_entry uses
      the fact that ->group != NULL to know if this group should be destroyed or
      if it's already been done.
      
      But fsnotify_add_mark sets the group and inode before it actually adds the
      mark to the i_list and g_list.  This can result in a race in inotify, it
      requires 3 threads.
      
      sys_inotify_add_watch("file")	sys_inotify_add_watch("file")	sys_inotify_rm_watch([a])
      inotify_update_watch()
      inotify_new_watch()
      inotify_add_to_idr()
         ^--- returns wd = [a]
      				inotfiy_update_watch()
      				inotify_new_watch()
      				inotify_add_to_idr()
      				fsnotify_add_mark()
      				   ^--- returns wd = [b]
      				returns to userspace;
      								inotify_idr_find([a])
      								   ^--- gives us the pointer from task 1
      fsnotify_add_mark()
         ^--- this is going to set the mark->group and mark->inode fields, but will
      return -EEXIST because of the race with [b].
      								fsnotify_destroy_mark()
      								   ^--- since ->group != NULL we call back
      									into inotify_freeing_mark() which calls
      								inotify_remove_from_idr([a])
      
      since fsnotify_add_mark() failed we call:
      inotify_remove_from_idr([a])     <------WHOOPS it's not in the idr, this could
      					have been any entry added later!
      
      The fix is to make sure we don't set mark->group until we are sure the mark is
      on the inode and fsnotify_add_mark will return success.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      9f0d793b
  12. 12 6月, 2009 3 次提交
    • E
      fsnotify: allow groups to set freeing_mark to null · a092ee20
      Eric Paris 提交于
      Most fsnotify listeners (all but inotify) do not care about marks being
      freed.  Allow groups to set freeing_mark to null and do not call any
      function if it is set that way.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      a092ee20
    • E
      fsnotify: handle filesystem unmounts with fsnotify marks · 164bc619
      Eric Paris 提交于
      When an fs is unmounted with an fsnotify mark entry attached to one of its
      inodes we need to destroy that mark entry and we also (like inotify) send
      an unmount event.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      Acked-by: NAl Viro <viro@zeniv.linux.org.uk>
      Cc: Christoph Hellwig <hch@lst.de>
      164bc619
    • E
      fsnotify: fsnotify marks on inodes pin them in core · 1ef5f13c
      Eric Paris 提交于
      This patch pins any inodes with an fsnotify mark in core.  The idea is that
      as soon as the mark is removed from the inode->fsnotify_mark_entries list
      the inode will be iput.  In reality is doesn't quite work exactly this way.
      The igrab will happen when the mark is added to an inode, but the iput will
      happen when the inode pointer is NULL'd inside the mark.
      
      It's possible that 2 racing things will try to remove the mark from
      different directions.  One may try to remove the mark because of an
      explicit request and one might try to remove it because the inode was
      deleted.  It's possible that the removal because of inode deletion will
      remove the mark from the inode's list, but the removal by explicit request
      will actually set entry->inode == NULL; and call the iput.  This is safe.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      Acked-by: NAl Viro <viro@zeniv.linux.org.uk>
      Cc: Christoph Hellwig <hch@lst.de>
      1ef5f13c