Skip to contentSkip to conversation

atomic-add-alignment-check-to-instrumented-atomic-operations.patch removed from -mm tree

merged mm-nonmm-stable Andrew Morton 1 participant 1 message Jan 21

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: atomic: add alignment check to instrumented atomic operations
has been removed from the -mm tree. Its filename was
atomic-add-alignment-check-to-instrumented-atomic-operations.patch

This patch was dropped because it was merged into the mm-nonmm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Peter Zijlstra <[email protected]>
Subject: atomic: add alignment check to instrumented atomic operations
Date: Tue, 13 Jan 2026 16:22:28 +1100

Add a Kconfig option for debug builds which logs a warning when an instrumented atomic operation takes place that's misaligned. Some platforms don't trap for this.

[[email protected]: added __DISABLE_EXPORTS conditional and refactored as helper function]
Cc Sasha Levin <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Boqun Feng <[email protected]>
Cc Daniel Borkman <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Eduard Zingerman <[email protected]>
Cc Gary Guo <[email protected]>
Cc Guo Ren <[email protected]>
Cc Hao Luo <[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 Rich Felker <[email protected]>
Cc Song Liu <[email protected]>
Cc Stafford Horne <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Cc Stefan Kristiansson <[email protected]>
Cc Will Deacon <[email protected]>
Cc Yonghong Song <[email protected]>
Cc Yoshinori Sato <[email protected]>

---

 include/linux/instrumented.h |   11 +++++++++++
 lib/Kconfig.debug            |   10 ++++++++++
 2 files changed, 21 insertions(+)
include/linux/instrumented.h renamed from include/linux/instrumented.h~atomic-add-alignment-check-to-instrumented-atomic-operations +11 -0
@@ -7,6 +7,7 @@
 #ifndef _LINUX_INSTRUMENTED_H
 #define _LINUX_INSTRUMENTED_H
 
+#include <linux/bug.h>
 #include <linux/compiler.h>
 #include <linux/kasan-checks.h>
 #include <linux/kcsan-checks.h>
@@ -55,6 +56,13 @@ static __always_inline void instrument_r
 	kcsan_check_read_write(v, size);
 }
 
+static __always_inline void instrument_atomic_check_alignment(const volatile void *v, size_t size)
+{
+#ifndef __DISABLE_EXPORTS
+	WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ATOMIC) && ((unsigned long)v & (size - 1)));
+#endif
+}
+
 /**
  * instrument_atomic_read - instrument atomic read access
  * @v: address of access
@@ -67,6 +75,7 @@ static __always_inline void instrument_a
 {
 	kasan_check_read(v, size);
 	kcsan_check_atomic_read(v, size);
+	instrument_atomic_check_alignment(v, size);
 }
 
 /**
@@ -81,6 +90,7 @@ static __always_inline void instrument_a
 {
 	kasan_check_write(v, size);
 	kcsan_check_atomic_write(v, size);
+	instrument_atomic_check_alignment(v, size);
 }
 
 /**
@@ -95,6 +105,7 @@ static __always_inline void instrument_a
 {
 	kasan_check_write(v, size);
 	kcsan_check_atomic_read_write(v, size);
+	instrument_atomic_check_alignment(v, size);
 }
 
 /**
lib/Kconfig.debug renamed from lib/Kconfig.debug~atomic-add-alignment-check-to-instrumented-atomic-operations +10 -0
@@ -1360,6 +1360,16 @@ config DEBUG_PREEMPT
 	  depending on workload as it triggers debugging routines for each
 	  this_cpu operation. It should only be used for debugging purposes.
 
+config DEBUG_ATOMIC
+	bool "Debug atomic variables"
+	depends on DEBUG_KERNEL
+	help
+	  If you say Y here then the kernel will add a runtime alignment check
+	  to atomic accesses. Useful for architectures that do not have trap on
+	  mis-aligned access.
+
+	  This option has potentially significant overhead.
+
 menu "Lock Debugging (spinlocks, mutexes, etc...)"
 
 config LOCK_DEBUGGING_SUPPORT

_

Patches currently in -mm which might be from [email protected] are