11 Jan, 2012

1 commit

  • We can place this in definitions that we expect the compiler to remove by
    dead code elimination. If this assertion fails, we get a nice error
    message at build time.

    The GCC function attribute error("message") was added in version 4.3, so
    we define a new macro __linktime_error(message) to expand to this for
    GCC-4.3 and later. This will give us an error diagnostic from the
    compiler on the line that fails. For other compilers
    __linktime_error(message) expands to nothing, and we have to be content
    with a link time error, but at least we will still get a build error.

    BUILD_BUG() expands to the undefined function __build_bug_failed() and
    will fail at link time if the compiler ever emits code for it. On GCC-4.3
    and later, attribute((error())) is used so that the failure will be noted
    at compile time instead.

    Signed-off-by: David Daney
    Acked-by: David Rientjes
    Cc: DM
    Cc: Ralf Baechle
    Acked-by: David Howells
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    David Daney
     

20 Aug, 2010

1 commit

  • This commit provides definitions for the __rcu annotation defined earlier.
    This annotation permits sparse to check for correct use of RCU-protected
    pointers. If a pointer that is annotated with __rcu is accessed
    directly (as opposed to via rcu_dereference(), rcu_assign_pointer(),
    or one of their variants), sparse can be made to complain. To enable
    such complaints, use the new default-disabled CONFIG_SPARSE_RCU_POINTER
    kernel configuration option. Please note that these sparse complaints are
    intended to be a debugging aid, -not- a code-style-enforcement mechanism.

    There are special rcu_dereference_protected() and rcu_access_pointer()
    accessors for use when RCU read-side protection is not required, for
    example, when no other CPU has access to the data structure in question
    or while the current CPU hold the update-side lock.

    This patch also updates a number of docbook comments that were showing
    their age.

    Signed-off-by: Arnd Bergmann
    Signed-off-by: Paul E. McKenney
    Cc: Christopher Li
    Reviewed-by: Josh Triplett

    Paul E. McKenney
     

15 Jun, 2010

1 commit

  • This commit defines an __rcu API, but provides only vacuous definitions
    for it. This breaks dependencies among most of the subsequent patches,
    allowing them to reach mainline asynchronously via whatever trees are
    appropriate.

    Signed-off-by: Arnd Bergmann
    Signed-off-by: Paul E. McKenney
    Cc: Christopher Li
    Cc: Josh Triplett

    Paul E. McKenney
     

05 Jan, 2010

1 commit


06 Dec, 2009

3 commits

  • * 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
    include/linux/compiler-gcc4.h: Fix build bug - gcc-4.0.2 doesn't understand __builtin_object_size
    x86/alternatives: No need for alternatives-asm.h to re-invent stuff already in asm.h
    x86/alternatives: Check replacementlen t use the strict copy checks when branch profiling is in use
    x86, 64-bit: Move K8 B step iret fixup to fault entry asm
    x86: Generate cmpxchg build failures
    x86: Add a Kconfig option to turn the copy_from_user warnings into errors
    x86: Turn the copy_from_user check into an (optional) compile time warning
    x86: Use __builtin_memset and __builtin_memcpy for memset/memcpy
    x86: Use __builtin_object_size() to validate the buffer size for copy_from_user()

    Linus Torvalds
     
  • …el/git/tip/linux-2.6-tip

    * 'tracing-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (40 commits)
    tracing: Separate raw syscall from syscall tracer
    ring-buffer-benchmark: Add parameters to set produce/consumer priorities
    tracing, function tracer: Clean up strstrip() usage
    ring-buffer benchmark: Run producer/consumer threads at nice +19
    tracing: Remove the stale include/trace/power.h
    tracing: Only print objcopy version warning once from recordmcount
    tracing: Prevent build warning: 'ftrace_graph_buf' defined but not used
    ring-buffer: Move access to commit_page up into function used
    tracing: do not disable interrupts for trace_clock_local
    ring-buffer: Add multiple iterations between benchmark timestamps
    kprobes: Sanitize struct kretprobe_instance allocations
    tracing: Fix to use __always_unused attribute
    compiler: Introduce __always_unused
    tracing: Exit with error if a weak function is used in recordmcount.pl
    tracing: Move conditional into update_funcs() in recordmcount.pl
    tracing: Add regex for weak functions in recordmcount.pl
    tracing: Move mcount section search to front of loop in recordmcount.pl
    tracing: Fix objcopy revision check in recordmcount.pl
    tracing: Check absolute path of input file in recordmcount.pl
    tracing: Correct the check for number of arguments in recordmcount.pl
    ...

    Linus Torvalds
     
  • Starting with version 4.5, GCC has a new built-in function
    __builtin_unreachable() that can be used in places like the kernel's
    BUG() where inline assembly is used to transfer control flow. This
    eliminated the need for an endless loop in these places.

    The patch adds a new macro 'unreachable()' that will expand to either
    __builtin_unreachable() or an endless loop depending on the compiler
    version.

    Change from v1: Simplify unreachable() for non-GCC 4.5 case.

    Signed-off-by: David Daney
    Acked-by: Ralf Baechle
    Signed-off-by: Linus Torvalds

    David Daney
     

