linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC v2 0/3] Align atomic storage
@ 2025-09-14  0:45 Finn Thain
  2025-09-14  0:45 ` [RFC v2 1/3] documentation: Discourage alignment assumptions Finn Thain
  0 siblings, 1 reply; 2+ messages in thread
From: Finn Thain @ 2025-09-14  0:45 UTC (permalink / raw)
  To: Peter Zijlstra, Will Deacon
  Cc: Andrew Morton, Arnd Bergmann, Boqun Feng, Jonathan Corbet,
	Geert Uytterhoeven, linux-arch, linux-doc, linux-kernel,
	linux-m68k, Mark Rutland

This series adds the __aligned attribute to atomic_t and atomic64_t.
It also adds a Kconfig option to enable a new runtime warning to help
reveal misaligned atomic accesses on platforms which don't trap that.

Some people might assume scalars are aligned to 4-byte boundaries, while
others might assume natural alignment. Best not to encourage such
assumptions.

Moreover, being that locks are performance sensitive, and being that
atomic operations tend to involve further assumptions, there seems to be
room for improvement here.

Pertinent to this discussion are the section "Memory Efficiency" in
Documentation/RCU/Design/Requirements/Requirements.rst
and the section "GUARANTEES" in Documentation/memory-barriers.txt


Finn Thain (2):
  documentation: Discourage alignment assumptions
  atomic: Specify alignment for atomic_t and atomic64_t

Peter Zijlstra (1):
  atomic: Add alignment check to instrumented atomic operations

 Documentation/core-api/unaligned-memory-access.rst |  7 -------
 include/asm-generic/atomic64.h                     |  2 +-
 include/linux/instrumented.h                       |  4 ++++
 include/linux/types.h                              |  2 +-
 lib/Kconfig.debug                                  | 10 ++++++++++
 5 files changed, 16 insertions(+), 9 deletions(-)

-- 
2.49.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [RFC v2 1/3] documentation: Discourage alignment assumptions
  2025-09-14  0:45 [RFC v2 0/3] Align atomic storage Finn Thain
@ 2025-09-14  0:45 ` Finn Thain
  0 siblings, 0 replies; 2+ messages in thread
From: Finn Thain @ 2025-09-14  0:45 UTC (permalink / raw)
  To: Peter Zijlstra, Will Deacon, Jonathan Corbet
  Cc: Andrew Morton, Boqun Feng, Mark Rutland, Arnd Bergmann,
	linux-kernel, linux-arch, Geert Uytterhoeven, linux-m68k,
	linux-doc

Discourage assumptions that simply don't hold for all Linux ABIs.
Exceptions to the natural alignment rule for scalar types include
long long on i386 and sh.
---
 Documentation/core-api/unaligned-memory-access.rst | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/Documentation/core-api/unaligned-memory-access.rst b/Documentation/core-api/unaligned-memory-access.rst
index 5ceeb80eb539..1390ce2b7291 100644
--- a/Documentation/core-api/unaligned-memory-access.rst
+++ b/Documentation/core-api/unaligned-memory-access.rst
@@ -40,9 +40,6 @@ The rule mentioned above forms what we refer to as natural alignment:
 When accessing N bytes of memory, the base memory address must be evenly
 divisible by N, i.e. addr % N == 0.
 
-When writing code, assume the target architecture has natural alignment
-requirements.
-
 In reality, only a few architectures require natural alignment on all sizes
 of memory access. However, we must consider ALL supported architectures;
 writing code that satisfies natural alignment requirements is the easiest way
@@ -103,10 +100,6 @@ Therefore, for standard structure types you can always rely on the compiler
 to pad structures so that accesses to fields are suitably aligned (assuming
 you do not cast the field to a type of different length).
 
-Similarly, you can also rely on the compiler to align variables and function
-parameters to a naturally aligned scheme, based on the size of the type of
-the variable.
-
 At this point, it should be clear that accessing a single byte (u8 or char)
 will never cause an unaligned access, because all memory addresses are evenly
 divisible by one.
-- 
2.49.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-14  0:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-14  0:45 [RFC v2 0/3] Align atomic storage Finn Thain
2025-09-14  0:45 ` [RFC v2 1/3] documentation: Discourage alignment assumptions Finn Thain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).