LWN: Comments on "Detecting and handling split locks" https://lwn.net/Articles/790464/ This is a special feed containing comments posted to the individual LWN article titled "Detecting and handling split locks". en-us Wed, 29 Oct 2025 11:03:46 +0000 Wed, 29 Oct 2025 11:03:46 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Detecting and handling split locks https://lwn.net/Articles/951365/ https://lwn.net/Articles/951365/ wsy <div class="FormattedComment"> <a href="https://lwn.net/Articles/911219/">https://lwn.net/Articles/911219/</a><br> <a href="https://elixir.bootlin.com/linux/latest/source/arch/x86/kernel/cpu/intel.c#L1172">https://elixir.bootlin.com/linux/latest/source/arch/x86/k...</a><br> <p> Kernel will give a warning with IP attached.<br> </div> Wed, 15 Nov 2023 04:25:25 +0000 Detecting and handling split locks https://lwn.net/Articles/951355/ https://lwn.net/Articles/951355/ farnz <p>The easiest way to catch these is to boot with <tt>split_lock_detect=fatal</tt>; then the kernel will send your process a SIGBUS signal every time you get it wrong. You can then use <tt>catch signal SIGBUS</tt> or <tt>handle signal SIGBUS stop</tt> to get GDB to take control whenever you get a SIGBUS, and your normal tools to debug the program. Note that <tt>catch signal SIGBUS</tt> sets a catchpoint, which can have all your usual nice tools for working with breakpoints applied to it (e.g. <a href="https://sourceware.org/gdb/current/onlinedocs/gdb.html/Break-Commands.html#Break-Commands">automatic commands run</a> when you hit the catchpoint, or <a href="https://sourceware.org/gdb/current/onlinedocs/gdb.html/Conditions.html#Conditions">conditional behaviour</a> such as continuing anyway for a SIGBUS that isn't related to a split lock. Tue, 14 Nov 2023 21:28:54 +0000 Detecting and handling split locks https://lwn.net/Articles/951345/ https://lwn.net/Articles/951345/ d3x0r <div class="FormattedComment"> Is there any support for GDB to be able to pause on these? I have some code apparently that needs alignment, but I don't know where; most structures are typically aligned so setting the break on the exchange will catch thousands of operations otherwise. Is there a signal generated? when I do a search for 'split lock detection gdb' I get articles about one or the other, but not both topics together.<br> </div> Tue, 14 Nov 2023 20:10:21 +0000 Detecting and handling split locks https://lwn.net/Articles/896528/ https://lwn.net/Articles/896528/ pabs <div class="FormattedComment"> Is the 32-bit userland on 64-bit kernel issue something that could be handled by the kernel or a hardware limitation?<br> </div> Sat, 28 May 2022 02:44:26 +0000 Detecting and handling split locks https://lwn.net/Articles/896525/ https://lwn.net/Articles/896525/ plugwash <div class="FormattedComment"> Unaligned access on arm is a horrible mess.<br> <p> On modern arm32, regular loads and stores are unaligned safe, but many other instructions (notably ldrd and vldr) are not. 32-bit kernels will trap and emulate unaligned accesses by default, but 64-bit kernels running 32-bit applications will not.<br> </div> Sat, 28 May 2022 02:06:22 +0000 Detecting and handling split locks https://lwn.net/Articles/861833/ https://lwn.net/Articles/861833/ plugwash <div class="FormattedComment"> It&#x27;s not that simple.<br> <p> arm can handle unaligned accesses on regular ldr and str instructions (and I think also ldrh and strh but i&#x27;m not 100% sure on that) since armv6. There are other instructions the hardware can&#x27;t handle unaligned accesses on though (ldrd and vldr spring to mind as ones I&#x27;ve had trouble with in real code). Some of these will be emulated by 32-bit kernels but not by 64-bit kernels leading to programs crashing when run on 64-bit kernels.<br> <p> While I haven&#x27;t checked I certainly wouldn&#x27;t expect fancy stuff like atomics to properly support unaligned access on arm.<br> </div> Mon, 05 Jul 2021 02:00:22 +0000 Detecting and handling split locks https://lwn.net/Articles/810289/ https://lwn.net/Articles/810289/ erkki <div class="FormattedComment"> I benchmarked this and split locks cause a 200 times slow down for single threaded workloads: <a href="https://rigtorp.se/split-locks/">https://rigtorp.se/split-locks/</a><br> </div> Wed, 22 Jan 2020 16:22:41 +0000 Improving portability advice https://lwn.net/Articles/791123/ https://lwn.net/Articles/791123/ meuh <div class="FormattedComment"> <font class="QuotedText">&gt; This is actually bad advice, here’s my suggestion for improvement,</font><br> <font class="QuotedText">&gt; and why this is important:</font><br> <font class="QuotedText">&gt; </font><br> <font class="QuotedText">&gt;&gt; When writing code, assume the target architecture has natural alignment</font><br> <font class="QuotedText">&gt;&gt; requirements, but be prepared for less alignment.</font><br> <p> The original advice should be interpreted as you have to explicitly pad your structure so that members are naturally aligned.<br> <p> <font class="QuotedText">&gt; [...] the proper fix is to make all struct padding explicit by adding explicitly unused members to the structures.</font><br> <p> Yes, this is the rule you have to follow when designing a data structure to be exchanged between kernel and userspace (or between kernel and firmware/hardware) so that the structure as a fixed size regarding the architecture (and padding can be initialized and/or inspected for unknown bit set).<br> <p> </div> Fri, 14 Jun 2019 08:03:20 +0000 Improving portability advice https://lwn.net/Articles/790884/ https://lwn.net/Articles/790884/ fotoba <div class="FormattedComment"> If pointers will be huge or far<br> not near or not specified <br> <a href="https://www.geeksforgeeks.org/what-are-near-far-and-huge-pointers/">https://www.geeksforgeeks.org/what-are-near-far-and-huge-...</a><br> <p> <p> This problem will not happend as I read well waht happend<br> <p> <p> </div> Tue, 11 Jun 2019 15:02:02 +0000 Improving portability advice https://lwn.net/Articles/790849/ https://lwn.net/Articles/790849/ k8to <div class="FormattedComment"> The typical userland allocators on Solaris &amp; Windows also behave this way. It's not very surprising.<br> <p> On Linux my memory is a bit muddied between the default glibc allocator, tcmalloc, jemalloc etc. so I'm less confident, but I would expect the same.<br> </div> Tue, 11 Jun 2019 13:26:57 +0000 Detecting and handling split locks https://lwn.net/Articles/790834/ https://lwn.net/Articles/790834/ flussence <div class="FormattedComment"> If x86-64 was to support a full x86-32 feature set anyway (which it had to, to avoid the fate of Itanic), it would probably be more costly to selectively gate off all those features in long mode than to let them through.<br> </div> Mon, 10 Jun 2019 20:26:48 +0000 Improving portability advice https://lwn.net/Articles/790782/ https://lwn.net/Articles/790782/ bcopeland <div class="FormattedComment"> If the arrays are dynamically allocated, slab allocator (for example) might do this. I once looked at a case that was allocating a bunch of individual pointers that all got rounded up from 8 to 32 bytes, meaning 75% of each allocation was unused. It makes sense that the allocators work that way, but if you don't know that and do this sort of thing hundreds of times, and especially if the memory being allocated happens to be something like 2**n + small_amount, you can accidentally waste a lot of memory. <br> </div> Mon, 10 Jun 2019 13:17:46 +0000 Detecting and handling split locks https://lwn.net/Articles/790775/ https://lwn.net/Articles/790775/ dmiller <div class="FormattedComment"> You could get a deadlock pretty easily this way, and that's one thing that hardware engineers are going to be very careful to try and avoid. Imagine processor 1 has virtual address 0xA0000 mapped to physical address 0x1000 and 0xA1000 mapped to 0x2000, while processor 2 has 0xA0000 mapped to 0x2000 and 0xA1000 mapped to 0x1000. Now say that both do a 4-byte atomic operation to 0xA0FFF at about the same time. This is equivalent to the "Dining Philosophers Problem" for n=2 which requires a good amount of complexity to do safely.<br> </div> Mon, 10 Jun 2019 10:03:06 +0000 Detecting and handling split locks https://lwn.net/Articles/790771/ https://lwn.net/Articles/790771/ camhusmj38 <div class="FormattedComment"> Lots of things should have been tidied up at that time. Presumably, AMD thought that might make porting more difficult.<br> </div> Mon, 10 Jun 2019 07:10:38 +0000 Detecting and handling split locks https://lwn.net/Articles/790769/ https://lwn.net/Articles/790769/ epa <div class="FormattedComment"> That doesn’t explain why it wasn’t quietly dropped with the move to x86-64. <br> </div> Mon, 10 Jun 2019 06:20:55 +0000 Detecting and handling split locks https://lwn.net/Articles/790767/ https://lwn.net/Articles/790767/ jcm <div class="FormattedComment"> Indeed. This is literally what the LOCK instruction prefix byte means in x86.<br> </div> Mon, 10 Jun 2019 02:38:26 +0000 Detecting and handling split locks https://lwn.net/Articles/790765/ https://lwn.net/Articles/790765/ khim <div class="FormattedComment"> TSX is very recent invention and it's implementation is very tricky and buggy. First generations of CPUs where it was implemented had it disable on almost all models in the end.<br> <p> I'm not surprised they haven't used it to implement something they needed 20 years ago.<br> </div> Sun, 09 Jun 2019 22:53:31 +0000 Improving portability advice https://lwn.net/Articles/790760/ https://lwn.net/Articles/790760/ itvirta <div class="FormattedComment"> What exactly pads your structures to powers of two in arrays?<br> <p> </div> Sun, 09 Jun 2019 18:44:26 +0000 Improving portability advice https://lwn.net/Articles/790752/ https://lwn.net/Articles/790752/ mirabilos <div class="FormattedComment"> Oh, so ESR wrote a detailled article about it. I only knew from OpenBSD commits and figuring out the rest myself.<br> <p> Yes! I’ve significantly reduced the in-memory size of several structures (which are then used in arrays, which pads them to powers of 2 at the end too, so going down from 36 to 32 actually reduces from 64 to 32) in some codebasēs.<br> </div> Sun, 09 Jun 2019 11:53:28 +0000 Improving portability advice https://lwn.net/Articles/790745/ https://lwn.net/Articles/790745/ marcH <div class="FormattedComment"> I liked this BTW, do you approve? <a href="http://www.catb.org/esr/structure-packing/">http://www.catb.org/esr/structure-packing/</a><br> </div> Sun, 09 Jun 2019 04:29:29 +0000 indeed https://lwn.net/Articles/790741/ https://lwn.net/Articles/790741/ gus3 <div class="FormattedComment"> I agree with you wholeheartedly. In fact, you inspired me to renew my subscription, which was set to end next month.<br> </div> Sun, 09 Jun 2019 01:19:11 +0000 Detecting and handling split locks https://lwn.net/Articles/790740/ https://lwn.net/Articles/790740/ luto <div class="FormattedComment"> Intel *has* that feature: TSX. I’m a bit surprised that microcode doesn’t emulate split locks using TSX.<br> </div> Sat, 08 Jun 2019 23:43:50 +0000 Improving portability advice https://lwn.net/Articles/790737/ https://lwn.net/Articles/790737/ scientes <div class="FormattedComment"> I did that for SocketCAN frames. a2f11835994ed5bcd6d66c7205947cc482231b08<br> <p> </div> Sat, 08 Jun 2019 23:14:58 +0000 Detecting and handling split locks https://lwn.net/Articles/790736/ https://lwn.net/Articles/790736/ pbonzini <div class="FormattedComment"> Because back in the 386 (and earlier) days there was no cache and atomic operations were done by literally locking the whole bus, so for the processor it was simpler not to do any check on the alignment after all it did not do any check on non-locked accesses). And when a cache was added, backwards compatibility meant you couldn't drop the feature.<br> </div> Sat, 08 Jun 2019 22:32:49 +0000 Improving portability advice https://lwn.net/Articles/790735/ https://lwn.net/Articles/790735/ mirabilos <div class="FormattedComment"> The kernel documentation currently states:<br> <p> <font class="QuotedText">&gt; When writing code, assume the target architecture has natural alignment</font><br> <font class="QuotedText">&gt; requirements.</font><br> <p> This is actually bad advice, here’s my suggestion for improvement,<br> and why this is important:<br> <p> <font class="QuotedText">&gt; When writing code, assume the target architecture has natural alignment</font><br> <font class="QuotedText">&gt; requirements, but be prepared for less alignment.</font><br> <p> On m68k, even dword (32-bit) quantities are only aligned for 16 bits,<br> and there has been software that implicitly relies on the implicit<br> padding added by natural-alignment architectures if you have a<br> struct { short; int; }; which is not added on m68k.<br> <p> We’ve been fixing some of them by changing some assertions (against<br> accidental struct growth) from sizeof(struct) == value to &lt;= value,<br> but the proper fix is to make all struct padding explicit by adding<br> explicitly unused members to the structures. This also helps visua‐<br> lising the problems of uninitialised padding when comparing them.<br> <p> I’d appreciate if someone with experuence in the LKML community<br> could pick this up and discuss and fix it there.<br> </div> Sat, 08 Jun 2019 20:54:05 +0000 Detecting and handling split locks https://lwn.net/Articles/790731/ https://lwn.net/Articles/790731/ mokki <div class="FormattedComment"> Most likely the easiest way to avoid deadlocks for this rare case is to take bus lock<br> </div> Sat, 08 Jun 2019 19:39:38 +0000 Detecting and handling split locks https://lwn.net/Articles/790730/ https://lwn.net/Articles/790730/ lkundrak <div class="FormattedComment"> Thanks for this article. It did an excellent job at being an easy read even for someone who happens to be rather ignorant about the multi-processor synchronization or cache architectures. Quality writing of this sort makes it easy to recommend subscribing to LWN to friends.<br> </div> Sat, 08 Jun 2019 17:57:41 +0000 Detecting and handling split locks https://lwn.net/Articles/790729/ https://lwn.net/Articles/790729/ andresfreund <div class="FormattedComment"> <font class="QuotedText">&gt; The Intel architecture allows misaligned memory access in situations where other architectures (such as ARM or RISC-V) do not. One such situation is atomic operations on memory that is split across two cache lines. This feature is largely unknown, but its impact is even less so.</font><br> <p> Does anybody have any insight why support for such "split" atomic accesses was added? Seems like it's an obvious source of complexity - without IMO having a lot of practical benefit? Allowing un-aligned memory accesses is certainly useful for some work, but I don't quite see that being necessary for atomic operations?<br> </div> Sat, 08 Jun 2019 17:55:04 +0000 Detecting and handling split locks https://lwn.net/Articles/790716/ https://lwn.net/Articles/790716/ marcH <div class="FormattedComment"> In software you can implement large number of overly complex features for a fixed and low cost and deliver bug fixes later (or... never).<br> <p> Hardware is a bit different.<br> </div> Sat, 08 Jun 2019 05:14:32 +0000 Detecting and handling split locks https://lwn.net/Articles/790713/ https://lwn.net/Articles/790713/ khim <div class="FormattedComment"> Because it would need to introduce the whole new protocol for that. Basically adding *lots* of complexity to the common and very time-critical pass for the sake of something which, in property designed system, doesn't happen at all.<br> </div> Sat, 08 Jun 2019 03:11:38 +0000 Detecting and handling split locks https://lwn.net/Articles/790710/ https://lwn.net/Articles/790710/ quotemstr <div class="FormattedComment"> Why doesn't the processor just lock both cache lines in the case that an atomic operation spans a cache line? I don't see why it would have to lock the whole bus.<br> </div> Sat, 08 Jun 2019 01:12:00 +0000 Worst case scenario ? https://lwn.net/Articles/790706/ https://lwn.net/Articles/790706/ mpr22 <div class="FormattedComment"> I wasn't even thinking that far, merely as far as "if your software system does this, then something is wrong with it and you should do something about that".<br> </div> Fri, 07 Jun 2019 23:41:32 +0000 Detecting and handling split locks https://lwn.net/Articles/790701/ https://lwn.net/Articles/790701/ daney <div class="FormattedComment"> They are not talking about "normal" memory accesses. The fun seems to happen on unaligned "atomic" accesses. IIRC, ARM does not allow for cache line splitting on atomic operations nor on load-exclusive/store-exclusive.<br> </div> Fri, 07 Jun 2019 22:58:14 +0000 Detecting and handling split locks https://lwn.net/Articles/790697/ https://lwn.net/Articles/790697/ scientes <div class="FormattedComment"> ARM can handle unaligned memory accesses since ARMv6.<br> </div> Fri, 07 Jun 2019 22:06:40 +0000 Worst case scenario ? https://lwn.net/Articles/790695/ https://lwn.net/Articles/790695/ JoeBuck <div class="FormattedComment"> "Identify the saboteur" ... if this approach can be used deliberately as an attack that could allow unprivileged code in a container to bring the host to its knees.<br> <p> </div> Fri, 07 Jun 2019 21:24:49 +0000 Worst case scenario ? https://lwn.net/Articles/790691/ https://lwn.net/Articles/790691/ mpr22 <div class="FormattedComment"> At that point I submit that you need to either recruit better programmers or identify the saboteur :)<br> </div> Fri, 07 Jun 2019 20:58:06 +0000 Worst case scenario ? https://lwn.net/Articles/790688/ https://lwn.net/Articles/790688/ meuh <div class="FormattedComment"> What about an unaligned atomic operation across two consecutive unmapped pages, which will be mapped from physical memory belonging to two different NUMA nodes ?<br> <p> </div> Fri, 07 Jun 2019 20:50:57 +0000 Detecting and handling split locks https://lwn.net/Articles/790682/ https://lwn.net/Articles/790682/ jcm <div class="FormattedComment"> Intel calls these "data chunk split misaligned" loads and stores. When they occur, the (e.g.) load buffer will hold them until the ROB indicates that the execution results would be committable to architectural state. There's a couple of fun patents if you search "data chunk split misaligned" in your favorite search engine.<br> </div> Fri, 07 Jun 2019 19:02:01 +0000