02 Nov, 2009

1 commit

  • I wrote some code which is used as compile-time checker, and the
    code should be elided after compile.

    So I need to annotate the code as "always unused", compared to
    "maybe unused".

    Signed-off-by: Li Zefan
    Cc: Steven Rostedt
    Cc: Frederic Weisbecker
    Cc: Linus Torvalds
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Li Zefan
     

29 Oct, 2009

1 commit

  • We have to make __kernel "__attribute__((address_space(0)))" so we can
    cast to it.

    tj: * put_cpu_var() update.

    * Annotations added to dynamic allocator interface.

    Signed-off-by: Rusty Russell
    Cc: Al Viro
    Signed-off-by: Tejun Heo

    Rusty Russell
     

03 Oct, 2009

1 commit

  • For automated testing it is useful to have the option to turn
    the warnings on copy_from_user() etc checks into errors:

    In function ‘copy_from_user’,
    inlined from ‘fd_copyin’ at drivers/block/floppy.c:3080,
    inlined from ‘fd_ioctl’ at drivers/block/floppy.c:3503:
    linux/arch/x86/include/asm/uaccess_32.h:213:
    error: call to ‘copy_from_user_overflow’ declared with attribute error:
    copy_from_user buffer size is not provably correct

    Signed-off-by: Arjan van de Ven
    Cc: Linus Torvalds
    Cc: Andrew Morton
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Arjan van de Ven
     

01 Oct, 2009

1 commit

  • A previous patch added the buffer size check to copy_from_user().

    One of the things learned from analyzing the result of the previous
    patch is that in general, gcc is really good at proving that the
    code contains sufficient security checks to not need to do a
    runtime check. But that for those cases where gcc could not prove
    this, there was a relatively high percentage of real security
    issues.

    This patch turns the case of "gcc cannot prove" into a compile time
    warning, as long as a sufficiently new gcc is in use that supports
    this. The objective is that these warnings will trigger developers
    checking new cases out before a security hole enters a linux kernel
    release.

    Signed-off-by: Arjan van de Ven
    Cc: Linus Torvalds
    Cc: "David S. Miller"
    Cc: James Morris
    Cc: Jan Beulich
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Arjan van de Ven
     

26 Sep, 2009

1 commit

  • gcc (4.x) supports the __builtin_object_size() builtin, which
    reports the size of an object that a pointer point to, when known
    at compile time. If the buffer size is not known at compile time, a
    constant -1 is returned.

    This patch uses this feature to add a sanity check to
    copy_from_user(); if the target buffer is known to be smaller than
    the copy size, the copy is aborted and a WARNing is emitted in
    memory debug mode.

    These extra checks compile away when the object size is not known,
    or if both the buffer size and the copy length are constants.

    Signed-off-by: Arjan van de Ven
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Arjan van de Ven
     

12 Jun, 2009

1 commit


07 Apr, 2009

2 commits

  • Fix the branch tracer barfing on comma statements within if ()
    statements.

    Signed-off-by: Ingo Molnar

    Linus Torvalds
     
  • One of the changes between kernels 2.6.28 and 2.6.29 is that a branch profiler
    has been added for if() statements. Unfortunately this patch makes the sparse
    output unusable with CONFIG_TRACE_BRANCH_PROFILING=y: when branch profiling is
    enabled, sparse prints so much false positives that the real issues are no
    longer visible. This behavior can be reproduced as follows:
    * enable CONFIG_TRACE_BRANCH_PROFILING, e.g. by running make allyesconfig or
    make allmodconfig.
    * run make C=2

    Result: a huge number of the following sparse warnings.
    ...
    include/linux/cpumask.h:547:2: warning: symbol '______r' shadows an earlier one
    include/linux/cpumask.h:547:2: originally declared here
    ...

    The patch below fixes this by disabling branch profiling while analyzing the
    kernel code with sparse.

    See also:
    * http://lkml.org/lkml/2008/11/21/18
    * http://bugzilla.kernel.org/show_bug.cgi?id=12925

    Signed-off-by: Bart Van Assche
    Cc: Andrew Morton
    Cc: Steven Rostedt
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Bart Van Assche
     

