1. 04 10月, 2013 3 次提交
    • T
      sysfs: make __sysfs_remove_dir() recursive · bcdde7e2
      Tejun Heo 提交于
      Currently, sysfs directory removal is inconsistent in that it would
      remove any files directly under it but wouldn't recurse into
      directories.  Thanks to group subdirectories, this doesn't even match
      with kobject boundaries.  sysfs is in the process of being separated
      out so that it can be used by multiple subsystems and we want to have
      a consistent behavior - either removal of a sysfs_dirent should remove
      every descendant entries or none instead of something inbetween.
      
      This patch implements proper recursive removal in
      __sysfs_remove_dir().  The function now walks its subtree in a
      post-order walk to remove all descendants.
      
      This is a behavior change but kobject / driver layer, which currently
      is the only consumer, has already been updated to handle duplicate
      removal attempts, so nothing should be broken after this change.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bcdde7e2
    • T
      kobject: grab an extra reference on kobject->sd to allow duplicate deletes · 26ea12de
      Tejun Heo 提交于
      sysfs currently has a rather weird behavior regarding removals.  A
      directory removal would delete all files directly under it but
      wouldn't recurse into subdirectories, which, while a bit inconsistent,
      seems to make sense at the first glance as each directory is
      supposedly associated with a kobject and each kobject can take care of
      the directory deletion; however, this doesn't really hold as we have
      groups which can be directories without a kobject associated with it
      and require explicit deletions.
      
      We're in the process of separating out sysfs from kboject / driver
      core and want a consistent behavior.  A removal should delete either
      only the specified node or everything under it.  I think it is helpful
      to support recursive atomic removal and later patches will implement
      it.
      
      Such change means that a sysfs_dirent associated with kobject may be
      deleted before the kobject itself is removed if one of its ancestor
      gets removed before it.  As sysfs_remove_dir() puts the base ref, we
      may end up with dangling pointer on descendants.  This can be solved
      by holding an extra reference on the sd from kobject.
      
      Acquire an extra reference on the associated sysfs_dirent on directory
      creation and put it after removal.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      26ea12de
    • T
      sysfs: remove sysfs_addrm_cxt->parent_sd · d69ac5a0
      Tejun Heo 提交于
      sysfs_addrm_start/finish() enclose sysfs_dirent additions and
      deletions and sysfs_addrm_cxt is used to record information necessary
      to finish the operations.  Currently, sysfs_addrm_start() takes
      @parent_sd, records it in sysfs_addrm_cxt, and assumes that all
      operations in the block are performed under that @parent_sd.
      
      This assumption has been fine until now but we want to make some
      operations behave recursively and, while having @parent_sd recorded in
      sysfs_addrm_cxt doesn't necessarily prevents that, it becomes
      confusing.
      
      This patch removes sysfs_addrm_cxt->parent_sd and makes
      sysfs_add_one() take an explicit @parent_sd parameter.  Note that
      sysfs_remove_one() doesn't need the extra argument as its parent is
      always known from the target @sd.
      
      While at it, add __acquires/releases() notations to
      sysfs_addrm_start/finish() respectively.
      
      This patch doesn't make any functional difference.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d69ac5a0
  2. 27 9月, 2013 5 次提交
    • T
      sysfs: @name comes before @ns · cfec0bc8
      Tejun Heo 提交于
      Some internal sysfs functions which take explicit namespace argument
      are weird in that they place the optional @ns in front of @name which
      is contrary to the established convention.  This is confusing and
      error-prone especially as @ns and @name may be interchanged without
      causing compilation warning.
      
      Swap the positions of @name and @ns in the following internal
      functions.
      
       sysfs_find_dirent()
       sysfs_rename()
       sysfs_hash_and_remove()
       sysfs_name_hash()
       sysfs_name_compare()
       create_dir()
      
      This patch doesn't introduce any functional changes.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Kay Sievers <kay@vrfy.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cfec0bc8
    • T
      sysfs: clean up sysfs_get_dirent() · 388975cc
      Tejun Heo 提交于
      The pre-existing sysfs interfaces which take explicit namespace
      argument are weird in that they place the optional @ns in front of
      @name which is contrary to the established convention.  For example,
      we end up forcing vast majority of sysfs_get_dirent() users to do
      sysfs_get_dirent(parent, NULL, name), which is silly and error-prone
      especially as @ns and @name may be interchanged without causing
      compilation warning.
      
      This renames sysfs_get_dirent() to sysfs_get_dirent_ns() and swap the
      positions of @name and @ns, and sysfs_get_dirent() is now a wrapper
      around sysfs_get_dirent_ns().  This makes confusions a lot less
      likely.
      
      There are other interfaces which take @ns before @name.  They'll be
      updated by following patches.
      
      This patch doesn't introduce any functional changes.
      
      v2: EXPORT_SYMBOL_GPL() wasn't updated leading to undefined symbol
          error on module builds.  Reported by build test robot.  Fixed.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Kay Sievers <kay@vrfy.org>
      Cc: Fengguang Wu <fengguang.wu@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      388975cc
    • T
      sysfs: drop kobj_ns_type handling · cb26a311
      Tejun Heo 提交于
      The way namespace tags are implemented in sysfs is more complicated
      than necessary.  As each tag is a pointer value and required to be
      non-NULL under a namespace enabled parent, there's no need to record
      separately what type each tag is or where namespace is enabled.
      
      If multiple namespace types are needed, which currently aren't, we can
      simply compare the tag to a set of allowed tags in the superblock
      assuming that the tags, being pointers, won't have the same value
      across multiple types.  Also, whether to filter by namespace tag or
      not can be trivially determined by whether the node has any tagged
      children or not.
      
      This patch rips out kobj_ns_type handling from sysfs.  sysfs no longer
      cares whether specific type of namespace is enabled or not.  If a
      sysfs_dirent has a non-NULL tag, the parent is marked as needing
      namespace filtering and the value is tested against the allowed set of
      tags for the superblock (currently only one but increasing this number
      isn't difficult) and the sysfs_dirent is ignored if it doesn't match.
      
      This removes most kobject namespace knowledge from sysfs proper which
      will enable proper separation and layering of sysfs.  The namespace
      sanity checks in fs/sysfs/dir.c are replaced by the new sanity check
      in kobject_namespace().  As this is the only place ktype->namespace()
      is called for sysfs, this doesn't weaken the sanity check
      significantly.  I omitted converting the sanity check in
      sysfs_do_create_link_sd().  While the check can be shifted to upper
      layer, mistakes there are well contained and should be easily visible
      anyway.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Kay Sievers <kay@vrfy.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cb26a311
    • T
      sysfs: remove ktype->namespace() invocations in directory code · e34ff490
      Tejun Heo 提交于
      For some unrecognizable reason, namespace information is communicated
      to sysfs through ktype->namespace() callback when there's *nothing*
      which needs the use of a callback.  The whole sequence of operations
      is completely synchronous and sysfs operations simply end up calling
      back into the layer which just invoked it in order to find out the
      namespace information, which is completely backwards, obfuscates
      what's going on and unnecessarily tangles two separate layers.
      
      This patch doesn't remove ktype->namespace() but shifts its handling
      to kobject layer.  We probably want to get rid of the callback in the
      long term.
      
      This patch adds an explicit param to sysfs_{create|rename|move}_dir()
      and renames them to sysfs_{create|rename|move}_dir_ns(), respectively.
      ktype->namespace() invocations are moved to the calling sites of the
      above functions.  A new helper kboject_namespace() is introduced which
      directly tests kobj_ns_type_operations->type which should give the
      same result as testing sysfs_fs_type(parent_sd) and returns @kobj's
      namespace tag as necessary.  kobject_namespace() is extern as it will
      be used from another file in the following patches.
      
      This patch should be an equivalent conversion without any functional
      difference.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Kay Sievers <kay@vrfy.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e34ff490
    • T
      sysfs: drop semicolon from to_sysfs_dirent() definition · bcac3769
      Tejun Heo 提交于
      The expansion of to_sysfs_dirent() contains an unncessary trailing
      semicolon making it impossible to use in the middle of statements.
      Drop it.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bcac3769
  3. 06 9月, 2013 1 次提交
  4. 22 8月, 2013 4 次提交
  5. 29 6月, 2013 1 次提交
  6. 18 5月, 2013 1 次提交
  7. 06 4月, 2013 1 次提交
    • M
      sysfs: check if one entry has been removed before freeing · bb2b0051
      Ming Lei 提交于
      It might be a kernel disaster if one sysfs entry is freed but
      still referenced by sysfs tree.
      
      Recently Dave and Sasha reported one use-after-free problem on
      sysfs entry, and the problem has been troubleshooted with help
      of debug message added in this patch.
      
      Given sysfs_get_dirent/sysfs_put are exported APIs, even inside
      sysfs they are called in many contexts(kobject/attribe add/delete,
      inode init/drop, dentry lookup/release, readdir, ...), it is healthful
      to check the removed flag before freeing one entry and dump message
      if it is freeing without being removed first.
      
      Cc: Dave Jones <davej@redhat.com>
      Cc: Sasha Levin <levinsasha928@gmail.com>
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bb2b0051
  8. 04 4月, 2013 1 次提交
  9. 26 3月, 2013 1 次提交
  10. 21 3月, 2013 2 次提交
  11. 25 10月, 2012 1 次提交
  12. 18 7月, 2012 2 次提交
  13. 14 7月, 2012 4 次提交
  14. 15 5月, 2012 1 次提交
    • A
      sysfs: get rid of some lockdep false positives · 356c05d5
      Alan Stern 提交于
      This patch (as1554) fixes a lockdep false-positive report.  The
      problem arises because lockdep is unable to deal with the
      tree-structured locks created by the device core and sysfs.
      
      This particular problem involves a sysfs attribute method that
      unregisters itself, not from the device it was called for, but from a
      descendant device.  Lockdep doesn't understand the distinction and
      reports a possible deadlock, even though the operation is safe.
      
      This is the sort of thing that would normally be handled by using a
      nested lock annotation; unfortunately it's not feasible to do that
      here.  There's no sensible way to tell sysfs when attribute removal
      occurs in the context of a parent attribute method.
      
      As a workaround, the patch adds a new flag to struct attribute
      telling sysfs not to inform lockdep when it acquires a readlock on a
      sysfs_dirent instance for the attribute.  The readlock is still
      acquired, but lockdep doesn't know about it and hence does not
      complain about impossible deadlock scenarios.
      
      Also added are macros for static initialization of attribute
      structures with the ignore_lockdep flag set.  The three offending
      attributes in the USB subsystem are converted to use the new macros.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Acked-by: NTejun Heo <tj@kernel.org>
      CC: Eric W. Biederman <ebiederm@xmission.com>
      CC: Peter Zijlstra <peterz@infradead.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      356c05d5
  15. 03 5月, 2012 1 次提交
  16. 11 4月, 2012 1 次提交
    • D
      sysfs: handle 'parent deleted before child added' · 3a198886
      Dan Williams 提交于
      In scsi at least two cases of the parent device being deleted before the
      child is added have been observed.
      
      1/ scsi is performing async scans and the device is removed prior to the
         async can thread running (can happen with an in-opportune / unlikely
         unplug during initial scan).
      
      2/ libsas discovery event running after the parent port has been torn
         down (this is a bug in libsas).
      
      Result in crash signatures like:
       BUG: unable to handle kernel NULL pointer dereference at 0000000000000098
       IP: [<ffffffff8115e100>] sysfs_create_dir+0x32/0xb6
       ...
       Process scsi_scan_8 (pid: 5417, threadinfo ffff88080bd16000, task ffff880801b8a0b0)
       Stack:
        00000000fffffffe ffff880813470628 ffff88080bd17cd0 ffff88080614b7e8
        ffff88080b45c108 00000000fffffffe ffff88080bd17d20 ffffffff8125e4a8
        ffff88080bd17cf0 ffffffff81075149 ffff88080bd17d30 ffff88080614b7e8
       Call Trace:
        [<ffffffff8125e4a8>] kobject_add_internal+0x120/0x1e3
        [<ffffffff81075149>] ? trace_hardirqs_on+0xd/0xf
        [<ffffffff8125e641>] kobject_add_varg+0x41/0x50
        [<ffffffff8125e70b>] kobject_add+0x64/0x66
        [<ffffffff8131122b>] device_add+0x12d/0x63a
      
      In this scenario the parent is still valid (because we have a
      reference), but it has been device_del()'d which means its kobj->sd
      pointer is NULL'd via:
      
       device_del()->kobject_del()->sysfs_remove_dir()
      
      ...and then sysfs_create_dir() (without this fix) goes ahead and
      de-references parent_sd via sysfs_ns_type():
      
       return (sd->s_flags & SYSFS_NS_TYPE_MASK) >> SYSFS_NS_TYPE_SHIFT;
      
      This scenario is being fixed in scsi/libsas, but if other subsystems
      present the same ordering the system need not immediately crash.
      
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: James Bottomley <JBottomley@parallels.com>
      Signed-off-by: NDan Williams <dan.j.williams@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3a198886
  17. 10 4月, 2012 1 次提交
  18. 09 3月, 2012 1 次提交
  19. 01 2月, 2012 1 次提交
  20. 25 1月, 2012 3 次提交
  21. 02 11月, 2011 1 次提交
    • E
      sysfs: Make sysfs_rename safe with sysfs_dirents in rbtrees. · f6d90b4f
      Eric W. Biederman 提交于
      In sysfs_rename we need to remove the optimization of not calling
      sysfs_unlink_sibling and sysfs_link_sibling if the renamed parent
      directory is not changing.  This optimization is no longer valid now
      that sysfs dirents are stored in an rbtree sorted by name.
      
      Move the assignment of s_ns before the call of sysfs_link_sibling.  With
      no sysfs_dirent fields changing after the call of sysfs_link_sibling
      this allows sysfs_link_sibling to take any of the directory entries into
      account when it builds the rbtrees, and s_ns looks like a prime canidate
      to be used in the rbtree in the future.
      Signed-off-by: NEric W. Biederman <ebiederm@xmission.com>
      Cc: Jiri Slaby <jirislaby@gmail.com>
      Cc: Greg KH <gregkh@suse.de>
      Cc: David Miller <davem@davemloft.net>
      Cc: Mikulas Patocka <mpatocka@redhat.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      f6d90b4f
  22. 25 10月, 2011 1 次提交
  23. 20 10月, 2011 2 次提交