Example of memory ordering causing excitement in the real world

By: Linus Torvalds (torvalds.delete@this.linux-foundation.org),
Room: Moderated Discussions
Maynard Handley (name99.delete@this.name99.org) on July 9, 2015 10:12 am wrote:
>
> In a talk by Leslie Lamport at Stanford a few months ago, he claimed that formal verification of
> an implementation of the POWER memory model had caught a bug that testing would not have caught.
> You can read this as "the POWER memory model sucks" or you can read this as "this
> sort of thing should be handled by formal verification rather than testing"...

I think formal verification is absolutely the way to go when it comes to memory ordering. Because it is too damn hard any other way.

However, I happen to believe in formal verification as a solution for things like cache protocol definitions (where it is already used) and hardware (where I think it's used at some levels). Make the rules clear, understandable and unambiguous (and very much not surprising), and show that the hardware actually follows the rules.

But formal verification is not necessarily nearly as useful for software.

I used to think that it was completely unrealistic for software, but it turns out that it's at least somewhat possible to maybe not really "formally" verify these things, but at least automate a lot of memory access verification, and there are groups doing some very impressive things.

The software verification is often with adding annotations or simplifying the problem space other ways, though - so the "verification" is not necessarily verifying the actual totality code, but a simplified representation or sub-case. In most cases the verification is run over traces of code (running on different CPU's) and verifying that those traces follow the rules. So it may not be formally verifying the whole thing, but at least it's verifying something, preferably against the actual hardware rules that have also been verified to be honored by the hardware.

But that kind of software verification will not be run on most software. There are groups using Linux for their work (and presumably other systems too, I just wouldn't know about it), and there are groups (often the same group) looking at things like core system libraries. So hopefully there will be coverage of the really core system code, and hopefully at least the core locking primitives have been verified to work, and some really basic libraries are using them correctly.

But verifying software (even with the caveats mentioned above) formally in general? Yeah, not going to happen. People will forget to take locks, and people will create their own ad-hoc synchronization models, and they will get them wrong. And they will "work". Most of the time.

And the subtler and the less intuitive the hardware rules are, the more likely it will be that they will work fine on one piece of hardware (inevitably the one that the developer has, because that's what he tested his fancy new idea on), but then result in very odd and occasional problems on other implementations.

Tightening down the hardware rules really does help enormously with problems like that. The code may be buggy as hell, but at least what you tested on one machine tends to be reasonably close to what you run three generations later and your binary still works, rather than mysteriously crashing in ways you can't reproduce.

And btw, this is not at all a new issue. The whole "one CPU does something subtly different from another CPU because it wasn't well-defined in the architecture" is age-old, and it has been a problem before.

Think "undefined flags after operations" kind of things (x86 had several cases of that), or unused high bits in pointer uses (m68k), or incomplete instruction decoding (6502) or silent odd behavior with unaligned addresses (ARM) or any number of those under-specified hardware issues that people ended up using even though they often weren't documented (and then people had to document them).

HW designers have largely learnt not to do that any more. Weak memory ordering isn't really all that different. It's simply worth making the definition stricter (and using extra hardware to enforce the stricter rules) to avoid problems down the line in the next microarchitecture when you changed something fundamentally internally but don't want that change to break existing applications.

Linus
< Previous Post in ThreadNext Post in Thread >
Thread (202 posts)
TopicPosted ByPosted
Cyclone Macro-op fusionMaynard Handley
  Cyclone Macro-op fusionGabriele Svelto
    Cyclone Macro-op fusionMaynard Handley
      Cyclone Macro-op fusionWilco
        Cyclone Macro-op fusionMaynard Handley
          Cyclone Macro-op fusionMaynard Handley
            Cyclone Macro-op fusionGabriele Svelto
      Power8 branch conversionSHK
        Power8 branch conversionMaynard Handley
          Power8 branch conversionMaynard Handley
        Benefit of dynamic hammock predicationPaul A. Clayton
          Benefit of dynamic hammock predicationMaynard Handley
            Benefit of dynamic hammock predicationEduardoS
            Benefit of dynamic hammock predicationPatrick Chase
          Benefit of dynamic hammock predicationLinus Torvalds
            Benefit of dynamic hammock predicationWilco
              Benefit of dynamic hammock predicationLinus Torvalds
                Benefit of dynamic hammock predicationanon
            Benefit of dynamic hammock predicationPatrick Chase
              Benefit of dynamic hammock predicationanon
              Benefit of dynamic hammock predicationMichael S
              Benefit of dynamic hammock predicationLinus Torvalds
                Benefit of dynamic hammock predicationPatrick Chase
                  Benefit of dynamic hammock predicationSHK
                  Benefit of dynamic hammock predicationMaynard Handley
                    Benefit of dynamic hammock predicationExophase
                      Benefit of dynamic hammock predicationWilco
                      Benefit of dynamic hammock predicationMaynard Handley
                    Benefit of dynamic hammock predicationPatrick Chase
                    Benefit of dynamic hammock predicationMichael S
                  Benefit of dynamic hammock predicationSylvain Collange
                    Benefit of dynamic hammock predicationMaynard Handley
                      Benefit of dynamic hammock predicationSylvain Collange
                        Benefit of dynamic hammock predicationMaynard Handley
                        Sadly, skewed associativity has not been broadly adoptedPaul A. Clayton
                        Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Maynard Handley
                          Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)David Kanter
                            Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Maynard Handley
                              Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Tim McCaffrey
                                Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Patrick Chase
                                  Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Sylvain Collange
                              Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)David Kanter
                                Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Maynard Handley
                            Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Patrick Chase
                          Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Patrick Chase
                          Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)someone
            Benefit of dynamic hammock predicationKonrad Schwarz
            Benefit of dynamic hammock predicationdmcq
              Benefit of dynamic hammock predicationLinus Torvalds
                Benefit of dynamic hammock predicationdmcq
                  Benefit of dynamic hammock predicationLinus Torvalds
                    Example of memory ordering causing excitement in the real worldMark Roulo
                      Example of memory ordering causing excitement in the real worlddmcq
                        Example of memory ordering causing excitement in the real worldMark Roulo
                          Example of memory ordering causing excitement in the real worlddmcq
                          Example of memory ordering causing excitement in the real worldMaynard Handley
                            Example of memory ordering causing excitement in the real worldLinus Torvalds
                              Example of memory ordering causing excitement in the real worlddmcq
                                Example of memory ordering causing excitement in the real worldSimon Farnsworth
                                  Example of memory ordering causing excitement in the real worlddmcq
                                    Example of memory ordering causing excitement in the real worldSimon Farnsworth
                                      Example of memory ordering causing excitement in the real worlddmcq
                                        Example of memory ordering causing excitement in the real worldMichael S
                                        Example of memory ordering causing excitement in the real worldSimon Farnsworth
                                          Example of memory ordering causing excitement in the real worlddmcq
                                            Example of memory ordering causing excitement in the real worldSimon Farnsworth
                                              Example of memory ordering causing excitement in the real worlddmcq
                                                Example of memory ordering causing excitement in the real worldSimon Farnsworth
                                                  Example of memory ordering causing excitement in the real worldWilco
                                                    Example of memory ordering causing excitement in the real worldLinus Torvalds
                                                      Example of memory ordering causing excitement in the real worlddmcq
                                          Example of memory ordering causing excitement in the real worldJouni Osmala
                                            Example of memory ordering causing excitement in the real worldSimon Farnsworth
                                              Example of memory ordering causing excitement in the real worldJouni Osmala
                                                ISA support for bound checkingMichael S
                                                  ISA support for bound checkingEtienne
                                                  MPX on SkylakeMark Roulo
                                                    MPX on SkylakeMichael S
                                                      MPX on SkylakeMark Roulo
                                  Example of memory ordering causing excitement in the real worldanon
                                    Example of memory ordering causing excitement in the real worlddmcq
                                    Example of memory ordering causing excitement in the real worldLinus Torvalds
                                      Example of memory ordering causing excitement in the real worldEduardoS
                                        Example of memory ordering causing excitement in the real worldLinus Torvalds
                                          Example of memory ordering causing excitement in the real worldanon
                                            Example of memory ordering causing excitement in the real worldLinus Torvalds
                                              Example of memory ordering causing excitement in the real worlddmcq
                                                Example of memory ordering causing excitement in the real worldLinus Torvalds
                                                  Example of memory ordering causing excitement in the real worldMaynard Handley
                                                    Example of memory ordering causing excitement in the real worldanon
                                                    Simple cores justifying weak ordering?Paul A. Clayton
                                                      David's Paul A. Clayton
                                                      David's 2015-07-12 10:34 post confirmed some of that (NT)Paul A. Clayton
                                                    Example of memory ordering causing excitement in the real worldEtienne
                                                  Example of memory ordering causing excitement in the real worlddmcq
                                                  Reality is even worseTerry Gray
                                                    Reality is even worseKonrad Schwarz
                                                  A simple CAS/MCAS semanticsβš›
                                                    A simple CAS/MCAS semanticsLinus Torvalds
                                                    A simple CAS/MCAS semanticsEduardoS
                                                Example of memory ordering causing excitement in the real worldsylt
                                                  Example of memory ordering causing excitement in the real worlddmcq
                                                    Example of memory ordering causing excitement in the real worldEduardoS
                                                      Example of memory ordering causing excitement in the real worldMaynard Handley
                                                        Example of memory ordering causing excitement in the real worldEduardoS
                                                      Example of memory ordering causing excitement in the real worldanon
                                                    What high level languages do you have in mind?Mark Roulo
                                                      What high level languages do you have in mind?dmcq
                                                  Example of memory ordering causing excitement in the real worldWilco
                                                    Example of memory ordering causing excitement in the real worldEduardoS
                                                      Example of memory ordering causing excitement in the real worldanon
                                                        Example of memory ordering causing excitement in the real worldEduardoS
                                                          Example of memory ordering causing excitement in the real worldanon
                                      Example of memory ordering causing excitement in the real worldMaynard Handley
                                        Example of memory ordering causing excitement in the real worldEduardoS
                                        Example of memory ordering causing excitement in the real worldLinus Torvalds
                                          Example of memory ordering causing excitement in the real worldEduardoS
                                            Example of memory ordering causing excitement in the real worldNoSpammer
                                              Example of memory ordering causing excitement in the real worldWilco
                                                Example of memory ordering causing excitement in the real worldNoSpammer
                                                  Example of memory ordering causing excitement in the real worldanon
                                                    Example of memory ordering causing excitement in the real worldMichael S
                                                      Example of memory ordering causing excitement in the real worldanon
                                                        Example of memory ordering causing excitement in the real worldNoSpammer
                                                          Example of memory ordering causing excitement in the real worlddmcq
                                                            Example of memory ordering causing excitement in the real worldMichael S
                                                              Example of memory ordering causing excitement in the real worlddmcq
                                                              Can string ops use microarchitectural state?Paul A. Clayton
                                                                Can string ops use microarchitectural state?rwessel
                                                                  Can string ops use microarchitectural state?Paul A. Clayton
                                                                    Can string ops use microarchitectural state?rwessel
                                                                      Can string ops use microarchitectural state?Michael S
                                                                        Can string ops use microarchitectural state?rwessel
                                                                Consider interrupt followed by task preemptionMichael S
                                                                  Consider interrupt followed by task preemptionPaul A. Clayton
                                                            Example of memory ordering causing excitement in the real worldNoSpammer
                                                              Example of memory ordering causing excitement in the real worldLinus Torvalds
                                                                Example of memory ordering causing excitement in the real worldNoSpammer
                                                                  Example of memory ordering causing excitement in the real worldLinus Torvalds
                                                      Example of memory ordering causing excitement in the real worldNoSpammer
                                                    Example of memory ordering causing excitement in the real worldLinus Torvalds
                                                      Example of memory ordering causing excitement in the real worldWilco
                                                        Example of memory ordering causing excitement in the real worldanon
                                                        Example of memory ordering causing excitement in the real worldLinus Torvalds
                                                          Example of memory ordering causing excitement in the real worlddmcq
                                                            Example of memory ordering causing excitement in the real worlddmcq
                                        Example of memory ordering causing excitement in the real worldKonrad Schwarz
                                      Example of memory ordering causing excitement in the real worldanon
                                        Example of memory ordering causing excitement in the real worldanon
                                        Example of memory ordering causing excitement in the real worldDavid Kanter
                                          Example of memory ordering causing excitement in the real worldMichael S
                                            Example of memory ordering causing excitement in the real worldDavid Kanter
                                          Example of memory ordering causing excitement in the real worldanon
                                            Example of memory ordering causing excitement in the real worldGabriele Svelto
                                          Example of memory ordering causing excitement in the real worlddmcq
                                        Example of memory ordering causing excitement in the real worldanon
                                          Example of memory ordering causing excitement in the real worldanon
                                        Example of memory ordering causing excitement in the real worlddmcq
                                          Example of memory ordering causing excitement in the real worldanon
                                            Example of memory ordering causing excitement in the real worlddmcq
                                      Store queues in POWER/PowerPC processorsGabriele Svelto
                                        Not sure about that conclusionDavid Kanter
                                          The POWER4 had the same structureGabriele Svelto
                                        Committing stores in program orderPaul A. Clayton
                                          Committing stores in program orderMaynard Handley
                                      Example of memory ordering causing excitement in the real worldKonrad Schwarz
                                        Example of memory ordering causing excitement in the real worldanon
                                          Example of memory ordering causing excitement in the real worldKonrad Schwarz
                                            Example of memory ordering causing excitement in the real worlddmcq
                                            Example of memory ordering causing excitement in the real worldMichael S
                                              Example of memory ordering causing excitement in the real worldKonrad Schwarz
                                            Example of memory ordering causing excitement in the real worldanon
                                              Example of memory ordering causing excitement in the real worldKonrad Schwarz
                                                Example of memory ordering causing excitement in the real worldanon
                                              Example of memory ordering causing excitement in the real worldanon
                                                Example of memory ordering causing excitement in the real worldanon
                                                Example of memory ordering causing excitement in the real worldGabriele Svelto
                                                Example of memory ordering causing excitement in the real worldKonrad Schwarz
                                                  Example of memory ordering causing excitement in the real worldKonrad Schwarz
                                                  Example of memory ordering causing excitement in the real worldanon
                                                    Example of memory ordering causing excitement in the real worldKonrad Schwarz
                                                      Example of memory ordering causing excitement in the real worldMichael S
                                                        Example of memory ordering causing excitement in the real worldKonrad Schwarz
                                                          Example of memory ordering causing excitement in the real worldKonrad Schwarz
                                                            Example of memory ordering causing excitement in the real worlddmcq
                                    Example of memory ordering causing excitement in the real worlddmcq
                          Example of memory ordering causing excitement in the real worldKonrad Schwarz
                      Example of memory ordering causing excitement in the real worldAnonymousse
          Benefit of dynamic hammock predicationsomeotherdude
            Benefit of dynamic hammock predicationMichael S
          Benefit of dynamic hammock predicationPatrick Chase
            SIMD predication is also helpful, of course (NT)Paul A. Clayton
        Power8 branch conversionGabriele Svelto
          isel works for storesPaul A. Clayton
            isel works for storesPatrick Chase
            isel DOES NOT work for storessomeotherdude
              isel DOES NOT work for storesWilco
              Yes it doesPatrick Chase
                Yes it doesvvid
            You don't need isel eitherGabriele Svelto
              You don't need isel eitherPaul A. Clayton
                You don't need isel eitherGabriele Svelto