18 Mar, 2009

1 commit

  • Impact: better performance for if branch tracer

    Use an array to count the hit and misses of a conditional instead
    of using another conditional. This cuts down on saturation of branch
    predictions and increases performance of modern pipelined architectures.

    Signed-off-by: Witold Baryluk
    Signed-off-by: Steven Rostedt

    Witold Baryluk
     

03 Jan, 2009

1 commit

  • - include the gcc version-dependent header files from the generic gcc
    header file, rather than the other way around (iow: don't make the
    non-gcc header file have to know about gcc versions)

    - don't include compiler-gcc4.h for gcc 5 (for whenever it gets
    released). That's just confusing and made us do odd things in the
    gcc4 header file (testing that we really had version 4!)

    - generate the name from the __GNUC__ version directly, rather than
    having a mess of #if conditionals.

    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

23 Nov, 2008

3 commits

  • Impact: feature to profile if statements

    This patch adds a branch profiler for all if () statements.
    The results will be found in:

    /debugfs/tracing/profile_branch

    For example:

    miss hit % Function File Line
    ------- --------- - -------- ---- ----
    0 1 100 x86_64_start_reservations head64.c 127
    0 1 100 copy_bootdata head64.c 69
    1 0 0 x86_64_start_kernel head64.c 111
    32 0 0 set_intr_gate desc.h 319
    1 0 0 reserve_ebda_region head.c 51
    1 0 0 reserve_ebda_region head.c 47
    0 1 100 reserve_ebda_region head.c 42
    0 0 X maxcpus main.c 165

    Miss means the branch was not taken. Hit means the branch was taken.
    The percent is the percentage the branch was taken.

    This adds a significant amount of overhead and should only be used
    by those analyzing their system.

    Signed-off-by: Steven Rostedt
    Signed-off-by: Ingo Molnar

    Steven Rostedt
     
  • Impact: clean up to make one profiler of like and unlikely tracer

    The likely and unlikely profiler prints out the file and line numbers
    of the annotated branches that it is profiling. It shows the number
    of times it was correct or incorrect in its guess. Having two
    different files or sections for that matter to tell us if it was a
    likely or unlikely is pretty pointless. We really only care if
    it was correct or not.

    Signed-off-by: Steven Rostedt
    Signed-off-by: Ingo Molnar

    Steven Rostedt
     
  • Impact: clean up of branch check

    The unlikely/likely profiler does an extra assign of the f.line.
    This is not needed since it is already calculated at compile time.

    Signed-off-by: Steven Rostedt
    Signed-off-by: Ingo Molnar

    Steven Rostedt
     

13 Nov, 2008

1 commit

  • Impact: name change of unlikely tracer and profiler

    Ingo Molnar suggested changing the config from UNLIKELY_PROFILE
    to BRANCH_PROFILING. I never did like the "unlikely" name so I
    went one step farther, and renamed all the unlikely configurations
    to a "BRANCH" variant.

    Signed-off-by: Steven Rostedt
    Signed-off-by: Ingo Molnar

    Steven Rostedt
     

12 Nov, 2008

