1. 14 1月, 2014 1 次提交
  2. 11 1月, 2014 2 次提交
    • T
      sysfs, driver-core: remove unused {sysfs|device}_schedule_callback_owner() · d1ba277e
      Tejun Heo 提交于
      All device_schedule_callback_owner() users are converted to use
      device_remove_file_self().  Remove now unused
      {sysfs|device}_schedule_callback_owner().
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d1ba277e
    • T
      kernfs, sysfs, driver-core: implement kernfs_remove_self() and its wrappers · 1ae06819
      Tejun Heo 提交于
      Sometimes it's necessary to implement a node which wants to delete
      nodes including itself.  This isn't straightforward because of kernfs
      active reference.  While a file operation is in progress, an active
      reference is held and kernfs_remove() waits for all such references to
      drain before completing.  For a self-deleting node, this is a deadlock
      as kernfs_remove() ends up waiting for an active reference that itself
      is sitting on top of.
      
      This currently is worked around in the sysfs layer using
      sysfs_schedule_callback() which makes such removals asynchronous.
      While it works, it's rather cumbersome and inherently breaks
      synchronicity of the operation - the file operation which triggered
      the operation may complete before the removal is finished (or even
      started) and the removal may fail asynchronously.  If a removal
      operation is immmediately followed by another operation which expects
      the specific name to be available (e.g. removal followed by rename
      onto the same name), there's no way to make the latter operation
      reliable.
      
      The thing is there's no inherent reason for this to be asynchrnous.
      All that's necessary to do this synchronous is a dedicated operation
      which drops its own active ref and deactivates self.  This patch
      implements kernfs_remove_self() and its wrappers in sysfs and driver
      core.  kernfs_remove_self() is to be called from one of the file
      operations, drops the active ref and deactivates using
      __kernfs_deactivate_self(), removes the self node, and restores active
      ref to the dead node using __kernfs_reactivate_self() so that the ref
      is balanced afterwards.  __kernfs_remove() is updated so that it takes
      an early exit if the target node is already fully removed so that the
      active ref restored by kernfs_remove_self() after removal doesn't
      confuse the deactivation path.
      
      This makes implementing self-deleting nodes very easy.  The normal
      removal path doesn't even need to be changed to use
      kernfs_remove_self() for the self-deleting node.  The method can
      invoke kernfs_remove_self() on itself before proceeding the normal
      removal path.  kernfs_remove() invoked on the node by the normal
      deletion path will simply be ignored.
      
      This will replace sysfs_schedule_callback().  A subtle feature of
      sysfs_schedule_callback() is that it collapses multiple invocations -
      even if multiple removals are triggered, the removal callback is run
      only once.  An equivalent effect can be achieved by testing the return
      value of kernfs_remove_self() - only the one which gets %true return
      value should proceed with actual deletion.  All other instances of
      kernfs_remove_self() will wait till the enclosing kernfs operation
      which invoked the winning instance of kernfs_remove_self() finishes
      and then return %false.  This trivially makes all users of
      kernfs_remove_self() automatically show correct synchronous behavior
      even when there are multiple concurrent operations - all "echo 1 >
      delete" instances will finish only after the whole operation is
      completed by one of the instances.
      
      v2: For !CONFIG_SYSFS, dummy version kernfs_remove_self() was missing
          and sysfs_remove_file_self() had incorrect return type.  Fix it.
          Reported by kbuild test bot.
      
      v3: Updated to use __kernfs_{de|re}activate_self().
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Cc: kbuild test robot <fengguang.wu@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1ae06819
  3. 18 12月, 2013 1 次提交
    • T
      kernfs: mark static names with KERNFS_STATIC_NAME · 2063d608
      Tejun Heo 提交于
      Because sysfs used struct attribute which are supposed to stay
      constant, sysfs didn't copy names when creating regular files.  The
      specified string for name was supposed to stay constant.  Such
      distinction isn't inherent for kernfs.  kernfs_create_file[_ns]()
      should be able to take the same @name as kernfs_create_dir[_ns]()
      
      As there can be huge number of sysfs attributes, we still want to be
      able to use static names for sysfs attributes.  This patch renames
      kernfs_create_file_ns_key() to __kernfs_create_file() and adds
      @name_is_static parameter so that the caller can explicitly indicate
      that @name can be used without copying.  kernfs is updated to use
      KERNFS_STATIC_NAME to distinguish static and copied names.
      
      This patch doesn't introduce any behavior changes.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2063d608
  4. 12 12月, 2013 4 次提交
    • T
      kernfs: s/sysfs/kernfs/ in constants · df23fc39
      Tejun Heo 提交于
      kernfs has just been separated out from sysfs and we're already in
      full conflict mode.  Nothing can make the situation any worse.  Let's
      take the chance to name things properly.
      
      This patch performs the following renames.
      
      * s/SYSFS_DIR/KERNFS_DIR/
      * s/SYSFS_KOBJ_ATTR/KERNFS_FILE/
      * s/SYSFS_KOBJ_LINK/KERNFS_LINK/
      * s/SYSFS_{TYPE_FLAGS}/KERNFS_{TYPE_FLAGS}/
      * s/SYSFS_FLAG_{FLAG}/KERNFS_{FLAG}/
      * s/sysfs_type()/kernfs_type()/
      * s/SD_DEACTIVATED_BIAS/KN_DEACTIVATED_BIAS/
      
      This patch is strictly rename only and doesn't introduce any
      functional difference.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      df23fc39
    • T
      kernfs: s/sysfs/kernfs/ in various data structures · c525aadd
      Tejun Heo 提交于
      kernfs has just been separated out from sysfs and we're already in
      full conflict mode.  Nothing can make the situation any worse.  Let's
      take the chance to name things properly.
      
      This patch performs the following renames.
      
      * s/sysfs_open_dirent/kernfs_open_node/
      * s/sysfs_open_file/kernfs_open_file/
      * s/sysfs_inode_attrs/kernfs_iattrs/
      * s/sysfs_addrm_cxt/kernfs_addrm_cxt/
      * s/sysfs_super_info/kernfs_super_info/
      * s/sysfs_info()/kernfs_info()/
      * s/sysfs_open_dirent_lock/kernfs_open_node_lock/
      * s/sysfs_open_file_mutex/kernfs_open_file_mutex/
      * s/sysfs_of()/kernfs_of()/
      
      This patch is strictly rename only and doesn't introduce any
      functional difference.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c525aadd
    • T
      kernfs: drop s_ prefix from kernfs_node members · adc5e8b5
      Tejun Heo 提交于
      kernfs has just been separated out from sysfs and we're already in
      full conflict mode.  Nothing can make the situation any worse.  Let's
      take the chance to name things properly.
      
      s_ prefix for kernfs members is used inconsistently and a misnomer
      now.  It's not like kernfs_node is used widely across the kernel
      making the ability to grep for the members particularly useful.  Let's
      just drop the prefix.
      
      This patch is strictly rename only and doesn't introduce any
      functional difference.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      adc5e8b5
    • T
      kernfs: s/sysfs_dirent/kernfs_node/ and rename its friends accordingly · 324a56e1
      Tejun Heo 提交于
      kernfs has just been separated out from sysfs and we're already in
      full conflict mode.  Nothing can make the situation any worse.  Let's
      take the chance to name things properly.
      
      This patch performs the following renames.
      
      * s/sysfs_elem_dir/kernfs_elem_dir/
      * s/sysfs_elem_symlink/kernfs_elem_symlink/
      * s/sysfs_elem_attr/kernfs_elem_file/
      * s/sysfs_dirent/kernfs_node/
      * s/sd/kn/ in kernfs proper
      * s/parent_sd/parent/
      * s/target_sd/target/
      * s/dir_sd/parent/
      * s/to_sysfs_dirent()/rb_to_kn()/
      * misc renames of local vars when they conflict with the above
      
      Because md, mic and gpio dig into sysfs details, this patch ends up
      modifying them.  All are sysfs_dirent renames and trivial.  While we
      can avoid these by introducing a dummy wrapping struct sysfs_dirent
      around kernfs_node, given the limited usage outside kernfs and sysfs
      proper, I don't think such workaround is called for.
      
      This patch is strictly rename only and doesn't introduce any
      functional difference.
      
      - mic / gpio renames were missing.  Spotted by kbuild test robot.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Neil Brown <neilb@suse.de>
      Cc: Linus Walleij <linus.walleij@linaro.org>
      Cc: Ashutosh Dixit <ashutosh.dixit@intel.com>
      Cc: kbuild test robot <fengguang.wu@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      324a56e1
  5. 11 12月, 2013 1 次提交
    • T
      sysfs: bail early from kernfs_file_mmap() to avoid spurious lockdep warning · 9b2db6e1
      Tejun Heo 提交于
      This is v3.14 fix for the same issue that a8b14744 ("sysfs: give
      different locking key to regular and bin files") addresses for v3.13.
      Due to the extensive kernfs reorganization in v3.14 branch, the same
      fix couldn't be ported as-is.  The v3.13 fix was ignored while merging
      it into v3.14 branch.
      
      027a485d ("sysfs: use a separate locking class for open files
      depending on mmap") assigned different lockdep key to
      sysfs_open_file->mutex depending on whether the file implements mmap
      or not in an attempt to avoid spurious lockdep warning caused by
      merging of regular and bin file paths.
      
      While this restored some of the original behavior of using different
      locks (at least lockdep is concerned) for the different clases of
      files.  The restoration wasn't full because now the lockdep key
      assignment depends on whether the file has mmap or not instead of
      whether it's a regular file or not.
      
      This means that bin files which don't implement mmap will get assigned
      the same lockdep class as regular files.  This is problematic because
      file_operations for bin files still implements the mmap file operation
      and checking whether the sysfs file actually implements mmap happens
      in the file operation after grabbing @sysfs_open_file->mutex.  We
      still end up adding locking dependency from mmap locking to
      sysfs_open_file->mutex to the regular file mutex which triggers
      spurious circular locking warning.
      
      For v3.13, a8b14744 ("sysfs: give different locking key to regular
      and bin files") fixed it by giving sysfs_open_file->mutex different
      lockdep keys depending on whether the file is regular or bin instead
      of whether mmap exists or not; however, due to the way sysfs is now
      layered behind kernfs, this approach is no longer viable.  kernfs can
      tell whether a sysfs node has mmap implemented or not but can't tell
      whether a bin file from a regular one.
      
      This patch updates kernfs such that kernfs_file_mmap() checks
      SYSFS_FLAG_HAS_MMAP and bail before grabbing sysfs_open_file->mutex so
      that it doesn't add spurious locking dependency from mmap to
      sysfs_open_file->mutex and changes sysfs so that it specifies
      kernfs_ops->mmap iff the sysfs file implements mmap.  Combined, this
      ensures that sysfs_open_file->mutex is grabbed under mmap path iff the
      sysfs file actually implements mmap.  As sysfs_open_file->mutex is
      already given a different lockdep key if mmap is implemented, this
      removes the spurious locking dependency.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Reported-by: NDave Jones <davej@redhat.com>
      Link: http://lkml.kernel.org/g/20131203184324.GA11320@redhat.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9b2db6e1
  6. 08 12月, 2013 1 次提交
    • T
      sysfs: give different locking key to regular and bin files · a8b14744
      Tejun Heo 提交于
      027a485d ("sysfs: use a separate locking class for open files
      depending on mmap") assigned different lockdep key to
      sysfs_open_file->mutex depending on whether the file implements mmap
      or not in an attempt to avoid spurious lockdep warning caused by
      merging of regular and bin file paths.
      
      While this restored some of the original behavior of using different
      locks (at least lockdep is concerned) for the different clases of
      files.  The restoration wasn't full because now the lockdep key
      assignment depends on whether the file has mmap or not instead of
      whether it's a regular file or not.
      
      This means that bin files which don't implement mmap will get assigned
      the same lockdep class as regular files.  This is problematic because
      file_operations for bin files still implements the mmap file operation
      and checking whether the sysfs file actually implements mmap happens
      in the file operation after grabbing @sysfs_open_file->mutex.  We
      still end up adding locking dependency from mmap locking to
      sysfs_open_file->mutex to the regular file mutex which triggers
      spurious circular locking warning.
      
      Fix it by restoring the original behavior fully by differentiating
      lockdep key by whether the file is regular or bin, instead of the
      existence of mmap.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Reported-by: NDave Jones <davej@redhat.com>
      Link: http://lkml.kernel.org/g/20131203184324.GA11320@redhat.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a8b14744
  7. 30 11月, 2013 16 次提交
    • T
      sysfs, kernfs: move file core code to fs/kernfs/file.c · 414985ae
      Tejun Heo 提交于
      Move core file code to fs/kernfs/file.c.  fs/sysfs/file.c now contains
      sysfs kernfs_ops callbacks, sysfs wrappers around kernfs interfaces,
      and sysfs_schedule_callback().  The respective declarations in
      fs/sysfs/sysfs.h are moved to fs/kernfs/kernfs-internal.h.
      
      This is pure relocation.
      
      v2: Refreshed on top of the v2 of "sysfs, kernfs: prepare read path
          for kernfs".
      
      v3: Refreshed on top of the v3 of "sysfs, kernfs: prepare read path
          for kernfs".
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      414985ae
    • T
      sysfs, kernfs: introduce kernfs[_find_and]_get() and kernfs_put() · ccf73cf3
      Tejun Heo 提交于
      Introduce kernfs interface for finding, getting and putting
      sysfs_dirents.
      
      * sysfs_find_dirent() is renamed to kernfs_find_ns() and lockdep
        assertion for sysfs_mutex is added.
      
      * sysfs_get_dirent_ns() is renamed to kernfs_find_and_get().
      
      * Macro inline dancing around __sysfs_get/put() are removed and
        kernfs_get/put() are made proper functions implemented in
        fs/sysfs/dir.c.
      
      While the conversions are mostly equivalent, there's one difference -
      kernfs_get() doesn't return the input param as its return value.  This
      change is intentional.  While passing through the input increases
      writability in some areas, it is unnecessary and has been shown to
      cause confusion regarding how the last ref is handled.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ccf73cf3
    • T
      sysfs, kernfs: revamp sysfs_dirent active_ref lockdep annotation · 517e64f5
      Tejun Heo 提交于
      Currently, sysfs_dirent active_ref lockdep annotation uses
      attribute->[s]key as the lockdep key, which forces
      kernfs_create_file_ns() to assume that sysfs_dirent->priv is pointing
      to a struct attribute which may not be true for non-sysfs users.  This
      patch restructures the lockdep annotation such that
      
      * kernfs_ops contains lockdep_key which is used by default for files
        created kernfs_create_file_ns().
      
      * kernfs_create_file_ns_key() is introduced which takes an extra @key
        argument.  The created file will use the specified key for
        active_ref lockdep annotation.  If NULL is specified, lockdep for
        the file is disabled.
      
      * sysfs_add_file_mode_ns() is updated to use
        kernfs_create_file_ns_key() with the appropriate key from the
        attribute or NULL if ignore_lockdep is set.
      
      This makes the lockdep annotation properly contained in kernfs while
      allowing sysfs to cleanly keep its current behavior.  This patch
      doesn't introduce any behavior differences.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      517e64f5
    • T
      sysfs, kernfs: introduce kernfs_notify() · 024f6471
      Tejun Heo 提交于
      Introduce kernfs interface to wake up poll(2) which takes and returns
      sysfs_dirents.
      
      sysfs_notify_dirent() is renamed to kernfs_notify() and sysfs_notify()
      is updated so that it doesn't directly grab sysfs_mutex but acquires
      the target sysfs_dirents using sysfs_get_dirent().
      sysfs_notify_dirent() is reimplemented as a dumb inline wrapper around
      kernfs_notify().
      
      This patch doesn't introduce any behavior changes.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      024f6471
    • T
      sysfs, kernfs: add kernfs_ops->seq_{start|next|stop}() · d19b9846
      Tejun Heo 提交于
      kernfs_ops currently only supports single_open() behavior which is
      pretty restrictive.  Add optional callbacks ->seq_{start|next|stop}()
      which, when implemented, are invoked for seq_file traversal.  This
      allows full seq_file functionality for kernfs users.  This currently
      doesn't have any user and doesn't change any behavior.
      
      v2: Refreshed on top of the updated "sysfs, kernfs: prepare read path
          for kernfs".
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d19b9846
    • T
      sysfs, kernfs: remove sysfs_add_one() · 2d0cfbec
      Tejun Heo 提交于
      sysfs_add_one() is a wrapper around __sysfs_add_one() which prints out
      duplicate name warning if __sysfs_add_one() fails with -EEXIST.  The
      previous kernfs conversions moved all dup warnings to sysfs interface
      functions and sysfs_add_one() doesn't have any user left.
      
      Remove sysfs_add_one() and update __sysfs_add_one() to take its name.
      
      This patch doesn't make any functional changes.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2d0cfbec
    • T
      sysfs, kernfs: introduce kernfs_create_file[_ns]() · 496f7394
      Tejun Heo 提交于
      Introduce kernfs interface to create a file which takes and returns
      sysfs_dirents.
      
      The actual file creation part is separated out from
      sysfs_add_file_mode_ns() into kernfs_create_file_ns().  The former now
      only decides the kernfs_ops to use and the file's size and invokes the
      latter.
      
      This patch doesn't introduce behavior changes.
      
      v2: Dummy implementation for !CONFIG_SYSFS updated to return -ENOSYS.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      496f7394
    • T
      sysfs, kernfs: remove SYSFS_KOBJ_BIN_ATTR · a7dc66df
      Tejun Heo 提交于
      After kernfs_ops and sysfs_dirent->s_attr.size addition, the
      distinction between SYSFS_KOBJ_BIN_ATTR and SYSFS_KOBJ_ATTR is only
      necessary while creating files to decide which kernfs_ops to use.
      Afterwards, they behave exactly the same.
      
      This patch removes SYSFS_KOBJ_BIN_ATTR along with sysfs_is_bin().
      sysfs_add_file[_mode_ns]() are updated to take bool @is_bin instead of
      @type.
      
      This patch doesn't introduce any behavior changes.  This completely
      isolates the distinction between the two sysfs file types in the sysfs
      layer proper.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a7dc66df
    • T
      sysfs, kernfs: add sysfs_dirent->s_attr.size · 471bd7b7
      Tejun Heo 提交于
      sysfs sets the size of regular files unconditionally at PAGE_SIZE and
      takes the size of bin files from bin_attribute.  The latter is a
      pretty bad interface which forces bin_attribute users to create a
      separate copy of bin_attribute for each instance of the file -
      e.g. pci resource files.
      
      Add sysfs_dirent->s_attr.size so that the size can be specified
      separately.  This unifies inode init paths of ATTR and BIN_ATTR
      identical and allows for generic size handling for kernfs.
      
      Unfortunately, this grows the size of sysfs_dirent by sizeof(loff_t).
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      471bd7b7
    • T
      sysfs, kernfs: introduce kernfs_ops · f6acf8bb
      Tejun Heo 提交于
      We're in the process of separating out core sysfs functionality into
      kernfs which will deal with sysfs_dirents directly.  This patch
      introduces kernfs_ops which hosts methods kernfs users implement and
      updates fs/sysfs/file.c such that sysfs_kf_*() functions populate
      kernfs_ops and kernfs_file_*() functions call the matching entries
      from kernfs_ops.
      
      kernfs_ops contains the following groups of methods.
      
      * seq_show() - for kernfs files which use seq_file for reads.
      
      * read() - for direct read implementations.  Used iff seq_show() is
        not implemented.
      
      * write() - for writes.
      
      * mmap() - for mmaps.
      
      Notes:
      
      * sysfs_elem_attr->ops is added so that kernfs_ops can be accessed
        from sysfs_dirent.  kernfs_ops() helper is added to verify locking
        and access the field.
      
      * SYSFS_FLAG_HAS_(SEQ_SHOW|MMAP) added.  sd->s_attr->ops is accessible
        only while holding active_ref and there are cases where we want to
        take different actions depending on which ops are implemented.
        These two flags cache whether the two ops are implemented for those.
      
      * kernfs_file_*() no longer test sysfs type but chooses different
        behaviors depending on which methods in kernfs_ops are implemented.
        The conversions are trivial except for the open path.  As
        kernfs_file_open() now decides whether to allow read/write accesses
        depending on the kernfs_ops implemented, the presence of methods in
        kobjs and attribute_bin should be propagated to kernfs_ops.
        sysfs_add_file_mode_ns() is updated so that it propagates presence /
        absence of the callbacks through _empty, _ro, _wo, _rw kernfs_ops.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f6acf8bb
    • T
      sysfs, kernfs: move sysfs_open_file to include/linux/kernfs.h · dd8a5b03
      Tejun Heo 提交于
      sysfs_open_file will be used as the primary handle for kernfs methods.
      Move its definition from fs/sysfs/file.c to include/linux/kernfs.h and
      mark the public and private fields.
      
      This is pure relocation.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      dd8a5b03
    • T
      sysfs, kernfs: prepare open, release, poll paths for kernfs · c6fb4495
      Tejun Heo 提交于
      We're in the process of separating out core sysfs functionality into
      kernfs which will deal with sysfs_dirents directly.  This patch
      prepares the rest - open, release and poll.  There isn't much to do.
      Just renaming is enough.  As sysfs_file_operations and
      sysfs_bin_operations are identical now, use the same file_operations
      for both - kernfs_file_operations.
      
      This patch doesn't introduce any behavior changes.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c6fb4495
    • T
      sysfs, kernfs: prepare mmap path for kernfs · fdbffaa4
      Tejun Heo 提交于
      We're in the process of separating out core sysfs functionality into
      kernfs which will deal with sysfs_dirents directly.  This patch
      rearranges mmap path so that the kernfs and sysfs parts are separate.
      
      sysfs_kf_bin_mmap() which handles the interaction with bin_attribute
      mmap method is factored out of sysfs_bin_mmap(), which is renamed to
      kernfs_file_mmap().  All vma ops are renamed accordingly.
      
      sysfs_bin_mmap() is updated such that it can be used for both file
      types.  This will eventually allow using the same file_operations for
      both file types, which is necessary to separate out kernfs.
      
      This patch doesn't introduce any behavior changes.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fdbffaa4
    • T
      sysfs, kernfs: prepare write path for kernfs · 50b38ca0
      Tejun Heo 提交于
      We're in the process of separating out core sysfs functionality into
      kernfs which will deal with sysfs_dirents directly.  This patch
      rearranges write path so that the kernfs and sysfs parts are separate.
      
      kernfs_file_write() handles all boilerplate work including buffer
      management and locking and invokes sysfs_kf_write() or
      sysfs_kf_bin_write() depending on the file type which deals with the
      interaction with kobj store or bin_attribute write method.
      
      While this patch changes the order of some operations, it shouldn't
      change any visible behavior.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      50b38ca0
    • T
      sysfs, kernfs: prepare read path for kernfs · c2b19daf
      Tejun Heo 提交于
      We're in the process of separating out core sysfs functionality into
      kernfs which will deal with sysfs_dirents directly.  This patch
      rearranges read path so that the kernfs and sysfs parts are separate.
      
      * Regular file read path is refactored such that
        kernfs_seq_start/next/stop/show() handle all the boilerplate work
        including locking and updating event count for poll, while
        sysfs_kf_seq_show() deals with interaction with kobj show method.
      
      * Bin file read path is refactored such that kernfs_file_direct_read()
        handles all the boilerplate work including buffer management and
        locking, while sysfs_kf_bin_read() deals with interaction with
        bin_attribute read method.
      
      kernfs_file_read() is added.  It invokes either the seq_file or direct
      read path depending on the file type.  This will eventually allow
      using the same file_operations for both file types, which is necessary
      to separate out kernfs.
      
      While this patch changes the order of some operations, it shouldn't
      change any visible behavior.
      
      v2: Dropped unnecessary zeroing of @count from sysfs_kf_seq_show().
          Add comments explaining single_open() behavior.  Both suggested by
          Pavel.
      
      v3: seq_stop() is called even after seq_start() failed.
          kernfs_seq_start() updated so that it doesn't unlock
          sysfs_open_file->mutex on failure so that kernfs_seq_stop()
          doesn't try to unlock an already unlocked mutex.  Reported by
          Fengguang.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Pavel Machek <pavel@ucw.cz>
      Cc: Fengguang Wu <fengguang.wu@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c2b19daf
    • T
      sysfs, kernfs: replace sysfs_dirent->s_dir.kobj and ->s_attr.[bin_]attr with ->priv · 7c6e2d36
      Tejun Heo 提交于
      A directory sysfs_dirent points to the associated kobj.  A regular or
      bin file points to the associated [bin_]attribute.  This patch
      replaces sysfs_dirent->s_dir.kobj and ->s_attr.[bin_]attr with void *
      ->priv.
      
      This is to prepare for kernfs interface so that sysfs can specify the
      private data in the same way for directories and files.  This lower
      debuggability but not by much - the whole thing was overlaid in a
      union anyway.  If debuggability becomes an issue, we can later add
      ->priv accessors which explicitly check for the sysfs_dirent type and
      performs casting.
      
      This patch doesn't introduce any behavior difference.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7c6e2d36
  8. 28 11月, 2013 2 次提交
  9. 24 11月, 2013 1 次提交
    • T
      sysfs: use a separate locking class for open files depending on mmap · 027a485d
      Tejun Heo 提交于
      The following two commits implemented mmap support in the regular file
      path and merged bin file support into the regular path.
      
       73d97146 ("sysfs: copy bin mmap support from fs/sysfs/bin.c to fs/sysfs/file.c")
       3124eb16 ("sysfs: merge regular and bin file handling")
      
      After the merge, the following commands trigger a spurious lockdep
      warning.  "test-mmap-read" simply mmaps the file and dumps the
      content.
      
        $ cat /sys/block/sda/trace/act_mask
        $ test-mmap-read /sys/devices/pci0000\:00/0000\:00\:03.0/resource0 4096
      
        ======================================================
        [ INFO: possible circular locking dependency detected ]
        3.12.0-work+ #378 Not tainted
        -------------------------------------------------------
        test-mmap-read/567 is trying to acquire lock:
         (&of->mutex){+.+.+.}, at: [<ffffffff8120a8df>] sysfs_bin_mmap+0x4f/0x120
      
        but task is already holding lock:
         (&mm->mmap_sem){++++++}, at: [<ffffffff8114b399>] vm_mmap_pgoff+0x49/0xa0
      
        which lock already depends on the new lock.
      
        the existing dependency chain (in reverse order) is:
      
        -> #3 (&mm->mmap_sem){++++++}:
        ...
        -> #2 (sr_mutex){+.+.+.}:
        ...
        -> #1 (&bdev->bd_mutex){+.+.+.}:
        ...
        -> #0 (&of->mutex){+.+.+.}:
        ...
      
        other info that might help us debug this:
      
        Chain exists of:
         &of->mutex --> sr_mutex --> &mm->mmap_sem
      
         Possible unsafe locking scenario:
      
      	 CPU0                    CPU1
      	 ----                    ----
          lock(&mm->mmap_sem);
      				 lock(sr_mutex);
      				 lock(&mm->mmap_sem);
          lock(&of->mutex);
      
         *** DEADLOCK ***
      
        1 lock held by test-mmap-read/567:
         #0:  (&mm->mmap_sem){++++++}, at: [<ffffffff8114b399>] vm_mmap_pgoff+0x49/0xa0
      
        stack backtrace:
        CPU: 3 PID: 567 Comm: test-mmap-read Not tainted 3.12.0-work+ #378
        Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
         ffffffff81ed41a0 ffff880009441bc8 ffffffff81611ad2 ffffffff81eccb80
         ffff880009441c08 ffffffff8160f215 ffff880009441c60 ffff880009c75208
         0000000000000000 ffff880009c751e0 ffff880009c75208 ffff880009c74ac0
        Call Trace:
         [<ffffffff81611ad2>] dump_stack+0x4e/0x7a
         [<ffffffff8160f215>] print_circular_bug+0x2b0/0x2bf
         [<ffffffff8109ca0a>] __lock_acquire+0x1a3a/0x1e60
         [<ffffffff8109d6ba>] lock_acquire+0x9a/0x1d0
         [<ffffffff81615547>] mutex_lock_nested+0x67/0x3f0
         [<ffffffff8120a8df>] sysfs_bin_mmap+0x4f/0x120
         [<ffffffff8115d363>] mmap_region+0x3b3/0x5b0
         [<ffffffff8115d8ae>] do_mmap_pgoff+0x34e/0x3d0
         [<ffffffff8114b3ba>] vm_mmap_pgoff+0x6a/0xa0
         [<ffffffff8115be3e>] SyS_mmap_pgoff+0xbe/0x250
         [<ffffffff81008282>] SyS_mmap+0x22/0x30
         [<ffffffff8161a4d2>] system_call_fastpath+0x16/0x1b
      
      This happens because one file nests sr_mutex, which nests mm->mmap_sem
      under it, under of->mutex while mmap implementation naturally nests
      of->mutex under mm->mmap_sem.  The warning is false positive as
      of->mutex is per open-file and the two paths belong to two different
      files.  This warning didn't trigger before regular and bin file
      supports were merged because only bin file supported mmap and the
      other side of locking happened only on regular files which used
      equivalent but separate locking.
      
      It'd be best if we give separate locking classes per file but we can't
      easily do that.  Let's differentiate on ->mmap() for now.  Later we'll
      add explicit file operations struct and can add per-ops lockdep key
      there.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Reported-by: NDave Jones <davej@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      027a485d
  10. 02 11月, 2013 1 次提交
    • T
      sysfs: use generic_file_llseek() for sysfs_file_operations · 044e3bc3
      Tejun Heo 提交于
      13c589d5 ("sysfs: use seq_file when reading regular files")
      converted regular sysfs files to use seq_file.  The commit substituted
      generic_file_llseek() with seq_lseek() for llseek implementation.
      
      Before the change, all regular sysfs files were allowed to seek to any
      position in [0, PAGE_SIZE] as the file size is always PAGE_SIZE and
      generic_file_llseek() allows any seeking inside the range under file
      size; however, seq_lseek()'s behavior is different.  It traverses the
      output by repeatedly invoking ->show() until it reaches the target
      offset or traversal indicates EOF.  As seq_files are fully dynamic and
      may not end at all, it doesn't support seeking from the end
      (SEEK_END).
      
      Apparently, there are userland tools which uses SEEK_END to discover
      the buffer size to use and the switch to seq_lseek() disturbs them as
      SEEK_END fails with -EINVAL.
      
      The only benefits of using seq_lseek() instead of
      generic_file_llseek() are
      
      * Early failure.  If traversing to certain file position should fail,
        seq_lseek() will report such failures on lseek(2) instead of the
        following read/write operations.
      
      * EOF detection.  While SEEK_END is not supported, SEEK_SET/CUR +
        large offset can be used to detect eof - eof at the time of the seek
        anyway as the file size may change dynamically.
      
      Both aren't necessary for sysfs or prospect kernfs users.  Revert to
      genefic_file_llseek() and preserve the original behavior.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Reported-by: NHeiko Carstens <heiko.carstens@de.ibm.com>
      Link: https://lkml.kernel.org/r/20131031114358.GA5551@osirisTested-by: NHeiko Carstens <heiko.carstens@de.ibm.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      044e3bc3
  11. 31 10月, 2013 1 次提交
  12. 30 10月, 2013 1 次提交
    • T
      sysfs: merge sysfs_elem_bin_attr into sysfs_elem_attr · 56b3f3b8
      Tejun Heo 提交于
      3124eb16 ("sysfs: merge regular and bin file handling") folded bin
      file handling into regular file handling.  Among other things, bin
      file now shares the same open path including sysfs_open_dirent
      association using sysfs_dirent->s_attr.open.  This is buggy because
      ->s_bin_attr lives in the same union and doesn't have the field.  This
      bug doesn't trigger because sysfs_elem_bin_attr doesn't have an active
      field at the conflicting position.  It does have a field "buffers" but
      it isn't used anymore.
      
      This patch collapses sysfs_elem_bin_attr into sysfs_elem_attr so that
      the bin_attr is accessed through ->s_attr.bin_attr which lives with
      ->s_attr.attr in an anonymous union.  The code paths already assume
      bin_attr contains attr as the first element, so this doesn't add any
      more assumptions while making it explicit that the two types are
      handled together.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      56b3f3b8
  13. 25 10月, 2013 1 次提交
  14. 15 10月, 2013 1 次提交
  15. 14 10月, 2013 1 次提交
    • T
      sysfs: make sysfs_file_ops() follow ignore_lockdep flag · 785a162d
      Tejun Heo 提交于
      375b611e ("sysfs: remove sysfs_buffer->ops") introduced
      sysfs_file_ops() which determines the associated file operation of a
      given sysfs_dirent.  As file ops access should be protected by an
      active reference, the new function includes a lockdep assertion on the
      sysfs_dirent; unfortunately, I forgot to take attr->ignore_lockdep
      flag into account and the lockdep assertion trips spuriously for files
      which opt out from active reference lockdep checking.
      
      # cat /sys/devices/pci0000:00/0000:00:01.2/usb1/authorized
      
       ------------[ cut here ]------------
       WARNING: CPU: 1 PID: 540 at /work/os/work/fs/sysfs/file.c:79 sysfs_file_ops+0x4e/0x60()
       Modules linked in:
       CPU: 1 PID: 540 Comm: cat Not tainted 3.11.0-work+ #3
       Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
        0000000000000009 ffff880016205c08 ffffffff81ca0131 0000000000000000
        ffff880016205c40 ffffffff81096d0d ffff8800166cb898 ffff8800166f6f60
        ffffffff8125a220 ffff880011ab1ec0 ffff88000aff0c78 ffff880016205c50
       Call Trace:
        [<ffffffff81ca0131>] dump_stack+0x4e/0x82
        [<ffffffff81096d0d>] warn_slowpath_common+0x7d/0xa0
        [<ffffffff81096dea>] warn_slowpath_null+0x1a/0x20
        [<ffffffff8125994e>] sysfs_file_ops+0x4e/0x60
        [<ffffffff8125a274>] sysfs_open_file+0x54/0x300
        [<ffffffff811df612>] do_dentry_open.isra.17+0x182/0x280
        [<ffffffff811df820>] finish_open+0x30/0x40
        [<ffffffff811f0623>] do_last+0x503/0xd90
        [<ffffffff811f0f6b>] path_openat+0xbb/0x6d0
        [<ffffffff811f23ba>] do_filp_open+0x3a/0x90
        [<ffffffff811e09a9>] do_sys_open+0x129/0x220
        [<ffffffff811e0abe>] SyS_open+0x1e/0x20
        [<ffffffff81caf3c2>] system_call_fastpath+0x16/0x1b
       ---[ end trace aa48096b111dafdb ]---
      
      Rename fs/sysfs/dir.c::ignore_lockdep() to sysfs_ignore_lockdep() and
      move it to fs/sysfs/sysfs.h and make sysfs_file_ops() skip lockdep
      assertion if sysfs_ignore_lockdep() is true.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Reported-by: NYinghai Lu <yinghai@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      785a162d
  16. 06 10月, 2013 5 次提交
    • T
      sysfs: merge regular and bin file handling · 3124eb16
      Tejun Heo 提交于
      With the previous changes, sysfs regular file code is ready to handle
      bin files too.  This patch makes bin files share the regular file
      path.
      
      * sysfs_create/remove_bin_file() are moved to fs/sysfs/file.c.
      
      * sysfs_init_inode() is updated to use the new sysfs_bin_operations
        instead of bin_fops for bin files.
      
      * fs/sysfs/bin.c and the related pieces are removed.
      
      This patch shouldn't introduce any behavior difference to bin file
      accesses.
      
      Overall, this unification reduces the amount of duplicate logic, makes
      behaviors more consistent and paves the road for building simpler and
      more versatile interface which will allow other subsystems to make use
      of sysfs for their pseudo filesystems.
      
      v2: Stale fs/sysfs/bin.c reference dropped from
          Documentation/DocBook/filesystems.tmpl.  Reported by kbuild test
          robot.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Kay Sievers <kay@vrfy.org>
      Cc: kbuild test robot <fengguang.wu@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3124eb16
    • T
      sysfs: prepare open path for unified regular / bin file handling · 49fe6047
      Tejun Heo 提交于
      sysfs bin file handling will be merged into the regular file support.
      This patch prepares the open path.
      
      This patch updates sysfs_open_file() such that it can handle both
      regular and bin files.
      
      This is a preparation and the new bin file path isn't used yet.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      49fe6047
    • T
      sysfs: copy bin mmap support from fs/sysfs/bin.c to fs/sysfs/file.c · 73d97146
      Tejun Heo 提交于
      sysfs bin file handling will be merged into the regular file support.
      This patch copies mmap support from bin so that fs/sysfs/file.c can
      handle mmapping bin files.
      
      The code is copied mostly verbatim with the following updates.
      
      * ->mmapped and ->vm_ops are added to sysfs_open_file and bin_buffer
        references are replaced with sysfs_open_file ones.
      
      * Symbols are prefixed with sysfs_.
      
      * sysfs_unmap_bin_file() grabs sysfs_open_dirent and traverses
        ->files.  Invocation of this function is added to
        sysfs_addrm_finish().
      
      * sysfs_bin_mmap() is added to sysfs_bin_operations.
      
      This is a preparation and the new mmap path isn't used yet.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      73d97146
    • T
      sysfs: add sysfs_bin_read() · 2f0c6b75
      Tejun Heo 提交于
      sysfs bin file handling will be merged into the regular file support.
      This patch prepares the read path.
      
      Copy fs/sysfs/bin.c::read() to fs/sysfs/file.c and make it use
      sysfs_open_file instead of bin_buffer.  The function is identical copy
      except for the use of sysfs_open_file.
      
      The new function is added to sysfs_bin_operations.  This isn't used
      yet but will eventually replace fs/sysfs/bin.c.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2f0c6b75
    • T
      sysfs: prepare path write for unified regular / bin file handling · f9b9a621
      Tejun Heo 提交于
      sysfs bin file handling will be merged into the regular file support.
      This patch prepares the write path.
      
      bin file write is almost identical to regular file write except that
      the write length is capped by the inode size and @off is passed to the
      write method.  This patch adds bin file handling to sysfs_write_file()
      so that it can handle both regular and bin files.
      
      A new file_operations struct sysfs_bin_operations is added, which
      currently only hosts sysfs_write_file() and generic_file_llseek().
      This isn't used yet but will eventually replace fs/sysfs/bin.c.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f9b9a621