13 Nov, 2013

3 commits

  • We already have list_first_entry(), it makes sense to also add
    list_last_entry() for consistency. And we use both helpers in
    list_for_each_*().

    Signed-off-by: Oleg Nesterov
    Cc: Eilon Greenstein
    Cc: Greg Kroah-Hartman
    Cc: Peter Zijlstra
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     
  • Now that we have list_{next,prev}_entry() we can change
    list_for_each_entry*() and list_safe_reset_next() to use the new helpers
    to improve the readability.

    Signed-off-by: Oleg Nesterov
    Cc: Eilon Greenstein
    Cc: Greg Kroah-Hartman
    Cc: Peter Zijlstra
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     
  • Add two trivial helpers list_next_entry() and list_prev_entry(), they
    can have a lot of users including list.h itself. In fact the 1st one is
    already defined in events/core.c and bnx2x_sp.c, so the patch simply
    moves the definition to list.h.

    Signed-off-by: Oleg Nesterov
    Cc: Eilon Greenstein
    Cc: Greg Kroah-Hartman
    Cc: Peter Zijlstra
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     

17 Jul, 2013

1 commit

  • __list_for_each used to be the non prefetch() aware list walking
    primitive. When we removed the prefetch macros from the list routines,
    it became redundant. Given it does exactly the same thing as
    list_for_each now, we might as well remove it and call list_for_each
    directly.

    All users of __list_for_each have been converted to list_for_each calls
    in the current merge window.

    Signed-off-by: Dave Jones
    Signed-off-by: Linus Torvalds

    Dave Jones
     

01 Jun, 2013

1 commit


15 Mar, 2013

1 commit

  • The current version of hlist_entry_safe() fetches the pointer twice,
    once to test for NULL and the other to compute the offset back to the
    enclosing structure. This is OK for normal lock-based use because in
    that case, the pointer cannot change. However, when the pointer is
    protected by RCU (as in "rcu_dereference(p)"), then the pointer can
    change at any time. This use case can result in the following sequence
    of events:

    1. CPU 0 invokes hlist_entry_safe(), fetches the RCU-protected
    pointer as sees that it is non-NULL.

    2. CPU 1 invokes hlist_del_rcu(), deleting the entry that CPU 0
    just fetched a pointer to. Because this is the last entry
    in the list, the pointer fetched by CPU 0 is now NULL.

    3. CPU 0 refetches the pointer, obtains NULL, and then gets a
    NULL-pointer crash.

    This commit therefore applies gcc's "({ })" statement expression to
    create a temporary variable so that the specified pointer is fetched
    only once, avoiding the above sequence of events. Please note that
    it is the caller's responsibility to use rcu_dereference() as needed.
    This allows RCU-protected uses to work correctly without imposing
    any additional overhead on the non-RCU case.

    Many thanks to Eric Dumazet for spotting root cause!

    Reported-by: CAI Qian
    Reported-by: Eric Dumazet
    Signed-off-by: Paul E. McKenney
    Tested-by: Li Zefan

    Paul E. McKenney
     

28 Feb, 2013