2 commits

  • Impact: fix bootup crash

    the branch tracer missed arch/x86/vdso/vclock_gettime.c from
    disabling tracing, which caused such bootup crashes:

    [ 201.840097] init[1]: segfault at 7fffed3fe7c0 ip 00007fffed3fea2e sp 000077

    also clean up the ugly ifdefs in arch/x86/kernel/vsyscall_64.c by
    creating DISABLE_UNLIKELY_PROFILE facility for code to turn off
    instrumentation on a per file basis.

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • Impact: new unlikely/likely profiler

    Andrew Morton recently suggested having an in-kernel way to profile
    likely and unlikely macros. This patch achieves that goal.

    When configured, every(*) likely and unlikely macro gets a counter attached
    to it. When the condition is hit, the hit and misses of that condition
    are recorded. These numbers can later be retrieved by:

    /debugfs/tracing/profile_likely - All likely markers
    /debugfs/tracing/profile_unlikely - All unlikely markers.

    # cat /debug/tracing/profile_unlikely | head
    correct incorrect % Function File Line
    ------- --------- - -------- ---- ----
    2167 0 0 do_arch_prctl process_64.c 832
    0 0 0 do_arch_prctl process_64.c 804
    2670 0 0 IS_ERR err.h 34
    71230 5693 7 __switch_to process_64.c 673
    76919 0 0 __switch_to process_64.c 639
    43184 33743 43 __switch_to process_64.c 624
    12740 64181 83 __switch_to process_64.c 594
    12740 64174 83 __switch_to process_64.c 590

    # cat /debug/tracing/profile_unlikely | \
    awk '{ if ($3 > 25) print $0; }' |head -20
    44963 35259 43 __switch_to process_64.c 624
    12762 67454 84 __switch_to process_64.c 594
    12762 67447 84 __switch_to process_64.c 590
    1478 595 28 syscall_get_error syscall.h 51
    0 2821 100 syscall_trace_leave ptrace.c 1567
    0 1 100 native_smp_prepare_cpus smpboot.c 1237
    86338 265881 75 calc_delta_fair sched_fair.c 408
    210410 108540 34 calc_delta_mine sched.c 1267
    0 54550 100 sched_info_queued sched_stats.h 222
    51899 66435 56 pick_next_task_fair sched_fair.c 1422
    6 10 62 yield_task_fair sched_fair.c 982
    7325 2692 26 rt_policy sched.c 144
    0 1270 100 pre_schedule_rt sched_rt.c 1261
    1268 48073 97 pick_next_task_rt sched_rt.c 884
    0 45181 100 sched_info_dequeued sched_stats.h 177
    0 15 100 sched_move_task sched.c 8700
    0 15 100 sched_move_task sched.c 8690
    53167 33217 38 schedule sched.c 4457
    0 80208 100 sched_info_switch sched_stats.h 270
    30585 49631 61 context_switch sched.c 2619

    # cat /debug/tracing/profile_likely | awk '{ if ($3 > 25) print $0; }'
    39900 36577 47 pick_next_task sched.c 4397
    20824 15233 42 switch_mm mmu_context_64.h 18
    0 7 100 __cancel_work_timer workqueue.c 560
    617 66484 99 clocksource_adjust timekeeping.c 456
    0 346340 100 audit_syscall_exit auditsc.c 1570
    38 347350 99 audit_get_context auditsc.c 732
    0 345244 100 audit_syscall_entry auditsc.c 1541
    38 1017 96 audit_free auditsc.c 1446
    0 1090 100 audit_alloc auditsc.c 862
    2618 1090 29 audit_alloc auditsc.c 858
    0 6 100 move_masked_irq migration.c 9
    1 198 99 probe_sched_wakeup trace_sched_switch.c 58
    2 2 50 probe_wakeup trace_sched_wakeup.c 227
    0 2 100 probe_wakeup_sched_switch trace_sched_wakeup.c 144
    4514 2090 31 __grab_cache_page filemap.c 2149
    12882 228786 94 mapping_unevictable pagemap.h 50
    4 11 73 __flush_cpu_slab slub.c 1466
    627757 330451 34 slab_free slub.c 1731
    2959 61245 95 dentry_lru_del_init dcache.c 153
    946 1217 56 load_elf_binary binfmt_elf.c 904
    102 82 44 disk_put_part genhd.h 206
    1 1 50 dst_gc_task dst.c 82
    0 19 100 tcp_mss_split_point tcp_output.c 1126

    As you can see by the above, there's a bit of work to do in rethinking
    the use of some unlikelys and likelys. Note: the unlikely case had 71 hits
    that were more than 25%.

    Note: After submitting my first version of this patch, Andrew Morton
    showed me a version written by Daniel Walker, where I picked up
    the following ideas from:

    1) Using __builtin_constant_p to avoid profiling fixed values.
    2) Using __FILE__ instead of instruction pointers.
    3) Using the preprocessor to stop all profiling of likely
    annotations from vsyscall_64.c.

    Thanks to Andrew Morton, Arjan van de Ven, Theodore Tso and Ingo Molnar
    for their feed back on this patch.

    (*) Not ever unlikely is recorded, those that are used by vsyscalls
    (a few of them) had to have profiling disabled.

    Signed-off-by: Steven Rostedt
    Cc: Andrew Morton
    Cc: Frederic Weisbecker
    Cc: Theodore Tso
    Cc: Arjan van de Ven
    Cc: Steven Rostedt
    Signed-off-by: Ingo Molnar

    Steven Rostedt
     

14 Oct, 2008

1 commit


18 Aug, 2008

1 commit


11 May, 2008

1 commit


05 Mar, 2008

1 commit

  • People are adding `noinline' in various places to prevent excess stack
    consumption due to gcc inlining. But once this is done, it is quite unobvious
    why the `noinline' is present in the code. We can comment each and every
    site, or we can use noinline_for_stack.

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

    Andrew Morton
     

29 Jan, 2008

2 commits


26 Oct, 2007

