Bug 203751

Summary: check alignment of atomicops/bitops
Product: Memory Management Reporter: Dmitry Vyukov (dvyukov)
Component: SanitizersAssignee: MM/Sanitizers virtual assignee (mm_sanitizers)
Status: NEW ---    
Severity: enhancement CC: kasan-dev
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: ALL Subsystem:
Regression: No Bisected commit-id:

Description Dmitry Vyukov 2019-05-29 11:28:43 UTC
This come up during review of bitops instrumentation:
https://groups.google.com/d/msg/kasan-dev/g8BcLLjpgoA/qxaxdveBBQAJ

It would be useful to check that addresses passed to atomicops/bitops are properly aligned, because the future hardware may trap on unaligned accesses, there is significant performance penalty for accesses splitting cache lines and it may cause problems with bit/little-endiness.

Bitops should be aligned to long:
https://groups.google.com/d/msg/kasan-dev/g8BcLLjpgoA/Fr5uTbiEBQAJ
Documentation/core-api/atomic_ops.rst
        Native atomic bit operations are defined to operate on objects aligned
        to the size of an "unsigned long" C data type, and are least of that
        size.  The endianness of the bits within each "unsigned long" are the
        native endianness of the cpu.

This should be done as a separate config (not KASAN) as not related to
KASAN per se. But the existing {atomicops,bitops}-instrumented.h hooks provide handy foundation for such checks.