Skip to content

Commit 9a229ae

Browse files
fthainakpm00
authored andcommitted
atomic: add option for weaker alignment check
Add a new Kconfig symbol to make CONFIG_DEBUG_ATOMIC more useful on those architectures which do not align dynamic allocations to 8-byte boundaries. Without this, CONFIG_DEBUG_ATOMIC produces excessive WARN splats. Link: https://lkml.kernel.org/r/6d25a12934fe9199332f4d65d17c17de450139a8.1768281748.git.fthain@linux-m68k.org Signed-off-by: Finn Thain <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Boqun Feng <[email protected]> Cc: "Borislav Petkov (AMD)" <[email protected]> Cc: Daniel Borkman <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Dinh Nguyen <[email protected]> Cc: Eduard Zingerman <[email protected]> Cc: Gary Guo <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Guo Ren <[email protected]> Cc: Hao Luo <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Fastabend <[email protected]> Cc: John Paul Adrian Glaubitz <[email protected]> Cc: Jonas Bonn <[email protected]> Cc: KP Singh <[email protected]> Cc: Marc Rutland <[email protected]> Cc: Martin KaFai Lau <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Rich Felker <[email protected]> Cc: Sasha Levin (Microsoft) <[email protected]> Cc: Song Liu <[email protected]> Cc: Stafford Horne <[email protected]> Cc: Stanislav Fomichev <[email protected]> Cc: Stefan Kristiansson <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Will Deacon <[email protected]> Cc: Yonghong Song <[email protected]> Cc: Yoshinori Sato <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 80047d8 commit 9a229ae

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

include/linux/instrumented.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ static __always_inline void instrument_read_write(const volatile void *v, size_t
5959
static __always_inline void instrument_atomic_check_alignment(const volatile void *v, size_t size)
6060
{
6161
#ifndef __DISABLE_EXPORTS
62-
WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ATOMIC) && ((unsigned long)v & (size - 1)));
62+
if (IS_ENABLED(CONFIG_DEBUG_ATOMIC)) {
63+
unsigned int mask = size - 1;
64+
65+
if (IS_ENABLED(CONFIG_DEBUG_ATOMIC_LARGEST_ALIGN))
66+
mask &= sizeof(struct { long x; } __aligned_largest) - 1;
67+
WARN_ON_ONCE((unsigned long)v & mask);
68+
}
6369
#endif
6470
}
6571

lib/Kconfig.debug

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,14 @@ config DEBUG_ATOMIC
13701370

13711371
This option has potentially significant overhead.
13721372

1373+
config DEBUG_ATOMIC_LARGEST_ALIGN
1374+
bool "Check alignment only up to __aligned_largest"
1375+
depends on DEBUG_ATOMIC
1376+
help
1377+
If you say Y here then the check for natural alignment of
1378+
atomic accesses will be constrained to the compiler's largest
1379+
alignment for scalar types.
1380+
13731381
menu "Lock Debugging (spinlocks, mutexes, etc...)"
13741382

13751383
config LOCK_DEBUGGING_SUPPORT

0 commit comments

Comments
 (0)