1 commit

  • The __deprecated marker is quite useful in highlighting the remnants of
    old APIs that want removing.

    However, it is quite normal for one or more years to pass, before the
    (usually ancient, bitrotten) code in question is either updated or
    deleted.

    Thus, like __must_check, add a Kconfig option that permits the silencing
    of this compiler warning.

    This change mimics the ifdef-ery and Kconfig defaults of MUST_CHECK as
    closely as possible.

    Signed-off-by: Jeff Garzik
    Signed-off-by: Linus Torvalds

    Jeff Garzik
     

19 Oct, 2007

1 commit

  • To be consistent with the use of attributes in the rest of the kernel
    replace all use of __attribute_pure__ with __pure and delete the definition
    of __attribute_pure__.

    Signed-off-by: Ralf Baechle
    Cc: Russell King
    Acked-by: Mauro Carvalho Chehab
    Cc: Bryan Wu
    Cc: Paul Mackerras
    Cc: Benjamin Herrenschmidt
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ralf Baechle
     

27 Jul, 2007

1 commit


22 Jul, 2007

1 commit

  • gcc 4.3 supports a new __attribute__((__cold__)) to mark functions cold. Any
    path directly leading to a call of this function will be unlikely. And gcc
    will try to generate smaller code for the function itself.

    Please use with care. The code generation advantage isn't large and in most
    cases it is not worth uglifying code with this.

    This patch marks some common error functions like panic(), printk()
    as cold. This will longer term make many unlikely()s unnecessary, although
    we can keep them for now for older compilers.

    BUG is not marked cold because there is currently no way to tell
    gcc to mark a inline function told.

    Also all __init and __exit functions are marked cold. With a non -Os
    build this will tell the compiler to generate slightly smaller code
    for them. I think it currently only uses less alignments for labels,
    but that might change in the future.

    One disadvantage over *likely() is that they cannot be easily instrumented
    to verify them.

    Another drawback is that only the latest gcc 4.3 snapshots support this.
    Unfortunately we cannot detect this using the preprocessor. This means older
    snapshots will fail now. I don't think that's a problem because they are
    unreleased compilers that nobody should be using.

    gcc also has a __hot__ attribute, but I don't see any sense in using
    this in the kernel right now. But someday I hope gcc will be able
    to use more aggressive optimizing for hot functions even in -Os,
    if that happens it should be added.

    Includes compile fix from Thomas Gleixner.

    Cc: Jan Hubicka
    Signed-off-by: Andi Kleen
    Signed-off-by: Linus Torvalds

    Andi Kleen
     

22 May, 2007

1 commit


10 May, 2007

1 commit

  • __used is defined to be __attribute__((unused)) for all pre-3.3 gcc
    compilers to suppress warnings for unused functions because perhaps they
    are referenced only in inline assembly. It is defined to be
    __attribute__((used)) for gcc 3.3 and later so that the code is still
    emitted for such functions.

    __maybe_unused is defined to be __attribute__((unused)) for both function
    and variable use if it could possibly be unreferenced due to the evaluation
    of preprocessor macros. Function prototypes shall be marked with
    __maybe_unused if the actual definition of the function is dependant on
    preprocessor macros.

    No update to compiler-intel.h is necessary because ICC supports both
    __attribute__((used)) and __attribute__((unused)) as specified by the gcc
    manual.

    __attribute_used__ is deprecated and will be removed once all current
    code is converted to using __used.

    Cc: Rusty Russell
    Cc: Adrian Bunk
    Signed-off-by: David Rientjes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    David Rientjes
     

27 Mar, 2007

1 commit

  • Change prototypes for __chk_user_ptr and __chk_io_ptr to take const
    void* instead of void*, so that code can pass "const void *" to them.

    (Right now sparse does not warn about passing const void* to void*
    functions, but that is a separate bug that I believe Josh is working on,
    and once sparse does check this, the changed prototypes will be
    necessary.)

    Signed-off-by: Russ Cox
    Signed-off-by: Josh Triplett
    Acked-by: Christopher Li
    Signed-off-by: Linus Torvalds

    Russ Cox
     

13 Dec, 2006

1 commit


01 Oct, 2006

1 commit

  • The lock annotation macros __acquires, __releases, __acquire, and __release
    all currently throw away the lock expression passed as an argument. Now
    that sparse can parse __context__ and __attribute__((context)) with a
    context expression, pass the lock expression down to sparse as the context
    expression. This requires a version of sparse from GIT commit
    37475a6c1c3e66219e68d912d5eb833f4098fd72 or later.

    Signed-off-by: Josh Triplett
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Josh Triplett
     

30 Sep, 2006

1 commit


26 Sep, 2006

1 commit