04 Oct, 2015

1 commit


18 Jul, 2015

1 commit

  • Using __printf attributes helps to detect several format string issues
    at compile time (even though -Wformat-security is currently disabled in
    Makefile). For example it can detect when formatting a pointer as a
    number, like the issue fixed in commit a3fa71c40f18 ("wl18xx: show
    rx_frames_per_rates as an array as it really is"), or when the arguments
    do not match the format string, c.f. for example commit 5ce1aca81435
    ("reiserfs: fix __RASSERT format string").

    To prevent similar bugs in the future, add a __printf attribute to every
    function prototype which needs one in include/linux/ and lib/. These
    functions were mostly found by using gcc's -Wsuggest-attribute=format
    flag.

    Signed-off-by: Nicolas Iooss
    Cc: Greg Kroah-Hartman
    Cc: Felipe Balbi
    Cc: Joel Becker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Nicolas Iooss
     

26 Apr, 2014

1 commit


04 Apr, 2014

1 commit

  • Currently kobject_uevent has somewhat unpredictable semantics. The
    point is, since it may call a usermode helper and wait for it to execute
    (UMH_WAIT_EXEC), it is impossible to say for sure what lock dependencies
    it will introduce for the caller - strictly speaking it depends on what
    fs the binary is located on and the set of locks fork may take. There
    are quite a few kobject_uevent's users that do not take this into
    account and call it with various mutexes taken, e.g. rtnl_mutex,
    net_mutex, which might potentially lead to a deadlock.

    Since there is actually no reason to wait for the usermode helper to
    execute there, let's make kobject_uevent start the helper asynchronously
    with the aid of the UMH_NO_WAIT flag.

    Personally, I'm interested in this, because I really want kobject_uevent
    to be called under the slab_mutex in the slub implementation as it used
    to be some time ago, because it greatly simplifies synchronization and
    automatically fixes a kmemcg-related race. However, there was a
    deadlock detected on an attempt to call kobject_uevent under the
    slab_mutex (see https://lkml.org/lkml/2012/1/14/45), which was reported
    to be fixed by releasing the slab_mutex for kobject_uevent.

    Unfortunately, there was no information about who exactly blocked on the
    slab_mutex causing the usermode helper to stall, neither have I managed
    to find this out or reproduce the issue.

    BTW, this is not the first attempt to make kobject_uevent use
    UMH_NO_WAIT. Previous one was made by commit f520360d93cd ("kobject:
    don't block for each kobject_uevent"), but it was wrong (it passed
    arguments allocated on stack to async thread) so it was reverted in
    05f54c13cd0c ("Revert "kobject: don't block for each kobject_uevent".").
    It targeted on speeding up the boot process though.

    Signed-off-by: Vladimir Davydov
    Cc: Greg KH
    Cc: Christoph Lameter
    Cc: Pekka Enberg
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Vladimir Davydov
     

12 Dec, 2013

1 commit

  • 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: Tejun Heo
    Cc: Neil Brown
    Cc: Linus Walleij
    Cc: Ashutosh Dixit
    Cc: kbuild test robot
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     

27 Sep, 2013

1 commit

  • 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: Tejun Heo
    Cc: Eric W. Biederman
    Cc: Kay Sievers
    Signed-off-by: Greg Kroah-Hartman

    Tejun Heo
     

26 Jul, 2013

1 commit

  • Implement debugging for kobject release functions. kobjects are
    reference counted, so the drop of the last reference to them is not
    predictable. However, the common case is for the last reference to be
    the kobject's removal from a subsystem, which results in the release
    function being immediately called.

    This can hide subtle bugs, which can occur when another thread holds a
    reference to the kobject at the same time that a kobject is removed.
    This results in the release method being delayed.

    In order to make these kinds of problems more visible, the following
    patch implements a delayed release; this has the effect that the
    release function will be out of order with respect to the removal of
    the kobject in the same manner that it would be if a reference was
    being held.

    This provides us with an easy way to allow driver writers to debug
    their drivers and fix otherwise hidden problems.

    Signed-off-by: Russell King
    Signed-off-by: Greg Kroah-Hartman

    Russell King
     

29 Nov, 2012

1 commit


07 Sep, 2012

1 commit

  • Fengguang Wu writes:

    > After the __devinit* removal series, I can still get kernel panic in
    > show_uevent(). So there are more sources of bug..
    >
    > Debug patch:
    >
    > @@ -343,8 +343,11 @@ static ssize_t show_uevent(struct device
    > goto out;
    >
    > /* copy keys to file */
    > - for (i = 0; i < env->envp_idx; i++)
    > + dev_err(dev, "uevent %d env[%d]: %s/.../%s\n", env->buflen, env->envp_idx, top_kobj->name, dev->kobj.name);
    > + for (i = 0; i < env->envp_idx; i++) {
    > + printk(KERN_ERR "uevent %d env[%d]: %s\n", (int)count, i, env->envp[i]);
    > count += sprintf(&buf[count], "%s\n", env->envp[i]);
    > + }
    >
    > Oops message, the env[] is again not properly initilized:
    >
    > [ 44.068623] input input0: uevent 61 env[805306368]: input0/.../input0
    > [ 44.069552] uevent 0 env[0]: (null)

    This is a completely different CONFIG_HOTPLUG problem, only
    demonstrating another reason why CONFIG_HOTPLUG should go away. I had a
    hard time trying to disable it anyway ;-)

    The problem this time is lots of code assuming that a call to
    add_uevent_var() will guarantee that env->buflen > 0. This is not true
    if CONFIG_HOTPLUG is unset. So things like this end up overwriting
    env->envp_idx because the array index is -1:

    if (add_uevent_var(env, "MODALIAS="))
    return -ENOMEM;
    len = input_print_modalias(&env->buf[env->buflen - 1],
    sizeof(env->buf) - env->buflen,
    dev, 0);

    Don't know what the best action is, given that there seem to be a *lot*
    of this around the kernel. This patch "fixes" the problem for me, but I
    don't know if it can be considered an appropriate fix.

    [ It is the correct fix for now, for 3.7 forcing CONFIG_HOTPLUG to
    always be on is the longterm fix, but it's too late for 3.6 and older
    kernels to resolve this that way - gregkh ]

    Reported-by: Fengguang Wu
    Signed-off-by: Bjørn Mork
    Tested-by: Fengguang Wu
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Bjørn Mork
     

22 Dec, 2011

1 commit


01 Nov, 2011

1 commit

  • Standardize the style for compiler based printf format verification.
    Standardized the location of __printf too.

    Done via script and a little typing.

    $ grep -rPl --include=*.[ch] -w "__attribute__" * | \
    grep -vP "^(tools|scripts|include/linux/compiler-gcc.h)" | \
    xargs perl -n -i -e 'local $/; while (<>) { s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.+)\s*,\s*(.+)\s*\)\s*\)\s*\)/__printf($1, $2)/g ; print; }'

    [akpm@linux-foundation.org: revert arch bits]
    Signed-off-by: Joe Perches
    Cc: "Kirill A. Shutemov"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Joe Perches
     

27 Jul, 2011

1 commit

  • This allows us to move duplicated code in
    (atomic_inc_not_zero() for now) to

    Signed-off-by: Arun Sharma
    Reviewed-by: Eric Dumazet
    Cc: Ingo Molnar
    Cc: David Miller
    Cc: Eric Dumazet
    Acked-by: Mike Frysinger
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Arun Sharma
     

19 Feb, 2011

1 commit

  • When CONFIG_HOTPLUG is not enabled, the inline function add_uevent_var()
    needs to have its __attribute__ before the function name/parameters,
    otherwise there are syntax errors.

    linux-next-20110207/include/linux/kobject.h:232: error: expected ',' or ';' before '{' token

    Signed-off-by: Randy Dunlap
    Signed-off-by: Greg Kroah-Hartman

    Randy Dunlap
     

04 Feb, 2011

1 commit


23 Oct, 2010

1 commit

  • One call chain getting to kset_find_obj is:
    link_mem_sections()
    find_mem_section()
    kset_find_obj()

    This is done during boot. The memory sections were added in a linearly
    increasing order and link_mem_sections tends to utilize them in that
    same linear order.

    Introduce a kset_find_obj_hinted which is passed the result of the
    previous kset_find_obj which it uses for a quick "is the next object
    our desired object" check before falling back to the old behavior.

    Signed-off-by: Robin Holt
    To: Robert P. J. Day
    Reviewed-by: KAMEZAWA Hiroyuki
    Signed-off-by: Greg Kroah-Hartman

    Robin Holt
     

24 Aug, 2010

1 commit


22 May, 2010

3 commits

  • The problem. Network devices show up in sysfs and with the network
    namespace active multiple devices with the same name can show up in
    the same directory, ouch!

    To avoid that problem and allow existing applications in network namespaces
    to see the same interface that is currently presented in sysfs, this
    patch enables the tagging directory support in sysfs.

    By using the network namespace pointers as tags to separate out the
    the sysfs directory entries we ensure that we don't have conflicts
    in the directories and applications only see a limited set of
    the network devices.

    Signed-off-by: Eric W. Biederman
    Acked-by: David S. Miller
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     
  • Add some in-line comments to explain the new infrastructure, which
    was introduced to support sysfs directory tagging with namespaces.
    I think an overall description someplace might be good too, but it
    didn't really seem to fit into Documentation/filesystems/sysfs.txt,
    which appears more geared toward users, rather than maintainers, of
    sysfs.

    (Tejun, please let me know if I can make anything clearer or failed
    altogether to comment something that should be commented.)

    Signed-off-by: Serge E. Hallyn
    Cc: Eric W. Biederman
    Cc: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Serge E. Hallyn
     
  • Move complete knowledge of namespaces into the kobject layer
    so we can use that information when reporting kobjects to
    userspace.

    Signed-off-by: Eric W. Biederman
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     

08 Mar, 2010

2 commits

  • Constify struct sysfs_ops.

    This is part of the ops structure constification
    effort started by Arjan van de Ven et al.

    Benefits of this constification:

    * prevents modification of data that is shared
    (referenced) by many other structure instances
    at runtime

    * detects/prevents accidental (but not intentional)
    modification attempts on archs that enforce
    read-only kernel data at runtime

    * potentially better optimized code as the compiler
    can assume that the const data cannot be changed

    * the compiler/linker move const data into .rodata
    and therefore exclude them from false sharing

    Signed-off-by: Emese Revfy
    Acked-by: David Teigland
    Acked-by: Matt Domsch
    Acked-by: Maciej Sosnowski
    Acked-by: Hans J. Koch
    Acked-by: Pekka Enberg
    Acked-by: Jens Axboe
    Acked-by: Stephen Hemminger
    Signed-off-by: Greg Kroah-Hartman

    Emese Revfy
     
  • Constify struct kset_uevent_ops.

    This is part of the ops structure constification
    effort started by Arjan van de Ven et al.

    Benefits of this constification:

    * prevents modification of data that is shared
    (referenced) by many other structure instances
    at runtime

    * detects/prevents accidental (but not intentional)
    modification attempts on archs that enforce
    read-only kernel data at runtime

    * potentially better optimized code as the compiler
    can assume that the const data cannot be changed

    * the compiler/linker move const data into .rodata
    and therefore exclude them from false sharing

    Signed-off-by: Emese Revfy
    Signed-off-by: Greg Kroah-Hartman

    Emese Revfy
     

25 Mar, 2009

2 commits

  • This patch implements uevent suppress in kobject and removes it
    from struct device, based on the following ideas:

    1,Uevent sending should be one attribute of kobject, so suppressing it
    in kobject layer is more natural than in device layer. By this way,
    we can do it for other objects embedded with kobject.

    2,It may save several bytes for each instance of struct device.(On my
    omap3(32bit ARM) based box, can save 8bytes per device object)

    This patch also introduces dev_set|get_uevent_suppress() helpers to
    set and query uevent_suppress attribute in case to help kobject
    as private part of struct device in future.

    [This version is against the latest driver-core patch set of Greg,please
    ignore the last version.]

    Signed-off-by: Ming Lei
    Signed-off-by: Greg Kroah-Hartman

    Ming Lei
     
  • Now that all users of bus_id is gone, we can remove it from struct
    device.

    Signed-off-by: Kay Sievers
    Signed-off-by: Greg Kroah-Hartman

    Kay Sievers
     

25 Jul, 2008

1 commit

  • Add a kobject to create /sys/kernel/mm when sysfs is mounted. The kobject
    will exist regardless. This will allow for the hugepage related sysfs
    directories to exist under the mm "subsystem" directory. Add an ABI file
    appropriately.

    [kosaki.motohiro@jp.fujitsu.com: fix build]
    Signed-off-by: Nishanth Aravamudan
    Cc: Nick Piggin
    Cc: Mel Gorman
    Signed-off-by: KOSAKI Motohiro
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Nishanth Aravamudan
     

22 Jul, 2008

2 commits


30 Apr, 2008

1 commit


25 Jan, 2008

13 commits