[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d4ab82f5646f901b7c556c4cb8f8adf4096f0c50.1759875560.git.fthain@linux-m68k.org>
Date: Wed, 08 Oct 2025 09:19:20 +1100
From: Finn Thain <fthain@...ux-m68k.org>
To: Peter Zijlstra <peterz@...radead.org>,
Will Deacon <will@...nel.org>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Boqun Feng <boqun.feng@...il.com>,
Jonathan Corbet <corbet@....net>,
Mark Rutland <mark.rutland@....com>,
Arnd Bergmann <arnd@...db.de>,
linux-kernel@...r.kernel.org,
linux-arch@...r.kernel.org,
Geert Uytterhoeven <geert@...ux-m68k.org>,
linux-m68k@...r.kernel.org
Subject: [RFC v3 5/5] 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.
---
include/linux/instrumented.h | 14 +++++++++++---
lib/Kconfig.debug | 9 +++++++++
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/include/linux/instrumented.h b/include/linux/instrumented.h
index 402a999a0d6b..3c9a570dbfa7 100644
--- a/include/linux/instrumented.h
+++ b/include/linux/instrumented.h
@@ -8,11 +8,13 @@
#define _LINUX_INSTRUMENTED_H
#include <linux/bug.h>
+#include <linux/cache.h>
#include <linux/compiler.h>
#include <linux/kasan-checks.h>
#include <linux/kcsan-checks.h>
#include <linux/kmsan-checks.h>
#include <linux/types.h>
+#include <vdso/align.h>
/**
* instrument_read - instrument regular read access
@@ -68,7 +70,9 @@ static __always_inline void instrument_atomic_read(const volatile void *v, size_
{
kasan_check_read(v, size);
kcsan_check_atomic_read(v, size);
- WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ATOMIC) && ((unsigned long)v & (size - 1)));
+ if (IS_ENABLED(CONFIG_DEBUG_ATOMIC))
+ WARN_ON_ONCE(v != PTR_ALIGN(v, IS_ENABLED(CONFIG_DEBUG_ATOMIC_LARGEST_ALIGN) ?
+ __LARGEST_ALIGN : size));
}
/**
@@ -83,7 +87,9 @@ static __always_inline void instrument_atomic_write(const volatile void *v, size
{
kasan_check_write(v, size);
kcsan_check_atomic_write(v, size);
- WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ATOMIC) && ((unsigned long)v & (size - 1)));
+ if (IS_ENABLED(CONFIG_DEBUG_ATOMIC))
+ WARN_ON_ONCE(v != PTR_ALIGN(v, IS_ENABLED(CONFIG_DEBUG_ATOMIC_LARGEST_ALIGN) ?
+ __LARGEST_ALIGN : size));
}
/**
@@ -98,7 +104,9 @@ static __always_inline void instrument_atomic_read_write(const volatile void *v,
{
kasan_check_write(v, size);
kcsan_check_atomic_read_write(v, size);
- WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ATOMIC) && ((unsigned long)v & (size - 1)));
+ if (IS_ENABLED(CONFIG_DEBUG_ATOMIC))
+ WARN_ON_ONCE(v != PTR_ALIGN(v, IS_ENABLED(CONFIG_DEBUG_ATOMIC_LARGEST_ALIGN) ?
+ __LARGEST_ALIGN : size));
}
/**
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index d82626b7d6be..f81b8a9b9216 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1373,6 +1373,15 @@ config DEBUG_ATOMIC
This option has potentially significant overhead.
+config DEBUG_ATOMIC_LARGEST_ALIGN
+ bool "Check alignment only up to __LARGEST_ALIGN"
+ depends on DEBUG_ATOMIC
+ help
+ Say Y here if you require natural alignment of atomic accesses
+ only up to long word boundaries. That is, char, short, int and long
+ will be checked for natural alignment but anything larger checked
+ only for alignment with a long word boundary.
+
menu "Lock Debugging (spinlocks, mutexes, etc...)"
config LOCK_DEBUGGING_SUPPORT
--
2.49.1
Powered by blists - more mailing lists