1. 15 10月, 2009 1 次提交
    • N
      sysfs: Allow sysfs_notify_dirent to be called from interrupt context. · 83db93f4
      Neil Brown 提交于
      sysfs_notify_dirent is a simple atomic operation that can be used to
      alert user-space that new data can be read from a sysfs attribute.
      
      Unfortunately it cannot currently be called from non-process context
      because of its use of spin_lock which is sometimes taken with
      interrupts enabled.
      
      So change all lockers of sysfs_open_dirent_lock to disable interrupts,
      thus making sysfs_notify_dirent safe to be called from non-process
      context (as drivers/md does in md_safemode_timeout).
      
      sysfs_get_open_dirent is (documented as being) only called from
      process context, so it uses spin_lock_irq.  Other places
      use spin_lock_irqsave.
      
      The usage for sysfs_notify_dirent in md_safemode_timeout was
      introduced in 2.6.28, so this patch is suitable for that and more
      recent kernels.
      Reported-by: NJoel Andres Granados <jgranado@redhat.com>
      Signed-off-by: NNeilBrown <neilb@suse.de>
      Signed-off-by: NDan Williams <dan.j.williams@intel.com>
      Cc: stable <stable@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      83db93f4
  2. 29 5月, 2009 1 次提交
  3. 17 4月, 2009 2 次提交
    • K
      sysfs: sysfs poll keep the poll rule of regular file. · 1af3557a
      KOSAKI Motohiro 提交于
      Currently, following test programs don't finished.
      
      % ruby -e '
      Thread.new { sleep }
      File.read("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies")
      '
      
      strace expose the reason.
      
      ...
      open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies", O_RDONLY|O_LARGEFILE) = 3
      ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbf9fa6b8) = -1 ENOTTY (Inappropriate ioctl for device)
      fstat64(3, {st_mode=S_IFREG|0444, st_size=4096, ...}) = 0
      _llseek(3, 0, [0], SEEK_CUR)            = 0
      select(4, [3], NULL, NULL, NULL)        = 1 (in [3])
      read(3, "1400000 1300000 1200000 1100000 1"..., 4096) = 62
      select(4, [3], NULL, NULL, NULL
      
      
      Because Ruby (the scripting language) VM assume select system-call
      against regular file don't block.  it because SUSv3 says "Regular files
      shall always poll TRUE for reading and writing".  see
      http://www.opengroup.org/onlinepubs/009695399/functions/poll.html it
      seems valid assumption.
      
      But sysfs_poll() don't keep this rule although sysfs file can read and
      write always.
      
      This patch restore proper poll behavior to sysfs.
      /sys/block/md*/md/sync_action polling application and another sysfs
      updating sensitive application still can use POLLERR and POLLPRI.
      
      Cc: Neil Brown <neilb@suse.de>
      Signed-off-by: NKOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      1af3557a
    • A
      sysfs: don't use global workqueue in sysfs_schedule_callback() · d110271e
      Alex Chiang 提交于
      A sysfs attribute using sysfs_schedule_callback() to commit suicide
      may end up calling device_unregister(), which will eventually call
      a driver's ->remove function.
      
      Drivers may call flush_scheduled_work() in their shutdown routines,
      in which case lockdep will complain with something like the following:
      
        =============================================
        [ INFO: possible recursive locking detected ]
        2.6.29-rc8-kk #1
        ---------------------------------------------
        events/4/56 is trying to acquire lock:
        (events){--..}, at: [<ffffffff80257fc0>] flush_workqueue+0x0/0xa0
      
        but task is already holding lock:
        (events){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230
      
        other info that might help us debug this:
        3 locks held by events/4/56:
        #0:  (events){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230
        #1:  (&ss->work){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230
        #2:  (pci_remove_rescan_mutex){--..}, at: [<ffffffff803c10d1>] remove_callback+0x21/0x40
      
        stack backtrace:
        Pid: 56, comm: events/4 Not tainted 2.6.29-rc8-kk #1
        Call Trace:
        [<ffffffff8026dfcd>] validate_chain+0xb7d/0x1260
        [<ffffffff8026eade>] __lock_acquire+0x42e/0xa40
        [<ffffffff8026f148>] lock_acquire+0x58/0x80
        [<ffffffff80257fc0>] ? flush_workqueue+0x0/0xa0
        [<ffffffff8025800d>] flush_workqueue+0x4d/0xa0
        [<ffffffff80257fc0>] ? flush_workqueue+0x0/0xa0
        [<ffffffff80258070>] flush_scheduled_work+0x10/0x20
        [<ffffffffa0144065>] e1000_remove+0x55/0xfe [e1000e]
        [<ffffffff8033ee30>] ? sysfs_schedule_callback_work+0x0/0x50
        [<ffffffff803bfeb2>] pci_device_remove+0x32/0x70
        [<ffffffff80441da9>] __device_release_driver+0x59/0x90
        [<ffffffff80441edb>] device_release_driver+0x2b/0x40
        [<ffffffff804419d6>] bus_remove_device+0xa6/0x120
        [<ffffffff8043e46b>] device_del+0x12b/0x190
        [<ffffffff8043e4f6>] device_unregister+0x26/0x70
        [<ffffffff803ba969>] pci_stop_dev+0x49/0x60
        [<ffffffff803baab0>] pci_remove_bus_device+0x40/0xc0
        [<ffffffff803c10d9>] remove_callback+0x29/0x40
        [<ffffffff8033ee4f>] sysfs_schedule_callback_work+0x1f/0x50
        [<ffffffff8025769a>] run_workqueue+0x15a/0x230
        [<ffffffff80257648>] ? run_workqueue+0x108/0x230
        [<ffffffff8025846f>] worker_thread+0x9f/0x100
        [<ffffffff8025bce0>] ? autoremove_wake_function+0x0/0x40
        [<ffffffff802583d0>] ? worker_thread+0x0/0x100
        [<ffffffff8025b89d>] kthread+0x4d/0x80
        [<ffffffff8020d4ba>] child_rip+0xa/0x20
        [<ffffffff8020cebc>] ? restore_args+0x0/0x30
        [<ffffffff8025b850>] ? kthread+0x0/0x80
        [<ffffffff8020d4b0>] ? child_rip+0x0/0x20
      
      Although we know that the device_unregister path will never acquire
      a lock that a driver might try to acquire in its ->remove, in general
      we should never attempt to flush a workqueue from within the same
      workqueue, and lockdep rightly complains.
      
      So as long as sysfs attributes cannot commit suicide directly and we
      are stuck with this callback mechanism, put the sysfs callbacks on
      their own workqueue instead of the global one.
      
      This has the side benefit that if a suicidal sysfs attribute kicks
      off a long chain of ->remove callbacks, we no longer induce a long
      delay on the global queue.
      
      This also fixes a missing module_put in the error path introduced
      by sysfs-only-allow-one-scheduled-removal-callback-per-kobj.patch.
      
      We never destroy the workqueue, but I'm not sure that's a
      problem.
      Reported-by: NKenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
      Tested-by: NKenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
      Signed-off-by: NAlex Chiang <achiang@hp.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      d110271e
  4. 25 3月, 2009 1 次提交
    • A
      sysfs: only allow one scheduled removal callback per kobj · 66942064
      Alex Chiang 提交于
      The only way for a sysfs attribute to remove itself (without
      deadlock) is to use the sysfs_schedule_callback() interface.
      
      Vegard Nossum discovered that a poorly written sysfs ->store
      callback can repeatedly schedule remove callbacks on the same
      device over and over, e.g.
      
      	$ while true ; do echo 1 > /sys/devices/.../remove ; done
      
      If the 'remove' attribute uses the sysfs_schedule_callback API
      and also does not protect itself from concurrent accesses, its
      callback handler will be called multiple times, and will
      eventually attempt to perform operations on a freed kobject,
      leading to many problems.
      
      Instead of requiring all callers of sysfs_schedule_callback to
      implement their own synchronization, provide the protection in
      the infrastructure.
      
      Now, sysfs_schedule_callback will only allow one scheduled
      callback per kobject. On subsequent calls with the same kobject,
      return -EAGAIN.
      
      This is a short term fix. The long term fix is to allow sysfs
      attributes to remove themselves directly, without any of this
      callback hokey pokey.
      
      [cornelia.huck@de.ibm.com: s390 ccwgroup bits]
      
      Reported-by: vegard.nossum@gmail.com
      Signed-off-by: NAlex Chiang <achiang@hp.com>
      Acked-by: NCornelia Huck <cornelia.huck@de.ibm.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      66942064
  5. 17 10月, 2008 3 次提交
  6. 27 7月, 2008 1 次提交
  7. 22 7月, 2008 1 次提交
  8. 30 4月, 2008 1 次提交
  9. 23 4月, 2008 1 次提交
  10. 20 4月, 2008 2 次提交
  11. 25 3月, 2008 1 次提交
  12. 25 1月, 2008 3 次提交
  13. 24 1月, 2008 1 次提交
  14. 29 11月, 2007 1 次提交
    • M
      sysfs: fix off-by-one error in fill_read_buffer() · 8118a859
      Miao Xie 提交于
      I found that there is a off-by-one problem in the following code.
      
      Version:	2.6.24-rc2
      File:		fs/sysfs/file.c:118-122
      Function:	fill_read_buffer
      --------------------------------------------------------------------
      	count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
      
      	sysfs_put_active_two(attr_sd);
      
      	BUG_ON(count > (ssize_t)PAGE_SIZE);
      --------------------------------------------------------------------
      
      Because according to the specification of the sysfs and the implement of
      the show methods, the show methods return the number of bytes which would
      be generated for the given input, excluding the trailing null.So if the
      return value of the show methods equals PAGE_SIZE - 1, the buffer is full
      in fact.  And if the return value equals PAGE_SIZE, the resulting string
      was already truncated,or buffer overflow occurred.
      
      This patch fixes an off-by-one error in fill_read_buffer.
      Signed-off-by: NMiao Xie <miaox@cn.fujitsu.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Acked-by: NTejun Heo <teheo@suse.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      8118a859
  15. 20 10月, 2007 1 次提交
  16. 13 10月, 2007 13 次提交
  17. 19 7月, 2007 1 次提交
    • T
      sysfs: cosmetic clean up on node creation failure paths · 967e35dc
      Tejun Heo 提交于
      Node addition failure is detected by testing return value of
      sysfs_addfm_finish() which returns the number of added and removed
      nodes.  As the function is called as the last step of addition right
      on top of error handling block, the if blocks looked like the
      following.
      
      	if (sysfs_addrm_finish(&acxt))
      		success handling, usually return;
      	/* fall through to error handling */
      
      This is the opposite of usual convention in sysfs and makes the code
      difficult to understand.  This patch inverts the test and makes those
      blocks look more like others.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Cc: Gabriel C <nix.or.die@googlemail.com>
      Cc: Miles Lane <miles.lane@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      967e35dc
  18. 12 7月, 2007 5 次提交
    • T
      sysfs: make directory dentries and inodes reclaimable · 51225039
      Tejun Heo 提交于
      This patch makes dentries and inodes for sysfs directories
      reclaimable.
      
      * sysfs_notify() is modified to walk sysfs_dirent tree instead of
        dentry tree.
      
      * sysfs_update_file() and sysfs_chmod_file() use sysfs_get_dentry() to
        grab the victim dentry.
      
      * sysfs_rename_dir() and sysfs_move_dir() grab all dentries using
        sysfs_get_dentry() on startup.
      
      * Dentries for all shadowed directories are pinned in memory to serve
        as lookup start point.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      51225039
    • T
      sysfs: restructure add/remove paths and fix inode update · fb6896da
      Tejun Heo 提交于
      The original add/remove code had the following problems.
      
      * parent's timestamps are updated on dentry instantiation.  this is
        incorrect with reclaimable files.
      
      * updating parent's timestamps isn't synchronized.
      
      * parent nlink update assumes the inode is accessible which won't be
        true once directory dentries are made reclaimable.
      
      This patch restructures add/remove paths to resolve the above
      problems.  Add/removal are done in the following steps.
      
      1. sysfs_addrm_start() : acquire locks including sysfs_mutex and other
         resources.
      
      2-a. sysfs_add_one() : add new sd.  linking the new sd into the
           children list is caller's responsibility.
      
      2-b. sysfs_remove_one() : remove a sd.  unlinking the sd from the
           children list is caller's responsibility.
      
      3. sysfs_addrm_finish() : release all resources and clean up.
      
      Steps 2-a and/or 2-b can be repeated multiple times.
      
      Parent's inode is looked up during sysfs_addrm_start().  If available
      (always at the moment), it's pinned and nlink is updated as sd's are
      added and removed.  Timestamps are updated during finish if any sd has
      been added or removed.  If parent's inode is not available during
      start, sysfs_mutex ensures that parent inode is not created till
      add/remove is complete.
      
      All the complexity is contained inside the helper functions.
      Especially, dentry/inode handling is properly hidden from the rest of
      sysfs which now mostly operate on sysfs_dirents.  As an added bonus,
      codes which use these helpers to add and remove sysfs_dirents are now
      more structured and simpler.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      fb6896da
    • T
      sysfs: use sysfs_mutex to protect the sysfs_dirent tree · 3007e997
      Tejun Heo 提交于
      As kobj sysfs dentries and inodes are gonna be made reclaimable,
      i_mutex can't be used to protect sysfs_dirent tree.  Use sysfs_mutex
      globally instead.  As the whole tree is protected with sysfs_mutex,
      there is no reason to keep sysfs_rename_sem.  Drop it.
      
      While at it, add docbook comments to functions which require
      sysfs_mutex locking.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      3007e997
    • T
      sysfs: make kobj point to sysfs_dirent instead of dentry · 608e266a
      Tejun Heo 提交于
      As kobj sysfs dentries and inodes are gonna be made reclaimable,
      dentry can't be used as naming token for sysfs file/directory, replace
      kobj->dentry with kobj->sd.  The only external interface change is
      shadow directory handling.  All other changes are contained in kobj
      and sysfs.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      608e266a
    • T
      sysfs: implement sysfs_find_dirent() and sysfs_get_dirent() · f0b0af47
      Tejun Heo 提交于
      Implement sysfs_find_dirent() and sysfs_get_dirent().
      sysfs_dirent_exist() is replaced by sysfs_find_dirent().  These will
      be used to make directory entries reclamiable.
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      f0b0af47