• Marco Elver's avatar
    kcsan: Support compounded read-write instrumentation · 14e2ac8d
    Marco Elver authored
    Add support for compounded read-write instrumentation if supported by
    the compiler. Adds the necessary instrumentation functions, and a new
    type which is used to generate a more descriptive report.
    
    Furthermore, such compounded memory access instrumentation is excluded
    from the "assume aligned writes up to word size are atomic" rule,
    because we cannot assume that the compiler emits code that is atomic for
    compound ops.
    
    LLVM/Clang added support for the feature in:
    https://github.com/llvm/llvm-project/commit/785d41a261d136b64ab6c15c5d35f2adc5ad53e3
    
    The new instrumentation is emitted for sets of memory accesses in the
    same basic block to the same address with at least one read appearing
    before a write. These typically result from compound operations such as
    ++, --, +=, -=, |=, &=, etc. but also equivalent forms such as "var =
    var + 1". Where the compiler determines that it is equivalent to emit a
    call to a single __tsan_read_write instead of separate __tsan_read and
    __tsan_write, we can then benefit from improved performance and better
    reporting for such access patterns.
    
    The new reports now show that the ops are both reads and writes, for
    example:
    
    	read-write to 0xffffffff90548a38 of 8 bytes by task 143 on cpu 3:
    	 test_kernel_rmw_array+0x45/0xa0
    	 access_thread+0x71/0xb0
    	 kthread+0x21e/0x240
    	 ret_from_fork+0x22/0x30
    
    	read-write to 0xffffffff90548a38 of 8 bytes by task 144 on cpu 2:
    	 test_kernel_rmw_array+0x45/0xa0
    	 access_thread+0x71/0xb0
    	 kthread+0x21e/0x240
    	 ret_from_fork+0x22/0x30
    Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: default avatarMarco Elver <elver@google.com>
    Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
    14e2ac8d
Makefile.kcsan 732 Bytes