17 Oct, 2013

12 commits


15 Oct, 2013

1 commit

  • While looking at the code, I noticed that bin_attribute read() and write()
    ops copy the inode size into an int for futher comparisons.

    Some bin_attributes can be fairly large. For example, pci creates some for
    BARs set to the BAR size and giant BARs are around the corner, so this is
    going to break something somewhere eventually.

    Let's use the right type.

    [adjust for seqfile conversions, only needed for bin_read() - gkh]

    Signed-off-by: Benjamin Herrenschmidt
    Cc: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Benjamin Herrenschmidt
     

14 Oct, 2013

1 commit

  • 375b611e60 ("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:
    [] dump_stack+0x4e/0x82
    [] warn_slowpath_common+0x7d/0xa0
    [] warn_slowpath_null+0x1a/0x20
    [] sysfs_file_ops+0x4e/0x60
    [] sysfs_open_file+0x54/0x300
    [] do_dentry_open.isra.17+0x182/0x280
    [] finish_open+0x30/0x40
    [] do_last+0x503/0xd90
    [] path_openat+0xbb/0x6d0
    [] do_filp_open+0x3a/0x90
    [] do_sys_open+0x129/0x220
    [] SyS_open+0x1e/0x20
    [] 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: Tejun Heo
    Reported-by: Yinghai Lu
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     

12 Oct, 2013

1 commit

  • Useful for locating buggy drivers on kernel oops.

    It may add dozens of new lines to boot dmesg. DEBUG_KOBJECT_RELEASE is
    hopefully only enabled in debug kernels (like maybe the Fedora rawhide
    one, or at developers), so being a bit more verbose is likely ok.

    Signed-off-by: Fengguang Wu
    Acked-by: Russell King
    Signed-off-by: Greg Kroah-Hartman

    Fengguang Wu
     

06 Oct, 2013

17 commits

  • No in-kernel code is now using this, they have all be converted over to
    using the bin_attrs support in attribute groups, so this field, and the
    code in the driver core that was creating/remove the binary files can be
    removed.

    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     
  • Now that all in-kernel users of the dev_attrs field are converted to use
    dev_groups, we can safely remove dev_attrs from struct class.

    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     
  • 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: Tejun Heo
    Cc: Kay Sievers
    Cc: kbuild test robot
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • read() is simple enough and fill_read() being in a separate function
    doesn't add anything. Let's collapse it into read(). This will make
    merging bin file handling with regular file.

    Signed-off-by: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • After b31ca3f5dfc ("sysfs: fix deadlock"), bin read() first writes
    data to bb->buffer and bounces it to a transient kernel buffer which
    is then copied out to userland. The double bouncing doesn't add
    anything. Let's just use the transient buffer directly.

    While at it, rename @temp to @buf for clarity.

    Signed-off-by: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • sysfs read path implements its own buffering scheme between userland
    and kernel callbacks, which essentially is a degenerate duplicate of
    seq_file. This patch replaces the custom read buffering
    implementation in sysfs with seq_file.

    While the amount of code reduction is small, this reduces low level
    hairiness and enables future development of a new versatile API based
    on seq_file so that sysfs features can be shared with other
    subsystems.

    As write path was already converted to not use sysfs_open_file->page,
    this patch makes ->page and ->count unused and removes them.

    Userland behavior remains the same except for some extreme corner
    cases - e.g. sysfs will now regenerate the content each time a file is
    read after a non-contiguous seek whereas the original code would keep
    using the same content. While this is a userland visible behavior
    change, it is extremely unlikely to be noticeable and brings sysfs
    behavior closer to that of procfs.

    Signed-off-by: Tejun Heo
    Cc: Kay Sievers
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • There isn't much to be gained by keeping around kernel buffer while a
    file is open especially as the read path planned to be converted to
    use seq_file and won't use the buffer. This patch makes
    sysfs_write_file() use per-write transient buffer instead of
    sysfs_open_file->page.

    This simplifies the write path, enables removing sysfs_open_file->page
    once read path is updated and will help merging bin file write path
    which already requires the use of a transient buffer due to a locking
    order issue.

    As the function comments of flush_write_buffer() and
    sysfs_write_buffer() are being updated anyway, reformat them so that
    they're more conventional.

    v2: Use min_t() instead of min() in sysfs_write_file() to avoid build
    warning on arm. Reported by build test robot.

    Signed-off-by: Tejun Heo
    Cc: kbuild test robot
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • sysfs will be converted to use seq_file for read path, which will make
    it difficult to pass around multiple pointers directly. This patch
    adds sysfs_open_file->sd and ->file so that we can reach all the
    necessary data structures from sysfs_open_file.

    flush_write_buffer() is updated to drop @dentry which was used to
    discover the sysfs_dirent as it's now available through
    sysfs_open_file->sd.

    This patch doesn't cause any behavior difference.

    Signed-off-by: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • sysfs read path will be converted to use seq_file which will handle
    buffering making sysfs_buffer a misnomer. Rename sysfs_buffer to
    sysfs_open_file, and sysfs_open_dirent->buffers to ->files.

    This path is pure rename.

    Signed-off-by: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • Add a separate mutex to protect sysfs_open_dirent->buffers list. This
    will allow performing sleepable operations while traversing
    sysfs_buffers, which will be renamed to sysfs_open_file.

    Note that currently sysfs_open_dirent->buffers list isn't being used
    for anything and this patch doesn't make any functional difference.
    It will be used to merge regular and bin file supports.

    Signed-off-by: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • Currently, sysfs_ops is fetched during sysfs_open_file() and cached in
    sysfs_buffer->ops to be used while the file is open. This patch
    removes the caching and makes each operation directly fetch sysfs_ops.

    This patch doesn't introduce any behavior difference and is to prepare
    for merging regular and bin file supports.

    Signed-off-by: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • ->needs_read_fill is used to implement the following behaviors.

    1. Ensure buffer filling on the first read.
    2. Force buffer filling after a write.
    3. Force buffer filling after a successful poll.

    However, #2 and #3 don't really work as sysfs doesn't reset file
    position. While the read buffer would be refilled, the next read
    would continue from the position after the last read or write,
    requiring an explicit seek to the start for it to be useful, which
    makes ->needs_read_fill superflous as read buffer is always refilled
    if f_pos == 0.

    Update sysfs_read_file() to test buffer->page for #1 instead and
    remove ->needs_read_fill. While this changes behavior in extreme
    corner cases - e.g. re-reading a sysfs file after seeking to non-zero
    position after a write or poll, it's highly unlikely to lead to actual
    breakage. This change is to prepare for using seq_file in the read
    path.

    While at it, reformat a comment in fill_write_buffer().

    Signed-off-by: Tejun Heo
    Cc: Kay Sievers
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • Signed-off-by: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     

04 Oct, 2013

5 commits

  • Given a sysfs_dirent, there is no reason to have multiple versions of
    removal functions. A function which removes the specified
    sysfs_dirent and its descendants is enough.

    This patch intorduces [__}sysfs_remove() which replaces all internal
    variations of removal functions. This will be the only removal
    function in the planned new sysfs_dirent based interface.

    Signed-off-by: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    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: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     
  • Two function declarations are absence if not define CONFIG_DEBUG_FS
    in include/linux/debugfs.h

    Signed-off-by: Weijie Yang
    Signed-off-by: Greg Kroah-Hartman

    Weijie Yang
     

30 Sep, 2013

3 commits

  • We want the driver core and sysfs fixes in here to make merges and
    development easier.

    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     
  • Linus Torvalds
     
  • Pull USB fixes from Greg KH:
    "Here are a number of USB driver fixes for 3.12-rc3.

    These are all for host controller issues that have been reported, and
    there's a fix for an annoying error message that gets printed every
    time you remove a USB 3 device from the system that's been bugging me
    for a while"

    * tag 'usb-3.12-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb:
    usb: dwc3: add support for Merrifield
    USB: fsl/ehci: fix failure of checking PHY_CLK_VALID during reinitialization
    USB: Fix breakage in ffs_fs_mount()
    fsl/usb: Resolve PHY_CLK_VLD instability issue for ULPI phy
    usb/core/devio.c: Don't reject control message to endpoint with wrong direction bit
    usb: chipidea: USB_CHIPIDEA should depend on HAS_DMA
    usb: chipidea: udc: free pending TD at removal procedure
    usb: chipidea: imx: Add usb_phy_shutdown at probe's error path
    usb: chipidea: Fix memleak for ci->hw_bank.regmap when removal
    usb: chipidea: udc: fix the oops after rmmod gadget
    USB: fix PM config symbol in uhci-hcd, ehci-hcd, and xhci-hcd
    USB: OHCI: accept very late isochronous URBs
    USB: UHCI: accept very late isochronous URBs
    USB: iMX21: accept very late isochronous URBs
    usbcore: check usb device's state before sending a Set SEL control transfer
    xhci: Fix race between ep halt and URB cancellation
    usb: Fix xHCI host issues on remote wakeup.
    xhci: Ensure a command structure points to the correct trb on the command ring
    xhci: Fix oops happening after address device timeout

    Linus Torvalds