1 commit

  • I'm not sure why, but the hlist for each entry iterators were conceived

    list_for_each_entry(pos, head, member)

    The hlist ones were greedy and wanted an extra parameter:

    hlist_for_each_entry(tpos, pos, head, member)

    Why did they need an extra pos parameter? I'm not quite sure. Not only
    they don't really need it, it also prevents the iterator from looking
    exactly like the list iterator, which is unfortunate.

    Besides the semantic patch, there was some manual work required:

    - Fix up the actual hlist iterators in linux/list.h
    - Fix up the declaration of other iterators based on the hlist ones.
    - A very small amount of places were using the 'node' parameter, this
    was modified to use 'obj->member' instead.
    - Coccinelle didn't handle the hlist_for_each_entry_safe iterator
    properly, so those had to be fixed up manually.

    The semantic patch which is mostly the work of Peter Senna Tschudin is here:

    @@
    iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;

    type T;
    expression a,c,d,e;
    identifier b;
    statement S;
    @@

    -T b;

    [akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
    [akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
    [akpm@linux-foundation.org: checkpatch fixes]
    [akpm@linux-foundation.org: fix warnings]
    [akpm@linux-foudnation.org: redo intrusive kvm changes]
    Tested-by: Peter Senna Tschudin
    Acked-by: Paul E. McKenney
    Signed-off-by: Sasha Levin
    Cc: Wu Fengguang
    Cc: Marcelo Tosatti
    Cc: Gleb Natapov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sasha Levin
     

20 May, 2011

2 commits

  • This is removes the use of software prefetching from the regular list
    iterators. We don't want it. If you do want to prefetch in some
    iterator of yours, go right ahead. Just don't expect the iterator to do
    it, since normally the downsides are bigger than the upsides.

    It also replaces with , because the
    use of LIST_POISON ends up needing it. is sadly not
    self-contained, and including prefetch.h just happened to hide that.

    Suggested by David Miller (networking has a lot of regular lists that
    are often empty or a single entry, and prefetching is not going to do
    anything but add useless instructions).

    Acked-by: Ingo Molnar
    Acked-by: David S. Miller
    Cc: linux-arch@vger.kernel.org
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     
  • They not only increase the code footprint, they actually make things
    slower rather than faster. On internationally acclaimed benchmarks
    ("make -j16" on an already fully built kernel source tree) the hlist
    prefetching slows down the build by up to 1%.

    (Almost all of it comes from hlist_for_each_entry_rcu() as used by
    avc_has_perm_noaudit(), which is very hot due to all the pathname
    lookups to see if there is anything to do).

    The cause seems to be two-fold:

    - on at least some Intel cores, prefetch(NULL) ends up with some
    microarchitectural stall due to the TLB miss that it incurs. The
    hlist case triggers this very commonly, since the NULL pointer is the
    last entry in the list.

    - the prefetch appears to cause more D$ activity, probably because it
    prefetches hash list entries that are never actually used (because we
    ended the search early due to a hit).

    Regardless, the numbers clearly say that the implicit prefetching is
    simply a bad idea. If some _particular_ user of the hlist iterators
    wants to prefetch the next list entry, they can do so themselves
    explicitly, rather than depend on all list iterators doing so
    implicitly.

    Acked-by: Ingo Molnar
    Acked-by: David S. Miller
    Cc: linux-arch@vger.kernel.org
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

19 Feb, 2011

1 commit

  • When list debugging is enabled, we aim to readably show list corruption
    errors, and the basic list_add/list_del operations end up having extra
    debugging code in them to do some basic validation of the list entries.

    However, "list_del_init()" and "list_move[_tail]()" ended up avoiding
    the debug code due to how they were written. This fixes that.

    So the _next_ time we have list_move() problems with stale list entries,
    we'll hopefully have an easier time finding them..

    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

26 Oct, 2010

1 commit


07 Oct, 2010

1 commit

  • Drop inclusions of asm/system.h from linux/hardirq.h and linux/list.h as
    they're no longer required and prevent the M68K arch's IRQ flag handling macros
    from being made into inlined functions due to circular dependencies.

    Signed-off-by: David Howells
    Acked-by: Greg Ungerer
    Acked-by: Geert Uytterhoeven

    David Howells
     

07 Jul, 2010

2 commits


30 Jun, 2010

1 commit

  • list_for_each_entry_safe is not suitable to protect against concurrent
    modification of the list. 6754af6 introduced a race in sb walking.

    list_for_each_entry can use the trick of pinning the current entry in
    the list before we drop and retake the lock because it subsequently
    follows cur->next. However list_for_each_entry_safe saves n=cur->next
    for following before entering the loop body, so when the lock is
    dropped, n may be deleted.

    Signed-off-by: Nick Piggin
    Cc: Christoph Hellwig
    Cc: John Stultz
    Cc: Frank Mayhar
    Cc: Al Viro
    Signed-off-by: Linus Torvalds

    npiggin@suse.de
     

07 Mar, 2010

1 commit


16 Jan, 2010

1 commit

  • Bring a new list_rotate_left() helper that rotates a list to
    the left. This is useful for codes that need to round roubin
    elements which queue priority increases from tail to head.

    Signed-off-by: Frederic Weisbecker
    Acked-by: Peter Zijlstra
    Cc: Paul Mackerras
    Cc: Ingo Molnar
    Cc: Arnaldo Carvalho de Melo

    Frederic Weisbecker
     

01 Sep, 2008

1 commit

  • Daniel J. Blueman reported:
    > =======================================================
    > [ INFO: possible circular locking dependency detected ]
    > 2.6.27-rc4-224c #1
    > -------------------------------------------------------
    > hald/4680 is trying to acquire lock:
    > (&n->list_lock){++..}, at: [] add_partial+0x26/0x80
    >
    > but task is already holding lock:
    > (&obj_hash[i].lock){++..}, at: []
    > debug_object_free+0x5c/0x120

    We fix it by moving the actual freeing to outside the lock (the lock
    now only protects the list).

    The pool lock is also promoted to irq-safe (suggested by Dan). It's
    necessary because free_pool is now called outside the irq disabled
    region. So we need to protect against an interrupt handler which calls
    debug_object_init().

    [tglx@linutronix.de: added hlist_move_list helper to avoid looping
    through the list twice]

    Reported-by: Daniel J Blueman
    Signed-off-by: Vegard Nossum
    Signed-off-by: Thomas Gleixner

    Vegard Nossum
     

09 Aug, 2008

1 commit

  • Fix fatal multi-line kernel-doc error in list.h:
    function short description must be on one line.

    Error(linux-2.6.27-rc2-git3//include/linux/list.h:318): duplicate section name 'Description'

    Signed-off-by: Randy Dunlap
    Signed-off-by: Linus Torvalds

    Randy Dunlap
     

07 Aug, 2008

2 commits


26 Jul, 2008

1 commit

  • Remove the conditional surrounding the definition of list_add() from list.h
    since, if you define CONFIG_DEBUG_LIST, the definition you will subsequently
    pick up from lib/list_debug.c will be absolutely identical, at which point you
    can remove that redundant definition from list_debug.c as well.

    Signed-off-by: Robert P. J. Day
    Cc: Dave Jones
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Robert P. J. Day
     

19 May, 2008

1 commit

  • Move rcu-protected lists from list.h into a new header file rculist.h.

    This is done because list are a very used primitive structure all over the
    kernel and it's currently impossible to include other header files in this
    list.h without creating some circular dependencies.

    For example, list.h implements rcu-protected list and uses rcu_dereference()
    without including rcupdate.h. It actually compiles because users of
    rcu_dereference() are macros. Others RCU functions could be used too but
    aren't probably because of this.

    Therefore this patch creates rculist.h which includes rcupdates without to
    many changes/troubles.

    Signed-off-by: Franck Bui-Huu
    Acked-by: Paul E. McKenney
    Acked-by: Josh Triplett
    Signed-off-by: Andrew Morton
    Signed-off-by: Ingo Molnar

    Franck Bui-Huu
     

30 Apr, 2008

1 commit


29 Apr, 2008

1 commit


28 Apr, 2008

1 commit

  • Add list_is_singular() to check a list has just one entry.

    list_is_singular() is useful to check whether a list_head which have been
    temporarily allocated for listing objects can be released or not.

    Signed-off-by: Masami Hiramatsu
    Cc: Peter Zijlstra
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Masami Hiramatsu
     

21 Apr, 2008

1 commit

  • The RCU iterators used 'rcu_dereference()' on an already-fetched RCU
    pointer value, which defeats the whole point of the exercise.

    When we dereference a pointer protected by RCU, we need to make sure
    that we only fetch the value _once_, because if the compiler ends up
    re-loading it due to register pressure, the newly reloaded value could
    be different from the previously fetched one, and you get inconsistent
    results.

    Cleaned-up, fixed, and the pointless list_for_each_safe_rcu #define
    deleted by Paul Kenney.

    Acked-by: Herbert Xu
    Signed-off-by: Paul E. McKenney
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

20 Oct, 2007

1 commit

  • Fix kernel-api docbook contents problems.

    docproc: linux-2.6.23-git13/include/asm-x86/unaligned_32.h: No such file or directory
    Warning(linux-2.6.23-git13//include/linux/list.h:482): bad line: of list entry
    Warning(linux-2.6.23-git13//mm/filemap.c:864): No description found for parameter 'ra'
    Warning(linux-2.6.23-git13//block/ll_rw_blk.c:3760): No description found for parameter 'req'
    Warning(linux-2.6.23-git13//include/linux/input.h:1077): No description found for parameter 'private'
    Warning(linux-2.6.23-git13//include/linux/input.h:1077): No description found for parameter 'cdev'

    Signed-off-by: Randy Dunlap
    Cc: Jens Axboe
    Cc: WU Fengguang
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Randy Dunlap
     

17 Oct, 2007

1 commit

  • This patch makes shrink_dcache_sb consistent with dentry pruning policy.

    On the first pass we iterate over dentry unused list and prepare some
    dentries for removal.

    However, since the existing code moves evicted dentries to the beginning of
    the LRU it can happen that fresh dentries from other superblocks will be
    inserted *before* our dentries.

    This can result in significant slowdown of shrink_dcache_sb(). Moreover,
    for virtual filesystems like unionfs which can call dput() during dentries
    kill existing code results in O(n^2) complexity.

    We observed 2 minutes shrink_dcache_sb() with only 35000 dentries.

    To avoid this effects we propose to isolate sb dentries at the end
    of LRU list.

    Signed-off-by: Denis V. Lunev
    Signed-off-by: Kirill Korotaev
    Signed-off-by: Andrey Mirkin
    Cc: Neil Brown
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Denis V. Lunev
     

11 Oct, 2007

1 commit

  • I proposed introducing a list_for_each_entry_continue_reverse macro
    to be used in setup_net() when unrolling the failed ->init callback.

    Here is the macro and some more cleanup in the setup_net() itself
    to remove one variable from the stack :) The same thing is for the
    cleanup_net() - the existing list_for_each_entry_reverse() is used.

    Minor, but the code looks nicer.

    Signed-off-by: Pavel Emelyanov
    Acked-by: "Eric W. Biederman"
    Signed-off-by: David S. Miller

    Pavel Emelyanov
     

13 May, 2007

1 commit


09 May, 2007

1 commit

  • There are many places in the kernel where the construction like

    foo = list_entry(head->next, struct foo_struct, list);

    are used.
    The code might look more descriptive and neat if using the macro

    list_first_entry(head, type, member) \
    list_entry((head)->next, type, member)

    Here is the macro itself and the examples of its usage in the generic code.
    If it will turn out to be useful, I can prepare the set of patches to
    inject in into arch-specific code, drivers, networking, etc.

    Signed-off-by: Pavel Emelianov
    Signed-off-by: Kirill Korotaev
    Cc: Randy Dunlap
    Cc: Andi Kleen
    Cc: Zach Brown
    Cc: Davide Libenzi
    Cc: John McCutchan
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: john stultz
    Cc: Ram Pai
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Pavel Emelianov
     

12 Feb, 2007

2 commits

  • A variety of (mostly) innocuous fixes to the embedded kernel-doc content in
    source files, including:

    * make multi-line initial descriptions single line
    * denote some function names, constants and structs as such
    * change erroneous opening '/*' to '/**' in a few places
    * reword some text for clarity

    Signed-off-by: Robert P. J. Day
    Cc: "Randy.Dunlap"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Robert P. J. Day
     
  • This patch is in support of the IPMI driver. I have tested this with the
    IPMI driver changes coming in the next patch.

    Add a list_splice_init_rcu() function to splice an RCU-protected list into
    another list. This takes the sync function as an argument, so one would do
    something like:

    INIT_LIST_HEAD(&list);
    list_splice_init_rcu(&source, &dest, synchronize_rcu);

    The idea being to keep the RCU API proliferation down to a dull roar.

    [akpm@osdl.org: build fix]
    Signed-off-by: Paul E. McKenney
    Signed-off-by: Corey Minyard
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Corey Minyard
     

27 Jan, 2007

1 commit


30 Sep, 2006

1 commit


15 Jul, 2006

1 commit


28 Jun, 2006

1 commit

  • Localize poison values into one header file for better documentation and
    easier/quicker debugging and so that the same values won't be used for
    multiple purposes.

    Use these constants in core arch., mm, driver, and fs code.

    Signed-off-by: Randy Dunlap
    Acked-by: Matt Mackall
    Cc: Paul Mackerras
    Cc: Benjamin Herrenschmidt
    Cc: "David S. Miller"
    Cc: Andi Kleen
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Randy Dunlap
     

26 Jun, 2006

2 commits

  • Use loop "cursor" instead of loop "counter" for list iterator descriptions.
    They are not counters, they are pointers or positions.

    Signed-off-by: Randy Dunlap
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Randy Dunlap
     
  • kernel-doc:

    Put all short function descriptions on one line or if they are too long,
    omit the short description & add a Description: section for them.

    Change some list iterator descriptions to use "current" point instead of
    "existing" point.

    Signed-off-by: Randy Dunlap
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Randy Dunlap